root/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _is_fw_read_cmd_down
  2. FillH2CCmd8723B
  3. ConstructBeacon
  4. ConstructPSPoll
  5. ConstructNullFunctionData
  6. ConstructARPResponse
  7. ConstructPnoInfo
  8. ConstructSSIDList
  9. ConstructScanInfo
  10. ConstructGTKResponse
  11. ConstructProbeReq
  12. ConstructProbeRsp
  13. CheckFwRsvdPageContent
  14. rtl8723b_set_FwRsvdPage_cmd
  15. rtl8723b_set_FwAoacRsvdPage_cmd
  16. rtl8723b_set_ap_wow_rsvdpage_cmd
  17. rtl8723b_set_FwMediaStatusRpt_cmd
  18. rtl8723b_set_FwKeepAlive_cmd
  19. rtl8723b_set_FwDisconDecision_cmd
  20. rtl8723b_set_FwMacIdConfig_cmd
  21. rtl8723b_set_rssi_cmd
  22. rtl8723b_set_FwPwrMode_cmd
  23. rtl8723b_set_FwPsTuneParam_cmd
  24. rtl8723b_set_FwPwrModeInIPS_cmd
  25. rtl8723b_set_FwWoWlanCtrl_Cmd
  26. rtl8723b_set_FwRemoteWakeCtrl_Cmd
  27. rtl8723b_set_FwAOACGlobalInfo_Cmd
  28. rtl8723b_set_FwScanOffloadInfo_cmd
  29. rtl8723b_set_wowlan_cmd
  30. rtl8723b_set_FwAPWoWlanCtrl_Cmd
  31. rtl8723b_set_Fw_AP_Offload_Cmd
  32. rtl8723b_set_ap_wowlan_cmd
  33. rtl8723b_set_FwRsvdPagePkt
  34. rtl8723b_set_AP_FwRsvdPagePkt
  35. rtl8723b_download_rsvd_page
  36. rtl8723b_set_FwJoinBssRpt_cmd
  37. rtl8723b_Add_RateATid
  38. ConstructBtNullFunctionData
  39. SetFwRsvdPagePkt_BTCoex
  40. rtl8723b_download_BTCoex_AP_mode_rsvd_page

   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 
  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 ******************************************/
  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)
  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 
 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 
 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 
 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) {
 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 /*  */
 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) {
 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
 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 
 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 
 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
 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
 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         int bssrate_len = 0;
 678         u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 679 
 680         pwlanhdr = (struct ieee80211_hdr *)pframe;
 681         mac = myid(&(padapter->eeprompriv));
 682 
 683         fctrl = &(pwlanhdr->frame_control);
 684         *(fctrl) = 0;
 685 
 686         /* broadcast probe request frame */
 687         memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
 688         memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
 689 
 690         memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
 691 
 692         SetSeqNum(pwlanhdr, 0);
 693         SetFrameSubType(pframe, WIFI_PROBEREQ);
 694 
 695         pktlen = sizeof(struct ieee80211_hdr_3addr);
 696         pframe += pktlen;
 697 
 698         pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &pktlen);
 699 
 700         get_rate_set(padapter, bssrate, &bssrate_len);
 701 
 702         if (bssrate_len > 8) {
 703                 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, bssrate, &pktlen);
 704                 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (bssrate_len - 8), (bssrate + 8), &pktlen);
 705         } else
 706                 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, bssrate_len, bssrate, &pktlen);
 707 
 708         *pLength = pktlen;
 709 }
 710 #endif /* CONFIG_PNO_SUPPORT */
 711 #endif /* CONFIG_WOWLAN */
 712 
 713 #ifdef CONFIG_AP_WOWLAN
 714 static void ConstructProbeRsp(struct adapter *padapter, u8 *pframe, u32 *pLength, u8 *StaAddr, bool bHideSSID)
 715 {
 716         struct ieee80211_hdr *pwlanhdr;
 717         u16 *fctrl;
 718         u8 *mac, *bssid;
 719         u32 pktlen;
 720         struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
 721         struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
 722         struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
 723         u8 *pwps_ie;
 724         uint wps_ielen;
 725         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 726 
 727         /* DBG_871X("%s\n", __func__); */
 728 
 729         pwlanhdr = (struct ieee80211_hdr *)pframe;
 730 
 731         mac = myid(&(padapter->eeprompriv));
 732         bssid = cur_network->MacAddress;
 733 
 734         fctrl = &(pwlanhdr->frame_control);
 735         *(fctrl) = 0;
 736         memcpy(pwlanhdr->addr1, StaAddr, ETH_ALEN);
 737         memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
 738         memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
 739 
 740         DBG_871X("%s FW Mac Addr:" MAC_FMT "\n", __func__, MAC_ARG(mac));
 741         DBG_871X("%s FW IP Addr" IP_FMT "\n", __func__, IP_ARG(StaAddr));
 742 
 743         SetSeqNum(pwlanhdr, 0);
 744         SetFrameSubType(fctrl, WIFI_PROBERSP);
 745 
 746         pktlen = sizeof(struct ieee80211_hdr_3addr);
 747         pframe += pktlen;
 748 
 749         if (cur_network->IELength > MAX_IE_SZ)
 750                 return;
 751 
 752         pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_,
 753                         cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
 754 
 755         /* inerset & update wps_probe_resp_ie */
 756         if (pmlmepriv->wps_probe_resp_ie && pwps_ie && (wps_ielen > 0)) {
 757                 uint wps_offset, remainder_ielen;
 758                 u8 *premainder_ie;
 759 
 760                 wps_offset = (uint)(pwps_ie - cur_network->IEs);
 761 
 762                 premainder_ie = pwps_ie + wps_ielen;
 763 
 764                 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
 765 
 766                 memcpy(pframe, cur_network->IEs, wps_offset);
 767                 pframe += wps_offset;
 768                 pktlen += wps_offset;
 769 
 770                 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
 771                 if ((wps_offset+wps_ielen+2) <= MAX_IE_SZ) {
 772                         memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
 773                         pframe += wps_ielen+2;
 774                         pktlen += wps_ielen+2;
 775                 }
 776 
 777                 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
 778                         memcpy(pframe, premainder_ie, remainder_ielen);
 779                         pframe += remainder_ielen;
 780                         pktlen += remainder_ielen;
 781                 }
 782         } else {
 783                 memcpy(pframe, cur_network->IEs, cur_network->IELength);
 784                 pframe += cur_network->IELength;
 785                 pktlen += cur_network->IELength;
 786         }
 787 
 788         /* retrieve SSID IE from cur_network->Ssid */
 789         {
 790                 u8 *ssid_ie;
 791                 sint ssid_ielen;
 792                 sint ssid_ielen_diff;
 793                 u8 buf[MAX_IE_SZ];
 794                 u8 *ies = pframe + sizeof(struct ieee80211_hdr_3addr);
 795 
 796                 ssid_ie = rtw_get_ie(ies+_FIXED_IE_LENGTH_, _SSID_IE_, &ssid_ielen,
 797                                         (pframe-ies)-_FIXED_IE_LENGTH_);
 798 
 799                 ssid_ielen_diff = cur_network->Ssid.SsidLength - ssid_ielen;
 800 
 801                 if (ssid_ie &&  cur_network->Ssid.SsidLength) {
 802                         uint remainder_ielen;
 803                         u8 *remainder_ie;
 804                         remainder_ie = ssid_ie+2;
 805                         remainder_ielen = (pframe-remainder_ie);
 806 
 807                         if (remainder_ielen > MAX_IE_SZ) {
 808                                 DBG_871X_LEVEL(_drv_warning_, FUNC_ADPT_FMT" remainder_ielen > MAX_IE_SZ\n", FUNC_ADPT_ARG(padapter));
 809                                 remainder_ielen = MAX_IE_SZ;
 810                         }
 811 
 812                         memcpy(buf, remainder_ie, remainder_ielen);
 813                         memcpy(remainder_ie+ssid_ielen_diff, buf, remainder_ielen);
 814                         *(ssid_ie+1) = cur_network->Ssid.SsidLength;
 815                         memcpy(ssid_ie+2, cur_network->Ssid.Ssid, cur_network->Ssid.SsidLength);
 816                         pframe += ssid_ielen_diff;
 817                         pktlen += ssid_ielen_diff;
 818                 }
 819         }
 820 
 821         *pLength = pktlen;
 822 
 823 }
 824 #endif /*  CONFIG_AP_WOWLAN */
 825 
 826 /*  To check if reserved page content is destroyed by beacon beacuse beacon is too large. */
 827 /*  2010.06.23. Added by tynli. */
 828 void CheckFwRsvdPageContent(struct adapter *Adapter)
 829 {
 830 }
 831 
 832 static void rtl8723b_set_FwRsvdPage_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc)
 833 {
 834         u8 u1H2CRsvdPageParm[H2C_RSVDPAGE_LOC_LEN] = {0};
 835 
 836         DBG_871X("8723BRsvdPageLoc: ProbeRsp =%d PsPoll =%d Null =%d QoSNull =%d BTNull =%d\n",
 837                 rsvdpageloc->LocProbeRsp, rsvdpageloc->LocPsPoll,
 838                 rsvdpageloc->LocNullData, rsvdpageloc->LocQosNull,
 839                 rsvdpageloc->LocBTQosNull);
 840 
 841         SET_8723B_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1H2CRsvdPageParm, rsvdpageloc->LocProbeRsp);
 842         SET_8723B_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1H2CRsvdPageParm, rsvdpageloc->LocPsPoll);
 843         SET_8723B_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocNullData);
 844         SET_8723B_H2CCMD_RSVDPAGE_LOC_QOS_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocQosNull);
 845         SET_8723B_H2CCMD_RSVDPAGE_LOC_BT_QOS_NULL_DATA(u1H2CRsvdPageParm, rsvdpageloc->LocBTQosNull);
 846 
 847         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CRsvdPageParm:", u1H2CRsvdPageParm, H2C_RSVDPAGE_LOC_LEN);
 848         FillH2CCmd8723B(padapter, H2C_8723B_RSVD_PAGE, H2C_RSVDPAGE_LOC_LEN, u1H2CRsvdPageParm);
 849 }
 850 
 851 static void rtl8723b_set_FwAoacRsvdPage_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc)
 852 {
 853 #ifdef CONFIG_WOWLAN
 854         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 855         u8 u1H2CAoacRsvdPageParm[H2C_AOAC_RSVDPAGE_LOC_LEN] = {0};
 856 
 857         DBG_871X("8723BAOACRsvdPageLoc: RWC =%d ArpRsp =%d NbrAdv =%d GtkRsp =%d GtkInfo =%d ProbeReq =%d NetworkList =%d\n",
 858                         rsvdpageloc->LocRemoteCtrlInfo, rsvdpageloc->LocArpRsp,
 859                         rsvdpageloc->LocNbrAdv, rsvdpageloc->LocGTKRsp,
 860                         rsvdpageloc->LocGTKInfo, rsvdpageloc->LocProbeReq,
 861                         rsvdpageloc->LocNetList);
 862 
 863         if (check_fwstate(pmlmepriv, _FW_LINKED)) {
 864                 SET_H2CCMD_AOAC_RSVDPAGE_LOC_REMOTE_WAKE_CTRL_INFO(u1H2CAoacRsvdPageParm, rsvdpageloc->LocRemoteCtrlInfo);
 865                 SET_H2CCMD_AOAC_RSVDPAGE_LOC_ARP_RSP(u1H2CAoacRsvdPageParm, rsvdpageloc->LocArpRsp);
 866                 /* SET_H2CCMD_AOAC_RSVDPAGE_LOC_NEIGHBOR_ADV(u1H2CAoacRsvdPageParm, rsvdpageloc->LocNbrAdv); */
 867                 SET_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_RSP(u1H2CAoacRsvdPageParm, rsvdpageloc->LocGTKRsp);
 868                 SET_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_INFO(u1H2CAoacRsvdPageParm, rsvdpageloc->LocGTKInfo);
 869 #ifdef CONFIG_GTK_OL
 870                 SET_H2CCMD_AOAC_RSVDPAGE_LOC_GTK_EXT_MEM(u1H2CAoacRsvdPageParm, rsvdpageloc->LocGTKEXTMEM);
 871 #endif /*  CONFIG_GTK_OL */
 872                 RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CAoacRsvdPageParm:", u1H2CAoacRsvdPageParm, H2C_AOAC_RSVDPAGE_LOC_LEN);
 873                 FillH2CCmd8723B(padapter, H2C_8723B_AOAC_RSVD_PAGE, H2C_AOAC_RSVDPAGE_LOC_LEN, u1H2CAoacRsvdPageParm);
 874         } else {
 875 #ifdef CONFIG_PNO_SUPPORT
 876                 if (!pwrpriv->pno_in_resume) {
 877                         DBG_871X("NLO_INFO =%d\n", rsvdpageloc->LocPNOInfo);
 878                         memset(&u1H2CAoacRsvdPageParm, 0, sizeof(u1H2CAoacRsvdPageParm));
 879                         SET_H2CCMD_AOAC_RSVDPAGE_LOC_NLO_INFO(u1H2CAoacRsvdPageParm, rsvdpageloc->LocPNOInfo);
 880                         FillH2CCmd8723B(padapter, H2C_AOAC_RSVDPAGE3, H2C_AOAC_RSVDPAGE_LOC_LEN, u1H2CAoacRsvdPageParm);
 881                         msleep(10);
 882                 }
 883 #endif
 884         }
 885 
 886 #endif /*  CONFIG_WOWLAN */
 887 }
 888 
 889 #ifdef CONFIG_AP_WOWLAN
 890 static void rtl8723b_set_ap_wow_rsvdpage_cmd(
 891         struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc
 892 )
 893 {
 894         u8 header;
 895         u8 rsvdparm[H2C_AOAC_RSVDPAGE_LOC_LEN] = {0};
 896 
 897         header = rtw_read8(padapter, REG_BCNQ_BDNY);
 898 
 899         DBG_871X("%s: beacon: %d, probeRsp: %d, header:0x%02x\n", __func__,
 900                         rsvdpageloc->LocApOffloadBCN,
 901                         rsvdpageloc->LocProbeRsp,
 902                         header);
 903 
 904         SET_H2CCMD_AP_WOWLAN_RSVDPAGE_LOC_BCN(rsvdparm,
 905                         rsvdpageloc->LocApOffloadBCN + header);
 906 
 907         FillH2CCmd8723B(padapter, H2C_8723B_BCN_RSVDPAGE,
 908                         H2C_BCN_RSVDPAGE_LEN, rsvdparm);
 909 
 910         msleep(10);
 911 
 912         memset(&rsvdparm, 0, sizeof(rsvdparm));
 913 
 914         SET_H2CCMD_AP_WOWLAN_RSVDPAGE_LOC_ProbeRsp(
 915                         rsvdparm,
 916                         rsvdpageloc->LocProbeRsp + header);
 917 
 918         FillH2CCmd8723B(padapter, H2C_8723B_PROBERSP_RSVDPAGE,
 919                         H2C_PROBERSP_RSVDPAGE_LEN, rsvdparm);
 920 
 921         msleep(10);
 922 }
 923 #endif /* CONFIG_AP_WOWLAN */
 924 
 925 void rtl8723b_set_FwMediaStatusRpt_cmd(struct adapter *padapter, u8 mstatus, u8 macid)
 926 {
 927         u8 u1H2CMediaStatusRptParm[H2C_MEDIA_STATUS_RPT_LEN] = {0};
 928         u8 macid_end = 0;
 929 
 930         DBG_871X("%s(): mstatus = %d macid =%d\n", __func__, mstatus, macid);
 931 
 932         SET_8723B_H2CCMD_MSRRPT_PARM_OPMODE(u1H2CMediaStatusRptParm, mstatus);
 933         SET_8723B_H2CCMD_MSRRPT_PARM_MACID_IND(u1H2CMediaStatusRptParm, 0);
 934         SET_8723B_H2CCMD_MSRRPT_PARM_MACID(u1H2CMediaStatusRptParm, macid);
 935         SET_8723B_H2CCMD_MSRRPT_PARM_MACID_END(u1H2CMediaStatusRptParm, macid_end);
 936 
 937         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CMediaStatusRptParm:", u1H2CMediaStatusRptParm, H2C_MEDIA_STATUS_RPT_LEN);
 938         FillH2CCmd8723B(padapter, H2C_8723B_MEDIA_STATUS_RPT, H2C_MEDIA_STATUS_RPT_LEN, u1H2CMediaStatusRptParm);
 939 }
 940 
 941 #ifdef CONFIG_WOWLAN
 942 static void rtl8723b_set_FwKeepAlive_cmd(struct adapter *padapter, u8 benable, u8 pkt_type)
 943 {
 944         u8 u1H2CKeepAliveParm[H2C_KEEP_ALIVE_CTRL_LEN] = {0};
 945         u8 adopt = 1, check_period = 5;
 946 
 947         DBG_871X("%s(): benable = %d\n", __func__, benable);
 948         SET_8723B_H2CCMD_KEEPALIVE_PARM_ENABLE(u1H2CKeepAliveParm, benable);
 949         SET_8723B_H2CCMD_KEEPALIVE_PARM_ADOPT(u1H2CKeepAliveParm, adopt);
 950         SET_8723B_H2CCMD_KEEPALIVE_PARM_PKT_TYPE(u1H2CKeepAliveParm, pkt_type);
 951         SET_8723B_H2CCMD_KEEPALIVE_PARM_CHECK_PERIOD(u1H2CKeepAliveParm, check_period);
 952 
 953         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CKeepAliveParm:", u1H2CKeepAliveParm, H2C_KEEP_ALIVE_CTRL_LEN);
 954 
 955         FillH2CCmd8723B(padapter, H2C_8723B_KEEP_ALIVE, H2C_KEEP_ALIVE_CTRL_LEN, u1H2CKeepAliveParm);
 956 }
 957 
 958 static void rtl8723b_set_FwDisconDecision_cmd(struct adapter *padapter, u8 benable)
 959 {
 960         u8 u1H2CDisconDecisionParm[H2C_DISCON_DECISION_LEN] = {0};
 961         u8 adopt = 1, check_period = 10, trypkt_num = 0;
 962 
 963         DBG_871X("%s(): benable = %d\n", __func__, benable);
 964         SET_8723B_H2CCMD_DISCONDECISION_PARM_ENABLE(u1H2CDisconDecisionParm, benable);
 965         SET_8723B_H2CCMD_DISCONDECISION_PARM_ADOPT(u1H2CDisconDecisionParm, adopt);
 966         SET_8723B_H2CCMD_DISCONDECISION_PARM_CHECK_PERIOD(u1H2CDisconDecisionParm, check_period);
 967         SET_8723B_H2CCMD_DISCONDECISION_PARM_TRY_PKT_NUM(u1H2CDisconDecisionParm, trypkt_num);
 968 
 969         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CDisconDecisionParm:", u1H2CDisconDecisionParm, H2C_DISCON_DECISION_LEN);
 970 
 971         FillH2CCmd8723B(padapter, H2C_8723B_DISCON_DECISION, H2C_DISCON_DECISION_LEN, u1H2CDisconDecisionParm);
 972 }
 973 #endif /*  CONFIG_WOWLAN */
 974 
 975 void rtl8723b_set_FwMacIdConfig_cmd(struct adapter *padapter, u8 mac_id, u8 raid, u8 bw, u8 sgi, u32 mask)
 976 {
 977         u8 u1H2CMacIdConfigParm[H2C_MACID_CFG_LEN] = {0};
 978 
 979         DBG_871X("%s(): mac_id =%d raid = 0x%x bw =%d mask = 0x%x\n", __func__, mac_id, raid, bw, mask);
 980 
 981         SET_8723B_H2CCMD_MACID_CFG_MACID(u1H2CMacIdConfigParm, mac_id);
 982         SET_8723B_H2CCMD_MACID_CFG_RAID(u1H2CMacIdConfigParm, raid);
 983         SET_8723B_H2CCMD_MACID_CFG_SGI_EN(u1H2CMacIdConfigParm, sgi ? 1 : 0);
 984         SET_8723B_H2CCMD_MACID_CFG_BW(u1H2CMacIdConfigParm, bw);
 985         SET_8723B_H2CCMD_MACID_CFG_RATE_MASK0(u1H2CMacIdConfigParm, (u8)(mask & 0x000000ff));
 986         SET_8723B_H2CCMD_MACID_CFG_RATE_MASK1(u1H2CMacIdConfigParm, (u8)((mask & 0x0000ff00) >> 8));
 987         SET_8723B_H2CCMD_MACID_CFG_RATE_MASK2(u1H2CMacIdConfigParm, (u8)((mask & 0x00ff0000) >> 16));
 988         SET_8723B_H2CCMD_MACID_CFG_RATE_MASK3(u1H2CMacIdConfigParm, (u8)((mask & 0xff000000) >> 24));
 989 
 990         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CMacIdConfigParm:", u1H2CMacIdConfigParm, H2C_MACID_CFG_LEN);
 991         FillH2CCmd8723B(padapter, H2C_8723B_MACID_CFG, H2C_MACID_CFG_LEN, u1H2CMacIdConfigParm);
 992 }
 993 
 994 void rtl8723b_set_rssi_cmd(struct adapter *padapter, u8 *param)
 995 {
 996         u8 u1H2CRssiSettingParm[H2C_RSSI_SETTING_LEN] = {0};
 997         u8 mac_id = *param;
 998         u8 rssi = *(param+2);
 999         u8 uldl_state = 0;
1000 
1001         /* DBG_871X("%s(): param =%.2x-%.2x-%.2x\n", __func__, *param, *(param+1), *(param+2)); */
1002         /* DBG_871X("%s(): mac_id =%d rssi =%d\n", __func__, mac_id, rssi); */
1003 
1004         SET_8723B_H2CCMD_RSSI_SETTING_MACID(u1H2CRssiSettingParm, mac_id);
1005         SET_8723B_H2CCMD_RSSI_SETTING_RSSI(u1H2CRssiSettingParm, rssi);
1006         SET_8723B_H2CCMD_RSSI_SETTING_ULDL_STATE(u1H2CRssiSettingParm, uldl_state);
1007 
1008         RT_PRINT_DATA(_module_hal_init_c_, _drv_notice_, "u1H2CRssiSettingParm:", u1H2CRssiSettingParm, H2C_RSSI_SETTING_LEN);
1009         FillH2CCmd8723B(padapter, H2C_8723B_RSSI_SETTING, H2C_RSSI_SETTING_LEN, u1H2CRssiSettingParm);
1010 }
1011 
1012 void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 psmode)
1013 {
1014         int i;
1015         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1016         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1017         u8 u1H2CPwrModeParm[H2C_PWRMODE_LEN] = {0};
1018         u8 PowerState = 0, awake_intvl = 1, byte5 = 0, rlbm = 0;
1019 
1020         if (pwrpriv->dtim > 0)
1021                 DBG_871X("%s(): FW LPS mode = %d, SmartPS =%d, dtim =%d\n", __func__, psmode, pwrpriv->smart_ps, pwrpriv->dtim);
1022         else
1023                 DBG_871X("%s(): FW LPS mode = %d, SmartPS =%d\n", __func__, psmode, pwrpriv->smart_ps);
1024 
1025 #ifdef CONFIG_WOWLAN
1026         if (psmode == PS_MODE_DTIM) { /* For WOWLAN LPS, DTIM = (awake_intvl - 1) */
1027                 awake_intvl = 3;/* DTIM =2 */
1028                 rlbm = 2;
1029         } else
1030 #endif /* CONFIG_WOWLAN */
1031         {
1032                 if (pwrpriv->dtim > 0 && pwrpriv->dtim < 16)
1033                         awake_intvl = pwrpriv->dtim+1;/* DTIM = (awake_intvl - 1) */
1034                 else
1035                         awake_intvl = 3;/* DTIM =2 */
1036 
1037                 rlbm = 2;
1038         }
1039 
1040 
1041         if (padapter->registrypriv.wifi_spec == 1) {
1042                 awake_intvl = 2;
1043                 rlbm = 2;
1044         }
1045 
1046         if (psmode > 0) {
1047                 if (hal_btcoex_IsBtControlLps(padapter) == true) {
1048                         PowerState = hal_btcoex_RpwmVal(padapter);
1049                         byte5 = hal_btcoex_LpsVal(padapter);
1050 
1051                         if ((rlbm == 2) && (byte5 & BIT(4))) {
1052                                 /*  Keep awake interval to 1 to prevent from */
1053                                 /*  decreasing coex performance */
1054                                 awake_intvl = 2;
1055                                 rlbm = 2;
1056                         }
1057                 } else {
1058                         PowerState = 0x00;/*  AllON(0x0C), RFON(0x04), RFOFF(0x00) */
1059                         byte5 = 0x40;
1060                 }
1061         } else {
1062                 PowerState = 0x0C;/*  AllON(0x0C), RFON(0x04), RFOFF(0x00) */
1063                 byte5 = 0x40;
1064         }
1065 
1066         SET_8723B_H2CCMD_PWRMODE_PARM_MODE(u1H2CPwrModeParm, (psmode > 0) ? 1 : 0);
1067         SET_8723B_H2CCMD_PWRMODE_PARM_SMART_PS(u1H2CPwrModeParm, pwrpriv->smart_ps);
1068         SET_8723B_H2CCMD_PWRMODE_PARM_RLBM(u1H2CPwrModeParm, rlbm);
1069         SET_8723B_H2CCMD_PWRMODE_PARM_BCN_PASS_TIME(u1H2CPwrModeParm, awake_intvl);
1070         SET_8723B_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(u1H2CPwrModeParm, padapter->registrypriv.uapsd_enable);
1071         SET_8723B_H2CCMD_PWRMODE_PARM_PWR_STATE(u1H2CPwrModeParm, PowerState);
1072         SET_8723B_H2CCMD_PWRMODE_PARM_BYTE5(u1H2CPwrModeParm, byte5);
1073         if (psmode != PS_MODE_ACTIVE) {
1074                 if (!pmlmeext->adaptive_tsf_done && pmlmeext->bcn_cnt > 0) {
1075                         u8 ratio_20_delay, ratio_80_delay;
1076 
1077                         /* byte 6 for adaptive_early_32k */
1078                         /* 0:3] = DrvBcnEarly  (ms) , [4:7] = DrvBcnTimeOut  (ms) */
1079                         /*  20% for DrvBcnEarly, 80% for DrvBcnTimeOut */
1080                         ratio_20_delay = 0;
1081                         ratio_80_delay = 0;
1082                         pmlmeext->DrvBcnEarly = 0xff;
1083                         pmlmeext->DrvBcnTimeOut = 0xff;
1084 
1085                         DBG_871X("%s(): bcn_cnt = %d\n", __func__, pmlmeext->bcn_cnt);
1086 
1087                         for (i = 0; i < 9; i++) {
1088                                 pmlmeext->bcn_delay_ratio[i] = (pmlmeext->bcn_delay_cnt[i]*100)/pmlmeext->bcn_cnt;
1089 
1090                                 DBG_871X(
1091                                         "%s(): bcn_delay_cnt[%d]=%d, bcn_delay_ratio[%d] = %d\n",
1092                                         __func__,
1093                                         i,
1094                                         pmlmeext->bcn_delay_cnt[i],
1095                                         i,
1096                                         pmlmeext->bcn_delay_ratio[i]
1097                                 );
1098 
1099                                 ratio_20_delay += pmlmeext->bcn_delay_ratio[i];
1100                                 ratio_80_delay += pmlmeext->bcn_delay_ratio[i];
1101 
1102                                 if (ratio_20_delay > 20 && pmlmeext->DrvBcnEarly == 0xff) {
1103                                         pmlmeext->DrvBcnEarly = i;
1104                                         DBG_871X("%s(): DrvBcnEarly = %d\n", __func__, pmlmeext->DrvBcnEarly);
1105                                 }
1106 
1107                                 if (ratio_80_delay > 80 && pmlmeext->DrvBcnTimeOut == 0xff) {
1108                                         pmlmeext->DrvBcnTimeOut = i;
1109                                         DBG_871X("%s(): DrvBcnTimeOut = %d\n", __func__, pmlmeext->DrvBcnTimeOut);
1110                                 }
1111 
1112                                 /* reset adaptive_early_32k cnt */
1113                                 pmlmeext->bcn_delay_cnt[i] = 0;
1114                                 pmlmeext->bcn_delay_ratio[i] = 0;
1115 
1116                         }
1117 
1118                         pmlmeext->bcn_cnt = 0;
1119                         pmlmeext->adaptive_tsf_done = true;
1120 
1121                 } else {
1122                         DBG_871X("%s(): DrvBcnEarly = %d\n", __func__, pmlmeext->DrvBcnEarly);
1123                         DBG_871X("%s(): DrvBcnTimeOut = %d\n", __func__, pmlmeext->DrvBcnTimeOut);
1124                 }
1125 
1126 /* offload to FW if fw version > v15.10
1127                 pmlmeext->DrvBcnEarly = 0;
1128                 pmlmeext->DrvBcnTimeOut =7;
1129 
1130                 if ((pmlmeext->DrvBcnEarly!= 0Xff) && (pmlmeext->DrvBcnTimeOut!= 0xff))
1131                         u1H2CPwrModeParm[H2C_PWRMODE_LEN-1] = BIT(0) | ((pmlmeext->DrvBcnEarly<<1)&0x0E) |((pmlmeext->DrvBcnTimeOut<<4)&0xf0) ;
1132 */
1133 
1134         }
1135 
1136         hal_btcoex_RecordPwrMode(padapter, u1H2CPwrModeParm, H2C_PWRMODE_LEN);
1137 
1138         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CPwrModeParm:", u1H2CPwrModeParm, H2C_PWRMODE_LEN);
1139 
1140         FillH2CCmd8723B(padapter, H2C_8723B_SET_PWR_MODE, H2C_PWRMODE_LEN, u1H2CPwrModeParm);
1141 }
1142 
1143 void rtl8723b_set_FwPsTuneParam_cmd(struct adapter *padapter)
1144 {
1145         u8 u1H2CPsTuneParm[H2C_PSTUNEPARAM_LEN] = {0};
1146         u8 bcn_to_limit = 10; /* 10 * 100 * awakeinterval (ms) */
1147         u8 dtim_timeout = 5; /* ms wait broadcast data timer */
1148         u8 ps_timeout = 20;  /* ms Keep awake when tx */
1149         u8 dtim_period = 3;
1150 
1151         /* DBG_871X("%s(): FW LPS mode = %d\n", __func__, psmode); */
1152 
1153         SET_8723B_H2CCMD_PSTUNE_PARM_BCN_TO_LIMIT(u1H2CPsTuneParm, bcn_to_limit);
1154         SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_TIMEOUT(u1H2CPsTuneParm, dtim_timeout);
1155         SET_8723B_H2CCMD_PSTUNE_PARM_PS_TIMEOUT(u1H2CPsTuneParm, ps_timeout);
1156         SET_8723B_H2CCMD_PSTUNE_PARM_ADOPT(u1H2CPsTuneParm, 1);
1157         SET_8723B_H2CCMD_PSTUNE_PARM_DTIM_PERIOD(u1H2CPsTuneParm, dtim_period);
1158 
1159         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CPsTuneParm:", u1H2CPsTuneParm, H2C_PSTUNEPARAM_LEN);
1160 
1161         FillH2CCmd8723B(padapter, H2C_8723B_PS_TUNING_PARA, H2C_PSTUNEPARAM_LEN, u1H2CPsTuneParm);
1162 }
1163 
1164 void rtl8723b_set_FwPwrModeInIPS_cmd(struct adapter *padapter, u8 cmd_param)
1165 {
1166         /* BIT0:enable, BIT1:NoConnect32k */
1167 
1168         DBG_871X("%s()\n", __func__);
1169 
1170         FillH2CCmd8723B(padapter, H2C_8723B_FWLPS_IN_IPS_, 1, &cmd_param);
1171 }
1172 
1173 #ifdef CONFIG_WOWLAN
1174 static void rtl8723b_set_FwWoWlanCtrl_Cmd(struct adapter *padapter, u8 bFuncEn)
1175 {
1176         struct security_priv *psecpriv = &padapter->securitypriv;
1177         u8 u1H2CWoWlanCtrlParm[H2C_WOWLAN_LEN] = {0};
1178         u8 discont_wake = 1, gpionum = 0, gpio_dur = 0, hw_unicast = 0;
1179         u8 sdio_wakeup_enable = 1;
1180         u8 gpio_high_active = 0; /* 0: low active, 1: high active */
1181         u8 magic_pkt = 0;
1182 
1183 #ifdef CONFIG_GPIO_WAKEUP
1184         gpionum = WAKEUP_GPIO_IDX;
1185         sdio_wakeup_enable = 0;
1186 #endif
1187 
1188 #ifdef CONFIG_PNO_SUPPORT
1189         if (!ppwrpriv->wowlan_pno_enable)
1190                 magic_pkt = 1;
1191 #endif
1192 
1193         if (psecpriv->dot11PrivacyAlgrthm == _WEP40_ || psecpriv->dot11PrivacyAlgrthm == _WEP104_)
1194                 hw_unicast = 1;
1195 
1196         DBG_871X("%s(): bFuncEn =%d\n", __func__, bFuncEn);
1197 
1198         SET_H2CCMD_WOWLAN_FUNC_ENABLE(u1H2CWoWlanCtrlParm, bFuncEn);
1199         SET_H2CCMD_WOWLAN_PATTERN_MATCH_ENABLE(u1H2CWoWlanCtrlParm, 0);
1200         SET_H2CCMD_WOWLAN_MAGIC_PKT_ENABLE(u1H2CWoWlanCtrlParm, magic_pkt);
1201         SET_H2CCMD_WOWLAN_UNICAST_PKT_ENABLE(u1H2CWoWlanCtrlParm, hw_unicast);
1202         SET_H2CCMD_WOWLAN_ALL_PKT_DROP(u1H2CWoWlanCtrlParm, 0);
1203         SET_H2CCMD_WOWLAN_GPIO_ACTIVE(u1H2CWoWlanCtrlParm, gpio_high_active);
1204         SET_H2CCMD_WOWLAN_DISCONNECT_WAKE_UP(u1H2CWoWlanCtrlParm, discont_wake);
1205         SET_H2CCMD_WOWLAN_GPIONUM(u1H2CWoWlanCtrlParm, gpionum);
1206         SET_H2CCMD_WOWLAN_DATAPIN_WAKE_UP(u1H2CWoWlanCtrlParm, sdio_wakeup_enable);
1207         SET_H2CCMD_WOWLAN_GPIO_DURATION(u1H2CWoWlanCtrlParm, gpio_dur);
1208         /* SET_H2CCMD_WOWLAN_GPIO_PULSE_EN(u1H2CWoWlanCtrlParm, 1); */
1209         SET_H2CCMD_WOWLAN_GPIO_PULSE_COUNT(u1H2CWoWlanCtrlParm, 0x09);
1210 
1211         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CWoWlanCtrlParm:", u1H2CWoWlanCtrlParm, H2C_WOWLAN_LEN);
1212 
1213         FillH2CCmd8723B(padapter, H2C_8723B_WOWLAN, H2C_WOWLAN_LEN, u1H2CWoWlanCtrlParm);
1214 }
1215 
1216 static void rtl8723b_set_FwRemoteWakeCtrl_Cmd(struct adapter *padapter, u8 benable)
1217 {
1218         u8 u1H2CRemoteWakeCtrlParm[H2C_REMOTE_WAKE_CTRL_LEN] = {0};
1219         struct security_priv *psecuritypriv = &(padapter->securitypriv);
1220         struct pwrctrl_priv *ppwrpriv = adapter_to_pwrctl(padapter);
1221 
1222         DBG_871X("%s(): Enable =%d\n", __func__, benable);
1223 
1224         if (!ppwrpriv->wowlan_pno_enable) {
1225                 SET_H2CCMD_REMOTE_WAKECTRL_ENABLE(u1H2CRemoteWakeCtrlParm, benable);
1226                 SET_H2CCMD_REMOTE_WAKE_CTRL_ARP_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, 1);
1227 #ifdef CONFIG_GTK_OL
1228                 if (psecuritypriv->binstallKCK_KEK &&
1229                     psecuritypriv->dot11PrivacyAlgrthm == _AES_) {
1230                         SET_H2CCMD_REMOTE_WAKE_CTRL_GTK_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, 1);
1231                 } else {
1232                         DBG_871X("no kck or security is not AES\n");
1233                         SET_H2CCMD_REMOTE_WAKE_CTRL_GTK_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, 0);
1234                 }
1235 #endif /* CONFIG_GTK_OL */
1236 
1237                 SET_H2CCMD_REMOTE_WAKE_CTRL_FW_UNICAST_EN(u1H2CRemoteWakeCtrlParm, 1);
1238 
1239                 if ((psecuritypriv->dot11PrivacyAlgrthm == _AES_) ||
1240                     (psecuritypriv->dot11PrivacyAlgrthm == _NO_PRIVACY_))
1241                         SET_H2CCMD_REMOTE_WAKE_CTRL_ARP_ACTION(u1H2CRemoteWakeCtrlParm, 0);
1242                 else
1243                         SET_H2CCMD_REMOTE_WAKE_CTRL_ARP_ACTION(u1H2CRemoteWakeCtrlParm, 1);
1244         }
1245 #ifdef CONFIG_PNO_SUPPORT
1246         else {
1247                 SET_H2CCMD_REMOTE_WAKECTRL_ENABLE(u1H2CRemoteWakeCtrlParm, benable);
1248                 SET_H2CCMD_REMOTE_WAKE_CTRL_NLO_OFFLOAD_EN(u1H2CRemoteWakeCtrlParm, benable);
1249         }
1250 #endif
1251         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CRemoteWakeCtrlParm:", u1H2CRemoteWakeCtrlParm, H2C_REMOTE_WAKE_CTRL_LEN);
1252         FillH2CCmd8723B(padapter, H2C_8723B_REMOTE_WAKE_CTRL,
1253                 H2C_REMOTE_WAKE_CTRL_LEN, u1H2CRemoteWakeCtrlParm);
1254 #ifdef CONFIG_PNO_SUPPORT
1255         if (ppwrpriv->wowlan_pno_enable && !ppwrpriv->pno_in_resume) {
1256                 res = rtw_read8(padapter, REG_PNO_STATUS);
1257                 DBG_871X("cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", res);
1258                 while (!(res&BIT(7)) && count < 25) {
1259                         DBG_871X("[%d] cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", count, res);
1260                         res = rtw_read8(padapter, REG_PNO_STATUS);
1261                         count++;
1262                         msleep(2);
1263                 }
1264                 DBG_871X("cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", res);
1265         }
1266 #endif /* CONFIG_PNO_SUPPORT */
1267 }
1268 
1269 static void rtl8723b_set_FwAOACGlobalInfo_Cmd(struct adapter *padapter,  u8 group_alg, u8 pairwise_alg)
1270 {
1271         u8 u1H2CAOACGlobalInfoParm[H2C_AOAC_GLOBAL_INFO_LEN] = {0};
1272 
1273         DBG_871X("%s(): group_alg =%d pairwise_alg =%d\n", __func__, group_alg, pairwise_alg);
1274 
1275         SET_H2CCMD_AOAC_GLOBAL_INFO_PAIRWISE_ENC_ALG(u1H2CAOACGlobalInfoParm, pairwise_alg);
1276         SET_H2CCMD_AOAC_GLOBAL_INFO_GROUP_ENC_ALG(u1H2CAOACGlobalInfoParm, group_alg);
1277 
1278         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CAOACGlobalInfoParm:", u1H2CAOACGlobalInfoParm, H2C_AOAC_GLOBAL_INFO_LEN);
1279 
1280         FillH2CCmd8723B(padapter, H2C_8723B_AOAC_GLOBAL_INFO, H2C_AOAC_GLOBAL_INFO_LEN, u1H2CAOACGlobalInfoParm);
1281 }
1282 
1283 #ifdef CONFIG_PNO_SUPPORT
1284 static void rtl8723b_set_FwScanOffloadInfo_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc, u8 enable)
1285 {
1286         u8 u1H2CScanOffloadInfoParm[H2C_SCAN_OFFLOAD_CTRL_LEN] = {0};
1287 
1288         DBG_871X("%s: loc_probe_packet:%d, loc_scan_info: %d loc_ssid_info:%d\n",
1289                 __func__, rsvdpageloc->LocProbePacket, rsvdpageloc->LocScanInfo, rsvdpageloc->LocSSIDInfo);
1290 
1291         SET_H2CCMD_AOAC_NLO_FUN_EN(u1H2CScanOffloadInfoParm, enable);
1292         SET_H2CCMD_AOAC_RSVDPAGE_LOC_SCAN_INFO(u1H2CScanOffloadInfoParm, rsvdpageloc->LocScanInfo);
1293         SET_H2CCMD_AOAC_RSVDPAGE_LOC_PROBE_PACKET(u1H2CScanOffloadInfoParm, rsvdpageloc->LocProbePacket);
1294         SET_H2CCMD_AOAC_RSVDPAGE_LOC_SSID_INFO(u1H2CScanOffloadInfoParm, rsvdpageloc->LocSSIDInfo);
1295 
1296         RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CScanOffloadInfoParm:", u1H2CScanOffloadInfoParm, H2C_SCAN_OFFLOAD_CTRL_LEN);
1297         FillH2CCmd8723B(padapter, H2C_8723B_D0_SCAN_OFFLOAD_INFO, H2C_SCAN_OFFLOAD_CTRL_LEN, u1H2CScanOffloadInfoParm);
1298 
1299         msleep(20);
1300 }
1301 #endif /* CONFIG_PNO_SUPPORT */
1302 
1303 void rtl8723b_set_wowlan_cmd(struct adapter *padapter, u8 enable)
1304 {
1305         struct security_priv *psecpriv = &padapter->securitypriv;
1306         struct pwrctrl_priv *ppwrpriv = adapter_to_pwrctl(padapter);
1307         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1308         struct sta_info *psta = NULL;
1309         u8 pkt_type = 0;
1310 
1311         DBG_871X_LEVEL(_drv_always_, "+%s()+: enable =%d\n", __func__, enable);
1312         if (enable) {
1313                 rtl8723b_set_FwAOACGlobalInfo_Cmd(padapter, psecpriv->dot118021XGrpPrivacy, psecpriv->dot11PrivacyAlgrthm);
1314 
1315                 rtl8723b_set_FwJoinBssRpt_cmd(padapter, RT_MEDIA_CONNECT);      /* RT_MEDIA_CONNECT will confuse in the future */
1316 
1317                 if (!(ppwrpriv->wowlan_pno_enable)) {
1318                         psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(pmlmepriv));
1319                         if (psta)
1320                                 rtl8723b_set_FwMediaStatusRpt_cmd(padapter, RT_MEDIA_CONNECT, psta->mac_id);
1321                 } else
1322                         DBG_871X("%s(): Disconnected, no FwMediaStatusRpt CONNECT\n", __func__);
1323 
1324                 msleep(2);
1325 
1326                 if (!(ppwrpriv->wowlan_pno_enable)) {
1327                         rtl8723b_set_FwDisconDecision_cmd(padapter, enable);
1328                         msleep(2);
1329 
1330                         if ((psecpriv->dot11PrivacyAlgrthm != _WEP40_) || (psecpriv->dot11PrivacyAlgrthm != _WEP104_))
1331                                 pkt_type = 1;
1332 
1333                         rtl8723b_set_FwKeepAlive_cmd(padapter, enable, pkt_type);
1334                         msleep(2);
1335                 }
1336 
1337                 rtl8723b_set_FwWoWlanCtrl_Cmd(padapter, enable);
1338                 msleep(2);
1339 
1340                 rtl8723b_set_FwRemoteWakeCtrl_Cmd(padapter, enable);
1341         } else {
1342                 rtl8723b_set_FwRemoteWakeCtrl_Cmd(padapter, enable);
1343                 msleep(2);
1344                 rtl8723b_set_FwWoWlanCtrl_Cmd(padapter, enable);
1345         }
1346 
1347         DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__);
1348 }
1349 #endif /* CONFIG_WOWLAN */
1350 
1351 #ifdef CONFIG_AP_WOWLAN
1352 static void rtl8723b_set_FwAPWoWlanCtrl_Cmd(struct adapter *padapter, u8 bFuncEn)
1353 {
1354         u8 u1H2CAPWoWlanCtrlParm[H2C_WOWLAN_LEN] = {0};
1355         u8 gpionum = 0, gpio_dur = 0;
1356         u8 gpio_high_active = 1; /* 0: low active, 1: high active */
1357         u8 gpio_pulse = bFuncEn;
1358 #ifdef CONFIG_GPIO_WAKEUP
1359         gpionum = WAKEUP_GPIO_IDX;
1360 #endif
1361 
1362         DBG_871X("%s(): bFuncEn =%d\n", __func__, bFuncEn);
1363 
1364         if (bFuncEn)
1365                 gpio_dur = 16;
1366         else
1367                 gpio_dur = 0;
1368 
1369         SET_H2CCMD_AP_WOW_GPIO_CTRL_INDEX(u1H2CAPWoWlanCtrlParm,
1370                         gpionum);
1371         SET_H2CCMD_AP_WOW_GPIO_CTRL_PLUS(u1H2CAPWoWlanCtrlParm,
1372                         gpio_pulse);
1373         SET_H2CCMD_AP_WOW_GPIO_CTRL_HIGH_ACTIVE(u1H2CAPWoWlanCtrlParm,
1374                         gpio_high_active);
1375         SET_H2CCMD_AP_WOW_GPIO_CTRL_EN(u1H2CAPWoWlanCtrlParm,
1376                         bFuncEn);
1377         SET_H2CCMD_AP_WOW_GPIO_CTRL_DURATION(u1H2CAPWoWlanCtrlParm,
1378                         gpio_dur);
1379 
1380         FillH2CCmd8723B(padapter, H2C_8723B_AP_WOW_GPIO_CTRL,
1381                         H2C_AP_WOW_GPIO_CTRL_LEN, u1H2CAPWoWlanCtrlParm);
1382 }
1383 
1384 static void rtl8723b_set_Fw_AP_Offload_Cmd(struct adapter *padapter, u8 bFuncEn)
1385 {
1386         u8 u1H2CAPOffloadCtrlParm[H2C_WOWLAN_LEN] = {0};
1387 
1388         DBG_871X("%s(): bFuncEn =%d\n", __func__, bFuncEn);
1389 
1390         SET_H2CCMD_AP_WOWLAN_EN(u1H2CAPOffloadCtrlParm, bFuncEn);
1391 
1392         FillH2CCmd8723B(padapter, H2C_8723B_AP_OFFLOAD,
1393                         H2C_AP_OFFLOAD_LEN, u1H2CAPOffloadCtrlParm);
1394 }
1395 
1396 void rtl8723b_set_ap_wowlan_cmd(struct adapter *padapter, u8 enable)
1397 {
1398         DBG_871X_LEVEL(_drv_always_, "+%s()+: enable =%d\n", __func__, enable);
1399         if (enable) {
1400                 rtl8723b_set_FwJoinBssRpt_cmd(padapter, RT_MEDIA_CONNECT);
1401                 issue_beacon(padapter, 0);
1402         }
1403 
1404         rtl8723b_set_FwAPWoWlanCtrl_Cmd(padapter, enable);
1405         msleep(10);
1406         rtl8723b_set_Fw_AP_Offload_Cmd(padapter, enable);
1407         msleep(10);
1408         DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__);
1409 }
1410 #endif /* CONFIG_AP_WOWLAN */
1411 
1412 /*  */
1413 /*  Description: Fill the reserved packets that FW will use to RSVD page. */
1414 /*                      Now we just send 4 types packet to rsvd page. */
1415 /*                      (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. */
1416 /*      Input: */
1417 /*          bDLFinished - false: At the first time we will send all the packets as a large packet to Hw, */
1418 /*                                              so we need to set the packet length to total lengh. */
1419 /*                            true: At the second time, we should send the first packet (default:beacon) */
1420 /*                                              to Hw again and set the lengh in descriptor to the real beacon lengh. */
1421 /*  2009.10.15 by tynli. */
1422 static void rtl8723b_set_FwRsvdPagePkt(
1423         struct adapter *padapter, bool bDLFinished
1424 )
1425 {
1426         struct xmit_frame *pcmdframe;
1427         struct pkt_attrib *pattrib;
1428         struct xmit_priv *pxmitpriv;
1429         struct mlme_ext_priv *pmlmeext;
1430         struct mlme_ext_info *pmlmeinfo;
1431         struct pwrctrl_priv *pwrctl;
1432         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1433         u32 BeaconLength = 0, PSPollLength = 0;
1434         u32 NullDataLength = 0, QosNullLength = 0, BTQosNullLength = 0;
1435         u8 *ReservedPagePacket;
1436         u8 TxDescLen = TXDESC_SIZE, TxDescOffset = TXDESC_OFFSET;
1437         u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0;
1438         u16 BufIndex, PageSize = 128;
1439         u32 TotalPacketLen, MaxRsvdPageBufSize = 0;
1440         RSVDPAGE_LOC RsvdPageLoc;
1441 #ifdef CONFIG_WOWLAN
1442         u32 ARPLegnth = 0, GTKLegnth = 0;
1443         u8 currentip[4];
1444         u8 cur_dot11txpn[8];
1445 #ifdef CONFIG_GTK_OL
1446         struct sta_priv *pstapriv = &padapter->stapriv;
1447         struct sta_info *psta;
1448         u8 kek[RTW_KEK_LEN];
1449         u8 kck[RTW_KCK_LEN];
1450 #endif
1451 #endif
1452 
1453         /* DBG_871X("%s---->\n", __func__); */
1454 
1455         pxmitpriv = &padapter->xmitpriv;
1456         pmlmeext = &padapter->mlmeextpriv;
1457         pmlmeinfo = &pmlmeext->mlmext_info;
1458         pwrctl = adapter_to_pwrctl(padapter);
1459 
1460         RsvdPageNum = BCNQ_PAGE_NUM_8723B + WOWLAN_PAGE_NUM_8723B;
1461         MaxRsvdPageBufSize = RsvdPageNum*PageSize;
1462 
1463         pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv);
1464         if (!pcmdframe) {
1465                 DBG_871X("%s: alloc ReservedPagePacket fail!\n", __func__);
1466                 return;
1467         }
1468 
1469         ReservedPagePacket = pcmdframe->buf_addr;
1470         memset(&RsvdPageLoc, 0, sizeof(RSVDPAGE_LOC));
1471 
1472         /* 3 (1) beacon */
1473         BufIndex = TxDescOffset;
1474         ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength);
1475 
1476         /*  When we count the first page size, we need to reserve description size for the RSVD */
1477         /*  packet, it will be filled in front of the packet in TXPKTBUF. */
1478         CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength);
1479         /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */
1480         if (CurtPktPageNum == 1)
1481                 CurtPktPageNum += 1;
1482 
1483         TotalPageNum += CurtPktPageNum;
1484 
1485         BufIndex += (CurtPktPageNum*PageSize);
1486 
1487         /* 3 (2) ps-poll */
1488         RsvdPageLoc.LocPsPoll = TotalPageNum;
1489         ConstructPSPoll(padapter, &ReservedPagePacket[BufIndex], &PSPollLength);
1490         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], PSPollLength, true, false, false);
1491 
1492         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: PS-POLL %p %d\n", */
1493         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (PSPollLength+TxDescLen)); */
1494 
1495         CurtPktPageNum = (u8)PageNum_128(TxDescLen + PSPollLength);
1496 
1497         TotalPageNum += CurtPktPageNum;
1498 
1499         BufIndex += (CurtPktPageNum*PageSize);
1500 
1501         /* 3 (3) null data */
1502         RsvdPageLoc.LocNullData = TotalPageNum;
1503         ConstructNullFunctionData(
1504                 padapter,
1505                 &ReservedPagePacket[BufIndex],
1506                 &NullDataLength,
1507                 get_my_bssid(&pmlmeinfo->network),
1508                 false, 0, 0, false
1509         );
1510         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], NullDataLength, false, false, false);
1511 
1512         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: NULL DATA %p %d\n", */
1513         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (NullDataLength+TxDescLen)); */
1514 
1515         CurtPktPageNum = (u8)PageNum_128(TxDescLen + NullDataLength);
1516 
1517         TotalPageNum += CurtPktPageNum;
1518 
1519         BufIndex += (CurtPktPageNum*PageSize);
1520 
1521         /* 3 (5) Qos null data */
1522         RsvdPageLoc.LocQosNull = TotalPageNum;
1523         ConstructNullFunctionData(
1524                 padapter,
1525                 &ReservedPagePacket[BufIndex],
1526                 &QosNullLength,
1527                 get_my_bssid(&pmlmeinfo->network),
1528                 true, 0, 0, false
1529         );
1530         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], QosNullLength, false, false, false);
1531 
1532         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: QOS NULL DATA %p %d\n", */
1533         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (QosNullLength+TxDescLen)); */
1534 
1535         CurtPktPageNum = (u8)PageNum_128(TxDescLen + QosNullLength);
1536 
1537         TotalPageNum += CurtPktPageNum;
1538 
1539         BufIndex += (CurtPktPageNum*PageSize);
1540 
1541         /* 3 (6) BT Qos null data */
1542         RsvdPageLoc.LocBTQosNull = TotalPageNum;
1543         ConstructNullFunctionData(
1544                 padapter,
1545                 &ReservedPagePacket[BufIndex],
1546                 &BTQosNullLength,
1547                 get_my_bssid(&pmlmeinfo->network),
1548                 true, 0, 0, false
1549         );
1550         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], BTQosNullLength, false, true, false);
1551 
1552         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: BT QOS NULL DATA %p %d\n", */
1553         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (BTQosNullLength+TxDescLen)); */
1554 
1555         CurtPktPageNum = (u8)PageNum_128(TxDescLen + BTQosNullLength);
1556 
1557         TotalPageNum += CurtPktPageNum;
1558 
1559         BufIndex += (CurtPktPageNum*PageSize);
1560 
1561 #ifdef CONFIG_WOWLAN
1562         if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1563         /* if (pwrctl->wowlan_mode == true) { */
1564                 /* BufIndex += (CurtPktPageNum*PageSize); */
1565 
1566         /* 3(7) ARP RSP */
1567         rtw_get_current_ip_address(padapter, currentip);
1568         RsvdPageLoc.LocArpRsp = TotalPageNum;
1569         {
1570         ConstructARPResponse(
1571                 padapter,
1572                 &ReservedPagePacket[BufIndex],
1573                 &ARPLegnth,
1574                 currentip
1575                 );
1576         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], ARPLegnth, false, false, true);
1577 
1578         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: ARP RSP %p %d\n", */
1579         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (ARPLegnth+TxDescLen)); */
1580 
1581         CurtPktPageNum = (u8)PageNum_128(TxDescLen + ARPLegnth);
1582         }
1583         TotalPageNum += CurtPktPageNum;
1584 
1585         BufIndex += (CurtPktPageNum*PageSize);
1586 
1587         /* 3(8) SEC IV */
1588         rtw_get_sec_iv(padapter, cur_dot11txpn, get_my_bssid(&pmlmeinfo->network));
1589         RsvdPageLoc.LocRemoteCtrlInfo = TotalPageNum;
1590         memcpy(ReservedPagePacket+BufIndex-TxDescLen, cur_dot11txpn, _AES_IV_LEN_);
1591 
1592         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: SEC IV %p %d\n", */
1593         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], _AES_IV_LEN_); */
1594 
1595         CurtPktPageNum = (u8)PageNum_128(_AES_IV_LEN_);
1596 
1597         TotalPageNum += CurtPktPageNum;
1598 
1599 #ifdef CONFIG_GTK_OL
1600         BufIndex += (CurtPktPageNum*PageSize);
1601 
1602         /* if the ap staion info. exists, get the kek, kck from staion info. */
1603         psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
1604         if (!psta) {
1605                 memset(kek, 0, RTW_KEK_LEN);
1606                 memset(kck, 0, RTW_KCK_LEN);
1607                 DBG_8192C("%s, KEK, KCK download rsvd page all zero\n", __func__);
1608         } else {
1609                 memcpy(kek, psta->kek, RTW_KEK_LEN);
1610                 memcpy(kck, psta->kck, RTW_KCK_LEN);
1611         }
1612 
1613         /* 3(9) KEK, KCK */
1614         RsvdPageLoc.LocGTKInfo = TotalPageNum;
1615         memcpy(ReservedPagePacket+BufIndex-TxDescLen, kck, RTW_KCK_LEN);
1616         memcpy(ReservedPagePacket+BufIndex-TxDescLen+RTW_KCK_LEN, kek, RTW_KEK_LEN);
1617 
1618         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: KEK KCK %p %d\n", */
1619         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (TxDescLen + RTW_KCK_LEN + RTW_KEK_LEN)); */
1620 
1621         CurtPktPageNum = (u8)PageNum_128(TxDescLen + RTW_KCK_LEN + RTW_KEK_LEN);
1622 
1623         TotalPageNum += CurtPktPageNum;
1624 
1625         BufIndex += (CurtPktPageNum*PageSize);
1626 
1627         /* 3(10) GTK Response */
1628         RsvdPageLoc.LocGTKRsp = TotalPageNum;
1629         ConstructGTKResponse(
1630                 padapter,
1631                 &ReservedPagePacket[BufIndex],
1632                 &GTKLegnth
1633         );
1634 
1635         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], GTKLegnth, false, false, true);
1636         /* DBG_871X("%s(): HW_VAR_SET_TX_CMD: GTK RSP %p %d\n", */
1637         /*      __func__, &ReservedPagePacket[BufIndex-TxDescLen], (TxDescLen + GTKLegnth)); */
1638 
1639         CurtPktPageNum = (u8)PageNum_128(TxDescLen + GTKLegnth);
1640 
1641         TotalPageNum += CurtPktPageNum;
1642 
1643         BufIndex += (CurtPktPageNum*PageSize);
1644 
1645         /* below page is empty for GTK extension memory */
1646         /* 3(11) GTK EXT MEM */
1647         RsvdPageLoc.LocGTKEXTMEM = TotalPageNum;
1648 
1649         CurtPktPageNum = 2;
1650 
1651         TotalPageNum += CurtPktPageNum;
1652 
1653         TotalPacketLen = BufIndex-TxDescLen + 256; /* extension memory for FW */
1654 #else
1655         TotalPacketLen = BufIndex-TxDescLen + sizeof (union pn48); /* IV len */
1656 #endif /* CONFIG_GTK_OL */
1657         } else
1658 #endif /* CONFIG_WOWLAN */
1659         {
1660 #ifdef CONFIG_PNO_SUPPORT
1661                 if (!pwrctl->pno_in_resume && pwrctl->pno_inited) {
1662                         /* Probe Request */
1663                         RsvdPageLoc.LocProbePacket = TotalPageNum;
1664                         ConstructProbeReq(
1665                                 padapter,
1666                                 &ReservedPagePacket[BufIndex],
1667                                 &ProbeReqLength);
1668 
1669                         rtl8723b_fill_fake_txdesc(padapter,
1670                                 &ReservedPagePacket[BufIndex-TxDescLen],
1671                                 ProbeReqLength, false, false, false);
1672 #ifdef CONFIG_PNO_SET_DEBUG
1673         {
1674                         int gj;
1675                         printk("probe req pkt =>\n");
1676                         for (gj = 0; gj < ProbeReqLength+TxDescLen; gj++) {
1677                                 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1678                                 if ((gj+1)%8 == 0)
1679                                         printk("\n");
1680                         }
1681                         printk(" <=end\n");
1682         }
1683 #endif
1684                         CurtPktPageNum =
1685                                 (u8)PageNum_128(TxDescLen + ProbeReqLength);
1686 
1687                         TotalPageNum += CurtPktPageNum;
1688 
1689                         BufIndex += (CurtPktPageNum*PageSize);
1690 
1691                         /* PNO INFO Page */
1692                         RsvdPageLoc.LocPNOInfo = TotalPageNum;
1693                         ConstructPnoInfo(padapter, &ReservedPagePacket[BufIndex-TxDescLen], &PNOLength);
1694 #ifdef CONFIG_PNO_SET_DEBUG
1695         {
1696                         int gj;
1697                         printk("PNO pkt =>\n");
1698                         for (gj = 0; gj < PNOLength; gj++) {
1699                                 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1700                                 if ((gj + 1)%8 == 0)
1701                                         printk("\n");
1702                         }
1703                         printk(" <=end\n");
1704         }
1705 #endif
1706 
1707                         CurtPktPageNum = (u8)PageNum_128(PNOLength);
1708                         TotalPageNum += CurtPktPageNum;
1709                         BufIndex += (CurtPktPageNum*PageSize);
1710 
1711                         /* SSID List Page */
1712                         RsvdPageLoc.LocSSIDInfo = TotalPageNum;
1713                         ConstructSSIDList(padapter, &ReservedPagePacket[BufIndex-TxDescLen], &SSIDLegnth);
1714 #ifdef CONFIG_PNO_SET_DEBUG
1715         {
1716                         int gj;
1717                         printk("SSID list pkt =>\n");
1718                         for (gj = 0; gj < SSIDLegnth; gj++) {
1719                                 printk(" %02x ", ReservedPagePacket[BufIndex-TxDescLen+gj]);
1720                                 if ((gj + 1)%8 == 0)
1721                                         printk("\n");
1722                         }
1723                         printk(" <=end\n");
1724         }
1725 #endif
1726                         CurtPktPageNum = (u8)PageNum_128(SSIDLegnth);
1727                         TotalPageNum += CurtPktPageNum;
1728                         BufIndex += (CurtPktPageNum*PageSize);
1729 
1730                         /* Scan Info Page */
1731                         RsvdPageLoc.LocScanInfo = TotalPageNum;
1732                         ConstructScanInfo(padapter, &ReservedPagePacket[BufIndex-TxDescLen], &ScanInfoLength);
1733 #ifdef CONFIG_PNO_SET_DEBUG
1734         {
1735                         int gj;
1736                         printk("Scan info pkt =>\n");
1737                         for (gj = 0; gj < ScanInfoLength; 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(ScanInfoLength);
1746                         TotalPageNum += CurtPktPageNum;
1747                         BufIndex += (CurtPktPageNum*PageSize);
1748 
1749                         TotalPacketLen = BufIndex + ScanInfoLength;
1750                 } else {
1751                 TotalPacketLen = BufIndex + BTQosNullLength;
1752         }
1753 #else /* CONFIG_PNO_SUPPORT */
1754                 TotalPacketLen = BufIndex + BTQosNullLength;
1755 #endif
1756         }
1757 
1758         if (TotalPacketLen > MaxRsvdPageBufSize) {
1759                 DBG_871X("%s(): ERROR: The rsvd page size is not enough!!TotalPacketLen %d, MaxRsvdPageBufSize %d\n", __func__,
1760                         TotalPacketLen, MaxRsvdPageBufSize);
1761                 goto error;
1762         } else {
1763                 /*  update attribute */
1764                 pattrib = &pcmdframe->attrib;
1765                 update_mgntframe_attrib(padapter, pattrib);
1766                 pattrib->qsel = 0x10;
1767                 pattrib->pktlen = pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset;
1768                 dump_mgntframe_and_wait(padapter, pcmdframe, 100);
1769         }
1770 
1771         DBG_871X("%s: Set RSVD page location to Fw , TotalPacketLen(%d), TotalPageNum(%d)\n", __func__, TotalPacketLen, TotalPageNum);
1772         if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1773                 rtl8723b_set_FwRsvdPage_cmd(padapter, &RsvdPageLoc);
1774                 rtl8723b_set_FwAoacRsvdPage_cmd(padapter, &RsvdPageLoc);
1775         } else {
1776                 rtl8723b_set_FwAoacRsvdPage_cmd(padapter, &RsvdPageLoc);
1777 #ifdef CONFIG_PNO_SUPPORT
1778                 if (pwrctl->pno_in_resume)
1779                         rtl8723b_set_FwScanOffloadInfo_cmd(padapter,
1780                                         &RsvdPageLoc, 0);
1781                 else
1782                         rtl8723b_set_FwScanOffloadInfo_cmd(padapter,
1783                                         &RsvdPageLoc, 1);
1784 #endif
1785         }
1786         return;
1787 
1788 error:
1789 
1790         rtw_free_xmitframe(pxmitpriv, pcmdframe);
1791 }
1792 
1793 #ifdef CONFIG_AP_WOWLAN
1794 /*  */
1795 /* Description: Fill the reserved packets that FW will use to RSVD page. */
1796 /* Now we just send 2 types packet to rsvd page. (1)Beacon, (2)ProbeRsp. */
1797 /*  */
1798 /* Input: bDLFinished */
1799 /*  */
1800 /* false: At the first time we will send all the packets as a large packet to Hw, */
1801 /*       so we need to set the packet length to total lengh. */
1802 /*  */
1803 /* true: At the second time, we should send the first packet (default:beacon) */
1804 /*      to Hw again and set the lengh in descriptor to the real beacon lengh. */
1805 /*  2009.10.15 by tynli. */
1806 static void rtl8723b_set_AP_FwRsvdPagePkt(
1807         struct adapter *padapter, bool bDLFinished
1808 )
1809 {
1810         struct hal_com_data *pHalData;
1811         struct xmit_frame *pcmdframe;
1812         struct pkt_attrib *pattrib;
1813         struct xmit_priv *pxmitpriv;
1814         struct mlme_ext_priv *pmlmeext;
1815         struct mlme_ext_info *pmlmeinfo;
1816         struct pwrctrl_priv *pwrctl;
1817         u32 BeaconLength = 0, ProbeRspLength = 0;
1818         u8 *ReservedPagePacket;
1819         u8 TxDescLen = TXDESC_SIZE, TxDescOffset = TXDESC_OFFSET;
1820         u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0;
1821         u8 currentip[4];
1822         u16 BufIndex, PageSize = 128;
1823         u32 TotalPacketLen = 0, MaxRsvdPageBufSize = 0;
1824         RSVDPAGE_LOC RsvdPageLoc;
1825 
1826         /* DBG_871X("%s---->\n", __func__); */
1827         DBG_8192C("+" FUNC_ADPT_FMT ": iface_type =%d\n",
1828                 FUNC_ADPT_ARG(padapter), get_iface_type(padapter));
1829 
1830         pHalData = GET_HAL_DATA(padapter);
1831         pxmitpriv = &padapter->xmitpriv;
1832         pmlmeext = &padapter->mlmeextpriv;
1833         pmlmeinfo = &pmlmeext->mlmext_info;
1834         pwrctl = adapter_to_pwrctl(padapter);
1835 
1836         RsvdPageNum = BCNQ_PAGE_NUM_8723B + AP_WOWLAN_PAGE_NUM_8723B;
1837         MaxRsvdPageBufSize = RsvdPageNum*PageSize;
1838 
1839         pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv);
1840         if (!pcmdframe) {
1841                 DBG_871X("%s: alloc ReservedPagePacket fail!\n", __func__);
1842                 return;
1843         }
1844 
1845         ReservedPagePacket = pcmdframe->buf_addr;
1846         memset(&RsvdPageLoc, 0, sizeof(RSVDPAGE_LOC));
1847 
1848         /* 3 (1) beacon */
1849         BufIndex = TxDescOffset;
1850         ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength);
1851 
1852         /*  When we count the first page size, we need to reserve description size for the RSVD */
1853         /*  packet, it will be filled in front of the packet in TXPKTBUF. */
1854         CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength);
1855         /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */
1856         if (CurtPktPageNum == 1)
1857                 CurtPktPageNum += 1;
1858         TotalPageNum += CurtPktPageNum;
1859 
1860         BufIndex += (CurtPktPageNum*PageSize);
1861 
1862         /* 2 (4) probe response */
1863         RsvdPageLoc.LocProbeRsp = TotalPageNum;
1864 
1865         rtw_get_current_ip_address(padapter, currentip);
1866 
1867         ConstructProbeRsp(
1868                 padapter,
1869                 &ReservedPagePacket[BufIndex],
1870                 &ProbeRspLength,
1871                 currentip,
1872                 false);
1873         rtl8723b_fill_fake_txdesc(padapter,
1874                         &ReservedPagePacket[BufIndex-TxDescLen],
1875                         ProbeRspLength,
1876                         false, false, false);
1877 
1878         DBG_871X("%s(): HW_VAR_SET_TX_CMD: PROBE RSP %p %d\n",
1879                 __func__, &ReservedPagePacket[BufIndex-TxDescLen],
1880                 (ProbeRspLength+TxDescLen));
1881 
1882         CurtPktPageNum = (u8)PageNum_128(TxDescLen + ProbeRspLength);
1883 
1884         TotalPageNum += CurtPktPageNum;
1885 
1886         BufIndex += (CurtPktPageNum*PageSize);
1887 
1888         TotalPacketLen = BufIndex + ProbeRspLength;
1889 
1890         if (TotalPacketLen > MaxRsvdPageBufSize) {
1891                 DBG_871X("%s(): ERROR: The rsvd page size is not enough \
1892                                 !!TotalPacketLen %d, MaxRsvdPageBufSize %d\n",
1893                                 __func__, TotalPacketLen, MaxRsvdPageBufSize);
1894                 goto error;
1895         } else {
1896                 /*  update attribute */
1897                 pattrib = &pcmdframe->attrib;
1898                 update_mgntframe_attrib(padapter, pattrib);
1899                 pattrib->qsel = 0x10;
1900                 pattrib->pktlen = TotalPacketLen - TxDescOffset;
1901                 pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset;
1902                 dump_mgntframe_and_wait(padapter, pcmdframe, 100);
1903         }
1904 
1905         DBG_871X("%s: Set RSVD page location to Fw , TotalPacketLen(%d), TotalPageNum(%d)\n", __func__, TotalPacketLen, TotalPageNum);
1906         rtl8723b_set_ap_wow_rsvdpage_cmd(padapter, &RsvdPageLoc);
1907 
1908         return;
1909 error:
1910         rtw_free_xmitframe(pxmitpriv, pcmdframe);
1911 }
1912 #endif /* CONFIG_AP_WOWLAN */
1913 
1914 void rtl8723b_download_rsvd_page(struct adapter *padapter, u8 mstatus)
1915 {
1916         struct hal_com_data     *pHalData = GET_HAL_DATA(padapter);
1917 #ifdef CONFIG_AP_WOWLAN
1918         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1919 #endif
1920         struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1921         struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1922         bool bcn_valid = false;
1923         u8 DLBcnCount = 0;
1924         u32 poll = 0;
1925         u8 val8;
1926 
1927         DBG_8192C("+" FUNC_ADPT_FMT ": iface_type =%d mstatus(%x)\n",
1928                 FUNC_ADPT_ARG(padapter), get_iface_type(padapter), mstatus);
1929 
1930         if (mstatus == RT_MEDIA_CONNECT) {
1931                 bool bRecover = false;
1932                 u8 v8;
1933 
1934                 /*  We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */
1935                 /*  Suggested by filen. Added by tynli. */
1936                 rtw_write16(padapter, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid));
1937 
1938                 /*  set REG_CR bit 8 */
1939                 v8 = rtw_read8(padapter, REG_CR+1);
1940                 v8 |= BIT(0); /*  ENSWBCN */
1941                 rtw_write8(padapter, REG_CR+1, v8);
1942 
1943                 /*  Disable Hw protection for a time which revserd for Hw sending beacon. */
1944                 /*  Fix download reserved page packet fail that access collision with the protection time. */
1945                 /*  2010.05.11. Added by tynli. */
1946                 val8 = rtw_read8(padapter, REG_BCN_CTRL);
1947                 val8 &= ~EN_BCN_FUNCTION;
1948                 val8 |= DIS_TSF_UDT;
1949                 rtw_write8(padapter, REG_BCN_CTRL, val8);
1950 
1951                 /*  Set FWHW_TXQ_CTRL 0x422[6]= 0 to tell Hw the packet is not a real beacon frame. */
1952                 if (pHalData->RegFwHwTxQCtrl & BIT(6))
1953                         bRecover = true;
1954 
1955                 /*  To tell Hw the packet is not a real beacon frame. */
1956                 rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl & ~BIT(6));
1957                 pHalData->RegFwHwTxQCtrl &= ~BIT(6);
1958 
1959                 /*  Clear beacon valid check bit. */
1960                 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
1961                 rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
1962 
1963                 DLBcnCount = 0;
1964                 poll = 0;
1965                 do {
1966 #ifdef CONFIG_AP_WOWLAN
1967                         if (pwrpriv->wowlan_ap_mode)
1968                                 rtl8723b_set_AP_FwRsvdPagePkt(padapter, 0);
1969                         else
1970                                 rtl8723b_set_FwRsvdPagePkt(padapter, 0);
1971 #else
1972                         /*  download rsvd page. */
1973                         rtl8723b_set_FwRsvdPagePkt(padapter, 0);
1974 #endif
1975                         DLBcnCount++;
1976                         do {
1977                                 yield();
1978                                 /* mdelay(10); */
1979                                 /*  check rsvd page download OK. */
1980                                 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid));
1981                                 poll++;
1982                         } while (!bcn_valid && (poll%10) != 0 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
1983 
1984                 } while (!bcn_valid && DLBcnCount <= 100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
1985 
1986                 if (padapter->bSurpriseRemoved || padapter->bDriverStopped) {
1987                 } else if (!bcn_valid)
1988                         DBG_871X(ADPT_FMT": 1 DL RSVD page failed! DLBcnCount:%u, poll:%u\n",
1989                                 ADPT_ARG(padapter), DLBcnCount, poll);
1990                 else {
1991                         struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
1992                         pwrctl->fw_psmode_iface_id = padapter->iface_id;
1993                         DBG_871X(ADPT_FMT": 1 DL RSVD page success! DLBcnCount:%u, poll:%u\n",
1994                                 ADPT_ARG(padapter), DLBcnCount, poll);
1995                 }
1996 
1997                 /*  2010.05.11. Added by tynli. */
1998                 val8 = rtw_read8(padapter, REG_BCN_CTRL);
1999                 val8 |= EN_BCN_FUNCTION;
2000                 val8 &= ~DIS_TSF_UDT;
2001                 rtw_write8(padapter, REG_BCN_CTRL, val8);
2002 
2003                 /*  To make sure that if there exists an adapter which would like to send beacon. */
2004                 /*  If exists, the origianl value of 0x422[6] will be 1, we should check this to */
2005                 /*  prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */
2006                 /*  the beacon cannot be sent by HW. */
2007                 /*  2010.06.23. Added by tynli. */
2008                 if (bRecover) {
2009                         rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl | BIT(6));
2010                         pHalData->RegFwHwTxQCtrl |= BIT(6);
2011                 }
2012 
2013                 /*  Clear CR[8] or beacon packet will not be send to TxBuf anymore. */
2014                 v8 = rtw_read8(padapter, REG_CR+1);
2015                 v8 &= ~BIT(0); /*  ~ENSWBCN */
2016                 rtw_write8(padapter, REG_CR+1, v8);
2017         }
2018 }
2019 
2020 void rtl8723b_set_FwJoinBssRpt_cmd(struct adapter *padapter, u8 mstatus)
2021 {
2022         if (mstatus == 1)
2023                 rtl8723b_download_rsvd_page(padapter, RT_MEDIA_CONNECT);
2024 }
2025 
2026 /* arg[0] = macid */
2027 /* arg[1] = raid */
2028 /* arg[2] = shortGIrate */
2029 /* arg[3] = init_rate */
2030 void rtl8723b_Add_RateATid(
2031         struct adapter *padapter,
2032         u32 bitmap,
2033         u8 *arg,
2034         u8 rssi_level
2035 )
2036 {
2037         struct hal_com_data     *pHalData = GET_HAL_DATA(padapter);
2038         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2039         struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2040         struct sta_info *psta;
2041         u8 mac_id = arg[0];
2042         u8 raid = arg[1];
2043         u8 shortGI = arg[2];
2044         u8 bw;
2045         u32 mask = bitmap&0x0FFFFFFF;
2046 
2047         psta = pmlmeinfo->FW_sta_info[mac_id].psta;
2048         if (!psta)
2049                 return;
2050 
2051         bw = psta->bw_mode;
2052 
2053         if (rssi_level != DM_RATR_STA_INIT)
2054                 mask = ODM_Get_Rate_Bitmap(&pHalData->odmpriv, mac_id, mask, rssi_level);
2055 
2056         DBG_871X("%s(): mac_id =%d raid = 0x%x bw =%d mask = 0x%x\n", __func__, mac_id, raid, bw, mask);
2057         rtl8723b_set_FwMacIdConfig_cmd(padapter, mac_id, raid, bw, shortGI, mask);
2058 }
2059 
2060 static void ConstructBtNullFunctionData(
2061         struct adapter *padapter,
2062         u8 *pframe,
2063         u32 *pLength,
2064         u8 *StaAddr,
2065         u8 bQoS,
2066         u8 AC,
2067         u8 bEosp,
2068         u8 bForcePowerSave
2069 )
2070 {
2071         struct ieee80211_hdr *pwlanhdr;
2072         __le16 *fctrl;
2073         u32 pktlen;
2074         struct mlme_ext_priv *pmlmeext;
2075         struct mlme_ext_info *pmlmeinfo;
2076         u8 bssid[ETH_ALEN];
2077 
2078 
2079         DBG_871X("+" FUNC_ADPT_FMT ": qos =%d eosp =%d ps =%d\n",
2080                 FUNC_ADPT_ARG(padapter), bQoS, bEosp, bForcePowerSave);
2081 
2082         pwlanhdr = (struct ieee80211_hdr *)pframe;
2083         pmlmeext = &padapter->mlmeextpriv;
2084         pmlmeinfo = &pmlmeext->mlmext_info;
2085 
2086         if (!StaAddr) {
2087                 memcpy(bssid, myid(&padapter->eeprompriv), ETH_ALEN);
2088                 StaAddr = bssid;
2089         }
2090 
2091         fctrl = &pwlanhdr->frame_control;
2092         *fctrl = 0;
2093         if (bForcePowerSave)
2094                 SetPwrMgt(fctrl);
2095 
2096         SetFrDs(fctrl);
2097         memcpy(pwlanhdr->addr1, StaAddr, ETH_ALEN);
2098         memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
2099         memcpy(pwlanhdr->addr3, myid(&padapter->eeprompriv), ETH_ALEN);
2100 
2101         SetDuration(pwlanhdr, 0);
2102         SetSeqNum(pwlanhdr, 0);
2103 
2104         if (bQoS) {
2105                 struct ieee80211_qos_hdr *pwlanqoshdr;
2106 
2107                 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
2108 
2109                 pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe;
2110                 SetPriority(&pwlanqoshdr->qos_ctrl, AC);
2111                 SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp);
2112 
2113                 pktlen = sizeof(struct ieee80211_qos_hdr);
2114         } else {
2115                 SetFrameSubType(pframe, WIFI_DATA_NULL);
2116 
2117                 pktlen = sizeof(struct ieee80211_hdr_3addr);
2118         }
2119 
2120         *pLength = pktlen;
2121 }
2122 
2123 static void SetFwRsvdPagePkt_BTCoex(struct adapter *padapter)
2124 {
2125         struct hal_com_data *pHalData;
2126         struct xmit_frame *pcmdframe;
2127         struct pkt_attrib *pattrib;
2128         struct xmit_priv *pxmitpriv;
2129         struct mlme_ext_priv *pmlmeext;
2130         struct mlme_ext_info *pmlmeinfo;
2131         u32 BeaconLength = 0;
2132         u32 BTQosNullLength = 0;
2133         u8 *ReservedPagePacket;
2134         u8 TxDescLen, TxDescOffset;
2135         u8 TotalPageNum = 0, CurtPktPageNum = 0, RsvdPageNum = 0;
2136         u16 BufIndex, PageSize;
2137         u32 TotalPacketLen, MaxRsvdPageBufSize = 0;
2138         RSVDPAGE_LOC RsvdPageLoc;
2139 
2140 
2141 /*      DBG_8192C("+" FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(padapter)); */
2142 
2143         pHalData = GET_HAL_DATA(padapter);
2144         pxmitpriv = &padapter->xmitpriv;
2145         pmlmeext = &padapter->mlmeextpriv;
2146         pmlmeinfo = &pmlmeext->mlmext_info;
2147         TxDescLen = TXDESC_SIZE;
2148         TxDescOffset = TXDESC_OFFSET;
2149         PageSize = PAGE_SIZE_TX_8723B;
2150 
2151         RsvdPageNum = BCNQ_PAGE_NUM_8723B;
2152         MaxRsvdPageBufSize = RsvdPageNum*PageSize;
2153 
2154         pcmdframe = rtw_alloc_cmdxmitframe(pxmitpriv);
2155         if (!pcmdframe) {
2156                 DBG_8192C("%s: alloc ReservedPagePacket fail!\n", __func__);
2157                 return;
2158         }
2159 
2160         ReservedPagePacket = pcmdframe->buf_addr;
2161         memset(&RsvdPageLoc, 0, sizeof(RSVDPAGE_LOC));
2162 
2163         /* 3 (1) beacon */
2164         BufIndex = TxDescOffset;
2165         ConstructBeacon(padapter, &ReservedPagePacket[BufIndex], &BeaconLength);
2166 
2167         /*  When we count the first page size, we need to reserve description size for the RSVD */
2168         /*  packet, it will be filled in front of the packet in TXPKTBUF. */
2169         CurtPktPageNum = (u8)PageNum_128(TxDescLen + BeaconLength);
2170         /* If we don't add 1 more page, the WOWLAN function has a problem. Baron thinks it's a bug of firmware */
2171         if (CurtPktPageNum == 1)
2172                 CurtPktPageNum += 1;
2173         TotalPageNum += CurtPktPageNum;
2174 
2175         BufIndex += (CurtPktPageNum*PageSize);
2176 
2177         /*  Jump to lastest page */
2178         if (BufIndex < (MaxRsvdPageBufSize - PageSize)) {
2179                 BufIndex = TxDescOffset + (MaxRsvdPageBufSize - PageSize);
2180                 TotalPageNum = BCNQ_PAGE_NUM_8723B - 1;
2181         }
2182 
2183         /* 3 (6) BT Qos null data */
2184         RsvdPageLoc.LocBTQosNull = TotalPageNum;
2185         ConstructBtNullFunctionData(
2186                 padapter,
2187                 &ReservedPagePacket[BufIndex],
2188                 &BTQosNullLength,
2189                 NULL,
2190                 true, 0, 0, false
2191         );
2192         rtl8723b_fill_fake_txdesc(padapter, &ReservedPagePacket[BufIndex-TxDescLen], BTQosNullLength, false, true, false);
2193 
2194         CurtPktPageNum = (u8)PageNum_128(TxDescLen + BTQosNullLength);
2195 
2196         TotalPageNum += CurtPktPageNum;
2197 
2198         TotalPacketLen = BufIndex + BTQosNullLength;
2199         if (TotalPacketLen > MaxRsvdPageBufSize) {
2200                 DBG_8192C(FUNC_ADPT_FMT ": ERROR: The rsvd page size is not enough!!TotalPacketLen %d, MaxRsvdPageBufSize %d\n",
2201                         FUNC_ADPT_ARG(padapter), TotalPacketLen, MaxRsvdPageBufSize);
2202                 goto error;
2203         }
2204 
2205         /*  update attribute */
2206         pattrib = &pcmdframe->attrib;
2207         update_mgntframe_attrib(padapter, pattrib);
2208         pattrib->qsel = 0x10;
2209         pattrib->pktlen = pattrib->last_txcmdsz = TotalPacketLen - TxDescOffset;
2210         dump_mgntframe_and_wait(padapter, pcmdframe, 100);
2211 
2212 /*      DBG_8192C(FUNC_ADPT_FMT ": Set RSVD page location to Fw, TotalPacketLen(%d), TotalPageNum(%d)\n", */
2213 /*              FUNC_ADPT_ARG(padapter), TotalPacketLen, TotalPageNum); */
2214         rtl8723b_set_FwRsvdPage_cmd(padapter, &RsvdPageLoc);
2215         rtl8723b_set_FwAoacRsvdPage_cmd(padapter, &RsvdPageLoc);
2216 
2217         return;
2218 
2219 error:
2220         rtw_free_xmitframe(pxmitpriv, pcmdframe);
2221 }
2222 
2223 void rtl8723b_download_BTCoex_AP_mode_rsvd_page(struct adapter *padapter)
2224 {
2225         struct hal_com_data *pHalData;
2226         struct mlme_ext_priv *pmlmeext;
2227         struct mlme_ext_info *pmlmeinfo;
2228         u8 bRecover = false;
2229         u8 bcn_valid = false;
2230         u8 DLBcnCount = 0;
2231         u32 poll = 0;
2232         u8 val8;
2233 
2234 
2235         DBG_8192C("+" FUNC_ADPT_FMT ": iface_type =%d fw_state = 0x%08X\n",
2236                 FUNC_ADPT_ARG(padapter), get_iface_type(padapter), get_fwstate(&padapter->mlmepriv));
2237 
2238 #ifdef DEBUG
2239         if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == false) {
2240                 DBG_8192C(FUNC_ADPT_FMT ": [WARNING] not in AP mode!!\n",
2241                         FUNC_ADPT_ARG(padapter));
2242         }
2243 #endif /*  DEBUG */
2244 
2245         pHalData = GET_HAL_DATA(padapter);
2246         pmlmeext = &padapter->mlmeextpriv;
2247         pmlmeinfo = &pmlmeext->mlmext_info;
2248 
2249         /*  We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */
2250         /*  Suggested by filen. Added by tynli. */
2251         rtw_write16(padapter, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid));
2252 
2253         /*  set REG_CR bit 8 */
2254         val8 = rtw_read8(padapter, REG_CR+1);
2255         val8 |= BIT(0); /*  ENSWBCN */
2256         rtw_write8(padapter,  REG_CR+1, val8);
2257 
2258         /*  Disable Hw protection for a time which revserd for Hw sending beacon. */
2259         /*  Fix download reserved page packet fail that access collision with the protection time. */
2260         /*  2010.05.11. Added by tynli. */
2261         val8 = rtw_read8(padapter, REG_BCN_CTRL);
2262         val8 &= ~EN_BCN_FUNCTION;
2263         val8 |= DIS_TSF_UDT;
2264         rtw_write8(padapter, REG_BCN_CTRL, val8);
2265 
2266         /*  Set FWHW_TXQ_CTRL 0x422[6]= 0 to tell Hw the packet is not a real beacon frame. */
2267         if (pHalData->RegFwHwTxQCtrl & BIT(6))
2268                 bRecover = true;
2269 
2270         /*  To tell Hw the packet is not a real beacon frame. */
2271         pHalData->RegFwHwTxQCtrl &= ~BIT(6);
2272         rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl);
2273 
2274         /*  Clear beacon valid check bit. */
2275         rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
2276         rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
2277 
2278         DLBcnCount = 0;
2279         poll = 0;
2280         do {
2281                 SetFwRsvdPagePkt_BTCoex(padapter);
2282                 DLBcnCount++;
2283                 do {
2284                         yield();
2285 /*                      mdelay(10); */
2286                         /*  check rsvd page download OK. */
2287                         rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, &bcn_valid);
2288                         poll++;
2289                 } while (!bcn_valid && (poll%10) != 0 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
2290         } while (!bcn_valid && (DLBcnCount <= 100) && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
2291 
2292         if (bcn_valid) {
2293                 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
2294                 pwrctl->fw_psmode_iface_id = padapter->iface_id;
2295                 DBG_8192C(ADPT_FMT": DL RSVD page success! DLBcnCount:%d, poll:%d\n",
2296                         ADPT_ARG(padapter), DLBcnCount, poll);
2297         } else {
2298                 DBG_8192C(ADPT_FMT": DL RSVD page fail! DLBcnCount:%d, poll:%d\n",
2299                         ADPT_ARG(padapter), DLBcnCount, poll);
2300                 DBG_8192C(ADPT_FMT": DL RSVD page fail! bSurpriseRemoved =%d\n",
2301                         ADPT_ARG(padapter), padapter->bSurpriseRemoved);
2302                 DBG_8192C(ADPT_FMT": DL RSVD page fail! bDriverStopped =%d\n",
2303                         ADPT_ARG(padapter), padapter->bDriverStopped);
2304         }
2305 
2306         /*  2010.05.11. Added by tynli. */
2307         val8 = rtw_read8(padapter, REG_BCN_CTRL);
2308         val8 |= EN_BCN_FUNCTION;
2309         val8 &= ~DIS_TSF_UDT;
2310         rtw_write8(padapter, REG_BCN_CTRL, val8);
2311 
2312         /*  To make sure that if there exists an adapter which would like to send beacon. */
2313         /*  If exists, the origianl value of 0x422[6] will be 1, we should check this to */
2314         /*  prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */
2315         /*  the beacon cannot be sent by HW. */
2316         /*  2010.06.23. Added by tynli. */
2317         if (bRecover) {
2318                 pHalData->RegFwHwTxQCtrl |= BIT(6);
2319                 rtw_write8(padapter, REG_FWHW_TXQ_CTRL+2, pHalData->RegFwHwTxQCtrl);
2320         }
2321 
2322         /*  Clear CR[8] or beacon packet will not be send to TxBuf anymore. */
2323         val8 = rtw_read8(padapter, REG_CR+1);
2324         val8 &= ~BIT(0); /*  ~ENSWBCN */
2325         rtw_write8(padapter, REG_CR+1, val8);
2326 }

/* [<][>][^][v][top][bottom][index][help] */