2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
28 /***********************************************************************/
30 /* Program: rt_linux.c */
31 /* Created: 4/21/2006 1:17:38 PM */
32 /* Author: Wu Xi-Kun */
33 /* Comments: `description` */
35 /*---------------------------------------------------------------------*/
38 /* Revision 1.1 4/21/2006 1:17:38 PM xsikun */
39 /* Initial revision */
41 /***********************************************************************/
43 #include "rtmp_type.h"
44 #include <linux/module.h>
45 #include <linux/version.h>
46 #include <linux/kernel.h>
47 #include <linux/kthread.h>
49 #include <linux/spinlock.h>
50 #include <linux/init.h>
51 #include <linux/string.h>
52 #include <linux/timer.h>
53 #include <linux/errno.h>
54 #include <linux/slab.h>
55 #include <linux/interrupt.h>
56 #include <linux/pci.h>
57 #include <linux/netdevice.h>
58 #include <linux/etherdevice.h>
59 #include <linux/skbuff.h>
60 #include <linux/ethtool.h>
61 #include <linux/wireless.h>
62 #include <linux/proc_fs.h>
63 #include <linux/delay.h>
64 #include <linux/if_arp.h>
65 #include <linux/ctype.h>
66 #include <linux/vmalloc.h>
69 #include <net/iw_handler.h>
72 #define __KERNEL_SYSCALLS__
73 #include <linux/unistd.h>
74 #include <asm/uaccess.h>
77 #define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
83 //#define CONFIG_CKIP_SUPPORT
86 #define __inline static inline
88 typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
92 #ifdef CONFIG_STA_SUPPORT
95 #define STA_PROFILE_PATH "/etc/Wireless/RT2870STA/RT2870STA.dat"
96 #define STA_RT2870_IMAGE_FILE_NAME "/etc/Wireless/RT2870STA/rt2870.bin"
97 #define STA_NIC_DEVICE_NAME "RT2870STA"
98 #define STA_DRIVER_VERSION "1.4.0.0"
99 #ifdef MULTIPLE_CARD_SUPPORT
100 #define CARD_INFO_PATH "/etc/Wireless/RT2870STA/RT2870STACard.dat"
101 #endif // MULTIPLE_CARD_SUPPORT //
104 #endif // CONFIG_STA_SUPPORT //
107 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
109 #define RTMP_TIME_AFTER(a,b) \
110 (typecheck(unsigned long, (unsigned long)a) && \
111 typecheck(unsigned long, (unsigned long)b) && \
112 ((long)(b) - (long)(a) < 0))
114 #define RTMP_TIME_AFTER_EQ(a,b) \
115 (typecheck(unsigned long, (unsigned long)a) && \
116 typecheck(unsigned long, (unsigned long)b) && \
117 ((long)(a) - (long)(b) >= 0))
118 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
120 #define RTMP_TIME_AFTER(a,b) time_after(a, b)
123 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
124 #define RT_MOD_INC_USE_COUNT() \
125 if (!try_module_get(THIS_MODULE)) \
127 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
131 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
133 #define RT_MOD_INC_USE_COUNT() MOD_INC_USE_COUNT;
134 #define RT_MOD_DEC_USE_COUNT() MOD_DEC_USE_COUNT;
139 #define ETH_LENGTH_OF_ADDRESS 6
144 #define NDIS_STATUS INT
145 #define NDIS_STATUS_SUCCESS 0x00
146 #define NDIS_STATUS_FAILURE 0x01
147 #define NDIS_STATUS_INVALID_DATA 0x02
148 #define NDIS_STATUS_RESOURCES 0x03
150 #define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
151 #define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
152 #define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
153 #define MIN_NET_DEVICE_FOR_APCLI 0x20
154 #define MIN_NET_DEVICE_FOR_MESH 0x30
155 #ifdef CONFIG_STA_SUPPORT
156 #define MIN_NET_DEVICE_FOR_DLS 0x40
157 #endif // CONFIG_STA_SUPPORT //
160 #ifdef CONFIG_STA_SUPPORT
161 #define NDIS_PACKET_TYPE_DIRECTED 0
162 #define NDIS_PACKET_TYPE_MULTICAST 1
163 #define NDIS_PACKET_TYPE_BROADCAST 2
164 #define NDIS_PACKET_TYPE_ALL_MULTICAST 3
165 #endif // CONFIG_STA_SUPPORT //
167 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
168 typedef struct pid * THREAD_PID;
169 #define GET_PID(_v) find_get_pid(_v)
170 #define GET_PID_NUMBER(_v) pid_nr(_v)
171 #define CHECK_PID_LEGALITY(_pid) if (pid_nr(_pid) >= 0)
172 #define KILL_THREAD_PID(_A, _B, _C) kill_pid(_A, _B, _C)
174 typedef pid_t THREAD_PID;
175 #define GET_PID(_v) _v
176 #define GET_PID_NUMBER(_v) _v
177 #define CHECK_PID_LEGALITY(_pid) if (_pid >= 0)
178 #define KILL_THREAD_PID(_A, _B, _C) kill_proc(_A, _B, _C)
190 struct usb_device *pUsb_Dev;
192 struct task_struct *MLMEThr_task;
193 struct task_struct *RTUSBCmdThr_task;
194 struct task_struct *TimerQThr_task;
197 struct tasklet_struct rx_done_task;
198 struct tasklet_struct mgmt_dma_done_task;
199 struct tasklet_struct ac0_dma_done_task;
200 struct tasklet_struct ac1_dma_done_task;
201 struct tasklet_struct ac2_dma_done_task;
202 struct tasklet_struct ac3_dma_done_task;
203 struct tasklet_struct hcca_dma_done_task;
204 struct tasklet_struct tbtt_task;
206 struct tasklet_struct null_frame_complete_task;
207 struct tasklet_struct rts_frame_complete_task;
208 struct tasklet_struct pspoll_frame_complete_task;
212 unsigned long apd_pid; //802.1x daemon pid
217 typedef struct _VIRTUAL_ADAPTER
219 struct net_device *RtmpDev;
220 struct net_device *VirtualDev;
221 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
228 printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
232 typedef struct os_cookie * POS_COOKIE;
233 typedef struct pci_dev * PPCI_DEV;
234 typedef struct net_device * PNET_DEV;
235 typedef void * PNDIS_PACKET;
236 typedef char NDIS_PACKET;
237 typedef PNDIS_PACKET * PPNDIS_PACKET;
238 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
239 typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
240 //typedef struct timer_list RALINK_TIMER_STRUCT;
241 //typedef struct timer_list * PRALINK_TIMER_STRUCT;
242 //typedef struct os_lock NDIS_SPIN_LOCK;
243 typedef spinlock_t NDIS_SPIN_LOCK;
244 typedef struct timer_list NDIS_MINIPORT_TIMER;
245 typedef void * NDIS_HANDLE;
246 typedef char * PNDIS_BUFFER;
250 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
252 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
253 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
256 ////////////////////////////////////////
258 /////////////////////////////////////////
259 #define PKTSRC_NDIS 0x7f
260 #define PKTSRC_DRIVER 0x0f
261 #define PRINT_MAC(addr) \
262 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
265 #define RT2860_PCI_DEVICE_ID 0x0601
269 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
271 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
275 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
276 dma_cache_wback(_ptr, _size)
279 //////////////////////////////////////////
281 //////////////////////////////////////////
284 #define NdisMIndicateStatus(_w, _x, _y, _z)
286 typedef struct timer_list RTMP_OS_TIMER;
289 /* ----------------- Timer Related MARCO ---------------*/
290 // In RT2870, we have a lot of timer functions and will read/write register, it's
291 // not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
292 // to ctrl pipe). So we need a wrapper function to take care it.
294 typedef VOID (*RT2870_TIMER_HANDLE)(
295 IN PVOID SystemSpecific1,
296 IN PVOID FunctionContext,
297 IN PVOID SystemSpecific2,
298 IN PVOID SystemSpecific3);
302 typedef struct _RALINK_TIMER_STRUCT {
303 RTMP_OS_TIMER TimerObj; // Ndis Timer object
304 BOOLEAN Valid; // Set to True when call RTMPInitTimer
305 BOOLEAN State; // True if timer cancelled
306 BOOLEAN PeriodicType; // True if timer is periodic timer
307 BOOLEAN Repeat; // True if periodic timer
308 ULONG TimerValue; // Timer value in milliseconds
309 ULONG cookie; // os specific object
311 RT2870_TIMER_HANDLE handle;
314 } RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
319 typedef enum _RT2870_KERNEL_THREAD_STATUS_
321 RT2870_THREAD_UNKNOWN = 0,
322 RT2870_THREAD_INITED = 1,
323 RT2870_THREAD_RUNNING = 2,
324 RT2870_THREAD_STOPED = 4,
325 }RT2870_KERNEL_THREAD_STATUS;
327 #define RT2870_THREAD_CAN_DO_INSERT (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
329 typedef struct _RT2870_TIMER_ENTRY_
331 RALINK_TIMER_STRUCT *pRaTimer;
332 struct _RT2870_TIMER_ENTRY_ *pNext;
336 #define TIMER_QUEUE_SIZE_MAX 128
337 typedef struct _RT2870_TIMER_QUEUE_
340 //wait_queue_head_t timerWaitQ;
343 RT2870_TIMER_ENTRY *pQPollFreeList;
344 RT2870_TIMER_ENTRY *pQHead;
345 RT2870_TIMER_ENTRY *pQTail;
353 // MACRO for debugging information
357 extern ULONG RTDebugLevel;
359 #define DBGPRINT_RAW(Level, Fmt) \
361 if (Level <= RTDebugLevel) \
367 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
370 #define DBGPRINT_ERR(Fmt) \
372 printk("ERROR!!! "); \
376 #define DBGPRINT_S(Status, Fmt) \
383 #define DBGPRINT(Level, Fmt)
384 #define DBGPRINT_RAW(Level, Fmt)
385 #define DBGPRINT_S(Status, Fmt)
386 #define DBGPRINT_ERR(Fmt)
391 // spin_lock enhanced for Nested spin lock
393 #define NdisAllocateSpinLock(__lock) \
395 spin_lock_init((spinlock_t *)(__lock)); \
398 #define NdisFreeSpinLock(lock) \
403 #define RTMP_SEM_LOCK(__lock) \
405 spin_lock_bh((spinlock_t *)(__lock)); \
408 #define RTMP_SEM_UNLOCK(__lock) \
410 spin_unlock_bh((spinlock_t *)(__lock)); \
413 #if 0 // sample, IRQ LOCK
414 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
416 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
417 pAd->irq_disabled |= 1; \
420 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
422 pAd->irq_disabled &= 0; \
423 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
427 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
428 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
431 spin_lock_bh((spinlock_t *)(__lock)); \
432 pAd->irq_disabled |= 1; \
435 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
437 pAd->irq_disabled &= 0; \
438 spin_unlock_bh((spinlock_t *)(__lock)); \
441 #define RTMP_INT_LOCK(__lock, __irqflags) \
443 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
446 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
448 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
455 //Patch for ASIC turst read/write bug, needs to remove after metel fix
456 #define RTMP_IO_READ32(_A, _R, _pV) \
457 RTUSBReadMACRegister(_A, _R, _pV)
459 #define RTMP_IO_READ8(_A, _R, _pV) \
463 #define RTMP_IO_WRITE32(_A, _R, _V) \
464 RTUSBWriteMACRegister(_A, _R, _V)
467 #define RTMP_IO_WRITE8(_A, _R, _V) \
470 RTUSBSingleWrite(_A, _R, _Val); \
474 #define RTMP_IO_WRITE16(_A, _R, _V) \
476 RTUSBSingleWrite(_A, _R, _V); \
480 #ifndef wait_event_interruptible_timeout
481 #define __wait_event_interruptible_timeout(wq, condition, ret) \
483 wait_queue_t __wait; \
484 init_waitqueue_entry(&__wait, current); \
485 add_wait_queue(&wq, &__wait); \
487 set_current_state(TASK_INTERRUPTIBLE); \
490 if (!signal_pending(current)) { \
491 ret = schedule_timeout(ret); \
496 ret = -ERESTARTSYS; \
499 current->state = TASK_RUNNING; \
500 remove_wait_queue(&wq, &__wait); \
503 #define wait_event_interruptible_timeout(wq, condition, timeout) \
505 long __ret = timeout; \
507 __wait_event_interruptible_timeout(wq, condition, __ret); \
512 #define OS_WAIT(_time) \
514 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
515 wait_queue_head_t _wait; \
516 init_waitqueue_head(&_wait); \
517 for (_i=0; _i<(_loop); _i++) \
518 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
521 typedef void (*TIMER_FUNCTION)(unsigned long);
523 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
525 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
526 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
530 #define BUILD_TIMER_FUNCTION(_func) \
531 void linux_##_func(unsigned long data) \
533 PRALINK_TIMER_STRUCT _pTimer = (PRALINK_TIMER_STRUCT)data; \
534 RT2870_TIMER_ENTRY *_pQNode; \
535 RTMP_ADAPTER *_pAd; \
537 _pTimer->handle = _func; \
538 _pAd = (RTMP_ADAPTER *)_pTimer->pAd; \
539 _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer); \
540 if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)) \
541 RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ); \
546 #define DECLARE_TIMER_FUNCTION(_func) \
547 void linux_##_func(unsigned long data)
549 #define GET_TIMER_FUNCTION(_func) \
552 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
553 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
554 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
555 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
556 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
558 DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
562 #ifdef CONFIG_STA_SUPPORT
563 DECLARE_TIMER_FUNCTION(BeaconTimeout);
564 DECLARE_TIMER_FUNCTION(ScanTimeout);
565 DECLARE_TIMER_FUNCTION(AuthTimeout);
566 DECLARE_TIMER_FUNCTION(AssocTimeout);
567 DECLARE_TIMER_FUNCTION(ReassocTimeout);
568 DECLARE_TIMER_FUNCTION(DisassocTimeout);
569 DECLARE_TIMER_FUNCTION(LinkDownExec);
571 DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
573 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
574 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
575 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
576 DECLARE_TIMER_FUNCTION(RadioOnExec);
578 #ifdef QOS_DLS_SUPPORT
579 DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
580 #endif // QOS_DLS_SUPPORT //
581 #endif // CONFIG_STA_SUPPORT //
583 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
588 * - convert internal rt packet to os packet or
589 * os packet to rt packet
591 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
592 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
594 #define GET_OS_PKT_DATAPTR(_pkt) \
595 (RTPKT_TO_OSPKT(_pkt)->data)
597 #define GET_OS_PKT_LEN(_pkt) \
598 (RTPKT_TO_OSPKT(_pkt)->len)
600 #define GET_OS_PKT_DATATAIL(_pkt) \
601 (RTPKT_TO_OSPKT(_pkt)->tail)
603 #define GET_OS_PKT_HEAD(_pkt) \
604 (RTPKT_TO_OSPKT(_pkt)->head)
606 #define GET_OS_PKT_END(_pkt) \
607 (RTPKT_TO_OSPKT(_pkt)->end)
609 #define GET_OS_PKT_NETDEV(_pkt) \
610 (RTPKT_TO_OSPKT(_pkt)->dev)
612 #define GET_OS_PKT_TYPE(_pkt) \
613 (RTPKT_TO_OSPKT(_pkt))
615 #define GET_OS_PKT_NEXT(_pkt) \
616 (RTPKT_TO_OSPKT(_pkt)->next)
619 #define OS_NTOHS(_Val) \
621 #define OS_HTONS(_Val) \
623 #define OS_NTOHL(_Val) \
625 #define OS_HTONL(_Val) \
628 /* statistics counter */
629 #define STATS_INC_RX_PACKETS(_pAd, _dev)
630 #define STATS_INC_TX_PACKETS(_pAd, _dev)
632 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
633 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
635 #define STATS_INC_RX_ERRORS(_pAd, _dev)
636 #define STATS_INC_TX_ERRORS(_pAd, _dev)
638 #define STATS_INC_RX_DROPPED(_pAd, _dev)
639 #define STATS_INC_TX_DROPPED(_pAd, _dev)
645 // check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
646 // ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
648 //#define RTMP_GET_PACKET_MR(_p) (RTPKT_TO_OSPKT(_p))
651 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
652 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
655 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
656 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
658 // 0x0 ~0x7f: TX to AP's own BSS which has the specified AID. if AID>127, set bit 7 in RTMP_SET_PACKET_EMACTAB too.
659 //(this value also as MAC(on-chip WCID) table index)
660 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
661 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
662 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
664 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
665 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
666 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
668 // RTS/CTS-to-self protection method
669 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
670 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
671 // see RTMP_S(G)ET_PACKET_EMACTAB
674 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
675 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
677 // From which Interface
678 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
679 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
680 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
681 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
682 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
683 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
684 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
685 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
687 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
688 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
690 //#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
691 //#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) (RTPKT_TO_OSPKT(_p)->cb[8])
697 //#define RTMP_SET_PACKET_DHCP(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
698 //#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
701 // Sepcific Pakcet Type definition
703 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
705 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
706 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
707 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
708 #define RTMP_PACKET_SPECIFIC_WAI 0x08
709 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
710 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
713 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
716 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
719 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
721 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
723 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
726 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
729 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
731 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
733 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
736 #define RTMP_SET_PACKET_WAI(_p, _flg) \
739 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
741 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
743 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
745 #define RTMP_GET_PACKET_LOWRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & (RTMP_PACKET_SPECIFIC_EAPOL | RTMP_PACKET_SPECIFIC_DHCP | RTMP_PACKET_SPECIFIC_WAI))
748 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
751 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
753 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
755 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
758 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
761 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
763 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
766 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
769 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
772 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
774 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
777 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
782 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
783 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
784 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
786 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
787 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
790 #ifdef CONFIG_5VT_ENHANCE
791 #define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
795 #define NDIS_SET_PACKET_STATUS(_p, _status)
798 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
799 rt_get_sg_list_from_packet(_p, _sc)
802 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
803 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
804 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
805 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
806 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
809 #define RTMP_INC_REF(_A) 0
810 #define RTMP_DEC_REF(_A) 0
811 #define RTMP_GET_REF(_A) 0
817 * RTMP_GetPhysicalAddressLow(
818 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
820 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
824 * RTMP_GetPhysicalAddressHigh(
825 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
827 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
831 * RTMP_SetPhysicalAddressLow(
832 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
835 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
836 PhysicalAddress = Value;
840 * RTMP_SetPhysicalAddressHigh(
841 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
844 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
847 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
848 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
849 (PNDIS_PACKET)(pEntry)
851 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
852 (PQUEUE_ENTRY)(pPacket)
855 #ifndef CONTAINING_RECORD
856 #define CONTAINING_RECORD(address, type, field) \
857 ((type *)((PCHAR)(address) - offsetof(type, field)))
861 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
863 RTMPFreeNdisPacket(_pAd, _pPacket); \
867 #define SWITCH_PhyAB(_pAA, _pBB) \
869 ULONG AABasePaHigh; \
871 ULONG BBBasePaHigh; \
873 BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
874 BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
875 AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
876 AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
877 RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
878 RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
879 RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
880 RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
884 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
885 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
888 #define NdisAcquireSpinLock RTMP_SEM_LOCK
889 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
891 static inline void NdisGetSystemUpTime(ULONG *time)
896 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
897 #define QUEUE_ENTRY_TO_PKT(pEntry) \
898 ((PNDIS_PACKET) (pEntry))
900 int rt28xx_packet_xmit(struct sk_buff *skb);
904 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);