1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
10 #include <rtw_debug.h>
12 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
13 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
15 static void _init_txservq(struct tx_servq *ptxservq)
17 INIT_LIST_HEAD(&ptxservq->tx_pending);
18 _rtw_init_queue(&ptxservq->sta_pending);
22 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
24 memset((unsigned char *)psta_xmitpriv, 0, sizeof(struct sta_xmit_priv));
26 spin_lock_init(&psta_xmitpriv->lock);
28 /* for (i = 0 ; i < MAX_NUMBLKS; i++) */
29 /* _init_txservq(&(psta_xmitpriv->blk_q[i])); */
31 _init_txservq(&psta_xmitpriv->be_q);
32 _init_txservq(&psta_xmitpriv->bk_q);
33 _init_txservq(&psta_xmitpriv->vi_q);
34 _init_txservq(&psta_xmitpriv->vo_q);
35 INIT_LIST_HEAD(&psta_xmitpriv->legacy_dz);
36 INIT_LIST_HEAD(&psta_xmitpriv->apsd);
39 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
42 struct xmit_buf *pxmitbuf;
43 struct xmit_frame *pxframe;
46 spin_lock_init(&pxmitpriv->lock);
47 spin_lock_init(&pxmitpriv->lock_sctx);
48 init_completion(&pxmitpriv->xmit_comp);
49 init_completion(&pxmitpriv->terminate_xmitthread_comp);
52 Please insert all the queue initializaiton using _rtw_init_queue below
55 pxmitpriv->adapter = padapter;
57 /* for (i = 0 ; i < MAX_NUMBLKS; i++) */
58 /* _rtw_init_queue(&pxmitpriv->blk_strms[i]); */
60 _rtw_init_queue(&pxmitpriv->be_pending);
61 _rtw_init_queue(&pxmitpriv->bk_pending);
62 _rtw_init_queue(&pxmitpriv->vi_pending);
63 _rtw_init_queue(&pxmitpriv->vo_pending);
64 _rtw_init_queue(&pxmitpriv->bm_pending);
66 /* _rtw_init_queue(&pxmitpriv->legacy_dz_queue); */
67 /* _rtw_init_queue(&pxmitpriv->apsd_queue); */
69 _rtw_init_queue(&pxmitpriv->free_xmit_queue);
72 Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
73 and initialize free_xmit_frame below.
74 Please also apply free_txobj to link_up all the xmit_frames...
77 pxmitpriv->pallocated_frame_buf = vzalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
79 if (pxmitpriv->pallocated_frame_buf == NULL) {
80 pxmitpriv->pxmit_frame_buf = NULL;
81 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_frame fail!\n"));
85 pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_frame_buf), 4);
86 /* pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - */
87 /* ((SIZE_PTR) (pxmitpriv->pallocated_frame_buf) &3); */
89 pxframe = (struct xmit_frame *) pxmitpriv->pxmit_frame_buf;
91 for (i = 0; i < NR_XMITFRAME; i++) {
92 INIT_LIST_HEAD(&(pxframe->list));
94 pxframe->padapter = padapter;
95 pxframe->frame_tag = NULL_FRAMETAG;
99 pxframe->buf_addr = NULL;
100 pxframe->pxmitbuf = NULL;
102 list_add_tail(&(pxframe->list), &(pxmitpriv->free_xmit_queue.queue));
107 pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
109 pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
113 _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue);
114 _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue);
116 pxmitpriv->pallocated_xmitbuf = vzalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
118 if (pxmitpriv->pallocated_xmitbuf == NULL) {
119 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_buf fail!\n"));
124 pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmitbuf), 4);
125 /* pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - */
126 /* ((SIZE_PTR) (pxmitpriv->pallocated_xmitbuf) &3); */
128 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
130 for (i = 0; i < NR_XMITBUFF; i++) {
131 INIT_LIST_HEAD(&pxmitbuf->list);
133 pxmitbuf->priv_data = NULL;
134 pxmitbuf->padapter = padapter;
135 pxmitbuf->buf_tag = XMITBUF_DATA;
137 /* Tx buf allocation may fail sometimes, so sleep and retry. */
138 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), true);
141 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), true);
146 pxmitbuf->phead = pxmitbuf->pbuf;
147 pxmitbuf->pend = pxmitbuf->pbuf + MAX_XMITBUF_SZ;
149 pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
151 pxmitbuf->flags = XMIT_VO_QUEUE;
153 list_add_tail(&pxmitbuf->list, &(pxmitpriv->free_xmitbuf_queue.queue));
162 pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
164 /* init xframe_ext queue, the same count as extbuf */
165 _rtw_init_queue(&pxmitpriv->free_xframe_ext_queue);
167 pxmitpriv->xframe_ext_alloc_addr = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_frame) + 4);
169 if (pxmitpriv->xframe_ext_alloc_addr == NULL) {
170 pxmitpriv->xframe_ext = NULL;
171 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xframe_ext fail!\n"));
175 pxmitpriv->xframe_ext = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->xframe_ext_alloc_addr), 4);
176 pxframe = (struct xmit_frame *)pxmitpriv->xframe_ext;
178 for (i = 0; i < NR_XMIT_EXTBUFF; i++) {
179 INIT_LIST_HEAD(&(pxframe->list));
181 pxframe->padapter = padapter;
182 pxframe->frame_tag = NULL_FRAMETAG;
186 pxframe->buf_addr = NULL;
187 pxframe->pxmitbuf = NULL;
189 pxframe->ext_tag = 1;
191 list_add_tail(&(pxframe->list), &(pxmitpriv->free_xframe_ext_queue.queue));
195 pxmitpriv->free_xframe_ext_cnt = NR_XMIT_EXTBUFF;
197 /* Init xmit extension buff */
198 _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
200 pxmitpriv->pallocated_xmit_extbuf = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_buf) + 4);
202 if (pxmitpriv->pallocated_xmit_extbuf == NULL) {
203 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_extbuf fail!\n"));
208 pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmit_extbuf), 4);
210 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
212 for (i = 0; i < NR_XMIT_EXTBUFF; i++) {
213 INIT_LIST_HEAD(&pxmitbuf->list);
215 pxmitbuf->priv_data = NULL;
216 pxmitbuf->padapter = padapter;
217 pxmitbuf->buf_tag = XMITBUF_MGNT;
219 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, MAX_XMIT_EXTBUF_SZ + XMITBUF_ALIGN_SZ, true);
225 pxmitbuf->phead = pxmitbuf->pbuf;
226 pxmitbuf->pend = pxmitbuf->pbuf + MAX_XMIT_EXTBUF_SZ;
228 pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
230 list_add_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
231 #ifdef DBG_XMIT_BUF_EXT
238 pxmitpriv->free_xmit_extbuf_cnt = NR_XMIT_EXTBUFF;
240 for (i = 0; i < CMDBUF_MAX; i++) {
241 pxmitbuf = &pxmitpriv->pcmd_xmitbuf[i];
243 INIT_LIST_HEAD(&pxmitbuf->list);
245 pxmitbuf->priv_data = NULL;
246 pxmitbuf->padapter = padapter;
247 pxmitbuf->buf_tag = XMITBUF_CMD;
249 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, MAX_CMDBUF_SZ+XMITBUF_ALIGN_SZ, true);
255 pxmitbuf->phead = pxmitbuf->pbuf;
256 pxmitbuf->pend = pxmitbuf->pbuf + MAX_CMDBUF_SZ;
258 pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
259 pxmitbuf->alloc_sz = MAX_CMDBUF_SZ+XMITBUF_ALIGN_SZ;
263 res = rtw_alloc_hwxmits(padapter);
266 rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
268 for (i = 0; i < 4; i++) {
269 pxmitpriv->wmm_para_seq[i] = i;
272 pxmitpriv->ack_tx = false;
273 mutex_init(&pxmitpriv->ack_tx_mutex);
274 rtw_sctx_init(&pxmitpriv->ack_tx_ops, 0);
276 rtw_hal_init_xmit_priv(padapter);
282 void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv)
285 struct adapter *padapter = pxmitpriv->adapter;
286 struct xmit_frame *pxmitframe = (struct xmit_frame *) pxmitpriv->pxmit_frame_buf;
287 struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
289 rtw_hal_free_xmit_priv(padapter);
291 if (pxmitpriv->pxmit_frame_buf == NULL)
294 for (i = 0; i < NR_XMITFRAME; i++) {
295 rtw_os_xmit_complete(padapter, pxmitframe);
300 for (i = 0; i < NR_XMITBUFF; i++) {
301 rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), true);
306 if (pxmitpriv->pallocated_frame_buf)
307 vfree(pxmitpriv->pallocated_frame_buf);
310 if (pxmitpriv->pallocated_xmitbuf)
311 vfree(pxmitpriv->pallocated_xmitbuf);
313 /* free xframe_ext queue, the same count as extbuf */
314 pxmitframe = (struct xmit_frame *)pxmitpriv->xframe_ext;
316 for (i = 0; i < NR_XMIT_EXTBUFF; i++) {
317 rtw_os_xmit_complete(padapter, pxmitframe);
321 if (pxmitpriv->xframe_ext_alloc_addr)
322 vfree(pxmitpriv->xframe_ext_alloc_addr);
324 /* free xmit extension buff */
325 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
326 for (i = 0; i < NR_XMIT_EXTBUFF; i++) {
327 rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMIT_EXTBUF_SZ + XMITBUF_ALIGN_SZ), true);
332 if (pxmitpriv->pallocated_xmit_extbuf) {
333 vfree(pxmitpriv->pallocated_xmit_extbuf);
336 for (i = 0; i < CMDBUF_MAX; i++) {
337 pxmitbuf = &pxmitpriv->pcmd_xmitbuf[i];
338 if (pxmitbuf != NULL)
339 rtw_os_xmit_resource_free(padapter, pxmitbuf, MAX_CMDBUF_SZ+XMITBUF_ALIGN_SZ, true);
342 rtw_free_hwxmits(padapter);
344 mutex_destroy(&pxmitpriv->ack_tx_mutex);
347 u8 query_ra_short_GI(struct sta_info *psta)
349 u8 sgi = false, sgi_20m = false, sgi_40m = false, sgi_80m = false;
351 sgi_20m = psta->htpriv.sgi_20m;
352 sgi_40m = psta->htpriv.sgi_40m;
354 switch (psta->bw_mode) {
355 case CHANNEL_WIDTH_80:
358 case CHANNEL_WIDTH_40:
361 case CHANNEL_WIDTH_20:
370 static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *pxmitframe)
373 struct pkt_attrib *pattrib = &pxmitframe->attrib;
374 /* struct sta_info *psta = pattrib->psta; */
375 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
376 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
378 if (pattrib->nr_frags != 1)
379 sz = padapter->xmitpriv.frag_len;
381 sz = pattrib->last_txcmdsz;
383 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
384 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
385 /* Other fragments are protected by previous fragment. */
386 /* So we only need to check the length of first fragment. */
387 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
388 if (sz > padapter->registrypriv.rts_thresh)
389 pattrib->vcs_mode = RTS_CTS;
392 pattrib->vcs_mode = RTS_CTS;
393 else if (pattrib->cts2self)
394 pattrib->vcs_mode = CTS_TO_SELF;
396 pattrib->vcs_mode = NONE_VCS;
401 if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS) && (pattrib->ampdu_en == true) &&
402 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
403 pattrib->vcs_mode = CTS_TO_SELF;
408 /* check ERP protection */
409 if (pattrib->rtsen || pattrib->cts2self) {
411 pattrib->vcs_mode = RTS_CTS;
412 else if (pattrib->cts2self)
413 pattrib->vcs_mode = CTS_TO_SELF;
418 /* check HT op mode */
419 if (pattrib->ht_en) {
420 u8 HTOpMode = pmlmeinfo->HT_protection;
421 if ((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) ||
422 (!pmlmeext->cur_bwmode && HTOpMode == 3)) {
423 pattrib->vcs_mode = RTS_CTS;
429 if (sz > padapter->registrypriv.rts_thresh) {
430 pattrib->vcs_mode = RTS_CTS;
434 /* to do list: check MIMO power save condition. */
436 /* check AMPDU aggregation for TXOP */
437 if (pattrib->ampdu_en == true) {
438 pattrib->vcs_mode = RTS_CTS;
442 pattrib->vcs_mode = NONE_VCS;
447 /* for debug : force driver control vrtl_carrier_sense. */
448 if (padapter->driver_vcs_en == 1)
449 pattrib->vcs_mode = padapter->driver_vcs_type;
452 static void update_attrib_phy_info(struct adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta)
454 struct mlme_ext_priv *mlmeext = &padapter->mlmeextpriv;
456 pattrib->rtsen = psta->rtsen;
457 pattrib->cts2self = psta->cts2self;
461 pattrib->triggered = 0;
462 pattrib->ampdu_spacing = 0;
464 /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
465 pattrib->qos_en = psta->qos_option;
467 pattrib->raid = psta->raid;
469 if (mlmeext->cur_bwmode < psta->bw_mode)
470 pattrib->bwmode = mlmeext->cur_bwmode;
472 pattrib->bwmode = psta->bw_mode;
474 pattrib->sgi = query_ra_short_GI(psta);
476 pattrib->ldpc = psta->ldpc;
477 pattrib->stbc = psta->stbc;
479 pattrib->ht_en = psta->htpriv.ht_option;
480 pattrib->ch_offset = psta->htpriv.ch_offset;
481 pattrib->ampdu_en = false;
483 if (padapter->driver_ampdu_spacing != 0xFF) /* driver control AMPDU Density for peer sta's rx */
484 pattrib->ampdu_spacing = padapter->driver_ampdu_spacing;
486 pattrib->ampdu_spacing = psta->htpriv.rx_ampdu_min_spacing;
488 /* if (pattrib->ht_en && psta->htpriv.ampdu_enable) */
490 /* if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority)) */
491 /* pattrib->ampdu_en = true; */
495 pattrib->retry_ctrl = false;
497 #ifdef CONFIG_AUTO_AP_MODE
498 if (psta->isrc && psta->pid > 0)
499 pattrib->pctrl = true;
504 static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta)
507 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
508 struct security_priv *psecuritypriv = &padapter->securitypriv;
509 sint bmcast = IS_MCAST(pattrib->ra);
511 memset(pattrib->dot118021x_UncstKey.skey, 0, 16);
512 memset(pattrib->dot11tkiptxmickey.skey, 0, 16);
513 pattrib->mac_id = psta->mac_id;
515 if (psta->ieee8021x_blocked == true) {
516 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\n psta->ieee8021x_blocked == true\n"));
518 pattrib->encrypt = 0;
520 if ((pattrib->ether_type != 0x888e) && (check_fwstate(pmlmepriv, WIFI_MP_STATE) == false)) {
521 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != 0x888e\n", pattrib->ether_type));
522 #ifdef DBG_TX_DROP_FRAME
523 DBG_871X("DBG_TX_DROP_FRAME %s psta->ieee8021x_blocked == true, pattrib->ether_type(%04x) != 0x888e\n", __func__, pattrib->ether_type);
529 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
531 switch (psecuritypriv->dot11AuthAlgrthm) {
532 case dot11AuthAlgrthm_Open:
533 case dot11AuthAlgrthm_Shared:
534 case dot11AuthAlgrthm_Auto:
535 pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
537 case dot11AuthAlgrthm_8021X:
539 pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid;
541 pattrib->key_idx = 0;
544 pattrib->key_idx = 0;
548 /* For WPS 1.0 WEP, driver should not encrypt EAPOL Packet for WPS handshake. */
549 if (((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) && (pattrib->ether_type == 0x888e))
550 pattrib->encrypt = _NO_PRIVACY_;
554 switch (pattrib->encrypt) {
558 pattrib->icv_len = 4;
559 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
564 pattrib->icv_len = 4;
566 if (psecuritypriv->busetkipkey == _FAIL) {
567 #ifdef DBG_TX_DROP_FRAME
568 DBG_871X("DBG_TX_DROP_FRAME %s psecuritypriv->busetkipkey(%d) == _FAIL drop packet\n", __func__, psecuritypriv->busetkipkey);
575 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
577 TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
580 memcpy(pattrib->dot11tkiptxmickey.skey, psta->dot11tkiptxmickey.skey, 16);
587 pattrib->icv_len = 8;
590 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
592 AES_IV(pattrib->iv, psta->dot11txpn, 0);
598 pattrib->icv_len = 0;
602 if (pattrib->encrypt > 0)
603 memcpy(pattrib->dot118021x_UncstKey.skey, psta->dot118021x_UncstKey.skey, 16);
605 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
606 ("update_attrib: encrypt =%d securitypriv.sw_encrypt =%d\n",
607 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
609 if (pattrib->encrypt &&
610 ((padapter->securitypriv.sw_encrypt == true) || (psecuritypriv->hw_decrypted == false))) {
611 pattrib->bswenc = true;
612 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
613 ("update_attrib: encrypt =%d securitypriv.hw_decrypted =%d bswenc =true\n",
614 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
616 pattrib->bswenc = false;
617 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("update_attrib: bswenc =false\n"));
626 u8 qos_acm(u8 acm_mask, u8 priority)
628 u8 change_priority = priority;
633 if (acm_mask & BIT(1))
641 if (acm_mask & BIT(2))
646 if (acm_mask & BIT(3))
650 DBG_871X("qos_acm(): invalid pattrib->priority: %d!!!\n", priority);
654 return change_priority;
657 static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
659 struct ethhdr etherhdr;
661 s32 UserPriority = 0;
664 _rtw_open_pktfile(ppktfile->pkt, ppktfile);
665 _rtw_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN);
667 /* get UserPriority from IP hdr */
668 if (pattrib->ether_type == 0x0800) {
669 _rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
670 /* UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3; */
671 UserPriority = ip_hdr.tos >> 5;
673 pattrib->priority = UserPriority;
674 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
675 pattrib->subtype = WIFI_QOS_DATA_TYPE;
678 static s32 update_attrib(struct adapter *padapter, _pkt *pkt, struct pkt_attrib *pattrib)
681 struct pkt_file pktfile;
682 struct sta_info *psta = NULL;
683 struct ethhdr etherhdr;
686 struct sta_priv *pstapriv = &padapter->stapriv;
687 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
688 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
691 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib);
693 _rtw_open_pktfile(pkt, &pktfile);
694 i = _rtw_pktfile_read(&pktfile, (u8 *)ðerhdr, ETH_HLEN);
696 pattrib->ether_type = ntohs(etherhdr.h_proto);
699 memcpy(pattrib->dst, ðerhdr.h_dest, ETH_ALEN);
700 memcpy(pattrib->src, ðerhdr.h_source, ETH_ALEN);
703 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
704 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
705 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
706 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
707 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_adhoc);
708 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
709 memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
710 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
711 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_sta);
712 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
713 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
714 memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
715 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_ap);
717 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_unknown);
719 pattrib->pktlen = pktfile.pkt_len;
721 if (ETH_P_IP == pattrib->ether_type) {
722 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */
723 /* to prevent DHCP protocol fail */
727 _rtw_pktfile_read(&pktfile, &tmp[0], 24);
729 pattrib->dhcp_pkt = 0;
730 if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
731 if (ETH_P_IP == pattrib->ether_type) {/* IP header */
732 if (((tmp[21] == 68) && (tmp[23] == 67)) ||
733 ((tmp[21] == 67) && (tmp[23] == 68))) {
734 /* 68 : UDP BOOTP client */
735 /* 67 : UDP BOOTP server */
736 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("======================update_attrib: get DHCP Packet\n"));
737 pattrib->dhcp_pkt = 1;
738 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_dhcp);
743 /* for parsing ICMP pakcets */
745 struct iphdr *piphdr = (struct iphdr *)tmp;
747 pattrib->icmp_pkt = 0;
748 if (piphdr->protocol == 0x1) { /* protocol type in ip header 0x1 is ICMP */
749 pattrib->icmp_pkt = 1;
750 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_icmp);
755 } else if (0x888e == pattrib->ether_type) {
756 DBG_871X_LEVEL(_drv_always_, "send eapol packet\n");
759 if ((pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
760 rtw_set_scan_deny(padapter, 3000);
762 /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
763 if (pattrib->icmp_pkt == 1)
764 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1);
765 else if (pattrib->dhcp_pkt == 1) {
766 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_active);
767 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
770 bmcast = IS_MCAST(pattrib->ra);
774 psta = rtw_get_bcmc_stainfo(padapter);
776 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
777 if (psta == NULL) { /* if we cannot get psta => drop the pkt */
778 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_ucast_sta);
779 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT"\n", MAC_ARG(pattrib->ra)));
780 #ifdef DBG_TX_DROP_FRAME
781 DBG_871X("DBG_TX_DROP_FRAME %s get sta_info fail, ra:" MAC_FMT"\n", __func__, MAC_ARG(pattrib->ra));
785 } else if ((check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) && (!(psta->state & _FW_LINKED))) {
786 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_ucast_ap_link);
793 /* if we cannot get psta => drop the pkt */
794 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_sta);
795 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT "\n", MAC_ARG(pattrib->ra)));
796 #ifdef DBG_TX_DROP_FRAME
797 DBG_871X("DBG_TX_DROP_FRAME %s get sta_info fail, ra:" MAC_FMT"\n", __func__, MAC_ARG(pattrib->ra));
803 if (!(psta->state & _FW_LINKED)) {
804 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_link);
805 DBG_871X("%s, psta("MAC_FMT")->state(0x%x) != _FW_LINKED\n", __func__, MAC_ARG(psta->hwaddr), psta->state);
812 if (update_attrib_sec_info(padapter, pattrib, psta) == _FAIL) {
813 DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_sec);
818 update_attrib_phy_info(padapter, pattrib, psta);
820 /* DBG_8192C("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
822 pattrib->psta = psta;
827 pattrib->ack_policy = 0;
828 /* get ether_hdr_len */
829 pattrib->pkt_hdrlen = ETH_HLEN;/* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
831 pattrib->hdrlen = WLAN_HDR_A3_LEN;
832 pattrib->subtype = WIFI_DATA_TYPE;
833 pattrib->priority = 0;
835 if (check_fwstate(pmlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) {
837 set_qos(&pktfile, pattrib);
839 if (pqospriv->qos_option) {
840 set_qos(&pktfile, pattrib);
842 if (pmlmepriv->acm_mask != 0)
843 pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
848 /* pattrib->priority = 5; force to used VI queue, for testing */
854 static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitframe)
856 sint curfragnum, length;
857 u8 *pframe, *payload, mic[8];
858 struct mic_data micdata;
859 /* struct sta_info *stainfo; */
860 struct pkt_attrib *pattrib = &pxmitframe->attrib;
861 struct security_priv *psecuritypriv = &padapter->securitypriv;
862 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
863 u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
864 u8 hw_hdr_offset = 0;
865 sint bmcst = IS_MCAST(pattrib->ra);
870 stainfo = pattrib->psta;
874 DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
875 stainfo =rtw_get_stainfo(&padapter->stapriv ,&pattrib->ra[0]);
880 DBG_871X("%s, psta ==NUL\n", __func__);
884 if (!(stainfo->state &_FW_LINKED))
886 DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, stainfo->state);
891 hw_hdr_offset = TXDESC_OFFSET;
893 if (pattrib->encrypt == _TKIP_) { /* if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_PRIVACY_) */
894 /* encode mic code */
895 /* if (stainfo!= NULL) */
897 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
899 pframe = pxmitframe->buf_addr + hw_hdr_offset;
902 if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)) {
903 /* DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey == 0\n"); */
907 /* start to calculate the mic code */
908 rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
910 if (!memcmp(&pattrib->dot11tkiptxmickey.skey[0], null_key, 16)) {
911 /* DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey == 0\n"); */
915 /* start to calculate the mic code */
916 rtw_secmicsetkey(&micdata, &pattrib->dot11tkiptxmickey.skey[0]);
919 if (pframe[1]&1) { /* ToDS == 1 */
920 rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */
921 if (pframe[1]&2) /* From Ds == 1 */
922 rtw_secmicappend(&micdata, &pframe[24], 6);
924 rtw_secmicappend(&micdata, &pframe[10], 6);
925 } else { /* ToDS == 0 */
926 rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */
927 if (pframe[1]&2) /* From Ds == 1 */
928 rtw_secmicappend(&micdata, &pframe[16], 6);
930 rtw_secmicappend(&micdata, &pframe[10], 6);
934 /* if (pqospriv->qos_option == 1) */
936 priority[0] = (u8)pxmitframe->attrib.priority;
939 rtw_secmicappend(&micdata, &priority[0], 4);
943 for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
944 payload = (u8 *)RND4((SIZE_PTR)(payload));
945 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("===curfragnum =%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
946 curfragnum, *payload, *(payload+1), *(payload+2), *(payload+3), *(payload+4), *(payload+5), *(payload+6), *(payload+7)));
948 payload = payload+pattrib->hdrlen+pattrib->iv_len;
949 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum =%d pattrib->hdrlen =%d pattrib->iv_len =%d", curfragnum, pattrib->hdrlen, pattrib->iv_len));
950 if ((curfragnum+1) == pattrib->nr_frags) {
951 length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
952 rtw_secmicappend(&micdata, payload, length);
953 payload = payload+length;
955 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
956 rtw_secmicappend(&micdata, payload, length);
957 payload = payload+length+pattrib->icv_len;
958 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum =%d length =%d pattrib->icv_len =%d", curfragnum, length, pattrib->icv_len));
961 rtw_secgetmic(&micdata, &(mic[0]));
962 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: before add mic code!!!\n"));
963 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: pattrib->last_txcmdsz =%d!!!\n", pattrib->last_txcmdsz));
964 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: mic[0]= 0x%.2x , mic[1]= 0x%.2x , mic[2]= 0x%.2x , mic[3]= 0x%.2x\n\
965 mic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x , mic[7]= 0x%.2x !!!!\n",
966 mic[0], mic[1], mic[2], mic[3], mic[4], mic[5], mic[6], mic[7]));
967 /* add mic code and add the mic code length in last_txcmdsz */
969 memcpy(payload, &(mic[0]), 8);
970 pattrib->last_txcmdsz += 8;
972 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("\n ========last pkt ========\n"));
973 payload = payload-pattrib->last_txcmdsz+8;
974 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz; curfragnum = curfragnum+8)
975 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
976 *(payload+curfragnum), *(payload+curfragnum+1), *(payload+curfragnum+2), *(payload+curfragnum+3),
977 *(payload+curfragnum+4), *(payload+curfragnum+5), *(payload+curfragnum+6), *(payload+curfragnum+7)));
981 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: rtw_get_stainfo == NULL!!!\n"));
988 static s32 xmitframe_swencrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
991 struct pkt_attrib *pattrib = &pxmitframe->attrib;
992 /* struct security_priv *psecuritypriv =&padapter->securitypriv; */
994 /* if ((psecuritypriv->sw_encrypt)||(pattrib->bswenc)) */
995 if (pattrib->bswenc) {
996 /* DBG_871X("start xmitframe_swencrypt\n"); */
997 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("### xmitframe_swencrypt\n"));
998 switch (pattrib->encrypt) {
1001 rtw_wep_encrypt(padapter, (u8 *)pxmitframe);
1004 rtw_tkip_encrypt(padapter, (u8 *)pxmitframe);
1007 rtw_aes_encrypt(padapter, (u8 *)pxmitframe);
1014 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_, ("### xmitframe_hwencrypt\n"));
1019 s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib)
1023 struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr;
1024 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1025 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
1026 u8 qos_option = false;
1027 sint res = _SUCCESS;
1028 __le16 *fctrl = &pwlanhdr->frame_control;
1030 memset(hdr, 0, WLANHDR_OFFSET);
1032 SetFrameSubType(fctrl, pattrib->subtype);
1034 if (pattrib->subtype & WIFI_DATA_TYPE) {
1035 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)) {
1036 /* to_ds = 1, fr_ds = 0; */
1039 /* 1.Data transfer to AP */
1040 /* 2.Arp pkt will relayed by AP */
1042 memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
1043 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
1044 memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
1047 if (pqospriv->qos_option)
1050 } else if ((check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)) {
1051 /* to_ds = 0, fr_ds = 1; */
1053 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
1054 memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), ETH_ALEN);
1055 memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
1057 if (pattrib->qos_en)
1059 } else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
1060 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
1061 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
1062 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
1063 memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
1065 if (pattrib->qos_en)
1068 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv)));
1076 if (pattrib->encrypt)
1080 qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
1082 if (pattrib->priority)
1083 SetPriority(qc, pattrib->priority);
1085 SetEOSP(qc, pattrib->eosp);
1087 SetAckpolicy(qc, pattrib->ack_policy);
1090 /* TODO: fill HT Control Field */
1092 /* Update Seq Num will be handled by f/w */
1094 struct sta_info *psta;
1095 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
1096 if (pattrib->psta != psta) {
1097 DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
1102 DBG_871X("%s, psta ==NUL\n", __func__);
1106 if (!(psta->state & _FW_LINKED)) {
1107 DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
1113 psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
1114 psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
1115 pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
1117 SetSeqNum(hdr, pattrib->seqnum);
1119 /* check if enable ampdu */
1120 if (pattrib->ht_en && psta->htpriv.ampdu_enable)
1121 if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
1122 pattrib->ampdu_en = true;
1125 /* re-check if enable ampdu by BA_starting_seqctrl */
1126 if (pattrib->ampdu_en == true) {
1129 tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
1131 /* check BA_starting_seqctrl */
1132 if (SN_LESS(pattrib->seqnum, tx_seq)) {
1133 /* DBG_871X("tx ampdu seqnum(%d) < tx_seq(%d)\n", pattrib->seqnum, tx_seq); */
1134 pattrib->ampdu_en = false;/* AGG BK */
1135 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
1136 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
1138 pattrib->ampdu_en = true;/* AGG EN */
1140 /* DBG_871X("tx ampdu over run\n"); */
1141 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
1142 pattrib->ampdu_en = true;/* AGG EN */
1157 s32 rtw_txframes_pending(struct adapter *padapter)
1159 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1161 return ((!list_empty(&pxmitpriv->be_pending.queue)) ||
1162 (!list_empty(&pxmitpriv->bk_pending.queue)) ||
1163 (!list_empty(&pxmitpriv->vi_pending.queue)) ||
1164 (!list_empty(&pxmitpriv->vo_pending.queue)));
1168 * Calculate wlan 802.11 packet MAX size from pkt_attrib
1169 * This function doesn't consider fragment case
1171 u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib)
1175 len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */
1176 len += SNAP_SIZE + sizeof(u16); /* LLC */
1177 len += pattrib->pktlen;
1178 if (pattrib->encrypt == _TKIP_)
1180 len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */
1187 This sub-routine will perform all the following:
1189 1. remove 802.3 header.
1190 2. create wlan_header, based on the info in pxmitframe
1191 3. append sta's iv/ext-iv
1193 5. move frag chunk from pframe to pxmitframe->mem
1194 6. apply sw-encrypt, if necessary.
1197 s32 rtw_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe)
1199 struct pkt_file pktfile;
1201 s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
1205 u8 *pframe, *mem_start;
1208 /* struct sta_info *psta; */
1209 /* struct sta_priv *pstapriv = &padapter->stapriv; */
1210 /* struct mlme_priv *pmlmepriv = &padapter->mlmepriv; */
1211 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1213 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1217 s32 bmcst = IS_MCAST(pattrib->ra);
1223 psta = pattrib->psta;
1226 DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
1227 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
1233 DBG_871X("%s, psta ==NUL\n", __func__);
1238 if (!(psta->state &_FW_LINKED))
1240 DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
1244 if (pxmitframe->buf_addr == NULL) {
1245 DBG_8192C("==> %s buf_addr == NULL\n", __func__);
1249 pbuf_start = pxmitframe->buf_addr;
1251 hw_hdr_offset = TXDESC_OFFSET;
1252 mem_start = pbuf_start + hw_hdr_offset;
1254 if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
1255 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n"));
1256 DBG_8192C("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n");
1261 _rtw_open_pktfile(pkt, &pktfile);
1262 _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
1265 frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
1274 SetMFrag(mem_start);
1276 pframe += pattrib->hdrlen;
1277 mpdu_len -= pattrib->hdrlen;
1279 /* adding icv, if necessary... */
1280 if (pattrib->iv_len) {
1281 memcpy(pframe, pattrib->iv, pattrib->iv_len);
1283 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
1284 ("rtw_xmitframe_coalesce: keyid =%d pattrib->iv[3]=%.2x pframe =%.2x %.2x %.2x %.2x\n",
1285 padapter->securitypriv.dot11PrivacyKeyIndex, pattrib->iv[3], *pframe, *(pframe+1), *(pframe+2), *(pframe+3)));
1287 pframe += pattrib->iv_len;
1289 mpdu_len -= pattrib->iv_len;
1293 llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
1298 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1299 mpdu_len -= pattrib->icv_len;
1304 /* don't do fragment to broadcat/multicast packets */
1305 mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen);
1307 mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
1312 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1313 memcpy(pframe, pattrib->icv, pattrib->icv_len);
1314 pframe += pattrib->icv_len;
1319 if (bmcst || (rtw_endofpktfile(&pktfile) == true)) {
1320 pattrib->nr_frags = frg_inx;
1322 pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz:0) +
1323 ((pattrib->bswenc) ? pattrib->icv_len : 0) + mem_sz;
1325 ClearMFrag(mem_start);
1329 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("%s: There're still something in packet!\n", __func__));
1331 addr = (SIZE_PTR)(pframe);
1333 mem_start = (unsigned char *)RND4(addr) + hw_hdr_offset;
1334 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
1338 if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
1339 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
1340 DBG_8192C("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
1345 xmitframe_swencrypt(padapter, pxmitframe);
1348 update_attrib_vcs_info(padapter, pxmitframe);
1350 pattrib->vcs_mode = NONE_VCS;
1356 /* broadcast or multicast management pkt use BIP, unicast management pkt use CCMP encryption */
1357 s32 rtw_mgmt_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe)
1359 u8 *pframe, *mem_start = NULL, *tmp_buf = NULL;
1361 struct sta_info *psta = NULL;
1362 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1363 s32 bmcst = IS_MCAST(pattrib->ra);
1365 u8 *MGMT_body = NULL;
1367 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1368 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1369 struct ieee80211_hdr *pwlanhdr;
1370 u8 MME[_MME_IE_LENGTH_];
1372 mem_start = pframe = (u8 *)(pxmitframe->buf_addr) + TXDESC_OFFSET;
1373 pwlanhdr = (struct ieee80211_hdr *)pframe;
1375 ori_len = BIP_AAD_SIZE+pattrib->pktlen;
1376 tmp_buf = BIP_AAD = rtw_zmalloc(ori_len);
1377 subtype = GetFrameSubType(pframe); /* bit(7)~bit(2) */
1379 if (BIP_AAD == NULL)
1382 spin_lock_bh(&padapter->security_key_mutex);
1384 /* only support station mode */
1385 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE) || !check_fwstate(pmlmepriv, _FW_LINKED))
1386 goto xmitframe_coalesce_success;
1388 /* IGTK key is not install, it may not support 802.11w */
1389 if (padapter->securitypriv.binstallBIPkey != true) {
1390 DBG_871X("no instll BIP key\n");
1391 goto xmitframe_coalesce_success;
1393 /* station mode doesn't need TX BIP, just ready the code */
1400 /* other types doesn't need the BIP */
1401 if (GetFrameSubType(pframe) != WIFI_DEAUTH && GetFrameSubType(pframe) != WIFI_DISASSOC)
1402 goto xmitframe_coalesce_fail;
1404 MGMT_body = pframe + sizeof(struct ieee80211_hdr_3addr);
1405 pframe += pattrib->pktlen;
1407 /* octent 0 and 1 is key index , BIP keyid is 4 or 5, LSB only need octent 0 */
1408 MME[0] = padapter->securitypriv.dot11wBIPKeyid;
1409 /* copy packet number */
1410 memcpy(&MME[2], &pmlmeext->mgnt_80211w_IPN, 6);
1411 /* increase the packet number */
1412 pmlmeext->mgnt_80211w_IPN++;
1414 /* add MME IE with MIC all zero, MME string doesn't include element id and length */
1415 pframe = rtw_set_ie(pframe, _MME_IE_, 16, MME, &(pattrib->pktlen));
1416 pattrib->last_txcmdsz = pattrib->pktlen;
1417 /* total frame length - header length */
1418 frame_body_len = pattrib->pktlen - sizeof(struct ieee80211_hdr_3addr);
1420 /* conscruct AAD, copy frame control field */
1421 memcpy(BIP_AAD, &pwlanhdr->frame_control, 2);
1422 ClearRetry(BIP_AAD);
1423 ClearPwrMgt(BIP_AAD);
1424 ClearMData(BIP_AAD);
1425 /* conscruct AAD, copy address 1 to address 3 */
1426 memcpy(BIP_AAD+2, pwlanhdr->addr1, 18);
1427 /* copy management fram body */
1428 memcpy(BIP_AAD+BIP_AAD_SIZE, MGMT_body, frame_body_len);
1430 if (omac1_aes_128(padapter->securitypriv.dot11wBIPKey[padapter->securitypriv.dot11wBIPKeyid].skey
1431 , BIP_AAD, BIP_AAD_SIZE+frame_body_len, mic))
1432 goto xmitframe_coalesce_fail;
1434 /* copy right BIP mic value, total is 128bits, we use the 0~63 bits */
1435 memcpy(pframe-8, mic, 8);
1436 } else { /* unicast mgmt frame TX */
1437 /* start to encrypt mgmt frame */
1438 if (subtype == WIFI_DEAUTH || subtype == WIFI_DISASSOC ||
1439 subtype == WIFI_REASSOCREQ || subtype == WIFI_ACTION) {
1441 psta = pattrib->psta;
1443 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
1447 DBG_871X("%s, psta ==NUL\n", __func__);
1448 goto xmitframe_coalesce_fail;
1451 if (!(psta->state & _FW_LINKED) || pxmitframe->buf_addr == NULL) {
1452 DBG_871X("%s, not _FW_LINKED or addr null\n", __func__);
1453 goto xmitframe_coalesce_fail;
1456 /* DBG_871X("%s, action frame category =%d\n", __func__, pframe[WLAN_HDR_A3_LEN]); */
1457 /* according 802.11-2012 standard, these five types are not robust types */
1458 if (subtype == WIFI_ACTION &&
1459 (pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_PUBLIC ||
1460 pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_HT ||
1461 pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_UNPROTECTED_WNM ||
1462 pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_SELF_PROTECTED ||
1463 pframe[WLAN_HDR_A3_LEN] == RTW_WLAN_CATEGORY_P2P))
1464 goto xmitframe_coalesce_fail;
1465 /* before encrypt dump the management packet content */
1466 if (pattrib->encrypt > 0)
1467 memcpy(pattrib->dot118021x_UncstKey.skey, psta->dot118021x_UncstKey.skey, 16);
1468 /* bakeup original management packet */
1469 memcpy(tmp_buf, pframe, pattrib->pktlen);
1470 /* move to data portion */
1471 pframe += pattrib->hdrlen;
1473 /* 802.11w unicast management packet must be _AES_ */
1474 pattrib->iv_len = 8;
1475 /* it's MIC of AES */
1476 pattrib->icv_len = 8;
1478 switch (pattrib->encrypt) {
1480 /* set AES IV header */
1481 AES_IV(pattrib->iv, psta->dot11wtxpn, 0);
1484 goto xmitframe_coalesce_fail;
1486 /* insert iv header into management frame */
1487 memcpy(pframe, pattrib->iv, pattrib->iv_len);
1488 pframe += pattrib->iv_len;
1489 /* copy mgmt data portion after CCMP header */
1490 memcpy(pframe, tmp_buf+pattrib->hdrlen, pattrib->pktlen-pattrib->hdrlen);
1491 /* move pframe to end of mgmt pkt */
1492 pframe += pattrib->pktlen-pattrib->hdrlen;
1493 /* add 8 bytes CCMP IV header to length */
1494 pattrib->pktlen += pattrib->iv_len;
1495 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1496 memcpy(pframe, pattrib->icv, pattrib->icv_len);
1497 pframe += pattrib->icv_len;
1499 /* add 8 bytes MIC */
1500 pattrib->pktlen += pattrib->icv_len;
1501 /* set final tx command size */
1502 pattrib->last_txcmdsz = pattrib->pktlen;
1504 /* set protected bit must be beofre SW encrypt */
1505 SetPrivacy(mem_start);
1506 /* software encrypt */
1507 xmitframe_swencrypt(padapter, pxmitframe);
1511 xmitframe_coalesce_success:
1512 spin_unlock_bh(&padapter->security_key_mutex);
1516 xmitframe_coalesce_fail:
1517 spin_unlock_bh(&padapter->security_key_mutex);
1522 /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1523 * IEEE LLC/SNAP header contains 8 octets
1524 * First 3 octets comprise the LLC portion
1525 * SNAP portion, 5 octets, is divided into two fields:
1526 *Organizationally Unique Identifier(OUI), 3 octets,
1527 *type, defined by that organization, 2 octets.
1529 s32 rtw_put_snap(u8 *data, u16 h_proto)
1531 struct ieee80211_snap_hdr *snap;
1534 snap = (struct ieee80211_snap_hdr *)data;
1539 if (h_proto == 0x8137 || h_proto == 0x80f3)
1544 snap->oui[0] = oui[0];
1545 snap->oui[1] = oui[1];
1546 snap->oui[2] = oui[2];
1548 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
1550 return SNAP_SIZE + sizeof(u16);
1553 void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len)
1559 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1560 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1562 switch (pxmitpriv->vcs_setting) {
1564 pxmitpriv->vcs = NONE_VCS;
1572 perp = rtw_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
1574 pxmitpriv->vcs = NONE_VCS;
1576 protection = (*(perp + 2)) & BIT(1);
1578 if (pregistrypriv->vcs_type == RTS_CTS)
1579 pxmitpriv->vcs = RTS_CTS;
1581 pxmitpriv->vcs = CTS_TO_SELF;
1583 pxmitpriv->vcs = NONE_VCS;
1591 void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz)
1593 struct sta_info *psta = NULL;
1594 struct stainfo_stats *pstats = NULL;
1595 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1596 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1599 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) {
1600 pkt_num = pxmitframe->agg_num;
1602 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pkt_num;
1604 pxmitpriv->tx_pkts += pkt_num;
1606 pxmitpriv->tx_bytes += sz;
1608 psta = pxmitframe->attrib.psta;
1610 pstats = &psta->sta_stats;
1612 pstats->tx_pkts += pkt_num;
1614 pstats->tx_bytes += sz;
1619 static struct xmit_buf *__rtw_alloc_cmd_xmitbuf(struct xmit_priv *pxmitpriv,
1620 enum cmdbuf_type buf_type)
1622 struct xmit_buf *pxmitbuf = NULL;
1624 pxmitbuf = &pxmitpriv->pcmd_xmitbuf[buf_type];
1625 if (pxmitbuf != NULL) {
1626 pxmitbuf->priv_data = NULL;
1629 pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
1630 pxmitbuf->agg_num = 0;
1631 pxmitbuf->pg_num = 0;
1633 if (pxmitbuf->sctx) {
1634 DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
1635 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1638 DBG_871X("%s fail, no xmitbuf available !!!\n", __func__);
1643 struct xmit_frame *__rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv,
1644 enum cmdbuf_type buf_type)
1646 struct xmit_frame *pcmdframe;
1647 struct xmit_buf *pxmitbuf;
1649 pcmdframe = rtw_alloc_xmitframe(pxmitpriv);
1650 if (pcmdframe == NULL) {
1651 DBG_871X("%s, alloc xmitframe fail\n", __func__);
1655 pxmitbuf = __rtw_alloc_cmd_xmitbuf(pxmitpriv, buf_type);
1656 if (pxmitbuf == NULL) {
1657 DBG_871X("%s, alloc xmitbuf fail\n", __func__);
1658 rtw_free_xmitframe(pxmitpriv, pcmdframe);
1662 pcmdframe->frame_tag = MGNT_FRAMETAG;
1664 pcmdframe->pxmitbuf = pxmitbuf;
1666 pcmdframe->buf_addr = pxmitbuf->pbuf;
1668 pxmitbuf->priv_data = pcmdframe;
1674 struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
1677 struct xmit_buf *pxmitbuf = NULL;
1678 struct list_head *plist, *phead;
1679 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1681 spin_lock_irqsave(&pfree_queue->lock, irqL);
1683 if (list_empty(&pfree_queue->queue)) {
1687 phead = get_list_head(pfree_queue);
1689 plist = get_next(phead);
1691 pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
1693 list_del_init(&(pxmitbuf->list));
1696 if (pxmitbuf != NULL) {
1697 pxmitpriv->free_xmit_extbuf_cnt--;
1698 #ifdef DBG_XMIT_BUF_EXT
1699 DBG_871X("DBG_XMIT_BUF_EXT ALLOC no =%d, free_xmit_extbuf_cnt =%d\n", pxmitbuf->no, pxmitpriv->free_xmit_extbuf_cnt);
1703 pxmitbuf->priv_data = NULL;
1706 pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
1707 pxmitbuf->agg_num = 1;
1709 if (pxmitbuf->sctx) {
1710 DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
1711 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1716 spin_unlock_irqrestore(&pfree_queue->lock, irqL);
1721 s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1724 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1726 if (pxmitbuf == NULL)
1729 spin_lock_irqsave(&pfree_queue->lock, irqL);
1731 list_del_init(&pxmitbuf->list);
1733 list_add_tail(&(pxmitbuf->list), get_list_head(pfree_queue));
1734 pxmitpriv->free_xmit_extbuf_cnt++;
1735 #ifdef DBG_XMIT_BUF_EXT
1736 DBG_871X("DBG_XMIT_BUF_EXT FREE no =%d, free_xmit_extbuf_cnt =%d\n", pxmitbuf->no, pxmitpriv->free_xmit_extbuf_cnt);
1739 spin_unlock_irqrestore(&pfree_queue->lock, irqL);
1744 struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
1747 struct xmit_buf *pxmitbuf = NULL;
1748 struct list_head *plist, *phead;
1749 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1751 /* DBG_871X("+rtw_alloc_xmitbuf\n"); */
1753 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
1755 if (list_empty(&pfree_xmitbuf_queue->queue)) {
1759 phead = get_list_head(pfree_xmitbuf_queue);
1761 plist = get_next(phead);
1763 pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
1765 list_del_init(&(pxmitbuf->list));
1768 if (pxmitbuf != NULL) {
1769 pxmitpriv->free_xmitbuf_cnt--;
1771 DBG_871X("DBG_XMIT_BUF ALLOC no =%d, free_xmitbuf_cnt =%d\n", pxmitbuf->no, pxmitpriv->free_xmitbuf_cnt);
1773 /* DBG_871X("alloc, free_xmitbuf_cnt =%d\n", pxmitpriv->free_xmitbuf_cnt); */
1775 pxmitbuf->priv_data = NULL;
1778 pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
1779 pxmitbuf->agg_num = 0;
1780 pxmitbuf->pg_num = 0;
1782 if (pxmitbuf->sctx) {
1783 DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
1784 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1789 DBG_871X("DBG_XMIT_BUF rtw_alloc_xmitbuf return NULL\n");
1792 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
1797 s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1800 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1802 /* DBG_871X("+rtw_free_xmitbuf\n"); */
1804 if (pxmitbuf == NULL)
1807 if (pxmitbuf->sctx) {
1808 DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
1809 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
1812 if (pxmitbuf->buf_tag == XMITBUF_CMD) {
1813 } else if (pxmitbuf->buf_tag == XMITBUF_MGNT) {
1814 rtw_free_xmitbuf_ext(pxmitpriv, pxmitbuf);
1816 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
1818 list_del_init(&pxmitbuf->list);
1820 list_add_tail(&(pxmitbuf->list), get_list_head(pfree_xmitbuf_queue));
1822 pxmitpriv->free_xmitbuf_cnt++;
1823 /* DBG_871X("FREE, free_xmitbuf_cnt =%d\n", pxmitpriv->free_xmitbuf_cnt); */
1825 DBG_871X("DBG_XMIT_BUF FREE no =%d, free_xmitbuf_cnt =%d\n", pxmitbuf->no, pxmitpriv->free_xmitbuf_cnt);
1827 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
1832 static void rtw_init_xmitframe(struct xmit_frame *pxframe)
1834 if (pxframe != NULL) { /* default value setting */
1835 pxframe->buf_addr = NULL;
1836 pxframe->pxmitbuf = NULL;
1838 memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
1839 /* pxframe->attrib.psta = NULL; */
1841 pxframe->frame_tag = DATA_FRAMETAG;
1843 pxframe->pg_num = 1;
1844 pxframe->agg_num = 1;
1845 pxframe->ack_report = 0;
1852 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
1854 If we turn on USE_RXTHREAD, then, no need for critical section.
1855 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
1857 Must be very very cautious...
1860 struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)/* _queue *pfree_xmit_queue) */
1863 Please remember to use all the osdep_service api,
1864 and lock/unlock or _enter/_exit critical to protect
1868 struct xmit_frame *pxframe = NULL;
1869 struct list_head *plist, *phead;
1870 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1872 spin_lock_bh(&pfree_xmit_queue->lock);
1874 if (list_empty(&pfree_xmit_queue->queue)) {
1875 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe:%d\n", pxmitpriv->free_xmitframe_cnt));
1878 phead = get_list_head(pfree_xmit_queue);
1880 plist = get_next(phead);
1882 pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
1884 list_del_init(&(pxframe->list));
1885 pxmitpriv->free_xmitframe_cnt--;
1886 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe():free_xmitframe_cnt =%d\n", pxmitpriv->free_xmitframe_cnt));
1889 spin_unlock_bh(&pfree_xmit_queue->lock);
1891 rtw_init_xmitframe(pxframe);
1895 struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv)
1897 struct xmit_frame *pxframe = NULL;
1898 struct list_head *plist, *phead;
1899 struct __queue *queue = &pxmitpriv->free_xframe_ext_queue;
1901 spin_lock_bh(&queue->lock);
1903 if (list_empty(&queue->queue)) {
1904 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe_ext:%d\n", pxmitpriv->free_xframe_ext_cnt));
1907 phead = get_list_head(queue);
1908 plist = get_next(phead);
1909 pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
1911 list_del_init(&(pxframe->list));
1912 pxmitpriv->free_xframe_ext_cnt--;
1913 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe_ext():free_xmitframe_cnt =%d\n", pxmitpriv->free_xframe_ext_cnt));
1916 spin_unlock_bh(&queue->lock);
1918 rtw_init_xmitframe(pxframe);
1923 struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv)
1925 struct xmit_frame *pxframe = NULL;
1928 alloc_addr = rtw_zmalloc(sizeof(struct xmit_frame) + 4);
1930 if (alloc_addr == NULL)
1933 pxframe = (struct xmit_frame *)N_BYTE_ALIGMENT((SIZE_PTR)(alloc_addr), 4);
1934 pxframe->alloc_addr = alloc_addr;
1936 pxframe->padapter = pxmitpriv->adapter;
1937 pxframe->frame_tag = NULL_FRAMETAG;
1939 pxframe->pkt = NULL;
1941 pxframe->buf_addr = NULL;
1942 pxframe->pxmitbuf = NULL;
1944 rtw_init_xmitframe(pxframe);
1946 DBG_871X("################## %s ##################\n", __func__);
1952 s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
1954 struct __queue *queue = NULL;
1955 struct adapter *padapter = pxmitpriv->adapter;
1956 _pkt *pndis_pkt = NULL;
1958 if (pxmitframe == NULL) {
1959 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("======rtw_free_xmitframe():pxmitframe == NULL!!!!!!!!!!\n"));
1963 if (pxmitframe->pkt) {
1964 pndis_pkt = pxmitframe->pkt;
1965 pxmitframe->pkt = NULL;
1968 if (pxmitframe->alloc_addr) {
1969 DBG_871X("################## %s with alloc_addr ##################\n", __func__);
1970 kfree(pxmitframe->alloc_addr);
1971 goto check_pkt_complete;
1974 if (pxmitframe->ext_tag == 0)
1975 queue = &pxmitpriv->free_xmit_queue;
1976 else if (pxmitframe->ext_tag == 1)
1977 queue = &pxmitpriv->free_xframe_ext_queue;
1982 spin_lock_bh(&queue->lock);
1984 list_del_init(&pxmitframe->list);
1985 list_add_tail(&pxmitframe->list, get_list_head(queue));
1986 if (pxmitframe->ext_tag == 0) {
1987 pxmitpriv->free_xmitframe_cnt++;
1988 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xmitframe_cnt =%d\n", pxmitpriv->free_xmitframe_cnt));
1989 } else if (pxmitframe->ext_tag == 1) {
1990 pxmitpriv->free_xframe_ext_cnt++;
1991 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xframe_ext_cnt =%d\n", pxmitpriv->free_xframe_ext_cnt));
1995 spin_unlock_bh(&queue->lock);
2000 rtw_os_pkt_complete(padapter, pndis_pkt);
2006 void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue)
2008 struct list_head *plist, *phead;
2009 struct xmit_frame *pxmitframe;
2011 spin_lock_bh(&(pframequeue->lock));
2013 phead = get_list_head(pframequeue);
2014 plist = get_next(phead);
2016 while (phead != plist) {
2018 pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
2020 plist = get_next(plist);
2022 rtw_free_xmitframe(pxmitpriv, pxmitframe);
2025 spin_unlock_bh(&(pframequeue->lock));
2028 s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
2030 DBG_COUNTER(padapter->tx_logs.core_tx_enqueue);
2031 if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL) {
2032 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
2033 ("rtw_xmitframe_enqueue: drop xmit pkt for classifier fail\n"));
2034 /* pxmitframe->pkt = NULL; */
2041 struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, sint up, u8 *ac)
2043 struct tx_servq *ptxservq = NULL;
2048 ptxservq = &(psta->sta_xmitpriv.bk_q);
2050 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BK\n"));
2055 ptxservq = &(psta->sta_xmitpriv.vi_q);
2057 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VI\n"));
2062 ptxservq = &(psta->sta_xmitpriv.vo_q);
2064 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VO\n"));
2070 ptxservq = &(psta->sta_xmitpriv.be_q);
2072 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BE\n"));
2081 * Will enqueue pxmitframe to the proper queue,
2082 * and indicate it to xx_pending list.....
2084 s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe)
2088 struct sta_info *psta;
2089 struct tx_servq *ptxservq;
2090 struct pkt_attrib *pattrib = &pxmitframe->attrib;
2091 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
2092 sint res = _SUCCESS;
2094 DBG_COUNTER(padapter->tx_logs.core_tx_enqueue_class);
2097 if (pattrib->psta) {
2098 psta = pattrib->psta;
2100 DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
2101 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
2105 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
2106 if (pattrib->psta != psta) {
2107 DBG_COUNTER(padapter->tx_logs.core_tx_enqueue_class_err_sta);
2108 DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
2113 DBG_COUNTER(padapter->tx_logs.core_tx_enqueue_class_err_nosta);
2115 DBG_8192C("rtw_xmit_classifier: psta == NULL\n");
2116 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmit_classifier: psta == NULL\n"));
2120 if (!(psta->state & _FW_LINKED)) {
2121 DBG_COUNTER(padapter->tx_logs.core_tx_enqueue_class_err_fwlink);
2122 DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
2126 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
2128 /* spin_lock_irqsave(&pstapending->lock, irqL0); */
2130 if (list_empty(&ptxservq->tx_pending)) {
2131 list_add_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue));
2134 /* spin_lock_irqsave(&ptxservq->sta_pending.lock, irqL1); */
2136 list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
2138 phwxmits[ac_index].accnt++;
2140 /* spin_unlock_irqrestore(&ptxservq->sta_pending.lock, irqL1); */
2142 /* spin_unlock_irqrestore(&pstapending->lock, irqL0); */
2149 s32 rtw_alloc_hwxmits(struct adapter *padapter)
2151 struct hw_xmit *hwxmits;
2152 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2154 pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
2156 pxmitpriv->hwxmits = NULL;
2158 pxmitpriv->hwxmits = rtw_zmalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry);
2160 if (!pxmitpriv->hwxmits)
2163 hwxmits = pxmitpriv->hwxmits;
2165 if (pxmitpriv->hwxmit_entry == 5) {
2166 /* pxmitpriv->bmc_txqueue.head = 0; */
2167 /* hwxmits[0] .phwtxqueue = &pxmitpriv->bmc_txqueue; */
2168 hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
2170 /* pxmitpriv->vo_txqueue.head = 0; */
2171 /* hwxmits[1] .phwtxqueue = &pxmitpriv->vo_txqueue; */
2172 hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
2174 /* pxmitpriv->vi_txqueue.head = 0; */
2175 /* hwxmits[2] .phwtxqueue = &pxmitpriv->vi_txqueue; */
2176 hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
2178 /* pxmitpriv->bk_txqueue.head = 0; */
2179 /* hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue; */
2180 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
2182 /* pxmitpriv->be_txqueue.head = 0; */
2183 /* hwxmits[4] .phwtxqueue = &pxmitpriv->be_txqueue; */
2184 hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
2186 } else if (pxmitpriv->hwxmit_entry == 4) {
2188 /* pxmitpriv->vo_txqueue.head = 0; */
2189 /* hwxmits[0] .phwtxqueue = &pxmitpriv->vo_txqueue; */
2190 hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
2192 /* pxmitpriv->vi_txqueue.head = 0; */
2193 /* hwxmits[1] .phwtxqueue = &pxmitpriv->vi_txqueue; */
2194 hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
2196 /* pxmitpriv->be_txqueue.head = 0; */
2197 /* hwxmits[2] .phwtxqueue = &pxmitpriv->be_txqueue; */
2198 hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
2200 /* pxmitpriv->bk_txqueue.head = 0; */
2201 /* hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue; */
2202 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
2210 void rtw_free_hwxmits(struct adapter *padapter)
2212 struct hw_xmit *hwxmits;
2213 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2215 hwxmits = pxmitpriv->hwxmits;
2217 kfree((u8 *)hwxmits);
2220 void rtw_init_hwxmits(struct hw_xmit *phwxmit, sint entry)
2224 for (i = 0; i < entry; i++, phwxmit++) {
2225 /* spin_lock_init(&phwxmit->xmit_lock); */
2226 /* INIT_LIST_HEAD(&phwxmit->pending); */
2227 /* phwxmit->txcmdcnt = 0; */
2232 u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe)
2235 struct pkt_attrib *pattrib = &pxmitframe->attrib;
2237 switch (pattrib->qsel) {
2240 addr = BE_QUEUE_INX;
2244 addr = BK_QUEUE_INX;
2248 addr = VI_QUEUE_INX;
2252 addr = VO_QUEUE_INX;
2255 addr = BCN_QUEUE_INX;
2257 case 0x11:/* BC/MC in PS (HIQ) */
2258 addr = HIGH_QUEUE_INX;
2262 addr = MGT_QUEUE_INX;
2271 static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib)
2275 qsel = pattrib->priority;
2276 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("### do_queue_select priority =%d , qsel = %d\n", pattrib->priority, qsel));
2278 pattrib->qsel = qsel;
2282 * The main transmit(tx) entry
2286 *0 success, hardware will handle this xmit frame(packet)
2289 s32 rtw_xmit(struct adapter *padapter, _pkt **ppkt)
2291 static unsigned long start;
2292 static u32 drop_cnt;
2294 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2295 struct xmit_frame *pxmitframe = NULL;
2299 DBG_COUNTER(padapter->tx_logs.core_tx);
2304 pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
2306 if (jiffies_to_msecs(jiffies - start) > 2000) {
2308 DBG_871X("DBG_TX_DROP_FRAME %s no more pxmitframe, drop_cnt:%u\n", __func__, drop_cnt);
2313 if (pxmitframe == NULL) {
2315 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: no more pxmitframe\n"));
2316 DBG_COUNTER(padapter->tx_logs.core_tx_err_pxmitframe);
2320 res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
2323 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: update attrib fail\n"));
2324 #ifdef DBG_TX_DROP_FRAME
2325 DBG_871X("DBG_TX_DROP_FRAME %s update attrib fail\n", __func__);
2327 rtw_free_xmitframe(pxmitpriv, pxmitframe);
2330 pxmitframe->pkt = *ppkt;
2332 do_queue_select(padapter, &pxmitframe->attrib);
2334 spin_lock_bh(&pxmitpriv->lock);
2335 if (xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe) == true) {
2336 spin_unlock_bh(&pxmitpriv->lock);
2337 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue);
2340 spin_unlock_bh(&pxmitpriv->lock);
2343 if (rtw_hal_xmit(padapter, pxmitframe) == false)
2349 #define RTW_HIQ_FILTER_ALLOW_ALL 0
2350 #define RTW_HIQ_FILTER_ALLOW_SPECIAL 1
2351 #define RTW_HIQ_FILTER_DENY_ALL 2
2353 inline bool xmitframe_hiq_filter(struct xmit_frame *xmitframe)
2356 struct adapter *adapter = xmitframe->padapter;
2357 struct registry_priv *registry = &adapter->registrypriv;
2359 if (registry->hiq_filter == RTW_HIQ_FILTER_ALLOW_SPECIAL) {
2361 struct pkt_attrib *attrib = &xmitframe->attrib;
2363 if (attrib->ether_type == 0x0806
2364 || attrib->ether_type == 0x888e
2367 DBG_871X(FUNC_ADPT_FMT" ether_type:0x%04x%s\n", FUNC_ADPT_ARG(xmitframe->padapter)
2368 , attrib->ether_type, attrib->dhcp_pkt?" DHCP":"");
2371 } else if (registry->hiq_filter == RTW_HIQ_FILTER_ALLOW_ALL)
2373 else if (registry->hiq_filter == RTW_HIQ_FILTER_DENY_ALL) {
2380 sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe)
2383 struct sta_info *psta = NULL;
2384 struct sta_priv *pstapriv = &padapter->stapriv;
2385 struct pkt_attrib *pattrib = &pxmitframe->attrib;
2386 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2387 sint bmcst = IS_MCAST(pattrib->ra);
2388 bool update_tim = false;
2390 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false) {
2391 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_warn_fwstate);
2397 psta = pattrib->psta;
2401 DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
2402 psta =rtw_get_stainfo(pstapriv, pattrib->ra);
2405 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
2406 if (pattrib->psta != psta) {
2407 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_warn_sta);
2408 DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
2413 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_warn_nosta);
2414 DBG_871X("%s, psta ==NUL\n", __func__);
2418 if (!(psta->state & _FW_LINKED)) {
2419 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_warn_link);
2420 DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
2424 if (pattrib->triggered == 1) {
2425 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_warn_trigger);
2426 /* DBG_871X("directly xmit pspoll_triggered packet\n"); */
2428 /* pattrib->triggered = 0; */
2429 if (bmcst && xmitframe_hiq_filter(pxmitframe))
2430 pattrib->qsel = 0x11;/* HIQ */
2437 spin_lock_bh(&psta->sleep_q.lock);
2439 if (pstapriv->sta_dz_bitmap) { /* if anyone sta is in ps mode */
2440 /* pattrib->qsel = 0x11;HIQ */
2442 list_del_init(&pxmitframe->list);
2444 /* spin_lock_bh(&psta->sleep_q.lock); */
2446 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
2450 if (!(pstapriv->tim_bitmap & BIT(0)))
2453 pstapriv->tim_bitmap |= BIT(0);/* */
2454 pstapriv->sta_dz_bitmap |= BIT(0);
2456 /* DBG_871X("enqueue, sq_len =%d, tim =%x\n", psta->sleepq_len, pstapriv->tim_bitmap); */
2459 update_beacon(padapter, _TIM_IE_, NULL, true);
2461 chk_bmc_sleepq_cmd(padapter);
2464 /* spin_unlock_bh(&psta->sleep_q.lock); */
2468 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_mcast);
2472 spin_unlock_bh(&psta->sleep_q.lock);
2479 spin_lock_bh(&psta->sleep_q.lock);
2481 if (psta->state&WIFI_SLEEP_STATE) {
2484 if (pstapriv->sta_dz_bitmap & BIT(psta->aid)) {
2485 list_del_init(&pxmitframe->list);
2487 /* spin_lock_bh(&psta->sleep_q.lock); */
2489 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
2493 switch (pattrib->priority) {
2496 wmmps_ac = psta->uapsd_bk&BIT(0);
2500 wmmps_ac = psta->uapsd_vi&BIT(0);
2504 wmmps_ac = psta->uapsd_vo&BIT(0);
2509 wmmps_ac = psta->uapsd_be&BIT(0);
2514 psta->sleepq_ac_len++;
2516 if (((psta->has_legacy_ac) && (!wmmps_ac)) || ((!psta->has_legacy_ac) && (wmmps_ac))) {
2517 if (!(pstapriv->tim_bitmap & BIT(psta->aid)))
2520 pstapriv->tim_bitmap |= BIT(psta->aid);
2522 /* DBG_871X("enqueue, sq_len =%d, tim =%x\n", psta->sleepq_len, pstapriv->tim_bitmap); */
2525 /* DBG_871X("sleepq_len == 1, update BCNTIM\n"); */
2526 /* upate BCN for TIM IE */
2527 update_beacon(padapter, _TIM_IE_, NULL, true);
2530 /* spin_unlock_bh(&psta->sleep_q.lock); */
2532 /* if (psta->sleepq_len > (NR_XMITFRAME>>3)) */
2534 /* wakeup_sta_to_xmit(padapter, psta); */
2539 DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_ucast);
2544 spin_unlock_bh(&psta->sleep_q.lock);
2550 static void dequeue_xmitframes_to_sleeping_queue(struct adapter *padapter, struct sta_info *psta, struct __queue *pframequeue)
2553 struct list_head *plist, *phead;
2555 struct tx_servq *ptxservq;
2556 struct pkt_attrib *pattrib;
2557 struct xmit_frame *pxmitframe;
2558 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
2560 phead = get_list_head(pframequeue);
2561 plist = get_next(phead);
2563 while (phead != plist) {
2564 pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
2566 plist = get_next(plist);
2568 pattrib = &pxmitframe->attrib;
2570 pattrib->triggered = 0;
2572 ret = xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe);
2575 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
2578 phwxmits[ac_index].accnt--;
2580 /* DBG_871X("xmitframe_enqueue_for_sleeping_sta return false\n"); */
2587 void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta)
2589 struct sta_info *psta_bmc;
2590 struct sta_xmit_priv *pstaxmitpriv;
2591 struct sta_priv *pstapriv = &padapter->stapriv;
2592 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2594 pstaxmitpriv = &psta->sta_xmitpriv;
2596 /* for BC/MC Frames */
2597 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2600 spin_lock_bh(&pxmitpriv->lock);
2602 psta->state |= WIFI_SLEEP_STATE;
2604 pstapriv->sta_dz_bitmap |= BIT(psta->aid);
2608 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
2609 list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
2612 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
2613 list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
2616 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending);
2617 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
2620 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending);
2621 list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
2623 /* for BC/MC Frames */
2624 pstaxmitpriv = &psta_bmc->sta_xmitpriv;
2625 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending);
2626 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
2628 spin_unlock_bh(&pxmitpriv->lock);
2631 void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta)
2633 u8 update_mask = 0, wmmps_ac = 0;
2634 struct sta_info *psta_bmc;
2635 struct list_head *xmitframe_plist, *xmitframe_phead;
2636 struct xmit_frame *pxmitframe = NULL;
2637 struct sta_priv *pstapriv = &padapter->stapriv;
2638 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2640 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2643 /* spin_lock_bh(&psta->sleep_q.lock); */
2644 spin_lock_bh(&pxmitpriv->lock);
2646 xmitframe_phead = get_list_head(&psta->sleep_q);
2647 xmitframe_plist = get_next(xmitframe_phead);
2649 while (xmitframe_phead != xmitframe_plist) {
2650 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2652 xmitframe_plist = get_next(xmitframe_plist);
2654 list_del_init(&pxmitframe->list);
2656 switch (pxmitframe->attrib.priority) {
2659 wmmps_ac = psta->uapsd_bk&BIT(1);
2663 wmmps_ac = psta->uapsd_vi&BIT(1);
2667 wmmps_ac = psta->uapsd_vo&BIT(1);
2672 wmmps_ac = psta->uapsd_be&BIT(1);
2677 if (psta->sleepq_len > 0)
2678 pxmitframe->attrib.mdata = 1;
2680 pxmitframe->attrib.mdata = 0;
2683 psta->sleepq_ac_len--;
2684 if (psta->sleepq_ac_len > 0) {
2685 pxmitframe->attrib.mdata = 1;
2686 pxmitframe->attrib.eosp = 0;
2688 pxmitframe->attrib.mdata = 0;
2689 pxmitframe->attrib.eosp = 1;
2693 pxmitframe->attrib.triggered = 1;
2696 spin_unlock_bh(&psta->sleep_q.lock);
2697 if (rtw_hal_xmit(padapter, pxmitframe) == true)
2699 rtw_os_xmit_complete(padapter, pxmitframe);
2701 spin_lock_bh(&psta->sleep_q.lock);
2703 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
2708 if (psta->sleepq_len == 0) {
2709 if (pstapriv->tim_bitmap & BIT(psta->aid)) {
2710 /* DBG_871X("wakeup to xmit, qlen == 0, update_BCNTIM, tim =%x\n", pstapriv->tim_bitmap); */
2711 /* upate BCN for TIM IE */
2712 /* update_BCNTIM(padapter); */
2713 update_mask = BIT(0);
2716 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2718 if (psta->state&WIFI_SLEEP_STATE)
2719 psta->state ^= WIFI_SLEEP_STATE;
2721 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
2722 DBG_871X("%s alive check\n", __func__);
2723 psta->expire_to = pstapriv->expire_to;
2724 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
2727 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
2730 /* for BC/MC Frames */
2734 if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) { /* no any sta in ps mode */
2735 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
2736 xmitframe_plist = get_next(xmitframe_phead);
2738 while (xmitframe_phead != xmitframe_plist) {
2739 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2741 xmitframe_plist = get_next(xmitframe_plist);
2743 list_del_init(&pxmitframe->list);
2745 psta_bmc->sleepq_len--;
2746 if (psta_bmc->sleepq_len > 0)
2747 pxmitframe->attrib.mdata = 1;
2749 pxmitframe->attrib.mdata = 0;
2752 pxmitframe->attrib.triggered = 1;
2754 spin_unlock_bh(&psta_bmc->sleep_q.lock);
2755 if (rtw_hal_xmit(padapter, pxmitframe) == true)
2757 rtw_os_xmit_complete(padapter, pxmitframe);
2759 spin_lock_bh(&psta_bmc->sleep_q.lock);
2762 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
2766 if (psta_bmc->sleepq_len == 0) {
2767 if (pstapriv->tim_bitmap & BIT(0)) {
2768 /* DBG_871X("wakeup to xmit, qlen == 0, update_BCNTIM, tim =%x\n", pstapriv->tim_bitmap); */
2769 /* upate BCN for TIM IE */
2770 /* update_BCNTIM(padapter); */
2771 update_mask |= BIT(1);
2773 pstapriv->tim_bitmap &= ~BIT(0);
2774 pstapriv->sta_dz_bitmap &= ~BIT(0);
2781 /* spin_unlock_bh(&psta_bmc->sleep_q.lock); */
2782 spin_unlock_bh(&pxmitpriv->lock);
2785 /* update_BCNTIM(padapter); */
2786 /* printk("%s => call update_beacon\n", __func__); */
2787 update_beacon(padapter, _TIM_IE_, NULL, true);
2791 void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta)
2794 struct list_head *xmitframe_plist, *xmitframe_phead;
2795 struct xmit_frame *pxmitframe = NULL;
2796 struct sta_priv *pstapriv = &padapter->stapriv;
2797 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2800 /* spin_lock_bh(&psta->sleep_q.lock); */
2801 spin_lock_bh(&pxmitpriv->lock);
2803 xmitframe_phead = get_list_head(&psta->sleep_q);
2804 xmitframe_plist = get_next(xmitframe_phead);
2806 while (xmitframe_phead != xmitframe_plist) {
2807 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2809 xmitframe_plist = get_next(xmitframe_plist);
2811 switch (pxmitframe->attrib.priority) {
2814 wmmps_ac = psta->uapsd_bk&BIT(1);
2818 wmmps_ac = psta->uapsd_vi&BIT(1);
2822 wmmps_ac = psta->uapsd_vo&BIT(1);
2827 wmmps_ac = psta->uapsd_be&BIT(1);
2834 list_del_init(&pxmitframe->list);
2837 psta->sleepq_ac_len--;
2839 if (psta->sleepq_ac_len > 0) {
2840 pxmitframe->attrib.mdata = 1;
2841 pxmitframe->attrib.eosp = 0;
2843 pxmitframe->attrib.mdata = 0;
2844 pxmitframe->attrib.eosp = 1;
2847 pxmitframe->attrib.triggered = 1;
2848 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
2850 if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) && (wmmps_ac)) {
2851 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2853 /* DBG_871X("wakeup to xmit, qlen == 0, update_BCNTIM, tim =%x\n", pstapriv->tim_bitmap); */
2854 /* upate BCN for TIM IE */
2855 /* update_BCNTIM(padapter); */
2856 update_beacon(padapter, _TIM_IE_, NULL, true);
2857 /* update_mask = BIT(0); */
2862 /* spin_unlock_bh(&psta->sleep_q.lock); */
2863 spin_unlock_bh(&pxmitpriv->lock);
2866 void enqueue_pending_xmitbuf(
2867 struct xmit_priv *pxmitpriv,
2868 struct xmit_buf *pxmitbuf)
2870 struct __queue *pqueue;
2871 struct adapter *pri_adapter = pxmitpriv->adapter;
2873 pqueue = &pxmitpriv->pending_xmitbuf_queue;
2875 spin_lock_bh(&pqueue->lock);
2876 list_del_init(&pxmitbuf->list);
2877 list_add_tail(&pxmitbuf->list, get_list_head(pqueue));
2878 spin_unlock_bh(&pqueue->lock);
2880 complete(&(pri_adapter->xmitpriv.xmit_comp));
2883 void enqueue_pending_xmitbuf_to_head(
2884 struct xmit_priv *pxmitpriv,
2885 struct xmit_buf *pxmitbuf)
2887 struct __queue *pqueue;
2889 pqueue = &pxmitpriv->pending_xmitbuf_queue;
2891 spin_lock_bh(&pqueue->lock);
2892 list_del_init(&pxmitbuf->list);
2893 list_add(&pxmitbuf->list, get_list_head(pqueue));
2894 spin_unlock_bh(&pqueue->lock);
2897 struct xmit_buf *dequeue_pending_xmitbuf(
2898 struct xmit_priv *pxmitpriv)
2900 struct xmit_buf *pxmitbuf;
2901 struct __queue *pqueue;
2905 pqueue = &pxmitpriv->pending_xmitbuf_queue;
2907 spin_lock_bh(&pqueue->lock);
2909 if (!list_empty(&pqueue->queue)) {
2910 struct list_head *plist, *phead;
2912 phead = get_list_head(pqueue);
2913 plist = get_next(phead);
2914 pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
2915 list_del_init(&pxmitbuf->list);
2918 spin_unlock_bh(&pqueue->lock);
2923 struct xmit_buf *dequeue_pending_xmitbuf_under_survey(
2924 struct xmit_priv *pxmitpriv)
2926 struct xmit_buf *pxmitbuf;
2927 struct __queue *pqueue;
2931 pqueue = &pxmitpriv->pending_xmitbuf_queue;
2933 spin_lock_bh(&pqueue->lock);
2935 if (!list_empty(&pqueue->queue)) {
2936 struct list_head *plist, *phead;
2939 phead = get_list_head(pqueue);
2942 plist = get_next(plist);
2946 pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
2948 type = GetFrameSubType(pxmitbuf->pbuf + TXDESC_OFFSET);
2950 if ((type == WIFI_PROBEREQ) ||
2951 (type == WIFI_DATA_NULL) ||
2952 (type == WIFI_QOS_DATA_NULL)) {
2953 list_del_init(&pxmitbuf->list);
2960 spin_unlock_bh(&pqueue->lock);
2965 sint check_pending_xmitbuf(
2966 struct xmit_priv *pxmitpriv)
2968 struct __queue *pqueue;
2971 pqueue = &pxmitpriv->pending_xmitbuf_queue;
2973 spin_lock_bh(&pqueue->lock);
2975 if (!list_empty(&pqueue->queue))
2978 spin_unlock_bh(&pqueue->lock);
2983 int rtw_xmit_thread(void *context)
2986 struct adapter *padapter;
2992 thread_enter("RTW_XMIT_THREAD");
2995 err = rtw_hal_xmit_thread_handler(padapter);
2996 flush_signals_thread();
2997 } while (_SUCCESS == err);
2999 complete(&padapter->xmitpriv.terminate_xmitthread_comp);
3004 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms)
3006 sctx->timeout_ms = timeout_ms;
3007 sctx->submit_time = jiffies;
3008 init_completion(&sctx->done);
3009 sctx->status = RTW_SCTX_SUBMITTED;
3012 int rtw_sctx_wait(struct submit_ctx *sctx, const char *msg)
3015 unsigned long expire;
3018 expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) : MAX_SCHEDULE_TIMEOUT;
3019 if (!wait_for_completion_timeout(&sctx->done, expire)) {
3020 /* timeout, do something?? */
3021 status = RTW_SCTX_DONE_TIMEOUT;
3022 DBG_871X("%s timeout: %s\n", __func__, msg);
3024 status = sctx->status;
3027 if (status == RTW_SCTX_DONE_SUCCESS) {
3034 static bool rtw_sctx_chk_warning_status(int status)
3037 case RTW_SCTX_DONE_UNKNOWN:
3038 case RTW_SCTX_DONE_BUF_ALLOC:
3039 case RTW_SCTX_DONE_BUF_FREE:
3041 case RTW_SCTX_DONE_DRV_STOP:
3042 case RTW_SCTX_DONE_DEV_REMOVE:
3049 void rtw_sctx_done_err(struct submit_ctx **sctx, int status)
3052 if (rtw_sctx_chk_warning_status(status))
3053 DBG_871X("%s status:%d\n", __func__, status);
3054 (*sctx)->status = status;
3055 complete(&((*sctx)->done));
3060 void rtw_sctx_done(struct submit_ctx **sctx)
3062 rtw_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS);
3065 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms)
3067 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
3069 pack_tx_ops->submit_time = jiffies;
3070 pack_tx_ops->timeout_ms = timeout_ms;
3071 pack_tx_ops->status = RTW_SCTX_SUBMITTED;
3073 return rtw_sctx_wait(pack_tx_ops, __func__);
3076 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status)
3078 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
3080 if (pxmitpriv->ack_tx) {
3081 rtw_sctx_done_err(&pack_tx_ops, status);
3083 DBG_871X("%s ack_tx not set\n", __func__);