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