1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #define _RTL8723B_CMD_C_
8
9 #include <drv_types.h>
10 #include <rtw_debug.h>
11 #include <rtl8723b_hal.h>
12 #include "hal_com_h2c.h"
13
14 #define MAX_H2C_BOX_NUMS 4
15 #define MESSAGE_BOX_SIZE 4
16
17 #define RTL8723B_MAX_CMD_LEN 7
18 #define RTL8723B_EX_MESSAGE_BOX_SIZE 4
19
_is_fw_read_cmd_down(struct adapter * padapter,u8 msgbox_num)20 static u8 _is_fw_read_cmd_down(struct adapter *padapter, u8 msgbox_num)
21 {
22 u8 read_down = false;
23 int retry_cnts = 100;
24
25 u8 valid;
26
27 /* DBG_8192C(" _is_fw_read_cmd_down , reg_1cc(%x), msg_box(%d)...\n", rtw_read8(padapter, REG_HMETFR), msgbox_num); */
28
29 do {
30 valid = rtw_read8(padapter, REG_HMETFR) & BIT(msgbox_num);
31 if (0 == valid) {
32 read_down = true;
33 }
34 #ifdef CONFIG_WOWLAN
35 else
36 msleep(1);
37 #endif
38 } while ((!read_down) && (retry_cnts--));
39
40 return read_down;
41
42 }
43
44
45 /*****************************************
46 * H2C Msg format :
47 *| 31 - 8 |7-5 | 4 - 0 |
48 *| h2c_msg |Class |CMD_ID |
49 *| 31-0 |
50 *| Ext msg |
51 *
52 ******************************************/
FillH2CCmd8723B(struct adapter * padapter,u8 ElementID,u32 CmdLen,u8 * pCmdBuffer)53 s32 FillH2CCmd8723B(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
54 {
55 u8 h2c_box_num;
56 u32 msgbox_addr;
57 u32 msgbox_ex_addr = 0;
58 struct hal_com_data *pHalData;
59 u32 h2c_cmd = 0;
60 u32 h2c_cmd_ex = 0;
61 s32 ret = _FAIL;
62
63 padapter = GET_PRIMARY_ADAPTER(padapter);
64 pHalData = GET_HAL_DATA(padapter);
65 if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->h2c_fwcmd_mutex)))
66 return ret;
67
68 if (!pCmdBuffer) {
69 goto exit;
70 }
71
72 if (CmdLen > RTL8723B_MAX_CMD_LEN) {
73 goto exit;
74 }
75
76 if (padapter->bSurpriseRemoved == true)
77 goto exit;
78
79 /* pay attention to if race condition happened in H2C cmd setting. */
80 do {
81 h2c_box_num = pHalData->LastHMEBoxNum;
82
83 if (!_is_fw_read_cmd_down(padapter, h2c_box_num)) {
84 DBG_8192C(" fw read cmd failed...\n");
85 /* DBG_8192C(" 0x1c0: 0x%8x\n", rtw_read32(padapter, 0x1c0)); */
86 /* DBG_8192C(" 0x1c4: 0x%8x\n", rtw_read32(padapter, 0x1c4)); */
87 goto exit;
88 }
89
90 if (CmdLen <= 3)
91 memcpy((u8 *)(&h2c_cmd)+1, pCmdBuffer, CmdLen);
92 else {
93 memcpy((u8 *)(&h2c_cmd)+1, pCmdBuffer, 3);
94 memcpy((u8 *)(&h2c_cmd_ex), pCmdBuffer+3, CmdLen-3);
95 /* *(u8 *)(&h2c_cmd) |= BIT(7); */
96 }
97
98 *(u8 *)(&h2c_cmd) |= ElementID;
99
100 if (CmdLen > 3) {
101 msgbox_ex_addr = REG_HMEBOX_EXT0_8723B + (h2c_box_num*RTL8723B_EX_MESSAGE_BOX_SIZE);
102 rtw_write32(padapter, msgbox_ex_addr, h2c_cmd_ex);
103 }
104 msgbox_addr = REG_HMEBOX_0 + (h2c_box_num*MESSAGE_BOX_SIZE);
105 rtw_write32(padapter, msgbox_addr, h2c_cmd);
106
107 /* DBG_8192C("MSG_BOX:%d, CmdLen(%d), CmdID(0x%x), reg:0x%x =>h2c_cmd:0x%.8x, reg:0x%x =>h2c_cmd_ex:0x%.8x\n" */
108 /* , pHalData->LastHMEBoxNum , CmdLen, ElementID, msgbox_addr, h2c_cmd, msgbox_ex_addr, h2c_cmd_ex); */
109
110 pHalData->LastHMEBoxNum = (h2c_box_num+1) % MAX_H2C_BOX_NUMS;
111
112 } while (0);
113
114 ret = _SUCCESS;
115
116 exit:
117
118 mutex_unlock(&(adapter_to_dvobj(padapter)->h2c_fwcmd_mutex));
119 return ret;
120 }
121
ConstructBeacon(struct adapter * padapter,u8 * pframe,u32 * pLength)122 static void ConstructBeacon(struct adapter *padapter, u8 *pframe, u32 *pLength)
123 {
124 struct ieee80211_hdr *pwlanhdr;
125 __le16 *fctrl;
126 u32 rate_len, pktlen;
127 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
128 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
129 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
130 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
131
132
133 /* DBG_871X("%s\n", __func__); */
134
135 pwlanhdr = (struct ieee80211_hdr *)pframe;
136
137 fctrl = &(pwlanhdr->frame_control);
138 *(fctrl) = 0;
139
140 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
141 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
142 memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
143
144 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
145 /* pmlmeext->mgnt_seq++; */
146 SetFrameSubType(pframe, WIFI_BEACON);
147
148 pframe += sizeof(struct ieee80211_hdr_3addr);
149 pktlen = sizeof (struct ieee80211_hdr_3addr);
150
151 /* timestamp will be inserted by hardware */
152 pframe += 8;
153 pktlen += 8;
154
155 /* beacon interval: 2 bytes */
156 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
157
158 pframe += 2;
159 pktlen += 2;
160
161 /* capability info: 2 bytes */
162 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
163
164 pframe += 2;
165 pktlen += 2;
166
167 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
168 /* DBG_871X("ie len =%d\n", cur_network->IELength); */
169 pktlen += cur_network->IELength - sizeof(struct ndis_802_11_fix_ie);
170 memcpy(pframe, cur_network->IEs+sizeof(struct ndis_802_11_fix_ie), pktlen);
171
172 goto _ConstructBeacon;
173 }
174
175 /* below for ad-hoc mode */
176
177 /* SSID */
178 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pktlen);
179
180 /* supported rates... */
181 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
182 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pktlen);
183
184 /* DS parameter set */
185 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pktlen);
186
187 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
188 u32 ATIMWindow;
189 /* IBSS Parameter Set... */
190 /* ATIMWindow = cur->Configuration.ATIMWindow; */
191 ATIMWindow = 0;
192 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pktlen);
193 }
194
195
196 /* todo: ERP IE */
197
198
199 /* EXTERNDED SUPPORTED RATE */
200 if (rate_len > 8)
201 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pktlen);
202
203
204 /* todo:HT for adhoc */
205
206 _ConstructBeacon:
207
208 if ((pktlen + TXDESC_SIZE) > 512) {
209 DBG_871X("beacon frame too large\n");
210 return;
211 }
212
213 *pLength = pktlen;
214
215 /* DBG_871X("%s bcn_sz =%d\n", __func__, pktlen); */
216
217 }
218
ConstructPSPoll(struct adapter * padapter,u8 * pframe,u32 * pLength)219 static void ConstructPSPoll(struct adapter *padapter, u8 *pframe, u32 *pLength)
220 {
221 struct ieee80211_hdr *pwlanhdr;
222 __le16 *fctrl;
223 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
224 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
225
226 /* DBG_871X("%s\n", __func__); */
227
228 pwlanhdr = (struct ieee80211_hdr *)pframe;
229
230 /* Frame control. */
231 fctrl = &(pwlanhdr->frame_control);
232 *(fctrl) = 0;
233 SetPwrMgt(fctrl);
234 SetFrameSubType(pframe, WIFI_PSPOLL);
235
236 /* AID. */
237 SetDuration(pframe, (pmlmeinfo->aid | 0xc000));
238
239 /* BSSID. */
240 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
241
242 /* TA. */
243 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
244
245 *pLength = 16;
246 }
247
ConstructNullFunctionData(struct adapter * padapter,u8 * pframe,u32 * pLength,u8 * StaAddr,u8 bQoS,u8 AC,u8 bEosp,u8 bForcePowerSave)248 static void ConstructNullFunctionData(
249 struct adapter *padapter,
250 u8 *pframe,
251 u32 *pLength,
252 u8 *StaAddr,
253 u8 bQoS,
254 u8 AC,
255 u8 bEosp,
256 u8 bForcePowerSave
257 )
258 {
259 struct ieee80211_hdr *pwlanhdr;
260 __le16 *fctrl;
261 u32 pktlen;
262 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
263 struct wlan_network *cur_network = &pmlmepriv->cur_network;
264 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
265 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
266
267
268 /* DBG_871X("%s:%d\n", __func__, bForcePowerSave); */
269
270 pwlanhdr = (struct ieee80211_hdr *)pframe;
271
272 fctrl = &pwlanhdr->frame_control;
273 *(fctrl) = 0;
274 if (bForcePowerSave)
275 SetPwrMgt(fctrl);
276
277 switch (cur_network->network.InfrastructureMode) {
278 case Ndis802_11Infrastructure:
279 SetToDs(fctrl);
280 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
281 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
282 memcpy(pwlanhdr->addr3, StaAddr, ETH_ALEN);
283 break;
284 case Ndis802_11APMode:
285 SetFrDs(fctrl);
286 memcpy(pwlanhdr->addr1, StaAddr, ETH_ALEN);
287 memcpy(pwlanhdr->addr2, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
288 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
289 break;
290 case Ndis802_11IBSS:
291 default:
292 memcpy(pwlanhdr->addr1, StaAddr, ETH_ALEN);
293 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
294 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
295 break;
296 }
297
298 SetSeqNum(pwlanhdr, 0);
299
300 if (bQoS == true) {
301 struct ieee80211_qos_hdr *pwlanqoshdr;
302
303 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
304
305 pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe;
306 SetPriority(&pwlanqoshdr->qos_ctrl, AC);
307 SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp);
308
309 pktlen = sizeof(struct ieee80211_qos_hdr);
310 } else {
311 SetFrameSubType(pframe, WIFI_DATA_NULL);
312
313 pktlen = sizeof(struct ieee80211_hdr_3addr);
314 }
315
316 *pLength = pktlen;
317 }
318
319
320 #ifdef CONFIG_WOWLAN
321 /* */
322 /* Description: */
323 /* Construct the ARP response packet to support ARP offload. */
324 /* */
ConstructARPResponse(struct adapter * padapter,u8 * pframe,u32 * pLength,u8 * pIPAddress)325 static void ConstructARPResponse(
326 struct adapter *padapter,
327 u8 *pframe,
328 u32 *pLength,
329 u8 *pIPAddress
330 )
331 {
332 struct ieee80211_hdr *pwlanhdr;
333 __le16 *fctrl;
334 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
335 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
336 struct security_priv *psecuritypriv = &padapter->securitypriv;
337 static u8 ARPLLCHeader[8] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x08, 0x06};
338 u8 *pARPRspPkt = pframe;
339 /* for TKIP Cal MIC */
340 u8 *payload = pframe;
341 u8 EncryptionHeadOverhead = 0;
342 /* DBG_871X("%s:%d\n", __func__, bForcePowerSave); */
343
344 pwlanhdr = (struct ieee80211_hdr *)pframe;
345
346 fctrl = &pwlanhdr->frame_control;
347 *(fctrl) = 0;
348
349 /* */
350 /* MAC Header. */
351 /* */
352 SetFrameType(fctrl, WIFI_DATA);
353 /* SetFrameSubType(fctrl, 0); */
354 SetToDs(fctrl);
355 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
356 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
357 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
358
359 SetSeqNum(pwlanhdr, 0);
360 SetDuration(pwlanhdr, 0);
361 /* SET_80211_HDR_FRAME_CONTROL(pARPRspPkt, 0); */
362 /* SET_80211_HDR_TYPE_AND_SUBTYPE(pARPRspPkt, Type_Data); */
363 /* SET_80211_HDR_TO_DS(pARPRspPkt, 1); */
364 /* SET_80211_HDR_ADDRESS1(pARPRspPkt, pMgntInfo->Bssid); */
365 /* SET_80211_HDR_ADDRESS2(pARPRspPkt, Adapter->CurrentAddress); */
366 /* SET_80211_HDR_ADDRESS3(pARPRspPkt, pMgntInfo->Bssid); */
367
368 /* SET_80211_HDR_DURATION(pARPRspPkt, 0); */
369 /* SET_80211_HDR_FRAGMENT_SEQUENCE(pARPRspPkt, 0); */
370 *pLength = 24;
371
372 /* */
373 /* Security Header: leave space for it if necessary. */
374 /* */
375
376 switch (psecuritypriv->dot11PrivacyAlgrthm) {
377 case _WEP40_:
378 case _WEP104_:
379 EncryptionHeadOverhead = 4;
380 break;
381 case _TKIP_:
382 EncryptionHeadOverhead = 8;
383 break;
384 case _AES_:
385 EncryptionHeadOverhead = 8;
386 break;
387 default:
388 EncryptionHeadOverhead = 0;
389 }
390
391 if (EncryptionHeadOverhead > 0) {
392 memset(&(pframe[*pLength]), 0, EncryptionHeadOverhead);
393 *pLength += EncryptionHeadOverhead;
394 SetPrivacy(fctrl);
395 }
396
397 /* */
398 /* Frame Body. */
399 /* */
400 pARPRspPkt = (u8 *)(pframe + *pLength);
401 payload = pARPRspPkt; /* Get Payload pointer */
402 /* LLC header */
403 memcpy(pARPRspPkt, ARPLLCHeader, 8);
404 *pLength += 8;
405
406 /* ARP element */
407 pARPRspPkt += 8;
408 SET_ARP_PKT_HW(pARPRspPkt, 0x0100);
409 SET_ARP_PKT_PROTOCOL(pARPRspPkt, 0x0008); /* IP protocol */
410 SET_ARP_PKT_HW_ADDR_LEN(pARPRspPkt, 6);
411 SET_ARP_PKT_PROTOCOL_ADDR_LEN(pARPRspPkt, 4);
412 SET_ARP_PKT_OPERATION(pARPRspPkt, 0x0200); /* ARP response */
413 SET_ARP_PKT_SENDER_MAC_ADDR(pARPRspPkt, myid(&(padapter->eeprompriv)));
414 SET_ARP_PKT_SENDER_IP_ADDR(pARPRspPkt, pIPAddress);
415 {
416 SET_ARP_PKT_TARGET_MAC_ADDR(pARPRspPkt, get_my_bssid(&(pmlmeinfo->network)));
417 SET_ARP_PKT_TARGET_IP_ADDR(pARPRspPkt, pIPAddress);
418 DBG_871X("%s Target Mac Addr:" MAC_FMT "\n", __func__, MAC_ARG(get_my_bssid(&(pmlmeinfo->network))));
419 DBG_871X("%s Target IP Addr" IP_FMT "\n", __func__, IP_ARG(pIPAddress));
420 }
421
422 *pLength += 28;
423
424 if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_) {
425 u8 mic[8];
426 struct mic_data micdata;
427 struct sta_info *psta = NULL;
428 u8 priority[4] = {
429 0x0, 0x0, 0x0, 0x0
430 };
431 u8 null_key[16] = {
432 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
433 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
434 };
435
436 DBG_871X("%s(): Add MIC\n", __func__);
437
438 psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(&(pmlmeinfo->network)));
439 if (psta != NULL) {
440 if (!memcmp(&psta->dot11tkiptxmickey.skey[0], null_key, 16)) {
441 DBG_871X("%s(): STA dot11tkiptxmickey == 0\n", __func__);
442 }
443 /* start to calculate the mic code */
444 rtw_secmicsetkey(&micdata, &psta->dot11tkiptxmickey.skey[0]);
445 }
446
447 rtw_secmicappend(&micdata, pwlanhdr->addr3, 6); /* DA */
448
449 rtw_secmicappend(&micdata, pwlanhdr->addr2, 6); /* SA */
450
451 priority[0] = 0;
452 rtw_secmicappend(&micdata, &priority[0], 4);
453
454 rtw_secmicappend(&micdata, payload, 36); /* payload length = 8 + 28 */
455
456 rtw_secgetmic(&micdata, &(mic[0]));
457
458 pARPRspPkt += 28;
459 memcpy(pARPRspPkt, &(mic[0]), 8);
460
461 *pLength += 8;
462 }
463 }
464
465 #ifdef CONFIG_PNO_SUPPORT
ConstructPnoInfo(struct adapter * padapter,u8 * pframe,u32 * pLength)466 static void ConstructPnoInfo(
467 struct adapter *padapter, u8 *pframe, u32 *pLength
468 )
469 {
470
471 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
472
473 u8 *pPnoInfoPkt = pframe;
474 pPnoInfoPkt = (u8 *)(pframe + *pLength);
475 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->ssid_num, 4);
476
477 *pLength += 4;
478 pPnoInfoPkt += 4;
479 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->fast_scan_period, 4);
480
481 *pLength += 4;
482 pPnoInfoPkt += 4;
483 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->fast_scan_iterations, 4);
484
485 *pLength += 4;
486 pPnoInfoPkt += 4;
487 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->slow_scan_period, 4);
488
489 *pLength += 4;
490 pPnoInfoPkt += 4;
491 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->ssid_length,
492 MAX_PNO_LIST_COUNT);
493
494 *pLength += MAX_PNO_LIST_COUNT;
495 pPnoInfoPkt += MAX_PNO_LIST_COUNT;
496 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->ssid_cipher_info,
497 MAX_PNO_LIST_COUNT);
498
499 *pLength += MAX_PNO_LIST_COUNT;
500 pPnoInfoPkt += MAX_PNO_LIST_COUNT;
501 memcpy(pPnoInfoPkt, &pwrctl->pnlo_info->ssid_channel_info,
502 MAX_PNO_LIST_COUNT);
503
504 *pLength += MAX_PNO_LIST_COUNT;
505 pPnoInfoPkt += MAX_PNO_LIST_COUNT;
506 }
507
ConstructSSIDList(struct adapter * padapter,u8 * pframe,u32 * pLength)508 static void ConstructSSIDList(
509 struct adapter *padapter, u8 *pframe, u32 *pLength
510 )
511 {
512 int i = 0;
513 u8 *pSSIDListPkt = pframe;
514 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
515
516 pSSIDListPkt = (u8 *)(pframe + *pLength);
517
518 for (i = 0; i < pwrctl->pnlo_info->ssid_num ; i++) {
519 memcpy(pSSIDListPkt, &pwrctl->pno_ssid_list->node[i].SSID,
520 pwrctl->pnlo_info->ssid_length[i]);
521
522 *pLength += WLAN_SSID_MAXLEN;
523 pSSIDListPkt += WLAN_SSID_MAXLEN;
524 }
525 }
526
ConstructScanInfo(struct adapter * padapter,u8 * pframe,u32 * pLength)527 static void ConstructScanInfo(
528 struct adapter *padapter, u8 *pframe, u32 *pLength
529 )
530 {
531 int i = 0;
532 u8 *pScanInfoPkt = pframe;
533 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
534
535 pScanInfoPkt = (u8 *)(pframe + *pLength);
536
537 memcpy(pScanInfoPkt, &pwrctl->pscan_info->channel_num, 1);
538
539 *pLength += 1;
540 pScanInfoPkt += 1;
541 memcpy(pScanInfoPkt, &pwrctl->pscan_info->orig_ch, 1);
542
543
544 *pLength += 1;
545 pScanInfoPkt += 1;
546 memcpy(pScanInfoPkt, &pwrctl->pscan_info->orig_bw, 1);
547
548
549 *pLength += 1;
550 pScanInfoPkt += 1;
551 memcpy(pScanInfoPkt, &pwrctl->pscan_info->orig_40_offset, 1);
552
553 *pLength += 1;
554 pScanInfoPkt += 1;
555 memcpy(pScanInfoPkt, &pwrctl->pscan_info->orig_80_offset, 1);
556
557 *pLength += 1;
558 pScanInfoPkt += 1;
559 memcpy(pScanInfoPkt, &pwrctl->pscan_info->periodScan, 1);
560
561 *pLength += 1;
562 pScanInfoPkt += 1;
563 memcpy(pScanInfoPkt, &pwrctl->pscan_info->period_scan_time, 1);
564
565 *pLength += 1;
566 pScanInfoPkt += 1;
567 memcpy(pScanInfoPkt, &pwrctl->pscan_info->enableRFE, 1);
568
569 *pLength += 1;
570 pScanInfoPkt += 1;
571 memcpy(pScanInfoPkt, &pwrctl->pscan_info->rfe_type, 8);
572
573 *pLength += 8;
574 pScanInfoPkt += 8;
575
576 for (i = 0; i < MAX_SCAN_LIST_COUNT; i++) {
577 memcpy(pScanInfoPkt, &pwrctl->pscan_info->ssid_channel_info[i], 4);
578 *pLength += 4;
579 pScanInfoPkt += 4;
580 }
581 }
582 #endif
583
584 #ifdef CONFIG_GTK_OL
ConstructGTKResponse(struct adapter * padapter,u8 * pframe,u32 * pLength)585 static void ConstructGTKResponse(
586 struct adapter *padapter, u8 *pframe, u32 *pLength
587 )
588 {
589 struct ieee80211_hdr *pwlanhdr;
590 u16 *fctrl;
591 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
592 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
593 struct security_priv *psecuritypriv = &padapter->securitypriv;
594 static u8 LLCHeader[8] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8E};
595 static u8 GTKbody_a[11] = {0x01, 0x03, 0x00, 0x5F, 0x02, 0x03, 0x12, 0x00, 0x10, 0x42, 0x0B};
596 u8 *pGTKRspPkt = pframe;
597 u8 EncryptionHeadOverhead = 0;
598 /* DBG_871X("%s:%d\n", __func__, bForcePowerSave); */
599
600 pwlanhdr = (struct ieee80211_hdr *)pframe;
601
602 fctrl = &pwlanhdr->frame_control;
603 *(fctrl) = 0;
604
605 /* */
606 /* MAC Header. */
607 /* */
608 SetFrameType(fctrl, WIFI_DATA);
609 /* SetFrameSubType(fctrl, 0); */
610 SetToDs(fctrl);
611 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
612 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
613 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
614
615 SetSeqNum(pwlanhdr, 0);
616 SetDuration(pwlanhdr, 0);
617
618 *pLength = 24;
619
620 /* */
621 /* Security Header: leave space for it if necessary. */
622 /* */
623
624 switch (psecuritypriv->dot11PrivacyAlgrthm) {
625 case _WEP40_:
626 case _WEP104_:
627 EncryptionHeadOverhead = 4;
628 break;
629 case _TKIP_:
630 EncryptionHeadOverhead = 8;
631 break;
632 case _AES_:
633 EncryptionHeadOverhead = 8;
634 break;
635 default:
636 EncryptionHeadOverhead = 0;
637 }
638
639 if (EncryptionHeadOverhead > 0) {
640 memset(&(pframe[*pLength]), 0, EncryptionHeadOverhead);
641 *pLength += EncryptionHeadOverhead;
642 /* GTK's privacy bit is done by FW */
643 /* SetPrivacy(fctrl); */
644 }
645
646 /* */
647 /* Frame Body. */
648 /* */
649 pGTKRspPkt = (u8 *)(pframe + *pLength);
650 /* LLC header */
651 memcpy(pGTKRspPkt, LLCHeader, 8);
652 *pLength += 8;
653
654 /* GTK element */
655 pGTKRspPkt += 8;
656
657 /* GTK frame body after LLC, part 1 */
658 memcpy(pGTKRspPkt, GTKbody_a, 11);
659 *pLength += 11;
660 pGTKRspPkt += 11;
661 /* GTK frame body after LLC, part 2 */
662 memset(&(pframe[*pLength]), 0, 88);
663 *pLength += 88;
664 pGTKRspPkt += 88;
665
666 }
667 #endif /* CONFIG_GTK_OL */
668
669 #ifdef CONFIG_PNO_SUPPORT
ConstructProbeReq(struct adapter * padapter,u8 * pframe,u32 * pLength)670 static void ConstructProbeReq(struct adapter *padapter, u8 *pframe, u32 *pLength)
671 {
672 struct ieee80211_hdr *pwlanhdr;
673 u16 *fctrl;
674 u32 pktlen;
675 unsigned char *mac;
676 unsigned char bssrate[NumRates];
677 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
678 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
679 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
680 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
681 int bssrate_len = 0;
682 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
683
684 pwlanhdr = (struct ieee80211_hdr *)pframe;
685 mac = myid(&(padapter->eeprompriv));
686
687 fctrl = &(pwlanhdr->frame_control);
688 *(fctrl) = 0;
689
690 /* broadcast probe request frame */
691 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
692 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
693
694 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
695
696 SetSeqNum(pwlanhdr, 0);
697 SetFrameSubType(pframe, WIFI_PROBEREQ);
698
699 pktlen = sizeof(struct ieee80211_hdr_3addr);
700 pframe += pktlen;
701
702 pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &pktlen);
703
704 get_rate_set(padapter, bssrate, &bssrate_len);
705
706 if (bssrate_len > 8) {
707 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, bssrate, &pktlen);
708 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (bssrate_len - 8), (bssrate + 8), &pktlen);
709 } else
710 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, bssrate_len, bssrate, &pktlen);
711
712 *pLength = pktlen;
713 }
714 #endif /* CONFIG_PNO_SUPPORT */
715 #endif /* CONFIG_WOWLAN */
716
717 #ifdef CONFIG_AP_WOWLAN
ConstructProbeRsp(struct adapter * padapter,u8 * pframe,u32 * pLength,u8 * StaAddr,bool bHideSSID)718 static void ConstructProbeRsp(struct adapter *padapter, u8 *pframe, u32 *pLength, u8 *StaAddr, bool bHideSSID)
719 {
720 struct ieee80211_hdr *pwlanhdr;
721 u16 *fctrl;
722 u8 *mac, *bssid;
723 u32 pktlen;
724 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
725 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
726 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
727 u8 *pwps_ie;
728 uint wps_ielen;
729 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
730
731 /* DBG_871X("%s\n", __func__); */
732
733 pwlanhdr = (struct ieee80211_hdr *)pframe;
734
735 mac = myid(&(padapter->eeprompriv));
736 bssid = cur_network->MacAddress;
737
738 fctrl = &(pwlanhdr->frame_control);
739 *(fctrl) = 0;
740 memcpy(pwlanhdr->addr1, StaAddr, ETH_ALEN);
741 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
742 memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
743
744 DBG_871X("%s FW Mac Addr:" MAC_FMT "\n", __func__, MAC_ARG(mac));
745 DBG_871X("%s FW IP Addr" IP_FMT "\n", __func__, IP_ARG(StaAddr));
746
747 SetSeqNum(pwlanhdr, 0);
748 SetFrameSubType(fctrl, WIFI_PROBERSP);
749
750 pktlen = sizeof(struct ieee80211_hdr_3addr);
751 pframe += pktlen;
752
753 if (cur_network->IELength > MAX_IE_SZ)
754 return;
755
756 pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_,
757 cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
758
759 /* inerset & update wps_probe_resp_ie */
760 if ((pmlmepriv->wps_probe_resp_ie != NULL) && pwps_ie && (wps_ielen > 0)) {
761 uint wps_offset, remainder_ielen;
762 u8 *premainder_ie;
763
764 wps_offset = (uint)(pwps_ie - cur_network->IEs);
765
766 premainder_ie = pwps_ie + wps_ielen;
767
768 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
769
770 memcpy(pframe, cur_network->IEs, wps_offset);
771 pframe += wps_offset;
772 pktlen += wps_offset;
773
774 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
775 if ((wps_offset+wps_ielen+2) <= MAX_IE_SZ) {
776 memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
777 pframe += wps_ielen+2;
778 pktlen += wps_ielen+2;
779 }
780
781 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
782 memcpy(pframe, premainder_ie, remainder_ielen);
783 pframe += remainder_ielen;
784 pktlen += remainder_ielen;
785 }
786 } else {
787 memcpy(pframe, cur_network->IEs, cur_network->IELength);
788 pframe += cur_network->IELength;
789 pktlen += cur_network->IELength;
790 }
791
792 /* retrieve SSID IE from cur_network->Ssid */
793 {
794 u8 *ssid_ie;
795 sint ssid_ielen;
796 sint ssid_ielen_diff;
797 u8 buf[MAX_IE_SZ];
798 u8 *ies = pframe + sizeof(struct ieee80211_hdr_3addr);
799
800 ssid_ie = rtw_get_ie(ies+_FIXED_IE_LENGTH_, _SSID_IE_, &ssid_ielen,
801 (pframe-ies)-_FIXED_IE_LENGTH_);
802
803 ssid_ielen_diff = cur_network->Ssid.SsidLength - ssid_ielen;
804
805 if (ssid_ie && cur_network->Ssid.SsidLength) {
806 uint remainder_ielen;
807 u8 *remainder_ie;
808 remainder_ie = ssid_ie+2;
809 remainder_ielen = (pframe-remainder_ie);
810
811 if (remainder_ielen > MAX_IE_SZ) {
812 DBG_871X_LEVEL(_drv_warning_, FUNC_ADPT_FMT" remainder_ielen > MAX_IE_SZ\n", FUNC_ADPT_ARG(padapter));
813 remainder_ielen = MAX_IE_SZ;
814 }
815
816 memcpy(buf, remainder_ie, remainder_ielen);
817 memcpy(remainder_ie+ssid_ielen_diff, buf, remainder_ielen);
818 *(ssid_ie+1) = cur_network->Ssid.SsidLength;
819 memcpy(ssid_ie+2, cur_network->Ssid.Ssid, cur_network->Ssid.SsidLength);
820 pframe += ssid_ielen_diff;
821 pktlen += ssid_ielen_diff;
822 }
823 }
824
825 *pLength = pktlen;
826
827 }
828 #endif /* CONFIG_AP_WOWLAN */
829
830 /* To check if reserved page content is destroyed by beacon beacuse beacon is too large. */
831 /* 2010.06.23. Added by tynli. */
CheckFwRsvdPageContent(struct adapter * Adapter)832 void CheckFwRsvdPageContent(struct adapter *Adapter)
833 {
834 }
835
rtl8723b_set_FwRsvdPage_cmd(struct adapter * padapter,PRSVDPAGE_LOC rsvdpageloc)836 static void rtl8723b_set_FwRsvdPage_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc)
837 {
838 u8 u1H2CRsvdPageParm[H2C_RSVDPAGE_LOC_LEN] = {0};
839
840 DBG_871X("8723BRsvdPageLoc: ProbeRsp =%d PsPoll =%d Null =%d QoSNull =%d BTNull =%d\n",
841 rsvdpageloc->LocProbeRsp, rsvdpageloc->LocPsPoll,
842 rsvdpageloc->LocNullData, rsvdpageloc->LocQosNull,
843 rsvdpageloc->LocBTQosNull);
844
845 SET_8723B_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1H2CRsvdPageParm, rsvdpageloc->LocProbeRsp);
846 SET_8723B_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1H2CRsvdPageParm, rsvdpageloc->LocPsPoll);
847 SET_8723B_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocNullData);
848 SET_8723B_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocQosNull);
849 SET_8723B_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocBTQosNull);
850
851 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CRsvdPageParm:", u1H2CRsvdPageParm, H2C_RSVDPAGE_LOC_LEN);
852 FillH2CCmd8723B(padapter, H2C_8723B_RSVD_PAGE, H2C_RSVDPAGE_LOC_LEN, u1H2CRsvdPageParm);
853 }
854
rtl8723b_set_FwAoacRsvdPage_cmd(struct adapter * padapter,PRSVDPAGE_LOC rsvdpageloc)855 static void rtl8723b_set_FwAoacRsvdPage_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc)
856 {
857 #ifdef CONFIG_WOWLAN
858 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
859 u8 u1H2CAoacRsvdPageParm[H2C_AOAC_RSVDPAGE_LOC_LEN] = {0};
860
861 DBG_871X("8723BAOACRsvdPageLoc: RWC =%d ArpRsp =%d NbrAdv =%d GtkRsp =%d GtkInfo =%d ProbeReq =%d NetworkList =%d\n",
862 rsvdpageloc->LocRemoteCtrlInfo, rsvdpageloc->LocArpRsp,
863 rsvdpageloc->LocNbrAdv, rsvdpageloc->LocGTKRsp,
864 rsvdpageloc->LocGTKInfo, rsvdpageloc->LocProbeReq,
865 rsvdpageloc->LocNetList);
866
867 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
868 SET_H2CCMD_AOAC_RSVDPAGE_LOC_REMOTE_WAKE_CTRL_INFO(u1H2CAoacRsvdPageParm, rsvdpageloc->LocRemoteCtrlInfo);
869 SET_H2CCMD_AOAC_RSVDPAGE_LOC_ARP_RSP(u1H2CAoacRsvdPageParm, rsvdpageloc->LocArpRsp);
870 /* SET_H2CCMD_AOAC_RSVDPAGE_LOC_NEIGHBOR_ADV(u1H2CAoacRsvdPageParm, rsvdpageloc->LocNbrAdv); */
871 SET_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_RSP(u1H2CAoacRsvdPageParm, rsvdpageloc->LocGTKRsp);
872 SET_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_INFO(u1H2CAoacRsvdPageParm, rsvdpageloc->LocGTKInfo);
873 #ifdef CONFIG_GTK_OL
874 SET_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_EXT_MEM(u1H2CAoacRsvdPageParm, rsvdpageloc->LocGTKEXTMEM);
875 #endif /* CONFIG_GTK_OL */
876 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CAoacRsvdPageParm:", u1H2CAoacRsvdPageParm, H2C_AOAC_RSVDPAGE_LOC_LEN);
877 FillH2CCmd8723B(padapter, H2C_8723B_AOAC_RSVD_PAGE, H2C_AOAC_RSVDPAGE_LOC_LEN, u1H2CAoacRsvdPageParm);
878 } else {
879 #ifdef CONFIG_PNO_SUPPORT
880 if (!pwrpriv->pno_in_resume) {
881 DBG_871X("NLO_INFO =%d\n", rsvdpageloc->LocPNOInfo);
882 memset(&u1H2CAoacRsvdPageParm, 0, sizeof(u1H2CAoacRsvdPageParm));
883 SET_H2CCMD_AOAC_RSVDPAGE_LOC_NLO_INFO(u1H2CAoacRsvdPageParm, rsvdpageloc->LocPNOInfo);
884 FillH2CCmd8723B(padapter, H2C_AOAC_RSVDPAGE3, H2C_AOAC_RSVDPAGE_LOC_LEN, u1H2CAoacRsvdPageParm);
885 msleep(10);
886 }
887 #endif
888 }
889
890 #endif /* CONFIG_WOWLAN */
891 }
892
893 #ifdef CONFIG_AP_WOWLAN
rtl8723b_set_ap_wow_rsvdpage_cmd(struct adapter * padapter,PRSVDPAGE_LOC rsvdpageloc)894 static void rtl8723b_set_ap_wow_rsvdpage_cmd(
895 struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc
896 )
897 {
898 u8 header;
899 u8 rsvdparm[H2C_AOAC_RSVDPAGE_LOC_LEN] = {0};
900
901 header = rtw_read8(padapter, REG_BCNQ_BDNY);
902
903 DBG_871X("%s: beacon: %d, probeRsp: %d, header:0x%02x\n", __func__,
904 rsvdpageloc->LocApOffloadBCN,
905 rsvdpageloc->LocProbeRsp,
906 header);
907
908 SET_H2CCMD_AP_WOWLAN_RSVDPAGE_LOC_BCN(rsvdparm,
909 rsvdpageloc->LocApOffloadBCN + header);
910
911 FillH2CCmd8723B(padapter, H2C_8723B_BCN_RSVDPAGE,
912 H2C_BCN_RSVDPAGE_LEN, rsvdparm);
913
914 msleep(10);
915
916 memset(&rsvdparm, 0, sizeof(rsvdparm));
917
918 SET_H2CCMD_AP_WOWLAN_RSVDPAGE_LOC_ProbeRsp(
919 rsvdparm,
920 rsvdpageloc->LocProbeRsp + header);
921
922 FillH2CCmd8723B(padapter, H2C_8723B_PROBERSP_RSVDPAGE,
923 H2C_PROBERSP_RSVDPAGE_LEN, rsvdparm);
924
925 msleep(10);
926 }
927 #endif /* CONFIG_AP_WOWLAN */
928
rtl8723b_set_FwMediaStatusRpt_cmd(struct adapter * padapter,u8 mstatus,u8 macid)929 void rtl8723b_set_FwMediaStatusRpt_cmd(struct adapter *padapter, u8 mstatus, u8 macid)
930 {
931 u8 u1H2CMediaStatusRptParm[H2C_MEDIA_STATUS_RPT_LEN] = {0};
932 u8 macid_end = 0;
933
934 DBG_871X("%s(): mstatus = %d macid =%d\n", __func__, mstatus, macid);
935
936 SET_8723B_H2CCMD_MSRRPT_PARM_OPMODE(u1H2CMediaStatusRptParm, mstatus);
937 SET_8723B_H2CCMD_MSRRPT_PARM_MACID_IND(u1H2CMediaStatusRptParm, 0);
938 SET_8723B_H2CCMD_MSRRPT_PARM_MACID(u1H2CMediaStatusRptParm, macid);
939 SET_8723B_H2CCMD_MSRRPT_PARM_MACID_END(u1H2CMediaStatusRptParm, macid_end);
940
941 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CMediaStatusRptParm:", u1H2CMediaStatusRptParm, H2C_MEDIA_STATUS_RPT_LEN);
942 FillH2CCmd8723B(padapter, H2C_8723B_MEDIA_STATUS_RPT, H2C_MEDIA_STATUS_RPT_LEN, u1H2CMediaStatusRptParm);
943 }
944
945 #ifdef CONFIG_WOWLAN
rtl8723b_set_FwKeepAlive_cmd(struct adapter * padapter,u8 benable,u8 pkt_type)946 static void rtl8723b_set_FwKeepAlive_cmd(struct adapter *padapter, u8 benable, u8 pkt_type)
947 {
948 u8 u1H2CKeepAliveParm[H2C_KEEP_ALIVE_CTRL_LEN] = {0};
949 u8 adopt = 1, check_period = 5;
950
951 DBG_871X("%s(): benable = %d\n", __func__, benable);
952 SET_8723B_H2CCMD_KEEPALIVE_PARM_ENABLE(u1H2CKeepAliveParm, benable);
953 SET_8723B_H2CCMD_KEEPALIVE_PARM_ADOPT(u1H2CKeepAliveParm, adopt);
954 SET_8723B_H2CCMD_KEEPALIVE_PARM_PKT_TYPE(u1H2CKeepAliveParm, pkt_type);
955 SET_8723B_H2CCMD_KEEPALIVE_PARM_CHECK_PERIOD(u1H2CKeepAliveParm, check_period);
956
957 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CKeepAliveParm:", u1H2CKeepAliveParm, H2C_KEEP_ALIVE_CTRL_LEN);
958
959 FillH2CCmd8723B(padapter, H2C_8723B_KEEP_ALIVE, H2C_KEEP_ALIVE_CTRL_LEN, u1H2CKeepAliveParm);
960 }
961
rtl8723b_set_FwDisconDecision_cmd(struct adapter * padapter,u8 benable)962 static void rtl8723b_set_FwDisconDecision_cmd(struct adapter *padapter, u8 benable)
963 {
964 u8 u1H2CDisconDecisionParm[H2C_DISCON_DECISION_LEN] = {0};
965 u8 adopt = 1, check_period = 10, trypkt_num = 0;
966
967 DBG_871X("%s(): benable = %d\n", __func__, benable);
968 SET_8723B_H2CCMD_DISCONDECISION_PARM_ENABLE(u1H2CDisconDecisionParm, benable);
969 SET_8723B_H2CCMD_DISCONDECISION_PARM_ADOPT(u1H2CDisconDecisionParm, adopt);
970 SET_8723B_H2CCMD_DISCONDECISION_PARM_CHECK_PERIOD(u1H2CDisconDecisionParm, check_period);
971 SET_8723B_H2CCMD_DISCONDECISION_PARM_TRY_PKT_NUM(u1H2CDisconDecisionParm, trypkt_num);
972
973 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CDisconDecisionParm:", u1H2CDisconDecisionParm, H2C_DISCON_DECISION_LEN);
974
975 FillH2CCmd8723B(padapter, H2C_8723B_DISCON_DECISION, H2C_DISCON_DECISION_LEN, u1H2CDisconDecisionParm);
976 }
977 #endif /* CONFIG_WOWLAN */
978
rtl8723b_set_FwMacIdConfig_cmd(struct adapter * padapter,u8 mac_id,u8 raid,u8 bw,u8 sgi,u32 mask)979 void rtl8723b_set_FwMacIdConfig_cmd(struct adapter *padapter, u8 mac_id, u8 raid, u8 bw, u8 sgi, u32 mask)
980 {
981 u8 u1H2CMacIdConfigParm[H2C_MACID_CFG_LEN] = {0};
982
983 DBG_871X("%s(): mac_id =%d raid = 0x%x bw =%d mask = 0x%x\n", __func__, mac_id, raid, bw, mask);
984
985 SET_8723B_H2CCMD_MACID_CFG_MACID(u1H2CMacIdConfigParm, mac_id);
986 SET_8723B_H2CCMD_MACID_CFG_RAID(u1H2CMacIdConfigParm, raid);
987 SET_8723B_H2CCMD_MACID_CFG_SGI_EN(u1H2CMacIdConfigParm, sgi ? 1 : 0);
988 SET_8723B_H2CCMD_MACID_CFG_BW(u1H2CMacIdConfigParm, bw);
989 SET_8723B_H2CCMD_MACID_CFG_RATE_MASK0(u1H2CMacIdConfigParm, (u8)(mask & 0x000000ff));
990 SET_8723B_H2CCMD_MACID_CFG_RATE_MASK1(u1H2CMacIdConfigParm, (u8)((mask & 0x0000ff00) >> 8));
991 SET_8723B_H2CCMD_MACID_CFG_RATE_MASK2(u1H2CMacIdConfigParm, (u8)((mask & 0x00ff0000) >> 16));
992 SET_8723B_H2CCMD_MACID_CFG_RATE_MASK3(u1H2CMacIdConfigParm, (u8)((mask & 0xff000000) >> 24));
993
994 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CMacIdConfigParm:", u1H2CMacIdConfigParm, H2C_MACID_CFG_LEN);
995 FillH2CCmd8723B(padapter, H2C_8723B_MACID_CFG, H2C_MACID_CFG_LEN, u1H2CMacIdConfigParm);
996 }
997
rtl8723b_set_FwRssiSetting_cmd(struct adapter * padapter,u8 * param)998 static void rtl8723b_set_FwRssiSetting_cmd(struct adapter *padapter, u8 *param)
999 {
1000 u8 u1H2CRssiSettingParm[H2C_RSSI_SETTING_LEN] = {0};
1001 u8 mac_id = *param;
1002 u8 rssi = *(param+2);
1003 u8 uldl_state = 0;
1004
1005 /* DBG_871X("%s(): param =%.2x-%.2x-%.2x\n", __func__, *param, *(param+1), *(param+2)); */
1006 /* DBG_871X("%s(): mac_id =%d rssi =%d\n", __func__, mac_id, rssi); */
1007
1008 SET_8723B_H2CCMD_RSSI_SETTING_MACID(u1H2CRssiSettingParm, mac_id);
1009 SET_8723B_H2CCMD_RSSI_SETTING_RSSI(u1H2CRssiSettingParm, rssi);
1010 SET_8723B_H2CCMD_RSSI_SETTING_ULDL_STATE(u1H2CRssiSettingParm, uldl_state);
1011
1012 RT_PRINT_DATA(_module_hal_init_c_, _drv_notice_, "u1H2CRssiSettingParm:", u1H2CRssiSettingParm, H2C_RSSI_SETTING_LEN);
1013 FillH2CCmd8723B(padapter, H2C_8723B_RSSI_SETTING, H2C_RSSI_SETTING_LEN, u1H2CRssiSettingParm);
1014 }
1015
rtl8723b_set_FwPwrMode_cmd(struct adapter * padapter,u8 psmode)1016 void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 psmode)
1017 {
1018 int i;
1019 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1020 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1021 u8 u1H2CPwrModeParm[H2C_PWRMODE_LEN] = {0};
1022 u8 PowerState = 0, awake_intvl = 1, byte5 = 0, rlbm = 0;
1023
1024 if (pwrpriv->dtim > 0)
1025 DBG_871X("%s(): FW LPS mode = %d, SmartPS =%d, dtim =%d\n", __func__, psmode, pwrpriv->smart_ps, pwrpriv->dtim);
1026 else
1027 DBG_871X("%s(): FW LPS mode = %d, SmartPS =%d\n", __func__, psmode, pwrpriv->smart_ps);
1028
1029 #ifdef CONFIG_WOWLAN
1030 if (psmode == PS_MODE_DTIM) { /* For WOWLAN LPS, DTIM = (awake_intvl - 1) */
1031 awake_intvl = 3;/* DTIM =2 */
1032 rlbm = 2;
1033 } else
1034 #endif /* CONFIG_WOWLAN */
1035 {
1036 if (pwrpriv->dtim > 0 && pwrpriv->dtim < 16)
1037 awake_intvl = pwrpriv->dtim+1;/* DTIM = (awake_intvl - 1) */
1038 else
1039 awake_intvl = 3;/* DTIM =2 */
1040
1041 rlbm = 2;
1042 }
1043
1044
1045 if (padapter->registrypriv.wifi_spec == 1) {
1046 awake_intvl = 2;
1047 rlbm = 2;
1048 }
1049
1050 if (psmode > 0) {
1051 if (rtw_btcoex_IsBtControlLps(padapter) == true) {
1052 PowerState = rtw_btcoex_RpwmVal(padapter);
1053 byte5 = rtw_btcoex_LpsVal(padapter);
1054
1055 if ((rlbm == 2) && (byte5 & BIT(4))) {
1056 /* Keep awake interval to 1 to prevent from */
1057 /* decreasing coex performance */
1058 awake_intvl = 2;
1059 rlbm = 2;
1060 }
1061 } else {
1062 PowerState = 0x00;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */
1063 byte5 = 0x40;
1064 }
1065 } else {
1066 PowerState = 0x0C;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */
1067 byte5 = 0x40;
1068 }
1069
1070 SET_8723B_H2CCMD_PWRMODE_PARM_MODE(u1H2CPwrModeParm, (psmode > 0) ? 1 : 0);
1071 SET_8723B_H2CCMD_PWRMODE_PARM_SMART_PS(u1H2CPwrModeParm, pwrpriv->smart_ps);
1072 SET_8723B_H2CCMD_PWRMODE_PARM_RLBM(u1H2CPwrModeParm, rlbm);
1073 SET_8723B_H2CCMD_PWRMODE_PARM_BCN_PASS_TIME(u1H2CPwrModeParm, awake_intvl);
1074 SET_8723B_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(u1H2CPwrModeParm, padapter->registrypriv.uapsd_enable);
1075 SET_8723B_H2CCMD_PWRMODE_PARM_PWR_STATE(u1H2CPwrModeParm, PowerState);
1076 SET_8723B_H2CCMD_PWRMODE_PARM_BYTE5(u1H2CPwrModeParm, byte5);
1077 if (psmode != PS_MODE_ACTIVE) {
1078 if (pmlmeext->adaptive_tsf_done == false && pmlmeext->bcn_cnt > 0) {
1079 u8 ratio_20_delay, ratio_80_delay;
1080
1081 /* byte 6 for adaptive_early_32k */
1082 /* 0:3] = DrvBcnEarly (ms) , [4:7] = DrvBcnTimeOut (ms) */
1083 /* 20% for DrvBcnEarly, 80% for DrvBcnTimeOut */
1084 ratio_20_delay = 0;
1085 ratio_80_delay = 0;
1086 pmlmeext->DrvBcnEarly = 0xff;
1087 pmlmeext->DrvBcnTimeOut = 0xff;
1088
1089 DBG_871X("%s(): bcn_cnt = %d\n", __func__, pmlmeext->bcn_cnt);
1090
1091 for (i = 0; i < 9; i++) {
1092 pmlmeext->bcn_delay_ratio[i] = (pmlmeext->bcn_delay_cnt[i]*100)/pmlmeext->bcn_cnt;
1093
1094 DBG_871X(
1095 "%s(): bcn_delay_cnt[%d]=%d, bcn_delay_ratio[%d] = %d\n",
1096 __func__,
1097 i,
1098 pmlmeext->bcn_delay_cnt[i],
1099 i,
1100 pmlmeext->bcn_delay_ratio[i]
1101 );
1102
1103 ratio_20_delay += pmlmeext->bcn_delay_ratio[i];
1104 ratio_80_delay += pmlmeext->bcn_delay_ratio[i];
1105
1106 if (ratio_20_delay > 20 && pmlmeext->DrvBcnEarly == 0xff) {
1107 pmlmeext->DrvBcnEarly = i;
1108 DBG_871X("%s(): DrvBcnEarly = %d\n", __func__, pmlmeext->DrvBcnEarly);
1109 }
1110
1111 if (ratio_80_delay > 80 && pmlmeext->DrvBcnTimeOut == 0xff) {
1112 pmlmeext->DrvBcnTimeOut = i;
1113 DBG_871X("%s(): DrvBcnTimeOut = %d\n", __func__, pmlmeext->DrvBcnTimeOut);
1114 }
1115
1116 /* reset adaptive_early_32k cnt */
1117 pmlmeext->bcn_delay_cnt[i] = 0;
1118 pmlmeext->bcn_delay_ratio[i] = 0;
1119
1120 }
1121
1122 pmlmeext->bcn_cnt = 0;
1123 pmlmeext->adaptive_tsf_done = true;
1124
1125 } else {
1126 DBG_871X("%s(): DrvBcnEarly = %d\n", __func__, pmlmeext->DrvBcnEarly);
1127 DBG_871X("%s(): DrvBcnTimeOut = %d\n", __func__, pmlmeext->DrvBcnTimeOut);
1128 }
1129
1130 /* offload to FW if fw version > v15.10
1131 pmlmeext->DrvBcnEarly = 0;
1132 pmlmeext->DrvBcnTimeOut =7;
1133
1134 if ((pmlmeext->DrvBcnEarly!= 0Xff) && (pmlmeext->DrvBcnTimeOut!= 0xff))
1135 u1H2CPwrModeParm[H2C_PWRMODE_LEN-1] = BIT(0) | ((pmlmeext->DrvBcnEarly<<1)&0x0E) |((pmlmeext->DrvBcnTimeOut<<4)&0xf0) ;
1136 */
1137
1138 }
1139
1140 rtw_btcoex_RecordPwrMode(padapter, u1H2CPwrModeParm, H2C_PWRMODE_LEN);
1141
1142 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CPwrModeParm:", u1H2CPwrModeParm, H2C_PWRMODE_LEN);
1143
1144 FillH2CCmd8723B(padapter, H2C_8723B_SET_PWR_MODE, H2C_PWRMODE_LEN, u1H2CPwrModeParm);
1145 }
1146
rtl8723b_set_FwPsTuneParam_cmd(struct adapter * padapter)1147 void rtl8723b_set_FwPsTuneParam_cmd(struct adapter *padapter)
1148 {
1149 u8 u1H2CPsTuneParm[H2C_PSTUNEPARAM_LEN] = {0};
1150 u8 bcn_to_limit = 10; /* 10 * 100 * awakeinterval (ms) */
1151 u8 dtim_timeout = 5; /* ms wait broadcast data timer */
1152 u8 ps_timeout = 20; /* ms Keep awake when tx */
1153 u8 dtim_period = 3;
1154
1155 /* DBG_871X("%s(): FW LPS mode = %d\n", __func__, psmode); */
1156
1157 SET_8723B_H2CCMD_PSTUNE_PARM_BCN_TO_LIMIT(u1H2CPsTuneParm, bcn_to_limit);
1158 SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_TIMEOUT(u1H2CPsTuneParm, dtim_timeout);
1159 SET_8723B_H2CCMD_PSTUNE_PARM_PS_TIMEOUT(u1H2CPsTuneParm, ps_timeout);
1160 SET_8723B_H2CCMD_PSTUNE_PARM_ADOPT(u1H2CPsTuneParm, 1);
1161 SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_PERIOD(u1H2CPsTuneParm, dtim_period);
1162
1163 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CPsTuneParm:", u1H2CPsTuneParm, H2C_PSTUNEPARAM_LEN);
1164
1165 FillH2CCmd8723B(padapter, H2C_8723B_PS_TUNING_PARA, H2C_PSTUNEPARAM_LEN, u1H2CPsTuneParm);
1166 }
1167
rtl8723b_set_FwPwrModeInIPS_cmd(struct adapter * padapter,u8 cmd_param)1168 void rtl8723b_set_FwPwrModeInIPS_cmd(struct adapter *padapter, u8 cmd_param)
1169 {
1170 /* BIT0:enable, BIT1:NoConnect32k */
1171
1172 DBG_871X("%s()\n", __func__);
1173
1174 FillH2CCmd8723B(padapter, H2C_8723B_FWLPS_IN_IPS_, 1, &cmd_param);
1175 }
1176
1177 #ifdef CONFIG_WOWLAN
rtl8723b_set_FwWoWlanCtrl_Cmd(struct adapter * padapter,u8 bFuncEn)1178 static void rtl8723b_set_FwWoWlanCtrl_Cmd(struct adapter *padapter, u8 bFuncEn)
1179 {
1180 struct security_priv *psecpriv = &padapter->securitypriv;
1181 u8 u1H2CWoWlanCtrlParm[H2C_WOWLAN_LEN] = {0};
1182 u8 discont_wake = 1, gpionum = 0, gpio_dur = 0, hw_unicast = 0;
1183 u8 sdio_wakeup_enable = 1;
1184 u8 gpio_high_active = 0; /* 0: low active, 1: high active */
1185 u8 magic_pkt = 0;
1186
1187 #ifdef CONFIG_GPIO_WAKEUP
1188 gpionum = WAKEUP_GPIO_IDX;
1189 sdio_wakeup_enable = 0;
1190 #endif
1191
1192 #ifdef CONFIG_PNO_SUPPORT
1193 if (!ppwrpriv->wowlan_pno_enable)
1194 magic_pkt = 1;
1195 #endif
1196
1197 if (psecpriv->dot11PrivacyAlgrthm == _WEP40_ || psecpriv->dot11PrivacyAlgrthm == _WEP104_)
1198 hw_unicast = 1;
1199
1200 DBG_871X("%s(): bFuncEn =%d\n", __func__, bFuncEn);
1201
1202 SET_H2CCMD_WOWLAN_FUNC_ENABLE(u1H2CWoWlanCtrlParm, bFuncEn);
1203 SET_H2CCMD_WOWLAN_PATTERN_MATCH_ENABLE(u1H2CWoWlanCtrlParm, 0);
1204 SET_H2CCMD_WOWLAN_MAGIC_PKT_ENABLE(u1H2CWoWlanCtrlParm, magic_pkt);
1205 SET_H2CCMD_WOWLAN_UNICAST_PKT_ENABLE(u1H2CWoWlanCtrlParm, hw_unicast);
1206 SET_H2CCMD_WOWLAN_ALL_PKT_DROP(u1H2CWoWlanCtrlParm, 0);
1207 SET_H2CCMD_WOWLAN_GPIO_ACTIVE(u1H2CWoWlanCtrlParm, gpio_high_active);
1208 SET_H2CCMD_WOWLAN_DISCONNECT_WAKE_UP(u1H2CWoWlanCtrlParm, discont_wake);
1209 SET_H2CCMD_WOWLAN_GPIONUM(u1H2CWoWlanCtrlParm, gpionum);
1210 SET_H2CCMD_WOWLAN_DATAPIN_WAKE_UP(u1H2CWoWlanCtrlParm, sdio_wakeup_enable);
1211 SET_H2CCMD_WOWLAN_GPIO_DURATION(u1H2CWoWlanCtrlParm, gpio_dur);
1212 /* SET_H2CCMD_WOWLAN_GPIO_PULSE_EN(u1H2CWoWlanCtrlParm, 1); */
1213 SET_H2CCMD_WOWLAN_GPIO_PULSE_COUNT(u1H2CWoWlanCtrlParm, 0x09);
1214
1215 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CWoWlanCtrlParm:", u1H2CWoWlanCtrlParm, H2C_WOWLAN_LEN);
1216
1217 FillH2CCmd8723B(padapter, H2C_8723B_WOWLAN, H2C_WOWLAN_LEN, u1H2CWoWlanCtrlParm);
1218 }
1219
rtl8723b_set_FwRemoteWakeCtrl_Cmd(struct adapter * padapter,u8 benable)1220 static void rtl8723b_set_FwRemoteWakeCtrl_Cmd(struct adapter *padapter, u8 benable)
1221 {
1222 u8 u1H2CRemoteWakeCtrlParm[H2C_REMOTE_WAKE_CTRL_LEN] = {0};
1223 struct security_priv *psecuritypriv = &(padapter->securitypriv);
1224 struct pwrctrl_priv *ppwrpriv = adapter_to_pwrctl(padapter);
1225
1226 DBG_871X("%s(): Enable =%d\n", __func__, benable);
1227
1228 if (!ppwrpriv->wowlan_pno_enable) {
1229 SET_H2CCMD_REMOTE_WAKECTRL_ENABLE(u1H2CRemoteWakeCtrlParm, benable);
1230 SET_H2CCMD_REMOTE_WAKE_CTRL_ARP_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, 1);
1231 #ifdef CONFIG_GTK_OL
1232 if (psecuritypriv->binstallKCK_KEK &&
1233 psecuritypriv->dot11PrivacyAlgrthm == _AES_) {
1234 SET_H2CCMD_REMOTE_WAKE_CTRL_GTK_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, 1);
1235 } else {
1236 DBG_871X("no kck or security is not AES\n");
1237 SET_H2CCMD_REMOTE_WAKE_CTRL_GTK_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, 0);
1238 }
1239 #endif /* CONFIG_GTK_OL */
1240
1241 SET_H2CCMD_REMOTE_WAKE_CTRL_FW_UNICAST_EN(u1H2CRemoteWakeCtrlParm, 1);
1242
1243 if ((psecuritypriv->dot11PrivacyAlgrthm == _AES_) ||
1244 (psecuritypriv->dot11PrivacyAlgrthm == _NO_PRIVACY_))
1245 SET_H2CCMD_REMOTE_WAKE_CTRL_ARP_ACTION(u1H2CRemoteWakeCtrlParm, 0);
1246 else
1247 SET_H2CCMD_REMOTE_WAKE_CTRL_ARP_ACTION(u1H2CRemoteWakeCtrlParm, 1);
1248 }
1249 #ifdef CONFIG_PNO_SUPPORT
1250 else {
1251 SET_H2CCMD_REMOTE_WAKECTRL_ENABLE(u1H2CRemoteWakeCtrlParm, benable);
1252 SET_H2CCMD_REMOTE_WAKE_CTRL_NLO_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, benable);
1253 }
1254 #endif
1255 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CRemoteWakeCtrlParm:", u1H2CRemoteWakeCtrlParm, H2C_REMOTE_WAKE_CTRL_LEN);
1256 FillH2CCmd8723B(padapter, H2C_8723B_REMOTE_WAKE_CTRL,
1257 H2C_REMOTE_WAKE_CTRL_LEN, u1H2CRemoteWakeCtrlParm);
1258 #ifdef CONFIG_PNO_SUPPORT
1259 if (ppwrpriv->wowlan_pno_enable && ppwrpriv->pno_in_resume == false) {
1260 res = rtw_read8(padapter, REG_PNO_STATUS);
1261 DBG_871X("cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", res);
1262 while (!(res&BIT(7)) && count < 25) {
1263 DBG_871X("[%d] cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", count, res);
1264 res = rtw_read8(padapter, REG_PNO_STATUS);
1265 count++;
1266 msleep(2);
1267 }
1268 DBG_871X("cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", res);
1269 }
1270 #endif /* CONFIG_PNO_SUPPORT */
1271 }
1272
rtl8723b_set_FwAOACGlobalInfo_Cmd(struct adapter * padapter,u8 group_alg,u8 pairwise_alg)1273 static void rtl8723b_set_FwAOACGlobalInfo_Cmd(struct adapter *padapter, u8 group_alg, u8 pairwise_alg)
1274 {
1275 u8 u1H2CAOACGlobalInfoParm[H2C_AOAC_GLOBAL_INFO_LEN] = {0};
1276
1277 DBG_871X("%s(): group_alg =%d pairwise_alg =%d\n", __func__, group_alg, pairwise_alg);
1278
1279 SET_H2CCMD_AOAC_GLOBAL_INFO_PAIRWISE_ENC_ALG(u1H2CAOACGlobalInfoParm, pairwise_alg);
1280 SET_H2CCMD_AOAC_GLOBAL_INFO_GROUP_ENC_ALG(u1H2CAOACGlobalInfoParm, group_alg);
1281
1282 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CAOACGlobalInfoParm:", u1H2CAOACGlobalInfoParm, H2C_AOAC_GLOBAL_INFO_LEN);
1283
1284 FillH2CCmd8723B(padapter, H2C_8723B_AOAC_GLOBAL_INFO, H2C_AOAC_GLOBAL_INFO_LEN, u1H2CAOACGlobalInfoParm);
1285 }
1286
1287 #ifdef CONFIG_PNO_SUPPORT
rtl8723b_set_FwScanOffloadInfo_cmd(struct adapter * padapter,PRSVDPAGE_LOC rsvdpageloc,u8 enable)1288 static void rtl8723b_set_FwScanOffloadInfo_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc, u8 enable)
1289 {
1290 u8 u1H2CScanOffloadInfoParm[H2C_SCAN_OFFLOAD_CTRL_LEN] = {0};
1291 u8 res = 0, count = 0;
1292 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1293
1294 DBG_871X("%s: loc_probe_packet:%d, loc_scan_info: %d loc_ssid_info:%d\n",
1295 __func__, rsvdpageloc->LocProbePacket, rsvdpageloc->LocScanInfo, rsvdpageloc->LocSSIDInfo);
1296
1297 SET_H2CCMD_AOAC_NLO_FUN_EN(u1H2CScanOffloadInfoParm, enable);
1298 SET_H2CCMD_AOAC_RSVDPAGE_LOC_SCAN_INFO(u1H2CScanOffloadInfoParm, rsvdpageloc->LocScanInfo);
1299 SET_H2CCMD_AOAC_RSVDPAGE_LOC_PROBE_PACKET(u1H2CScanOffloadInfoParm, rsvdpageloc->LocProbePacket);
1300 SET_H2CCMD_AOAC_RSVDPAGE_LOC_SSID_INFO(u1H2CScanOffloadInfoParm, rsvdpageloc->LocSSIDInfo);
1301
1302 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CScanOffloadInfoParm:", u1H2CScanOffloadInfoParm, H2C_SCAN_OFFLOAD_CTRL_LEN);
1303 FillH2CCmd8723B(padapter, H2C_8723B_D0_SCAN_OFFLOAD_INFO, H2C_SCAN_OFFLOAD_CTRL_LEN, u1H2CScanOffloadInfoParm);
1304
1305 msleep(20);
1306 }
1307 #endif /* CONFIG_PNO_SUPPORT */
1308
rtl8723b_set_FwWoWlanRelated_cmd(struct adapter * padapter,u8 enable)1309 static void rtl8723b_set_FwWoWlanRelated_cmd(struct adapter *padapter, u8 enable)
1310 {
1311 struct security_priv *psecpriv = &padapter->securitypriv;
1312 struct pwrctrl_priv *ppwrpriv = adapter_to_pwrctl(padapter);
1313 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1314 struct sta_info *psta = NULL;
1315 u8 pkt_type = 0;
1316
1317 DBG_871X_LEVEL(_drv_always_, "+%s()+: enable =%d\n", __func__, enable);
1318 if (enable) {
1319 rtl8723b_set_FwAOACGlobalInfo_Cmd(padapter, psecpriv->dot118021XGrpPrivacy, psecpriv->dot11PrivacyAlgrthm);
1320
1321 rtl8723b_set_FwJoinBssRpt_cmd(padapter, RT_MEDIA_CONNECT); /* RT_MEDIA_CONNECT will confuse in the future */
1322
1323 if (!(ppwrpriv->wowlan_pno_enable)) {
1324 psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(pmlmepriv));
1325 if (psta != NULL)
1326 rtl8723b_set_FwMediaStatusRpt_cmd(padapter, RT_MEDIA_CONNECT, psta->mac_id);
1327 } else
1328 DBG_871X("%s(): Disconnected, no FwMediaStatusRpt CONNECT\n", __func__);
1329
1330 msleep(2);
1331
1332 if (!(ppwrpriv->wowlan_pno_enable)) {
1333 rtl8723b_set_FwDisconDecision_cmd(padapter, enable);
1334 msleep(2);
1335
1336 if ((psecpriv->dot11PrivacyAlgrthm != _WEP40_) || (psecpriv->dot11PrivacyAlgrthm != _WEP104_))
1337 pkt_type = 1;
1338
1339 rtl8723b_set_FwKeepAlive_cmd(padapter, enable, pkt_type);
1340 msleep(2);
1341 }
1342
1343 rtl8723b_set_FwWoWlanCtrl_Cmd(padapter, enable);
1344 msleep(2);
1345
1346 rtl8723b_set_FwRemoteWakeCtrl_Cmd(padapter, enable);
1347 } else {
1348 rtl8723b_set_FwRemoteWakeCtrl_Cmd(padapter, enable);
1349 msleep(2);
1350 rtl8723b_set_FwWoWlanCtrl_Cmd(padapter, enable);
1351 }
1352
1353 DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__);
1354 }
1355
rtl8723b_set_wowlan_cmd(struct adapter * padapter,u8 enable)1356 void rtl8723b_set_wowlan_cmd(struct adapter *padapter, u8 enable)
1357 {
1358 rtl8723b_set_FwWoWlanRelated_cmd(padapter, enable);
1359 }
1360 #endif /* CONFIG_WOWLAN */
1361
1362 #ifdef CONFIG_AP_WOWLAN
rtl8723b_set_FwAPWoWlanCtrl_Cmd(struct adapter * padapter,u8 bFuncEn)1363 static void rtl8723b_set_FwAPWoWlanCtrl_Cmd(struct adapter *padapter, u8 bFuncEn)
1364 {
1365 u8 u1H2CAPWoWlanCtrlParm[H2C_WOWLAN_LEN] = {0};
1366 u8 gpionum = 0, gpio_dur = 0;
1367 u8 gpio_high_active = 1; /* 0: low active, 1: high active */
1368 u8 gpio_pulse = bFuncEn;
1369 #ifdef CONFIG_GPIO_WAKEUP
1370 gpionum = WAKEUP_GPIO_IDX;
1371 #endif
1372
1373 DBG_871X("%s(): bFuncEn =%d\n", __func__, bFuncEn);
1374
1375 if (bFuncEn)
1376 gpio_dur = 16;
1377 else
1378 gpio_dur = 0;
1379
1380 SET_H2CCMD_AP_WOW_GPIO_CTRL_INDEX(u1H2CAPWoWlanCtrlParm,
1381 gpionum);
1382 SET_H2CCMD_AP_WOW_GPIO_CTRL_PLUS(u1H2CAPWoWlanCtrlParm,
1383 gpio_pulse);
1384 SET_H2CCMD_AP_WOW_GPIO_CTRL_HIGH_ACTIVE(u1H2CAPWoWlanCtrlParm,
1385 gpio_high_active);
1386 SET_H2CCMD_AP_WOW_GPIO_CTRL_EN(u1H2CAPWoWlanCtrlParm,
1387 bFuncEn);
1388 SET_H2CCMD_AP_WOW_GPIO_CTRL_DURATION(u1H2CAPWoWlanCtrlParm,
1389 gpio_dur);
1390
1391 FillH2CCmd8723B(padapter, H2C_8723B_AP_WOW_GPIO_CTRL,
1392 H2C_AP_WOW_GPIO_CTRL_LEN, u1H2CAPWoWlanCtrlParm);
1393 }
1394
rtl8723b_set_Fw_AP_Offload_Cmd(struct adapter * padapter,u8 bFuncEn)1395 static void rtl8723b_set_Fw_AP_Offload_Cmd(struct adapter *padapter, u8 bFuncEn)
1396 {
1397 u8 u1H2CAPOffloadCtrlParm[H2C_WOWLAN_LEN] = {0};
1398
1399 DBG_871X("%s(): bFuncEn =%d\n", __func__, bFuncEn);
1400
1401 SET_H2CCMD_AP_WOWLAN_EN(u1H2CAPOffloadCtrlParm, bFuncEn);
1402
1403 FillH2CCmd8723B(padapter, H2C_8723B_AP_OFFLOAD,
1404 H2C_AP_OFFLOAD_LEN, u1H2CAPOffloadCtrlParm);
1405 }
1406
rtl8723b_set_AP_FwWoWlan_cmd(struct adapter * padapter,u8 enable)1407 static void rtl8723b_set_AP_FwWoWlan_cmd(struct adapter *padapter, u8 enable)
1408 {
1409 DBG_871X_LEVEL(_drv_always_, "+%s()+: enable =%d\n", __func__, enable);
1410 if (enable) {
1411 rtl8723b_set_FwJoinBssRpt_cmd(padapter, RT_MEDIA_CONNECT);
1412 issue_beacon(padapter, 0);
1413 }
1414
1415 rtl8723b_set_FwAPWoWlanCtrl_Cmd(padapter, enable);
1416 msleep(10);
1417 rtl8723b_set_Fw_AP_Offload_Cmd(padapter, enable);
1418 msleep(10);
1419 DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__);
1420 return ;
1421 }
1422
rtl8723b_set_ap_wowlan_cmd(struct adapter * padapter,u8 enable)1423 void rtl8723b_set_ap_wowlan_cmd(struct adapter *padapter, u8 enable)
1424 {
1425 rtl8723b_set_AP_FwWoWlan_cmd(padapter, enable);
1426 }
1427 #endif /* CONFIG_AP_WOWLAN */
1428
1429 /* */
1430 /* Description: Fill the reserved packets that FW will use to RSVD page. */
1431 /* Now we just send 4 types packet to rsvd page. */
1432 /* (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. */
1433 /* Input: */
1434 /* bDLFinished - false: At the first time we will send all the packets as a large packet to Hw, */
1435 /* so we need to set the packet length to total lengh. */
1436 /* true: At the second time, we should send the first packet (default:beacon) */
1437 /* to Hw again and set the lengh in descriptor to the real beacon lengh. */
1438 /* 2009.10.15 by tynli. */
rtl8723b_set_FwRsvdPagePkt(struct adapter * padapter,bool bDLFinished)1439 static void rtl8723b_set_FwRsvdPagePkt(
1440 struct adapter *padapter, bool bDLFinished
1441 )
1442 {
1443 struct hal_com_data *pHalData;
1444 struct xmit_frame *pcmdframe;
1445 struct pkt_attrib *pattrib;
1446 struct xmit_priv *pxmitpriv;
1447 struct mlme_ext_priv *pmlmeext;
1448 struct mlme_ext_info *pmlmeinfo;
1449 struct pwrctrl_priv *pwrctl;
1450 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1451 u32 BeaconLength = 0, PSPollLength = 0;
1452 u32 NullDataLength = 0, QosNullLength = 0, BTQosNullLength = 0;
1453 u8 *ReservedPagePacket;
1454 u8 TxDescLen = TXDESC_SIZE, TxDescOffset = TXDESC_OFFSET;
1455 u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0;
1456 u16 BufIndex, PageSize = 128;
1457 u32 TotalPacketLen, MaxRsvdPageBufSize = 0;
1458 RSVDPAGE_LOC RsvdPageLoc;
1459 #ifdef CONFIG_WOWLAN
1460 u32 ARPLegnth = 0, GTKLegnth = 0;
1461 u8 currentip[4];
1462 u8 cur_dot11txpn[8];
1463 #ifdef CONFIG_GTK_OL
1464 struct sta_priv *pstapriv = &padapter->stapriv;
1465 struct sta_info *psta;
1466 u8 kek[RTW_KEK_LEN];
1467 u8 kck[RTW_KCK_LEN];
1468 #endif
1469 #endif
1470
1471 /* DBG_871X("%s---->\n", __func__); */
1472
1473 pHalData = GET_HAL_DATA(padapter);
1474 pxmitpriv = &padapter->xmitpriv;
1475 pmlmeext = &padapter->mlmeextpriv;
1476 pmlmeinfo = &pmlmeext->mlmext_info;
1477 pwrctl = adapter_to_pwrctl(padapter);
1478
1479 RsvdPageNum = BCNQ_PAGE_NUM_8723B + WOWLAN_PAGE_NUM_8723B;
1480 MaxRsvdPageBufSize = RsvdPageNum*PageSize;
1481
1482 pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv);
1483 if (pcmdframe == NULL) {
1484 DBG_871X("%s: alloc ReservedPagePacket fail!\n", __func__);
1485 return;
1486 }
1487
1488 ReservedPagePacket = pcmdframe->buf_addr;
1489 memset(&RsvdPageLoc, 0, sizeof(RSVDPAGE_LOC));
1490
1491 /* 3 (1) beacon */
1492 BufIndex = TxDescOffset;
1493 ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength);
1494
1495 /* When we count the first page size, we need to reserve description size for the RSVD */
1496 /* packet, it will be filled in front of the packet in TXPKTBUF. */
1497 CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength);
1498 /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */
1499 if (CurtPktPageNum == 1)
1500 CurtPktPageNum += 1;
1501
1502 TotalPageNum += CurtPktPageNum;
1503
1504 BufIndex += (CurtPktPageNum*PageSize);
1505
1506 /* 3 (2) ps-poll */
1507 RsvdPageLoc.LocPsPoll = TotalPageNum;
1508 ConstructPSPoll(padapter, &ReservedPagePacket[BufIndex], &PSPollLength);
1509 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], PSPollLength, true, false, false);
1510
1511 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: PS-POLL %p %d\n", */
1512 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (PSPollLength+TxDescLen)); */
1513
1514 CurtPktPageNum = (u8)PageNum_128(TxDescLen + PSPollLength);
1515
1516 TotalPageNum += CurtPktPageNum;
1517
1518 BufIndex += (CurtPktPageNum*PageSize);
1519
1520 /* 3 (3) null data */
1521 RsvdPageLoc.LocNullData = TotalPageNum;
1522 ConstructNullFunctionData(
1523 padapter,
1524 &ReservedPagePacket[BufIndex],
1525 &NullDataLength,
1526 get_my_bssid(&pmlmeinfo->network),
1527 false, 0, 0, false
1528 );
1529 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], NullDataLength, false, false, false);
1530
1531 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: NULL DATA %p %d\n", */
1532 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (NullDataLength+TxDescLen)); */
1533
1534 CurtPktPageNum = (u8)PageNum_128(TxDescLen + NullDataLength);
1535
1536 TotalPageNum += CurtPktPageNum;
1537
1538 BufIndex += (CurtPktPageNum*PageSize);
1539
1540 /* 3 (5) Qos null data */
1541 RsvdPageLoc.LocQosNull = TotalPageNum;
1542 ConstructNullFunctionData(
1543 padapter,
1544 &ReservedPagePacket[BufIndex],
1545 &QosNullLength,
1546 get_my_bssid(&pmlmeinfo->network),
1547 true, 0, 0, false
1548 );
1549 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], QosNullLength, false, false, false);
1550
1551 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: QOS NULL DATA %p %d\n", */
1552 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (QosNullLength+TxDescLen)); */
1553
1554 CurtPktPageNum = (u8)PageNum_128(TxDescLen + QosNullLength);
1555
1556 TotalPageNum += CurtPktPageNum;
1557
1558 BufIndex += (CurtPktPageNum*PageSize);
1559
1560 /* 3 (6) BT Qos null data */
1561 RsvdPageLoc.LocBTQosNull = TotalPageNum;
1562 ConstructNullFunctionData(
1563 padapter,
1564 &ReservedPagePacket[BufIndex],
1565 &BTQosNullLength,
1566 get_my_bssid(&pmlmeinfo->network),
1567 true, 0, 0, false
1568 );
1569 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], BTQosNullLength, false, true, false);
1570
1571 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: BT QOS NULL DATA %p %d\n", */
1572 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (BTQosNullLength+TxDescLen)); */
1573
1574 CurtPktPageNum = (u8)PageNum_128(TxDescLen + BTQosNullLength);
1575
1576 TotalPageNum += CurtPktPageNum;
1577
1578 BufIndex += (CurtPktPageNum*PageSize);
1579
1580 #ifdef CONFIG_WOWLAN
1581 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1582 /* if (pwrctl->wowlan_mode == true) { */
1583 /* BufIndex += (CurtPktPageNum*PageSize); */
1584
1585 /* 3(7) ARP RSP */
1586 rtw_get_current_ip_address(padapter, currentip);
1587 RsvdPageLoc.LocArpRsp = TotalPageNum;
1588 {
1589 ConstructARPResponse(
1590 padapter,
1591 &ReservedPagePacket[BufIndex],
1592 &ARPLegnth,
1593 currentip
1594 );
1595 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], ARPLegnth, false, false, true);
1596
1597 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: ARP RSP %p %d\n", */
1598 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (ARPLegnth+TxDescLen)); */
1599
1600 CurtPktPageNum = (u8)PageNum_128(TxDescLen + ARPLegnth);
1601 }
1602 TotalPageNum += CurtPktPageNum;
1603
1604 BufIndex += (CurtPktPageNum*PageSize);
1605
1606 /* 3(8) SEC IV */
1607 rtw_get_sec_iv(padapter, cur_dot11txpn, get_my_bssid(&pmlmeinfo->network));
1608 RsvdPageLoc.LocRemoteCtrlInfo = TotalPageNum;
1609 memcpy(ReservedPagePacket+BufIndex-TxDescLen, cur_dot11txpn, _AES_IV_LEN_);
1610
1611 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: SEC IV %p %d\n", */
1612 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], _AES_IV_LEN_); */
1613
1614 CurtPktPageNum = (u8)PageNum_128(_AES_IV_LEN_);
1615
1616 TotalPageNum += CurtPktPageNum;
1617
1618 #ifdef CONFIG_GTK_OL
1619 BufIndex += (CurtPktPageNum*PageSize);
1620
1621 /* if the ap staion info. exists, get the kek, kck from staion info. */
1622 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
1623 if (psta == NULL) {
1624 memset(kek, 0, RTW_KEK_LEN);
1625 memset(kck, 0, RTW_KCK_LEN);
1626 DBG_8192C("%s, KEK, KCK download rsvd page all zero\n", __func__);
1627 } else {
1628 memcpy(kek, psta->kek, RTW_KEK_LEN);
1629 memcpy(kck, psta->kck, RTW_KCK_LEN);
1630 }
1631
1632 /* 3(9) KEK, KCK */
1633 RsvdPageLoc.LocGTKInfo = TotalPageNum;
1634 memcpy(ReservedPagePacket+BufIndex-TxDescLen, kck, RTW_KCK_LEN);
1635 memcpy(ReservedPagePacket+BufIndex-TxDescLen+RTW_KCK_LEN, kek, RTW_KEK_LEN);
1636
1637 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: KEK KCK %p %d\n", */
1638 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (TxDescLen + RTW_KCK_LEN + RTW_KEK_LEN)); */
1639
1640 CurtPktPageNum = (u8)PageNum_128(TxDescLen + RTW_KCK_LEN + RTW_KEK_LEN);
1641
1642 TotalPageNum += CurtPktPageNum;
1643
1644 BufIndex += (CurtPktPageNum*PageSize);
1645
1646 /* 3(10) GTK Response */
1647 RsvdPageLoc.LocGTKRsp = TotalPageNum;
1648 ConstructGTKResponse(
1649 padapter,
1650 &ReservedPagePacket[BufIndex],
1651 >KLegnth
1652 );
1653
1654 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], GTKLegnth, false, false, true);
1655 /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: GTK RSP %p %d\n", */
1656 /* __func__, &ReservedPagePacket[BufIndex-TxDescLen], (TxDescLen + GTKLegnth)); */
1657
1658 CurtPktPageNum = (u8)PageNum_128(TxDescLen + GTKLegnth);
1659
1660 TotalPageNum += CurtPktPageNum;
1661
1662 BufIndex += (CurtPktPageNum*PageSize);
1663
1664 /* below page is empty for GTK extension memory */
1665 /* 3(11) GTK EXT MEM */
1666 RsvdPageLoc.LocGTKEXTMEM = TotalPageNum;
1667
1668 CurtPktPageNum = 2;
1669
1670 TotalPageNum += CurtPktPageNum;
1671
1672 TotalPacketLen = BufIndex-TxDescLen + 256; /* extension memory for FW */
1673 #else
1674 TotalPacketLen = BufIndex-TxDescLen + sizeof (union pn48); /* IV len */
1675 #endif /* CONFIG_GTK_OL */
1676 } else
1677 #endif /* CONFIG_WOWLAN */
1678 {
1679 #ifdef CONFIG_PNO_SUPPORT
1680 if (pwrctl->pno_in_resume == false && pwrctl->pno_inited == true) {
1681 /* Probe Request */
1682 RsvdPageLoc.LocProbePacket = TotalPageNum;
1683 ConstructProbeReq(
1684 padapter,
1685 &ReservedPagePacket[BufIndex],
1686 &ProbeReqLength);
1687
1688 rtl8723b_fill_fake_txdesc(padapter,
1689 &ReservedPagePacket[BufIndex-TxDescLen],
1690 ProbeReqLength, false, false, false);
1691 #ifdef CONFIG_PNO_SET_DEBUG
1692 {
1693 int gj;
1694 printk("probe req pkt =>\n");
1695 for (gj = 0; gj < ProbeReqLength+TxDescLen; gj++) {
1696 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1697 if ((gj+1)%8 == 0)
1698 printk("\n");
1699 }
1700 printk(" <=end\n");
1701 }
1702 #endif
1703 CurtPktPageNum =
1704 (u8)PageNum_128(TxDescLen + ProbeReqLength);
1705
1706 TotalPageNum += CurtPktPageNum;
1707
1708 BufIndex += (CurtPktPageNum*PageSize);
1709
1710 /* PNO INFO Page */
1711 RsvdPageLoc.LocPNOInfo = TotalPageNum;
1712 ConstructPnoInfo(padapter, &ReservedPagePacket[BufIndex-TxDescLen], &PNOLength);
1713 #ifdef CONFIG_PNO_SET_DEBUG
1714 {
1715 int gj;
1716 printk("PNO pkt =>\n");
1717 for (gj = 0; gj < PNOLength; gj++) {
1718 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1719 if ((gj + 1)%8 == 0)
1720 printk("\n");
1721 }
1722 printk(" <=end\n");
1723 }
1724 #endif
1725
1726 CurtPktPageNum = (u8)PageNum_128(PNOLength);
1727 TotalPageNum += CurtPktPageNum;
1728 BufIndex += (CurtPktPageNum*PageSize);
1729
1730 /* SSID List Page */
1731 RsvdPageLoc.LocSSIDInfo = TotalPageNum;
1732 ConstructSSIDList(padapter, &ReservedPagePacket[BufIndex-TxDescLen], &SSIDLegnth);
1733 #ifdef CONFIG_PNO_SET_DEBUG
1734 {
1735 int gj;
1736 printk("SSID list pkt =>\n");
1737 for (gj = 0; gj < SSIDLegnth; gj++) {
1738 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1739 if ((gj + 1)%8 == 0)
1740 printk("\n");
1741 }
1742 printk(" <=end\n");
1743 }
1744 #endif
1745 CurtPktPageNum = (u8)PageNum_128(SSIDLegnth);
1746 TotalPageNum += CurtPktPageNum;
1747 BufIndex += (CurtPktPageNum*PageSize);
1748
1749 /* Scan Info Page */
1750 RsvdPageLoc.LocScanInfo = TotalPageNum;
1751 ConstructScanInfo(padapter, &ReservedPagePacket[BufIndex-TxDescLen], &ScanInfoLength);
1752 #ifdef CONFIG_PNO_SET_DEBUG
1753 {
1754 int gj;
1755 printk("Scan info pkt =>\n");
1756 for (gj = 0; gj < ScanInfoLength; gj++) {
1757 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1758 if ((gj + 1)%8 == 0)
1759 printk("\n");
1760 }
1761 printk(" <=end\n");
1762 }
1763 #endif
1764 CurtPktPageNum = (u8)PageNum_128(ScanInfoLength);
1765 TotalPageNum += CurtPktPageNum;
1766 BufIndex += (CurtPktPageNum*PageSize);
1767
1768 TotalPacketLen = BufIndex + ScanInfoLength;
1769 } else {
1770 TotalPacketLen = BufIndex + BTQosNullLength;
1771 }
1772 #else /* CONFIG_PNO_SUPPORT */
1773 TotalPacketLen = BufIndex + BTQosNullLength;
1774 #endif
1775 }
1776
1777 if (TotalPacketLen > MaxRsvdPageBufSize) {
1778 DBG_871X("%s(): ERROR: The rsvd page size is not enough!!TotalPacketLen %d, MaxRsvdPageBufSize %d\n", __func__,
1779 TotalPacketLen, MaxRsvdPageBufSize);
1780 goto error;
1781 } else {
1782 /* update attribute */
1783 pattrib = &pcmdframe->attrib;
1784 update_mgntframe_attrib(padapter, pattrib);
1785 pattrib->qsel = 0x10;
1786 pattrib->pktlen = pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset;
1787 dump_mgntframe_and_wait(padapter, pcmdframe, 100);
1788 }
1789
1790 DBG_871X("%s: Set RSVD page location to Fw , TotalPacketLen(%d), TotalPageNum(%d)\n", __func__, TotalPacketLen, TotalPageNum);
1791 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1792 rtl8723b_set_FwRsvdPage_cmd(padapter, &RsvdPageLoc);
1793 rtl8723b_set_FwAoacRsvdPage_cmd(padapter, &RsvdPageLoc);
1794 } else {
1795 rtl8723b_set_FwAoacRsvdPage_cmd(padapter, &RsvdPageLoc);
1796 #ifdef CONFIG_PNO_SUPPORT
1797 if (pwrctl->pno_in_resume)
1798 rtl8723b_set_FwScanOffloadInfo_cmd(padapter,
1799 &RsvdPageLoc, 0);
1800 else
1801 rtl8723b_set_FwScanOffloadInfo_cmd(padapter,
1802 &RsvdPageLoc, 1);
1803 #endif
1804 }
1805 return;
1806
1807 error:
1808
1809 rtw_free_xmitframe(pxmitpriv, pcmdframe);
1810 }
1811
1812 #ifdef CONFIG_AP_WOWLAN
1813 /* */
1814 /* Description: Fill the reserved packets that FW will use to RSVD page. */
1815 /* Now we just send 2 types packet to rsvd page. (1)Beacon, (2)ProbeRsp. */
1816 /* */
1817 /* Input: bDLFinished */
1818 /* */
1819 /* false: At the first time we will send all the packets as a large packet to Hw, */
1820 /* so we need to set the packet length to total lengh. */
1821 /* */
1822 /* true: At the second time, we should send the first packet (default:beacon) */
1823 /* to Hw again and set the lengh in descriptor to the real beacon lengh. */
1824 /* 2009.10.15 by tynli. */
rtl8723b_set_AP_FwRsvdPagePkt(struct adapter * padapter,bool bDLFinished)1825 static void rtl8723b_set_AP_FwRsvdPagePkt(
1826 struct adapter *padapter, bool bDLFinished
1827 )
1828 {
1829 struct hal_com_data *pHalData;
1830 struct xmit_frame *pcmdframe;
1831 struct pkt_attrib *pattrib;
1832 struct xmit_priv *pxmitpriv;
1833 struct mlme_ext_priv *pmlmeext;
1834 struct mlme_ext_info *pmlmeinfo;
1835 struct pwrctrl_priv *pwrctl;
1836 u32 BeaconLength = 0, ProbeRspLength = 0;
1837 u8 *ReservedPagePacket;
1838 u8 TxDescLen = TXDESC_SIZE, TxDescOffset = TXDESC_OFFSET;
1839 u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0;
1840 u8 currentip[4];
1841 u16 BufIndex, PageSize = 128;
1842 u32 TotalPacketLen = 0, MaxRsvdPageBufSize = 0;
1843 RSVDPAGE_LOC RsvdPageLoc;
1844
1845 /* DBG_871X("%s---->\n", __func__); */
1846 DBG_8192C("+" FUNC_ADPT_FMT ": iface_type =%d\n",
1847 FUNC_ADPT_ARG(padapter), get_iface_type(padapter));
1848
1849 pHalData = GET_HAL_DATA(padapter);
1850 pxmitpriv = &padapter->xmitpriv;
1851 pmlmeext = &padapter->mlmeextpriv;
1852 pmlmeinfo = &pmlmeext->mlmext_info;
1853 pwrctl = adapter_to_pwrctl(padapter);
1854
1855 RsvdPageNum = BCNQ_PAGE_NUM_8723B + AP_WOWLAN_PAGE_NUM_8723B;
1856 MaxRsvdPageBufSize = RsvdPageNum*PageSize;
1857
1858 pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv);
1859 if (pcmdframe == NULL) {
1860 DBG_871X("%s: alloc ReservedPagePacket fail!\n", __func__);
1861 return;
1862 }
1863
1864 ReservedPagePacket = pcmdframe->buf_addr;
1865 memset(&RsvdPageLoc, 0, sizeof(RSVDPAGE_LOC));
1866
1867 /* 3 (1) beacon */
1868 BufIndex = TxDescOffset;
1869 ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength);
1870
1871 /* When we count the first page size, we need to reserve description size for the RSVD */
1872 /* packet, it will be filled in front of the packet in TXPKTBUF. */
1873 CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength);
1874 /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */
1875 if (CurtPktPageNum == 1)
1876 CurtPktPageNum += 1;
1877 TotalPageNum += CurtPktPageNum;
1878
1879 BufIndex += (CurtPktPageNum*PageSize);
1880
1881 /* 2 (4) probe response */
1882 RsvdPageLoc.LocProbeRsp = TotalPageNum;
1883
1884 rtw_get_current_ip_address(padapter, currentip);
1885
1886 ConstructProbeRsp(
1887 padapter,
1888 &ReservedPagePacket[BufIndex],
1889 &ProbeRspLength,
1890 currentip,
1891 false);
1892 rtl8723b_fill_fake_txdesc(padapter,
1893 &ReservedPagePacket[BufIndex-TxDescLen],
1894 ProbeRspLength,
1895 false, false, false);
1896
1897 DBG_871X("%s(): HW_VAR_SET_TX_CMD: PROBE RSP %p %d\n",
1898 __func__, &ReservedPagePacket[BufIndex-TxDescLen],
1899 (ProbeRspLength+TxDescLen));
1900
1901 CurtPktPageNum = (u8)PageNum_128(TxDescLen + ProbeRspLength);
1902
1903 TotalPageNum += CurtPktPageNum;
1904
1905 BufIndex += (CurtPktPageNum*PageSize);
1906
1907 TotalPacketLen = BufIndex + ProbeRspLength;
1908
1909 if (TotalPacketLen > MaxRsvdPageBufSize) {
1910 DBG_871X("%s(): ERROR: The rsvd page size is not enough \
1911 !!TotalPacketLen %d, MaxRsvdPageBufSize %d\n",
1912 __func__, TotalPacketLen, MaxRsvdPageBufSize);
1913 goto error;
1914 } else {
1915 /* update attribute */
1916 pattrib = &pcmdframe->attrib;
1917 update_mgntframe_attrib(padapter, pattrib);
1918 pattrib->qsel = 0x10;
1919 pattrib->pktlen = TotalPacketLen - TxDescOffset;
1920 pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset;
1921 dump_mgntframe_and_wait(padapter, pcmdframe, 100);
1922 }
1923
1924 DBG_871X("%s: Set RSVD page location to Fw , TotalPacketLen(%d), TotalPageNum(%d)\n", __func__, TotalPacketLen, TotalPageNum);
1925 rtl8723b_set_ap_wow_rsvdpage_cmd(padapter, &RsvdPageLoc);
1926
1927 return;
1928 error:
1929 rtw_free_xmitframe(pxmitpriv, pcmdframe);
1930 }
1931 #endif /* CONFIG_AP_WOWLAN */
1932
rtl8723b_download_rsvd_page(struct adapter * padapter,u8 mstatus)1933 void rtl8723b_download_rsvd_page(struct adapter *padapter, u8 mstatus)
1934 {
1935 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
1936 #ifdef CONFIG_AP_WOWLAN
1937 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1938 #endif
1939 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1940 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1941 bool bcn_valid = false;
1942 u8 DLBcnCount = 0;
1943 u32 poll = 0;
1944 u8 val8;
1945
1946 DBG_8192C("+" FUNC_ADPT_FMT ": iface_type =%d mstatus(%x)\n",
1947 FUNC_ADPT_ARG(padapter), get_iface_type(padapter), mstatus);
1948
1949 if (mstatus == RT_MEDIA_CONNECT) {
1950 bool bRecover = false;
1951 u8 v8;
1952
1953 /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */
1954 /* Suggested by filen. Added by tynli. */
1955 rtw_write16(padapter, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid));
1956
1957 /* set REG_CR bit 8 */
1958 v8 = rtw_read8(padapter, REG_CR+1);
1959 v8 |= BIT(0); /* ENSWBCN */
1960 rtw_write8(padapter, REG_CR+1, v8);
1961
1962 /* Disable Hw protection for a time which revserd for Hw sending beacon. */
1963 /* Fix download reserved page packet fail that access collision with the protection time. */
1964 /* 2010.05.11. Added by tynli. */
1965 val8 = rtw_read8(padapter, REG_BCN_CTRL);
1966 val8 &= ~EN_BCN_FUNCTION;
1967 val8 |= DIS_TSF_UDT;
1968 rtw_write8(padapter, REG_BCN_CTRL, val8);
1969
1970 /* Set FWHW_TXQ_CTRL 0x422[6]= 0 to tell Hw the packet is not a real beacon frame. */
1971 if (pHalData->RegFwHwTxQCtrl & BIT(6))
1972 bRecover = true;
1973
1974 /* To tell Hw the packet is not a real beacon frame. */
1975 rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl & ~BIT(6));
1976 pHalData->RegFwHwTxQCtrl &= ~BIT(6);
1977
1978 /* Clear beacon valid check bit. */
1979 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
1980 rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
1981
1982 DLBcnCount = 0;
1983 poll = 0;
1984 do {
1985 #ifdef CONFIG_AP_WOWLAN
1986 if (pwrpriv->wowlan_ap_mode)
1987 rtl8723b_set_AP_FwRsvdPagePkt(padapter, 0);
1988 else
1989 rtl8723b_set_FwRsvdPagePkt(padapter, 0);
1990 #else
1991 /* download rsvd page. */
1992 rtl8723b_set_FwRsvdPagePkt(padapter, 0);
1993 #endif
1994 DLBcnCount++;
1995 do {
1996 yield();
1997 /* mdelay(10); */
1998 /* check rsvd page download OK. */
1999 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid));
2000 poll++;
2001 } while (!bcn_valid && (poll%10) != 0 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
2002
2003 } while (!bcn_valid && DLBcnCount <= 100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
2004
2005 if (padapter->bSurpriseRemoved || padapter->bDriverStopped) {
2006 } else if (!bcn_valid)
2007 DBG_871X(ADPT_FMT": 1 DL RSVD page failed! DLBcnCount:%u, poll:%u\n",
2008 ADPT_ARG(padapter), DLBcnCount, poll);
2009 else {
2010 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
2011 pwrctl->fw_psmode_iface_id = padapter->iface_id;
2012 DBG_871X(ADPT_FMT": 1 DL RSVD page success! DLBcnCount:%u, poll:%u\n",
2013 ADPT_ARG(padapter), DLBcnCount, poll);
2014 }
2015
2016 /* 2010.05.11. Added by tynli. */
2017 val8 = rtw_read8(padapter, REG_BCN_CTRL);
2018 val8 |= EN_BCN_FUNCTION;
2019 val8 &= ~DIS_TSF_UDT;
2020 rtw_write8(padapter, REG_BCN_CTRL, val8);
2021
2022 /* To make sure that if there exists an adapter which would like to send beacon. */
2023 /* If exists, the origianl value of 0x422[6] will be 1, we should check this to */
2024 /* prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */
2025 /* the beacon cannot be sent by HW. */
2026 /* 2010.06.23. Added by tynli. */
2027 if (bRecover) {
2028 rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl | BIT(6));
2029 pHalData->RegFwHwTxQCtrl |= BIT(6);
2030 }
2031
2032 /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */
2033 v8 = rtw_read8(padapter, REG_CR+1);
2034 v8 &= ~BIT(0); /* ~ENSWBCN */
2035 rtw_write8(padapter, REG_CR+1, v8);
2036 }
2037 }
2038
rtl8723b_set_rssi_cmd(struct adapter * padapter,u8 * param)2039 void rtl8723b_set_rssi_cmd(struct adapter *padapter, u8 *param)
2040 {
2041 rtl8723b_set_FwRssiSetting_cmd(padapter, param);
2042 }
2043
rtl8723b_set_FwJoinBssRpt_cmd(struct adapter * padapter,u8 mstatus)2044 void rtl8723b_set_FwJoinBssRpt_cmd(struct adapter *padapter, u8 mstatus)
2045 {
2046 if (mstatus == 1)
2047 rtl8723b_download_rsvd_page(padapter, RT_MEDIA_CONNECT);
2048 }
2049
2050 /* arg[0] = macid */
2051 /* arg[1] = raid */
2052 /* arg[2] = shortGIrate */
2053 /* arg[3] = init_rate */
rtl8723b_Add_RateATid(struct adapter * padapter,u32 bitmap,u8 * arg,u8 rssi_level)2054 void rtl8723b_Add_RateATid(
2055 struct adapter *padapter,
2056 u32 bitmap,
2057 u8 *arg,
2058 u8 rssi_level
2059 )
2060 {
2061 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
2062 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2063 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2064 struct sta_info *psta;
2065 u8 mac_id = arg[0];
2066 u8 raid = arg[1];
2067 u8 shortGI = arg[2];
2068 u8 bw;
2069 u32 mask = bitmap&0x0FFFFFFF;
2070
2071 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
2072 if (psta == NULL)
2073 return;
2074
2075 bw = psta->bw_mode;
2076
2077 if (rssi_level != DM_RATR_STA_INIT)
2078 mask = ODM_Get_Rate_Bitmap(&pHalData->odmpriv, mac_id, mask, rssi_level);
2079
2080 DBG_871X("%s(): mac_id =%d raid = 0x%x bw =%d mask = 0x%x\n", __func__, mac_id, raid, bw, mask);
2081 rtl8723b_set_FwMacIdConfig_cmd(padapter, mac_id, raid, bw, shortGI, mask);
2082 }
2083
ConstructBtNullFunctionData(struct adapter * padapter,u8 * pframe,u32 * pLength,u8 * StaAddr,u8 bQoS,u8 AC,u8 bEosp,u8 bForcePowerSave)2084 static void ConstructBtNullFunctionData(
2085 struct adapter *padapter,
2086 u8 *pframe,
2087 u32 *pLength,
2088 u8 *StaAddr,
2089 u8 bQoS,
2090 u8 AC,
2091 u8 bEosp,
2092 u8 bForcePowerSave
2093 )
2094 {
2095 struct ieee80211_hdr *pwlanhdr;
2096 __le16 *fctrl;
2097 u32 pktlen;
2098 struct mlme_ext_priv *pmlmeext;
2099 struct mlme_ext_info *pmlmeinfo;
2100 u8 bssid[ETH_ALEN];
2101
2102
2103 DBG_871X("+" FUNC_ADPT_FMT ": qos =%d eosp =%d ps =%d\n",
2104 FUNC_ADPT_ARG(padapter), bQoS, bEosp, bForcePowerSave);
2105
2106 pwlanhdr = (struct ieee80211_hdr *)pframe;
2107 pmlmeext = &padapter->mlmeextpriv;
2108 pmlmeinfo = &pmlmeext->mlmext_info;
2109
2110 if (NULL == StaAddr) {
2111 memcpy(bssid, myid(&padapter->eeprompriv), ETH_ALEN);
2112 StaAddr = bssid;
2113 }
2114
2115 fctrl = &pwlanhdr->frame_control;
2116 *fctrl = 0;
2117 if (bForcePowerSave)
2118 SetPwrMgt(fctrl);
2119
2120 SetFrDs(fctrl);
2121 memcpy(pwlanhdr->addr1, StaAddr, ETH_ALEN);
2122 memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
2123 memcpy(pwlanhdr->addr3, myid(&padapter->eeprompriv), ETH_ALEN);
2124
2125 SetDuration(pwlanhdr, 0);
2126 SetSeqNum(pwlanhdr, 0);
2127
2128 if (bQoS == true) {
2129 struct ieee80211_qos_hdr *pwlanqoshdr;
2130
2131 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
2132
2133 pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe;
2134 SetPriority(&pwlanqoshdr->qos_ctrl, AC);
2135 SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp);
2136
2137 pktlen = sizeof(struct ieee80211_qos_hdr);
2138 } else {
2139 SetFrameSubType(pframe, WIFI_DATA_NULL);
2140
2141 pktlen = sizeof(struct ieee80211_hdr_3addr);
2142 }
2143
2144 *pLength = pktlen;
2145 }
2146
SetFwRsvdPagePkt_BTCoex(struct adapter * padapter)2147 static void SetFwRsvdPagePkt_BTCoex(struct adapter *padapter)
2148 {
2149 struct hal_com_data *pHalData;
2150 struct xmit_frame *pcmdframe;
2151 struct pkt_attrib *pattrib;
2152 struct xmit_priv *pxmitpriv;
2153 struct mlme_ext_priv *pmlmeext;
2154 struct mlme_ext_info *pmlmeinfo;
2155 u32 BeaconLength = 0;
2156 u32 BTQosNullLength = 0;
2157 u8 *ReservedPagePacket;
2158 u8 TxDescLen, TxDescOffset;
2159 u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0;
2160 u16 BufIndex, PageSize;
2161 u32 TotalPacketLen, MaxRsvdPageBufSize = 0;
2162 RSVDPAGE_LOC RsvdPageLoc;
2163
2164
2165 /* DBG_8192C("+" FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(padapter)); */
2166
2167 pHalData = GET_HAL_DATA(padapter);
2168 pxmitpriv = &padapter->xmitpriv;
2169 pmlmeext = &padapter->mlmeextpriv;
2170 pmlmeinfo = &pmlmeext->mlmext_info;
2171 TxDescLen = TXDESC_SIZE;
2172 TxDescOffset = TXDESC_OFFSET;
2173 PageSize = PAGE_SIZE_TX_8723B;
2174
2175 RsvdPageNum = BCNQ_PAGE_NUM_8723B;
2176 MaxRsvdPageBufSize = RsvdPageNum*PageSize;
2177
2178 pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv);
2179 if (pcmdframe == NULL) {
2180 DBG_8192C("%s: alloc ReservedPagePacket fail!\n", __func__);
2181 return;
2182 }
2183
2184 ReservedPagePacket = pcmdframe->buf_addr;
2185 memset(&RsvdPageLoc, 0, sizeof(RSVDPAGE_LOC));
2186
2187 /* 3 (1) beacon */
2188 BufIndex = TxDescOffset;
2189 ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength);
2190
2191 /* When we count the first page size, we need to reserve description size for the RSVD */
2192 /* packet, it will be filled in front of the packet in TXPKTBUF. */
2193 CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength);
2194 /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */
2195 if (CurtPktPageNum == 1)
2196 CurtPktPageNum += 1;
2197 TotalPageNum += CurtPktPageNum;
2198
2199 BufIndex += (CurtPktPageNum*PageSize);
2200
2201 /* Jump to lastest page */
2202 if (BufIndex < (MaxRsvdPageBufSize - PageSize)) {
2203 BufIndex = TxDescOffset + (MaxRsvdPageBufSize - PageSize);
2204 TotalPageNum = BCNQ_PAGE_NUM_8723B - 1;
2205 }
2206
2207 /* 3 (6) BT Qos null data */
2208 RsvdPageLoc.LocBTQosNull = TotalPageNum;
2209 ConstructBtNullFunctionData(
2210 padapter,
2211 &ReservedPagePacket[BufIndex],
2212 &BTQosNullLength,
2213 NULL,
2214 true, 0, 0, false
2215 );
2216 rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], BTQosNullLength, false, true, false);
2217
2218 CurtPktPageNum = (u8)PageNum_128(TxDescLen + BTQosNullLength);
2219
2220 TotalPageNum += CurtPktPageNum;
2221
2222 TotalPacketLen = BufIndex + BTQosNullLength;
2223 if (TotalPacketLen > MaxRsvdPageBufSize) {
2224 DBG_8192C(FUNC_ADPT_FMT ": ERROR: The rsvd page size is not enough!!TotalPacketLen %d, MaxRsvdPageBufSize %d\n",
2225 FUNC_ADPT_ARG(padapter), TotalPacketLen, MaxRsvdPageBufSize);
2226 goto error;
2227 }
2228
2229 /* update attribute */
2230 pattrib = &pcmdframe->attrib;
2231 update_mgntframe_attrib(padapter, pattrib);
2232 pattrib->qsel = 0x10;
2233 pattrib->pktlen = pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset;
2234 dump_mgntframe_and_wait(padapter, pcmdframe, 100);
2235
2236 /* DBG_8192C(FUNC_ADPT_FMT ": Set RSVD page location to Fw, TotalPacketLen(%d), TotalPageNum(%d)\n", */
2237 /* FUNC_ADPT_ARG(padapter), TotalPacketLen, TotalPageNum); */
2238 rtl8723b_set_FwRsvdPage_cmd(padapter, &RsvdPageLoc);
2239 rtl8723b_set_FwAoacRsvdPage_cmd(padapter, &RsvdPageLoc);
2240
2241 return;
2242
2243 error:
2244 rtw_free_xmitframe(pxmitpriv, pcmdframe);
2245 }
2246
rtl8723b_download_BTCoex_AP_mode_rsvd_page(struct adapter * padapter)2247 void rtl8723b_download_BTCoex_AP_mode_rsvd_page(struct adapter *padapter)
2248 {
2249 struct hal_com_data *pHalData;
2250 struct mlme_ext_priv *pmlmeext;
2251 struct mlme_ext_info *pmlmeinfo;
2252 u8 bRecover = false;
2253 u8 bcn_valid = false;
2254 u8 DLBcnCount = 0;
2255 u32 poll = 0;
2256 u8 val8;
2257
2258
2259 DBG_8192C("+" FUNC_ADPT_FMT ": iface_type =%d fw_state = 0x%08X\n",
2260 FUNC_ADPT_ARG(padapter), get_iface_type(padapter), get_fwstate(&padapter->mlmepriv));
2261
2262 #ifdef DEBUG
2263 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == false) {
2264 DBG_8192C(FUNC_ADPT_FMT ": [WARNING] not in AP mode!!\n",
2265 FUNC_ADPT_ARG(padapter));
2266 }
2267 #endif /* DEBUG */
2268
2269 pHalData = GET_HAL_DATA(padapter);
2270 pmlmeext = &padapter->mlmeextpriv;
2271 pmlmeinfo = &pmlmeext->mlmext_info;
2272
2273 /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */
2274 /* Suggested by filen. Added by tynli. */
2275 rtw_write16(padapter, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid));
2276
2277 /* set REG_CR bit 8 */
2278 val8 = rtw_read8(padapter, REG_CR+1);
2279 val8 |= BIT(0); /* ENSWBCN */
2280 rtw_write8(padapter, REG_CR+1, val8);
2281
2282 /* Disable Hw protection for a time which revserd for Hw sending beacon. */
2283 /* Fix download reserved page packet fail that access collision with the protection time. */
2284 /* 2010.05.11. Added by tynli. */
2285 val8 = rtw_read8(padapter, REG_BCN_CTRL);
2286 val8 &= ~EN_BCN_FUNCTION;
2287 val8 |= DIS_TSF_UDT;
2288 rtw_write8(padapter, REG_BCN_CTRL, val8);
2289
2290 /* Set FWHW_TXQ_CTRL 0x422[6]= 0 to tell Hw the packet is not a real beacon frame. */
2291 if (pHalData->RegFwHwTxQCtrl & BIT(6))
2292 bRecover = true;
2293
2294 /* To tell Hw the packet is not a real beacon frame. */
2295 pHalData->RegFwHwTxQCtrl &= ~BIT(6);
2296 rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl);
2297
2298 /* Clear beacon valid check bit. */
2299 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
2300 rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
2301
2302 DLBcnCount = 0;
2303 poll = 0;
2304 do {
2305 SetFwRsvdPagePkt_BTCoex(padapter);
2306 DLBcnCount++;
2307 do {
2308 yield();
2309 /* mdelay(10); */
2310 /* check rsvd page download OK. */
2311 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, &bcn_valid);
2312 poll++;
2313 } while (!bcn_valid && (poll%10) != 0 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
2314 } while (!bcn_valid && (DLBcnCount <= 100) && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
2315
2316 if (true == bcn_valid) {
2317 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
2318 pwrctl->fw_psmode_iface_id = padapter->iface_id;
2319 DBG_8192C(ADPT_FMT": DL RSVD page success! DLBcnCount:%d, poll:%d\n",
2320 ADPT_ARG(padapter), DLBcnCount, poll);
2321 } else {
2322 DBG_8192C(ADPT_FMT": DL RSVD page fail! DLBcnCount:%d, poll:%d\n",
2323 ADPT_ARG(padapter), DLBcnCount, poll);
2324 DBG_8192C(ADPT_FMT": DL RSVD page fail! bSurpriseRemoved =%d\n",
2325 ADPT_ARG(padapter), padapter->bSurpriseRemoved);
2326 DBG_8192C(ADPT_FMT": DL RSVD page fail! bDriverStopped =%d\n",
2327 ADPT_ARG(padapter), padapter->bDriverStopped);
2328 }
2329
2330 /* 2010.05.11. Added by tynli. */
2331 val8 = rtw_read8(padapter, REG_BCN_CTRL);
2332 val8 |= EN_BCN_FUNCTION;
2333 val8 &= ~DIS_TSF_UDT;
2334 rtw_write8(padapter, REG_BCN_CTRL, val8);
2335
2336 /* To make sure that if there exists an adapter which would like to send beacon. */
2337 /* If exists, the origianl value of 0x422[6] will be 1, we should check this to */
2338 /* prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */
2339 /* the beacon cannot be sent by HW. */
2340 /* 2010.06.23. Added by tynli. */
2341 if (bRecover) {
2342 pHalData->RegFwHwTxQCtrl |= BIT(6);
2343 rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl);
2344 }
2345
2346 /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */
2347 val8 = rtw_read8(padapter, REG_CR+1);
2348 val8 &= ~BIT(0); /* ~ENSWBCN */
2349 rtw_write8(padapter, REG_CR+1, val8);
2350 }
2351