rtw_recv.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #ifndef _RTW_RECV_H_
  21. #define _RTW_RECV_H_
  22. #ifdef PLATFORM_OS_XP
  23. #ifdef CONFIG_SDIO_HCI
  24. #define NR_RECVBUFF 1024//512//128
  25. #else
  26. #define NR_RECVBUFF (16)
  27. #endif
  28. #elif defined(PLATFORM_OS_CE)
  29. #ifdef CONFIG_SDIO_HCI
  30. #define NR_RECVBUFF (128)
  31. #else
  32. #define NR_RECVBUFF (4)
  33. #endif
  34. #else //PLATFORM_LINUX /PLATFORM_BSD
  35. #ifdef CONFIG_SINGLE_RECV_BUF
  36. #define NR_RECVBUFF (1)
  37. #else
  38. #if defined(CONFIG_GSPI_HCI)
  39. #define NR_RECVBUFF (32)
  40. #elif defined(CONFIG_SDIO_HCI)
  41. #define NR_RECVBUFF (8)
  42. #else
  43. #define NR_RECVBUFF (4)
  44. #endif
  45. #endif //CONFIG_SINGLE_RECV_BUF
  46. #define NR_PREALLOC_RECV_SKB (8)
  47. #endif
  48. #define NR_RECVFRAME 256
  49. #define RXFRAME_ALIGN 8
  50. #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
  51. #define DRVINFO_SZ 4 // unit is 8bytes
  52. #define MAX_RXFRAME_CNT 512
  53. #define MAX_RX_NUMBLKS (32)
  54. #define RECVFRAME_HDR_ALIGN 128
  55. #define PHY_RSSI_SLID_WIN_MAX 100
  56. #define PHY_LINKQUALITY_SLID_WIN_MAX 20
  57. #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
  58. #define RX_MPDU_QUEUE 0
  59. #define RX_CMD_QUEUE 1
  60. #define RX_MAX_QUEUE 2
  61. static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
  62. static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
  63. static u8 SNAP_ETH_TYPE_APPLETALK_DDP[2] = {0x80, 0x9b};
  64. static u8 SNAP_ETH_TYPE_TDLS[2] = {0x89, 0x0d};
  65. static u8 SNAP_HDR_APPLETALK_DDP[3] = {0x08, 0x00, 0x07}; // Datagram Delivery Protocol
  66. static u8 oui_8021h[] = {0x00, 0x00, 0xf8};
  67. static u8 oui_rfc1042[]= {0x00,0x00,0x00};
  68. #define MAX_SUBFRAME_COUNT 64
  69. static u8 rtw_rfc1042_header[] =
  70. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  71. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  72. static u8 rtw_bridge_tunnel_header[] =
  73. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  74. //for Rx reordering buffer control
  75. struct recv_reorder_ctrl
  76. {
  77. _adapter *padapter;
  78. u8 enable;
  79. u16 indicate_seq;//=wstart_b, init_value=0xffff
  80. u16 wend_b;
  81. u8 wsize_b;
  82. _queue pending_recvframe_queue;
  83. _timer reordering_ctrl_timer;
  84. };
  85. struct stainfo_rxcache {
  86. u16 tid_rxseq[16];
  87. /*
  88. unsigned short tid0_rxseq;
  89. unsigned short tid1_rxseq;
  90. unsigned short tid2_rxseq;
  91. unsigned short tid3_rxseq;
  92. unsigned short tid4_rxseq;
  93. unsigned short tid5_rxseq;
  94. unsigned short tid6_rxseq;
  95. unsigned short tid7_rxseq;
  96. unsigned short tid8_rxseq;
  97. unsigned short tid9_rxseq;
  98. unsigned short tid10_rxseq;
  99. unsigned short tid11_rxseq;
  100. unsigned short tid12_rxseq;
  101. unsigned short tid13_rxseq;
  102. unsigned short tid14_rxseq;
  103. unsigned short tid15_rxseq;
  104. */
  105. };
  106. struct smooth_rssi_data {
  107. u32 elements[100]; //array to store values
  108. u32 index; //index to current array to store
  109. u32 total_num; //num of valid elements
  110. u32 total_val; //sum of valid elements
  111. };
  112. struct signal_stat {
  113. u8 update_req; //used to indicate
  114. u8 avg_val; //avg of valid elements
  115. u32 total_num; //num of valid elements
  116. u32 total_val; //sum of valid elements
  117. };
  118. struct phy_info
  119. {
  120. u8 RxPWDBAll;
  121. u8 SignalQuality; // in 0-100 index.
  122. s8 RxMIMOSignalQuality[4]; //per-path's EVM
  123. u8 RxMIMOEVMdbm[4]; //per-path's EVM dbm
  124. u8 RxMIMOSignalStrength[4];// in 0~100 index
  125. u16 Cfo_short[4]; // per-path's Cfo_short
  126. u16 Cfo_tail[4]; // per-path's Cfo_tail
  127. s8 RxPower; // in dBm Translate from PWdB
  128. s8 RecvSignalPower;// Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures.
  129. u8 BTRxRSSIPercentage;
  130. u8 SignalStrength; // in 0-100 index.
  131. u8 RxPwr[4]; //per-path's pwdb
  132. u8 RxSNR[4]; //per-path's SNR
  133. u8 BandWidth;
  134. u8 btCoexPwrAdjust;
  135. };
  136. struct rx_pkt_attrib {
  137. u16 pkt_len;
  138. u8 physt;
  139. u8 drvinfo_sz;
  140. u8 shift_sz;
  141. u8 hdrlen; //the WLAN Header Len
  142. u8 to_fr_ds;
  143. u8 amsdu;
  144. u8 qos;
  145. u8 priority;
  146. u8 pw_save;
  147. u8 mdata;
  148. u16 seq_num;
  149. u8 frag_num;
  150. u8 mfrag;
  151. u8 order;
  152. u8 privacy; //in frame_ctrl field
  153. u8 bdecrypted;
  154. u8 encrypt; //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
  155. u8 iv_len;
  156. u8 icv_len;
  157. u8 crc_err;
  158. u8 icv_err;
  159. u16 eth_type;
  160. u8 dst[ETH_ALEN];
  161. u8 src[ETH_ALEN];
  162. u8 ta[ETH_ALEN];
  163. u8 ra[ETH_ALEN];
  164. u8 bssid[ETH_ALEN];
  165. u8 ack_policy;
  166. //#ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
  167. u8 tcpchk_valid; // 0: invalid, 1: valid
  168. u8 ip_chkrpt; //0: incorrect, 1: correct
  169. u8 tcp_chkrpt; //0: incorrect, 1: correct
  170. //#endif
  171. u8 key_index;
  172. u8 data_rate;
  173. u8 sgi;
  174. u8 pkt_rpt_type;
  175. u32 MacIDValidEntry[2]; // 64 bits present 64 entry.
  176. /*
  177. u8 signal_qual;
  178. s8 rx_mimo_signal_qual[2];
  179. u8 signal_strength;
  180. u32 RxPWDBAll;
  181. s32 RecvSignalPower;
  182. */
  183. struct phy_info phy_info;
  184. };
  185. //These definition is used for Rx packet reordering.
  186. #define SN_LESS(a, b) (((a-b)&0x800)!=0)
  187. #define SN_EQUAL(a, b) (a == b)
  188. //#define REORDER_WIN_SIZE 128
  189. //#define REORDER_ENTRY_NUM 128
  190. #define REORDER_WAIT_TIME (50) // (ms)
  191. #define RECVBUFF_ALIGN_SZ 8
  192. #define RXDESC_SIZE 24
  193. #define RXDESC_OFFSET RXDESC_SIZE
  194. struct recv_stat
  195. {
  196. unsigned int rxdw0;
  197. unsigned int rxdw1;
  198. unsigned int rxdw2;
  199. unsigned int rxdw3;
  200. unsigned int rxdw4;
  201. unsigned int rxdw5;
  202. #ifdef CONFIG_PCI_HCI
  203. unsigned int rxdw6;
  204. unsigned int rxdw7;
  205. #endif
  206. };
  207. #define EOR BIT(30)
  208. #ifdef CONFIG_PCI_HCI
  209. #define PCI_MAX_RX_QUEUE 1// MSDU packet queue, Rx Command Queue
  210. #define PCI_MAX_RX_COUNT 128
  211. struct rtw_rx_ring {
  212. struct recv_stat *desc;
  213. dma_addr_t dma;
  214. unsigned int idx;
  215. struct sk_buff *rx_buf[PCI_MAX_RX_COUNT];
  216. };
  217. #endif
  218. /*
  219. accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
  220. ; halt(passive) ;
  221. using enter_critical section to protect
  222. */
  223. struct recv_priv
  224. {
  225. _lock lock;
  226. #ifdef CONFIG_RECV_THREAD_MODE
  227. _sema recv_sema;
  228. _sema terminate_recvthread_sema;
  229. #endif
  230. //_queue blk_strms[MAX_RX_NUMBLKS]; // keeping the block ack frame until return ack
  231. _queue free_recv_queue;
  232. _queue recv_pending_queue;
  233. _queue uc_swdec_pending_queue;
  234. u8 *pallocated_frame_buf;
  235. u8 *precv_frame_buf;
  236. uint free_recvframe_cnt;
  237. _adapter *adapter;
  238. #ifdef PLATFORM_WINDOWS
  239. _nic_hdl RxPktPoolHdl;
  240. _nic_hdl RxBufPoolHdl;
  241. #ifdef PLATFORM_OS_XP
  242. PMDL pbytecnt_mdl;
  243. #endif
  244. uint counter; //record the number that up-layer will return to drv; only when counter==0 can we release recv_priv
  245. NDIS_EVENT recv_resource_evt ;
  246. #endif
  247. u32 bIsAnyNonBEPkts;
  248. u64 rx_bytes;
  249. u64 rx_pkts;
  250. u64 rx_drop;
  251. u64 last_rx_bytes;
  252. uint rx_icv_err;
  253. uint rx_largepacket_crcerr;
  254. uint rx_smallpacket_crcerr;
  255. uint rx_middlepacket_crcerr;
  256. #ifdef CONFIG_USB_HCI
  257. //u8 *pallocated_urb_buf;
  258. _sema allrxreturnevt;
  259. uint ff_hwaddr;
  260. u8 rx_pending_cnt;
  261. #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
  262. #ifdef PLATFORM_LINUX
  263. PURB int_in_urb;
  264. #endif
  265. u8 *int_in_buf;
  266. #endif //CONFIG_USB_INTERRUPT_IN_PIPE
  267. #endif
  268. #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
  269. #ifdef PLATFORM_FREEBSD
  270. struct task irq_prepare_beacon_tasklet;
  271. struct task recv_tasklet;
  272. #else //PLATFORM_FREEBSD
  273. struct tasklet_struct irq_prepare_beacon_tasklet;
  274. struct tasklet_struct recv_tasklet;
  275. #endif //PLATFORM_FREEBSD
  276. struct sk_buff_head free_recv_skb_queue;
  277. struct sk_buff_head rx_skb_queue;
  278. #ifdef CONFIG_RX_INDICATE_QUEUE
  279. struct task rx_indicate_tasklet;
  280. struct ifqueue rx_indicate_queue;
  281. #endif // CONFIG_RX_INDICATE_QUEUE
  282. #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
  283. _queue recv_buf_pending_queue;
  284. #endif // CONFIG_USE_USB_BUFFER_ALLOC_RX
  285. #endif //defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
  286. u8 *pallocated_recv_buf;
  287. u8 *precv_buf; // 4 alignment
  288. _queue free_recv_buf_queue;
  289. u32 free_recv_buf_queue_cnt;
  290. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  291. _queue recv_buf_pending_queue;
  292. #endif
  293. #ifdef CONFIG_PCI_HCI
  294. // Rx
  295. struct rtw_rx_ring rx_ring[PCI_MAX_RX_QUEUE];
  296. int rxringcount;
  297. u16 rxbuffersize;
  298. #endif
  299. //For display the phy informatiom
  300. u8 is_signal_dbg; // for debug
  301. u8 signal_strength_dbg; // for debug
  302. s8 rssi;
  303. s8 rxpwdb;
  304. u8 signal_strength;
  305. u8 signal_qual;
  306. u8 noise;
  307. int RxSNRdB[2];
  308. s8 RxRssi[2];
  309. int FalseAlmCnt_all;
  310. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  311. _timer signal_stat_timer;
  312. u32 signal_stat_sampling_interval;
  313. //u32 signal_stat_converging_constant;
  314. struct signal_stat signal_qual_data;
  315. struct signal_stat signal_strength_data;
  316. #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
  317. struct smooth_rssi_data signal_qual_data;
  318. struct smooth_rssi_data signal_strength_data;
  319. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  320. };
  321. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  322. #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
  323. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  324. struct sta_recv_priv {
  325. _lock lock;
  326. sint option;
  327. //_queue blk_strms[MAX_RX_NUMBLKS];
  328. _queue defrag_q; //keeping the fragment frame until defrag
  329. struct stainfo_rxcache rxcache;
  330. //uint sta_rx_bytes;
  331. //uint sta_rx_pkts;
  332. //uint sta_rx_fail;
  333. };
  334. struct recv_buf
  335. {
  336. _list list;
  337. _lock recvbuf_lock;
  338. u32 ref_cnt;
  339. PADAPTER adapter;
  340. u8 *pbuf;
  341. u8 *pallocated_buf;
  342. u32 len;
  343. u8 *phead;
  344. u8 *pdata;
  345. u8 *ptail;
  346. u8 *pend;
  347. #ifdef CONFIG_USB_HCI
  348. #if defined(PLATFORM_OS_XP)||defined(PLATFORM_LINUX)||defined(PLATFORM_FREEBSD)
  349. PURB purb;
  350. dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */
  351. u32 alloc_sz;
  352. #endif
  353. #ifdef PLATFORM_OS_XP
  354. PIRP pirp;
  355. #endif
  356. #ifdef PLATFORM_OS_CE
  357. USB_TRANSFER usb_transfer_read_port;
  358. #endif
  359. u8 irp_pending;
  360. int transfer_len;
  361. #endif
  362. #ifdef PLATFORM_LINUX
  363. _pkt *pskb;
  364. u8 reuse;
  365. #endif
  366. #ifdef PLATFORM_FREEBSD //skb solution
  367. struct sk_buff *pskb;
  368. u8 reuse;
  369. #endif //PLATFORM_FREEBSD //skb solution
  370. };
  371. /*
  372. head ----->
  373. data ----->
  374. payload
  375. tail ----->
  376. end ----->
  377. len = (unsigned int )(tail - data);
  378. */
  379. struct recv_frame_hdr
  380. {
  381. _list list;
  382. #ifndef CONFIG_BSD_RX_USE_MBUF
  383. struct sk_buff *pkt;
  384. struct sk_buff *pkt_newalloc;
  385. #else // CONFIG_BSD_RX_USE_MBUF
  386. _pkt *pkt;
  387. _pkt *pkt_newalloc;
  388. #endif // CONFIG_BSD_RX_USE_MBUF
  389. _adapter *adapter;
  390. u8 fragcnt;
  391. int frame_tag;
  392. struct rx_pkt_attrib attrib;
  393. uint len;
  394. u8 *rx_head;
  395. u8 *rx_data;
  396. u8 *rx_tail;
  397. u8 *rx_end;
  398. void *precvbuf;
  399. //
  400. struct sta_info *psta;
  401. //for A-MPDU Rx reordering buffer control
  402. struct recv_reorder_ctrl *preorder_ctrl;
  403. #ifdef CONFIG_WAPI_SUPPORT
  404. u8 UserPriority;
  405. u8 WapiTempPN[16];
  406. u8 WapiSrcAddr[6];
  407. u8 bWapiCheckPNInDecrypt;
  408. u8 bIsWaiPacket;
  409. #endif
  410. };
  411. union recv_frame{
  412. union{
  413. _list list;
  414. struct recv_frame_hdr hdr;
  415. uint mem[RECVFRAME_HDR_ALIGN>>2];
  416. }u;
  417. //uint mem[MAX_RXSZ>>2];
  418. };
  419. typedef enum _RX_PACKET_TYPE{
  420. NORMAL_RX,//Normal rx packet
  421. TX_REPORT1,//CCX
  422. TX_REPORT2,//TX RPT
  423. HIS_REPORT,// USB HISR RPT
  424. C2H_PACKET
  425. }RX_PACKET_TYPE, *PRX_PACKET_TYPE;
  426. extern union recv_frame *_rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue
  427. extern union recv_frame *rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue
  428. extern void rtw_init_recvframe(union recv_frame *precvframe ,struct recv_priv *precvpriv);
  429. extern int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
  430. #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
  431. extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
  432. extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
  433. extern void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue);
  434. u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
  435. sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
  436. sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
  437. struct recv_buf *rtw_dequeue_recvbuf (_queue *queue);
  438. void rtw_reordering_ctrl_timeout_handler(void *pcontext);
  439. __inline static u8 *get_rxmem(union recv_frame *precvframe)
  440. {
  441. //always return rx_head...
  442. if(precvframe==NULL)
  443. return NULL;
  444. return precvframe->u.hdr.rx_head;
  445. }
  446. __inline static u8 *get_rx_status(union recv_frame *precvframe)
  447. {
  448. return get_rxmem(precvframe);
  449. }
  450. __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
  451. {
  452. //alwasy return rx_data
  453. if(precvframe==NULL)
  454. return NULL;
  455. return precvframe->u.hdr.rx_data;
  456. }
  457. __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
  458. {
  459. // append data before rx_data
  460. /* add data to the start of recv_frame
  461. *
  462. * This function extends the used data area of the recv_frame at the buffer
  463. * start. rx_data must be still larger than rx_head, after pushing.
  464. */
  465. if(precvframe==NULL)
  466. return NULL;
  467. precvframe->u.hdr.rx_data -= sz ;
  468. if( precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head )
  469. {
  470. precvframe->u.hdr.rx_data += sz ;
  471. return NULL;
  472. }
  473. precvframe->u.hdr.len +=sz;
  474. return precvframe->u.hdr.rx_data;
  475. }
  476. __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
  477. {
  478. // rx_data += sz; move rx_data sz bytes hereafter
  479. //used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller
  480. if(precvframe==NULL)
  481. return NULL;
  482. precvframe->u.hdr.rx_data += sz;
  483. if(precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
  484. {
  485. precvframe->u.hdr.rx_data -= sz;
  486. return NULL;
  487. }
  488. precvframe->u.hdr.len -=sz;
  489. return precvframe->u.hdr.rx_data;
  490. }
  491. __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
  492. {
  493. // rx_tai += sz; move rx_tail sz bytes hereafter
  494. //used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller
  495. //after putting, rx_tail must be still larger than rx_end.
  496. unsigned char * prev_rx_tail;
  497. if(precvframe==NULL)
  498. return NULL;
  499. prev_rx_tail = precvframe->u.hdr.rx_tail;
  500. precvframe->u.hdr.rx_tail += sz;
  501. if(precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
  502. {
  503. precvframe->u.hdr.rx_tail -= sz;
  504. return NULL;
  505. }
  506. precvframe->u.hdr.len +=sz;
  507. return precvframe->u.hdr.rx_tail;
  508. }
  509. __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
  510. {
  511. // rmv data from rx_tail (by yitsen)
  512. //used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller
  513. //after pulling, rx_end must be still larger than rx_data.
  514. if(precvframe==NULL)
  515. return NULL;
  516. precvframe->u.hdr.rx_tail -= sz;
  517. if(precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
  518. {
  519. precvframe->u.hdr.rx_tail += sz;
  520. return NULL;
  521. }
  522. precvframe->u.hdr.len -=sz;
  523. return precvframe->u.hdr.rx_tail;
  524. }
  525. __inline static _buffer * get_rxbuf_desc(union recv_frame *precvframe)
  526. {
  527. _buffer * buf_desc;
  528. if(precvframe==NULL)
  529. return NULL;
  530. #ifdef PLATFORM_WINDOWS
  531. NdisQueryPacket(precvframe->u.hdr.pkt, NULL, NULL, &buf_desc, NULL);
  532. #endif
  533. return buf_desc;
  534. }
  535. __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
  536. {
  537. //due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame
  538. //from any given member of recv_frame.
  539. // rxmem indicates the any member/address in recv_frame
  540. return (union recv_frame*)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
  541. }
  542. __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
  543. {
  544. u8 * buf_star;
  545. union recv_frame * precv_frame;
  546. #ifdef PLATFORM_WINDOWS
  547. _buffer * buf_desc;
  548. uint len;
  549. NdisQueryPacket(pkt, NULL, NULL, &buf_desc, &len);
  550. NdisQueryBufferSafe(buf_desc, &buf_star, &len, HighPagePriority);
  551. #endif
  552. precv_frame = rxmem_to_recvframe((unsigned char*)buf_star);
  553. return precv_frame;
  554. }
  555. __inline static u8 *pkt_to_recvmem(_pkt *pkt)
  556. {
  557. // return the rx_head
  558. union recv_frame * precv_frame = pkt_to_recvframe(pkt);
  559. return precv_frame->u.hdr.rx_head;
  560. }
  561. __inline static u8 *pkt_to_recvdata(_pkt *pkt)
  562. {
  563. // return the rx_data
  564. union recv_frame * precv_frame =pkt_to_recvframe(pkt);
  565. return precv_frame->u.hdr.rx_data;
  566. }
  567. __inline static sint get_recvframe_len(union recv_frame *precvframe)
  568. {
  569. return precvframe->u.hdr.len;
  570. }
  571. __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
  572. {
  573. s32 SignalPower; // in dBm.
  574. // Translate to dBm (x=0.5y-95).
  575. SignalPower = (s32)((SignalStrengthIndex + 1) >> 1);
  576. SignalPower -= 95;
  577. return SignalPower;
  578. }
  579. struct sta_info;
  580. extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
  581. extern void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
  582. #endif