1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/wifi.h"
9 #include "../include/osdep_intf.h"
10 #include "../include/ip.h"
11 #include "../include/usb_ops.h"
12 #include "../include/usb_osintf.h"
14 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
15 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
17 static void _init_txservq(struct tx_servq *ptxservq)
20 INIT_LIST_HEAD(&ptxservq->tx_pending);
21 _rtw_init_queue(&ptxservq->sta_pending);
26 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
29 memset((unsigned char *)psta_xmitpriv, 0, sizeof (struct sta_xmit_priv));
30 spin_lock_init(&psta_xmitpriv->lock);
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);
40 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
43 struct xmit_buf *pxmitbuf;
44 struct xmit_frame *pxframe;
46 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
47 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
49 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */
51 spin_lock_init(&pxmitpriv->lock);
52 sema_init(&pxmitpriv->xmit_sema, 0);
53 sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
56 Please insert all the queue initializaiton using _rtw_init_queue below
59 pxmitpriv->adapter = padapter;
61 _rtw_init_queue(&pxmitpriv->be_pending);
62 _rtw_init_queue(&pxmitpriv->bk_pending);
63 _rtw_init_queue(&pxmitpriv->vi_pending);
64 _rtw_init_queue(&pxmitpriv->vo_pending);
65 _rtw_init_queue(&pxmitpriv->bm_pending);
67 _rtw_init_queue(&pxmitpriv->free_xmit_queue);
70 Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
71 and initialize free_xmit_frame below.
72 Please also apply free_txobj to link_up all the xmit_frames...
75 pxmitpriv->pallocated_frame_buf = rtw_zvmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
77 if (!pxmitpriv->pallocated_frame_buf) {
78 pxmitpriv->pxmit_frame_buf = NULL;
79 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_frame fail!\n"));
83 pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_frame_buf), 4);
84 /* pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - */
85 /* ((size_t) (pxmitpriv->pallocated_frame_buf) &3); */
87 pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
89 for (i = 0; i < NR_XMITFRAME; i++) {
90 INIT_LIST_HEAD(&(pxframe->list));
92 pxframe->padapter = padapter;
93 pxframe->frame_tag = NULL_FRAMETAG;
97 pxframe->buf_addr = NULL;
98 pxframe->pxmitbuf = NULL;
100 list_add_tail(&(pxframe->list), &(pxmitpriv->free_xmit_queue.queue));
105 pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
107 pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
110 _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue);
111 _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue);
113 pxmitpriv->pallocated_xmitbuf = rtw_zvmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
115 if (!pxmitpriv->pallocated_xmitbuf) {
116 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_buf fail!\n"));
121 pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmitbuf), 4);
122 /* pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - */
123 /* ((size_t) (pxmitpriv->pallocated_xmitbuf) &3); */
125 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
127 for (i = 0; i < NR_XMITBUFF; i++) {
128 INIT_LIST_HEAD(&pxmitbuf->list);
130 pxmitbuf->priv_data = NULL;
131 pxmitbuf->padapter = padapter;
132 pxmitbuf->ext_tag = false;
134 /* Tx buf allocation may fail sometimes, so sleep and retry. */
135 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
138 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
144 pxmitbuf->flags = XMIT_VO_QUEUE;
146 list_add_tail(&pxmitbuf->list, &(pxmitpriv->free_xmitbuf_queue.queue));
150 pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
152 /* Init xmit extension buff */
153 _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
155 pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
157 if (!pxmitpriv->pallocated_xmit_extbuf) {
158 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_extbuf fail!\n"));
163 pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmit_extbuf), 4);
165 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
167 for (i = 0; i < num_xmit_extbuf; i++) {
168 INIT_LIST_HEAD(&pxmitbuf->list);
170 pxmitbuf->priv_data = NULL;
171 pxmitbuf->padapter = padapter;
172 pxmitbuf->ext_tag = true;
174 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, max_xmit_extbuf_size + XMITBUF_ALIGN_SZ);
180 list_add_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
184 pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
186 rtw_alloc_hwxmits(padapter);
187 rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
189 for (i = 0; i < 4; i++)
190 pxmitpriv->wmm_para_seq[i] = i;
192 pxmitpriv->txirp_cnt = 1;
194 sema_init(&(pxmitpriv->tx_retevt), 0);
196 /* per AC pending irp */
197 pxmitpriv->beq_cnt = 0;
198 pxmitpriv->bkq_cnt = 0;
199 pxmitpriv->viq_cnt = 0;
200 pxmitpriv->voq_cnt = 0;
202 pxmitpriv->ack_tx = false;
203 _rtw_mutex_init(&pxmitpriv->ack_tx_mutex);
204 rtw_sctx_init(&pxmitpriv->ack_tx_ops, 0);
206 rtw_hal_init_xmit_priv(padapter);
213 static void rtw_mfree_xmit_priv_lock (struct xmit_priv *pxmitpriv)
217 void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv)
220 struct adapter *padapter = pxmitpriv->adapter;
221 struct xmit_frame *pxmitframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
222 struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
223 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
224 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
226 rtw_hal_free_xmit_priv(padapter);
228 rtw_mfree_xmit_priv_lock(pxmitpriv);
230 if (!pxmitpriv->pxmit_frame_buf)
233 for (i = 0; i < NR_XMITFRAME; i++) {
234 rtw_os_xmit_complete(padapter, pxmitframe);
239 for (i = 0; i < NR_XMITBUFF; i++) {
240 rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
244 vfree(pxmitpriv->pallocated_frame_buf);
246 vfree(pxmitpriv->pallocated_xmitbuf);
248 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
249 for (i = 0; i < num_xmit_extbuf; i++) {
250 rtw_os_xmit_resource_free(padapter, pxmitbuf, (max_xmit_extbuf_size + XMITBUF_ALIGN_SZ));
254 vfree(pxmitpriv->pallocated_xmit_extbuf);
256 rtw_free_hwxmits(padapter);
258 _rtw_mutex_free(&pxmitpriv->ack_tx_mutex);
261 static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *pxmitframe)
264 struct pkt_attrib *pattrib = &pxmitframe->attrib;
265 struct sta_info *psta = pattrib->psta;
266 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
267 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
269 if (pattrib->nr_frags != 1)
270 sz = padapter->xmitpriv.frag_len;
272 sz = pattrib->last_txcmdsz;
274 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
275 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
276 /* Other fragments are protected by previous fragment. */
277 /* So we only need to check the length of first fragment. */
278 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
279 if (sz > padapter->registrypriv.rts_thresh) {
280 pattrib->vcs_mode = RTS_CTS;
283 pattrib->vcs_mode = RTS_CTS;
284 else if (psta->cts2self)
285 pattrib->vcs_mode = CTS_TO_SELF;
287 pattrib->vcs_mode = NONE_VCS;
292 if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS) && pattrib->ampdu_en &&
293 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
294 pattrib->vcs_mode = CTS_TO_SELF;
298 /* check ERP protection */
299 if (psta->rtsen || psta->cts2self) {
301 pattrib->vcs_mode = RTS_CTS;
302 else if (psta->cts2self)
303 pattrib->vcs_mode = CTS_TO_SELF;
308 /* check HT op mode */
309 if (pattrib->ht_en) {
310 u8 htopmode = pmlmeinfo->HT_protection;
311 if ((pmlmeext->cur_bwmode && (htopmode == 2 || htopmode == 3)) ||
312 (!pmlmeext->cur_bwmode && htopmode == 3)) {
313 pattrib->vcs_mode = RTS_CTS;
319 if (sz > padapter->registrypriv.rts_thresh) {
320 pattrib->vcs_mode = RTS_CTS;
324 /* to do list: check MIMO power save condition. */
326 /* check AMPDU aggregation for TXOP */
327 if (pattrib->ampdu_en) {
328 pattrib->vcs_mode = RTS_CTS;
332 pattrib->vcs_mode = NONE_VCS;
338 static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
341 pattrib->vcs_mode = RTS_CTS;
342 else if (psta->cts2self)
343 pattrib->vcs_mode = CTS_TO_SELF;
345 pattrib->vcs_mode = NONE_VCS;*/
349 pattrib->triggered = 0;
351 /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
352 pattrib->qos_en = psta->qos_option;
354 pattrib->raid = psta->raid;
355 pattrib->ht_en = psta->htpriv.ht_option;
356 pattrib->bwmode = psta->htpriv.bwmode;
357 pattrib->ch_offset = psta->htpriv.ch_offset;
358 pattrib->sgi = psta->htpriv.sgi;
359 pattrib->ampdu_en = false;
360 pattrib->retry_ctrl = false;
363 u8 qos_acm(u8 acm_mask, u8 priority)
365 u8 change_priority = priority;
370 if (acm_mask & BIT(1))
378 if (acm_mask & BIT(2))
383 if (acm_mask & BIT(3))
387 DBG_88E("qos_acm(): invalid pattrib->priority: %d!!!\n", priority);
391 return change_priority;
394 static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
396 struct ethhdr etherhdr;
400 _rtw_open_pktfile(ppktfile->pkt, ppktfile);
401 _rtw_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN);
403 /* get user_prio from IP hdr */
404 if (pattrib->ether_type == 0x0800) {
405 _rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
406 /* user_prio = (ntohs(ip_hdr.tos) >> 5) & 0x3; */
407 user_prio = ip_hdr.tos >> 5;
408 } else if (pattrib->ether_type == 0x888e) {
409 /* "When priority processing of data frames is supported, */
410 /* a STA's SME should send EAPOL-Key frames at the highest priority." */
414 pattrib->priority = user_prio;
415 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
416 pattrib->subtype = WIFI_QOS_DATA_TYPE;
419 static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pkt_attrib *pattrib)
421 struct pkt_file pktfile;
422 struct sta_info *psta = NULL;
423 struct ethhdr etherhdr;
426 struct sta_priv *pstapriv = &padapter->stapriv;
427 struct security_priv *psecuritypriv = &padapter->securitypriv;
428 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
429 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
434 _rtw_open_pktfile(pkt, &pktfile);
435 _rtw_pktfile_read(&pktfile, (u8 *)ðerhdr, ETH_HLEN);
437 pattrib->ether_type = ntohs(etherhdr.h_proto);
439 memcpy(pattrib->dst, ðerhdr.h_dest, ETH_ALEN);
440 memcpy(pattrib->src, ðerhdr.h_source, ETH_ALEN);
444 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
445 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
446 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
447 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
448 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
449 memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
450 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
451 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
452 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
453 memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
456 pattrib->pktlen = pktfile.pkt_len;
458 if (ETH_P_IP == pattrib->ether_type) {
459 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */
460 /* to prevent DHCP protocol fail */
462 _rtw_pktfile_read(&pktfile, &tmp[0], 24);
463 pattrib->dhcp_pkt = 0;
464 if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
465 if (ETH_P_IP == pattrib->ether_type) {/* IP header */
466 if (((tmp[21] == 68) && (tmp[23] == 67)) ||
467 ((tmp[21] == 67) && (tmp[23] == 68))) {
468 /* 68 : UDP BOOTP client */
469 /* 67 : UDP BOOTP server */
470 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====================== update_attrib: get DHCP Packet\n"));
471 /* Use low rate to send DHCP packet. */
472 pattrib->dhcp_pkt = 1;
476 } else if (0x888e == pattrib->ether_type) {
477 DBG_88E_LEVEL(_drv_info_, "send eapol packet\n");
480 if ((pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
481 rtw_set_scan_deny(padapter, 3000);
483 /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
484 if ((pattrib->ether_type == 0x0806) || (pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
485 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
487 bmcast = IS_MCAST(pattrib->ra);
491 psta = rtw_get_bcmc_stainfo(padapter);
493 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
494 if (!psta) { /* if we cannot get psta => drrp the pkt */
495 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra: %pM\n", (pattrib->ra)));
498 } else if ((check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) && (!(psta->state & _FW_LINKED))) {
505 pattrib->mac_id = psta->mac_id;
506 /* DBG_88E("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
507 pattrib->psta = psta;
509 /* if we cannot get psta => drop the pkt */
510 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:%pM\n", (pattrib->ra)));
515 pattrib->ack_policy = 0;
516 /* get ether_hdr_len */
517 pattrib->pkt_hdrlen = ETH_HLEN;/* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
519 pattrib->hdrlen = WLAN_HDR_A3_LEN;
520 pattrib->subtype = WIFI_DATA_TYPE;
521 pattrib->priority = 0;
523 if (check_fwstate(pmlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) {
524 if (psta->qos_option)
525 set_qos(&pktfile, pattrib);
527 if (pqospriv->qos_option) {
528 set_qos(&pktfile, pattrib);
530 if (pmlmepriv->acm_mask != 0)
531 pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
535 if (psta->ieee8021x_blocked) {
536 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\n psta->ieee8021x_blocked == true\n"));
538 pattrib->encrypt = 0;
540 if ((pattrib->ether_type != 0x888e) && !check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
541 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != 0x888e\n", pattrib->ether_type));
546 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
548 switch (psecuritypriv->dot11AuthAlgrthm) {
549 case dot11AuthAlgrthm_Open:
550 case dot11AuthAlgrthm_Shared:
551 case dot11AuthAlgrthm_Auto:
552 pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
554 case dot11AuthAlgrthm_8021X:
556 pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid;
558 pattrib->key_idx = 0;
561 pattrib->key_idx = 0;
566 switch (pattrib->encrypt) {
570 pattrib->icv_len = 4;
574 pattrib->icv_len = 4;
576 if (padapter->securitypriv.busetkipkey == _FAIL) {
577 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
578 ("\npadapter->securitypriv.busetkipkey(%d) == _FAIL drop packet\n",
579 padapter->securitypriv.busetkipkey));
585 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("pattrib->encrypt=%d (_AES_)\n", pattrib->encrypt));
587 pattrib->icv_len = 8;
591 pattrib->icv_len = 0;
595 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
596 ("update_attrib: encrypt=%d securitypriv.sw_encrypt=%d\n",
597 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
599 if (pattrib->encrypt &&
600 (padapter->securitypriv.sw_encrypt || !psecuritypriv->hw_decrypted)) {
601 pattrib->bswenc = true;
602 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
603 ("update_attrib: encrypt=%d securitypriv.hw_decrypted=%d bswenc = true\n",
604 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
606 pattrib->bswenc = false;
607 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("update_attrib: bswenc = false\n"));
610 rtw_set_tx_chksum_offload(pkt, pattrib);
612 update_attrib_phy_info(pattrib, psta);
619 static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitframe)
621 int curfragnum, length;
622 u8 *pframe, *payload, mic[8];
623 struct mic_data micdata;
624 struct sta_info *stainfo;
625 struct pkt_attrib *pattrib = &pxmitframe->attrib;
626 struct security_priv *psecuritypriv = &padapter->securitypriv;
627 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
628 u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
629 u8 hw_hdr_offset = 0;
630 int bmcst = IS_MCAST(pattrib->ra);
633 stainfo = pattrib->psta;
635 stainfo = rtw_get_stainfo(&padapter->stapriv, &pattrib->ra[0]);
637 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);;
639 if (pattrib->encrypt == _TKIP_) {/* if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_PRIVACY_) */
640 /* encode mic code */
642 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
643 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
646 pframe = pxmitframe->buf_addr + hw_hdr_offset;
649 if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16))
651 /* start to calculate the mic code */
652 rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
654 if (!memcmp(&stainfo->dot11tkiptxmickey.skey[0], null_key, 16)) {
658 /* start to calculate the mic code */
659 rtw_secmicsetkey(&micdata, &stainfo->dot11tkiptxmickey.skey[0]);
662 if (pframe[1]&1) { /* ToDS == 1 */
663 rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */
664 if (pframe[1]&2) /* From Ds == 1 */
665 rtw_secmicappend(&micdata, &pframe[24], 6);
667 rtw_secmicappend(&micdata, &pframe[10], 6);
668 } else { /* ToDS == 0 */
669 rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */
670 if (pframe[1]&2) /* From Ds == 1 */
671 rtw_secmicappend(&micdata, &pframe[16], 6);
673 rtw_secmicappend(&micdata, &pframe[10], 6);
677 priority[0] = (u8)pxmitframe->attrib.priority;
679 rtw_secmicappend(&micdata, &priority[0], 4);
683 for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
684 payload = (u8 *)RND4((size_t)(payload));
685 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
686 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
687 curfragnum, *payload, *(payload+1),
688 *(payload+2), *(payload+3),
689 *(payload+4), *(payload+5),
690 *(payload+6), *(payload+7)));
692 payload = payload+pattrib->hdrlen+pattrib->iv_len;
693 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
694 ("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d",
695 curfragnum, pattrib->hdrlen, pattrib->iv_len));
696 if ((curfragnum+1) == pattrib->nr_frags) {
697 length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
698 rtw_secmicappend(&micdata, payload, length);
699 payload = payload+length;
701 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
702 rtw_secmicappend(&micdata, payload, length);
703 payload = payload+length+pattrib->icv_len;
704 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum=%d length=%d pattrib->icv_len=%d", curfragnum, length, pattrib->icv_len));
707 rtw_secgetmic(&micdata, &(mic[0]));
708 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: before add mic code!!!\n"));
709 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: pattrib->last_txcmdsz=%d!!!\n", pattrib->last_txcmdsz));
710 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\
711 mic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x , mic[7]= 0x%.2x !!!!\n",
712 mic[0], mic[1], mic[2], mic[3], mic[4], mic[5], mic[6], mic[7]));
713 /* add mic code and add the mic code length in last_txcmdsz */
715 memcpy(payload, &(mic[0]), 8);
716 pattrib->last_txcmdsz += 8;
718 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("\n ======== last pkt ========\n"));
719 payload = payload-pattrib->last_txcmdsz+8;
720 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz; curfragnum = curfragnum+8)
721 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
722 (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
723 *(payload+curfragnum), *(payload+curfragnum+1),
724 *(payload+curfragnum+2), *(payload+curfragnum+3),
725 *(payload+curfragnum+4), *(payload+curfragnum+5),
726 *(payload+curfragnum+6), *(payload+curfragnum+7)));
728 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: rtw_get_stainfo==NULL!!!\n"));
735 static s32 xmitframe_swencrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
737 struct pkt_attrib *pattrib = &pxmitframe->attrib;
739 if (pattrib->bswenc) {
740 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("### xmitframe_swencrypt\n"));
741 switch (pattrib->encrypt) {
744 rtw_wep_encrypt(padapter, (u8 *)pxmitframe);
747 rtw_tkip_encrypt(padapter, (u8 *)pxmitframe);
750 rtw_aes_encrypt(padapter, (u8 *)pxmitframe);
756 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_, ("### xmitframe_hwencrypt\n"));
762 s32 rtw_make_wlanhdr (struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib)
766 struct rtw_ieee80211_hdr *pwlanhdr = (struct rtw_ieee80211_hdr *)hdr;
767 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
768 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
769 u8 qos_option = false;
772 __le16 *fctrl = &pwlanhdr->frame_ctl;
774 struct sta_info *psta;
776 int bmcst = IS_MCAST(pattrib->ra);
779 psta = pattrib->psta;
782 psta = rtw_get_bcmc_stainfo(padapter);
784 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
788 memset(hdr, 0, WLANHDR_OFFSET);
790 SetFrameSubType(fctrl, pattrib->subtype);
792 if (pattrib->subtype & WIFI_DATA_TYPE) {
793 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)) {
794 /* to_ds = 1, fr_ds = 0; */
795 /* Data transfer to AP */
797 memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
798 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
799 memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
801 if (pqospriv->qos_option)
803 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
804 /* to_ds = 0, fr_ds = 1; */
806 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
807 memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), ETH_ALEN);
808 memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
810 if (psta->qos_option)
812 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
813 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
814 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
815 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
816 memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
818 if (psta->qos_option)
821 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv)));
829 if (pattrib->encrypt)
833 qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
835 if (pattrib->priority)
836 SetPriority(qc, pattrib->priority);
838 SetEOSP(qc, pattrib->eosp);
840 SetAckpolicy(qc, pattrib->ack_policy);
843 /* TODO: fill HT Control Field */
845 /* Update Seq Num will be handled by f/w */
847 psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
848 psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
850 pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
852 SetSeqNum(hdr, pattrib->seqnum);
854 /* check if enable ampdu */
855 if (pattrib->ht_en && psta->htpriv.ampdu_enable) {
856 if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
857 pattrib->ampdu_en = true;
860 /* re-check if enable ampdu by BA_starting_seqctrl */
861 if (pattrib->ampdu_en) {
864 tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
866 /* check BA_starting_seqctrl */
867 if (SN_LESS(pattrib->seqnum, tx_seq)) {
868 pattrib->ampdu_en = false;/* AGG BK */
869 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
870 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
872 pattrib->ampdu_en = true;/* AGG EN */
874 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
875 pattrib->ampdu_en = true;/* AGG EN */
885 s32 rtw_txframes_pending(struct adapter *padapter)
887 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
889 return (!list_empty(&pxmitpriv->be_pending.queue) ||
890 !list_empty(&pxmitpriv->bk_pending.queue) ||
891 !list_empty(&pxmitpriv->vi_pending.queue) ||
892 !list_empty(&pxmitpriv->vo_pending.queue));
895 s32 rtw_txframes_sta_ac_pending(struct adapter *padapter, struct pkt_attrib *pattrib)
897 struct sta_info *psta;
898 struct tx_servq *ptxservq;
899 int priority = pattrib->priority;
901 psta = pattrib->psta;
906 ptxservq = &(psta->sta_xmitpriv.bk_q);
910 ptxservq = &(psta->sta_xmitpriv.vi_q);
914 ptxservq = &(psta->sta_xmitpriv.vo_q);
919 ptxservq = &(psta->sta_xmitpriv.be_q);
924 return ptxservq->qcnt;
929 * Calculate wlan 802.11 packet MAX size from pkt_attrib
930 * This function doesn't consider fragment case
932 u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib)
936 len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */
937 len += SNAP_SIZE + sizeof(u16); /* LLC */
938 len += pattrib->pktlen;
939 if (pattrib->encrypt == _TKIP_)
941 len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */
948 This sub-routine will perform all the following:
950 1. remove 802.3 header.
951 2. create wlan_header, based on the info in pxmitframe
952 3. append sta's iv/ext-iv
954 5. move frag chunk from pframe to pxmitframe->mem
955 6. apply sw-encrypt, if necessary.
958 s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe)
960 struct pkt_file pktfile;
961 s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
963 u8 *pframe, *mem_start;
965 struct sta_info *psta;
966 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
967 struct pkt_attrib *pattrib = &pxmitframe->attrib;
969 s32 bmcst = IS_MCAST(pattrib->ra);
975 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
980 if (!pxmitframe->buf_addr) {
981 DBG_88E("==> %s buf_addr == NULL\n", __func__);
985 pbuf_start = pxmitframe->buf_addr;
987 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
989 mem_start = pbuf_start + hw_hdr_offset;
991 if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
992 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n"));
993 DBG_88E("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n");
998 _rtw_open_pktfile(pkt, &pktfile);
999 _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
1002 frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
1011 SetMFrag(mem_start);
1013 pframe += pattrib->hdrlen;
1014 mpdu_len -= pattrib->hdrlen;
1016 /* adding icv, if necessary... */
1017 if (pattrib->iv_len) {
1019 switch (pattrib->encrypt) {
1022 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1026 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1028 TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
1032 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1034 AES_IV(pattrib->iv, psta->dot11txpn, 0);
1039 memcpy(pframe, pattrib->iv, pattrib->iv_len);
1041 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
1042 ("rtw_xmitframe_coalesce: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n",
1043 padapter->securitypriv.dot11PrivacyKeyIndex, pattrib->iv[3], *pframe, *(pframe+1), *(pframe+2), *(pframe+3)));
1045 pframe += pattrib->iv_len;
1047 mpdu_len -= pattrib->iv_len;
1051 llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
1056 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1057 mpdu_len -= pattrib->icv_len;
1061 /* don't do fragment to broadcat/multicast packets */
1062 mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen);
1064 mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
1069 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1070 memcpy(pframe, pattrib->icv, pattrib->icv_len);
1071 pframe += pattrib->icv_len;
1076 if (bmcst || rtw_endofpktfile(&pktfile)) {
1077 pattrib->nr_frags = frg_inx;
1079 pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz : 0) +
1080 ((pattrib->bswenc) ? pattrib->icv_len : 0) + mem_sz;
1082 ClearMFrag(mem_start);
1086 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("%s: There're still something in packet!\n", __func__));
1089 addr = (size_t)(pframe);
1091 mem_start = (unsigned char *)RND4(addr) + hw_hdr_offset;
1092 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
1095 if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
1096 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
1097 DBG_88E("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
1102 xmitframe_swencrypt(padapter, pxmitframe);
1105 update_attrib_vcs_info(padapter, pxmitframe);
1107 pattrib->vcs_mode = NONE_VCS;
1114 /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1115 * IEEE LLC/SNAP header contains 8 octets
1116 * First 3 octets comprise the LLC portion
1117 * SNAP portion, 5 octets, is divided into two fields:
1118 * Organizationally Unique Identifier(OUI), 3 octets,
1119 * type, defined by that organization, 2 octets.
1121 s32 rtw_put_snap(u8 *data, u16 h_proto)
1123 struct ieee80211_snap_hdr *snap;
1126 snap = (struct ieee80211_snap_hdr *)data;
1131 if (h_proto == 0x8137 || h_proto == 0x80f3)
1136 snap->oui[0] = oui[0];
1137 snap->oui[1] = oui[1];
1138 snap->oui[2] = oui[2];
1140 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
1142 return SNAP_SIZE + sizeof(u16);
1145 void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len)
1150 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1151 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1153 switch (pxmitpriv->vcs_setting) {
1155 pxmitpriv->vcs = NONE_VCS;
1161 perp = rtw_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
1163 pxmitpriv->vcs = NONE_VCS;
1165 protection = (*(perp + 2)) & BIT(1);
1167 if (pregistrypriv->vcs_type == RTS_CTS)
1168 pxmitpriv->vcs = RTS_CTS;
1170 pxmitpriv->vcs = CTS_TO_SELF;
1172 pxmitpriv->vcs = NONE_VCS;
1180 void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz)
1182 struct sta_info *psta = NULL;
1183 struct stainfo_stats *pstats = NULL;
1184 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1185 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1187 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) {
1188 pxmitpriv->tx_bytes += sz;
1189 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pxmitframe->agg_num;
1191 psta = pxmitframe->attrib.psta;
1193 pstats = &psta->sta_stats;
1194 pstats->tx_pkts += pxmitframe->agg_num;
1195 pstats->tx_bytes += sz;
1200 struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
1202 struct xmit_buf *pxmitbuf = NULL;
1203 struct list_head *plist, *phead;
1204 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1205 unsigned long flags;
1207 spin_lock_irqsave(&pfree_queue->lock, flags);
1209 if (list_empty(&pfree_queue->queue)) {
1212 phead = get_list_head(pfree_queue);
1214 plist = phead->next;
1216 pxmitbuf = container_of(plist, struct xmit_buf, list);
1218 list_del_init(&(pxmitbuf->list));
1222 pxmitpriv->free_xmit_extbuf_cnt--;
1224 pxmitbuf->priv_data = NULL;
1225 /* pxmitbuf->ext_tag = true; */
1227 if (pxmitbuf->sctx) {
1228 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1229 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1233 spin_unlock_irqrestore(&pfree_queue->lock, flags);
1238 s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1240 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1241 unsigned long flags;
1246 spin_lock_irqsave(&pfree_queue->lock, flags);
1248 list_del_init(&pxmitbuf->list);
1250 list_add_tail(&(pxmitbuf->list), get_list_head(pfree_queue));
1251 pxmitpriv->free_xmit_extbuf_cnt++;
1253 spin_unlock_irqrestore(&pfree_queue->lock, flags);
1258 struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
1260 struct xmit_buf *pxmitbuf = NULL;
1261 struct list_head *plist, *phead;
1262 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1263 unsigned long flags;
1265 /* DBG_88E("+rtw_alloc_xmitbuf\n"); */
1267 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, flags);
1269 if (list_empty(&pfree_xmitbuf_queue->queue)) {
1272 phead = get_list_head(pfree_xmitbuf_queue);
1274 plist = phead->next;
1276 pxmitbuf = container_of(plist, struct xmit_buf, list);
1278 list_del_init(&(pxmitbuf->list));
1282 pxmitpriv->free_xmitbuf_cnt--;
1283 pxmitbuf->priv_data = NULL;
1284 if (pxmitbuf->sctx) {
1285 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1286 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1289 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, flags);
1294 s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1296 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1297 unsigned long flags;
1302 if (pxmitbuf->sctx) {
1303 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1304 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
1307 if (pxmitbuf->ext_tag) {
1308 rtw_free_xmitbuf_ext(pxmitpriv, pxmitbuf);
1310 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, flags);
1312 list_del_init(&pxmitbuf->list);
1314 list_add_tail(&(pxmitbuf->list), get_list_head(pfree_xmitbuf_queue));
1316 pxmitpriv->free_xmitbuf_cnt++;
1317 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, flags);
1326 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
1328 If we turn on USE_RXTHREAD, then, no need for critical section.
1329 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
1331 Must be very very cautious...
1335 struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)/* _queue *pfree_xmit_queue) */
1338 Please remember to use all the osdep_service api,
1339 and lock/unlock or _enter/_exit critical to protect
1343 struct xmit_frame *pxframe = NULL;
1344 struct list_head *plist, *phead;
1345 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1347 spin_lock_bh(&pfree_xmit_queue->lock);
1349 if (list_empty(&pfree_xmit_queue->queue)) {
1350 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe:%d\n", pxmitpriv->free_xmitframe_cnt));
1353 phead = get_list_head(pfree_xmit_queue);
1355 plist = phead->next;
1357 pxframe = container_of(plist, struct xmit_frame, list);
1359 list_del_init(&(pxframe->list));
1362 if (pxframe) { /* default value setting */
1363 pxmitpriv->free_xmitframe_cnt--;
1365 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
1367 pxframe->buf_addr = NULL;
1368 pxframe->pxmitbuf = NULL;
1370 memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
1371 /* pxframe->attrib.psta = NULL; */
1373 pxframe->frame_tag = DATA_FRAMETAG;
1375 pxframe->pkt = NULL;
1376 pxframe->pkt_offset = 1;/* default use pkt_offset to fill tx desc */
1378 pxframe->agg_num = 1;
1379 pxframe->ack_report = 0;
1382 spin_unlock_bh(&pfree_xmit_queue->lock);
1387 s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
1389 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1390 struct adapter *padapter = pxmitpriv->adapter;
1391 struct sk_buff *pndis_pkt = NULL;
1394 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====== rtw_free_xmitframe():pxmitframe == NULL!!!!!!!!!!\n"));
1398 spin_lock_bh(&pfree_xmit_queue->lock);
1400 list_del_init(&pxmitframe->list);
1402 if (pxmitframe->pkt) {
1403 pndis_pkt = pxmitframe->pkt;
1404 pxmitframe->pkt = NULL;
1407 list_add_tail(&pxmitframe->list, get_list_head(pfree_xmit_queue));
1409 pxmitpriv->free_xmitframe_cnt++;
1410 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
1412 spin_unlock_bh(&pfree_xmit_queue->lock);
1415 rtw_os_pkt_complete(padapter, pndis_pkt);
1422 void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue)
1424 struct list_head *plist, *phead;
1425 struct xmit_frame *pxmitframe;
1427 spin_lock_bh(&pframequeue->lock);
1429 phead = get_list_head(pframequeue);
1430 plist = phead->next;
1432 while (phead != plist) {
1433 pxmitframe = container_of(plist, struct xmit_frame, list);
1435 plist = plist->next;
1437 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1439 spin_unlock_bh(&pframequeue->lock);
1443 s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
1445 if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL) {
1446 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1447 ("rtw_xmitframe_enqueue: drop xmit pkt for classifier fail\n"));
1448 /* pxmitframe->pkt = NULL; */
1455 static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit, struct tx_servq *ptxservq, struct __queue *pframe_queue)
1457 struct list_head *xmitframe_plist, *xmitframe_phead;
1458 struct xmit_frame *pxmitframe = NULL;
1460 xmitframe_phead = get_list_head(pframe_queue);
1461 xmitframe_plist = xmitframe_phead->next;
1463 if (xmitframe_phead != xmitframe_plist) {
1464 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1466 xmitframe_plist = xmitframe_plist->next;
1468 list_del_init(&pxmitframe->list);
1475 struct xmit_frame *rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i, int entry)
1477 struct list_head *sta_plist, *sta_phead;
1478 struct hw_xmit *phwxmit;
1479 struct tx_servq *ptxservq = NULL;
1480 struct __queue *pframe_queue = NULL;
1481 struct xmit_frame *pxmitframe = NULL;
1482 struct adapter *padapter = pxmitpriv->adapter;
1483 struct registry_priv *pregpriv = &padapter->registrypriv;
1486 inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
1488 if (pregpriv->wifi_spec == 1) {
1491 for (j = 0; j < 4; j++)
1492 inx[j] = pxmitpriv->wmm_para_seq[j];
1495 spin_lock_bh(&pxmitpriv->lock);
1497 for (i = 0; i < entry; i++) {
1498 phwxmit = phwxmit_i + inx[i];
1500 sta_phead = get_list_head(phwxmit->sta_queue);
1501 sta_plist = sta_phead->next;
1503 while (sta_phead != sta_plist) {
1504 ptxservq = container_of(sta_plist, struct tx_servq, tx_pending);
1506 pframe_queue = &ptxservq->sta_pending;
1508 pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit, ptxservq, pframe_queue);
1513 /* Remove sta node when there are no pending packets. */
1514 if (list_empty(&pframe_queue->queue)) /* must be done after get_next and before break */
1515 list_del_init(&ptxservq->tx_pending);
1519 sta_plist = sta_plist->next;
1523 spin_unlock_bh(&pxmitpriv->lock);
1528 struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, int up, u8 *ac)
1530 struct tx_servq *ptxservq;
1535 ptxservq = &(psta->sta_xmitpriv.bk_q);
1537 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BK\n"));
1541 ptxservq = &(psta->sta_xmitpriv.vi_q);
1543 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VI\n"));
1547 ptxservq = &(psta->sta_xmitpriv.vo_q);
1549 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VO\n"));
1554 ptxservq = &(psta->sta_xmitpriv.be_q);
1556 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BE\n"));
1564 * Will enqueue pxmitframe to the proper queue,
1565 * and indicate it to xx_pending list.....
1567 s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe)
1570 struct sta_info *psta;
1571 struct tx_servq *ptxservq;
1572 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1573 struct sta_priv *pstapriv = &padapter->stapriv;
1574 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
1577 if (pattrib->psta) {
1578 psta = pattrib->psta;
1580 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
1585 DBG_88E("rtw_xmit_classifier: psta == NULL\n");
1586 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmit_classifier: psta == NULL\n"));
1590 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
1592 if (list_empty(&ptxservq->tx_pending))
1593 list_add_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue));
1595 list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
1597 phwxmits[ac_index].accnt++;
1603 void rtw_alloc_hwxmits(struct adapter *padapter)
1605 struct hw_xmit *hwxmits;
1606 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1608 pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
1610 pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL);
1612 hwxmits = pxmitpriv->hwxmits;
1614 if (pxmitpriv->hwxmit_entry == 5) {
1615 hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
1616 hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
1617 hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
1618 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1619 hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
1620 } else if (pxmitpriv->hwxmit_entry == 4) {
1621 hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
1622 hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
1623 hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
1624 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1629 void rtw_free_hwxmits(struct adapter *padapter)
1631 struct hw_xmit *hwxmits;
1632 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1634 hwxmits = pxmitpriv->hwxmits;
1638 void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry)
1642 for (i = 0; i < entry; i++, phwxmit++)
1647 static int rtw_br_client_tx(struct adapter *padapter, struct sk_buff **pskb)
1649 struct sk_buff *skb = *pskb;
1650 int res, is_vlan_tag = 0, i, do_nat25 = 1;
1651 unsigned short vlan_hdr = 0;
1652 void *br_port = NULL;
1655 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
1657 spin_lock_bh(&padapter->br_ext_lock);
1658 if (!(skb->data[0] & 1) && br_port &&
1659 memcmp(skb->data+MACADDRLEN, padapter->br_mac, MACADDRLEN) &&
1660 *((__be16 *)(skb->data+MACADDRLEN*2)) != __constant_htons(ETH_P_8021Q) &&
1661 *((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP) &&
1662 !memcmp(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN) && padapter->scdb_entry) {
1663 memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
1664 padapter->scdb_entry->ageing_timer = jiffies;
1665 spin_unlock_bh(&padapter->br_ext_lock);
1667 if (*((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_8021Q)) {
1669 vlan_hdr = *((unsigned short *)(skb->data+MACADDRLEN*2+2));
1670 for (i = 0; i < 6; i++)
1671 *((unsigned short *)(skb->data+MACADDRLEN*2+2-i*2)) = *((unsigned short *)(skb->data+MACADDRLEN*2-2-i*2));
1674 if (!memcmp(skb->data+MACADDRLEN, padapter->br_mac, MACADDRLEN) &&
1675 (*((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP)))
1676 memcpy(padapter->br_ip, skb->data+WLAN_ETHHDR_LEN+12, 4);
1678 if (*((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP)) {
1679 if (memcmp(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN)) {
1680 padapter->scdb_entry = (struct nat25_network_db_entry *)scdb_findEntry(padapter,
1681 skb->data+MACADDRLEN, skb->data+WLAN_ETHHDR_LEN+12);
1682 if (padapter->scdb_entry) {
1683 memcpy(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN);
1684 memcpy(padapter->scdb_ip, skb->data+WLAN_ETHHDR_LEN+12, 4);
1685 padapter->scdb_entry->ageing_timer = jiffies;
1689 if (padapter->scdb_entry) {
1690 padapter->scdb_entry->ageing_timer = jiffies;
1693 memset(padapter->scdb_mac, 0, MACADDRLEN);
1694 memset(padapter->scdb_ip, 0, 4);
1698 spin_unlock_bh(&padapter->br_ext_lock);
1700 if (nat25_db_handle(padapter, skb, NAT25_CHECK) == 0) {
1701 struct sk_buff *newskb;
1705 for (i = 0; i < 6; i++)
1706 *((unsigned short *)(skb->data+i*2)) = *((unsigned short *)(skb->data+4+i*2));
1707 *((__be16 *)(skb->data+MACADDRLEN*2)) = __constant_htons(ETH_P_8021Q);
1708 *((unsigned short *)(skb->data+MACADDRLEN*2+2)) = vlan_hdr;
1711 newskb = skb_copy(skb, GFP_ATOMIC);
1713 DEBUG_ERR("TX DROP: skb_copy fail!\n");
1716 dev_kfree_skb_any(skb);
1718 *pskb = skb = newskb;
1720 vlan_hdr = *((unsigned short *)(skb->data+MACADDRLEN*2+2));
1721 for (i = 0; i < 6; i++)
1722 *((unsigned short *)(skb->data+MACADDRLEN*2+2-i*2)) = *((unsigned short *)(skb->data+MACADDRLEN*2-2-i*2));
1727 if (skb_is_nonlinear(skb))
1728 DEBUG_ERR("%s(): skb_is_nonlinear!!\n", __func__);
1730 res = skb_linearize(skb);
1732 DEBUG_ERR("TX DROP: skb_linearize fail!\n");
1736 res = nat25_db_handle(padapter, skb, NAT25_INSERT);
1739 DEBUG_ERR("TX DROP: nat25_db_handle fail!\n");
1746 memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
1748 dhcp_flag_bcast(padapter, skb);
1752 for (i = 0; i < 6; i++)
1753 *((unsigned short *)(skb->data+i*2)) = *((unsigned short *)(skb->data+4+i*2));
1754 *((__be16 *)(skb->data+MACADDRLEN*2)) = __constant_htons(ETH_P_8021Q);
1755 *((unsigned short *)(skb->data+MACADDRLEN*2+2)) = vlan_hdr;
1759 /* check if SA is equal to our MAC */
1760 if (memcmp(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN)) {
1761 DEBUG_ERR("TX DROP: untransformed frame SA:%02X%02X%02X%02X%02X%02X!\n",
1762 skb->data[6], skb->data[7], skb->data[8], skb->data[9], skb->data[10], skb->data[11]);
1768 u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe)
1771 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1773 switch (pattrib->qsel) {
1776 addr = BE_QUEUE_INX;
1780 addr = BK_QUEUE_INX;
1784 addr = VI_QUEUE_INX;
1788 addr = VO_QUEUE_INX;
1791 addr = BCN_QUEUE_INX;
1793 case 0x11:/* BC/MC in PS (HIQ) */
1794 addr = HIGH_QUEUE_INX;
1798 addr = MGT_QUEUE_INX;
1805 static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib)
1809 qsel = pattrib->priority;
1810 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("### do_queue_select priority=%d , qsel = %d\n", pattrib->priority, qsel));
1812 pattrib->qsel = qsel;
1816 * The main transmit(tx) entry
1820 * 0 success, hardware will handle this xmit frame(packet)
1823 s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)
1825 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1826 struct xmit_frame *pxmitframe = NULL;
1827 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1828 void *br_port = NULL;
1831 pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
1833 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: no more pxmitframe\n"));
1834 DBG_88E("DBG_TX_DROP_FRAME %s no more pxmitframe\n", __func__);
1839 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
1842 if (br_port && check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE)) {
1843 res = rtw_br_client_tx(padapter, ppkt);
1845 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1850 res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
1853 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: update attrib fail\n"));
1854 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1857 pxmitframe->pkt = *ppkt;
1859 rtw_led_control(padapter, LED_CTL_TX);
1861 do_queue_select(padapter, &pxmitframe->attrib);
1863 #ifdef CONFIG_88EU_AP_MODE
1864 spin_lock_bh(&pxmitpriv->lock);
1865 if (xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe)) {
1866 spin_unlock_bh(&pxmitpriv->lock);
1869 spin_unlock_bh(&pxmitpriv->lock);
1872 if (rtw_hal_xmit(padapter, pxmitframe) == false)
1878 #if defined(CONFIG_88EU_AP_MODE)
1880 int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe)
1883 struct sta_info *psta = NULL;
1884 struct sta_priv *pstapriv = &padapter->stapriv;
1885 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1886 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1887 int bmcst = IS_MCAST(pattrib->ra);
1889 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false)
1893 psta = pattrib->psta;
1895 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
1900 if (pattrib->triggered == 1) {
1902 pattrib->qsel = 0x11;/* HIQ */
1907 spin_lock_bh(&psta->sleep_q.lock);
1909 if (pstapriv->sta_dz_bitmap) {/* if any one sta is in ps mode */
1910 list_del_init(&pxmitframe->list);
1912 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
1916 pstapriv->tim_bitmap |= BIT(0);/* */
1917 pstapriv->sta_dz_bitmap |= BIT(0);
1919 update_beacon(padapter, _TIM_IE_, NULL, false);/* tx bc/mc packets after upate bcn */
1924 spin_unlock_bh(&psta->sleep_q.lock);
1929 spin_lock_bh(&psta->sleep_q.lock);
1931 if (psta->state&WIFI_SLEEP_STATE) {
1934 if (pstapriv->sta_dz_bitmap&BIT(psta->aid)) {
1935 list_del_init(&pxmitframe->list);
1937 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
1941 switch (pattrib->priority) {
1944 wmmps_ac = psta->uapsd_bk&BIT(0);
1948 wmmps_ac = psta->uapsd_vi&BIT(0);
1952 wmmps_ac = psta->uapsd_vo&BIT(0);
1957 wmmps_ac = psta->uapsd_be&BIT(0);
1962 psta->sleepq_ac_len++;
1964 if (((psta->has_legacy_ac) && (!wmmps_ac)) ||
1965 ((!psta->has_legacy_ac) && (wmmps_ac))) {
1966 pstapriv->tim_bitmap |= BIT(psta->aid);
1968 if (psta->sleepq_len == 1) {
1969 /* upate BCN for TIM IE */
1970 update_beacon(padapter, _TIM_IE_, NULL, false);
1977 spin_unlock_bh(&psta->sleep_q.lock);
1982 static void dequeue_xmitframes_to_sleeping_queue(struct adapter *padapter, struct sta_info *psta, struct __queue *pframequeue)
1984 struct list_head *plist, *phead;
1986 struct tx_servq *ptxservq;
1987 struct pkt_attrib *pattrib;
1988 struct xmit_frame *pxmitframe;
1989 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
1991 phead = get_list_head(pframequeue);
1992 plist = phead->next;
1994 while (phead != plist) {
1995 pxmitframe = container_of(plist, struct xmit_frame, list);
1997 plist = plist->next;
1999 xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe);
2001 pattrib = &pxmitframe->attrib;
2003 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
2006 phwxmits[ac_index].accnt--;
2010 void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta)
2012 struct sta_info *psta_bmc;
2013 struct sta_xmit_priv *pstaxmitpriv;
2014 struct sta_priv *pstapriv = &padapter->stapriv;
2015 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2017 pstaxmitpriv = &psta->sta_xmitpriv;
2019 /* for BC/MC Frames */
2020 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2022 spin_lock_bh(&pxmitpriv->lock);
2024 psta->state |= WIFI_SLEEP_STATE;
2026 pstapriv->sta_dz_bitmap |= BIT(psta->aid);
2028 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
2029 list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
2031 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
2032 list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
2034 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending);
2035 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
2037 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending);
2038 list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
2040 /* for BC/MC Frames */
2041 pstaxmitpriv = &psta_bmc->sta_xmitpriv;
2042 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending);
2043 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
2045 spin_unlock_bh(&pxmitpriv->lock);
2048 void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta)
2050 u8 update_mask = 0, wmmps_ac = 0;
2051 struct sta_info *psta_bmc;
2052 struct list_head *xmitframe_plist, *xmitframe_phead;
2053 struct xmit_frame *pxmitframe = NULL;
2054 struct sta_priv *pstapriv = &padapter->stapriv;
2056 spin_lock_bh(&psta->sleep_q.lock);
2058 xmitframe_phead = get_list_head(&psta->sleep_q);
2059 xmitframe_plist = xmitframe_phead->next;
2061 while (xmitframe_phead != xmitframe_plist) {
2062 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
2064 xmitframe_plist = xmitframe_plist->next;
2066 list_del_init(&pxmitframe->list);
2068 switch (pxmitframe->attrib.priority) {
2071 wmmps_ac = psta->uapsd_bk&BIT(1);
2075 wmmps_ac = psta->uapsd_vi&BIT(1);
2079 wmmps_ac = psta->uapsd_vo&BIT(1);
2084 wmmps_ac = psta->uapsd_be&BIT(1);
2089 if (psta->sleepq_len > 0)
2090 pxmitframe->attrib.mdata = 1;
2092 pxmitframe->attrib.mdata = 0;
2095 psta->sleepq_ac_len--;
2096 if (psta->sleepq_ac_len > 0) {
2097 pxmitframe->attrib.mdata = 1;
2098 pxmitframe->attrib.eosp = 0;
2100 pxmitframe->attrib.mdata = 0;
2101 pxmitframe->attrib.eosp = 1;
2105 pxmitframe->attrib.triggered = 1;
2107 spin_unlock_bh(&psta->sleep_q.lock);
2108 if (rtw_hal_xmit(padapter, pxmitframe))
2109 rtw_os_xmit_complete(padapter, pxmitframe);
2110 spin_lock_bh(&psta->sleep_q.lock);
2113 if (psta->sleepq_len == 0) {
2114 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2116 update_mask = BIT(0);
2118 if (psta->state&WIFI_SLEEP_STATE)
2119 psta->state ^= WIFI_SLEEP_STATE;
2121 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
2122 psta->expire_to = pstapriv->expire_to;
2123 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
2126 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
2129 spin_unlock_bh(&psta->sleep_q.lock);
2131 /* for BC/MC Frames */
2132 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2136 if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) { /* no any sta in ps mode */
2137 spin_lock_bh(&psta_bmc->sleep_q.lock);
2139 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
2140 xmitframe_plist = xmitframe_phead->next;
2142 while (xmitframe_phead != xmitframe_plist) {
2143 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
2145 xmitframe_plist = xmitframe_plist->next;
2147 list_del_init(&pxmitframe->list);
2149 psta_bmc->sleepq_len--;
2150 if (psta_bmc->sleepq_len > 0)
2151 pxmitframe->attrib.mdata = 1;
2153 pxmitframe->attrib.mdata = 0;
2155 pxmitframe->attrib.triggered = 1;
2157 spin_unlock_bh(&psta_bmc->sleep_q.lock);
2158 if (rtw_hal_xmit(padapter, pxmitframe))
2159 rtw_os_xmit_complete(padapter, pxmitframe);
2160 spin_lock_bh(&psta_bmc->sleep_q.lock);
2163 if (psta_bmc->sleepq_len == 0) {
2164 pstapriv->tim_bitmap &= ~BIT(0);
2165 pstapriv->sta_dz_bitmap &= ~BIT(0);
2167 update_mask |= BIT(1);
2170 spin_unlock_bh(&psta_bmc->sleep_q.lock);
2174 update_beacon(padapter, _TIM_IE_, NULL, false);
2177 void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta)
2180 struct list_head *xmitframe_plist, *xmitframe_phead;
2181 struct xmit_frame *pxmitframe = NULL;
2182 struct sta_priv *pstapriv = &padapter->stapriv;
2184 spin_lock_bh(&psta->sleep_q.lock);
2186 xmitframe_phead = get_list_head(&psta->sleep_q);
2187 xmitframe_plist = xmitframe_phead->next;
2189 while (xmitframe_phead != xmitframe_plist) {
2190 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
2192 xmitframe_plist = xmitframe_plist->next;
2194 switch (pxmitframe->attrib.priority) {
2197 wmmps_ac = psta->uapsd_bk&BIT(1);
2201 wmmps_ac = psta->uapsd_vi&BIT(1);
2205 wmmps_ac = psta->uapsd_vo&BIT(1);
2210 wmmps_ac = psta->uapsd_be&BIT(1);
2217 list_del_init(&pxmitframe->list);
2220 psta->sleepq_ac_len--;
2222 if (psta->sleepq_ac_len > 0) {
2223 pxmitframe->attrib.mdata = 1;
2224 pxmitframe->attrib.eosp = 0;
2226 pxmitframe->attrib.mdata = 0;
2227 pxmitframe->attrib.eosp = 1;
2230 pxmitframe->attrib.triggered = 1;
2232 if (rtw_hal_xmit(padapter, pxmitframe) == true)
2233 rtw_os_xmit_complete(padapter, pxmitframe);
2235 if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) && (wmmps_ac)) {
2236 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2238 /* upate BCN for TIM IE */
2239 update_beacon(padapter, _TIM_IE_, NULL, false);
2243 spin_unlock_bh(&psta->sleep_q.lock);
2248 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms)
2250 sctx->timeout_ms = timeout_ms;
2251 sctx->submit_time = jiffies;
2252 init_completion(&sctx->done);
2253 sctx->status = RTW_SCTX_SUBMITTED;
2256 int rtw_sctx_wait(struct submit_ctx *sctx)
2259 unsigned long expire;
2262 expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) : MAX_SCHEDULE_TIMEOUT;
2263 if (!wait_for_completion_timeout(&sctx->done, expire)) {
2264 /* timeout, do something?? */
2265 status = RTW_SCTX_DONE_TIMEOUT;
2266 DBG_88E("%s timeout\n", __func__);
2268 status = sctx->status;
2271 if (status == RTW_SCTX_DONE_SUCCESS)
2277 static bool rtw_sctx_chk_waring_status(int status)
2280 case RTW_SCTX_DONE_UNKNOWN:
2281 case RTW_SCTX_DONE_BUF_ALLOC:
2282 case RTW_SCTX_DONE_BUF_FREE:
2284 case RTW_SCTX_DONE_DRV_STOP:
2285 case RTW_SCTX_DONE_DEV_REMOVE:
2292 void rtw_sctx_done_err(struct submit_ctx **sctx, int status)
2295 if (rtw_sctx_chk_waring_status(status))
2296 DBG_88E("%s status:%d\n", __func__, status);
2297 (*sctx)->status = status;
2298 complete(&((*sctx)->done));
2303 void rtw_sctx_done(struct submit_ctx **sctx)
2305 rtw_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS);
2308 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms)
2310 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2312 pack_tx_ops->submit_time = jiffies;
2313 pack_tx_ops->timeout_ms = timeout_ms;
2314 pack_tx_ops->status = RTW_SCTX_SUBMITTED;
2316 return rtw_sctx_wait(pack_tx_ops);
2319 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status)
2321 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2323 if (pxmitpriv->ack_tx)
2324 rtw_sctx_done_err(&pack_tx_ops, status);
2326 DBG_88E("%s ack_tx not set\n", __func__);