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"
101 #endif // CONFIG_STA_SUPPORT //
104 #define RTMP_TIME_AFTER(a,b) \
105 (typecheck(unsigned long, (unsigned long)a) && \
106 typecheck(unsigned long, (unsigned long)b) && \
107 ((long)(b) - (long)(a) < 0))
109 #define RTMP_TIME_AFTER_EQ(a,b) \
110 (typecheck(unsigned long, (unsigned long)a) && \
111 typecheck(unsigned long, (unsigned long)b) && \
112 ((long)(a) - (long)(b) >= 0))
113 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
115 #define RT_MOD_INC_USE_COUNT() \
116 if (!try_module_get(THIS_MODULE)) \
118 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
122 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
126 #define ETH_LENGTH_OF_ADDRESS 6
131 #define NDIS_STATUS INT
132 #define NDIS_STATUS_SUCCESS 0x00
133 #define NDIS_STATUS_FAILURE 0x01
134 #define NDIS_STATUS_INVALID_DATA 0x02
135 #define NDIS_STATUS_RESOURCES 0x03
137 #define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
138 #define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
139 #define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
140 #define MIN_NET_DEVICE_FOR_APCLI 0x20
141 #define MIN_NET_DEVICE_FOR_MESH 0x30
142 #ifdef CONFIG_STA_SUPPORT
143 #define MIN_NET_DEVICE_FOR_DLS 0x40
144 #endif // CONFIG_STA_SUPPORT //
147 #ifdef CONFIG_STA_SUPPORT
148 #define NDIS_PACKET_TYPE_DIRECTED 0
149 #define NDIS_PACKET_TYPE_MULTICAST 1
150 #define NDIS_PACKET_TYPE_BROADCAST 2
151 #define NDIS_PACKET_TYPE_ALL_MULTICAST 3
152 #endif // CONFIG_STA_SUPPORT //
154 typedef struct pid * THREAD_PID;
155 #define GET_PID(_v) find_get_pid(_v)
156 #define GET_PID_NUMBER(_v) pid_nr(_v)
157 #define CHECK_PID_LEGALITY(_pid) if (pid_nr(_pid) >= 0)
158 #define KILL_THREAD_PID(_A, _B, _C) kill_pid(_A, _B, _C)
169 struct usb_device *pUsb_Dev;
171 struct task_struct *MLMEThr_task;
172 struct task_struct *RTUSBCmdThr_task;
173 struct task_struct *TimerQThr_task;
176 struct tasklet_struct rx_done_task;
177 struct tasklet_struct mgmt_dma_done_task;
178 struct tasklet_struct ac0_dma_done_task;
179 struct tasklet_struct ac1_dma_done_task;
180 struct tasklet_struct ac2_dma_done_task;
181 struct tasklet_struct ac3_dma_done_task;
182 struct tasklet_struct hcca_dma_done_task;
183 struct tasklet_struct tbtt_task;
185 struct tasklet_struct null_frame_complete_task;
186 struct tasklet_struct rts_frame_complete_task;
187 struct tasklet_struct pspoll_frame_complete_task;
191 unsigned long apd_pid; //802.1x daemon pid
196 typedef struct _VIRTUAL_ADAPTER
198 struct net_device *RtmpDev;
199 struct net_device *VirtualDev;
200 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
207 printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
211 typedef struct os_cookie * POS_COOKIE;
212 typedef struct pci_dev * PPCI_DEV;
213 typedef struct net_device * PNET_DEV;
214 typedef void * PNDIS_PACKET;
215 typedef char NDIS_PACKET;
216 typedef PNDIS_PACKET * PPNDIS_PACKET;
217 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
218 typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
219 //typedef struct timer_list RALINK_TIMER_STRUCT;
220 //typedef struct timer_list * PRALINK_TIMER_STRUCT;
221 //typedef struct os_lock NDIS_SPIN_LOCK;
222 typedef spinlock_t NDIS_SPIN_LOCK;
223 typedef struct timer_list NDIS_MINIPORT_TIMER;
224 typedef void * NDIS_HANDLE;
225 typedef char * PNDIS_BUFFER;
229 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
231 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
232 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
235 ////////////////////////////////////////
237 /////////////////////////////////////////
238 #define PKTSRC_NDIS 0x7f
239 #define PKTSRC_DRIVER 0x0f
240 #define PRINT_MAC(addr) \
241 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
244 #define RT2860_PCI_DEVICE_ID 0x0601
248 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
250 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
254 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
255 dma_cache_wback(_ptr, _size)
258 //////////////////////////////////////////
260 //////////////////////////////////////////
263 #define NdisMIndicateStatus(_w, _x, _y, _z)
265 typedef struct timer_list RTMP_OS_TIMER;
268 /* ----------------- Timer Related MARCO ---------------*/
269 // In RT2870, we have a lot of timer functions and will read/write register, it's
270 // not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
271 // to ctrl pipe). So we need a wrapper function to take care it.
273 typedef VOID (*RT2870_TIMER_HANDLE)(
274 IN PVOID SystemSpecific1,
275 IN PVOID FunctionContext,
276 IN PVOID SystemSpecific2,
277 IN PVOID SystemSpecific3);
281 typedef struct _RALINK_TIMER_STRUCT {
282 RTMP_OS_TIMER TimerObj; // Ndis Timer object
283 BOOLEAN Valid; // Set to True when call RTMPInitTimer
284 BOOLEAN State; // True if timer cancelled
285 BOOLEAN PeriodicType; // True if timer is periodic timer
286 BOOLEAN Repeat; // True if periodic timer
287 ULONG TimerValue; // Timer value in milliseconds
288 ULONG cookie; // os specific object
290 RT2870_TIMER_HANDLE handle;
293 } RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
298 typedef enum _RT2870_KERNEL_THREAD_STATUS_
300 RT2870_THREAD_UNKNOWN = 0,
301 RT2870_THREAD_INITED = 1,
302 RT2870_THREAD_RUNNING = 2,
303 RT2870_THREAD_STOPED = 4,
304 }RT2870_KERNEL_THREAD_STATUS;
306 #define RT2870_THREAD_CAN_DO_INSERT (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
308 typedef struct _RT2870_TIMER_ENTRY_
310 RALINK_TIMER_STRUCT *pRaTimer;
311 struct _RT2870_TIMER_ENTRY_ *pNext;
315 #define TIMER_QUEUE_SIZE_MAX 128
316 typedef struct _RT2870_TIMER_QUEUE_
319 //wait_queue_head_t timerWaitQ;
322 RT2870_TIMER_ENTRY *pQPollFreeList;
323 RT2870_TIMER_ENTRY *pQHead;
324 RT2870_TIMER_ENTRY *pQTail;
332 // MACRO for debugging information
336 extern ULONG RTDebugLevel;
338 #define DBGPRINT_RAW(Level, Fmt) \
340 if (Level <= RTDebugLevel) \
346 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
349 #define DBGPRINT_ERR(Fmt) \
351 printk("ERROR!!! "); \
355 #define DBGPRINT_S(Status, Fmt) \
362 #define DBGPRINT(Level, Fmt)
363 #define DBGPRINT_RAW(Level, Fmt)
364 #define DBGPRINT_S(Status, Fmt)
365 #define DBGPRINT_ERR(Fmt)
370 // spin_lock enhanced for Nested spin lock
372 #define NdisAllocateSpinLock(__lock) \
374 spin_lock_init((spinlock_t *)(__lock)); \
377 #define NdisFreeSpinLock(lock) \
382 #define RTMP_SEM_LOCK(__lock) \
384 spin_lock_bh((spinlock_t *)(__lock)); \
387 #define RTMP_SEM_UNLOCK(__lock) \
389 spin_unlock_bh((spinlock_t *)(__lock)); \
392 #if 0 // sample, IRQ LOCK
393 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
395 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
396 pAd->irq_disabled |= 1; \
399 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
401 pAd->irq_disabled &= 0; \
402 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
406 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
407 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
410 spin_lock_bh((spinlock_t *)(__lock)); \
411 pAd->irq_disabled |= 1; \
414 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
416 pAd->irq_disabled &= 0; \
417 spin_unlock_bh((spinlock_t *)(__lock)); \
420 #define RTMP_INT_LOCK(__lock, __irqflags) \
422 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
425 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
427 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
434 //Patch for ASIC turst read/write bug, needs to remove after metel fix
435 #define RTMP_IO_READ32(_A, _R, _pV) \
436 RTUSBReadMACRegister(_A, _R, _pV)
438 #define RTMP_IO_READ8(_A, _R, _pV) \
442 #define RTMP_IO_WRITE32(_A, _R, _V) \
443 RTUSBWriteMACRegister(_A, _R, _V)
446 #define RTMP_IO_WRITE8(_A, _R, _V) \
449 RTUSBSingleWrite(_A, _R, _Val); \
453 #define RTMP_IO_WRITE16(_A, _R, _V) \
455 RTUSBSingleWrite(_A, _R, _V); \
459 #ifndef wait_event_interruptible_timeout
460 #define __wait_event_interruptible_timeout(wq, condition, ret) \
462 wait_queue_t __wait; \
463 init_waitqueue_entry(&__wait, current); \
464 add_wait_queue(&wq, &__wait); \
466 set_current_state(TASK_INTERRUPTIBLE); \
469 if (!signal_pending(current)) { \
470 ret = schedule_timeout(ret); \
475 ret = -ERESTARTSYS; \
478 current->state = TASK_RUNNING; \
479 remove_wait_queue(&wq, &__wait); \
482 #define wait_event_interruptible_timeout(wq, condition, timeout) \
484 long __ret = timeout; \
486 __wait_event_interruptible_timeout(wq, condition, __ret); \
491 #define OS_WAIT(_time) \
493 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
494 wait_queue_head_t _wait; \
495 init_waitqueue_head(&_wait); \
496 for (_i=0; _i<(_loop); _i++) \
497 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
500 typedef void (*TIMER_FUNCTION)(unsigned long);
502 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
504 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
505 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
509 #define BUILD_TIMER_FUNCTION(_func) \
510 void linux_##_func(unsigned long data) \
512 PRALINK_TIMER_STRUCT _pTimer = (PRALINK_TIMER_STRUCT)data; \
513 RT2870_TIMER_ENTRY *_pQNode; \
514 RTMP_ADAPTER *_pAd; \
516 _pTimer->handle = _func; \
517 _pAd = (RTMP_ADAPTER *)_pTimer->pAd; \
518 _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer); \
519 if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)) \
520 RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ); \
525 #define DECLARE_TIMER_FUNCTION(_func) \
526 void linux_##_func(unsigned long data)
528 #define GET_TIMER_FUNCTION(_func) \
531 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
532 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
533 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
534 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
535 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
537 DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
541 #ifdef CONFIG_STA_SUPPORT
542 DECLARE_TIMER_FUNCTION(BeaconTimeout);
543 DECLARE_TIMER_FUNCTION(ScanTimeout);
544 DECLARE_TIMER_FUNCTION(AuthTimeout);
545 DECLARE_TIMER_FUNCTION(AssocTimeout);
546 DECLARE_TIMER_FUNCTION(ReassocTimeout);
547 DECLARE_TIMER_FUNCTION(DisassocTimeout);
548 DECLARE_TIMER_FUNCTION(LinkDownExec);
549 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
550 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
551 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
552 DECLARE_TIMER_FUNCTION(RadioOnExec);
553 #endif // CONFIG_STA_SUPPORT //
555 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
560 * - convert internal rt packet to os packet or
561 * os packet to rt packet
563 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
564 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
566 #define GET_OS_PKT_DATAPTR(_pkt) \
567 (RTPKT_TO_OSPKT(_pkt)->data)
569 #define GET_OS_PKT_LEN(_pkt) \
570 (RTPKT_TO_OSPKT(_pkt)->len)
572 #define GET_OS_PKT_DATATAIL(_pkt) \
573 (RTPKT_TO_OSPKT(_pkt)->tail)
575 #define GET_OS_PKT_HEAD(_pkt) \
576 (RTPKT_TO_OSPKT(_pkt)->head)
578 #define GET_OS_PKT_END(_pkt) \
579 (RTPKT_TO_OSPKT(_pkt)->end)
581 #define GET_OS_PKT_NETDEV(_pkt) \
582 (RTPKT_TO_OSPKT(_pkt)->dev)
584 #define GET_OS_PKT_TYPE(_pkt) \
585 (RTPKT_TO_OSPKT(_pkt))
587 #define GET_OS_PKT_NEXT(_pkt) \
588 (RTPKT_TO_OSPKT(_pkt)->next)
591 #define OS_NTOHS(_Val) \
593 #define OS_HTONS(_Val) \
595 #define OS_NTOHL(_Val) \
597 #define OS_HTONL(_Val) \
600 /* statistics counter */
601 #define STATS_INC_RX_PACKETS(_pAd, _dev)
602 #define STATS_INC_TX_PACKETS(_pAd, _dev)
604 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
605 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
607 #define STATS_INC_RX_ERRORS(_pAd, _dev)
608 #define STATS_INC_TX_ERRORS(_pAd, _dev)
610 #define STATS_INC_RX_DROPPED(_pAd, _dev)
611 #define STATS_INC_TX_DROPPED(_pAd, _dev)
617 // check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
618 // ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
620 //#define RTMP_GET_PACKET_MR(_p) (RTPKT_TO_OSPKT(_p))
623 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
624 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
627 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
628 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
630 // 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.
631 //(this value also as MAC(on-chip WCID) table index)
632 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
633 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
634 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
636 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
637 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
638 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
640 // RTS/CTS-to-self protection method
641 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
642 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
643 // see RTMP_S(G)ET_PACKET_EMACTAB
646 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
647 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
649 // From which Interface
650 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
651 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
652 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
653 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
654 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
655 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
656 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
657 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
659 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
660 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
662 //#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
663 //#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) (RTPKT_TO_OSPKT(_p)->cb[8])
669 //#define RTMP_SET_PACKET_DHCP(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
670 //#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
673 // Sepcific Pakcet Type definition
675 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
677 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
678 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
679 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
680 #define RTMP_PACKET_SPECIFIC_WAI 0x08
681 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
682 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
685 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
688 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
691 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
693 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
695 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
698 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
701 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
703 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
705 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
708 #define RTMP_SET_PACKET_WAI(_p, _flg) \
711 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
713 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
715 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
717 #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))
720 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
723 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
725 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
727 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
730 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
733 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
735 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
738 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
741 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
744 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
746 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
749 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
754 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
755 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
756 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
758 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
759 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
762 #ifdef CONFIG_5VT_ENHANCE
763 #define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
767 #define NDIS_SET_PACKET_STATUS(_p, _status)
770 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
771 rt_get_sg_list_from_packet(_p, _sc)
774 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
775 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
776 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
777 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
778 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
781 #define RTMP_INC_REF(_A) 0
782 #define RTMP_DEC_REF(_A) 0
783 #define RTMP_GET_REF(_A) 0
789 * RTMP_GetPhysicalAddressLow(
790 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
792 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
796 * RTMP_GetPhysicalAddressHigh(
797 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
799 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
803 * RTMP_SetPhysicalAddressLow(
804 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
807 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
808 PhysicalAddress = Value;
812 * RTMP_SetPhysicalAddressHigh(
813 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
816 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
819 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
820 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
821 (PNDIS_PACKET)(pEntry)
823 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
824 (PQUEUE_ENTRY)(pPacket)
827 #ifndef CONTAINING_RECORD
828 #define CONTAINING_RECORD(address, type, field) \
829 ((type *)((PCHAR)(address) - offsetof(type, field)))
833 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
835 RTMPFreeNdisPacket(_pAd, _pPacket); \
839 #define SWITCH_PhyAB(_pAA, _pBB) \
841 ULONG AABasePaHigh; \
843 ULONG BBBasePaHigh; \
845 BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
846 BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
847 AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
848 AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
849 RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
850 RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
851 RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
852 RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
856 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
857 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
860 #define NdisAcquireSpinLock RTMP_SEM_LOCK
861 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
863 static inline void NdisGetSystemUpTime(ULONG *time)
868 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
869 #define QUEUE_ENTRY_TO_PKT(pEntry) \
870 ((PNDIS_PACKET) (pEntry))
872 int rt28xx_packet_xmit(struct sk_buff *skb);
876 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);