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