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>
48 #include <linux/spinlock.h>
49 #include <linux/init.h>
50 #include <linux/string.h>
51 #include <linux/timer.h>
52 #include <linux/errno.h>
53 #include <linux/slab.h>
54 #include <linux/interrupt.h>
55 #include <linux/pci.h>
56 #include <linux/netdevice.h>
57 #include <linux/etherdevice.h>
58 #include <linux/skbuff.h>
59 #include <linux/ethtool.h>
60 #include <linux/wireless.h>
61 #include <linux/proc_fs.h>
62 #include <linux/delay.h>
63 #include <linux/if_arp.h>
64 #include <linux/ctype.h>
65 #include <linux/vmalloc.h>
68 #include <linux/wireless.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", __FUNCTION__)); \
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 THREAD_PID_INIT_VALUE NULL
170 #define GET_PID(_v) find_get_pid(_v)
171 #define GET_PID_NUMBER(_v) pid_nr(_v)
172 #define CHECK_PID_LEGALITY(_pid) if (pid_nr(_pid) >= 0)
173 #define KILL_THREAD_PID(_A, _B, _C) kill_pid(_A, _B, _C)
175 typedef pid_t THREAD_PID
;
176 #define THREAD_PID_INIT_VALUE -1
177 #define GET_PID(_v) _v
178 #define GET_PID_NUMBER(_v) _v
179 #define CHECK_PID_LEGALITY(_pid) if (_pid >= 0)
180 #define KILL_THREAD_PID(_A, _B, _C) kill_proc(_A, _B, _C)
192 struct usb_device
*pUsb_Dev
;
194 THREAD_PID MLMEThr_pid
;
195 THREAD_PID RTUSBCmdThr_pid
;
196 THREAD_PID TimerQThr_pid
;
199 struct tasklet_struct rx_done_task
;
200 struct tasklet_struct mgmt_dma_done_task
;
201 struct tasklet_struct ac0_dma_done_task
;
202 struct tasklet_struct ac1_dma_done_task
;
203 struct tasklet_struct ac2_dma_done_task
;
204 struct tasklet_struct ac3_dma_done_task
;
205 struct tasklet_struct hcca_dma_done_task
;
206 struct tasklet_struct tbtt_task
;
208 struct tasklet_struct null_frame_complete_task
;
209 struct tasklet_struct rts_frame_complete_task
;
210 struct tasklet_struct pspoll_frame_complete_task
;
214 unsigned long apd_pid
; //802.1x daemon pid
219 typedef struct _VIRTUAL_ADAPTER
221 struct net_device
*RtmpDev
;
222 struct net_device
*VirtualDev
;
223 } VIRTUAL_ADAPTER
, PVIRTUAL_ADAPTER
;
230 printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
234 typedef struct os_cookie
* POS_COOKIE
;
235 typedef struct pci_dev
* PPCI_DEV
;
236 typedef struct net_device
* PNET_DEV
;
237 typedef void * PNDIS_PACKET
;
238 typedef char NDIS_PACKET
;
239 typedef PNDIS_PACKET
* PPNDIS_PACKET
;
240 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS
;
241 typedef dma_addr_t
* PNDIS_PHYSICAL_ADDRESS
;
242 //typedef struct timer_list RALINK_TIMER_STRUCT;
243 //typedef struct timer_list * PRALINK_TIMER_STRUCT;
244 //typedef struct os_lock NDIS_SPIN_LOCK;
245 typedef spinlock_t NDIS_SPIN_LOCK
;
246 typedef struct timer_list NDIS_MINIPORT_TIMER
;
247 typedef void * NDIS_HANDLE
;
248 typedef char * PNDIS_BUFFER
;
252 void hex_dump(char *str
, unsigned char *pSrcBufVA
, unsigned int SrcBufLen
);
254 dma_addr_t
linux_pci_map_single(void *handle
, void *ptr
, size_t size
, int sd_idx
, int direction
);
255 void linux_pci_unmap_single(void *handle
, dma_addr_t dma_addr
, size_t size
, int direction
);
258 ////////////////////////////////////////
260 /////////////////////////////////////////
261 #define PKTSRC_NDIS 0x7f
262 #define PKTSRC_DRIVER 0x0f
263 #define PRINT_MAC(addr) \
264 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
267 #define RT2860_PCI_DEVICE_ID 0x0601
271 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
273 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
277 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
278 dma_cache_wback(_ptr, _size)
281 //////////////////////////////////////////
283 //////////////////////////////////////////
286 #define NdisMIndicateStatus(_w, _x, _y, _z)
288 typedef struct timer_list RTMP_OS_TIMER
;
291 /* ----------------- Timer Related MARCO ---------------*/
292 // In RT2870, we have a lot of timer functions and will read/write register, it's
293 // not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
294 // to ctrl pipe). So we need a wrapper function to take care it.
296 typedef VOID (*RT2870_TIMER_HANDLE
)(
297 IN PVOID SystemSpecific1
,
298 IN PVOID FunctionContext
,
299 IN PVOID SystemSpecific2
,
300 IN PVOID SystemSpecific3
);
304 typedef struct _RALINK_TIMER_STRUCT
{
305 RTMP_OS_TIMER TimerObj
; // Ndis Timer object
306 BOOLEAN Valid
; // Set to True when call RTMPInitTimer
307 BOOLEAN State
; // True if timer cancelled
308 BOOLEAN PeriodicType
; // True if timer is periodic timer
309 BOOLEAN Repeat
; // True if periodic timer
310 ULONG TimerValue
; // Timer value in milliseconds
311 ULONG cookie
; // os specific object
313 RT2870_TIMER_HANDLE handle
;
316 } RALINK_TIMER_STRUCT
, *PRALINK_TIMER_STRUCT
;
321 typedef enum _RT2870_KERNEL_THREAD_STATUS_
323 RT2870_THREAD_UNKNOWN
= 0,
324 RT2870_THREAD_INITED
= 1,
325 RT2870_THREAD_RUNNING
= 2,
326 RT2870_THREAD_STOPED
= 4,
327 }RT2870_KERNEL_THREAD_STATUS
;
329 #define RT2870_THREAD_CAN_DO_INSERT (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
331 typedef struct _RT2870_TIMER_ENTRY_
333 RALINK_TIMER_STRUCT
*pRaTimer
;
334 struct _RT2870_TIMER_ENTRY_
*pNext
;
338 #define TIMER_QUEUE_SIZE_MAX 128
339 typedef struct _RT2870_TIMER_QUEUE_
342 //wait_queue_head_t timerWaitQ;
345 RT2870_TIMER_ENTRY
*pQPollFreeList
;
346 RT2870_TIMER_ENTRY
*pQHead
;
347 RT2870_TIMER_ENTRY
*pQTail
;
355 // MACRO for debugging information
359 extern ULONG RTDebugLevel
;
361 #define DBGPRINT_RAW(Level, Fmt) \
363 if (Level <= RTDebugLevel) \
369 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
372 #define DBGPRINT_ERR(Fmt) \
374 printk("ERROR!!! "); \
378 #define DBGPRINT_S(Status, Fmt) \
385 #define DBGPRINT(Level, Fmt)
386 #define DBGPRINT_RAW(Level, Fmt)
387 #define DBGPRINT_S(Status, Fmt)
388 #define DBGPRINT_ERR(Fmt)
393 // spin_lock enhanced for Nested spin lock
395 #define NdisAllocateSpinLock(__lock) \
397 spin_lock_init((spinlock_t *)(__lock)); \
400 #define NdisFreeSpinLock(lock) \
405 #define RTMP_SEM_LOCK(__lock) \
407 spin_lock_bh((spinlock_t *)(__lock)); \
410 #define RTMP_SEM_UNLOCK(__lock) \
412 spin_unlock_bh((spinlock_t *)(__lock)); \
415 #if 0 // sample, IRQ LOCK
416 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
418 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
419 pAd->irq_disabled |= 1; \
422 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
424 pAd->irq_disabled &= 0; \
425 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
429 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
430 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
433 spin_lock_bh((spinlock_t *)(__lock)); \
434 pAd->irq_disabled |= 1; \
437 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
439 pAd->irq_disabled &= 0; \
440 spin_unlock_bh((spinlock_t *)(__lock)); \
443 #define RTMP_INT_LOCK(__lock, __irqflags) \
445 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
448 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
450 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
457 //Patch for ASIC turst read/write bug, needs to remove after metel fix
458 #define RTMP_IO_READ32(_A, _R, _pV) \
459 RTUSBReadMACRegister(_A, _R, _pV)
461 #define RTMP_IO_READ8(_A, _R, _pV) \
465 #define RTMP_IO_WRITE32(_A, _R, _V) \
466 RTUSBWriteMACRegister(_A, _R, _V)
469 #define RTMP_IO_WRITE8(_A, _R, _V) \
472 RTUSBSingleWrite(_A, _R, _Val); \
476 #define RTMP_IO_WRITE16(_A, _R, _V) \
478 RTUSBSingleWrite(_A, _R, _V); \
482 #ifndef wait_event_interruptible_timeout
483 #define __wait_event_interruptible_timeout(wq, condition, ret) \
485 wait_queue_t __wait; \
486 init_waitqueue_entry(&__wait, current); \
487 add_wait_queue(&wq, &__wait); \
489 set_current_state(TASK_INTERRUPTIBLE); \
492 if (!signal_pending(current)) { \
493 ret = schedule_timeout(ret); \
498 ret = -ERESTARTSYS; \
501 current->state = TASK_RUNNING; \
502 remove_wait_queue(&wq, &__wait); \
505 #define wait_event_interruptible_timeout(wq, condition, timeout) \
507 long __ret = timeout; \
509 __wait_event_interruptible_timeout(wq, condition, __ret); \
514 #define OS_WAIT(_time) \
516 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
517 wait_queue_head_t _wait; \
518 init_waitqueue_head(&_wait); \
519 for (_i=0; _i<(_loop); _i++) \
520 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
523 typedef void (*TIMER_FUNCTION
)(unsigned long);
525 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
527 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
528 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
532 #define BUILD_TIMER_FUNCTION(_func) \
533 void linux_##_func(unsigned long data) \
535 PRALINK_TIMER_STRUCT _pTimer = (PRALINK_TIMER_STRUCT)data; \
536 RT2870_TIMER_ENTRY *_pQNode; \
537 RTMP_ADAPTER *_pAd; \
539 _pTimer->handle = _func; \
540 _pAd = (RTMP_ADAPTER *)_pTimer->pAd; \
541 _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer); \
542 if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)) \
543 RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ); \
548 #define DECLARE_TIMER_FUNCTION(_func) \
549 void linux_##_func(unsigned long data)
551 #define GET_TIMER_FUNCTION(_func) \
554 DECLARE_TIMER_FUNCTION(MlmePeriodicExec
);
555 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec
);
556 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout
);
557 DECLARE_TIMER_FUNCTION(APSDPeriodicExec
);
558 DECLARE_TIMER_FUNCTION(AsicRfTuningExec
);
560 DECLARE_TIMER_FUNCTION(BeaconUpdateExec
);
564 #ifdef CONFIG_STA_SUPPORT
565 DECLARE_TIMER_FUNCTION(BeaconTimeout
);
566 DECLARE_TIMER_FUNCTION(ScanTimeout
);
567 DECLARE_TIMER_FUNCTION(AuthTimeout
);
568 DECLARE_TIMER_FUNCTION(AssocTimeout
);
569 DECLARE_TIMER_FUNCTION(ReassocTimeout
);
570 DECLARE_TIMER_FUNCTION(DisassocTimeout
);
571 DECLARE_TIMER_FUNCTION(LinkDownExec
);
573 DECLARE_TIMER_FUNCTION(LeapAuthTimeout
);
575 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec
);
576 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc
);
577 DECLARE_TIMER_FUNCTION(PsPollWakeExec
);
578 DECLARE_TIMER_FUNCTION(RadioOnExec
);
580 #ifdef QOS_DLS_SUPPORT
581 DECLARE_TIMER_FUNCTION(DlsTimeoutAction
);
582 #endif // QOS_DLS_SUPPORT //
583 #endif // CONFIG_STA_SUPPORT //
585 void RTMP_GetCurrentSystemTime(LARGE_INTEGER
*time
);
590 * - convert internal rt packet to os packet or
591 * os packet to rt packet
593 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
594 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
596 #define GET_OS_PKT_DATAPTR(_pkt) \
597 (RTPKT_TO_OSPKT(_pkt)->data)
599 #define GET_OS_PKT_LEN(_pkt) \
600 (RTPKT_TO_OSPKT(_pkt)->len)
602 #define GET_OS_PKT_DATATAIL(_pkt) \
603 (RTPKT_TO_OSPKT(_pkt)->tail)
605 #define GET_OS_PKT_HEAD(_pkt) \
606 (RTPKT_TO_OSPKT(_pkt)->head)
608 #define GET_OS_PKT_END(_pkt) \
609 (RTPKT_TO_OSPKT(_pkt)->end)
611 #define GET_OS_PKT_NETDEV(_pkt) \
612 (RTPKT_TO_OSPKT(_pkt)->dev)
614 #define GET_OS_PKT_TYPE(_pkt) \
615 (RTPKT_TO_OSPKT(_pkt))
617 #define GET_OS_PKT_NEXT(_pkt) \
618 (RTPKT_TO_OSPKT(_pkt)->next)
621 #define OS_NTOHS(_Val) \
623 #define OS_HTONS(_Val) \
625 #define OS_NTOHL(_Val) \
627 #define OS_HTONL(_Val) \
630 /* statistics counter */
631 #define STATS_INC_RX_PACKETS(_pAd, _dev)
632 #define STATS_INC_TX_PACKETS(_pAd, _dev)
634 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
635 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
637 #define STATS_INC_RX_ERRORS(_pAd, _dev)
638 #define STATS_INC_TX_ERRORS(_pAd, _dev)
640 #define STATS_INC_RX_DROPPED(_pAd, _dev)
641 #define STATS_INC_TX_DROPPED(_pAd, _dev)
647 // check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
648 // ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
650 //#define RTMP_GET_PACKET_MR(_p) (RTPKT_TO_OSPKT(_p))
653 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
654 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
657 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
658 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
660 // 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.
661 //(this value also as MAC(on-chip WCID) table index)
662 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
663 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
664 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
666 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
667 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
668 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
670 // RTS/CTS-to-self protection method
671 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
672 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
673 // see RTMP_S(G)ET_PACKET_EMACTAB
676 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
677 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
679 // From which Interface
680 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
681 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
682 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
683 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
684 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
685 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
686 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
687 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
689 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
690 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
692 //#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
693 //#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) (RTPKT_TO_OSPKT(_p)->cb[8])
699 //#define RTMP_SET_PACKET_DHCP(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
700 //#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
703 // Sepcific Pakcet Type definition
705 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
707 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
708 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
709 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
710 #define RTMP_PACKET_SPECIFIC_WAI 0x08
711 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
712 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
715 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
718 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
721 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
723 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
725 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
728 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
731 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
733 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
735 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
738 #define RTMP_SET_PACKET_WAI(_p, _flg) \
741 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
743 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
745 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
747 #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))
750 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
753 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
755 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
757 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
760 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
763 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
765 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
768 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
771 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
774 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
776 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
779 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
784 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
785 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
786 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
788 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
789 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
792 #ifdef CONFIG_5VT_ENHANCE
793 #define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
797 #define NDIS_SET_PACKET_STATUS(_p, _status)
800 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
801 rt_get_sg_list_from_packet(_p, _sc)
804 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
805 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
806 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
807 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
808 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
811 #define RTMP_INC_REF(_A) 0
812 #define RTMP_DEC_REF(_A) 0
813 #define RTMP_GET_REF(_A) 0
819 * RTMP_GetPhysicalAddressLow(
820 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
822 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
826 * RTMP_GetPhysicalAddressHigh(
827 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
829 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
833 * RTMP_SetPhysicalAddressLow(
834 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
837 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
838 PhysicalAddress = Value;
842 * RTMP_SetPhysicalAddressHigh(
843 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
846 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
849 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
850 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
851 (PNDIS_PACKET)(pEntry)
853 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
854 (PQUEUE_ENTRY)(pPacket)
857 #ifndef CONTAINING_RECORD
858 #define CONTAINING_RECORD(address, type, field) \
859 ((type *)((PCHAR)(address) - offsetof(type, field)))
863 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
865 RTMPFreeNdisPacket(_pAd, _pPacket); \
869 #define SWITCH_PhyAB(_pAA, _pBB) \
871 ULONG AABasePaHigh; \
873 ULONG BBBasePaHigh; \
875 BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
876 BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
877 AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
878 AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
879 RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
880 RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
881 RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
882 RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
886 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
887 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
890 #define NdisAcquireSpinLock RTMP_SEM_LOCK
891 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
893 static inline void NdisGetSystemUpTime(ULONG
*time
)
898 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
899 #define QUEUE_ENTRY_TO_PKT(pEntry) \
900 ((PNDIS_PACKET) (pEntry))
902 int rt28xx_packet_xmit(struct sk_buff
*skb
);
906 void rtmp_os_thread_init(PUCHAR pThreadName
, PVOID pNotify
);