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