1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <osdep_service.h>
23 #include <drv_types.h>
25 #include <osdep_intf.h>
28 #include <usb_osintf.h>
30 static u8 P802_1H_OUI
[P80211_OUI_LEN
] = { 0x00, 0x00, 0xf8 };
31 static u8 RFC1042_OUI
[P80211_OUI_LEN
] = { 0x00, 0x00, 0x00 };
33 static void _init_txservq(struct tx_servq
*ptxservq
)
36 _rtw_init_listhead(&ptxservq
->tx_pending
);
37 _rtw_init_queue(&ptxservq
->sta_pending
);
42 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv
*psta_xmitpriv
)
45 _rtw_memset((unsigned char *)psta_xmitpriv
, 0, sizeof (struct sta_xmit_priv
));
46 _rtw_spinlock_init(&psta_xmitpriv
->lock
);
47 _init_txservq(&psta_xmitpriv
->be_q
);
48 _init_txservq(&psta_xmitpriv
->bk_q
);
49 _init_txservq(&psta_xmitpriv
->vi_q
);
50 _init_txservq(&psta_xmitpriv
->vo_q
);
51 _rtw_init_listhead(&psta_xmitpriv
->legacy_dz
);
52 _rtw_init_listhead(&psta_xmitpriv
->apsd
);
57 s32
_rtw_init_xmit_priv(struct xmit_priv
*pxmitpriv
, struct adapter
*padapter
)
60 struct xmit_buf
*pxmitbuf
;
61 struct xmit_frame
*pxframe
;
63 u32 max_xmit_extbuf_size
= MAX_XMIT_EXTBUF_SZ
;
64 u32 num_xmit_extbuf
= NR_XMIT_EXTBUFF
;
68 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */
70 _rtw_spinlock_init(&pxmitpriv
->lock
);
71 _rtw_init_sema(&pxmitpriv
->xmit_sema
, 0);
72 _rtw_init_sema(&pxmitpriv
->terminate_xmitthread_sema
, 0);
75 Please insert all the queue initializaiton using _rtw_init_queue below
78 pxmitpriv
->adapter
= padapter
;
80 _rtw_init_queue(&pxmitpriv
->be_pending
);
81 _rtw_init_queue(&pxmitpriv
->bk_pending
);
82 _rtw_init_queue(&pxmitpriv
->vi_pending
);
83 _rtw_init_queue(&pxmitpriv
->vo_pending
);
84 _rtw_init_queue(&pxmitpriv
->bm_pending
);
86 _rtw_init_queue(&pxmitpriv
->free_xmit_queue
);
89 Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
90 and initialize free_xmit_frame below.
91 Please also apply free_txobj to link_up all the xmit_frames...
94 pxmitpriv
->pallocated_frame_buf
= rtw_zvmalloc(NR_XMITFRAME
* sizeof(struct xmit_frame
) + 4);
96 if (pxmitpriv
->pallocated_frame_buf
== NULL
) {
97 pxmitpriv
->pxmit_frame_buf
= NULL
;
98 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("alloc xmit_frame fail!\n"));
102 pxmitpriv
->pxmit_frame_buf
= (u8
*)N_BYTE_ALIGMENT((size_t)(pxmitpriv
->pallocated_frame_buf
), 4);
103 /* pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - */
104 /* ((size_t) (pxmitpriv->pallocated_frame_buf) &3); */
106 pxframe
= (struct xmit_frame
*)pxmitpriv
->pxmit_frame_buf
;
108 for (i
= 0; i
< NR_XMITFRAME
; i
++) {
109 _rtw_init_listhead(&(pxframe
->list
));
111 pxframe
->padapter
= padapter
;
112 pxframe
->frame_tag
= NULL_FRAMETAG
;
116 pxframe
->buf_addr
= NULL
;
117 pxframe
->pxmitbuf
= NULL
;
119 rtw_list_insert_tail(&(pxframe
->list
), &(pxmitpriv
->free_xmit_queue
.queue
));
124 pxmitpriv
->free_xmitframe_cnt
= NR_XMITFRAME
;
126 pxmitpriv
->frag_len
= MAX_FRAG_THRESHOLD
;
129 _rtw_init_queue(&pxmitpriv
->free_xmitbuf_queue
);
130 _rtw_init_queue(&pxmitpriv
->pending_xmitbuf_queue
);
132 pxmitpriv
->pallocated_xmitbuf
= rtw_zvmalloc(NR_XMITBUFF
* sizeof(struct xmit_buf
) + 4);
134 if (pxmitpriv
->pallocated_xmitbuf
== NULL
) {
135 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("alloc xmit_buf fail!\n"));
140 pxmitpriv
->pxmitbuf
= (u8
*)N_BYTE_ALIGMENT((size_t)(pxmitpriv
->pallocated_xmitbuf
), 4);
141 /* pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - */
142 /* ((size_t) (pxmitpriv->pallocated_xmitbuf) &3); */
144 pxmitbuf
= (struct xmit_buf
*)pxmitpriv
->pxmitbuf
;
146 for (i
= 0; i
< NR_XMITBUFF
; i
++) {
147 _rtw_init_listhead(&pxmitbuf
->list
);
149 pxmitbuf
->priv_data
= NULL
;
150 pxmitbuf
->padapter
= padapter
;
151 pxmitbuf
->ext_tag
= false;
153 /* Tx buf allocation may fail sometimes, so sleep and retry. */
154 res
= rtw_os_xmit_resource_alloc(padapter
, pxmitbuf
, (MAX_XMITBUF_SZ
+ XMITBUF_ALIGN_SZ
));
157 res
= rtw_os_xmit_resource_alloc(padapter
, pxmitbuf
, (MAX_XMITBUF_SZ
+ XMITBUF_ALIGN_SZ
));
163 pxmitbuf
->flags
= XMIT_VO_QUEUE
;
165 rtw_list_insert_tail(&pxmitbuf
->list
, &(pxmitpriv
->free_xmitbuf_queue
.queue
));
169 pxmitpriv
->free_xmitbuf_cnt
= NR_XMITBUFF
;
171 /* Init xmit extension buff */
172 _rtw_init_queue(&pxmitpriv
->free_xmit_extbuf_queue
);
174 pxmitpriv
->pallocated_xmit_extbuf
= rtw_zvmalloc(num_xmit_extbuf
* sizeof(struct xmit_buf
) + 4);
176 if (pxmitpriv
->pallocated_xmit_extbuf
== NULL
) {
177 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("alloc xmit_extbuf fail!\n"));
182 pxmitpriv
->pxmit_extbuf
= (u8
*)N_BYTE_ALIGMENT((size_t)(pxmitpriv
->pallocated_xmit_extbuf
), 4);
184 pxmitbuf
= (struct xmit_buf
*)pxmitpriv
->pxmit_extbuf
;
186 for (i
= 0; i
< num_xmit_extbuf
; i
++) {
187 _rtw_init_listhead(&pxmitbuf
->list
);
189 pxmitbuf
->priv_data
= NULL
;
190 pxmitbuf
->padapter
= padapter
;
191 pxmitbuf
->ext_tag
= true;
193 res
= rtw_os_xmit_resource_alloc(padapter
, pxmitbuf
, max_xmit_extbuf_size
+ XMITBUF_ALIGN_SZ
);
199 rtw_list_insert_tail(&pxmitbuf
->list
, &(pxmitpriv
->free_xmit_extbuf_queue
.queue
));
203 pxmitpriv
->free_xmit_extbuf_cnt
= num_xmit_extbuf
;
205 rtw_alloc_hwxmits(padapter
);
206 rtw_init_hwxmits(pxmitpriv
->hwxmits
, pxmitpriv
->hwxmit_entry
);
208 for (i
= 0; i
< 4; i
++)
209 pxmitpriv
->wmm_para_seq
[i
] = i
;
211 pxmitpriv
->txirp_cnt
= 1;
213 _rtw_init_sema(&(pxmitpriv
->tx_retevt
), 0);
215 /* per AC pending irp */
216 pxmitpriv
->beq_cnt
= 0;
217 pxmitpriv
->bkq_cnt
= 0;
218 pxmitpriv
->viq_cnt
= 0;
219 pxmitpriv
->voq_cnt
= 0;
221 pxmitpriv
->ack_tx
= false;
222 _rtw_mutex_init(&pxmitpriv
->ack_tx_mutex
);
223 rtw_sctx_init(&pxmitpriv
->ack_tx_ops
, 0);
225 rtw_hal_init_xmit_priv(padapter
);
234 static void rtw_mfree_xmit_priv_lock (struct xmit_priv
*pxmitpriv
)
236 _rtw_spinlock_free(&pxmitpriv
->lock
);
237 _rtw_free_sema(&pxmitpriv
->xmit_sema
);
238 _rtw_free_sema(&pxmitpriv
->terminate_xmitthread_sema
);
240 _rtw_spinlock_free(&pxmitpriv
->be_pending
.lock
);
241 _rtw_spinlock_free(&pxmitpriv
->bk_pending
.lock
);
242 _rtw_spinlock_free(&pxmitpriv
->vi_pending
.lock
);
243 _rtw_spinlock_free(&pxmitpriv
->vo_pending
.lock
);
244 _rtw_spinlock_free(&pxmitpriv
->bm_pending
.lock
);
246 _rtw_spinlock_free(&pxmitpriv
->free_xmit_queue
.lock
);
247 _rtw_spinlock_free(&pxmitpriv
->free_xmitbuf_queue
.lock
);
248 _rtw_spinlock_free(&pxmitpriv
->pending_xmitbuf_queue
.lock
);
251 void _rtw_free_xmit_priv (struct xmit_priv
*pxmitpriv
)
254 struct adapter
*padapter
= pxmitpriv
->adapter
;
255 struct xmit_frame
*pxmitframe
= (struct xmit_frame
*)pxmitpriv
->pxmit_frame_buf
;
256 struct xmit_buf
*pxmitbuf
= (struct xmit_buf
*)pxmitpriv
->pxmitbuf
;
257 u32 max_xmit_extbuf_size
= MAX_XMIT_EXTBUF_SZ
;
258 u32 num_xmit_extbuf
= NR_XMIT_EXTBUFF
;
262 rtw_hal_free_xmit_priv(padapter
);
264 rtw_mfree_xmit_priv_lock(pxmitpriv
);
266 if (pxmitpriv
->pxmit_frame_buf
== NULL
)
269 for (i
= 0; i
< NR_XMITFRAME
; i
++) {
270 rtw_os_xmit_complete(padapter
, pxmitframe
);
275 for (i
= 0; i
< NR_XMITBUFF
; i
++) {
276 rtw_os_xmit_resource_free(padapter
, pxmitbuf
, (MAX_XMITBUF_SZ
+ XMITBUF_ALIGN_SZ
));
280 if (pxmitpriv
->pallocated_frame_buf
)
281 rtw_vmfree(pxmitpriv
->pallocated_frame_buf
, NR_XMITFRAME
* sizeof(struct xmit_frame
) + 4);
283 if (pxmitpriv
->pallocated_xmitbuf
)
284 rtw_vmfree(pxmitpriv
->pallocated_xmitbuf
, NR_XMITBUFF
* sizeof(struct xmit_buf
) + 4);
286 /* free xmit extension buff */
287 _rtw_spinlock_free(&pxmitpriv
->free_xmit_extbuf_queue
.lock
);
289 pxmitbuf
= (struct xmit_buf
*)pxmitpriv
->pxmit_extbuf
;
290 for (i
= 0; i
< num_xmit_extbuf
; i
++) {
291 rtw_os_xmit_resource_free(padapter
, pxmitbuf
, (max_xmit_extbuf_size
+ XMITBUF_ALIGN_SZ
));
295 if (pxmitpriv
->pallocated_xmit_extbuf
) {
296 rtw_vmfree(pxmitpriv
->pallocated_xmit_extbuf
, num_xmit_extbuf
* sizeof(struct xmit_buf
) + 4);
299 rtw_free_hwxmits(padapter
);
301 _rtw_mutex_free(&pxmitpriv
->ack_tx_mutex
);
308 static void update_attrib_vcs_info(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
)
311 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
312 struct sta_info
*psta
= pattrib
->psta
;
313 struct mlme_ext_priv
*pmlmeext
= &(padapter
->mlmeextpriv
);
314 struct mlme_ext_info
*pmlmeinfo
= &(pmlmeext
->mlmext_info
);
316 if (pattrib
->nr_frags
!= 1)
317 sz
= padapter
->xmitpriv
.frag_len
;
319 sz
= pattrib
->last_txcmdsz
;
321 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
322 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
323 /* Other fragments are protected by previous fragment. */
324 /* So we only need to check the length of first fragment. */
325 if (pmlmeext
->cur_wireless_mode
< WIRELESS_11_24N
|| padapter
->registrypriv
.wifi_spec
) {
326 if (sz
> padapter
->registrypriv
.rts_thresh
) {
327 pattrib
->vcs_mode
= RTS_CTS
;
330 pattrib
->vcs_mode
= RTS_CTS
;
331 else if (psta
->cts2self
)
332 pattrib
->vcs_mode
= CTS_TO_SELF
;
334 pattrib
->vcs_mode
= NONE_VCS
;
339 if ((pmlmeinfo
->assoc_AP_vendor
== HT_IOT_PEER_ATHEROS
) && pattrib
->ampdu_en
&&
340 (padapter
->securitypriv
.dot11PrivacyAlgrthm
== _AES_
)) {
341 pattrib
->vcs_mode
= CTS_TO_SELF
;
345 /* check ERP protection */
346 if (psta
->rtsen
|| psta
->cts2self
) {
348 pattrib
->vcs_mode
= RTS_CTS
;
349 else if (psta
->cts2self
)
350 pattrib
->vcs_mode
= CTS_TO_SELF
;
355 /* check HT op mode */
356 if (pattrib
->ht_en
) {
357 u8 htopmode
= pmlmeinfo
->HT_protection
;
358 if ((pmlmeext
->cur_bwmode
&& (htopmode
== 2 || htopmode
== 3)) ||
359 (!pmlmeext
->cur_bwmode
&& htopmode
== 3)) {
360 pattrib
->vcs_mode
= RTS_CTS
;
366 if (sz
> padapter
->registrypriv
.rts_thresh
) {
367 pattrib
->vcs_mode
= RTS_CTS
;
371 /* to do list: check MIMO power save condition. */
373 /* check AMPDU aggregation for TXOP */
374 if (pattrib
->ampdu_en
) {
375 pattrib
->vcs_mode
= RTS_CTS
;
379 pattrib
->vcs_mode
= NONE_VCS
;
385 static void update_attrib_phy_info(struct pkt_attrib
*pattrib
, struct sta_info
*psta
)
388 pattrib->vcs_mode = RTS_CTS;
389 else if (psta->cts2self)
390 pattrib->vcs_mode = CTS_TO_SELF;
392 pattrib->vcs_mode = NONE_VCS;*/
396 pattrib
->triggered
= 0;
398 /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
399 pattrib
->qos_en
= psta
->qos_option
;
401 pattrib
->raid
= psta
->raid
;
402 pattrib
->ht_en
= psta
->htpriv
.ht_option
;
403 pattrib
->bwmode
= psta
->htpriv
.bwmode
;
404 pattrib
->ch_offset
= psta
->htpriv
.ch_offset
;
405 pattrib
->sgi
= psta
->htpriv
.sgi
;
406 pattrib
->ampdu_en
= false;
407 pattrib
->retry_ctrl
= false;
410 u8
qos_acm(u8 acm_mask
, u8 priority
)
412 u8 change_priority
= priority
;
417 if (acm_mask
& BIT(1))
425 if (acm_mask
& BIT(2))
430 if (acm_mask
& BIT(3))
434 DBG_88E("qos_acm(): invalid pattrib->priority: %d!!!\n", priority
);
438 return change_priority
;
441 static void set_qos(struct pkt_file
*ppktfile
, struct pkt_attrib
*pattrib
)
443 struct ethhdr etherhdr
;
447 _rtw_open_pktfile(ppktfile
->pkt
, ppktfile
);
448 _rtw_pktfile_read(ppktfile
, (unsigned char *)ðerhdr
, ETH_HLEN
);
450 /* get user_prio from IP hdr */
451 if (pattrib
->ether_type
== 0x0800) {
452 _rtw_pktfile_read(ppktfile
, (u8
*)&ip_hdr
, sizeof(ip_hdr
));
453 /* user_prio = (ntohs(ip_hdr.tos) >> 5) & 0x3; */
454 user_prio
= ip_hdr
.tos
>> 5;
455 } else if (pattrib
->ether_type
== 0x888e) {
456 /* "When priority processing of data frames is supported, */
457 /* a STA's SME should send EAPOL-Key frames at the highest priority." */
461 pattrib
->priority
= user_prio
;
462 pattrib
->hdrlen
= WLAN_HDR_A3_QOS_LEN
;
463 pattrib
->subtype
= WIFI_QOS_DATA_TYPE
;
466 static s32
update_attrib(struct adapter
*padapter
, struct sk_buff
*pkt
, struct pkt_attrib
*pattrib
)
468 struct pkt_file pktfile
;
469 struct sta_info
*psta
= NULL
;
470 struct ethhdr etherhdr
;
473 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
474 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
475 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
476 struct qos_priv
*pqospriv
= &pmlmepriv
->qospriv
;
481 _rtw_open_pktfile(pkt
, &pktfile
);
482 _rtw_pktfile_read(&pktfile
, (u8
*)ðerhdr
, ETH_HLEN
);
484 pattrib
->ether_type
= ntohs(etherhdr
.h_proto
);
486 memcpy(pattrib
->dst
, ðerhdr
.h_dest
, ETH_ALEN
);
487 memcpy(pattrib
->src
, ðerhdr
.h_source
, ETH_ALEN
);
491 if (check_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
) ||
492 check_fwstate(pmlmepriv
, WIFI_ADHOC_MASTER_STATE
)) {
493 memcpy(pattrib
->ra
, pattrib
->dst
, ETH_ALEN
);
494 memcpy(pattrib
->ta
, pattrib
->src
, ETH_ALEN
);
495 } else if (check_fwstate(pmlmepriv
, WIFI_STATION_STATE
)) {
496 memcpy(pattrib
->ra
, get_bssid(pmlmepriv
), ETH_ALEN
);
497 memcpy(pattrib
->ta
, pattrib
->src
, ETH_ALEN
);
498 } else if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
)) {
499 memcpy(pattrib
->ra
, pattrib
->dst
, ETH_ALEN
);
500 memcpy(pattrib
->ta
, get_bssid(pmlmepriv
), ETH_ALEN
);
503 pattrib
->pktlen
= pktfile
.pkt_len
;
505 if (ETH_P_IP
== pattrib
->ether_type
) {
506 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */
507 /* to prevent DHCP protocol fail */
509 _rtw_pktfile_read(&pktfile
, &tmp
[0], 24);
510 pattrib
->dhcp_pkt
= 0;
511 if (pktfile
.pkt_len
> 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
512 if (ETH_P_IP
== pattrib
->ether_type
) {/* IP header */
513 if (((tmp
[21] == 68) && (tmp
[23] == 67)) ||
514 ((tmp
[21] == 67) && (tmp
[23] == 68))) {
515 /* 68 : UDP BOOTP client */
516 /* 67 : UDP BOOTP server */
517 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("====================== update_attrib: get DHCP Packet\n"));
518 /* Use low rate to send DHCP packet. */
519 pattrib
->dhcp_pkt
= 1;
523 } else if (0x888e == pattrib
->ether_type
) {
524 DBG_88E_LEVEL(_drv_info_
, "send eapol packet\n");
527 if ((pattrib
->ether_type
== 0x888e) || (pattrib
->dhcp_pkt
== 1))
528 rtw_set_scan_deny(padapter
, 3000);
530 /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
531 if ((pattrib
->ether_type
== 0x0806) || (pattrib
->ether_type
== 0x888e) || (pattrib
->dhcp_pkt
== 1))
532 rtw_lps_ctrl_wk_cmd(padapter
, LPS_CTRL_SPECIAL_PACKET
, 1);
534 bmcast
= IS_MCAST(pattrib
->ra
);
538 psta
= rtw_get_bcmc_stainfo(padapter
);
540 psta
= rtw_get_stainfo(pstapriv
, pattrib
->ra
);
541 if (psta
== NULL
) { /* if we cannot get psta => drrp the pkt */
542 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_alert_
, ("\nupdate_attrib => get sta_info fail, ra: %pM\n", (pattrib
->ra
)));
545 } else if ((check_fwstate(pmlmepriv
, WIFI_AP_STATE
) == true) && (!(psta
->state
& _FW_LINKED
))) {
552 pattrib
->mac_id
= psta
->mac_id
;
553 /* DBG_88E("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
554 pattrib
->psta
= psta
;
556 /* if we cannot get psta => drop the pkt */
557 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_alert_
, ("\nupdate_attrib => get sta_info fail, ra:%pM\n", (pattrib
->ra
)));
562 pattrib
->ack_policy
= 0;
563 /* get ether_hdr_len */
564 pattrib
->pkt_hdrlen
= ETH_HLEN
;/* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
566 pattrib
->hdrlen
= WLAN_HDR_A3_LEN
;
567 pattrib
->subtype
= WIFI_DATA_TYPE
;
568 pattrib
->priority
= 0;
570 if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
|WIFI_ADHOC_STATE
|WIFI_ADHOC_MASTER_STATE
)) {
571 if (psta
->qos_option
)
572 set_qos(&pktfile
, pattrib
);
574 if (pqospriv
->qos_option
) {
575 set_qos(&pktfile
, pattrib
);
577 if (pmlmepriv
->acm_mask
!= 0)
578 pattrib
->priority
= qos_acm(pmlmepriv
->acm_mask
, pattrib
->priority
);
582 if (psta
->ieee8021x_blocked
) {
583 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("\n psta->ieee8021x_blocked == true\n"));
585 pattrib
->encrypt
= 0;
587 if ((pattrib
->ether_type
!= 0x888e) && !check_fwstate(pmlmepriv
, WIFI_MP_STATE
)) {
588 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != 0x888e\n", pattrib
->ether_type
));
593 GET_ENCRY_ALGO(psecuritypriv
, psta
, pattrib
->encrypt
, bmcast
);
595 switch (psecuritypriv
->dot11AuthAlgrthm
) {
596 case dot11AuthAlgrthm_Open
:
597 case dot11AuthAlgrthm_Shared
:
598 case dot11AuthAlgrthm_Auto
:
599 pattrib
->key_idx
= (u8
)psecuritypriv
->dot11PrivacyKeyIndex
;
601 case dot11AuthAlgrthm_8021X
:
603 pattrib
->key_idx
= (u8
)psecuritypriv
->dot118021XGrpKeyid
;
605 pattrib
->key_idx
= 0;
608 pattrib
->key_idx
= 0;
613 switch (pattrib
->encrypt
) {
617 pattrib
->icv_len
= 4;
621 pattrib
->icv_len
= 4;
623 if (padapter
->securitypriv
.busetkipkey
== _FAIL
) {
624 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
,
625 ("\npadapter->securitypriv.busetkipkey(%d) == _FAIL drop packet\n",
626 padapter
->securitypriv
.busetkipkey
));
632 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("pattrib->encrypt=%d (_AES_)\n", pattrib
->encrypt
));
634 pattrib
->icv_len
= 8;
638 pattrib
->icv_len
= 0;
642 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
,
643 ("update_attrib: encrypt=%d securitypriv.sw_encrypt=%d\n",
644 pattrib
->encrypt
, padapter
->securitypriv
.sw_encrypt
));
646 if (pattrib
->encrypt
&&
647 (padapter
->securitypriv
.sw_encrypt
|| !psecuritypriv
->hw_decrypted
)) {
648 pattrib
->bswenc
= true;
649 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
,
650 ("update_attrib: encrypt=%d securitypriv.hw_decrypted=%d bswenc = true\n",
651 pattrib
->encrypt
, padapter
->securitypriv
.sw_encrypt
));
653 pattrib
->bswenc
= false;
654 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("update_attrib: bswenc = false\n"));
657 rtw_set_tx_chksum_offload(pkt
, pattrib
);
659 update_attrib_phy_info(pattrib
, psta
);
668 static s32
xmitframe_addmic(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
)
670 int curfragnum
, length
;
671 u8
*pframe
, *payload
, mic
[8];
672 struct mic_data micdata
;
673 struct sta_info
*stainfo
;
674 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
675 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
676 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
677 u8 priority
[4] = {0x0, 0x0, 0x0, 0x0};
678 u8 hw_hdr_offset
= 0;
679 int bmcst
= IS_MCAST(pattrib
->ra
);
682 stainfo
= pattrib
->psta
;
684 stainfo
= rtw_get_stainfo(&padapter
->stapriv
, &pattrib
->ra
[0]);
688 hw_hdr_offset
= TXDESC_SIZE
+ (pxmitframe
->pkt_offset
* PACKET_OFFSET_SZ
);
690 if (pattrib
->encrypt
== _TKIP_
) {/* if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_PRIVACY_) */
691 /* encode mic code */
692 if (stainfo
!= NULL
) {
693 u8 null_key
[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
694 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
697 pframe
= pxmitframe
->buf_addr
+ hw_hdr_offset
;
700 if (_rtw_memcmp(psecuritypriv
->dot118021XGrptxmickey
[psecuritypriv
->dot118021XGrpKeyid
].skey
, null_key
, 16))
702 /* start to calculate the mic code */
703 rtw_secmicsetkey(&micdata
, psecuritypriv
->dot118021XGrptxmickey
[psecuritypriv
->dot118021XGrpKeyid
].skey
);
705 if (_rtw_memcmp(&stainfo
->dot11tkiptxmickey
.skey
[0], null_key
, 16) == true) {
706 /* DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey == 0\n"); */
707 /* rtw_msleep_os(10); */
710 /* start to calculate the mic code */
711 rtw_secmicsetkey(&micdata
, &stainfo
->dot11tkiptxmickey
.skey
[0]);
714 if (pframe
[1]&1) { /* ToDS == 1 */
715 rtw_secmicappend(&micdata
, &pframe
[16], 6); /* DA */
716 if (pframe
[1]&2) /* From Ds == 1 */
717 rtw_secmicappend(&micdata
, &pframe
[24], 6);
719 rtw_secmicappend(&micdata
, &pframe
[10], 6);
720 } else { /* ToDS == 0 */
721 rtw_secmicappend(&micdata
, &pframe
[4], 6); /* DA */
722 if (pframe
[1]&2) /* From Ds == 1 */
723 rtw_secmicappend(&micdata
, &pframe
[16], 6);
725 rtw_secmicappend(&micdata
, &pframe
[10], 6);
729 priority
[0] = (u8
)pxmitframe
->attrib
.priority
;
731 rtw_secmicappend(&micdata
, &priority
[0], 4);
735 for (curfragnum
= 0; curfragnum
< pattrib
->nr_frags
; curfragnum
++) {
736 payload
= (u8
*)RND4((size_t)(payload
));
737 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
,
738 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
739 curfragnum
, *payload
, *(payload
+1),
740 *(payload
+2), *(payload
+3),
741 *(payload
+4), *(payload
+5),
742 *(payload
+6), *(payload
+7)));
744 payload
= payload
+pattrib
->hdrlen
+pattrib
->iv_len
;
745 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
,
746 ("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d",
747 curfragnum
, pattrib
->hdrlen
, pattrib
->iv_len
));
748 if ((curfragnum
+1) == pattrib
->nr_frags
) {
749 length
= pattrib
->last_txcmdsz
-pattrib
->hdrlen
-pattrib
->iv_len
-((pattrib
->bswenc
) ? pattrib
->icv_len
: 0);
750 rtw_secmicappend(&micdata
, payload
, length
);
751 payload
= payload
+length
;
753 length
= pxmitpriv
->frag_len
-pattrib
->hdrlen
-pattrib
->iv_len
-((pattrib
->bswenc
) ? pattrib
->icv_len
: 0);
754 rtw_secmicappend(&micdata
, payload
, length
);
755 payload
= payload
+length
+pattrib
->icv_len
;
756 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("curfragnum=%d length=%d pattrib->icv_len=%d", curfragnum
, length
, pattrib
->icv_len
));
759 rtw_secgetmic(&micdata
, &(mic
[0]));
760 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("xmitframe_addmic: before add mic code!!!\n"));
761 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("xmitframe_addmic: pattrib->last_txcmdsz=%d!!!\n", pattrib
->last_txcmdsz
));
762 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\
763 mic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x , mic[7]= 0x%.2x !!!!\n",
764 mic
[0], mic
[1], mic
[2], mic
[3], mic
[4], mic
[5], mic
[6], mic
[7]));
765 /* add mic code and add the mic code length in last_txcmdsz */
767 memcpy(payload
, &(mic
[0]), 8);
768 pattrib
->last_txcmdsz
+= 8;
770 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("\n ======== last pkt ========\n"));
771 payload
= payload
-pattrib
->last_txcmdsz
+8;
772 for (curfragnum
= 0; curfragnum
< pattrib
->last_txcmdsz
; curfragnum
= curfragnum
+8)
773 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
,
774 (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
775 *(payload
+curfragnum
), *(payload
+curfragnum
+1),
776 *(payload
+curfragnum
+2), *(payload
+curfragnum
+3),
777 *(payload
+curfragnum
+4), *(payload
+curfragnum
+5),
778 *(payload
+curfragnum
+6), *(payload
+curfragnum
+7)));
780 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("xmitframe_addmic: rtw_get_stainfo==NULL!!!\n"));
789 static s32
xmitframe_swencrypt(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
)
791 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
795 if (pattrib
->bswenc
) {
796 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_alert_
, ("### xmitframe_swencrypt\n"));
797 switch (pattrib
->encrypt
) {
800 rtw_wep_encrypt(padapter
, (u8
*)pxmitframe
);
803 rtw_tkip_encrypt(padapter
, (u8
*)pxmitframe
);
806 rtw_aes_encrypt(padapter
, (u8
*)pxmitframe
);
812 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_notice_
, ("### xmitframe_hwencrypt\n"));
820 s32
rtw_make_wlanhdr (struct adapter
*padapter
, u8
*hdr
, struct pkt_attrib
*pattrib
)
824 struct rtw_ieee80211_hdr
*pwlanhdr
= (struct rtw_ieee80211_hdr
*)hdr
;
825 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
826 struct qos_priv
*pqospriv
= &pmlmepriv
->qospriv
;
827 u8 qos_option
= false;
830 u16
*fctrl
= &pwlanhdr
->frame_ctl
;
832 struct sta_info
*psta
;
834 int bmcst
= IS_MCAST(pattrib
->ra
);
839 psta
= pattrib
->psta
;
842 psta
= rtw_get_bcmc_stainfo(padapter
);
844 psta
= rtw_get_stainfo(&padapter
->stapriv
, pattrib
->ra
);
848 _rtw_memset(hdr
, 0, WLANHDR_OFFSET
);
850 SetFrameSubType(fctrl
, pattrib
->subtype
);
852 if (pattrib
->subtype
& WIFI_DATA_TYPE
) {
853 if ((check_fwstate(pmlmepriv
, WIFI_STATION_STATE
) == true)) {
854 /* to_ds = 1, fr_ds = 0; */
855 /* Data transfer to AP */
857 memcpy(pwlanhdr
->addr1
, get_bssid(pmlmepriv
), ETH_ALEN
);
858 memcpy(pwlanhdr
->addr2
, pattrib
->src
, ETH_ALEN
);
859 memcpy(pwlanhdr
->addr3
, pattrib
->dst
, ETH_ALEN
);
861 if (pqospriv
->qos_option
)
863 } else if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
)) {
864 /* to_ds = 0, fr_ds = 1; */
866 memcpy(pwlanhdr
->addr1
, pattrib
->dst
, ETH_ALEN
);
867 memcpy(pwlanhdr
->addr2
, get_bssid(pmlmepriv
), ETH_ALEN
);
868 memcpy(pwlanhdr
->addr3
, pattrib
->src
, ETH_ALEN
);
870 if (psta
->qos_option
)
872 } else if (check_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
) ||
873 check_fwstate(pmlmepriv
, WIFI_ADHOC_MASTER_STATE
)) {
874 memcpy(pwlanhdr
->addr1
, pattrib
->dst
, ETH_ALEN
);
875 memcpy(pwlanhdr
->addr2
, pattrib
->src
, ETH_ALEN
);
876 memcpy(pwlanhdr
->addr3
, get_bssid(pmlmepriv
), ETH_ALEN
);
878 if (psta
->qos_option
)
881 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv
)));
889 if (pattrib
->encrypt
)
893 qc
= (unsigned short *)(hdr
+ pattrib
->hdrlen
- 2);
895 if (pattrib
->priority
)
896 SetPriority(qc
, pattrib
->priority
);
898 SetEOSP(qc
, pattrib
->eosp
);
900 SetAckpolicy(qc
, pattrib
->ack_policy
);
903 /* TODO: fill HT Control Field */
905 /* Update Seq Num will be handled by f/w */
907 psta
->sta_xmitpriv
.txseq_tid
[pattrib
->priority
]++;
908 psta
->sta_xmitpriv
.txseq_tid
[pattrib
->priority
] &= 0xFFF;
910 pattrib
->seqnum
= psta
->sta_xmitpriv
.txseq_tid
[pattrib
->priority
];
912 SetSeqNum(hdr
, pattrib
->seqnum
);
914 /* check if enable ampdu */
915 if (pattrib
->ht_en
&& psta
->htpriv
.ampdu_enable
) {
916 if (psta
->htpriv
.agg_enable_bitmap
& BIT(pattrib
->priority
))
917 pattrib
->ampdu_en
= true;
920 /* re-check if enable ampdu by BA_starting_seqctrl */
921 if (pattrib
->ampdu_en
) {
924 tx_seq
= psta
->BA_starting_seqctrl
[pattrib
->priority
& 0x0f];
926 /* check BA_starting_seqctrl */
927 if (SN_LESS(pattrib
->seqnum
, tx_seq
)) {
928 pattrib
->ampdu_en
= false;/* AGG BK */
929 } else if (SN_EQUAL(pattrib
->seqnum
, tx_seq
)) {
930 psta
->BA_starting_seqctrl
[pattrib
->priority
& 0x0f] = (tx_seq
+1)&0xfff;
932 pattrib
->ampdu_en
= true;/* AGG EN */
934 psta
->BA_starting_seqctrl
[pattrib
->priority
& 0x0f] = (pattrib
->seqnum
+1)&0xfff;
935 pattrib
->ampdu_en
= true;/* AGG EN */
946 s32
rtw_txframes_pending(struct adapter
*padapter
)
948 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
950 return ((_rtw_queue_empty(&pxmitpriv
->be_pending
) == false) ||
951 (_rtw_queue_empty(&pxmitpriv
->bk_pending
) == false) ||
952 (_rtw_queue_empty(&pxmitpriv
->vi_pending
) == false) ||
953 (_rtw_queue_empty(&pxmitpriv
->vo_pending
) == false));
956 s32
rtw_txframes_sta_ac_pending(struct adapter
*padapter
, struct pkt_attrib
*pattrib
)
958 struct sta_info
*psta
;
959 struct tx_servq
*ptxservq
;
960 int priority
= pattrib
->priority
;
962 psta
= pattrib
->psta
;
967 ptxservq
= &(psta
->sta_xmitpriv
.bk_q
);
971 ptxservq
= &(psta
->sta_xmitpriv
.vi_q
);
975 ptxservq
= &(psta
->sta_xmitpriv
.vo_q
);
980 ptxservq
= &(psta
->sta_xmitpriv
.be_q
);
984 return ptxservq
->qcnt
;
988 * Calculate wlan 802.11 packet MAX size from pkt_attrib
989 * This function doesn't consider fragment case
991 u32
rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib
*pattrib
)
995 len
= pattrib
->hdrlen
+ pattrib
->iv_len
; /* WLAN Header and IV */
996 len
+= SNAP_SIZE
+ sizeof(u16
); /* LLC */
997 len
+= pattrib
->pktlen
;
998 if (pattrib
->encrypt
== _TKIP_
)
1000 len
+= ((pattrib
->bswenc
) ? pattrib
->icv_len
: 0); /* ICV */
1007 This sub-routine will perform all the following:
1009 1. remove 802.3 header.
1010 2. create wlan_header, based on the info in pxmitframe
1011 3. append sta's iv/ext-iv
1013 5. move frag chunk from pframe to pxmitframe->mem
1014 6. apply sw-encrypt, if necessary.
1017 s32
rtw_xmitframe_coalesce(struct adapter
*padapter
, struct sk_buff
*pkt
, struct xmit_frame
*pxmitframe
)
1019 struct pkt_file pktfile
;
1020 s32 frg_inx
, frg_len
, mpdu_len
, llc_sz
, mem_sz
;
1022 u8
*pframe
, *mem_start
;
1024 struct sta_info
*psta
;
1025 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
1026 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
1028 s32 bmcst
= IS_MCAST(pattrib
->ra
);
1033 psta
= rtw_get_stainfo(&padapter
->stapriv
, pattrib
->ra
);
1038 if (pxmitframe
->buf_addr
== NULL
) {
1039 DBG_88E("==> %s buf_addr == NULL\n", __func__
);
1043 pbuf_start
= pxmitframe
->buf_addr
;
1045 hw_hdr_offset
= TXDESC_SIZE
+ (pxmitframe
->pkt_offset
* PACKET_OFFSET_SZ
);
1047 mem_start
= pbuf_start
+ hw_hdr_offset
;
1049 if (rtw_make_wlanhdr(padapter
, mem_start
, pattrib
) == _FAIL
) {
1050 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n"));
1051 DBG_88E("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n");
1056 _rtw_open_pktfile(pkt
, &pktfile
);
1057 _rtw_pktfile_read(&pktfile
, NULL
, pattrib
->pkt_hdrlen
);
1060 frg_len
= pxmitpriv
->frag_len
- 4;/* 2346-4 = 2342 */
1069 SetMFrag(mem_start
);
1071 pframe
+= pattrib
->hdrlen
;
1072 mpdu_len
-= pattrib
->hdrlen
;
1074 /* adding icv, if necessary... */
1075 if (pattrib
->iv_len
) {
1077 switch (pattrib
->encrypt
) {
1080 WEP_IV(pattrib
->iv
, psta
->dot11txpn
, pattrib
->key_idx
);
1084 TKIP_IV(pattrib
->iv
, psta
->dot11txpn
, pattrib
->key_idx
);
1086 TKIP_IV(pattrib
->iv
, psta
->dot11txpn
, 0);
1090 AES_IV(pattrib
->iv
, psta
->dot11txpn
, pattrib
->key_idx
);
1092 AES_IV(pattrib
->iv
, psta
->dot11txpn
, 0);
1097 memcpy(pframe
, pattrib
->iv
, pattrib
->iv_len
);
1099 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_notice_
,
1100 ("rtw_xmitframe_coalesce: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n",
1101 padapter
->securitypriv
.dot11PrivacyKeyIndex
, pattrib
->iv
[3], *pframe
, *(pframe
+1), *(pframe
+2), *(pframe
+3)));
1103 pframe
+= pattrib
->iv_len
;
1105 mpdu_len
-= pattrib
->iv_len
;
1109 llc_sz
= rtw_put_snap(pframe
, pattrib
->ether_type
);
1114 if ((pattrib
->icv_len
> 0) && (pattrib
->bswenc
)) {
1115 mpdu_len
-= pattrib
->icv_len
;
1119 /* don't do fragment to broadcat/multicast packets */
1120 mem_sz
= _rtw_pktfile_read(&pktfile
, pframe
, pattrib
->pktlen
);
1122 mem_sz
= _rtw_pktfile_read(&pktfile
, pframe
, mpdu_len
);
1127 if ((pattrib
->icv_len
> 0) && (pattrib
->bswenc
)) {
1128 memcpy(pframe
, pattrib
->icv
, pattrib
->icv_len
);
1129 pframe
+= pattrib
->icv_len
;
1134 if (bmcst
|| rtw_endofpktfile(&pktfile
)) {
1135 pattrib
->nr_frags
= frg_inx
;
1137 pattrib
->last_txcmdsz
= pattrib
->hdrlen
+ pattrib
->iv_len
+ ((pattrib
->nr_frags
== 1) ? llc_sz
: 0) +
1138 ((pattrib
->bswenc
) ? pattrib
->icv_len
: 0) + mem_sz
;
1140 ClearMFrag(mem_start
);
1144 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("%s: There're still something in packet!\n", __func__
));
1147 addr
= (size_t)(pframe
);
1149 mem_start
= (unsigned char *)RND4(addr
) + hw_hdr_offset
;
1150 memcpy(mem_start
, pbuf_start
+ hw_hdr_offset
, pattrib
->hdrlen
);
1153 if (xmitframe_addmic(padapter
, pxmitframe
) == _FAIL
) {
1154 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
1155 DBG_88E("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
1160 xmitframe_swencrypt(padapter
, pxmitframe
);
1163 update_attrib_vcs_info(padapter
, pxmitframe
);
1165 pattrib
->vcs_mode
= NONE_VCS
;
1174 /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1175 * IEEE LLC/SNAP header contains 8 octets
1176 * First 3 octets comprise the LLC portion
1177 * SNAP portion, 5 octets, is divided into two fields:
1178 * Organizationally Unique Identifier(OUI), 3 octets,
1179 * type, defined by that organization, 2 octets.
1181 s32
rtw_put_snap(u8
*data
, u16 h_proto
)
1183 struct ieee80211_snap_hdr
*snap
;
1188 snap
= (struct ieee80211_snap_hdr
*)data
;
1193 if (h_proto
== 0x8137 || h_proto
== 0x80f3)
1198 snap
->oui
[0] = oui
[0];
1199 snap
->oui
[1] = oui
[1];
1200 snap
->oui
[2] = oui
[2];
1202 *(__be16
*)(data
+ SNAP_SIZE
) = htons(h_proto
);
1206 return SNAP_SIZE
+ sizeof(u16
);
1209 void rtw_update_protection(struct adapter
*padapter
, u8
*ie
, uint ie_len
)
1214 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
1215 struct registry_priv
*pregistrypriv
= &padapter
->registrypriv
;
1219 switch (pxmitpriv
->vcs_setting
) {
1221 pxmitpriv
->vcs
= NONE_VCS
;
1227 perp
= rtw_get_ie(ie
, _ERPINFO_IE_
, &erp_len
, ie_len
);
1229 pxmitpriv
->vcs
= NONE_VCS
;
1231 protection
= (*(perp
+ 2)) & BIT(1);
1233 if (pregistrypriv
->vcs_type
== RTS_CTS
)
1234 pxmitpriv
->vcs
= RTS_CTS
;
1236 pxmitpriv
->vcs
= CTS_TO_SELF
;
1238 pxmitpriv
->vcs
= NONE_VCS
;
1247 void rtw_count_tx_stats(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
, int sz
)
1249 struct sta_info
*psta
= NULL
;
1250 struct stainfo_stats
*pstats
= NULL
;
1251 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
1252 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
1254 if ((pxmitframe
->frame_tag
&0x0f) == DATA_FRAMETAG
) {
1255 pxmitpriv
->tx_bytes
+= sz
;
1256 pmlmepriv
->LinkDetectInfo
.NumTxOkInPeriod
+= pxmitframe
->agg_num
;
1258 psta
= pxmitframe
->attrib
.psta
;
1260 pstats
= &psta
->sta_stats
;
1261 pstats
->tx_pkts
+= pxmitframe
->agg_num
;
1262 pstats
->tx_bytes
+= sz
;
1267 struct xmit_buf
*rtw_alloc_xmitbuf_ext(struct xmit_priv
*pxmitpriv
)
1270 struct xmit_buf
*pxmitbuf
= NULL
;
1271 struct list_head
*plist
, *phead
;
1272 struct __queue
*pfree_queue
= &pxmitpriv
->free_xmit_extbuf_queue
;
1276 _enter_critical(&pfree_queue
->lock
, &irql
);
1278 if (_rtw_queue_empty(pfree_queue
) == true) {
1281 phead
= get_list_head(pfree_queue
);
1283 plist
= get_next(phead
);
1285 pxmitbuf
= LIST_CONTAINOR(plist
, struct xmit_buf
, list
);
1287 rtw_list_delete(&(pxmitbuf
->list
));
1290 if (pxmitbuf
!= NULL
) {
1291 pxmitpriv
->free_xmit_extbuf_cnt
--;
1293 pxmitbuf
->priv_data
= NULL
;
1294 /* pxmitbuf->ext_tag = true; */
1296 if (pxmitbuf
->sctx
) {
1297 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__
);
1298 rtw_sctx_done_err(&pxmitbuf
->sctx
, RTW_SCTX_DONE_BUF_ALLOC
);
1302 _exit_critical(&pfree_queue
->lock
, &irql
);
1309 s32
rtw_free_xmitbuf_ext(struct xmit_priv
*pxmitpriv
, struct xmit_buf
*pxmitbuf
)
1312 struct __queue
*pfree_queue
= &pxmitpriv
->free_xmit_extbuf_queue
;
1316 if (pxmitbuf
== NULL
)
1319 _enter_critical(&pfree_queue
->lock
, &irql
);
1321 rtw_list_delete(&pxmitbuf
->list
);
1323 rtw_list_insert_tail(&(pxmitbuf
->list
), get_list_head(pfree_queue
));
1324 pxmitpriv
->free_xmit_extbuf_cnt
++;
1326 _exit_critical(&pfree_queue
->lock
, &irql
);
1333 struct xmit_buf
*rtw_alloc_xmitbuf(struct xmit_priv
*pxmitpriv
)
1336 struct xmit_buf
*pxmitbuf
= NULL
;
1337 struct list_head
*plist
, *phead
;
1338 struct __queue
*pfree_xmitbuf_queue
= &pxmitpriv
->free_xmitbuf_queue
;
1342 /* DBG_88E("+rtw_alloc_xmitbuf\n"); */
1344 _enter_critical(&pfree_xmitbuf_queue
->lock
, &irql
);
1346 if (_rtw_queue_empty(pfree_xmitbuf_queue
) == true) {
1349 phead
= get_list_head(pfree_xmitbuf_queue
);
1351 plist
= get_next(phead
);
1353 pxmitbuf
= LIST_CONTAINOR(plist
, struct xmit_buf
, list
);
1355 rtw_list_delete(&(pxmitbuf
->list
));
1358 if (pxmitbuf
!= NULL
) {
1359 pxmitpriv
->free_xmitbuf_cnt
--;
1360 pxmitbuf
->priv_data
= NULL
;
1361 if (pxmitbuf
->sctx
) {
1362 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__
);
1363 rtw_sctx_done_err(&pxmitbuf
->sctx
, RTW_SCTX_DONE_BUF_ALLOC
);
1366 _exit_critical(&pfree_xmitbuf_queue
->lock
, &irql
);
1373 s32
rtw_free_xmitbuf(struct xmit_priv
*pxmitpriv
, struct xmit_buf
*pxmitbuf
)
1376 struct __queue
*pfree_xmitbuf_queue
= &pxmitpriv
->free_xmitbuf_queue
;
1379 if (pxmitbuf
== NULL
)
1382 if (pxmitbuf
->sctx
) {
1383 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__
);
1384 rtw_sctx_done_err(&pxmitbuf
->sctx
, RTW_SCTX_DONE_BUF_FREE
);
1387 if (pxmitbuf
->ext_tag
) {
1388 rtw_free_xmitbuf_ext(pxmitpriv
, pxmitbuf
);
1390 _enter_critical(&pfree_xmitbuf_queue
->lock
, &irql
);
1392 rtw_list_delete(&pxmitbuf
->list
);
1394 rtw_list_insert_tail(&(pxmitbuf
->list
), get_list_head(pfree_xmitbuf_queue
));
1396 pxmitpriv
->free_xmitbuf_cnt
++;
1397 _exit_critical(&pfree_xmitbuf_queue
->lock
, &irql
);
1408 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
1410 If we turn on USE_RXTHREAD, then, no need for critical section.
1411 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
1413 Must be very very cautious...
1417 struct xmit_frame
*rtw_alloc_xmitframe(struct xmit_priv
*pxmitpriv
)/* _queue *pfree_xmit_queue) */
1420 Please remember to use all the osdep_service api,
1421 and lock/unlock or _enter/_exit critical to protect
1426 struct xmit_frame
*pxframe
= NULL
;
1427 struct list_head
*plist
, *phead
;
1428 struct __queue
*pfree_xmit_queue
= &pxmitpriv
->free_xmit_queue
;
1432 _enter_critical_bh(&pfree_xmit_queue
->lock
, &irql
);
1434 if (_rtw_queue_empty(pfree_xmit_queue
) == true) {
1435 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("rtw_alloc_xmitframe:%d\n", pxmitpriv
->free_xmitframe_cnt
));
1438 phead
= get_list_head(pfree_xmit_queue
);
1440 plist
= get_next(phead
);
1442 pxframe
= LIST_CONTAINOR(plist
, struct xmit_frame
, list
);
1444 rtw_list_delete(&(pxframe
->list
));
1447 if (pxframe
!= NULL
) { /* default value setting */
1448 pxmitpriv
->free_xmitframe_cnt
--;
1450 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv
->free_xmitframe_cnt
));
1452 pxframe
->buf_addr
= NULL
;
1453 pxframe
->pxmitbuf
= NULL
;
1455 _rtw_memset(&pxframe
->attrib
, 0, sizeof(struct pkt_attrib
));
1456 /* pxframe->attrib.psta = NULL; */
1458 pxframe
->frame_tag
= DATA_FRAMETAG
;
1460 pxframe
->pkt
= NULL
;
1461 pxframe
->pkt_offset
= 1;/* default use pkt_offset to fill tx desc */
1463 pxframe
->agg_num
= 1;
1464 pxframe
->ack_report
= 0;
1467 _exit_critical_bh(&pfree_xmit_queue
->lock
, &irql
);
1474 s32
rtw_free_xmitframe(struct xmit_priv
*pxmitpriv
, struct xmit_frame
*pxmitframe
)
1477 struct __queue
*pfree_xmit_queue
= &pxmitpriv
->free_xmit_queue
;
1478 struct adapter
*padapter
= pxmitpriv
->adapter
;
1479 struct sk_buff
*pndis_pkt
= NULL
;
1483 if (pxmitframe
== NULL
) {
1484 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("====== rtw_free_xmitframe():pxmitframe == NULL!!!!!!!!!!\n"));
1488 _enter_critical_bh(&pfree_xmit_queue
->lock
, &irql
);
1490 rtw_list_delete(&pxmitframe
->list
);
1492 if (pxmitframe
->pkt
) {
1493 pndis_pkt
= pxmitframe
->pkt
;
1494 pxmitframe
->pkt
= NULL
;
1497 rtw_list_insert_tail(&pxmitframe
->list
, get_list_head(pfree_xmit_queue
));
1499 pxmitpriv
->free_xmitframe_cnt
++;
1500 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_debug_
, ("rtw_free_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv
->free_xmitframe_cnt
));
1502 _exit_critical_bh(&pfree_xmit_queue
->lock
, &irql
);
1505 rtw_os_pkt_complete(padapter
, pndis_pkt
);
1514 void rtw_free_xmitframe_queue(struct xmit_priv
*pxmitpriv
, struct __queue
*pframequeue
)
1517 struct list_head
*plist
, *phead
;
1518 struct xmit_frame
*pxmitframe
;
1522 _enter_critical_bh(&(pframequeue
->lock
), &irql
);
1524 phead
= get_list_head(pframequeue
);
1525 plist
= get_next(phead
);
1527 while (!rtw_end_of_queue_search(phead
, plist
)) {
1528 pxmitframe
= LIST_CONTAINOR(plist
, struct xmit_frame
, list
);
1530 plist
= get_next(plist
);
1532 rtw_free_xmitframe(pxmitpriv
, pxmitframe
);
1534 _exit_critical_bh(&(pframequeue
->lock
), &irql
);
1539 s32
rtw_xmitframe_enqueue(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
)
1541 if (rtw_xmit_classifier(padapter
, pxmitframe
) == _FAIL
) {
1542 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
,
1543 ("rtw_xmitframe_enqueue: drop xmit pkt for classifier fail\n"));
1544 /* pxmitframe->pkt = NULL; */
1551 static struct xmit_frame
*dequeue_one_xmitframe(struct xmit_priv
*pxmitpriv
, struct hw_xmit
*phwxmit
, struct tx_servq
*ptxservq
, struct __queue
*pframe_queue
)
1553 struct list_head
*xmitframe_plist
, *xmitframe_phead
;
1554 struct xmit_frame
*pxmitframe
= NULL
;
1556 xmitframe_phead
= get_list_head(pframe_queue
);
1557 xmitframe_plist
= get_next(xmitframe_phead
);
1559 if (!rtw_end_of_queue_search(xmitframe_phead
, xmitframe_plist
)) {
1560 pxmitframe
= LIST_CONTAINOR(xmitframe_plist
, struct xmit_frame
, list
);
1562 xmitframe_plist
= get_next(xmitframe_plist
);
1564 rtw_list_delete(&pxmitframe
->list
);
1571 struct xmit_frame
*rtw_dequeue_xframe(struct xmit_priv
*pxmitpriv
, struct hw_xmit
*phwxmit_i
, int entry
)
1573 unsigned long irql0
;
1574 struct list_head
*sta_plist
, *sta_phead
;
1575 struct hw_xmit
*phwxmit
;
1576 struct tx_servq
*ptxservq
= NULL
;
1577 struct __queue
*pframe_queue
= NULL
;
1578 struct xmit_frame
*pxmitframe
= NULL
;
1579 struct adapter
*padapter
= pxmitpriv
->adapter
;
1580 struct registry_priv
*pregpriv
= &padapter
->registrypriv
;
1585 inx
[0] = 0; inx
[1] = 1; inx
[2] = 2; inx
[3] = 3;
1587 if (pregpriv
->wifi_spec
== 1) {
1590 for (j
= 0; j
< 4; j
++)
1591 inx
[j
] = pxmitpriv
->wmm_para_seq
[j
];
1594 _enter_critical_bh(&pxmitpriv
->lock
, &irql0
);
1596 for (i
= 0; i
< entry
; i
++) {
1597 phwxmit
= phwxmit_i
+ inx
[i
];
1599 sta_phead
= get_list_head(phwxmit
->sta_queue
);
1600 sta_plist
= get_next(sta_phead
);
1602 while (!rtw_end_of_queue_search(sta_phead
, sta_plist
)) {
1603 ptxservq
= LIST_CONTAINOR(sta_plist
, struct tx_servq
, tx_pending
);
1605 pframe_queue
= &ptxservq
->sta_pending
;
1607 pxmitframe
= dequeue_one_xmitframe(pxmitpriv
, phwxmit
, ptxservq
, pframe_queue
);
1612 /* Remove sta node when there are no pending packets. */
1613 if (_rtw_queue_empty(pframe_queue
)) /* must be done after get_next and before break */
1614 rtw_list_delete(&ptxservq
->tx_pending
);
1618 sta_plist
= get_next(sta_plist
);
1622 _exit_critical_bh(&pxmitpriv
->lock
, &irql0
);
1627 struct tx_servq
*rtw_get_sta_pending(struct adapter
*padapter
, struct sta_info
*psta
, int up
, u8
*ac
)
1629 struct tx_servq
*ptxservq
;
1635 ptxservq
= &(psta
->sta_xmitpriv
.bk_q
);
1637 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("rtw_get_sta_pending : BK\n"));
1641 ptxservq
= &(psta
->sta_xmitpriv
.vi_q
);
1643 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("rtw_get_sta_pending : VI\n"));
1647 ptxservq
= &(psta
->sta_xmitpriv
.vo_q
);
1649 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("rtw_get_sta_pending : VO\n"));
1654 ptxservq
= &(psta
->sta_xmitpriv
.be_q
);
1656 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("rtw_get_sta_pending : BE\n"));
1666 * Will enqueue pxmitframe to the proper queue,
1667 * and indicate it to xx_pending list.....
1669 s32
rtw_xmit_classifier(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
)
1671 /* unsigned long irql0; */
1673 struct sta_info
*psta
;
1674 struct tx_servq
*ptxservq
;
1675 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
1676 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
1677 struct hw_xmit
*phwxmits
= padapter
->xmitpriv
.hwxmits
;
1682 if (pattrib
->psta
) {
1683 psta
= pattrib
->psta
;
1685 psta
= rtw_get_stainfo(pstapriv
, pattrib
->ra
);
1690 DBG_88E("rtw_xmit_classifier: psta == NULL\n");
1691 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_err_
, ("rtw_xmit_classifier: psta == NULL\n"));
1695 ptxservq
= rtw_get_sta_pending(padapter
, psta
, pattrib
->priority
, (u8
*)(&ac_index
));
1697 if (rtw_is_list_empty(&ptxservq
->tx_pending
))
1698 rtw_list_insert_tail(&ptxservq
->tx_pending
, get_list_head(phwxmits
[ac_index
].sta_queue
));
1700 rtw_list_insert_tail(&pxmitframe
->list
, get_list_head(&ptxservq
->sta_pending
));
1702 phwxmits
[ac_index
].accnt
++;
1710 void rtw_alloc_hwxmits(struct adapter
*padapter
)
1712 struct hw_xmit
*hwxmits
;
1713 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
1715 pxmitpriv
->hwxmit_entry
= HWXMIT_ENTRY
;
1717 pxmitpriv
->hwxmits
= (struct hw_xmit
*)rtw_zmalloc(sizeof(struct hw_xmit
) * pxmitpriv
->hwxmit_entry
);
1719 hwxmits
= pxmitpriv
->hwxmits
;
1721 if (pxmitpriv
->hwxmit_entry
== 5) {
1722 hwxmits
[0] .sta_queue
= &pxmitpriv
->bm_pending
;
1723 hwxmits
[1] .sta_queue
= &pxmitpriv
->vo_pending
;
1724 hwxmits
[2] .sta_queue
= &pxmitpriv
->vi_pending
;
1725 hwxmits
[3] .sta_queue
= &pxmitpriv
->bk_pending
;
1726 hwxmits
[4] .sta_queue
= &pxmitpriv
->be_pending
;
1727 } else if (pxmitpriv
->hwxmit_entry
== 4) {
1728 hwxmits
[0] .sta_queue
= &pxmitpriv
->vo_pending
;
1729 hwxmits
[1] .sta_queue
= &pxmitpriv
->vi_pending
;
1730 hwxmits
[2] .sta_queue
= &pxmitpriv
->be_pending
;
1731 hwxmits
[3] .sta_queue
= &pxmitpriv
->bk_pending
;
1736 void rtw_free_hwxmits(struct adapter
*padapter
)
1738 struct hw_xmit
*hwxmits
;
1739 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
1741 hwxmits
= pxmitpriv
->hwxmits
;
1745 void rtw_init_hwxmits(struct hw_xmit
*phwxmit
, int entry
)
1749 for (i
= 0; i
< entry
; i
++, phwxmit
++)
1754 static int rtw_br_client_tx(struct adapter
*padapter
, struct sk_buff
**pskb
)
1756 struct sk_buff
*skb
= *pskb
;
1758 int res
, is_vlan_tag
= 0, i
, do_nat25
= 1;
1759 unsigned short vlan_hdr
= 0;
1760 void *br_port
= NULL
;
1763 br_port
= rcu_dereference(padapter
->pnetdev
->rx_handler_data
);
1765 _enter_critical_bh(&padapter
->br_ext_lock
, &irql
);
1766 if (!(skb
->data
[0] & 1) && br_port
&&
1767 memcmp(skb
->data
+MACADDRLEN
, padapter
->br_mac
, MACADDRLEN
) &&
1768 *((__be16
*)(skb
->data
+MACADDRLEN
*2)) != __constant_htons(ETH_P_8021Q
) &&
1769 *((__be16
*)(skb
->data
+MACADDRLEN
*2)) == __constant_htons(ETH_P_IP
) &&
1770 !memcmp(padapter
->scdb_mac
, skb
->data
+MACADDRLEN
, MACADDRLEN
) && padapter
->scdb_entry
) {
1771 memcpy(skb
->data
+MACADDRLEN
, GET_MY_HWADDR(padapter
), MACADDRLEN
);
1772 padapter
->scdb_entry
->ageing_timer
= jiffies
;
1773 _exit_critical_bh(&padapter
->br_ext_lock
, &irql
);
1775 if (*((__be16
*)(skb
->data
+MACADDRLEN
*2)) == __constant_htons(ETH_P_8021Q
)) {
1777 vlan_hdr
= *((unsigned short *)(skb
->data
+MACADDRLEN
*2+2));
1778 for (i
= 0; i
< 6; i
++)
1779 *((unsigned short *)(skb
->data
+MACADDRLEN
*2+2-i
*2)) = *((unsigned short *)(skb
->data
+MACADDRLEN
*2-2-i
*2));
1782 if (!memcmp(skb
->data
+MACADDRLEN
, padapter
->br_mac
, MACADDRLEN
) &&
1783 (*((__be16
*)(skb
->data
+MACADDRLEN
*2)) == __constant_htons(ETH_P_IP
)))
1784 memcpy(padapter
->br_ip
, skb
->data
+WLAN_ETHHDR_LEN
+12, 4);
1786 if (*((__be16
*)(skb
->data
+MACADDRLEN
*2)) == __constant_htons(ETH_P_IP
)) {
1787 if (memcmp(padapter
->scdb_mac
, skb
->data
+MACADDRLEN
, MACADDRLEN
)) {
1788 padapter
->scdb_entry
= (struct nat25_network_db_entry
*)scdb_findEntry(padapter
,
1789 skb
->data
+MACADDRLEN
, skb
->data
+WLAN_ETHHDR_LEN
+12);
1790 if (padapter
->scdb_entry
) {
1791 memcpy(padapter
->scdb_mac
, skb
->data
+MACADDRLEN
, MACADDRLEN
);
1792 memcpy(padapter
->scdb_ip
, skb
->data
+WLAN_ETHHDR_LEN
+12, 4);
1793 padapter
->scdb_entry
->ageing_timer
= jiffies
;
1797 if (padapter
->scdb_entry
) {
1798 padapter
->scdb_entry
->ageing_timer
= jiffies
;
1801 memset(padapter
->scdb_mac
, 0, MACADDRLEN
);
1802 memset(padapter
->scdb_ip
, 0, 4);
1806 _exit_critical_bh(&padapter
->br_ext_lock
, &irql
);
1808 if (nat25_db_handle(padapter
, skb
, NAT25_CHECK
) == 0) {
1809 struct sk_buff
*newskb
;
1813 for (i
= 0; i
< 6; i
++)
1814 *((unsigned short *)(skb
->data
+i
*2)) = *((unsigned short *)(skb
->data
+4+i
*2));
1815 *((__be16
*)(skb
->data
+MACADDRLEN
*2)) = __constant_htons(ETH_P_8021Q
);
1816 *((unsigned short *)(skb
->data
+MACADDRLEN
*2+2)) = vlan_hdr
;
1819 newskb
= skb_copy(skb
, GFP_ATOMIC
);
1820 if (newskb
== NULL
) {
1821 DEBUG_ERR("TX DROP: skb_copy fail!\n");
1824 dev_kfree_skb_any(skb
);
1826 *pskb
= skb
= newskb
;
1828 vlan_hdr
= *((unsigned short *)(skb
->data
+MACADDRLEN
*2+2));
1829 for (i
= 0; i
< 6; i
++)
1830 *((unsigned short *)(skb
->data
+MACADDRLEN
*2+2-i
*2)) = *((unsigned short *)(skb
->data
+MACADDRLEN
*2-2-i
*2));
1835 if (skb_is_nonlinear(skb
))
1836 DEBUG_ERR("%s(): skb_is_nonlinear!!\n", __func__
);
1838 res
= skb_linearize(skb
);
1840 DEBUG_ERR("TX DROP: skb_linearize fail!\n");
1844 res
= nat25_db_handle(padapter
, skb
, NAT25_INSERT
);
1847 DEBUG_ERR("TX DROP: nat25_db_handle fail!\n");
1854 memcpy(skb
->data
+MACADDRLEN
, GET_MY_HWADDR(padapter
), MACADDRLEN
);
1856 dhcp_flag_bcast(padapter
, skb
);
1860 for (i
= 0; i
< 6; i
++)
1861 *((unsigned short *)(skb
->data
+i
*2)) = *((unsigned short *)(skb
->data
+4+i
*2));
1862 *((__be16
*)(skb
->data
+MACADDRLEN
*2)) = __constant_htons(ETH_P_8021Q
);
1863 *((unsigned short *)(skb
->data
+MACADDRLEN
*2+2)) = vlan_hdr
;
1867 /* check if SA is equal to our MAC */
1868 if (memcmp(skb
->data
+MACADDRLEN
, GET_MY_HWADDR(padapter
), MACADDRLEN
)) {
1869 DEBUG_ERR("TX DROP: untransformed frame SA:%02X%02X%02X%02X%02X%02X!\n",
1870 skb
->data
[6], skb
->data
[7], skb
->data
[8], skb
->data
[9], skb
->data
[10], skb
->data
[11]);
1876 u32
rtw_get_ff_hwaddr(struct xmit_frame
*pxmitframe
)
1879 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
1881 switch (pattrib
->qsel
) {
1884 addr
= BE_QUEUE_INX
;
1888 addr
= BK_QUEUE_INX
;
1892 addr
= VI_QUEUE_INX
;
1896 addr
= VO_QUEUE_INX
;
1899 addr
= BCN_QUEUE_INX
;
1901 case 0x11:/* BC/MC in PS (HIQ) */
1902 addr
= HIGH_QUEUE_INX
;
1906 addr
= MGT_QUEUE_INX
;
1913 static void do_queue_select(struct adapter
*padapter
, struct pkt_attrib
*pattrib
)
1917 qsel
= pattrib
->priority
;
1918 RT_TRACE(_module_rtl871x_xmit_c_
, _drv_info_
, ("### do_queue_select priority=%d , qsel = %d\n", pattrib
->priority
, qsel
));
1920 pattrib
->qsel
= qsel
;
1924 * The main transmit(tx) entry
1928 * 0 success, hardware will handle this xmit frame(packet)
1931 s32
rtw_xmit(struct adapter
*padapter
, struct sk_buff
**ppkt
)
1933 #ifdef CONFIG_88EU_AP_MODE
1934 unsigned long irql0
;
1936 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
1937 struct xmit_frame
*pxmitframe
= NULL
;
1938 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
1939 void *br_port
= NULL
;
1942 pxmitframe
= rtw_alloc_xmitframe(pxmitpriv
);
1943 if (pxmitframe
== NULL
) {
1944 RT_TRACE(_module_xmit_osdep_c_
, _drv_err_
, ("rtw_xmit: no more pxmitframe\n"));
1945 DBG_88E("DBG_TX_DROP_FRAME %s no more pxmitframe\n", __func__
);
1950 br_port
= rcu_dereference(padapter
->pnetdev
->rx_handler_data
);
1953 if (br_port
&& check_fwstate(pmlmepriv
, WIFI_STATION_STATE
|WIFI_ADHOC_STATE
)) {
1954 res
= rtw_br_client_tx(padapter
, ppkt
);
1956 rtw_free_xmitframe(pxmitpriv
, pxmitframe
);
1961 res
= update_attrib(padapter
, *ppkt
, &pxmitframe
->attrib
);
1964 RT_TRACE(_module_xmit_osdep_c_
, _drv_err_
, ("rtw_xmit: update attrib fail\n"));
1965 rtw_free_xmitframe(pxmitpriv
, pxmitframe
);
1968 pxmitframe
->pkt
= *ppkt
;
1970 rtw_led_control(padapter
, LED_CTL_TX
);
1972 do_queue_select(padapter
, &pxmitframe
->attrib
);
1974 #ifdef CONFIG_88EU_AP_MODE
1975 _enter_critical_bh(&pxmitpriv
->lock
, &irql0
);
1976 if (xmitframe_enqueue_for_sleeping_sta(padapter
, pxmitframe
)) {
1977 _exit_critical_bh(&pxmitpriv
->lock
, &irql0
);
1980 _exit_critical_bh(&pxmitpriv
->lock
, &irql0
);
1983 if (rtw_hal_xmit(padapter
, pxmitframe
) == false)
1989 #if defined(CONFIG_88EU_AP_MODE)
1991 int xmitframe_enqueue_for_sleeping_sta(struct adapter
*padapter
, struct xmit_frame
*pxmitframe
)
1995 struct sta_info
*psta
= NULL
;
1996 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
1997 struct pkt_attrib
*pattrib
= &pxmitframe
->attrib
;
1998 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
1999 int bmcst
= IS_MCAST(pattrib
->ra
);
2001 if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
) == false)
2005 psta
= pattrib
->psta
;
2007 psta
= rtw_get_stainfo(pstapriv
, pattrib
->ra
);
2012 if (pattrib
->triggered
== 1) {
2014 pattrib
->qsel
= 0x11;/* HIQ */
2019 _enter_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2021 if (pstapriv
->sta_dz_bitmap
) {/* if any one sta is in ps mode */
2022 rtw_list_delete(&pxmitframe
->list
);
2024 rtw_list_insert_tail(&pxmitframe
->list
, get_list_head(&psta
->sleep_q
));
2028 pstapriv
->tim_bitmap
|= BIT(0);/* */
2029 pstapriv
->sta_dz_bitmap
|= BIT(0);
2031 update_beacon(padapter
, _TIM_IE_
, NULL
, false);/* tx bc/mc packets after upate bcn */
2036 _exit_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2041 _enter_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2043 if (psta
->state
&WIFI_SLEEP_STATE
) {
2046 if (pstapriv
->sta_dz_bitmap
&BIT(psta
->aid
)) {
2047 rtw_list_delete(&pxmitframe
->list
);
2049 rtw_list_insert_tail(&pxmitframe
->list
, get_list_head(&psta
->sleep_q
));
2053 switch (pattrib
->priority
) {
2056 wmmps_ac
= psta
->uapsd_bk
&BIT(0);
2060 wmmps_ac
= psta
->uapsd_vi
&BIT(0);
2064 wmmps_ac
= psta
->uapsd_vo
&BIT(0);
2069 wmmps_ac
= psta
->uapsd_be
&BIT(0);
2074 psta
->sleepq_ac_len
++;
2076 if (((psta
->has_legacy_ac
) && (!wmmps_ac
)) ||
2077 ((!psta
->has_legacy_ac
) && (wmmps_ac
))) {
2078 pstapriv
->tim_bitmap
|= BIT(psta
->aid
);
2080 if (psta
->sleepq_len
== 1) {
2081 /* upate BCN for TIM IE */
2082 update_beacon(padapter
, _TIM_IE_
, NULL
, false);
2089 _exit_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2094 static void dequeue_xmitframes_to_sleeping_queue(struct adapter
*padapter
, struct sta_info
*psta
, struct __queue
*pframequeue
)
2096 struct list_head
*plist
, *phead
;
2098 struct tx_servq
*ptxservq
;
2099 struct pkt_attrib
*pattrib
;
2100 struct xmit_frame
*pxmitframe
;
2101 struct hw_xmit
*phwxmits
= padapter
->xmitpriv
.hwxmits
;
2103 phead
= get_list_head(pframequeue
);
2104 plist
= get_next(phead
);
2106 while (!rtw_end_of_queue_search(phead
, plist
)) {
2107 pxmitframe
= LIST_CONTAINOR(plist
, struct xmit_frame
, list
);
2109 plist
= get_next(plist
);
2111 xmitframe_enqueue_for_sleeping_sta(padapter
, pxmitframe
);
2113 pattrib
= &pxmitframe
->attrib
;
2115 ptxservq
= rtw_get_sta_pending(padapter
, psta
, pattrib
->priority
, (u8
*)(&ac_index
));
2118 phwxmits
[ac_index
].accnt
--;
2122 void stop_sta_xmit(struct adapter
*padapter
, struct sta_info
*psta
)
2124 unsigned long irql0
;
2125 struct sta_info
*psta_bmc
;
2126 struct sta_xmit_priv
*pstaxmitpriv
;
2127 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
2128 struct xmit_priv
*pxmitpriv
= &padapter
->xmitpriv
;
2130 pstaxmitpriv
= &psta
->sta_xmitpriv
;
2132 /* for BC/MC Frames */
2133 psta_bmc
= rtw_get_bcmc_stainfo(padapter
);
2135 _enter_critical_bh(&pxmitpriv
->lock
, &irql0
);
2137 psta
->state
|= WIFI_SLEEP_STATE
;
2139 pstapriv
->sta_dz_bitmap
|= BIT(psta
->aid
);
2141 dequeue_xmitframes_to_sleeping_queue(padapter
, psta
, &pstaxmitpriv
->vo_q
.sta_pending
);
2142 rtw_list_delete(&(pstaxmitpriv
->vo_q
.tx_pending
));
2144 dequeue_xmitframes_to_sleeping_queue(padapter
, psta
, &pstaxmitpriv
->vi_q
.sta_pending
);
2145 rtw_list_delete(&(pstaxmitpriv
->vi_q
.tx_pending
));
2147 dequeue_xmitframes_to_sleeping_queue(padapter
, psta
, &pstaxmitpriv
->be_q
.sta_pending
);
2148 rtw_list_delete(&(pstaxmitpriv
->be_q
.tx_pending
));
2150 dequeue_xmitframes_to_sleeping_queue(padapter
, psta
, &pstaxmitpriv
->bk_q
.sta_pending
);
2151 rtw_list_delete(&(pstaxmitpriv
->bk_q
.tx_pending
));
2153 /* for BC/MC Frames */
2154 pstaxmitpriv
= &psta_bmc
->sta_xmitpriv
;
2155 dequeue_xmitframes_to_sleeping_queue(padapter
, psta_bmc
, &pstaxmitpriv
->be_q
.sta_pending
);
2156 rtw_list_delete(&(pstaxmitpriv
->be_q
.tx_pending
));
2158 _exit_critical_bh(&pxmitpriv
->lock
, &irql0
);
2161 void wakeup_sta_to_xmit(struct adapter
*padapter
, struct sta_info
*psta
)
2164 u8 update_mask
= 0, wmmps_ac
= 0;
2165 struct sta_info
*psta_bmc
;
2166 struct list_head
*xmitframe_plist
, *xmitframe_phead
;
2167 struct xmit_frame
*pxmitframe
= NULL
;
2168 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
2170 _enter_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2172 xmitframe_phead
= get_list_head(&psta
->sleep_q
);
2173 xmitframe_plist
= get_next(xmitframe_phead
);
2175 while (!rtw_end_of_queue_search(xmitframe_phead
, xmitframe_plist
)) {
2176 pxmitframe
= LIST_CONTAINOR(xmitframe_plist
, struct xmit_frame
, list
);
2178 xmitframe_plist
= get_next(xmitframe_plist
);
2180 rtw_list_delete(&pxmitframe
->list
);
2182 switch (pxmitframe
->attrib
.priority
) {
2185 wmmps_ac
= psta
->uapsd_bk
&BIT(1);
2189 wmmps_ac
= psta
->uapsd_vi
&BIT(1);
2193 wmmps_ac
= psta
->uapsd_vo
&BIT(1);
2198 wmmps_ac
= psta
->uapsd_be
&BIT(1);
2203 if (psta
->sleepq_len
> 0)
2204 pxmitframe
->attrib
.mdata
= 1;
2206 pxmitframe
->attrib
.mdata
= 0;
2209 psta
->sleepq_ac_len
--;
2210 if (psta
->sleepq_ac_len
> 0) {
2211 pxmitframe
->attrib
.mdata
= 1;
2212 pxmitframe
->attrib
.eosp
= 0;
2214 pxmitframe
->attrib
.mdata
= 0;
2215 pxmitframe
->attrib
.eosp
= 1;
2219 pxmitframe
->attrib
.triggered
= 1;
2221 _exit_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2222 if (rtw_hal_xmit(padapter
, pxmitframe
))
2223 rtw_os_xmit_complete(padapter
, pxmitframe
);
2224 _enter_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2227 if (psta
->sleepq_len
== 0) {
2228 pstapriv
->tim_bitmap
&= ~BIT(psta
->aid
);
2230 update_mask
= BIT(0);
2232 if (psta
->state
&WIFI_SLEEP_STATE
)
2233 psta
->state
^= WIFI_SLEEP_STATE
;
2235 if (psta
->state
& WIFI_STA_ALIVE_CHK_STATE
) {
2236 psta
->expire_to
= pstapriv
->expire_to
;
2237 psta
->state
^= WIFI_STA_ALIVE_CHK_STATE
;
2240 pstapriv
->sta_dz_bitmap
&= ~BIT(psta
->aid
);
2243 _exit_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2245 /* for BC/MC Frames */
2246 psta_bmc
= rtw_get_bcmc_stainfo(padapter
);
2250 if ((pstapriv
->sta_dz_bitmap
&0xfffe) == 0x0) { /* no any sta in ps mode */
2251 _enter_critical_bh(&psta_bmc
->sleep_q
.lock
, &irql
);
2253 xmitframe_phead
= get_list_head(&psta_bmc
->sleep_q
);
2254 xmitframe_plist
= get_next(xmitframe_phead
);
2256 while (!rtw_end_of_queue_search(xmitframe_phead
, xmitframe_plist
)) {
2257 pxmitframe
= LIST_CONTAINOR(xmitframe_plist
, struct xmit_frame
, list
);
2259 xmitframe_plist
= get_next(xmitframe_plist
);
2261 rtw_list_delete(&pxmitframe
->list
);
2263 psta_bmc
->sleepq_len
--;
2264 if (psta_bmc
->sleepq_len
> 0)
2265 pxmitframe
->attrib
.mdata
= 1;
2267 pxmitframe
->attrib
.mdata
= 0;
2269 pxmitframe
->attrib
.triggered
= 1;
2271 _exit_critical_bh(&psta_bmc
->sleep_q
.lock
, &irql
);
2272 if (rtw_hal_xmit(padapter
, pxmitframe
))
2273 rtw_os_xmit_complete(padapter
, pxmitframe
);
2274 _enter_critical_bh(&psta_bmc
->sleep_q
.lock
, &irql
);
2277 if (psta_bmc
->sleepq_len
== 0) {
2278 pstapriv
->tim_bitmap
&= ~BIT(0);
2279 pstapriv
->sta_dz_bitmap
&= ~BIT(0);
2281 update_mask
|= BIT(1);
2284 _exit_critical_bh(&psta_bmc
->sleep_q
.lock
, &irql
);
2288 update_beacon(padapter
, _TIM_IE_
, NULL
, false);
2291 void xmit_delivery_enabled_frames(struct adapter
*padapter
, struct sta_info
*psta
)
2295 struct list_head
*xmitframe_plist
, *xmitframe_phead
;
2296 struct xmit_frame
*pxmitframe
= NULL
;
2297 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
2299 _enter_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2301 xmitframe_phead
= get_list_head(&psta
->sleep_q
);
2302 xmitframe_plist
= get_next(xmitframe_phead
);
2304 while (!rtw_end_of_queue_search(xmitframe_phead
, xmitframe_plist
)) {
2305 pxmitframe
= LIST_CONTAINOR(xmitframe_plist
, struct xmit_frame
, list
);
2307 xmitframe_plist
= get_next(xmitframe_plist
);
2309 switch (pxmitframe
->attrib
.priority
) {
2312 wmmps_ac
= psta
->uapsd_bk
&BIT(1);
2316 wmmps_ac
= psta
->uapsd_vi
&BIT(1);
2320 wmmps_ac
= psta
->uapsd_vo
&BIT(1);
2325 wmmps_ac
= psta
->uapsd_be
&BIT(1);
2332 rtw_list_delete(&pxmitframe
->list
);
2335 psta
->sleepq_ac_len
--;
2337 if (psta
->sleepq_ac_len
> 0) {
2338 pxmitframe
->attrib
.mdata
= 1;
2339 pxmitframe
->attrib
.eosp
= 0;
2341 pxmitframe
->attrib
.mdata
= 0;
2342 pxmitframe
->attrib
.eosp
= 1;
2345 pxmitframe
->attrib
.triggered
= 1;
2347 if (rtw_hal_xmit(padapter
, pxmitframe
) == true)
2348 rtw_os_xmit_complete(padapter
, pxmitframe
);
2350 if ((psta
->sleepq_ac_len
== 0) && (!psta
->has_legacy_ac
) && (wmmps_ac
)) {
2351 pstapriv
->tim_bitmap
&= ~BIT(psta
->aid
);
2353 /* upate BCN for TIM IE */
2354 update_beacon(padapter
, _TIM_IE_
, NULL
, false);
2358 _exit_critical_bh(&psta
->sleep_q
.lock
, &irql
);
2363 void rtw_sctx_init(struct submit_ctx
*sctx
, int timeout_ms
)
2365 sctx
->timeout_ms
= timeout_ms
;
2366 sctx
->submit_time
= rtw_get_current_time();
2367 init_completion(&sctx
->done
);
2368 sctx
->status
= RTW_SCTX_SUBMITTED
;
2371 int rtw_sctx_wait(struct submit_ctx
*sctx
)
2374 unsigned long expire
;
2377 expire
= sctx
->timeout_ms
? msecs_to_jiffies(sctx
->timeout_ms
) : MAX_SCHEDULE_TIMEOUT
;
2378 if (!wait_for_completion_timeout(&sctx
->done
, expire
)) {
2379 /* timeout, do something?? */
2380 status
= RTW_SCTX_DONE_TIMEOUT
;
2381 DBG_88E("%s timeout\n", __func__
);
2383 status
= sctx
->status
;
2386 if (status
== RTW_SCTX_DONE_SUCCESS
)
2392 static bool rtw_sctx_chk_waring_status(int status
)
2395 case RTW_SCTX_DONE_UNKNOWN
:
2396 case RTW_SCTX_DONE_BUF_ALLOC
:
2397 case RTW_SCTX_DONE_BUF_FREE
:
2399 case RTW_SCTX_DONE_DRV_STOP
:
2400 case RTW_SCTX_DONE_DEV_REMOVE
:
2407 void rtw_sctx_done_err(struct submit_ctx
**sctx
, int status
)
2410 if (rtw_sctx_chk_waring_status(status
))
2411 DBG_88E("%s status:%d\n", __func__
, status
);
2412 (*sctx
)->status
= status
;
2413 complete(&((*sctx
)->done
));
2418 void rtw_sctx_done(struct submit_ctx
**sctx
)
2420 rtw_sctx_done_err(sctx
, RTW_SCTX_DONE_SUCCESS
);
2423 int rtw_ack_tx_wait(struct xmit_priv
*pxmitpriv
, u32 timeout_ms
)
2425 struct submit_ctx
*pack_tx_ops
= &pxmitpriv
->ack_tx_ops
;
2427 pack_tx_ops
->submit_time
= rtw_get_current_time();
2428 pack_tx_ops
->timeout_ms
= timeout_ms
;
2429 pack_tx_ops
->status
= RTW_SCTX_SUBMITTED
;
2431 return rtw_sctx_wait(pack_tx_ops
);
2434 void rtw_ack_tx_done(struct xmit_priv
*pxmitpriv
, int status
)
2436 struct submit_ctx
*pack_tx_ops
= &pxmitpriv
->ack_tx_ops
;
2438 if (pxmitpriv
->ack_tx
)
2439 rtw_sctx_done_err(&pack_tx_ops
, status
);
2441 DBG_88E("%s ack_tx not set\n", __func__
);