d5ce1e2a16588fa1de632224fe8da58d25c20862
[deliverable/linux.git] / drivers / staging / rtl8188eu / core / rtw_xmit.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #define _RTW_XMIT_C_
21
22 #include <osdep_service.h>
23 #include <drv_types.h>
24 #include <mon.h>
25 #include <wifi.h>
26 #include <osdep_intf.h>
27 #include <linux/vmalloc.h>
28
29 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
30 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
31
32 static void _init_txservq(struct tx_servq *ptxservq)
33 {
34 INIT_LIST_HEAD(&ptxservq->tx_pending);
35 _rtw_init_queue(&ptxservq->sta_pending);
36 ptxservq->qcnt = 0;
37 }
38
39 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
40 {
41 memset((unsigned char *)psta_xmitpriv, 0, sizeof(struct sta_xmit_priv));
42 spin_lock_init(&psta_xmitpriv->lock);
43 _init_txservq(&psta_xmitpriv->be_q);
44 _init_txservq(&psta_xmitpriv->bk_q);
45 _init_txservq(&psta_xmitpriv->vi_q);
46 _init_txservq(&psta_xmitpriv->vo_q);
47 INIT_LIST_HEAD(&psta_xmitpriv->legacy_dz);
48 INIT_LIST_HEAD(&psta_xmitpriv->apsd);
49
50 }
51
52 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
53 {
54 int i;
55 struct xmit_buf *pxmitbuf;
56 struct xmit_frame *pxframe;
57 int res = _SUCCESS;
58 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
59 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
60
61
62 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
63
64 spin_lock_init(&pxmitpriv->lock);
65 sema_init(&pxmitpriv->xmit_sema, 0);
66 sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
67
68 /*
69 Please insert all the queue initializaiton using _rtw_init_queue below
70 */
71
72 pxmitpriv->adapter = padapter;
73
74 _rtw_init_queue(&pxmitpriv->be_pending);
75 _rtw_init_queue(&pxmitpriv->bk_pending);
76 _rtw_init_queue(&pxmitpriv->vi_pending);
77 _rtw_init_queue(&pxmitpriv->vo_pending);
78 _rtw_init_queue(&pxmitpriv->bm_pending);
79
80 _rtw_init_queue(&pxmitpriv->free_xmit_queue);
81
82 /*
83 Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
84 and initialize free_xmit_frame below.
85 Please also apply free_txobj to link_up all the xmit_frames...
86 */
87
88 pxmitpriv->pallocated_frame_buf = vzalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
89
90 if (pxmitpriv->pallocated_frame_buf == NULL) {
91 pxmitpriv->pxmit_frame_buf = NULL;
92 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_frame fail!\n"));
93 res = _FAIL;
94 goto exit;
95 }
96 pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_frame_buf), 4);
97 /* pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - */
98 /* ((size_t) (pxmitpriv->pallocated_frame_buf) &3); */
99
100 pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
101
102 for (i = 0; i < NR_XMITFRAME; i++) {
103 INIT_LIST_HEAD(&(pxframe->list));
104
105 pxframe->padapter = padapter;
106 pxframe->frame_tag = NULL_FRAMETAG;
107
108 pxframe->pkt = NULL;
109
110 pxframe->buf_addr = NULL;
111 pxframe->pxmitbuf = NULL;
112
113 list_add_tail(&(pxframe->list), &(pxmitpriv->free_xmit_queue.queue));
114
115 pxframe++;
116 }
117
118 pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
119
120 pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
121
122 /* init xmit_buf */
123 _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue);
124 _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue);
125
126 pxmitpriv->pallocated_xmitbuf = vzalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
127
128 if (pxmitpriv->pallocated_xmitbuf == NULL) {
129 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_buf fail!\n"));
130 res = _FAIL;
131 goto exit;
132 }
133
134 pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmitbuf), 4);
135 /* pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - */
136 /* ((size_t) (pxmitpriv->pallocated_xmitbuf) &3); */
137
138 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
139
140 for (i = 0; i < NR_XMITBUFF; i++) {
141 INIT_LIST_HEAD(&pxmitbuf->list);
142
143 pxmitbuf->priv_data = NULL;
144 pxmitbuf->padapter = padapter;
145 pxmitbuf->ext_tag = false;
146
147 /* Tx buf allocation may fail sometimes, so sleep and retry. */
148 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
149 if (res == _FAIL) {
150 msleep(10);
151 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
152 if (res == _FAIL) {
153 goto exit;
154 }
155 }
156
157 pxmitbuf->flags = XMIT_VO_QUEUE;
158
159 list_add_tail(&pxmitbuf->list, &(pxmitpriv->free_xmitbuf_queue.queue));
160 pxmitbuf++;
161 }
162
163 pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
164
165 /* Init xmit extension buff */
166 _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
167
168 pxmitpriv->pallocated_xmit_extbuf = vzalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
169
170 if (pxmitpriv->pallocated_xmit_extbuf == NULL) {
171 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_extbuf fail!\n"));
172 res = _FAIL;
173 goto exit;
174 }
175
176 pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmit_extbuf), 4);
177
178 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
179
180 for (i = 0; i < num_xmit_extbuf; i++) {
181 INIT_LIST_HEAD(&pxmitbuf->list);
182
183 pxmitbuf->priv_data = NULL;
184 pxmitbuf->padapter = padapter;
185 pxmitbuf->ext_tag = true;
186
187 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, max_xmit_extbuf_size + XMITBUF_ALIGN_SZ);
188 if (res == _FAIL) {
189 res = _FAIL;
190 goto exit;
191 }
192
193 list_add_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
194 pxmitbuf++;
195 }
196
197 pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
198
199 rtw_alloc_hwxmits(padapter);
200 rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
201
202 for (i = 0; i < 4; i++)
203 pxmitpriv->wmm_para_seq[i] = i;
204
205 pxmitpriv->txirp_cnt = 1;
206
207 sema_init(&(pxmitpriv->tx_retevt), 0);
208
209 /* per AC pending irp */
210 pxmitpriv->beq_cnt = 0;
211 pxmitpriv->bkq_cnt = 0;
212 pxmitpriv->viq_cnt = 0;
213 pxmitpriv->voq_cnt = 0;
214
215 pxmitpriv->ack_tx = false;
216 mutex_init(&pxmitpriv->ack_tx_mutex);
217 rtw_sctx_init(&pxmitpriv->ack_tx_ops, 0);
218
219 rtw_hal_init_xmit_priv(padapter);
220
221 exit:
222
223
224 return res;
225 }
226
227 void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv)
228 {
229 int i;
230 struct adapter *padapter = pxmitpriv->adapter;
231 struct xmit_frame *pxmitframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
232 struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
233 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
234 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
235
236 if (pxmitpriv->pxmit_frame_buf == NULL)
237 return;
238
239 for (i = 0; i < NR_XMITFRAME; i++) {
240 rtw_os_xmit_complete(padapter, pxmitframe);
241
242 pxmitframe++;
243 }
244
245 for (i = 0; i < NR_XMITBUFF; i++) {
246 rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
247 pxmitbuf++;
248 }
249
250 if (pxmitpriv->pallocated_frame_buf)
251 vfree(pxmitpriv->pallocated_frame_buf);
252
253 if (pxmitpriv->pallocated_xmitbuf)
254 vfree(pxmitpriv->pallocated_xmitbuf);
255
256 /* free xmit extension buff */
257 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
258 for (i = 0; i < num_xmit_extbuf; i++) {
259 rtw_os_xmit_resource_free(padapter, pxmitbuf, (max_xmit_extbuf_size + XMITBUF_ALIGN_SZ));
260 pxmitbuf++;
261 }
262
263 if (pxmitpriv->pallocated_xmit_extbuf) {
264 vfree(pxmitpriv->pallocated_xmit_extbuf);
265 }
266
267 rtw_free_hwxmits(padapter);
268
269 mutex_destroy(&pxmitpriv->ack_tx_mutex);
270 }
271
272 static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *pxmitframe)
273 {
274 u32 sz;
275 struct pkt_attrib *pattrib = &pxmitframe->attrib;
276 struct sta_info *psta = pattrib->psta;
277 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
278 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
279
280 if (pattrib->nr_frags != 1)
281 sz = padapter->xmitpriv.frag_len;
282 else /* no frag */
283 sz = pattrib->last_txcmdsz;
284
285 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
286 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
287 /* Other fragments are protected by previous fragment. */
288 /* So we only need to check the length of first fragment. */
289 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
290 if (sz > padapter->registrypriv.rts_thresh) {
291 pattrib->vcs_mode = RTS_CTS;
292 } else {
293 if (psta->rtsen)
294 pattrib->vcs_mode = RTS_CTS;
295 else if (psta->cts2self)
296 pattrib->vcs_mode = CTS_TO_SELF;
297 else
298 pattrib->vcs_mode = NONE_VCS;
299 }
300 } else {
301 while (true) {
302 /* IOT action */
303 if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS) && pattrib->ampdu_en &&
304 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
305 pattrib->vcs_mode = CTS_TO_SELF;
306 break;
307 }
308
309 /* check ERP protection */
310 if (psta->rtsen || psta->cts2self) {
311 if (psta->rtsen)
312 pattrib->vcs_mode = RTS_CTS;
313 else if (psta->cts2self)
314 pattrib->vcs_mode = CTS_TO_SELF;
315
316 break;
317 }
318
319 /* check HT op mode */
320 if (pattrib->ht_en) {
321 u8 htopmode = pmlmeinfo->HT_protection;
322 if ((pmlmeext->cur_bwmode && (htopmode == 2 || htopmode == 3)) ||
323 (!pmlmeext->cur_bwmode && htopmode == 3)) {
324 pattrib->vcs_mode = RTS_CTS;
325 break;
326 }
327 }
328
329 /* check rts */
330 if (sz > padapter->registrypriv.rts_thresh) {
331 pattrib->vcs_mode = RTS_CTS;
332 break;
333 }
334
335 /* to do list: check MIMO power save condition. */
336
337 /* check AMPDU aggregation for TXOP */
338 if (pattrib->ampdu_en) {
339 pattrib->vcs_mode = RTS_CTS;
340 break;
341 }
342
343 pattrib->vcs_mode = NONE_VCS;
344 break;
345 }
346 }
347 }
348
349 static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
350 {
351 /*if (psta->rtsen)
352 pattrib->vcs_mode = RTS_CTS;
353 else if (psta->cts2self)
354 pattrib->vcs_mode = CTS_TO_SELF;
355 else
356 pattrib->vcs_mode = NONE_VCS;*/
357
358 pattrib->mdata = 0;
359 pattrib->eosp = 0;
360 pattrib->triggered = 0;
361
362 /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
363 pattrib->qos_en = psta->qos_option;
364
365 pattrib->raid = psta->raid;
366 pattrib->ht_en = psta->htpriv.ht_option;
367 pattrib->bwmode = psta->htpriv.bwmode;
368 pattrib->ch_offset = psta->htpriv.ch_offset;
369 pattrib->sgi = psta->htpriv.sgi;
370 pattrib->ampdu_en = false;
371 pattrib->retry_ctrl = false;
372 }
373
374 u8 qos_acm(u8 acm_mask, u8 priority)
375 {
376 u8 change_priority = priority;
377
378 switch (priority) {
379 case 0:
380 case 3:
381 if (acm_mask & BIT(1))
382 change_priority = 1;
383 break;
384 case 1:
385 case 2:
386 break;
387 case 4:
388 case 5:
389 if (acm_mask & BIT(2))
390 change_priority = 0;
391 break;
392 case 6:
393 case 7:
394 if (acm_mask & BIT(3))
395 change_priority = 5;
396 break;
397 default:
398 DBG_88E("qos_acm(): invalid pattrib->priority: %d!!!\n", priority);
399 break;
400 }
401
402 return change_priority;
403 }
404
405 static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
406 {
407 struct ethhdr etherhdr;
408 struct iphdr ip_hdr;
409 s32 user_prio = 0;
410
411 _rtw_open_pktfile(ppktfile->pkt, ppktfile);
412 _rtw_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
413
414 /* get user_prio from IP hdr */
415 if (pattrib->ether_type == 0x0800) {
416 _rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
417 /* user_prio = (ntohs(ip_hdr.tos) >> 5) & 0x3; */
418 user_prio = ip_hdr.tos >> 5;
419 } else if (pattrib->ether_type == 0x888e) {
420 /* "When priority processing of data frames is supported, */
421 /* a STA's SME should send EAPOL-Key frames at the highest priority." */
422 user_prio = 7;
423 }
424
425 pattrib->priority = user_prio;
426 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
427 pattrib->subtype = WIFI_QOS_DATA_TYPE;
428 }
429
430 static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pkt_attrib *pattrib)
431 {
432 struct pkt_file pktfile;
433 struct sta_info *psta = NULL;
434 struct ethhdr etherhdr;
435
436 int bmcast;
437 struct sta_priv *pstapriv = &padapter->stapriv;
438 struct security_priv *psecuritypriv = &padapter->securitypriv;
439 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
440 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
441 int res = _SUCCESS;
442
443
444 _rtw_open_pktfile(pkt, &pktfile);
445 _rtw_pktfile_read(&pktfile, (u8 *)&etherhdr, ETH_HLEN);
446
447 pattrib->ether_type = ntohs(etherhdr.h_proto);
448
449 memcpy(pattrib->dst, &etherhdr.h_dest, ETH_ALEN);
450 memcpy(pattrib->src, &etherhdr.h_source, ETH_ALEN);
451
452 pattrib->pctrl = 0;
453
454 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
455 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
456 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
457 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
458 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
459 memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
460 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
461 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
462 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
463 memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
464 }
465
466 pattrib->pktlen = pktfile.pkt_len;
467
468 if (ETH_P_IP == pattrib->ether_type) {
469 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */
470 /* to prevent DHCP protocol fail */
471 u8 tmp[24];
472 _rtw_pktfile_read(&pktfile, &tmp[0], 24);
473 pattrib->dhcp_pkt = 0;
474 if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
475 if (ETH_P_IP == pattrib->ether_type) {/* IP header */
476 if (((tmp[21] == 68) && (tmp[23] == 67)) ||
477 ((tmp[21] == 67) && (tmp[23] == 68))) {
478 /* 68 : UDP BOOTP client */
479 /* 67 : UDP BOOTP server */
480 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====================== update_attrib: get DHCP Packet\n"));
481 /* Use low rate to send DHCP packet. */
482 pattrib->dhcp_pkt = 1;
483 }
484 }
485 }
486 } else if (0x888e == pattrib->ether_type) {
487 DBG_88E_LEVEL(_drv_info_, "send eapol packet\n");
488 }
489
490 if ((pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
491 rtw_set_scan_deny(padapter, 3000);
492
493 /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
494 if ((pattrib->ether_type == 0x0806) || (pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
495 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
496
497 bmcast = IS_MCAST(pattrib->ra);
498
499 /* get sta_info */
500 if (bmcast) {
501 psta = rtw_get_bcmc_stainfo(padapter);
502 } else {
503 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
504 if (psta == NULL) { /* if we cannot get psta => drrp the pkt */
505 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra: %pM\n", (pattrib->ra)));
506 res = _FAIL;
507 goto exit;
508 } else if ((check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) && (!(psta->state & _FW_LINKED))) {
509 res = _FAIL;
510 goto exit;
511 }
512 }
513
514 if (psta) {
515 pattrib->mac_id = psta->mac_id;
516 /* DBG_88E("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
517 pattrib->psta = psta;
518 } else {
519 /* if we cannot get psta => drop the pkt */
520 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:%pM\n", (pattrib->ra)));
521 res = _FAIL;
522 goto exit;
523 }
524
525 pattrib->ack_policy = 0;
526 /* get ether_hdr_len */
527 pattrib->pkt_hdrlen = ETH_HLEN;/* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
528
529 pattrib->hdrlen = WLAN_HDR_A3_LEN;
530 pattrib->subtype = WIFI_DATA_TYPE;
531 pattrib->priority = 0;
532
533 if (check_fwstate(pmlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) {
534 if (psta->qos_option)
535 set_qos(&pktfile, pattrib);
536 } else {
537 if (pqospriv->qos_option) {
538 set_qos(&pktfile, pattrib);
539
540 if (pmlmepriv->acm_mask != 0)
541 pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
542 }
543 }
544
545 if (psta->ieee8021x_blocked) {
546 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\n psta->ieee8021x_blocked == true\n"));
547
548 pattrib->encrypt = 0;
549
550 if ((pattrib->ether_type != 0x888e) && !check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
551 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != 0x888e\n", pattrib->ether_type));
552 res = _FAIL;
553 goto exit;
554 }
555 } else {
556 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
557
558 switch (psecuritypriv->dot11AuthAlgrthm) {
559 case dot11AuthAlgrthm_Open:
560 case dot11AuthAlgrthm_Shared:
561 case dot11AuthAlgrthm_Auto:
562 pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
563 break;
564 case dot11AuthAlgrthm_8021X:
565 if (bmcast)
566 pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid;
567 else
568 pattrib->key_idx = 0;
569 break;
570 default:
571 pattrib->key_idx = 0;
572 break;
573 }
574 }
575
576 switch (pattrib->encrypt) {
577 case _WEP40_:
578 case _WEP104_:
579 pattrib->iv_len = 4;
580 pattrib->icv_len = 4;
581 break;
582 case _TKIP_:
583 pattrib->iv_len = 8;
584 pattrib->icv_len = 4;
585
586 if (padapter->securitypriv.busetkipkey == _FAIL) {
587 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
588 ("\npadapter->securitypriv.busetkipkey(%d) == _FAIL drop packet\n",
589 padapter->securitypriv.busetkipkey));
590 res = _FAIL;
591 goto exit;
592 }
593 break;
594 case _AES_:
595 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("pattrib->encrypt=%d (_AES_)\n", pattrib->encrypt));
596 pattrib->iv_len = 8;
597 pattrib->icv_len = 8;
598 break;
599 default:
600 pattrib->iv_len = 0;
601 pattrib->icv_len = 0;
602 break;
603 }
604
605 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
606 ("update_attrib: encrypt=%d securitypriv.sw_encrypt=%d\n",
607 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
608
609 if (pattrib->encrypt &&
610 (padapter->securitypriv.sw_encrypt || !psecuritypriv->hw_decrypted)) {
611 pattrib->bswenc = true;
612 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
613 ("update_attrib: encrypt=%d securitypriv.hw_decrypted=%d bswenc = true\n",
614 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
615 } else {
616 pattrib->bswenc = false;
617 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("update_attrib: bswenc = false\n"));
618 }
619
620 update_attrib_phy_info(pattrib, psta);
621
622 exit:
623
624
625 return res;
626 }
627
628 static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitframe)
629 {
630 int curfragnum, length;
631 u8 *pframe, *payload, mic[8];
632 struct mic_data micdata;
633 struct sta_info *stainfo;
634 struct pkt_attrib *pattrib = &pxmitframe->attrib;
635 struct security_priv *psecuritypriv = &padapter->securitypriv;
636 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
637 u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
638 u8 hw_hdr_offset = 0;
639 int bmcst = IS_MCAST(pattrib->ra);
640
641 if (pattrib->psta)
642 stainfo = pattrib->psta;
643 else
644 stainfo = rtw_get_stainfo(&padapter->stapriv, &pattrib->ra[0]);
645
646
647 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
648
649 if (pattrib->encrypt == _TKIP_) {/* if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_PRIVACY_) */
650 /* encode mic code */
651 if (stainfo != NULL) {
652 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
653 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
654 0x0, 0x0};
655
656 pframe = pxmitframe->buf_addr + hw_hdr_offset;
657
658 if (bmcst) {
659 if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16))
660 return _FAIL;
661 /* start to calculate the mic code */
662 rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
663 } else {
664 if (!memcmp(&stainfo->dot11tkiptxmickey.skey[0], null_key, 16)) {
665 /* DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey == 0\n"); */
666 /* msleep(10); */
667 return _FAIL;
668 }
669 /* start to calculate the mic code */
670 rtw_secmicsetkey(&micdata, &stainfo->dot11tkiptxmickey.skey[0]);
671 }
672
673 if (pframe[1]&1) { /* ToDS == 1 */
674 rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */
675 if (pframe[1]&2) /* From Ds == 1 */
676 rtw_secmicappend(&micdata, &pframe[24], 6);
677 else
678 rtw_secmicappend(&micdata, &pframe[10], 6);
679 } else { /* ToDS == 0 */
680 rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */
681 if (pframe[1]&2) /* From Ds == 1 */
682 rtw_secmicappend(&micdata, &pframe[16], 6);
683 else
684 rtw_secmicappend(&micdata, &pframe[10], 6);
685 }
686
687 if (pattrib->qos_en)
688 priority[0] = (u8)pxmitframe->attrib.priority;
689
690 rtw_secmicappend(&micdata, &priority[0], 4);
691
692 payload = pframe;
693
694 for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
695 payload = (u8 *)round_up((size_t)(payload), 4);
696 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
697 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
698 curfragnum, *payload, *(payload+1),
699 *(payload+2), *(payload+3),
700 *(payload+4), *(payload+5),
701 *(payload+6), *(payload+7)));
702
703 payload = payload+pattrib->hdrlen+pattrib->iv_len;
704 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
705 ("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d",
706 curfragnum, pattrib->hdrlen, pattrib->iv_len));
707 if ((curfragnum+1) == pattrib->nr_frags) {
708 length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
709 rtw_secmicappend(&micdata, payload, length);
710 payload = payload+length;
711 } else {
712 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
713 rtw_secmicappend(&micdata, payload, length);
714 payload = payload+length+pattrib->icv_len;
715 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum=%d length=%d pattrib->icv_len=%d", curfragnum, length, pattrib->icv_len));
716 }
717 }
718 rtw_secgetmic(&micdata, &(mic[0]));
719 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: before add mic code!!!\n"));
720 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: pattrib->last_txcmdsz=%d!!!\n", pattrib->last_txcmdsz));
721 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\
722 mic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x , mic[7]= 0x%.2x !!!!\n",
723 mic[0], mic[1], mic[2], mic[3], mic[4], mic[5], mic[6], mic[7]));
724 /* add mic code and add the mic code length in last_txcmdsz */
725
726 memcpy(payload, &(mic[0]), 8);
727 pattrib->last_txcmdsz += 8;
728
729 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("\n ======== last pkt ========\n"));
730 payload = payload-pattrib->last_txcmdsz+8;
731 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz; curfragnum = curfragnum+8)
732 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
733 (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
734 *(payload+curfragnum), *(payload+curfragnum+1),
735 *(payload+curfragnum+2), *(payload+curfragnum+3),
736 *(payload+curfragnum+4), *(payload+curfragnum+5),
737 *(payload+curfragnum+6), *(payload+curfragnum+7)));
738 } else {
739 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: rtw_get_stainfo==NULL!!!\n"));
740 }
741 }
742
743
744 return _SUCCESS;
745 }
746
747 static s32 xmitframe_swencrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
748 {
749 struct pkt_attrib *pattrib = &pxmitframe->attrib;
750
751
752 if (pattrib->bswenc) {
753 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("### xmitframe_swencrypt\n"));
754 switch (pattrib->encrypt) {
755 case _WEP40_:
756 case _WEP104_:
757 rtw_wep_encrypt(padapter, (u8 *)pxmitframe);
758 break;
759 case _TKIP_:
760 rtw_tkip_encrypt(padapter, (u8 *)pxmitframe);
761 break;
762 case _AES_:
763 rtw_aes_encrypt(padapter, (u8 *)pxmitframe);
764 break;
765 default:
766 break;
767 }
768 } else {
769 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_, ("### xmitframe_hwencrypt\n"));
770 }
771
772
773 return _SUCCESS;
774 }
775
776 s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib)
777 {
778 u16 *qc;
779
780 struct rtw_ieee80211_hdr *pwlanhdr = (struct rtw_ieee80211_hdr *)hdr;
781 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
782 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
783 u8 qos_option = false;
784
785 int res = _SUCCESS;
786 __le16 *fctrl = &pwlanhdr->frame_ctl;
787
788 struct sta_info *psta;
789
790 int bmcst = IS_MCAST(pattrib->ra);
791
792
793 if (pattrib->psta) {
794 psta = pattrib->psta;
795 } else {
796 if (bmcst) {
797 psta = rtw_get_bcmc_stainfo(padapter);
798 } else {
799 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
800 }
801 }
802
803 memset(hdr, 0, WLANHDR_OFFSET);
804
805 SetFrameSubType(fctrl, pattrib->subtype);
806
807 if (pattrib->subtype & WIFI_DATA_TYPE) {
808 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)) {
809 /* to_ds = 1, fr_ds = 0; */
810 /* Data transfer to AP */
811 SetToDs(fctrl);
812 memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
813 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
814 memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
815
816 if (pqospriv->qos_option)
817 qos_option = true;
818 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
819 /* to_ds = 0, fr_ds = 1; */
820 SetFrDs(fctrl);
821 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
822 memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), ETH_ALEN);
823 memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
824
825 if (psta->qos_option)
826 qos_option = true;
827 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
828 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
829 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
830 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
831 memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
832
833 if (psta->qos_option)
834 qos_option = true;
835 } else {
836 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv)));
837 res = _FAIL;
838 goto exit;
839 }
840
841 if (pattrib->mdata)
842 SetMData(fctrl);
843
844 if (pattrib->encrypt)
845 SetPrivacy(fctrl);
846
847 if (qos_option) {
848 qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
849
850 if (pattrib->priority)
851 SetPriority(qc, pattrib->priority);
852
853 SetEOSP(qc, pattrib->eosp);
854
855 SetAckpolicy(qc, pattrib->ack_policy);
856 }
857
858 /* TODO: fill HT Control Field */
859
860 /* Update Seq Num will be handled by f/w */
861 if (psta) {
862 psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
863 psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
864
865 pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
866
867 SetSeqNum(hdr, pattrib->seqnum);
868
869 /* check if enable ampdu */
870 if (pattrib->ht_en && psta->htpriv.ampdu_enable) {
871 if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
872 pattrib->ampdu_en = true;
873 }
874
875 /* re-check if enable ampdu by BA_starting_seqctrl */
876 if (pattrib->ampdu_en) {
877 u16 tx_seq;
878
879 tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
880
881 /* check BA_starting_seqctrl */
882 if (SN_LESS(pattrib->seqnum, tx_seq)) {
883 pattrib->ampdu_en = false;/* AGG BK */
884 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
885 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
886
887 pattrib->ampdu_en = true;/* AGG EN */
888 } else {
889 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
890 pattrib->ampdu_en = true;/* AGG EN */
891 }
892 }
893 }
894 }
895 exit:
896
897 return res;
898 }
899
900 s32 rtw_txframes_pending(struct adapter *padapter)
901 {
902 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
903
904 return (!list_empty(&pxmitpriv->be_pending.queue) ||
905 !list_empty(&pxmitpriv->bk_pending.queue) ||
906 !list_empty(&pxmitpriv->vi_pending.queue) ||
907 !list_empty(&pxmitpriv->vo_pending.queue));
908 }
909
910 s32 rtw_txframes_sta_ac_pending(struct adapter *padapter, struct pkt_attrib *pattrib)
911 {
912 struct sta_info *psta;
913 struct tx_servq *ptxservq;
914 int priority = pattrib->priority;
915
916 psta = pattrib->psta;
917
918 switch (priority) {
919 case 1:
920 case 2:
921 ptxservq = &(psta->sta_xmitpriv.bk_q);
922 break;
923 case 4:
924 case 5:
925 ptxservq = &(psta->sta_xmitpriv.vi_q);
926 break;
927 case 6:
928 case 7:
929 ptxservq = &(psta->sta_xmitpriv.vo_q);
930 break;
931 case 0:
932 case 3:
933 default:
934 ptxservq = &(psta->sta_xmitpriv.be_q);
935 break;
936 }
937
938 return ptxservq->qcnt;
939 }
940
941 /*
942 * Calculate wlan 802.11 packet MAX size from pkt_attrib
943 * This function doesn't consider fragment case
944 */
945 u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib)
946 {
947 u32 len = 0;
948
949 len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */
950 len += SNAP_SIZE + sizeof(u16); /* LLC */
951 len += pattrib->pktlen;
952 if (pattrib->encrypt == _TKIP_)
953 len += 8; /* MIC */
954 len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */
955
956 return len;
957 }
958
959 /*
960
961 This sub-routine will perform all the following:
962
963 1. remove 802.3 header.
964 2. create wlan_header, based on the info in pxmitframe
965 3. append sta's iv/ext-iv
966 4. append LLC
967 5. move frag chunk from pframe to pxmitframe->mem
968 6. apply sw-encrypt, if necessary.
969
970 */
971 s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe)
972 {
973 struct pkt_file pktfile;
974 s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
975 size_t addr;
976 u8 *pframe, *mem_start;
977 u8 hw_hdr_offset;
978 struct sta_info *psta;
979 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
980 struct pkt_attrib *pattrib = &pxmitframe->attrib;
981 u8 *pbuf_start;
982 s32 bmcst = IS_MCAST(pattrib->ra);
983 s32 res = _SUCCESS;
984
985
986 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
987
988 if (psta == NULL)
989 return _FAIL;
990
991 if (pxmitframe->buf_addr == NULL) {
992 DBG_88E("==> %s buf_addr == NULL\n", __func__);
993 return _FAIL;
994 }
995
996 pbuf_start = pxmitframe->buf_addr;
997
998 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
999
1000 mem_start = pbuf_start + hw_hdr_offset;
1001
1002 if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
1003 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n"));
1004 DBG_88E("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n");
1005 res = _FAIL;
1006 goto exit;
1007 }
1008
1009 _rtw_open_pktfile(pkt, &pktfile);
1010 _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
1011
1012 frg_inx = 0;
1013 frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
1014
1015 while (1) {
1016 llc_sz = 0;
1017
1018 mpdu_len = frg_len;
1019
1020 pframe = mem_start;
1021
1022 SetMFrag(mem_start);
1023
1024 pframe += pattrib->hdrlen;
1025 mpdu_len -= pattrib->hdrlen;
1026
1027 /* adding icv, if necessary... */
1028 if (pattrib->iv_len) {
1029 switch (pattrib->encrypt) {
1030 case _WEP40_:
1031 case _WEP104_:
1032 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1033 break;
1034 case _TKIP_:
1035 if (bmcst)
1036 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1037 else
1038 TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
1039 break;
1040 case _AES_:
1041 if (bmcst)
1042 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1043 else
1044 AES_IV(pattrib->iv, psta->dot11txpn, 0);
1045 break;
1046 }
1047
1048 memcpy(pframe, pattrib->iv, pattrib->iv_len);
1049
1050 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
1051 ("rtw_xmitframe_coalesce: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n",
1052 padapter->securitypriv.dot11PrivacyKeyIndex, pattrib->iv[3], *pframe, *(pframe+1), *(pframe+2), *(pframe+3)));
1053
1054 pframe += pattrib->iv_len;
1055
1056 mpdu_len -= pattrib->iv_len;
1057 }
1058
1059 if (frg_inx == 0) {
1060 llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
1061 pframe += llc_sz;
1062 mpdu_len -= llc_sz;
1063 }
1064
1065 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1066 mpdu_len -= pattrib->icv_len;
1067 }
1068
1069 if (bmcst) {
1070 /* don't do fragment to broadcat/multicast packets */
1071 mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen);
1072 } else {
1073 mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
1074 }
1075
1076 pframe += mem_sz;
1077
1078 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1079 memcpy(pframe, pattrib->icv, pattrib->icv_len);
1080 pframe += pattrib->icv_len;
1081 }
1082
1083 frg_inx++;
1084
1085 if (bmcst || rtw_endofpktfile(&pktfile)) {
1086 pattrib->nr_frags = frg_inx;
1087
1088 pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz : 0) +
1089 ((pattrib->bswenc) ? pattrib->icv_len : 0) + mem_sz;
1090
1091 ClearMFrag(mem_start);
1092
1093 break;
1094 } else {
1095 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("%s: There're still something in packet!\n", __func__));
1096 }
1097
1098 addr = (size_t)(pframe);
1099
1100 mem_start = (unsigned char *)round_up(addr, 4) + hw_hdr_offset;
1101 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
1102 }
1103
1104 /* Frame is about to be encrypted. Forward it to the monitor first. */
1105 rtl88eu_mon_xmit_hook(padapter->pmondev, pxmitframe, frg_len);
1106
1107 if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
1108 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
1109 DBG_88E("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
1110 res = _FAIL;
1111 goto exit;
1112 }
1113
1114 xmitframe_swencrypt(padapter, pxmitframe);
1115
1116 if (!bmcst)
1117 update_attrib_vcs_info(padapter, pxmitframe);
1118 else
1119 pattrib->vcs_mode = NONE_VCS;
1120
1121 exit:
1122
1123
1124 return res;
1125 }
1126
1127 /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1128 * IEEE LLC/SNAP header contains 8 octets
1129 * First 3 octets comprise the LLC portion
1130 * SNAP portion, 5 octets, is divided into two fields:
1131 * Organizationally Unique Identifier(OUI), 3 octets,
1132 * type, defined by that organization, 2 octets.
1133 */
1134 s32 rtw_put_snap(u8 *data, u16 h_proto)
1135 {
1136 struct ieee80211_snap_hdr *snap;
1137 u8 *oui;
1138
1139
1140 snap = (struct ieee80211_snap_hdr *)data;
1141 snap->dsap = 0xaa;
1142 snap->ssap = 0xaa;
1143 snap->ctrl = 0x03;
1144
1145 if (h_proto == 0x8137 || h_proto == 0x80f3)
1146 oui = P802_1H_OUI;
1147 else
1148 oui = RFC1042_OUI;
1149
1150 snap->oui[0] = oui[0];
1151 snap->oui[1] = oui[1];
1152 snap->oui[2] = oui[2];
1153
1154 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
1155
1156
1157 return SNAP_SIZE + sizeof(u16);
1158 }
1159
1160 void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len)
1161 {
1162 uint protection;
1163 u8 *perp;
1164 int erp_len;
1165 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1166 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1167
1168
1169 switch (pxmitpriv->vcs_setting) {
1170 case DISABLE_VCS:
1171 pxmitpriv->vcs = NONE_VCS;
1172 break;
1173 case ENABLE_VCS:
1174 break;
1175 case AUTO_VCS:
1176 default:
1177 perp = rtw_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
1178 if (perp == NULL) {
1179 pxmitpriv->vcs = NONE_VCS;
1180 } else {
1181 protection = (*(perp + 2)) & BIT(1);
1182 if (protection) {
1183 if (pregistrypriv->vcs_type == RTS_CTS)
1184 pxmitpriv->vcs = RTS_CTS;
1185 else
1186 pxmitpriv->vcs = CTS_TO_SELF;
1187 } else {
1188 pxmitpriv->vcs = NONE_VCS;
1189 }
1190 }
1191 break;
1192 }
1193
1194 }
1195
1196 void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz)
1197 {
1198 struct sta_info *psta = NULL;
1199 struct stainfo_stats *pstats = NULL;
1200 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1201 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1202
1203 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) {
1204 pxmitpriv->tx_bytes += sz;
1205 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pxmitframe->agg_num;
1206
1207 psta = pxmitframe->attrib.psta;
1208 if (psta) {
1209 pstats = &psta->sta_stats;
1210 pstats->tx_pkts += pxmitframe->agg_num;
1211 pstats->tx_bytes += sz;
1212 }
1213 }
1214 }
1215
1216 struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
1217 {
1218 unsigned long irql;
1219 struct xmit_buf *pxmitbuf;
1220 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1221
1222 spin_lock_irqsave(&pfree_queue->lock, irql);
1223 pxmitbuf = list_first_entry_or_null(&pfree_queue->queue,
1224 struct xmit_buf, list);
1225 if (pxmitbuf) {
1226 list_del_init(&pxmitbuf->list);
1227 pxmitpriv->free_xmit_extbuf_cnt--;
1228 pxmitbuf->priv_data = NULL;
1229 /* pxmitbuf->ext_tag = true; */
1230 if (pxmitbuf->sctx) {
1231 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1232 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1233 }
1234 }
1235 spin_unlock_irqrestore(&pfree_queue->lock, irql);
1236
1237 return pxmitbuf;
1238 }
1239
1240 s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1241 {
1242 unsigned long irql;
1243 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1244
1245
1246 if (pxmitbuf == NULL)
1247 return _FAIL;
1248
1249 spin_lock_irqsave(&pfree_queue->lock, irql);
1250
1251 list_del_init(&pxmitbuf->list);
1252
1253 list_add_tail(&(pxmitbuf->list), get_list_head(pfree_queue));
1254 pxmitpriv->free_xmit_extbuf_cnt++;
1255
1256 spin_unlock_irqrestore(&pfree_queue->lock, irql);
1257
1258
1259 return _SUCCESS;
1260 }
1261
1262 struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
1263 {
1264 unsigned long irql;
1265 struct xmit_buf *pxmitbuf;
1266 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1267
1268 /* DBG_88E("+rtw_alloc_xmitbuf\n"); */
1269
1270 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irql);
1271 pxmitbuf = list_first_entry_or_null(&pfree_xmitbuf_queue->queue,
1272 struct xmit_buf, list);
1273 if (pxmitbuf) {
1274 list_del_init(&pxmitbuf->list);
1275 pxmitpriv->free_xmitbuf_cnt--;
1276 pxmitbuf->priv_data = NULL;
1277 if (pxmitbuf->sctx) {
1278 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1279 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1280 }
1281 }
1282 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irql);
1283
1284 return pxmitbuf;
1285 }
1286
1287 s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1288 {
1289 unsigned long irql;
1290 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1291
1292 if (pxmitbuf == NULL)
1293 return _FAIL;
1294
1295 if (pxmitbuf->sctx) {
1296 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1297 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
1298 }
1299
1300 if (pxmitbuf->ext_tag) {
1301 rtw_free_xmitbuf_ext(pxmitpriv, pxmitbuf);
1302 } else {
1303 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irql);
1304
1305 list_del_init(&pxmitbuf->list);
1306
1307 list_add_tail(&(pxmitbuf->list), get_list_head(pfree_xmitbuf_queue));
1308
1309 pxmitpriv->free_xmitbuf_cnt++;
1310 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irql);
1311 }
1312
1313
1314 return _SUCCESS;
1315 }
1316
1317 /*
1318 Calling context:
1319 1. OS_TXENTRY
1320 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
1321
1322 If we turn on USE_RXTHREAD, then, no need for critical section.
1323 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
1324
1325 Must be very very cautious...
1326
1327 */
1328
1329 struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
1330 /* _queue *pfree_xmit_queue) */
1331 {
1332 /*
1333 Please remember to use all the osdep_service api,
1334 and lock/unlock or _enter/_exit critical to protect
1335 pfree_xmit_queue
1336 */
1337 struct xmit_frame *pxframe;
1338 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1339
1340 spin_lock_bh(&pfree_xmit_queue->lock);
1341 pxframe = list_first_entry_or_null(&pfree_xmit_queue->queue,
1342 struct xmit_frame, list);
1343 if (!pxframe) {
1344 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1345 ("rtw_alloc_xmitframe:%d\n",
1346 pxmitpriv->free_xmitframe_cnt));
1347 } else {
1348 list_del_init(&pxframe->list);
1349
1350 /* default value setting */
1351 pxmitpriv->free_xmitframe_cnt--;
1352
1353 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1354 ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n",
1355 pxmitpriv->free_xmitframe_cnt));
1356
1357 pxframe->buf_addr = NULL;
1358 pxframe->pxmitbuf = NULL;
1359
1360 memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
1361 /* pxframe->attrib.psta = NULL; */
1362
1363 pxframe->frame_tag = DATA_FRAMETAG;
1364
1365 pxframe->pkt = NULL;
1366 pxframe->pkt_offset = 1;/* default use pkt_offset to fill tx desc */
1367
1368 pxframe->agg_num = 1;
1369 pxframe->ack_report = 0;
1370 }
1371 spin_unlock_bh(&pfree_xmit_queue->lock);
1372
1373 return pxframe;
1374 }
1375
1376 s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
1377 {
1378 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1379 struct adapter *padapter = pxmitpriv->adapter;
1380 struct sk_buff *pndis_pkt = NULL;
1381
1382
1383 if (pxmitframe == NULL) {
1384 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====== rtw_free_xmitframe():pxmitframe == NULL!!!!!!!!!!\n"));
1385 goto exit;
1386 }
1387
1388 spin_lock_bh(&pfree_xmit_queue->lock);
1389
1390 list_del_init(&pxmitframe->list);
1391
1392 if (pxmitframe->pkt) {
1393 pndis_pkt = pxmitframe->pkt;
1394 pxmitframe->pkt = NULL;
1395 }
1396
1397 list_add_tail(&pxmitframe->list, get_list_head(pfree_xmit_queue));
1398
1399 pxmitpriv->free_xmitframe_cnt++;
1400 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
1401
1402 spin_unlock_bh(&pfree_xmit_queue->lock);
1403
1404 if (pndis_pkt)
1405 rtw_os_pkt_complete(padapter, pndis_pkt);
1406
1407 exit:
1408
1409
1410 return _SUCCESS;
1411 }
1412
1413 void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue)
1414 {
1415 struct list_head *plist, *phead;
1416 struct xmit_frame *pxmitframe;
1417
1418
1419 spin_lock_bh(&(pframequeue->lock));
1420
1421 phead = get_list_head(pframequeue);
1422 plist = phead->next;
1423
1424 while (phead != plist) {
1425 pxmitframe = container_of(plist, struct xmit_frame, list);
1426
1427 plist = plist->next;
1428
1429 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1430 }
1431 spin_unlock_bh(&(pframequeue->lock));
1432
1433 }
1434
1435 s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
1436 {
1437 if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL) {
1438 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1439 ("rtw_xmitframe_enqueue: drop xmit pkt for classifier fail\n"));
1440 /* pxmitframe->pkt = NULL; */
1441 return _FAIL;
1442 }
1443
1444 return _SUCCESS;
1445 }
1446
1447 static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit, struct tx_servq *ptxservq, struct __queue *pframe_queue)
1448 {
1449 struct list_head *xmitframe_plist, *xmitframe_phead;
1450 struct xmit_frame *pxmitframe = NULL;
1451
1452 xmitframe_phead = get_list_head(pframe_queue);
1453 xmitframe_plist = xmitframe_phead->next;
1454
1455 if (xmitframe_phead != xmitframe_plist) {
1456 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1457
1458 xmitframe_plist = xmitframe_plist->next;
1459
1460 list_del_init(&pxmitframe->list);
1461
1462 ptxservq->qcnt--;
1463 }
1464 return pxmitframe;
1465 }
1466
1467 struct xmit_frame *rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i, int entry)
1468 {
1469 struct list_head *sta_plist, *sta_phead;
1470 struct hw_xmit *phwxmit;
1471 struct tx_servq *ptxservq = NULL;
1472 struct __queue *pframe_queue = NULL;
1473 struct xmit_frame *pxmitframe = NULL;
1474 struct adapter *padapter = pxmitpriv->adapter;
1475 struct registry_priv *pregpriv = &padapter->registrypriv;
1476 int i, inx[4];
1477
1478
1479 inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
1480
1481 if (pregpriv->wifi_spec == 1) {
1482 int j;
1483
1484 for (j = 0; j < 4; j++)
1485 inx[j] = pxmitpriv->wmm_para_seq[j];
1486 }
1487
1488 spin_lock_bh(&pxmitpriv->lock);
1489
1490 for (i = 0; i < entry; i++) {
1491 phwxmit = phwxmit_i + inx[i];
1492
1493 sta_phead = get_list_head(phwxmit->sta_queue);
1494 sta_plist = sta_phead->next;
1495
1496 while (sta_phead != sta_plist) {
1497 ptxservq = container_of(sta_plist, struct tx_servq, tx_pending);
1498
1499 pframe_queue = &ptxservq->sta_pending;
1500
1501 pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit, ptxservq, pframe_queue);
1502
1503 if (pxmitframe) {
1504 phwxmit->accnt--;
1505
1506 /* Remove sta node when there are no pending packets. */
1507 if (list_empty(&pframe_queue->queue)) /* must be done after get_next and before break */
1508 list_del_init(&ptxservq->tx_pending);
1509 goto exit;
1510 }
1511
1512 sta_plist = sta_plist->next;
1513 }
1514 }
1515 exit:
1516 spin_unlock_bh(&pxmitpriv->lock);
1517 return pxmitframe;
1518 }
1519
1520 struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, int up, u8 *ac)
1521 {
1522 struct tx_servq *ptxservq;
1523
1524 switch (up) {
1525 case 1:
1526 case 2:
1527 ptxservq = &(psta->sta_xmitpriv.bk_q);
1528 *(ac) = 3;
1529 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BK\n"));
1530 break;
1531 case 4:
1532 case 5:
1533 ptxservq = &(psta->sta_xmitpriv.vi_q);
1534 *(ac) = 1;
1535 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VI\n"));
1536 break;
1537 case 6:
1538 case 7:
1539 ptxservq = &(psta->sta_xmitpriv.vo_q);
1540 *(ac) = 0;
1541 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VO\n"));
1542 break;
1543 case 0:
1544 case 3:
1545 default:
1546 ptxservq = &(psta->sta_xmitpriv.be_q);
1547 *(ac) = 2;
1548 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BE\n"));
1549 break;
1550 }
1551
1552
1553 return ptxservq;
1554 }
1555
1556 /*
1557 * Will enqueue pxmitframe to the proper queue,
1558 * and indicate it to xx_pending list.....
1559 */
1560 s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe)
1561 {
1562 u8 ac_index;
1563 struct sta_info *psta;
1564 struct tx_servq *ptxservq;
1565 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1566 struct sta_priv *pstapriv = &padapter->stapriv;
1567 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
1568 int res = _SUCCESS;
1569
1570
1571 if (pattrib->psta) {
1572 psta = pattrib->psta;
1573 } else {
1574 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
1575 }
1576
1577 if (psta == NULL) {
1578 res = _FAIL;
1579 DBG_88E("rtw_xmit_classifier: psta == NULL\n");
1580 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmit_classifier: psta == NULL\n"));
1581 goto exit;
1582 }
1583
1584 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
1585
1586 if (list_empty(&ptxservq->tx_pending))
1587 list_add_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue));
1588
1589 list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
1590 ptxservq->qcnt++;
1591 phwxmits[ac_index].accnt++;
1592 exit:
1593
1594
1595 return res;
1596 }
1597
1598 void rtw_alloc_hwxmits(struct adapter *padapter)
1599 {
1600 struct hw_xmit *hwxmits;
1601 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1602
1603 pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
1604
1605 pxmitpriv->hwxmits = kcalloc(pxmitpriv->hwxmit_entry,
1606 sizeof(struct hw_xmit), GFP_KERNEL);
1607
1608 hwxmits = pxmitpriv->hwxmits;
1609
1610 hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
1611 hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
1612 hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
1613 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1614 }
1615
1616 void rtw_free_hwxmits(struct adapter *padapter)
1617 {
1618 struct hw_xmit *hwxmits;
1619 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1620
1621 hwxmits = pxmitpriv->hwxmits;
1622 kfree(hwxmits);
1623 }
1624
1625 void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry)
1626 {
1627 int i;
1628 for (i = 0; i < entry; i++, phwxmit++)
1629 phwxmit->accnt = 0;
1630 }
1631
1632 u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe)
1633 {
1634 u32 addr;
1635 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1636
1637 switch (pattrib->qsel) {
1638 case 0:
1639 case 3:
1640 addr = BE_QUEUE_INX;
1641 break;
1642 case 1:
1643 case 2:
1644 addr = BK_QUEUE_INX;
1645 break;
1646 case 4:
1647 case 5:
1648 addr = VI_QUEUE_INX;
1649 break;
1650 case 6:
1651 case 7:
1652 addr = VO_QUEUE_INX;
1653 break;
1654 case 0x10:
1655 addr = BCN_QUEUE_INX;
1656 break;
1657 case 0x11:/* BC/MC in PS (HIQ) */
1658 addr = HIGH_QUEUE_INX;
1659 break;
1660 case 0x12:
1661 default:
1662 addr = MGT_QUEUE_INX;
1663 break;
1664 }
1665
1666 return addr;
1667 }
1668
1669 static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib)
1670 {
1671 u8 qsel;
1672
1673 qsel = pattrib->priority;
1674 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("### do_queue_select priority=%d , qsel = %d\n", pattrib->priority, qsel));
1675
1676 pattrib->qsel = qsel;
1677 }
1678
1679 /*
1680 * The main transmit(tx) entry
1681 *
1682 * Return
1683 * 1 enqueue
1684 * 0 success, hardware will handle this xmit frame(packet)
1685 * <0 fail
1686 */
1687 s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)
1688 {
1689 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1690 struct xmit_frame *pxmitframe = NULL;
1691 s32 res;
1692
1693 pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
1694 if (pxmitframe == NULL) {
1695 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: no more pxmitframe\n"));
1696 DBG_88E("DBG_TX_DROP_FRAME %s no more pxmitframe\n", __func__);
1697 return -1;
1698 }
1699
1700 res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
1701
1702 if (res == _FAIL) {
1703 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: update attrib fail\n"));
1704 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1705 return -1;
1706 }
1707 pxmitframe->pkt = *ppkt;
1708
1709 rtw_led_control(padapter, LED_CTL_TX);
1710
1711 do_queue_select(padapter, &pxmitframe->attrib);
1712
1713 #ifdef CONFIG_88EU_AP_MODE
1714 spin_lock_bh(&pxmitpriv->lock);
1715 if (xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe)) {
1716 spin_unlock_bh(&pxmitpriv->lock);
1717 return 1;
1718 }
1719 spin_unlock_bh(&pxmitpriv->lock);
1720 #endif
1721
1722 if (rtw_hal_xmit(padapter, pxmitframe) == false)
1723 return 1;
1724
1725 return 0;
1726 }
1727
1728 #if defined(CONFIG_88EU_AP_MODE)
1729
1730 int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe)
1731 {
1732 int ret = false;
1733 struct sta_info *psta = NULL;
1734 struct sta_priv *pstapriv = &padapter->stapriv;
1735 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1736 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1737 int bmcst = IS_MCAST(pattrib->ra);
1738
1739 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false)
1740 return ret;
1741
1742 if (pattrib->psta)
1743 psta = pattrib->psta;
1744 else
1745 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
1746
1747 if (psta == NULL)
1748 return ret;
1749
1750 if (pattrib->triggered == 1) {
1751 if (bmcst)
1752 pattrib->qsel = 0x11;/* HIQ */
1753 return ret;
1754 }
1755
1756 if (bmcst) {
1757 spin_lock_bh(&psta->sleep_q.lock);
1758
1759 if (pstapriv->sta_dz_bitmap) {/* if any one sta is in ps mode */
1760 list_del_init(&pxmitframe->list);
1761
1762 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
1763
1764 psta->sleepq_len++;
1765
1766 pstapriv->tim_bitmap |= BIT(0);/* */
1767 pstapriv->sta_dz_bitmap |= BIT(0);
1768
1769 update_beacon(padapter, _TIM_IE_, NULL, false);/* tx bc/mc packets after update bcn */
1770
1771 ret = true;
1772 }
1773
1774 spin_unlock_bh(&psta->sleep_q.lock);
1775
1776 return ret;
1777 }
1778
1779 spin_lock_bh(&psta->sleep_q.lock);
1780
1781 if (psta->state&WIFI_SLEEP_STATE) {
1782 u8 wmmps_ac = 0;
1783
1784 if (pstapriv->sta_dz_bitmap&BIT(psta->aid)) {
1785 list_del_init(&pxmitframe->list);
1786
1787 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
1788
1789 psta->sleepq_len++;
1790
1791 switch (pattrib->priority) {
1792 case 1:
1793 case 2:
1794 wmmps_ac = psta->uapsd_bk&BIT(0);
1795 break;
1796 case 4:
1797 case 5:
1798 wmmps_ac = psta->uapsd_vi&BIT(0);
1799 break;
1800 case 6:
1801 case 7:
1802 wmmps_ac = psta->uapsd_vo&BIT(0);
1803 break;
1804 case 0:
1805 case 3:
1806 default:
1807 wmmps_ac = psta->uapsd_be&BIT(0);
1808 break;
1809 }
1810
1811 if (wmmps_ac)
1812 psta->sleepq_ac_len++;
1813
1814 if (((psta->has_legacy_ac) && (!wmmps_ac)) ||
1815 ((!psta->has_legacy_ac) && (wmmps_ac))) {
1816 pstapriv->tim_bitmap |= BIT(psta->aid);
1817
1818 if (psta->sleepq_len == 1) {
1819 /* update BCN for TIM IE */
1820 update_beacon(padapter, _TIM_IE_, NULL, false);
1821 }
1822 }
1823 ret = true;
1824 }
1825 }
1826
1827 spin_unlock_bh(&psta->sleep_q.lock);
1828
1829 return ret;
1830 }
1831
1832 static void dequeue_xmitframes_to_sleeping_queue(struct adapter *padapter, struct sta_info *psta, struct __queue *pframequeue)
1833 {
1834 struct list_head *plist, *phead;
1835 u8 ac_index;
1836 struct tx_servq *ptxservq;
1837 struct pkt_attrib *pattrib;
1838 struct xmit_frame *pxmitframe;
1839 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
1840
1841 phead = get_list_head(pframequeue);
1842 plist = phead->next;
1843
1844 while (phead != plist) {
1845 pxmitframe = container_of(plist, struct xmit_frame, list);
1846
1847 plist = plist->next;
1848
1849 xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe);
1850
1851 pattrib = &pxmitframe->attrib;
1852
1853 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
1854
1855 ptxservq->qcnt--;
1856 phwxmits[ac_index].accnt--;
1857 }
1858 }
1859
1860 void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta)
1861 {
1862 struct sta_info *psta_bmc;
1863 struct sta_xmit_priv *pstaxmitpriv;
1864 struct sta_priv *pstapriv = &padapter->stapriv;
1865 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1866
1867 pstaxmitpriv = &psta->sta_xmitpriv;
1868
1869 /* for BC/MC Frames */
1870 psta_bmc = rtw_get_bcmc_stainfo(padapter);
1871
1872 spin_lock_bh(&pxmitpriv->lock);
1873
1874 psta->state |= WIFI_SLEEP_STATE;
1875
1876 pstapriv->sta_dz_bitmap |= BIT(psta->aid);
1877
1878 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
1879 list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
1880
1881 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
1882 list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
1883
1884 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending);
1885 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
1886
1887 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending);
1888 list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
1889
1890 /* for BC/MC Frames */
1891 pstaxmitpriv = &psta_bmc->sta_xmitpriv;
1892 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending);
1893 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
1894
1895 spin_unlock_bh(&pxmitpriv->lock);
1896 }
1897
1898 void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta)
1899 {
1900 u8 update_mask = 0, wmmps_ac = 0;
1901 struct sta_info *psta_bmc;
1902 struct list_head *xmitframe_plist, *xmitframe_phead;
1903 struct xmit_frame *pxmitframe = NULL;
1904 struct sta_priv *pstapriv = &padapter->stapriv;
1905
1906 spin_lock_bh(&psta->sleep_q.lock);
1907
1908 xmitframe_phead = get_list_head(&psta->sleep_q);
1909 xmitframe_plist = xmitframe_phead->next;
1910
1911 while (xmitframe_phead != xmitframe_plist) {
1912 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1913
1914 xmitframe_plist = xmitframe_plist->next;
1915
1916 list_del_init(&pxmitframe->list);
1917
1918 switch (pxmitframe->attrib.priority) {
1919 case 1:
1920 case 2:
1921 wmmps_ac = psta->uapsd_bk&BIT(1);
1922 break;
1923 case 4:
1924 case 5:
1925 wmmps_ac = psta->uapsd_vi&BIT(1);
1926 break;
1927 case 6:
1928 case 7:
1929 wmmps_ac = psta->uapsd_vo&BIT(1);
1930 break;
1931 case 0:
1932 case 3:
1933 default:
1934 wmmps_ac = psta->uapsd_be&BIT(1);
1935 break;
1936 }
1937
1938 psta->sleepq_len--;
1939 if (psta->sleepq_len > 0)
1940 pxmitframe->attrib.mdata = 1;
1941 else
1942 pxmitframe->attrib.mdata = 0;
1943
1944 if (wmmps_ac) {
1945 psta->sleepq_ac_len--;
1946 if (psta->sleepq_ac_len > 0) {
1947 pxmitframe->attrib.mdata = 1;
1948 pxmitframe->attrib.eosp = 0;
1949 } else {
1950 pxmitframe->attrib.mdata = 0;
1951 pxmitframe->attrib.eosp = 1;
1952 }
1953 }
1954
1955 pxmitframe->attrib.triggered = 1;
1956
1957 spin_unlock_bh(&psta->sleep_q.lock);
1958 if (rtw_hal_xmit(padapter, pxmitframe))
1959 rtw_os_xmit_complete(padapter, pxmitframe);
1960 spin_lock_bh(&psta->sleep_q.lock);
1961 }
1962
1963 if (psta->sleepq_len == 0) {
1964 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1965
1966 update_mask = BIT(0);
1967
1968 if (psta->state&WIFI_SLEEP_STATE)
1969 psta->state ^= WIFI_SLEEP_STATE;
1970
1971 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1972 psta->expire_to = pstapriv->expire_to;
1973 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1974 }
1975
1976 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
1977 }
1978
1979 spin_unlock_bh(&psta->sleep_q.lock);
1980
1981 /* for BC/MC Frames */
1982 psta_bmc = rtw_get_bcmc_stainfo(padapter);
1983 if (!psta_bmc)
1984 return;
1985
1986 if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) { /* no any sta in ps mode */
1987 spin_lock_bh(&psta_bmc->sleep_q.lock);
1988
1989 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
1990 xmitframe_plist = xmitframe_phead->next;
1991
1992 while (xmitframe_phead != xmitframe_plist) {
1993 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1994
1995 xmitframe_plist = xmitframe_plist->next;
1996
1997 list_del_init(&pxmitframe->list);
1998
1999 psta_bmc->sleepq_len--;
2000 if (psta_bmc->sleepq_len > 0)
2001 pxmitframe->attrib.mdata = 1;
2002 else
2003 pxmitframe->attrib.mdata = 0;
2004
2005 pxmitframe->attrib.triggered = 1;
2006
2007 spin_unlock_bh(&psta_bmc->sleep_q.lock);
2008 if (rtw_hal_xmit(padapter, pxmitframe))
2009 rtw_os_xmit_complete(padapter, pxmitframe);
2010 spin_lock_bh(&psta_bmc->sleep_q.lock);
2011 }
2012
2013 if (psta_bmc->sleepq_len == 0) {
2014 pstapriv->tim_bitmap &= ~BIT(0);
2015 pstapriv->sta_dz_bitmap &= ~BIT(0);
2016
2017 update_mask |= BIT(1);
2018 }
2019
2020 spin_unlock_bh(&psta_bmc->sleep_q.lock);
2021 }
2022
2023 if (update_mask)
2024 update_beacon(padapter, _TIM_IE_, NULL, false);
2025 }
2026
2027 void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta)
2028 {
2029 u8 wmmps_ac = 0;
2030 struct list_head *xmitframe_plist, *xmitframe_phead;
2031 struct xmit_frame *pxmitframe = NULL;
2032 struct sta_priv *pstapriv = &padapter->stapriv;
2033
2034 spin_lock_bh(&psta->sleep_q.lock);
2035
2036 xmitframe_phead = get_list_head(&psta->sleep_q);
2037 xmitframe_plist = xmitframe_phead->next;
2038
2039 while (xmitframe_phead != xmitframe_plist) {
2040 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
2041
2042 xmitframe_plist = xmitframe_plist->next;
2043
2044 switch (pxmitframe->attrib.priority) {
2045 case 1:
2046 case 2:
2047 wmmps_ac = psta->uapsd_bk&BIT(1);
2048 break;
2049 case 4:
2050 case 5:
2051 wmmps_ac = psta->uapsd_vi&BIT(1);
2052 break;
2053 case 6:
2054 case 7:
2055 wmmps_ac = psta->uapsd_vo&BIT(1);
2056 break;
2057 case 0:
2058 case 3:
2059 default:
2060 wmmps_ac = psta->uapsd_be&BIT(1);
2061 break;
2062 }
2063
2064 if (!wmmps_ac)
2065 continue;
2066
2067 list_del_init(&pxmitframe->list);
2068
2069 psta->sleepq_len--;
2070 psta->sleepq_ac_len--;
2071
2072 if (psta->sleepq_ac_len > 0) {
2073 pxmitframe->attrib.mdata = 1;
2074 pxmitframe->attrib.eosp = 0;
2075 } else {
2076 pxmitframe->attrib.mdata = 0;
2077 pxmitframe->attrib.eosp = 1;
2078 }
2079
2080 pxmitframe->attrib.triggered = 1;
2081
2082 if (rtw_hal_xmit(padapter, pxmitframe) == true)
2083 rtw_os_xmit_complete(padapter, pxmitframe);
2084
2085 if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) && (wmmps_ac)) {
2086 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2087
2088 /* update BCN for TIM IE */
2089 update_beacon(padapter, _TIM_IE_, NULL, false);
2090 }
2091 }
2092
2093 spin_unlock_bh(&psta->sleep_q.lock);
2094 }
2095
2096 #endif
2097
2098 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms)
2099 {
2100 sctx->timeout_ms = timeout_ms;
2101 sctx->submit_time = jiffies;
2102 init_completion(&sctx->done);
2103 sctx->status = RTW_SCTX_SUBMITTED;
2104 }
2105
2106 int rtw_sctx_wait(struct submit_ctx *sctx)
2107 {
2108 int ret = _FAIL;
2109 unsigned long expire;
2110 int status = 0;
2111
2112 expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) : MAX_SCHEDULE_TIMEOUT;
2113 if (!wait_for_completion_timeout(&sctx->done, expire)) {
2114 /* timeout, do something?? */
2115 status = RTW_SCTX_DONE_TIMEOUT;
2116 DBG_88E("%s timeout\n", __func__);
2117 } else {
2118 status = sctx->status;
2119 }
2120
2121 if (status == RTW_SCTX_DONE_SUCCESS)
2122 ret = _SUCCESS;
2123
2124 return ret;
2125 }
2126
2127 static bool rtw_sctx_chk_waring_status(int status)
2128 {
2129 switch (status) {
2130 case RTW_SCTX_DONE_UNKNOWN:
2131 case RTW_SCTX_DONE_BUF_ALLOC:
2132 case RTW_SCTX_DONE_BUF_FREE:
2133
2134 case RTW_SCTX_DONE_DRV_STOP:
2135 case RTW_SCTX_DONE_DEV_REMOVE:
2136 return true;
2137 default:
2138 return false;
2139 }
2140 }
2141
2142 void rtw_sctx_done_err(struct submit_ctx **sctx, int status)
2143 {
2144 if (*sctx) {
2145 if (rtw_sctx_chk_waring_status(status))
2146 DBG_88E("%s status:%d\n", __func__, status);
2147 (*sctx)->status = status;
2148 complete(&((*sctx)->done));
2149 *sctx = NULL;
2150 }
2151 }
2152
2153 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms)
2154 {
2155 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2156
2157 pack_tx_ops->submit_time = jiffies;
2158 pack_tx_ops->timeout_ms = timeout_ms;
2159 pack_tx_ops->status = RTW_SCTX_SUBMITTED;
2160
2161 return rtw_sctx_wait(pack_tx_ops);
2162 }
2163
2164 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status)
2165 {
2166 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2167
2168 if (pxmitpriv->ack_tx)
2169 rtw_sctx_done_err(&pack_tx_ops, status);
2170 else
2171 DBG_88E("%s ack_tx not set\n", __func__);
2172 }
This page took 0.079164 seconds and 4 git commands to generate.