OSDN Git Service

Remove more non Linux gibberish
[android-x86/external-modules-rtl8723au.git] / os_dep / ioctl_cfg80211.c
old mode 100755 (executable)
new mode 100644 (file)
index a12a5d9..c7eee1b
@@ -24,7 +24,6 @@
 #include <drv_types.h>
 #include <rtw_ioctl.h>
 #include <rtw_ioctl_set.h>
-#include <rtw_ioctl_query.h>
 #include <xmit_osdep.h>
 
 #ifdef CONFIG_IOCTL_CFG80211
@@ -169,12 +168,12 @@ struct ieee80211_supported_band *rtw_spt_band_alloc(
        struct ieee80211_supported_band *spt_band = NULL;
        int n_channels, n_bitrates;
 
-       if (band == IEEE80211_BAND_2GHZ)
+       if(band == IEEE80211_BAND_2GHZ)
        {
                n_channels = RTW_2G_CHANNELS_NUM;
                n_bitrates = RTW_G_RATES_NUM;
        }
-       else if (band == IEEE80211_BAND_5GHZ)
+       else if(band == IEEE80211_BAND_5GHZ)
        {
                n_channels = RTW_5G_CHANNELS_NUM;
                n_bitrates = RTW_A_RATES_NUM;
@@ -184,12 +183,11 @@ struct ieee80211_supported_band *rtw_spt_band_alloc(
                goto exit;
        }
 
-       spt_band = (struct ieee80211_supported_band *)rtw_zmalloc(
-               sizeof(struct ieee80211_supported_band)
-               + sizeof(struct ieee80211_channel)*n_channels
-               + sizeof(struct ieee80211_rate)*n_bitrates
-       );
-       if (!spt_band)
+       spt_band = (struct ieee80211_supported_band *)
+               kzalloc(sizeof(struct ieee80211_supported_band) +
+                       sizeof(struct ieee80211_channel)*n_channels +
+                       sizeof(struct ieee80211_rate)*n_bitrates, GFP_KERNEL);
+       if(!spt_band)
                goto exit;
 
        spt_band->channels = (struct ieee80211_channel*)(((u8*)spt_band)+sizeof(struct ieee80211_supported_band));
@@ -198,12 +196,12 @@ struct ieee80211_supported_band *rtw_spt_band_alloc(
        spt_band->n_channels = n_channels;
        spt_band->n_bitrates = n_bitrates;
 
-       if (band == IEEE80211_BAND_2GHZ)
+       if(band == IEEE80211_BAND_2GHZ)
        {
                rtw_2g_channels_init(spt_band->channels);
                rtw_2g_rates_init(spt_band->bitrates);
        }
-       else if (band == IEEE80211_BAND_5GHZ)
+       else if(band == IEEE80211_BAND_5GHZ)
        {
                rtw_5g_channels_init(spt_band->channels);
                rtw_5g_rates_init(spt_band->bitrates);
@@ -220,16 +218,16 @@ void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
 {
        u32 size;
 
-       if (!spt_band)
+       if(!spt_band)
                return;
 
-       if (spt_band->band == IEEE80211_BAND_2GHZ)
+       if(spt_band->band == IEEE80211_BAND_2GHZ)
        {
                size = sizeof(struct ieee80211_supported_band)
                        + sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
                        + sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM;
        }
-       else if (spt_band->band == IEEE80211_BAND_5GHZ)
+       else if(spt_band->band == IEEE80211_BAND_5GHZ)
        {
                size = sizeof(struct ieee80211_supported_band)
                        + sizeof(struct ieee80211_channel)*RTW_5G_CHANNELS_NUM
@@ -239,7 +237,7 @@ void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
        {
 
        }
-       rtw_mfree((u8*)spt_band, size);
+       kfree(spt_band);
 }
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
@@ -313,6 +311,7 @@ static int rtw_ieee80211_channel_to_frequency(int chan, int band)
        }
 }
 
+#define MAX_BSSINFO_LEN 1000
 static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnetwork)
 {
        int ret=0;
@@ -327,8 +326,8 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
        u8 *notify_ie;
        size_t notify_ielen;
        s32 notify_signal;
-       u8 buf[768], *pbuf;
-       size_t len;
+       u8 buf[MAX_BSSINFO_LEN], *pbuf;
+       size_t len,bssinf_len=0;
        struct rtw_ieee80211_hdr *pwlanhdr;
        unsigned short *fctrl;
        u8      bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@ -338,8 +337,13 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
 
-       //DBG_8192C("%s\n", __func__);
+       //DBG_8723A("%s\n", __func__);
 
+       bssinf_len = pnetwork->network.IELength+sizeof (struct rtw_ieee80211_hdr_3addr);
+       if(bssinf_len > MAX_BSSINFO_LEN){
+               DBG_8723A("%s IE Length too long > %d byte \n",__FUNCTION__,MAX_BSSINFO_LEN);
+               goto exit;
+       }
 
        channel = pnetwork->network.Configuration.DSConfig;
        if (channel <= RTW_CH_MAX_2G_CHANNEL)
@@ -360,7 +364,7 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
        notify_ielen = pnetwork->network.IELength-_FIXED_IE_LENGTH_;
 
        //We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm)
-       if ( check_fwstate(pmlmepriv, _FW_LINKED)== true &&
+       if ( check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE &&
                is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network)) {
                notify_signal = 100*translate_percentage_to_dbm(padapter->recvpriv.signal_strength);//dbm
        } else {
@@ -368,17 +372,18 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
        }
 
 /*
-       DBG_8192C("bssid: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+       DBG_8723A("bssid: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
                         pnetwork->network.MacAddress[0], pnetwork->network.MacAddress[1], pnetwork->network.MacAddress[2],
                         pnetwork->network.MacAddress[3], pnetwork->network.MacAddress[4], pnetwork->network.MacAddress[5]);
-       DBG_8192C("Channel: %d(%d)\n", channel, freq);
-       DBG_8192C("Capability: %X\n", notify_capability);
-       DBG_8192C("Beacon interval: %d\n", notify_interval);
-       DBG_8192C("Signal: %d\n", notify_signal);
-       DBG_8192C("notify_timestamp: %#018llx\n", notify_timestamp);
+       DBG_8723A("Channel: %d(%d)\n", channel, freq);
+       DBG_8723A("Capability: %X\n", notify_capability);
+       DBG_8723A("Beacon interval: %d\n", notify_interval);
+       DBG_8723A("Signal: %d\n", notify_signal);
+       DBG_8723A("notify_timestamp: %#018llx\n", notify_timestamp);
 */
 
        pbuf = buf;
+
        pwlanhdr = (struct rtw_ieee80211_hdr *)pbuf;
        fctrl = &(pwlanhdr->frame_ctl);
        *(fctrl) = 0;
@@ -405,9 +410,9 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
        len += pnetwork->network.IELength;
 
        //#ifdef CONFIG_P2P
-       //if (rtw_get_p2p_ie(pnetwork->network.IEs+12, pnetwork->network.IELength-12, NULL, NULL))
+       //if(rtw_get_p2p_ie(pnetwork->network.IEs+12, pnetwork->network.IELength-12, NULL, NULL))
        //{
-       //      DBG_8192C("%s, got p2p_ie\n", __func__);
+       //      DBG_8723A("%s, got p2p_ie\n", __func__);
        //}
        //#endif
 
@@ -423,7 +428,7 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
 #endif
 
        if (unlikely(!bss)) {
-               DBG_8192C("rtw_cfg80211_inform_bss error\n");
+               DBG_8723A("rtw_cfg80211_inform_bss error\n");
                return -EINVAL;
        }
 
@@ -432,7 +437,7 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
        //patch for cfg80211, update beacon ies to information_elements
        if (pnetwork->network.Reserved[0] == 1) { // WIFI_BEACON
 
-                if (bss->len_information_elements != bss->len_beacon_ies)
+                if(bss->len_information_elements != bss->len_beacon_ies)
                 {
                        bss->information_elements = bss->beacon_ies;
                        bss->len_information_elements =  bss->len_beacon_ies;
@@ -443,15 +448,15 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
 
 /*
        {
-               if ( bss->information_elements == bss->proberesp_ies)
+               if( bss->information_elements == bss->proberesp_ies)
                {
-                       if ( bss->len_information_elements !=  bss->len_proberesp_ies)
+                       if( bss->len_information_elements !=  bss->len_proberesp_ies)
                        {
-                               DBG_8192C("error!, len_information_elements !=  bss->len_proberesp_ies\n");
+                               DBG_8723A("error!, len_information_elements !=  bss->len_proberesp_ies\n");
                        }
 
                }
-               else if (bss->len_information_elements <  bss->len_beacon_ies)
+               else if(bss->len_information_elements <  bss->len_beacon_ies)
                {
                        bss->information_elements = bss->beacon_ies;
                        bss->len_information_elements =  bss->len_beacon_ies;
@@ -461,6 +466,7 @@ static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnet
 
        cfg80211_put_bss(bss);
 
+exit:
        return ret;
 
 }
@@ -475,7 +481,7 @@ void rtw_cfg80211_indicate_connect(_adapter *padapter)
 #endif
 
 
-       DBG_8192C("%s(padapter=%p)\n", __func__, padapter);
+       DBG_8723A("%s(padapter=%p)\n", __func__, padapter);
 
        if (pwdev->iftype != NL80211_IFTYPE_STATION
                #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
@@ -485,21 +491,21 @@ void rtw_cfg80211_indicate_connect(_adapter *padapter)
                return;
        }
 
-       if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
+       if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
                return;
 
 #ifdef CONFIG_P2P
-       if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+       if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
        {
                rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
                rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
                rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
-               DBG_8192C("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
+               DBG_8723A("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
        }
 #endif //CONFIG_P2P
 
        #ifdef CONFIG_LAYER2_ROAMING
-       if (pmlmepriv->to_roaming > 0) {
+       if (rtw_to_roaming(padapter) > 0) {
                #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
                struct wiphy *wiphy = pwdev->wiphy;
                struct ieee80211_channel *notify_channel;
@@ -514,7 +520,7 @@ void rtw_cfg80211_indicate_connect(_adapter *padapter)
                notify_channel = ieee80211_get_channel(wiphy, freq);
                #endif
 
-               DBG_871X("%s call cfg80211_roamed\n", __FUNCTION__);
+               DBG_8723A("%s call cfg80211_roamed\n", __FUNCTION__);
                cfg80211_roamed(padapter->pnetdev
                        #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
                        , notify_channel
@@ -529,14 +535,14 @@ void rtw_cfg80211_indicate_connect(_adapter *padapter)
        else
        #endif
        {
-               DBG_8192C("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
+               DBG_8723A("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
                cfg80211_connect_result(padapter->pnetdev, cur_network->network.MacAddress
                        , pmlmepriv->assoc_req+sizeof(struct rtw_ieee80211_hdr_3addr)+2
                        , pmlmepriv->assoc_req_len-sizeof(struct rtw_ieee80211_hdr_3addr)-2
                        , pmlmepriv->assoc_rsp+sizeof(struct rtw_ieee80211_hdr_3addr)+6
                        , pmlmepriv->assoc_rsp_len-sizeof(struct rtw_ieee80211_hdr_3addr)-6
                        , WLAN_STATUS_SUCCESS, GFP_ATOMIC);
-               DBG_8192C("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
+               DBG_8723A("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
        }
 }
 
@@ -548,7 +554,7 @@ void rtw_cfg80211_indicate_disconnect(_adapter *padapter)
        struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
 #endif
 
-       DBG_8192C("%s(padapter=%p)\n", __func__, padapter);
+       DBG_8723A("%s(padapter=%p)\n", __func__, padapter);
 
        if (pwdev->iftype != NL80211_IFTYPE_STATION
                #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
@@ -558,11 +564,11 @@ void rtw_cfg80211_indicate_disconnect(_adapter *padapter)
                return;
        }
 
-       if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
+       if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
                return;
 
 #ifdef CONFIG_P2P
-       if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+       if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
        {
                _cancel_timer_ex( &pwdinfo->find_phase_timer );
                _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
@@ -571,23 +577,22 @@ void rtw_cfg80211_indicate_disconnect(_adapter *padapter)
                rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
                rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
 
-               DBG_8192C("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
+               DBG_8723A("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
        }
 #endif //CONFIG_P2P
 
        if (!padapter->mlmepriv.not_indic_disco) {
-               DBG_8192C("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
+               DBG_8723A("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
 
-               if (pwdev->sme_state==CFG80211_SME_CONNECTING)
+               if(pwdev->sme_state==CFG80211_SME_CONNECTING)
                        cfg80211_connect_result(padapter->pnetdev, NULL, NULL, 0, NULL, 0,
-                                                               WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/);
-               else if (pwdev->sme_state==CFG80211_SME_CONNECTED)
-                       cfg80211_disconnected(padapter->pnetdev, 0,
-                                                               NULL, 0, GFP_ATOMIC);
+                               WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/);
+               else if(pwdev->sme_state==CFG80211_SME_CONNECTED)
+                       cfg80211_disconnected(padapter->pnetdev, 0, NULL, 0, GFP_ATOMIC);
                //else
-                       //DBG_8192C("pwdev->sme_state=%d\n", pwdev->sme_state);
+                       //DBG_8723A("pwdev->sme_state=%d\n", pwdev->sme_state);
 
-               DBG_8192C("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
+               DBG_8723A("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
        }
 }
 
@@ -600,15 +605,16 @@ static u8 set_pairwise_key(_adapter *padapter, struct sta_info *psta)
        struct cmd_priv                         *pcmdpriv=&padapter->cmdpriv;
        u8      res=_SUCCESS;
 
-       ph2c = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
+       ph2c = (struct cmd_obj*)kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
        if ( ph2c == NULL){
                res= _FAIL;
                goto exit;
        }
 
-       psetstakey_para = (struct set_stakey_parm*)rtw_zmalloc(sizeof(struct set_stakey_parm));
-       if (psetstakey_para==NULL){
-               rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
+       psetstakey_para = (struct set_stakey_parm*)
+               kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL);
+       if(psetstakey_para==NULL){
+               kfree(ph2c);
                res=_FAIL;
                goto exit;
        }
@@ -639,16 +645,17 @@ static int set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
        struct cmd_priv *pcmdpriv=&(padapter->cmdpriv);
        int res=_SUCCESS;
 
-       DBG_8192C("%s\n", __FUNCTION__);
+       DBG_8723A("%s\n", __FUNCTION__);
 
-       pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct       cmd_obj));
-       if (pcmd==NULL){
+       pcmd = (struct cmd_obj*)kzalloc(sizeof(struct   cmd_obj), GFP_KERNEL);
+       if(pcmd==NULL){
                res= _FAIL;
                goto exit;
        }
-       psetkeyparm=(struct setkey_parm*)rtw_zmalloc(sizeof(struct setkey_parm));
-       if (psetkeyparm==NULL){
-               rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
+       psetkeyparm=(struct setkey_parm*)
+               kzalloc(sizeof(struct setkey_parm), GFP_KERNEL);
+       if(psetkeyparm==NULL){
+               kfree(pcmd);
                res= _FAIL;
                goto exit;
        }
@@ -656,12 +663,14 @@ static int set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
        memset(psetkeyparm, 0, sizeof(struct setkey_parm));
 
        psetkeyparm->keyid=(u8)keyid;
+       if (is_wep_enc(alg))
+               padapter->mlmepriv.key_mask |= BIT(psetkeyparm->keyid);
 
        psetkeyparm->algorithm = alg;
 
        psetkeyparm->set_tx = 1;
 
-       switch (alg)
+       switch(alg)
        {
                case _WEP40_:
                        keylen = 5;
@@ -701,7 +710,7 @@ static int set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid)
 {
        u8 alg;
 
-       switch (keylen)
+       switch(keylen)
        {
                case 5:
                        alg =_WEP40_;
@@ -727,7 +736,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
        struct security_priv* psecuritypriv=&(padapter->securitypriv);
        struct sta_priv *pstapriv = &padapter->stapriv;
 
-       DBG_8192C("%s\n", __FUNCTION__);
+       DBG_8723A("%s\n", __FUNCTION__);
 
        param->u.crypt.err = 0;
        param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
@@ -753,10 +762,10 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
        else
        {
                psta = rtw_get_stainfo(pstapriv, param->sta_addr);
-               if (!psta)
+               if(!psta)
                {
                        //ret = -EINVAL;
-                       DBG_8192C("rtw_set_encryption(), sta has already been removed or never been added\n");
+                       DBG_8723A("rtw_set_encryption(), sta has already been removed or never been added\n");
                        goto exit;
                }
        }
@@ -765,7 +774,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
        {
                //todo:clear default encryption keys
 
-               DBG_8192C("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
+               DBG_8723A("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
 
                goto exit;
        }
@@ -773,14 +782,14 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
 
        if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta==NULL))
        {
-               DBG_8192C("r871x_set_encryption, crypt.alg = WEP\n");
+               DBG_8723A("r871x_set_encryption, crypt.alg = WEP\n");
 
                wep_key_idx = param->u.crypt.idx;
                wep_key_len = param->u.crypt.key_len;
 
-               DBG_8192C("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
+               DBG_8723A("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
 
-               if ((wep_key_idx >= WEP_KEYS) || (wep_key_len<=0))
+               if((wep_key_idx >= WEP_KEYS) || (wep_key_len<=0))
                {
                        ret = -EINVAL;
                        goto exit;
@@ -799,7 +808,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
                        psecuritypriv->dot11PrivacyAlgrthm=_WEP40_;
                        psecuritypriv->dot118021XGrpPrivacy=_WEP40_;
 
-                       if (wep_key_len == 13)
+                       if(wep_key_len == 13)
                        {
                                psecuritypriv->dot11PrivacyAlgrthm=_WEP104_;
                                psecuritypriv->dot118021XGrpPrivacy=_WEP104_;
@@ -819,26 +828,26 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
        }
 
 
-       if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) // //group key
+       if(!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) // //group key
        {
-               if (param->u.crypt.set_tx == 0) //group key
+               if(param->u.crypt.set_tx == 0) //group key
                {
-                       if (strcmp(param->u.crypt.alg, "WEP") == 0)
+                       if(strcmp(param->u.crypt.alg, "WEP") == 0)
                        {
-                               DBG_8192C("%s, set group_key, WEP\n", __FUNCTION__);
+                               DBG_8723A("%s, set group_key, WEP\n", __FUNCTION__);
 
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
 
                                psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
-                               if (param->u.crypt.key_len==13)
+                               if(param->u.crypt.key_len==13)
                                {
                                                psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
                                }
 
                        }
-                       else if (strcmp(param->u.crypt.alg, "TKIP") == 0)
+                       else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
                        {
-                               DBG_8192C("%s, set group_key, TKIP\n", __FUNCTION__);
+                               DBG_8723A("%s, set group_key, TKIP\n", __FUNCTION__);
 
                                psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
 
@@ -849,12 +858,12 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
                                memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
                                memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
 
-                               psecuritypriv->busetkipkey = true;
+                               psecuritypriv->busetkipkey = _TRUE;
 
                        }
-                       else if (strcmp(param->u.crypt.alg, "CCMP") == 0)
+                       else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
                        {
-                               DBG_8192C("%s, set group_key, CCMP\n", __FUNCTION__);
+                               DBG_8723A("%s, set group_key, CCMP\n", __FUNCTION__);
 
                                psecuritypriv->dot118021XGrpPrivacy = _AES_;
 
@@ -862,23 +871,23 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
                        }
                        else
                        {
-                               DBG_8192C("%s, set group_key, none\n", __FUNCTION__);
+                               DBG_8723A("%s, set group_key, none\n", __FUNCTION__);
 
                                psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
                        }
 
                        psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
 
-                       psecuritypriv->binstallGrpkey = true;
+                       psecuritypriv->binstallGrpkey = _TRUE;
 
                        psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;//!!!
 
                        set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
 
                        pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
-                       if (pbcmc_sta)
+                       if(pbcmc_sta)
                        {
-                               pbcmc_sta->ieee8021x_blocked = false;
+                               pbcmc_sta->ieee8021x_blocked = _FALSE;
                                pbcmc_sta->dot118021XPrivacy= psecuritypriv->dot118021XGrpPrivacy;//rx will use bmc_sta's dot118021XPrivacy
                        }
 
@@ -888,27 +897,27 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
 
        }
 
-       if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) // psk/802_1x
+       if(psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) // psk/802_1x
        {
-               if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
+               if(check_fwstate(pmlmepriv, WIFI_AP_STATE))
                {
-                       if (param->u.crypt.set_tx ==1) //pairwise key
+                       if(param->u.crypt.set_tx ==1) //pairwise key
                        {
                                memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
 
-                               if (strcmp(param->u.crypt.alg, "WEP") == 0)
+                               if(strcmp(param->u.crypt.alg, "WEP") == 0)
                                {
-                                       DBG_8192C("%s, set pairwise key, WEP\n", __FUNCTION__);
+                                       DBG_8723A("%s, set pairwise key, WEP\n", __FUNCTION__);
 
                                        psta->dot118021XPrivacy = _WEP40_;
-                                       if (param->u.crypt.key_len==13)
+                                       if(param->u.crypt.key_len==13)
                                        {
                                                psta->dot118021XPrivacy = _WEP104_;
                                        }
                                }
-                               else if (strcmp(param->u.crypt.alg, "TKIP") == 0)
+                               else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
                                {
-                                       DBG_8192C("%s, set pairwise key, TKIP\n", __FUNCTION__);
+                                       DBG_8723A("%s, set pairwise key, TKIP\n", __FUNCTION__);
 
                                        psta->dot118021XPrivacy = _TKIP_;
 
@@ -917,43 +926,43 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
                                        memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
                                        memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
 
-                                       psecuritypriv->busetkipkey = true;
+                                       psecuritypriv->busetkipkey = _TRUE;
 
                                }
-                               else if (strcmp(param->u.crypt.alg, "CCMP") == 0)
+                               else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
                                {
 
-                                       DBG_8192C("%s, set pairwise key, CCMP\n", __FUNCTION__);
+                                       DBG_8723A("%s, set pairwise key, CCMP\n", __FUNCTION__);
 
                                        psta->dot118021XPrivacy = _AES_;
                                }
                                else
                                {
-                                       DBG_8192C("%s, set pairwise key, none\n", __FUNCTION__);
+                                       DBG_8723A("%s, set pairwise key, none\n", __FUNCTION__);
 
                                        psta->dot118021XPrivacy = _NO_PRIVACY_;
                                }
 
                                set_pairwise_key(padapter, psta);
 
-                               psta->ieee8021x_blocked = false;
+                               psta->ieee8021x_blocked = _FALSE;
 
-                               psta->bpairwise_key_installed = true;
+                               psta->bpairwise_key_installed = _TRUE;
 
                        }
                        else//group key???
                        {
-                               if (strcmp(param->u.crypt.alg, "WEP") == 0)
+                               if(strcmp(param->u.crypt.alg, "WEP") == 0)
                                {
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
 
                                        psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
-                                       if (param->u.crypt.key_len==13)
+                                       if(param->u.crypt.key_len==13)
                                        {
                                                psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
                                        }
                                }
-                               else if (strcmp(param->u.crypt.alg, "TKIP") == 0)
+                               else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
                                {
                                        psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
 
@@ -964,10 +973,10 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
                                        memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
                                        memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
 
-                                       psecuritypriv->busetkipkey = true;
+                                       psecuritypriv->busetkipkey = _TRUE;
 
                                }
-                               else if (strcmp(param->u.crypt.alg, "CCMP") == 0)
+                               else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
                                {
                                        psecuritypriv->dot118021XGrpPrivacy = _AES_;
 
@@ -980,16 +989,16 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa
 
                                psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
 
-                               psecuritypriv->binstallGrpkey = true;
+                               psecuritypriv->binstallGrpkey = _TRUE;
 
                                psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;//!!!
 
                                set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
 
                                pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
-                               if (pbcmc_sta)
+                               if(pbcmc_sta)
                                {
-                                       pbcmc_sta->ieee8021x_blocked = false;
+                                       pbcmc_sta->ieee8021x_blocked = _FALSE;
                                        pbcmc_sta->dot118021XPrivacy= psecuritypriv->dot118021XGrpPrivacy;//rx will use bmc_sta's dot118021XPrivacy
                                }
 
@@ -1019,7 +1028,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param
 
 _func_enter_;
 
-       DBG_8192C("%s\n", __func__);
+       DBG_8723A("%s\n", __func__);
 
        param->u.crypt.err = 0;
        param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
@@ -1052,7 +1061,7 @@ _func_enter_;
        if (strcmp(param->u.crypt.alg, "WEP") == 0)
        {
                RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("wpa_set_encryption, crypt.alg = WEP\n"));
-               DBG_8192C("wpa_set_encryption, crypt.alg = WEP\n");
+               DBG_8723A("wpa_set_encryption, crypt.alg = WEP\n");
 
                wep_key_idx = param->u.crypt.idx;
                wep_key_len = param->u.crypt.key_len;
@@ -1073,7 +1082,7 @@ _func_enter_;
                        psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
                        psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
 
-                       if (wep_key_len==13)
+                       if(wep_key_len==13)
                        {
                                psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
                                psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
@@ -1091,69 +1100,69 @@ _func_enter_;
                goto exit;
        }
 
-       if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) // 802_1x
+       if(padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) // 802_1x
        {
                struct sta_info * psta,*pbcmc_sta;
                struct sta_priv * pstapriv = &padapter->stapriv;
 
-               //DBG_8192C("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X\n", __func__);
+               //DBG_8723A("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X \n", __func__);
 
-               if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == true) //sta mode
+               if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) //sta mode
                {
                        psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
                        if (psta == NULL) {
-                               //DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail\n"));
-                               DBG_8192C("%s, : Obtain Sta_info fail\n", __func__);
+                               //DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail \n"));
+                               DBG_8723A("%s, : Obtain Sta_info fail \n", __func__);
                        }
                        else
                        {
                                //Jeff: don't disable ieee8021x_blocked while clearing key
                                if (strcmp(param->u.crypt.alg, "none") != 0)
-                                       psta->ieee8021x_blocked = false;
+                                       psta->ieee8021x_blocked = _FALSE;
 
 
-                               if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
+                               if((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
                                                (padapter->securitypriv.ndisencryptstatus ==  Ndis802_11Encryption3Enabled))
                                {
                                        psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
                                }
 
-                               if (param->u.crypt.set_tx ==1)//pairwise key
+                               if(param->u.crypt.set_tx ==1)//pairwise key
                                {
 
-                                       DBG_8192C("%s, : param->u.crypt.set_tx ==1\n", __func__);
+                                       DBG_8723A("%s, : param->u.crypt.set_tx ==1 \n", __func__);
 
                                        memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
 
-                                       if (strcmp(param->u.crypt.alg, "TKIP") == 0)//set mic key
+                                       if(strcmp(param->u.crypt.alg, "TKIP") == 0)//set mic key
                                        {
                                                //DEBUG_ERR(("\nset key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len));
                                                memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
                                                memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
 
-                                               padapter->securitypriv.busetkipkey=false;
+                                               padapter->securitypriv.busetkipkey=_FALSE;
                                                //_set_timer(&padapter->securitypriv.tkip_timer, 50);
                                        }
 
                                        //DEBUG_ERR((" param->u.crypt.key_len=%d\n",param->u.crypt.key_len));
-                                       DBG_871X(" ~~~~set sta key:unicastkey\n");
+                                       DBG_8723A(" ~~~~set sta key:unicastkey\n");
 
-                                       rtw_setstakey_cmd(padapter, (unsigned char *)psta, true);
+                                       rtw_setstakey_cmd(padapter, (unsigned char *)psta, _TRUE);
                                }
                                else//group key
                                {
                                        memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key,(param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
                                        memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[16]),8);
                                        memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[24]),8);
-                                        padapter->securitypriv.binstallGrpkey = true;
+                                        padapter->securitypriv.binstallGrpkey = _TRUE;
                                        //DEBUG_ERR((" param->u.crypt.key_len=%d\n", param->u.crypt.key_len));
-                                       DBG_871X(" ~~~~set sta key:groupkey\n");
+                                       DBG_8723A(" ~~~~set sta key:groupkey\n");
 
                                        padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
 
                                        rtw_set_key(padapter,&padapter->securitypriv,param->u.crypt.idx, 1);
 #ifdef CONFIG_P2P
-                                       if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
+                                       if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
                                        {
                                                rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
                                        }
@@ -1163,24 +1172,24 @@ _func_enter_;
                        }
 
                        pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
-                       if (pbcmc_sta==NULL)
+                       if(pbcmc_sta==NULL)
                        {
-                               //DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n"));
+                               //DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null \n"));
                        }
                        else
                        {
                                //Jeff: don't disable ieee8021x_blocked while clearing key
                                if (strcmp(param->u.crypt.alg, "none") != 0)
-                                       pbcmc_sta->ieee8021x_blocked = false;
+                                       pbcmc_sta->ieee8021x_blocked = _FALSE;
 
-                               if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
+                               if((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
                                                (padapter->securitypriv.ndisencryptstatus ==  Ndis802_11Encryption3Enabled))
                                {
                                        pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
                                }
                        }
                }
-               else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) //adhoc mode
+               else if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) //adhoc mode
                {
                }
        }
@@ -1194,11 +1203,11 @@ _func_enter_;
                u8                                      WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
                u8                                      WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
 
-               if (param->u.crypt.set_tx == 1)
+               if(param->u.crypt.set_tx == 1)
                {
                        list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
-                               if (_rtw_memcmp(pWapiSta->PeerMacAddr,param->sta_addr,6))
-                               {
+                               if (!memcmp(pWapiSta->PeerMacAddr,
+                                           param->sta_addr, 6)) {
                                        memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16);
 
                                        pWapiSta->wapiUsk.bSet = true;
@@ -1226,14 +1235,14 @@ _func_enter_;
                else
                {
                        list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
-                               if (_rtw_memcmp(pWapiSta->PeerMacAddr,get_bssid(pmlmepriv),6))
-                               {
+                               if (!memcmp(pWapiSta->PeerMacAddr,
+                                           get_bssid(pmlmepriv), 6)) {
                                        pWapiSta->wapiMsk.bSet = true;
                                        memcpy(pWapiSta->wapiMsk.dataKey,param->u.crypt.key,16);
                                        memcpy(pWapiSta->wapiMsk.micKey,param->u.crypt.key+16,16);
                                        pWapiSta->wapiMsk.keyId = param->u.crypt.idx ;
                                        pWapiSta->wapiMsk.bTxEnable = false;
-                                       if (!pWapiSta->bSetkeyOk)
+                                       if(!pWapiSta->bSetkeyOk)
                                                pWapiSta->bSetkeyOk = true;
                                        pWapiSta->bAuthenticateInProgress = false;
 
@@ -1254,7 +1263,7 @@ _func_enter_;
 
 exit:
 
-       DBG_8192C("%s, ret=%d\n", __func__, ret);
+       DBG_8723A("%s, ret=%d\n", __func__, ret);
 
        _func_exit_;
 
@@ -1277,17 +1286,17 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
        _adapter *padapter = wiphy_to_adapter(wiphy);
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
-       DBG_871X(FUNC_NDEV_FMT" adding key for %pM\n", FUNC_NDEV_ARG(ndev), mac_addr);
-       DBG_871X("cipher=0x%x\n", params->cipher);
-       DBG_871X("key_len=0x%x\n", params->key_len);
-       DBG_871X("seq_len=0x%x\n", params->seq_len);
-       DBG_871X("key_index=%d\n", key_index);
+       DBG_8723A(FUNC_NDEV_FMT" adding key for %pM\n", FUNC_NDEV_ARG(ndev), mac_addr);
+       DBG_8723A("cipher=0x%x\n", params->cipher);
+       DBG_8723A("key_len=0x%x\n", params->key_len);
+       DBG_8723A("seq_len=0x%x\n", params->seq_len);
+       DBG_8723A("key_index=%d\n", key_index);
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       DBG_871X("pairwise=%d\n", pairwise);
+       DBG_8723A("pairwise=%d\n", pairwise);
 #endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
 
        param_len = sizeof(struct ieee_param) + params->key_len;
-       param = (struct ieee_param *)rtw_malloc(param_len);
+       param = (struct ieee_param *)kmalloc(param_len, GFP_KERNEL);
        if (param == NULL)
                return -1;
 
@@ -1316,16 +1325,16 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
 #ifdef CONFIG_WAPI_SUPPORT
        case WLAN_CIPHER_SUITE_SMS4:
                alg_name= "SMS4";
-               if (pairwise == NL80211_KEYTYPE_PAIRWISE) {
+               if(pairwise == NL80211_KEYTYPE_PAIRWISE) {
                        if (key_index != 0 && key_index != 1) {
                                ret = -ENOTSUPP;
                                goto addkey_end;
                        }
                        memcpy((void*)param->sta_addr, (void*)mac_addr, ETH_ALEN);
                } else {
-                       DBG_871X("mac_addr is null\n");
+                       DBG_8723A("mac_addr is null \n");
                }
-               DBG_871X("rtw_wx_set_enc_ext: SMS4 case\n");
+               DBG_8723A("rtw_wx_set_enc_ext: SMS4 case \n");
                break;
 #endif
 
@@ -1353,21 +1362,20 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
                memcpy(param->u.crypt.seq, params->seq, params->seq_len);
        }
 
-       if (params->key_len && params->key)
+       if(params->key_len && params->key)
        {
                param->u.crypt.key_len = params->key_len;
                memcpy(param->u.crypt.key, params->key, params->key_len);
        }
 
-       //if (rtw_wdev->iftype == NL80211_IFTYPE_STATION)
-       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
+       if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
        {
                ret =  rtw_cfg80211_set_encryption(ndev, param, param_len);
        }
-       else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)//else if (rtw_wdev->iftype == NL80211_IFTYPE_AP)
+       else if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
        {
 #ifdef CONFIG_AP_MODE
-               if (mac_addr)
+               if(mac_addr)
                        memcpy(param->sta_addr, (void*)mac_addr, ETH_ALEN);
 
                ret = rtw_cfg80211_ap_set_encryption(ndev, param, param_len);
@@ -1375,14 +1383,14 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
        }
        else
        {
-               DBG_8192C("error! fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype);
+               DBG_8723A("error! fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype);
 
        }
 
 addkey_end:
-       if (param)
+       if(param)
        {
-               rtw_mfree((u8*)param, param_len);
+               kfree(param);
        }
 
        return ret;
@@ -1399,7 +1407,26 @@ static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev,
                                void (*callback)(void *cookie,
                                                 struct key_params*))
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+#if 0
+       struct iwm_priv *iwm = ndev_to_iwm(ndev);
+       struct iwm_key *key = &iwm->keys[key_index];
+       struct key_params params;
+
+       IWM_DBG_WEXT(iwm, DBG, "Getting key %d\n", key_index);
+
+       memset(&params, 0, sizeof(params));
+
+       params.cipher = key->cipher;
+       params.key_len = key->key_len;
+       params.seq_len = key->seq_len;
+       params.seq = key->seq;
+       params.key = key->key;
+
+       callback(cookie, &params);
+
+       return key->key_len ? 0 : -ENOENT;
+#endif
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
        return 0;
 }
 
@@ -1413,7 +1440,7 @@ static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
        _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
        struct security_priv *psecuritypriv = &padapter->securitypriv;
 
-       DBG_871X(FUNC_NDEV_FMT" key_index=%d\n", FUNC_NDEV_ARG(ndev), key_index);
+       DBG_8723A(FUNC_NDEV_FMT" key_index=%d\n", FUNC_NDEV_ARG(ndev), key_index);
 
        if (key_index == psecuritypriv->dot11PrivacyKeyIndex)
        {
@@ -1434,7 +1461,7 @@ static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
        _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
        struct security_priv *psecuritypriv = &padapter->securitypriv;
 
-               DBG_871X(FUNC_NDEV_FMT" key_index=%d"
+               DBG_8723A(FUNC_NDEV_FMT" key_index=%d"
                #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
                ", unicast=%d, multicast=%d"
                #endif
@@ -1469,30 +1496,42 @@ static int cfg80211_rtw_get_station(struct wiphy *wiphy,
                                    struct net_device *ndev,
                                    u8 *mac, struct station_info *sinfo)
 {
+       int ret = 0;
        _adapter *padapter = wiphy_to_adapter(wiphy);
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+       struct sta_info *psta = NULL;
+       struct sta_priv *pstapriv = &padapter->stapriv;
+
+       sinfo->filled = 0;
 
        if (!mac) {
-               DBG_871X(FUNC_NDEV_FMT" mac==%p\n", FUNC_NDEV_ARG(ndev), mac);
-               return -ENOENT;
+               DBG_8723A(FUNC_NDEV_FMT" mac==%p\n", FUNC_NDEV_ARG(ndev), mac);
+               ret = -ENOENT;
+               goto exit;
+       }
+
+       psta = rtw_get_stainfo(pstapriv, mac);
+       if (psta == NULL) {
+               DBG_8723A("%s, sta_info is null\n", __func__);
+               ret = -ENOENT;
+               goto exit;
        }
-       sinfo->filled = 0;
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_871X(FUNC_NDEV_FMT" mac="MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
+       DBG_8723A(FUNC_NDEV_FMT" mac="MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
 #endif
 
        //for infra./P2PClient mode
-       if (    check_fwstate(pmlmepriv, WIFI_STATION_STATE)
+       if    check_fwstate(pmlmepriv, WIFI_STATION_STATE)
                && check_fwstate(pmlmepriv, _FW_LINKED)
        )
        {
                struct wlan_network  *cur_network = &(pmlmepriv->cur_network);
 
-               if (_rtw_memcmp(mac, cur_network->network.MacAddress, ETH_ALEN) == false)
-               {
-                       DBG_871X("%s, mismatch bssid="MAC_FMT"\n", __func__, MAC_ARG(cur_network->network.MacAddress));
-                       return -ENOENT;
+               if (memcmp(mac, cur_network->network.MacAddress, ETH_ALEN)) {
+                       DBG_8723A("%s, mismatch bssid="MAC_FMT"\n", __func__, MAC_ARG(cur_network->network.MacAddress));
+                       ret = -ENOENT;
+                       goto exit;
                }
 
                sinfo->filled |= STATION_INFO_SIGNAL;
@@ -1500,29 +1539,27 @@ static int cfg80211_rtw_get_station(struct wiphy *wiphy,
 
                sinfo->filled |= STATION_INFO_TX_BITRATE;
                sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter);
+
+               sinfo->filled |= STATION_INFO_RX_PACKETS;
+               sinfo->rx_packets = sta_rx_data_pkts(psta);
+
+               sinfo->filled |= STATION_INFO_TX_PACKETS;
+               sinfo->tx_packets = psta->sta_stats.tx_pkts;
+
        }
 
        //for Ad-Hoc/AP mode
-       if (    (       check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)
+       if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)
                        ||check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)
-                       ||check_fwstate(pmlmepriv, WIFI_AP_STATE) )
+                       ||check_fwstate(pmlmepriv, WIFI_AP_STATE))
                && check_fwstate(pmlmepriv, _FW_LINKED)
        )
        {
-               struct sta_info *psta = NULL;
-               struct sta_priv *pstapriv = &padapter->stapriv;
-
-               psta = rtw_get_stainfo(pstapriv, mac);
-               if (psta == NULL)
-               {
-                       DBG_8192C("%s, sta_info is null\n", __func__);
-                       return -ENOENT;
-               }
-
                //TODO: should acquire station info...
        }
 
-       return 0;
+exit:
+       return ret;
 }
 
 extern int netdev_open(struct net_device *pnetdev);
@@ -1561,39 +1598,39 @@ static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
        struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
 #endif
        int ret = 0;
-       u8 change = false;
+       u8 change = _FALSE;
 
 #ifdef CONFIG_CONCURRENT_MODE
-       if (!padapter->isprimary)
+       if(padapter->adapter_type == SECONDARY_ADAPTER)
        {
-               DBG_871X(FUNC_NDEV_FMT" call netdev_if2_open\n", FUNC_NDEV_ARG(ndev));
-               if (netdev_if2_open(ndev) != 0) {
+               DBG_8723A(FUNC_NDEV_FMT" call netdev_if2_open\n", FUNC_NDEV_ARG(ndev));
+               if(netdev_if2_open(ndev) != 0) {
                        ret= -EPERM;
                        goto exit;
                }
        }
-       else
+       else if(padapter->adapter_type == PRIMARY_ADAPTER)
 #endif //CONFIG_CONCURRENT_MODE
        {
-               DBG_871X(FUNC_NDEV_FMT" call netdev_open\n", FUNC_NDEV_ARG(ndev));
-               if (netdev_open(ndev) != 0) {
+               DBG_8723A(FUNC_NDEV_FMT" call netdev_open\n", FUNC_NDEV_ARG(ndev));
+               if(netdev_open(ndev) != 0) {
                        ret= -EPERM;
                        goto exit;
                }
        }
 
-       if (_FAIL == rtw_pwr_wakeup(padapter)) {
+       if(_FAIL == rtw_pwr_wakeup(padapter)) {
                ret= -EPERM;
                goto exit;
        }
 
        old_type = rtw_wdev->iftype;
-       DBG_871X(FUNC_NDEV_FMT" old_iftype=%d, new_iftype=%d\n",
+       DBG_8723A(FUNC_NDEV_FMT" old_iftype=%d, new_iftype=%d\n",
                FUNC_NDEV_ARG(ndev), old_type, type);
 
-       if (old_type != type)
+       if(old_type != type)
        {
-               change = true;
+               change = _TRUE;
                pmlmeext->action_public_rxseq = 0xffff;
                pmlmeext->action_public_dialog_token = 0xff;
        }
@@ -1608,7 +1645,7 @@ static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
        case NL80211_IFTYPE_STATION:
                networkType = Ndis802_11Infrastructure;
                #ifdef CONFIG_P2P
-               if (change && rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
+               if(change && rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
                {
                        _cancel_timer_ex( &pwdinfo->find_phase_timer );
                        _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
@@ -1618,7 +1655,7 @@ static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
                        rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
                        rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
 
-                       DBG_8192C("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
+                       DBG_8723A("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
                }
                #endif //CONFIG_P2P
                break;
@@ -1628,7 +1665,7 @@ static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
        case NL80211_IFTYPE_AP:
                networkType = Ndis802_11APMode;
                #ifdef CONFIG_P2P
-               if (change && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+               if(change && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
                {
                        //it means P2P Group created, we will be GO and change mode from  P2P DEVICE to AP(GO)
                        rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
@@ -1641,7 +1678,7 @@ static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
 
        rtw_wdev->iftype = type;
 
-       if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==false)
+       if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==_FALSE)
        {
                rtw_wdev->iftype = old_type;
                ret = -EPERM;
@@ -1657,22 +1694,22 @@ exit:
 
 void rtw_cfg80211_indicate_scan_done(struct rtw_wdev_priv *pwdev_priv, bool aborted)
 {
-       unsigned long   irqL;
+       _irqL   irqL;
 
-       _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
-       if (pwdev_priv->scan_request != NULL)
+       spin_lock_bh(&pwdev_priv->scan_req_lock);
+       if(pwdev_priv->scan_request != NULL)
        {
                //struct cfg80211_scan_request *scan_request = pwdev_priv->scan_request;
 
                #ifdef CONFIG_DEBUG_CFG80211
-               DBG_871X("%s with scan req\n", __FUNCTION__);
+               DBG_8723A("%s with scan req\n", __FUNCTION__);
                #endif
 
                //avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
-               //if (scan_request == wiphy_to_dev(scan_request->wiphy)->scan_req)
-               if (pwdev_priv->scan_request->wiphy != pwdev_priv->rtw_wdev->wiphy)
+               //if(scan_request == wiphy_to_dev(scan_request->wiphy)->scan_req)
+               if(pwdev_priv->scan_request->wiphy != pwdev_priv->rtw_wdev->wiphy)
                {
-                       DBG_8192C("error wiphy compare\n");
+                       DBG_8723A("error wiphy compare\n");
                }
                else
                {
@@ -1683,15 +1720,15 @@ void rtw_cfg80211_indicate_scan_done(struct rtw_wdev_priv *pwdev_priv, bool abor
 
        } else {
                #ifdef CONFIG_DEBUG_CFG80211
-               DBG_871X("%s without scan req\n", __FUNCTION__);
+               DBG_8723A("%s without scan req\n", __FUNCTION__);
                #endif
        }
-       _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
+       spin_unlock_bh(&pwdev_priv->scan_req_lock);
 }
 
 void rtw_cfg80211_surveydone_event_callback(_adapter *padapter)
 {
-       unsigned long   irqL;
+       _irqL   irqL;
        _list                                   *plist, *phead;
        struct  mlme_priv       *pmlmepriv = &(padapter->mlmepriv);
        _queue                          *queue  = &(pmlmepriv->scanned_queue);
@@ -1706,25 +1743,25 @@ void rtw_cfg80211_surveydone_event_callback(_adapter *padapter)
        struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s\n", __func__);
+       DBG_8723A("%s\n", __func__);
 #endif
 
-       _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+       spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
 
        phead = get_list_head(queue);
        plist = get_next(phead);
 
-       while (1)
+       while(1)
        {
-               if (rtw_end_of_queue_search(phead,plist)== true)
+               if (rtw_end_of_queue_search(phead,plist)== _TRUE)
                        break;
 
                pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
 
                //report network only if the current channel set contains the channel to which this network belongs
-               if ( true == rtw_is_channel_set_contains_channel(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig)
+               if(rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0
                        #ifdef CONFIG_VALIDATE_SSID
-                       && true == rtw_validate_ssid(&(pnetwork->network.Ssid))
+                       && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
                        #endif
                )
                {
@@ -1736,45 +1773,47 @@ void rtw_cfg80211_surveydone_event_callback(_adapter *padapter)
 
        }
 
-       _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
+       spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
 
        //call this after other things have been done
-       rtw_cfg80211_indicate_scan_done(wdev_to_priv(padapter->rtw_wdev), false);
+       rtw_cfg80211_indicate_scan_done(wdev_to_priv(padapter->rtw_wdev), _FALSE);
 }
 
-static int rtw_cfg80211_set_probe_req_wpsp2pie(struct net_device *net, char *buf, int len)
+static int rtw_cfg80211_set_probe_req_wpsp2pie(_adapter *padapter, char *buf, int len)
 {
        int ret = 0;
        uint wps_ielen = 0;
        u8 *wps_ie;
        u32     p2p_ielen = 0;
        u8 *p2p_ie;
-       _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
+       u32     wfd_ielen = 0;
+       u8 *wfd_ie;
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s, ielen=%d\n", __func__, len);
+       DBG_8723A("%s, ielen=%d\n", __func__, len);
 #endif
 
-       if (len>0)
+       if(len>0)
        {
-               if ((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
+               if((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
                {
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("probe_req_wps_ielen=%d\n", wps_ielen);
+                       DBG_8723A("probe_req_wps_ielen=%d\n", wps_ielen);
                        #endif
 
-                       if (pmlmepriv->wps_probe_req_ie)
+                       if(pmlmepriv->wps_probe_req_ie)
                        {
                                u32 free_len = pmlmepriv->wps_probe_req_ie_len;
                                pmlmepriv->wps_probe_req_ie_len = 0;
-                               rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
+                               kfree(pmlmepriv->wps_probe_req_ie);
                                pmlmepriv->wps_probe_req_ie = NULL;
                        }
 
-                       pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
+                       pmlmepriv->wps_probe_req_ie =
+                               kmalloc(wps_ielen, GFP_KERNEL);
                        if ( pmlmepriv->wps_probe_req_ie == NULL) {
-                               DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                return -EINVAL;
 
                        }
@@ -1782,27 +1821,28 @@ static int rtw_cfg80211_set_probe_req_wpsp2pie(struct net_device *net, char *buf
                        pmlmepriv->wps_probe_req_ie_len = wps_ielen;
                }
 
-               buf += wps_ielen;
-               len -= wps_ielen;
+               //buf += wps_ielen;
+               //len -= wps_ielen;
 
                #ifdef CONFIG_P2P
-               if ((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
+               if((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
                {
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("probe_req_p2p_ielen=%d\n", p2p_ielen);
+                       DBG_8723A("probe_req_p2p_ielen=%d\n", p2p_ielen);
                        #endif
 
-                       if (pmlmepriv->p2p_probe_req_ie)
+                       if(pmlmepriv->p2p_probe_req_ie)
                        {
                                u32 free_len = pmlmepriv->p2p_probe_req_ie_len;
                                pmlmepriv->p2p_probe_req_ie_len = 0;
-                               rtw_mfree(pmlmepriv->p2p_probe_req_ie, free_len);
+                               kfree(pmlmepriv->p2p_probe_req_ie);
                                pmlmepriv->p2p_probe_req_ie = NULL;
                        }
 
-                       pmlmepriv->p2p_probe_req_ie = rtw_malloc(len);
+                       pmlmepriv->p2p_probe_req_ie =
+                               kmalloc(p2p_ielen, GFP_KERNEL);
                        if ( pmlmepriv->p2p_probe_req_ie == NULL) {
-                               DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                return -EINVAL;
 
                        }
@@ -1811,22 +1851,55 @@ static int rtw_cfg80211_set_probe_req_wpsp2pie(struct net_device *net, char *buf
                }
                #endif //CONFIG_P2P
 
+               //buf += p2p_ielen;
+               //len -= p2p_ielen;
+
+               #ifdef CONFIG_WFD
+               if(rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen))
+               {
+                       #ifdef CONFIG_DEBUG_CFG80211
+                       DBG_8723A("probe_req_wfd_ielen=%d\n", wfd_ielen);
+                       #endif
+
+                       if(pmlmepriv->wfd_probe_req_ie)
+                       {
+                               u32 free_len = pmlmepriv->wfd_probe_req_ie_len;
+                               pmlmepriv->wfd_probe_req_ie_len = 0;
+                               kfree(pmlmepriv->wfd_probe_req_ie);
+                               pmlmepriv->wfd_probe_req_ie = NULL;
+                       }
+
+                       pmlmepriv->wfd_probe_req_ie =
+                               kmalloc(wfd_ielen, GFP_KERNEL);
+                       if ( pmlmepriv->wfd_probe_req_ie == NULL) {
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               return -EINVAL;
+
+                       }
+                       rtw_get_wfd_ie(buf, len, pmlmepriv->wfd_probe_req_ie, &pmlmepriv->wfd_probe_req_ie_len);
+               }
+               #endif //CONFIG_WFD
+
        }
 
        return ret;
 
 }
 
-static int cfg80211_rtw_scan(struct wiphy *wiphy, struct net_device *ndev,
-                            struct cfg80211_scan_request *request)
+static int cfg80211_rtw_scan(struct wiphy *wiphy
+       #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
+       , struct net_device *ndev
+       #endif
+       , struct cfg80211_scan_request *request)
 {
        int i;
-       u8 _status = false;
+       u8 _status = _FALSE;
        int ret = 0;
        _adapter *padapter = wiphy_to_adapter(wiphy);
        struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
        NDIS_802_11_SSID ssid[RTW_SSID_SCAN_AMOUNT];
-       unsigned long   irqL;
+       struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
+       _irqL   irqL;
        u8 *wps_ie=NULL;
        uint wps_ielen=0;
        u8 *p2p_ie=NULL;
@@ -1837,139 +1910,130 @@ static int cfg80211_rtw_scan(struct wiphy *wiphy, struct net_device *ndev,
        struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
        struct cfg80211_ssid *ssids = request->ssids;
        int social_channel = 0, j = 0;
-       bool need_indicate_scan_done = false;
+       bool need_indicate_scan_done = _FALSE;
 #ifdef CONFIG_CONCURRENT_MODE
-       PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
-       struct mlme_priv *pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
-#endif
+       PADAPTER pbuddy_adapter = NULL;
+       struct mlme_priv *pbuddy_mlmepriv = NULL;
+#endif //CONFIG_CONCURRENT_MODE
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
 #endif
-#ifdef CONFIG_MP_INCLUDED
-if (padapter->registrypriv.mp_mode == 1)
-{
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
+
+#ifdef CONFIG_CONCURRENT_MODE
+       if(rtw_buddy_adapter_up(padapter))
        {
-               ret = -EPERM;
-               goto exit;
+               pbuddy_adapter = padapter->pbuddy_adapter;
+               pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
        }
-}
-#endif
+#endif //CONFIG_CONCURRENT_MODE
 
-       _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
+       spin_lock_bh(&pwdev_priv->scan_req_lock);
        pwdev_priv->scan_request = request;
-       _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
+       spin_unlock_bh(&pwdev_priv->scan_req_lock);
 
-       if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
+       if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
        {
 
 #ifdef CONFIG_DEBUG_CFG80211
-               DBG_871X("%s under WIFI_AP_STATE\n", __FUNCTION__);
+               DBG_8723A("%s under WIFI_AP_STATE\n", __FUNCTION__);
 #endif
-               //need_indicate_scan_done = true;
+               //need_indicate_scan_done = _TRUE;
                //goto check_need_indicate_scan_done;
        }
 
-       if (_FAIL == rtw_pwr_wakeup(padapter)) {
-               need_indicate_scan_done = true;
+       if(_FAIL == rtw_pwr_wakeup(padapter)) {
+               need_indicate_scan_done = _TRUE;
                goto check_need_indicate_scan_done;
        }
 
        #ifdef CONFIG_P2P
-       if ( ssids->ssid != NULL )
-       {
-               if ( _rtw_memcmp(ssids->ssid, "DIRECT-", 7)
-                       && rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)
-               )
+       if (ssids->ssid != NULL &&
+           !memcmp(ssids->ssid, "DIRECT-", 7) &&
+           rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)) {
+               if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
                {
-                       if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
-                       {
-                               rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
-                               wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = true;
-                       }
-                       else
-                       {
-                               rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
-                               #ifdef CONFIG_DEBUG_CFG80211
-                               DBG_8192C("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
-                               #endif
-                       }
-                       rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
+                       rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
+                       wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = _TRUE;
+               }
+               else
+               {
+                       rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
+                       #ifdef CONFIG_DEBUG_CFG80211
+                       DBG_8723A("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
+                       #endif
+               }
+               rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
 
-                       if (request->n_channels == 3 &&
-                               request->channels[0]->hw_value == 1 &&
-                               request->channels[1]->hw_value == 6 &&
-                               request->channels[2]->hw_value == 11
-                       )
-                       {
-                               social_channel = 1;
-                       }
+               if(request->n_channels == 3 &&
+                       request->channels[0]->hw_value == 1 &&
+                       request->channels[1]->hw_value == 6 &&
+                       request->channels[2]->hw_value == 11
+               )
+               {
+                       social_channel = 1;
                }
        }
        #endif //CONFIG_P2P
 
-       if (request->ie && request->ie_len>0)
+       if(request->ie && request->ie_len>0)
        {
-               rtw_cfg80211_set_probe_req_wpsp2pie( ndev, (u8 *)request->ie, request->ie_len );
+               rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len );
        }
 
-       if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true)
+       if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)
        {
-               DBG_8192C("%s, bBusyTraffic == true\n", __func__);
-               need_indicate_scan_done = true;
+               DBG_8723A("%s, bBusyTraffic == _TRUE\n", __func__);
+               need_indicate_scan_done = _TRUE;
+               goto check_need_indicate_scan_done;
+       }
+       if (rtw_is_scan_deny(padapter)){
+               DBG_8723A(FUNC_ADPT_FMT  ": scan deny\n", FUNC_ADPT_ARG(padapter));
+               need_indicate_scan_done = _TRUE;
                goto check_need_indicate_scan_done;
        }
 
 #ifdef CONFIG_CONCURRENT_MODE
-       if (pbuddy_mlmepriv->LinkDetectInfo.bBusyTraffic == true)
+       if(pbuddy_mlmepriv && (pbuddy_mlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE))
        {
-               DBG_8192C("%s, bBusyTraffic == true at buddy_intf\n", __func__);
-               need_indicate_scan_done = true;
+               DBG_8723A("%s, bBusyTraffic == _TRUE at buddy_intf\n", __func__);
+               need_indicate_scan_done = _TRUE;
                goto check_need_indicate_scan_done;
        }
-#ifdef CONFIG_SET_SCAN_DENY_TIMER
-       if (ATOMIC_READ(&pbuddy_mlmepriv->set_scan_deny)==1){
-               DBG_871X(FUNC_NDEV_FMT  ": deny scan by buddy_intf\n", FUNC_NDEV_ARG(ndev));
-               need_indicate_scan_done = true;
-               goto check_need_indicate_scan_done;
-
-       }
-#endif //CONFIG_SET_SCAN_DENY_TIMER
 #endif //CONFIG_CONCURRENT_MODE
 
-       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == true)
+       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
        {
-               DBG_8192C("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
-               need_indicate_scan_done = true;
+               DBG_8723A("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
+               need_indicate_scan_done = _TRUE;
                goto check_need_indicate_scan_done;
        }
 
 #ifdef CONFIG_CONCURRENT_MODE
-       if (check_fwstate(pbuddy_mlmepriv,
-               _FW_UNDER_SURVEY|_FW_UNDER_LINKING|WIFI_UNDER_WPS) == true)
+       if (check_buddy_fwstate(padapter,
+               _FW_UNDER_SURVEY|_FW_UNDER_LINKING|WIFI_UNDER_WPS) == _TRUE)
        {
-               if (check_fwstate(pbuddy_mlmepriv, _FW_UNDER_SURVEY))
+               if(check_buddy_fwstate(padapter, _FW_UNDER_SURVEY))
                {
-                       DBG_8192C("scanning_via_buddy_intf\n");
-                       pmlmepriv->scanning_via_buddy_intf = true;
+                       DBG_8723A("scanning_via_buddy_intf\n");
+                       pmlmepriv->scanning_via_buddy_intf = _TRUE;
                }
 
-               DBG_8192C("buddy_intf's mlme state:0x%x\n", pbuddy_mlmepriv->fw_state);
+               DBG_8723A("buddy_intf's mlme state:0x%x\n", pbuddy_mlmepriv->fw_state);
 
-               need_indicate_scan_done = true;
+               need_indicate_scan_done = _TRUE;
                goto check_need_indicate_scan_done;
        }
 #endif
 
 
 #ifdef CONFIG_P2P
-       if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
+       if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
        {
                rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
-               rtw_free_network_queue(padapter, true);
+               rtw_free_network_queue(padapter, _TRUE);
 
-               if (social_channel == 0)
+               if(social_channel == 0)
                        rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
                else
                        rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_SOCIAL_LAST);
@@ -1981,30 +2045,42 @@ if (padapter->registrypriv.mp_mode == 1)
        //parsing request ssids, n_ssids
        for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
                #ifdef CONFIG_DEBUG_CFG80211
-               DBG_8192C("ssid=%s, len=%d\n", ssids[i].ssid, ssids[i].ssid_len);
+               DBG_8723A("ssid=%s, len=%d\n", ssids[i].ssid, ssids[i].ssid_len);
                #endif
                memcpy(ssid[i].Ssid, ssids[i].ssid, ssids[i].ssid_len);
                ssid[i].SsidLength = ssids[i].ssid_len;
        }
 
 
-#ifdef CONFIG_DEBUG_CFG80211
-       //parsing channels, n_channels
-       DBG_871X("%s n_channels:%u\n", __FUNCTION__, request->n_channels);
-#endif
+       /* parsing channels, n_channels */
+       memset(ch, 0, sizeof(struct rtw_ieee80211_channel)*RTW_CHANNEL_SCAN_AMOUNT);
+       if (request->n_channels == 1)
+       for (i=0;i<request->n_channels && i<RTW_CHANNEL_SCAN_AMOUNT;i++) {
+               #ifdef CONFIG_DEBUG_CFG80211
+               DBG_8723A(FUNC_ADPT_FMT CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(request->channels[i]));
+               #endif
+               ch[i].hw_value = request->channels[i]->hw_value;
+               ch[i].flags = request->channels[i]->flags;
+       }
 
-       _enter_critical_bh(&pmlmepriv->lock, &irqL);
-       _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT);
-       _exit_critical_bh(&pmlmepriv->lock, &irqL);
+       spin_lock_bh(&pmlmepriv->lock);
+       if (request->n_channels == 1) {
+               memcpy(&ch[1], &ch[0], sizeof(struct rtw_ieee80211_channel));
+               memcpy(&ch[2], &ch[0], sizeof(struct rtw_ieee80211_channel));
+               _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, 3);
+       } else {
+               _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, NULL, 0);
+       }
+       spin_unlock_bh(&pmlmepriv->lock);
 
 
-       if (_status == false)
+       if(_status == _FALSE)
        {
                ret = -1;
        }
 
 check_need_indicate_scan_done:
-       if (need_indicate_scan_done)
+       if(need_indicate_scan_done)
                rtw_cfg80211_surveydone_event_callback(padapter);
 
 exit:
@@ -2015,42 +2091,108 @@ exit:
 
 static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
 {
-       DBG_8192C("%s\n", __func__);
+#if 0
+       struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
+
+       if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
+           (iwm->conf.rts_threshold != wiphy->rts_threshold)) {
+               int ret;
+
+               iwm->conf.rts_threshold = wiphy->rts_threshold;
+
+               ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
+                                            CFG_RTS_THRESHOLD,
+                                            iwm->conf.rts_threshold);
+               if (ret < 0)
+                       return ret;
+       }
+
+       if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
+           (iwm->conf.frag_threshold != wiphy->frag_threshold)) {
+               int ret;
+
+               iwm->conf.frag_threshold = wiphy->frag_threshold;
+
+               ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
+                                            CFG_FRAG_THRESHOLD,
+                                            iwm->conf.frag_threshold);
+               if (ret < 0)
+                       return ret;
+       }
+#endif
+       DBG_8723A("%s\n", __func__);
        return 0;
 }
 
 static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
                                  struct cfg80211_ibss_params *params)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+#if 0
+       struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
+       struct ieee80211_channel *chan = params->channel;
+
+       if (!test_bit(IWM_STATUS_READY, &iwm->status))
+               return -EIO;
+
+       /* UMAC doesn't support creating or joining an IBSS network
+        * with specified bssid. */
+       if (params->bssid)
+               return -EOPNOTSUPP;
+
+       iwm->channel = ieee80211_frequency_to_channel(chan->center_freq);
+       iwm->umac_profile->ibss.band = chan->band;
+       iwm->umac_profile->ibss.channel = iwm->channel;
+       iwm->umac_profile->ssid.ssid_len = params->ssid_len;
+       memcpy(iwm->umac_profile->ssid.ssid, params->ssid, params->ssid_len);
+
+       return iwm_send_mlme_profile(iwm);
+#endif
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
        return 0;
 }
 
 static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+#if 0
+       struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
+
+       if (iwm->umac_profile_active)
+               return iwm_invalidate_mlme_profile(iwm);
+#endif
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
        return 0;
 }
 
 static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version)
 {
-       DBG_8192C("%s, wpa_version=%d\n", __func__, wpa_version);
+       DBG_8723A("%s, wpa_version=%d\n", __func__, wpa_version);
 
        if (!wpa_version) {
                psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
                return 0;
        }
 
+
        if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
+       {
                psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
+       }
+
+/*
+       if (wpa_version & NL80211_WPA_VERSION_2)
+       {
+               psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
+       }
+*/
 
        return 0;
+
 }
 
 static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
                             enum nl80211_auth_type sme_auth_type)
 {
-       DBG_8192C("%s, nl80211_auth_type=%d\n", __func__, sme_auth_type);
+       DBG_8723A("%s, nl80211_auth_type=%d\n", __func__, sme_auth_type);
 
 
        switch (sme_auth_type) {
@@ -2063,11 +2205,11 @@ static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
 
                psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
 
-               if (psecuritypriv->ndisauthtype>Ndis802_11AuthModeWPA)
+               if(psecuritypriv->ndisauthtype>Ndis802_11AuthModeWPA)
                        psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
 
 #ifdef CONFIG_WAPI_SUPPORT
-               if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWAPI)
+               if(psecuritypriv->ndisauthtype == Ndis802_11AuthModeWAPI)
                        psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
 #endif
 
@@ -2096,7 +2238,7 @@ static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 ciph
        u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
                &psecuritypriv->dot118021XGrpPrivacy;
 
-       DBG_8192C("%s, ucast=%d, cipher=0x%x\n", __func__, ucast, cipher);
+       DBG_8723A("%s, ucast=%d, cipher=0x%x\n", __func__, ucast, cipher);
 
 
        if (!cipher) {
@@ -2110,7 +2252,7 @@ static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 ciph
                *profile_cipher = _NO_PRIVACY_;
                ndisencryptstatus = Ndis802_11EncryptionDisabled;
 #ifdef CONFIG_WAPI_SUPPORT
-               if (psecuritypriv->dot11PrivacyAlgrthm ==_SMS4_ )
+               if(psecuritypriv->dot11PrivacyAlgrthm ==_SMS4_ )
                {
                        *profile_cipher = _SMS4_;
                }
@@ -2139,15 +2281,15 @@ static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 ciph
                break;
 #endif
        default:
-               DBG_8192C("Unsupported cipher: 0x%x\n", cipher);
+               DBG_8723A("Unsupported cipher: 0x%x\n", cipher);
                return -ENOTSUPP;
        }
 
-       if (ucast)
+       if(ucast)
        {
                psecuritypriv->ndisencryptstatus = ndisencryptstatus;
 
-               //if (psecuritypriv->dot11PrivacyAlgrthm >= _AES_)
+               //if(psecuritypriv->dot11PrivacyAlgrthm >= _AES_)
                //      psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
        }
 
@@ -2156,7 +2298,7 @@ static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 ciph
 
 static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt)
 {
-       DBG_8192C("%s, key_mgt=0x%x\n", __func__, key_mgt);
+       DBG_8723A("%s, key_mgt=0x%x\n", __func__, key_mgt);
 
        if (key_mgt == WLAN_AKM_SUITE_8021X)
                //*auth_type = UMAC_AUTH_TYPE_8021X;
@@ -2165,17 +2307,17 @@ static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key
                psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
        }
 #ifdef CONFIG_WAPI_SUPPORT
-       else if (key_mgt ==WLAN_AKM_SUITE_WAPI_PSK){
+       else if(key_mgt ==WLAN_AKM_SUITE_WAPI_PSK){
                psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
        }
-       else if (key_mgt ==WLAN_AKM_SUITE_WAPI_CERT){
+       else if(key_mgt ==WLAN_AKM_SUITE_WAPI_CERT){
                psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
        }
 #endif
 
 
        else {
-               DBG_8192C("Invalid key mgt: 0x%x\n", key_mgt);
+               DBG_8723A("Invalid key mgt: 0x%x\n", key_mgt);
                //return -EINVAL;
        }
 
@@ -2186,11 +2328,12 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
 {
        u8 *buf=NULL, *pos=NULL;
        u32 left;
-       int group_cipher = WPA_CIPHER_NONE, pairwise_cipher = WPA_CIPHER_NONE;
+       int group_cipher = 0, pairwise_cipher = 0;
        int ret = 0;
        int wpa_ielen=0;
        int wpa2_ielen=0;
        u8 *pwpa, *pwpa2;
+       u8 null_addr[]= {0,0,0,0,0,0};
 
        if (pie == NULL || !ielen) {
                /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */
@@ -2203,7 +2346,7 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
                goto exit;
        }
 
-       buf = rtw_zmalloc(ielen);
+       buf = kzalloc(ielen, GFP_KERNEL);
        if (buf == NULL){
                ret =  -ENOMEM;
                goto exit;
@@ -2214,45 +2357,54 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
        //dump
        {
                int i;
-               DBG_8192C("set wpa_ie(length:%zu):\n", ielen);
-               for (i=0;i<ielen;i=i+8)
-                       DBG_8192C("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",buf[i],buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6],buf[i+7]);
+               DBG_8723A("set wpa_ie(length:%zu):\n", ielen);
+               for(i=0;i<ielen;i=i+8)
+                       DBG_8723A("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x \n",buf[i],buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6],buf[i+7]);
        }
 
        pos = buf;
-       if (ielen < RSN_HEADER_LEN){
+       if(ielen < RSN_HEADER_LEN){
                RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("Ie len too short %d\n", ielen));
                ret  = -1;
                goto exit;
        }
 
        pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen);
-       if (pwpa && wpa_ielen>0)
+       if(pwpa && wpa_ielen>0)
        {
-               if (rtw_parse_wpa_ie(pwpa, wpa_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
+               if(rtw_parse_wpa_ie(pwpa, wpa_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
                {
                        padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
                        padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeWPAPSK;
                        memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen+2);
 
-                       DBG_8192C("got wpa_ie, wpa_ielen:%u\n", wpa_ielen);
+                       DBG_8723A("got wpa_ie, wpa_ielen:%u\n", wpa_ielen);
                }
        }
 
        pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen);
-       if (pwpa2 && wpa2_ielen>0)
+       if(pwpa2 && wpa2_ielen>0)
        {
-               if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
+               if(rtw_parse_wpa2_ie(pwpa2, wpa2_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
                {
                        padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
                        padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeWPA2PSK;
                        memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen+2);
 
-                       DBG_8192C("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen);
+                       DBG_8723A("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen);
                }
        }
 
-       switch (group_cipher)
+       if (group_cipher == 0)
+       {
+               group_cipher = WPA_CIPHER_NONE;
+       }
+       if (pairwise_cipher == 0)
+       {
+               pairwise_cipher = WPA_CIPHER_NONE;
+       }
+
+       switch(group_cipher)
        {
                case WPA_CIPHER_NONE:
                        padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
@@ -2276,7 +2428,7 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
                        break;
        }
 
-       switch (pairwise_cipher)
+       switch(pairwise_cipher)
        {
                case WPA_CIPHER_NONE:
                        padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
@@ -2306,7 +2458,7 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
 
                wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen);
                if (wps_ie && wps_ielen > 0) {
-                       DBG_8192C("got wps_ie, wps_ielen:%u\n", wps_ielen);
+                       DBG_8723A("got wps_ie, wps_ielen:%u\n", wps_ielen);
                        padapter->securitypriv.wps_ie_len = wps_ielen<MAX_WPS_IE_LEN?wps_ielen:MAX_WPS_IE_LEN;
                        memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len);
                        set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
@@ -2321,23 +2473,24 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
                u8 *p2p_ie;
                struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
-               if ((p2p_ie=rtw_get_p2p_ie(buf, ielen, NULL, &p2p_ielen)))
+               if((p2p_ie=rtw_get_p2p_ie(buf, ielen, NULL, &p2p_ielen)))
                {
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("%s p2p_assoc_req_ielen=%d\n", __FUNCTION__, p2p_ielen);
+                       DBG_8723A("%s p2p_assoc_req_ielen=%d\n", __FUNCTION__, p2p_ielen);
                        #endif
 
-                       if (pmlmepriv->p2p_assoc_req_ie)
+                       if(pmlmepriv->p2p_assoc_req_ie)
                        {
                                u32 free_len = pmlmepriv->p2p_assoc_req_ie_len;
                                pmlmepriv->p2p_assoc_req_ie_len = 0;
-                               rtw_mfree(pmlmepriv->p2p_assoc_req_ie, free_len);
+                               kfree(pmlmepriv->p2p_assoc_req_ie);
                                pmlmepriv->p2p_assoc_req_ie = NULL;
                        }
 
-                       pmlmepriv->p2p_assoc_req_ie = rtw_malloc(p2p_ielen);
+                       pmlmepriv->p2p_assoc_req_ie =
+                               kmalloc(p2p_ielen, GFP_KERNEL);
                        if ( pmlmepriv->p2p_assoc_req_ie == NULL) {
-                               DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                goto exit;
                        }
                        memcpy(pmlmepriv->p2p_assoc_req_ie, p2p_ie, p2p_ielen);
@@ -2346,13 +2499,52 @@ static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
        }
        #endif //CONFIG_P2P
 
+       #ifdef CONFIG_WFD
+       {//check wfd_ie for assoc req;
+               uint wfd_ielen=0;
+               u8 *wfd_ie;
+               struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
+
+               if(rtw_get_wfd_ie(buf, ielen, NULL, &wfd_ielen))
+               {
+                       #ifdef CONFIG_DEBUG_CFG80211
+                       DBG_8723A("%s wfd_assoc_req_ielen=%d\n", __FUNCTION__, wfd_ielen);
+                       #endif
+
+                       if(pmlmepriv->wfd_assoc_req_ie)
+                       {
+                               u32 free_len = pmlmepriv->wfd_assoc_req_ie_len;
+                               pmlmepriv->wfd_assoc_req_ie_len = 0;
+                               kfree(pmlmepriv->wfd_assoc_req_ie);
+                               pmlmepriv->wfd_assoc_req_ie = NULL;
+                       }
+
+                       pmlmepriv->wfd_assoc_req_ie =
+                               kmalloc(wfd_ielen, GFP_KERNEL);
+                       if ( pmlmepriv->wfd_assoc_req_ie == NULL) {
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               goto exit;
+                       }
+                       rtw_get_wfd_ie(buf, ielen, pmlmepriv->wfd_assoc_req_ie, &pmlmepriv->wfd_assoc_req_ie_len);
+               }
+       }
+       #endif //CONFIG_WFD
+
+       //TKIP and AES disallow multicast packets until installing group key
+       if(padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
+               || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
+               || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
+               //WPS open need to enable multicast
+               //|| check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE)
+               rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
+
        RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
                ("rtw_set_wpa_ie: pairwise_cipher=0x%08x padapter->securitypriv.ndisencryptstatus=%d padapter->securitypriv.ndisauthtype=%d\n",
                pairwise_cipher, padapter->securitypriv.ndisencryptstatus, padapter->securitypriv.ndisauthtype));
 
 exit:
        if (buf)
-               rtw_mfree(buf, ielen);
+               kfree(buf);
        if (ret)
                _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
        return ret;
@@ -2362,52 +2554,52 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                                 struct cfg80211_connect_params *sme)
 {
        int ret=0;
-       unsigned long irqL;
+       _irqL irqL;
        _list *phead;
        struct wlan_network *pnetwork = NULL;
        NDIS_802_11_AUTHENTICATION_MODE authmode;
        NDIS_802_11_SSID ndis_ssid;
        u8 *dst_ssid, *src_ssid;
        u8 *dst_bssid, *src_bssid;
-       //u8 matched_by_bssid=false;
-       //u8 matched_by_ssid=false;
-       u8 matched=false;
+       //u8 matched_by_bssid=_FALSE;
+       //u8 matched_by_ssid=_FALSE;
+       u8 matched=_FALSE;
        _adapter *padapter = wiphy_to_adapter(wiphy);
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct security_priv *psecuritypriv = &padapter->securitypriv;
        _queue *queue = &pmlmepriv->scanned_queue;
 
-       DBG_871X("=>"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
-       DBG_871X("privacy=%d, key=%p, key_len=%d, key_idx=%d\n",
+       DBG_8723A("=>"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A("privacy=%d, key=%p, key_len=%d, key_idx=%d\n",
                sme->privacy, sme->key, sme->key_len, sme->key_idx);
 
 
-       if (wdev_to_priv(padapter->rtw_wdev)->block == true)
+       if(wdev_to_priv(padapter->rtw_wdev)->block == _TRUE)
        {
                ret = -EBUSY;
-               DBG_871X("%s wdev_priv.block is set\n", __FUNCTION__);
+               DBG_8723A("%s wdev_priv.block is set\n", __FUNCTION__);
                goto exit;
        }
 
-       if (_FAIL == rtw_pwr_wakeup(padapter)) {
+       if(_FAIL == rtw_pwr_wakeup(padapter)) {
                ret= -EPERM;
                goto exit;
        }
 
-       if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
+       if(check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                ret = -EPERM;
                goto exit;
        }
 
 #ifdef CONFIG_CONCURRENT_MODE
-       if (check_buddy_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == true)
-       {
-               DBG_8192C("%s, but buddy_intf is under scanning or linking\n", __FUNCTION__);
-
+       if (check_buddy_fwstate(padapter, _FW_UNDER_LINKING) == _TRUE) {
+               DBG_8723A("%s, but buddy_intf is under linking\n", __FUNCTION__);
                ret = -EINVAL;
-
                goto exit;
        }
+       if (check_buddy_fwstate(padapter, _FW_UNDER_SURVEY) == _TRUE) {
+               rtw_scan_abort(padapter->pbuddy_adapter);
+       }
 #endif
 
        if (!sme->ssid || !sme->ssid_len)
@@ -2427,29 +2619,30 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
        ndis_ssid.SsidLength = sme->ssid_len;
        memcpy(ndis_ssid.Ssid, sme->ssid, sme->ssid_len);
 
-       DBG_8192C("ssid=%s, len=%zu\n", ndis_ssid.Ssid, sme->ssid_len);
+       DBG_8723A("ssid=%s, len=%zu\n", ndis_ssid.Ssid, sme->ssid_len);
 
 
        if (sme->bssid)
-               DBG_8192C("bssid="MAC_FMT"\n", MAC_ARG(sme->bssid));
+               DBG_8723A("bssid="MAC_FMT"\n", MAC_ARG(sme->bssid));
 
 
-       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == true)
-       {
+       if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
                ret = -EBUSY;
-               DBG_8192C("%s, fw_state=0x%x, goto exit\n", __FUNCTION__, pmlmepriv->fw_state);
+               DBG_8723A("%s, fw_state=0x%x, goto exit\n", __FUNCTION__, pmlmepriv->fw_state);
                goto exit;
        }
+       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
+               rtw_scan_abort(padapter);
+       }
 
-
-       _enter_critical_bh(&queue->lock, &irqL);
+       spin_lock_bh(&queue->lock);
 
        phead = get_list_head(queue);
        pmlmepriv->pscanned = get_next(phead);
 
        while (1)
        {
-               if (rtw_end_of_queue_search(phead, pmlmepriv->pscanned) == true)
+               if (rtw_end_of_queue_search(phead, pmlmepriv->pscanned) == _TRUE)
                {
                        break;
                }
@@ -2460,15 +2653,16 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                dst_ssid = pnetwork->network.Ssid.Ssid;
                dst_bssid = pnetwork->network.MacAddress;
 
-               if (sme->bssid)  {
-                       if (_rtw_memcmp(pnetwork->network.MacAddress, sme->bssid, ETH_ALEN) == false)
+               if(sme->bssid)  {
+                       if (memcmp(pnetwork->network.MacAddress,
+                                  sme->bssid, ETH_ALEN))
                                continue;
                }
 
-               if (sme->ssid && sme->ssid_len) {
-                       if (    pnetwork->network.Ssid.SsidLength != sme->ssid_len
-                               || _rtw_memcmp(pnetwork->network.Ssid.Ssid, sme->ssid, sme->ssid_len) == false
-                       )
+               if(sme->ssid && sme->ssid_len) {
+                       if (pnetwork->network.Ssid.SsidLength != sme->ssid_len||
+                            memcmp(pnetwork->network.Ssid.Ssid, sme->ssid,
+                                   sme->ssid_len))
                                continue;
                }
 
@@ -2477,14 +2671,14 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                {
                        src_bssid = sme->bssid;
 
-                       if ((_rtw_memcmp(dst_bssid, src_bssid, ETH_ALEN)) == true)
+                       if ((!memcmp(dst_bssid, src_bssid, ETH_ALEN)))
                        {
-                               DBG_8192C("matched by bssid\n");
+                               DBG_8723A("matched by bssid\n");
 
                                ndis_ssid.SsidLength = pnetwork->network.Ssid.SsidLength;
                                memcpy(ndis_ssid.Ssid, pnetwork->network.Ssid.Ssid, pnetwork->network.Ssid.SsidLength);
 
-                               matched=true;
+                               matched=_TRUE;
                                break;
                        }
 
@@ -2493,34 +2687,33 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                {
                        src_ssid = ndis_ssid.Ssid;
 
-                       if ((_rtw_memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength) == true) &&
+                       if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength)) &&
                                (pnetwork->network.Ssid.SsidLength==ndis_ssid.SsidLength))
                        {
-                               DBG_8192C("matched by ssid\n");
-                               matched=true;
+                               DBG_8723A("matched by ssid\n");
+                               matched=_TRUE;
                                break;
                        }
                }
 
        }
 
-       _exit_critical_bh(&queue->lock, &irqL);
+       spin_unlock_bh(&queue->lock);
 
-       if ((matched == false) || (pnetwork== NULL))
+       if((matched == _FALSE) || (pnetwork== NULL))
        {
                ret = -ENOENT;
-               DBG_8192C("connect, matched == false, goto exit\n");
+               DBG_8723A("connect, matched == _FALSE, goto exit\n");
                goto exit;
        }
 
 
-       if (rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode) == false)
+       if (rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode) == _FALSE)
        {
                ret = -EPERM;
                goto exit;
        }
 
-
        psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
        psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
        psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
@@ -2536,7 +2729,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                goto exit;
 
 #ifdef CONFIG_WAPI_SUPPORT
-       if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1)
+       if(sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1)
        {
                padapter->wapiInfo.bWapiEnable = true;
                padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
@@ -2547,7 +2740,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
        ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
 
 #ifdef CONFIG_WAPI_SUPPORT
-       if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_WAPI)
+       if(psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_WAPI)
                padapter->mlmeextpriv.mlmext_info.auth_algo = psecuritypriv->dot11AuthAlgrthm;
 #endif
 
@@ -2555,21 +2748,26 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
        if (ret < 0)
                goto exit;
 
+       DBG_8723A("%s, ie_len=%zu\n", __func__, sme->ie_len);
+
+       ret = rtw_cfg80211_set_wpa_ie(padapter, sme->ie, sme->ie_len);
+       if (ret < 0)
+               goto exit;
 
        if (sme->crypto.n_ciphers_pairwise) {
-               ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], true);
+               ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], _TRUE);
                if (ret < 0)
                        goto exit;
        }
 
        //For WEP Shared auth
-       if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared
+       if((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared
                || psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) && sme->key
        )
        {
                u32 wep_key_idx, wep_key_len,wep_total_len;
                NDIS_802_11_WEP  *pwep = NULL;
-               DBG_871X("%s(): Shared/Auto WEP\n",__FUNCTION__);
+               DBG_8723A("%s(): Shared/Auto WEP\n",__FUNCTION__);
 
                wep_key_idx = sme->key_idx;
                wep_key_len = sme->key_len;
@@ -2583,9 +2781,10 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                {
                        wep_key_len = wep_key_len <= 5 ? 5 : 13;
                        wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
-                       pwep =(NDIS_802_11_WEP   *) rtw_malloc(wep_total_len);
-                       if (pwep == NULL){
-                               DBG_871X(" wpa_set_encryption: pwep allocate fail !!!\n");
+                       pwep =(NDIS_802_11_WEP   *)kmalloc(wep_total_len,
+                                                          GFP_KERNEL);
+                       if(pwep == NULL){
+                               DBG_8723A(" wpa_set_encryption: pwep allocate fail !!!\n");
                                ret = -ENOMEM;
                                goto exit;
                        }
@@ -2595,7 +2794,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                        pwep->KeyLength = wep_key_len;
                        pwep->Length = wep_total_len;
 
-                       if (wep_key_len==13)
+                       if(wep_key_len==13)
                        {
                                padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
                                padapter->securitypriv.dot118021XGrpPrivacy=_WEP104_;
@@ -2611,20 +2810,20 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
 
                memcpy(pwep->KeyMaterial,  (void *)sme->key, pwep->KeyLength);
 
-               if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
+               if(rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
                {
                        ret = -EOPNOTSUPP ;
                }
 
                if (pwep) {
-                       rtw_mfree((u8 *)pwep,wep_total_len);
+                       kfree(pwep);
                }
 
-               if (ret < 0)
+               if(ret < 0)
                        goto exit;
        }
 
-       ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, false);
+       ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, _FALSE);
        if (ret < 0)
                return ret;
 
@@ -2635,38 +2834,30 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
        }
 
 #ifdef CONFIG_WAPI_SUPPORT
-      if (sme->crypto.akm_suites[0] ==WLAN_AKM_SUITE_WAPI_PSK){
+      if(sme->crypto.akm_suites[0] ==WLAN_AKM_SUITE_WAPI_PSK){
                padapter->wapiInfo.bWapiPSK = true;
        }
-       else if (sme->crypto.akm_suites[0] ==WLAN_AKM_SUITE_WAPI_CERT){
+       else if(sme->crypto.akm_suites[0] ==WLAN_AKM_SUITE_WAPI_CERT){
              padapter->wapiInfo.bWapiPSK = false;
        }
 #endif
 
-
-
-       DBG_8192C("%s, ie_len=%zu\n", __func__, sme->ie_len);
-
-       ret = rtw_cfg80211_set_wpa_ie(padapter, sme->ie, sme->ie_len);
-       if (ret < 0)
-               goto exit;
-
        authmode = psecuritypriv->ndisauthtype;
        rtw_set_802_11_authentication_mode(padapter, authmode);
 
        //rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus);
 
-       if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == false) {
+       if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
                ret = -1;
                goto exit;
        }
 
 
-       DBG_8192C("set ssid:dot11AuthAlgrthm=%d, dot11PrivacyAlgrthm=%d, dot118021XGrpPrivacy=%d\n", psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm, psecuritypriv->dot118021XGrpPrivacy);
+       DBG_8723A("set ssid:dot11AuthAlgrthm=%d, dot11PrivacyAlgrthm=%d, dot118021XGrpPrivacy=%d\n", psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm, psecuritypriv->dot118021XGrpPrivacy);
 
 exit:
 
-       DBG_8192C("<=%s, ret %d\n",__FUNCTION__, ret);
+       DBG_8723A("<=%s, ret %d\n",__FUNCTION__, ret);
 
        return ret;
 }
@@ -2676,17 +2867,21 @@ static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
 {
        _adapter *padapter = wiphy_to_adapter(wiphy);
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
-       if (check_fwstate(&padapter->mlmepriv, _FW_LINKED))
+       rtw_set_roaming(padapter, 0);
+
+       if(check_fwstate(&padapter->mlmepriv, _FW_LINKED))
        {
-               rtw_disassoc_cmd(padapter);
+               rtw_scan_abort(padapter);
+               LeaveAllPowerSaveMode(padapter);
+               rtw_disassoc_cmd(padapter, 500, _FALSE);
 
-               DBG_871X("%s...call rtw_indicate_disconnect\n ", __FUNCTION__);
+               DBG_8723A("%s...call rtw_indicate_disconnect\n", __FUNCTION__);
 
-               padapter->mlmepriv.not_indic_disco = true;
+               padapter->mlmepriv.not_indic_disco = _TRUE;
                rtw_indicate_disconnect(padapter);
-               padapter->mlmepriv.not_indic_disco = false;
+               padapter->mlmepriv.not_indic_disco = _FALSE;
 
                rtw_free_assoc_resources(padapter, 1);
        }
@@ -2695,42 +2890,82 @@ static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
 }
 
 static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
+       struct wireless_dev *wdev,
+#endif
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) || defined(COMPAT_KERNEL_RELEASE)
-                                   enum nl80211_tx_power_setting type, int mbm)
-#else  // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
-                                       enum tx_power_setting type, int dbm)
-#endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
+       enum nl80211_tx_power_setting type, int mbm)
+#else
+       enum tx_power_setting type, int dbm)
+#endif
 {
-       DBG_8192C("%s\n", __func__);
+#if 0
+       struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
+       int ret;
+
+       switch (type) {
+       case NL80211_TX_POWER_AUTOMATIC:
+               return 0;
+       case NL80211_TX_POWER_FIXED:
+               if (mbm < 0 || (mbm % 100))
+                       return -EOPNOTSUPP;
+
+               if (!test_bit(IWM_STATUS_READY, &iwm->status))
+                       return 0;
+
+               ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
+                                             CFG_TX_PWR_LIMIT_USR,
+                                             MBM_TO_DBM(mbm) * 2);
+               if (ret < 0)
+                       return ret;
+
+               return iwm_tx_power_trigger(iwm);
+       default:
+               IWM_ERR(iwm, "Unsupported power type: %d\n", type);
+               return -EOPNOTSUPP;
+       }
+#endif
+       DBG_8723A("%s\n", __func__);
        return 0;
 }
 
-static int cfg80211_rtw_get_txpower(struct wiphy *wiphy, int *dbm)
+static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
+       struct wireless_dev *wdev,
+#endif
+       int *dbm)
 {
-       DBG_8192C("%s\n", __func__);
+       //_adapter *padapter = wiphy_to_adapter(wiphy);
+
+       DBG_8723A("%s\n", __func__);
 
        *dbm = (12);
 
        return 0;
 }
 
+inline bool rtw_cfg80211_pwr_mgmt(_adapter *adapter)
+{
+       struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(adapter->rtw_wdev);
+       return rtw_wdev_priv->power_mgmt;
+}
+
 static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
                                       struct net_device *ndev,
                                       bool enabled, int timeout)
 {
        _adapter *padapter = wiphy_to_adapter(wiphy);
+       struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(padapter->rtw_wdev);
 
-       DBG_871X(FUNC_NDEV_FMT" enabled:%u, timeout:%d\n", FUNC_NDEV_ARG(ndev),
+       DBG_8723A(FUNC_NDEV_FMT" enabled:%u, timeout:%d\n", FUNC_NDEV_ARG(ndev),
                enabled, timeout);
 
-#if defined(CONFIG_CONCURRENT_MODE)
-       return -EPERM;
-#endif /* defined(CONFIG_CONCURRENT_MODE) */
+       rtw_wdev_priv->power_mgmt = enabled;
 
-       if (enabled)
-               rtw_pm_set_lps(padapter, PS_MODE_MIN);
-       else
-               rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
+       #ifdef CONFIG_LPS
+       if (!enabled)
+               LPS_Leave(padapter);
+       #endif
 
        return 0;
 }
@@ -2739,47 +2974,48 @@ static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
                                  struct net_device *netdev,
                                  struct cfg80211_pmksa *pmksa)
 {
-       u8      index,blInserted = false;
+       u8      index,blInserted = _FALSE;
        _adapter        *padapter = wiphy_to_adapter(wiphy);
        struct security_priv    *psecuritypriv = &padapter->securitypriv;
        u8      strZeroMacAddress[ ETH_ALEN ] = { 0x00 };
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
 
-       if ( _rtw_memcmp( pmksa->bssid, strZeroMacAddress, ETH_ALEN ) == true )
+       if (!memcmp(pmksa->bssid, strZeroMacAddress, ETH_ALEN))
        {
                return -EINVAL;
        }
 
-       blInserted = false;
+       blInserted = _FALSE;
 
        //overwrite PMKID
-       for (index=0 ; index<NUM_PMKID_CACHE; index++)
+       for(index=0 ; index<NUM_PMKID_CACHE; index++)
        {
-               if ( _rtw_memcmp( psecuritypriv->PMKIDList[index].Bssid, pmksa->bssid, ETH_ALEN) ==true )
-               { // BSSID is matched, the same AP => rewrite with new PMKID.
-                       DBG_871X(FUNC_NDEV_FMT" BSSID exists in the PMKList.\n", FUNC_NDEV_ARG(netdev));
+               if (!memcmp(psecuritypriv->PMKIDList[index].Bssid,
+                          pmksa->bssid, ETH_ALEN)) {
+                       /* BSSID is matched, the same AP => rewrite with new PMKID. */
+                       DBG_8723A(FUNC_NDEV_FMT" BSSID exists in the PMKList.\n", FUNC_NDEV_ARG(netdev));
 
-                       memcpy( psecuritypriv->PMKIDList[index].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
-                       psecuritypriv->PMKIDList[index].bUsed = true;
+                       memcpy(psecuritypriv->PMKIDList[index].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
+                       psecuritypriv->PMKIDList[index].bUsed = _TRUE;
                        psecuritypriv->PMKIDIndex = index+1;
-                       blInserted = true;
+                       blInserted = _TRUE;
                        break;
                }
        }
 
-       if (!blInserted)
+       if(!blInserted)
        {
                // Find a new entry
-               DBG_871X(FUNC_NDEV_FMT" Use the new entry index = %d for this PMKID.\n",
+               DBG_8723A(FUNC_NDEV_FMT" Use the new entry index = %d for this PMKID.\n",
                        FUNC_NDEV_ARG(netdev), psecuritypriv->PMKIDIndex );
 
                memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, pmksa->bssid, ETH_ALEN);
                memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
 
-               psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true;
+               psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = _TRUE;
                psecuritypriv->PMKIDIndex++ ;
-               if (psecuritypriv->PMKIDIndex==16)
+               if(psecuritypriv->PMKIDIndex==16)
                {
                        psecuritypriv->PMKIDIndex =0;
                }
@@ -2792,27 +3028,28 @@ static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
                                  struct net_device *netdev,
                                  struct cfg80211_pmksa *pmksa)
 {
-       u8      index, bMatched = false;
+       u8      index, bMatched = _FALSE;
        _adapter        *padapter = wiphy_to_adapter(wiphy);
        struct security_priv    *psecuritypriv = &padapter->securitypriv;
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
 
-       for (index=0 ; index<NUM_PMKID_CACHE; index++)
+       for(index=0 ; index<NUM_PMKID_CACHE; index++)
        {
-               if ( _rtw_memcmp( psecuritypriv->PMKIDList[index].Bssid, pmksa->bssid, ETH_ALEN) ==true )
-               { // BSSID is matched, the same AP => Remove this PMKID information and reset it.
-                       memset( psecuritypriv->PMKIDList[index].Bssid, 0x00, ETH_ALEN );
-                       memset( psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN );
-                       psecuritypriv->PMKIDList[index].bUsed = false;
-                       bMatched = true;
+               if (!memcmp(psecuritypriv->PMKIDList[index].Bssid,
+                           pmksa->bssid, ETH_ALEN)) {
+                       /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
+                       memset(psecuritypriv->PMKIDList[index].Bssid, 0x00, ETH_ALEN);
+                       memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN);
+                       psecuritypriv->PMKIDList[index].bUsed = _FALSE;
+                       bMatched = _TRUE;
                        break;
                }
        }
 
-       if (false == bMatched)
+       if(_FALSE == bMatched)
        {
-               DBG_871X(FUNC_NDEV_FMT" do not have matched BSSID\n"
+               DBG_8723A(FUNC_NDEV_FMT" do not have matched BSSID\n"
                        , FUNC_NDEV_ARG(netdev));
                return -EINVAL;
        }
@@ -2826,9 +3063,9 @@ static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
        _adapter        *padapter = wiphy_to_adapter(wiphy);
        struct security_priv    *psecuritypriv = &padapter->securitypriv;
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
 
-       memset( &psecuritypriv->PMKIDList[ 0 ], 0x00, sizeof( RT_PMKID_LIST ) * NUM_PMKID_CACHE );
+       memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
        psecuritypriv->PMKIDIndex = 0;
 
        return 0;
@@ -2843,7 +3080,7 @@ void rtw_cfg80211_indicate_sta_assoc(_adapter *padapter, u8 *pmgmt_frame, uint f
        struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
        struct net_device *ndev = padapter->pnetdev;
 
-       DBG_8192C("%s(padapter=%p,%s)\n", __func__, padapter, ndev->name);
+       DBG_8723A("%s(padapter=%p,%s)\n", __func__, padapter, ndev->name);
 
 #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
        {
@@ -2868,16 +3105,16 @@ void rtw_cfg80211_indicate_sta_assoc(_adapter *padapter, u8 *pmgmt_frame, uint f
                freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
 
        #ifdef COMPAT_KERNEL_RELEASE
-       rtw_cfg80211_rx_mgmt(ndev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
+       rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
        #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
-       rtw_cfg80211_rx_mgmt(ndev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
+       rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
        #else //COMPAT_KERNEL_RELEASE
        {
                //to avoid WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)  when calling cfg80211_send_rx_assoc()
                pwdev->iftype = NL80211_IFTYPE_STATION;
-               DBG_8192C("iftype=%d before call cfg80211_send_rx_assoc()\n", pwdev->iftype);
-               rtw_cfg80211_send_rx_assoc(ndev, NULL, pmgmt_frame, frame_len);
-               DBG_8192C("iftype=%d after call cfg80211_send_rx_assoc()\n", pwdev->iftype);
+               DBG_8723A("iftype=%d before call cfg80211_send_rx_assoc()\n", pwdev->iftype);
+               rtw_cfg80211_send_rx_assoc(padapter, NULL, pmgmt_frame, frame_len);
+               DBG_8723A("iftype=%d after call cfg80211_send_rx_assoc()\n", pwdev->iftype);
                pwdev->iftype = NL80211_IFTYPE_AP;
                //cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC);
        }
@@ -2899,7 +3136,7 @@ void rtw_cfg80211_indicate_sta_disassoc(_adapter *padapter, unsigned char *da, u
        struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
        struct net_device *ndev = padapter->pnetdev;
 
-       DBG_8192C("%s(padapter=%p,%s)\n", __func__, padapter, ndev->name);
+       DBG_8723A("%s(padapter=%p,%s)\n", __func__, padapter, ndev->name);
 
 #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
        cfg80211_del_sta(ndev, da, GFP_ATOMIC);
@@ -2933,9 +3170,9 @@ void rtw_cfg80211_indicate_sta_disassoc(_adapter *padapter, unsigned char *da, u
        pmgmt_frame = rtw_set_fixed_ie(pmgmt_frame, _RSON_CODE_ , (unsigned char *)&reason, &frame_len);
 
        #ifdef COMPAT_KERNEL_RELEASE
-       rtw_cfg80211_rx_mgmt(padapter->pnetdev, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
+       rtw_cfg80211_rx_mgmt(padapter, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
        #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
-       rtw_cfg80211_rx_mgmt(padapter->pnetdev, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
+       rtw_cfg80211_rx_mgmt(padapter, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
        #else //COMPAT_KERNEL_RELEASE
        cfg80211_send_disassoc(padapter->pnetdev, mgmt_buf, frame_len);
        //cfg80211_rx_action(padapter->pnetdev, freq, mgmt_buf, frame_len, GFP_ATOMIC);
@@ -2947,7 +3184,7 @@ static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
 {
        int ret = 0;
 
-       DBG_8192C("%s\n", __func__);
+       DBG_8723A("%s\n", __func__);
 
        return ret;
 }
@@ -2956,7 +3193,7 @@ static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
 {
        int ret = 0;
 
-       DBG_8192C("%s\n", __func__);
+       DBG_8723A("%s\n", __func__);
 
        return ret;
 }
@@ -2969,14 +3206,14 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
        int dot11_hdr_len = 24;
        int snap_len = 6;
        unsigned char *pdata;
-       unsigned short frame_ctl;
+       u16 frame_ctl;
        unsigned char src_mac_addr[6];
        unsigned char dst_mac_addr[6];
        struct ieee80211_hdr *dot11_hdr;
        struct ieee80211_radiotap_header *rtap_hdr;
        _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
                goto fail;
@@ -2989,9 +3226,9 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
        if (unlikely(skb->len < rtap_len))
                goto fail;
 
-       if (rtap_len != 14)
+       if(rtap_len != 14)
        {
-               DBG_8192C("radiotap len (should be 14): %d\n", rtap_len);
+               DBG_8723A("radiotap len (should be 14): %d\n", rtap_len);
                goto fail;
        }
 
@@ -3001,7 +3238,7 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
        dot11_hdr = (struct ieee80211_hdr *)skb->data;
        frame_ctl = le16_to_cpu(dot11_hdr->frame_control);
        /* Check if the QoS bit is set */
-       if ((frame_ctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
+       if ((frame_ctl & RTW_IEEE80211_FCTL_FTYPE) == RTW_IEEE80211_FTYPE_DATA) {
                /* Check if this ia a Wireless Distribution System (WDS) frame
                 * which has 4 MAC addresses
                 */
@@ -3021,7 +3258,7 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
                memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr));
                memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr));
 
-               DBG_8192C("should be eapol packet\n");
+               DBG_8723A("should be eapol packet\n");
 
                /* Use the real net device to transmit the packet */
                ret =  rtw_xmit_entry(skb, padapter->pnetdev);
@@ -3029,7 +3266,9 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
                return ret;
 
        }
-       else if ((frame_ctl & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE)) == cpu_to_le16(IEEE80211_STYPE_ACTION))
+       else if ((frame_ctl & (RTW_IEEE80211_FCTL_FTYPE|RTW_IEEE80211_FCTL_STYPE))
+               == (RTW_IEEE80211_FTYPE_MGMT|RTW_IEEE80211_STYPE_ACTION)
+       )
        {
                //only for action frames
                struct xmit_frame               *pmgntframe;
@@ -3042,26 +3281,27 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
                struct mlme_ext_priv    *pmlmeext = &(padapter->mlmeextpriv);
                u8 *buf = skb->data;
                u32 len = skb->len;
+               u8 category, action;
+               int type = -1;
 
-               #ifdef CONFIG_P2P
-               if (rtw_p2p_check_frames(padapter, buf, len, true) < 0)
-               {
+               if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
+                       DBG_8723A(FUNC_NDEV_FMT" frame_control:0x%x\n", FUNC_NDEV_ARG(ndev),
+                               le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
                        goto fail;
                }
-               #ifdef CONFIG_WFD
-               {
-                       struct wifi_display_info                *pwfd_info;
-
-                       pwfd_info = padapter->wdinfo.wfd_info;
 
-                       if ( true == pwfd_info->wfd_enable )
-                       {
-                               rtw_append_wfd_ie( padapter, buf, &skb->len );
-                       }
-               }
-               #endif // CONFIG_WFD
-               #endif // CONFIG_P2P
+               DBG_8723A("RTW_Tx:da="MAC_FMT" via "FUNC_NDEV_FMT"\n",
+                       MAC_ARG(GetAddr1Ptr(buf)), FUNC_NDEV_ARG(ndev));
+               #ifdef CONFIG_P2P
+               if((type = rtw_p2p_check_frames(padapter, buf, len, _TRUE)) >= 0)
+                       goto dump;
+               #endif
+               if (category == RTW_WLAN_CATEGORY_PUBLIC)
+                       DBG_8723A("RTW_Tx:%s\n", action_public_str(action));
+               else
+                       DBG_8723A("RTW_Tx:category(%u), action(%u)\n", category, action);
 
+dump:
                //starting alloc mgmt frame to dump it
                if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
                {
@@ -3071,13 +3311,26 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
                //update attribute
                pattrib = &pmgntframe->attrib;
                update_mgntframe_attrib(padapter, pattrib);
-               pattrib->retry_ctrl = false;
+               pattrib->retry_ctrl = _FALSE;
 
                memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
                pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
 
                memcpy(pframe, (void*)buf, len);
+               #ifdef CONFIG_WFD
+               if (type >= 0)
+               {
+                       struct wifi_display_info                *pwfd_info;
+
+                       pwfd_info = padapter->wdinfo.wfd_info;
+
+                       if ( _TRUE == pwfd_info->wfd_enable )
+                       {
+                               rtw_append_wfd_ie( padapter, pframe, &len );
+                       }
+               }
+               #endif // CONFIG_WFD
                pattrib->pktlen = len;
 
                pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
@@ -3094,7 +3347,7 @@ static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_de
        }
        else
        {
-               DBG_8192C("frame_ctl=0x%x\n", frame_ctl & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE));
+               DBG_8723A("frame_ctl=0x%x\n", frame_ctl & (RTW_IEEE80211_FCTL_FTYPE|RTW_IEEE80211_FCTL_STYPE));
        }
 
 
@@ -3108,14 +3361,14 @@ fail:
 
 static void rtw_cfg80211_monitor_if_set_multicast_list(struct net_device *ndev)
 {
-       DBG_8192C("%s\n", __func__);
+       DBG_8723A("%s\n", __func__);
 }
 
 static int rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
 {
        int ret = 0;
 
-       DBG_8192C("%s\n", __func__);
+       DBG_8723A("%s\n", __func__);
 
        return ret;
 }
@@ -3132,149 +3385,178 @@ static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
 };
 #endif
 
-static struct net_device *rtw_cfg80211_add_monitor_if (_adapter *padapter, char *name)
+static int rtw_cfg80211_add_monitor_if(_adapter *padapter, char *name, struct net_device **ndev)
 {
        int ret = 0;
-       struct net_device* ndev = NULL;
+       struct net_device* mon_ndev = NULL;
+       struct wireless_dev* mon_wdev = NULL;
        struct rtw_netdev_priv_indicator *pnpi;
        struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
 
-       DBG_8192C("%s\n", __func__);
-
        if (!name ) {
+               DBG_8723A(FUNC_ADPT_FMT" without specific name\n", FUNC_ADPT_ARG(padapter));
                ret = -EINVAL;
                goto out;
        }
 
-       if ((strnicmp(name, pwdev_priv->ifname_mon, strlen(name)) ==0)
-               && pwdev_priv->pmon_ndev)
-       {
-               ndev = pwdev_priv->pmon_ndev;
-
-               DBG_8192C("%s, monitor interface(%s) has existed\n", __func__, name);
-
+       if (pwdev_priv->pmon_ndev) {
+               DBG_8723A(FUNC_ADPT_FMT" monitor interface exist: "NDEV_FMT"\n",
+                       FUNC_ADPT_ARG(padapter), NDEV_ARG(pwdev_priv->pmon_ndev));
+               ret = -EBUSY;
                goto out;
        }
 
-
-       ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator));
-       if (!ndev) {
+       mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator));
+       if (!mon_ndev) {
+               DBG_8723A(FUNC_ADPT_FMT" allocate ndev fail\n", FUNC_ADPT_ARG(padapter));
                ret = -ENOMEM;
                goto out;
        }
 
-       ndev->type = ARPHRD_IEEE80211_RADIOTAP;
-       strncpy(ndev->name, name, IFNAMSIZ);
-       ndev->name[IFNAMSIZ - 1] = 0;
+       mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
+       strncpy(mon_ndev->name, name, IFNAMSIZ);
+       mon_ndev->name[IFNAMSIZ - 1] = 0;
+       mon_ndev->destructor = rtw_ndev_destructor;
 
 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
-       ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
+       mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
 #else
-       ndev->open = rtw_cfg80211_monitor_if_open;
-       ndev->stop = rtw_cfg80211_monitor_if_close;
-       ndev->hard_start_xmit = rtw_cfg80211_monitor_if_xmit_entry;
-       ndev->set_mac_address = rtw_cfg80211_monitor_if_set_mac_address;
+       mon_ndev->open = rtw_cfg80211_monitor_if_open;
+       mon_ndev->stop = rtw_cfg80211_monitor_if_close;
+       mon_ndev->hard_start_xmit = rtw_cfg80211_monitor_if_xmit_entry;
+       mon_ndev->set_mac_address = rtw_cfg80211_monitor_if_set_mac_address;
 #endif
 
-       pnpi = netdev_priv(ndev);
+       pnpi = netdev_priv(mon_ndev);
        pnpi->priv = padapter;
        pnpi->sizeof_priv = sizeof(_adapter);
 
-       ret = register_netdevice(ndev);
+       /*  wdev */
+       mon_wdev = (struct wireless_dev *)
+               kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
+       if (!mon_wdev) {
+               DBG_8723A(FUNC_ADPT_FMT" allocate mon_wdev fail\n", FUNC_ADPT_ARG(padapter));
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
+       mon_wdev->netdev = mon_ndev;
+       mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
+       mon_ndev->ieee80211_ptr = mon_wdev;
+
+       ret = register_netdevice(mon_ndev);
        if (ret) {
                goto out;
        }
 
-       pwdev_priv->pmon_ndev = ndev;
+       *ndev = pwdev_priv->pmon_ndev = mon_ndev;
        memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ+1);
 
 out:
-       if (ret && ndev)
-       {
-               free_netdev(ndev);
-               ndev = NULL;
+       if (ret && mon_wdev) {
+               kfree(mon_wdev);
+               mon_wdev = NULL;
        }
 
+       if (ret && mon_ndev) {
+               free_netdev(mon_ndev);
+               *ndev = mon_ndev = NULL;
+       }
 
-       DBG_8192C("%s, ndev=%p, pmon_ndev=%p, ret=%d\n", __func__, ndev, pwdev_priv->pmon_ndev, ret);
-
-       return ndev;
+       return ret;
 }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
-static struct net_device * cfg80211_rtw_add_virtual_intf(struct wiphy *wiphy, char *name,
-#else  // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-static int     cfg80211_rtw_add_virtual_intf(struct wiphy *wiphy, char *name,
-#endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-                                   enum nl80211_iftype type, u32 *flags,
-                                   struct vif_params *params)
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+static struct wireless_dev *
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
+static struct net_device *
+#else
+static int
+#endif
+       cfg80211_rtw_add_virtual_intf(
+               struct wiphy *wiphy,
+       #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0))
+               const char *name,
+       #else
+               char *name,
+       #endif
+               enum nl80211_iftype type, u32 *flags, struct vif_params *params)
 {
+       int ret = 0;
        struct net_device* ndev = NULL;
        _adapter *padapter = wiphy_to_adapter(wiphy);
 
-       DBG_8192C("%s(padapter=%p), ifname=%s, type=%d\n", __func__, padapter, name, type);
-
+       DBG_8723A(FUNC_ADPT_FMT " wiphy:%s, name:%s, type:%d\n",
+               FUNC_ADPT_ARG(padapter), wiphy_name(wiphy), name, type);
 
        switch (type) {
        case NL80211_IFTYPE_ADHOC:
        case NL80211_IFTYPE_AP_VLAN:
        case NL80211_IFTYPE_WDS:
        case NL80211_IFTYPE_MESH_POINT:
-
+               ret = -ENODEV;
                break;
        case NL80211_IFTYPE_MONITOR:
-               ndev = rtw_cfg80211_add_monitor_if (padapter, name);
+               ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev);
                break;
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
        case NL80211_IFTYPE_P2P_CLIENT:
 #endif
        case NL80211_IFTYPE_STATION:
-
+               ret = -ENODEV;
                break;
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
        case NL80211_IFTYPE_P2P_GO:
 #endif
        case NL80211_IFTYPE_AP:
-
+               ret = -ENODEV;
                break;
        default:
-               DBG_8192C("Unsupported interface type\n");
+               ret = -ENODEV;
+               DBG_8723A("Unsupported interface type\n");
                break;
        }
 
-       DBG_8192C("ndev=%p\n", ndev);
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
-       return ndev;
-#else  // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-       return 0;
-#endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
+       DBG_8723A(FUNC_ADPT_FMT" ndev:%p, ret:%d\n", FUNC_ADPT_ARG(padapter), ndev, ret);
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+       return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
+       return ndev ? ndev : ERR_PTR(ret);
+#else
+       return ret;
+#endif
 }
 
-static int     cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy, struct net_device *ndev)
+static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+       struct wireless_dev *wdev
+#else
+       struct net_device *ndev
+#endif
+)
 {
-       _adapter *padapter = wiphy_to_adapter(wiphy);
        struct rtw_wdev_priv *pwdev_priv = (struct rtw_wdev_priv *)wiphy_priv(wiphy);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+       struct net_device *ndev;
+       ndev = wdev ? wdev->netdev : NULL;
+#endif
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       if (!ndev)
+               goto exit;
 
-       if (ndev)
-       {
-               unregister_netdev(ndev);
+       unregister_netdevice(ndev);
 
-               free_netdev(ndev);
-
-               if (ndev == pwdev_priv->pmon_ndev)
-               {
-                       DBG_8192C("remove monitor interface\n");
-                       pwdev_priv->pmon_ndev =         NULL;
-                       pwdev_priv->ifname_mon[0] = '\0';
-               }
-       }
+       if (ndev == pwdev_priv->pmon_ndev) {
+               pwdev_priv->pmon_ndev = NULL;
+               pwdev_priv->ifname_mon[0] = '\0';
+               DBG_8723A(FUNC_NDEV_FMT" remove monitor interface\n", FUNC_NDEV_ARG(ndev));
+       }
 
+exit:
        return 0;
 }
 
@@ -3285,29 +3567,29 @@ static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, co
        uint len, wps_ielen=0;
        uint p2p_ielen=0;
        u8 *p2p_ie;
-       u8 got_p2p_ie = false;
+       u8 got_p2p_ie = _FALSE;
        struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
        //struct sta_priv *pstapriv = &padapter->stapriv;
 
 
-       DBG_8192C("%s beacon_head_len=%zu, beacon_tail_len=%zu\n", __FUNCTION__, head_len, tail_len);
+       DBG_8723A("%s beacon_head_len=%zu, beacon_tail_len=%zu\n", __FUNCTION__, head_len, tail_len);
 
 
-       if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
+       if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
                return -EINVAL;
 
-       if (head_len<24)
+       if(head_len<24)
                return -EINVAL;
 
 
-       pbuf = rtw_zmalloc(head_len+tail_len);
-       if (!pbuf)
+       pbuf = kzalloc(head_len+tail_len, GFP_KERNEL);
+       if(!pbuf)
                return -ENOMEM;
 
 
        //memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2);
 
-       //if ((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<=0))
+       //if((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<=0))
        //      pstapriv->max_num_sta = NUM_STA;
 
 
@@ -3317,36 +3599,35 @@ static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, co
        len = head_len+tail_len-24;
 
        //check wps ie if inclued
-       if (rtw_get_wps_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &wps_ielen))
-               DBG_8192C("add bcn, wps_ielen=%d\n", wps_ielen);
+       if(rtw_get_wps_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &wps_ielen))
+               DBG_8723A("add bcn, wps_ielen=%d\n", wps_ielen);
 
 #ifdef CONFIG_P2P
        //check p2p ie if inclued
-       if (rtw_get_p2p_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &p2p_ielen))
+       if(rtw_get_p2p_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &p2p_ielen))
        {
-               DBG_8192C("got p2p_ie, len=%d\n", p2p_ielen);
-               got_p2p_ie = true;
+               DBG_8723A("got p2p_ie, len=%d\n", p2p_ielen);
+               got_p2p_ie = _TRUE;
        }
 #endif
 
+       /* pbss_network->IEs will not include p2p_ie, wfd ie */
        rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, P2P_OUI, 4);
+       rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, WFD_OUI, 4);
 
-       // pbss_network->IEs will not include p2p_ie
-       if (rtw_check_beacon_data(adapter, pbuf,  len) == _SUCCESS)
-       //if (rtw_check_beacon_data(padapter, pbuf,  len) == _SUCCESS)
-       {
+       if (rtw_check_beacon_data(adapter, pbuf,  len) == _SUCCESS) {
 #ifdef  CONFIG_P2P
                //check p2p if enable
-               if (got_p2p_ie == true)
+               if(got_p2p_ie == _TRUE)
                {
                        struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
                        struct wifidirect_info *pwdinfo= &(adapter->wdinfo);
 
-                       if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+                       if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
                        {
-                               DBG_8192C("Enable P2P function for the first time\n");
+                               DBG_8723A("Enable P2P function for the first time\n");
                                rtw_p2p_enable(adapter, P2P_ROLE_GO);
-                               wdev_to_priv(adapter->rtw_wdev)->p2p_enabled = true;
+                               wdev_to_priv(adapter->rtw_wdev)->p2p_enabled = _TRUE;
                        }
                        else
                        {
@@ -3354,7 +3635,7 @@ static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, co
                                _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
                                _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
 
-                               DBG_8192C("enter GO Mode, p2p_ielen=%d\n", p2p_ielen);
+                               DBG_8723A("enter GO Mode, p2p_ielen=%d\n", p2p_ielen);
 
                                rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
                                rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
@@ -3375,7 +3656,7 @@ static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, co
        }
 
 
-       rtw_mfree(pbuf, head_len+tail_len);
+       kfree(pbuf);
 
        return ret;
 }
@@ -3387,7 +3668,7 @@ static int        cfg80211_rtw_add_beacon(struct wiphy *wiphy, struct net_device *ndev,
        int ret=0;
        _adapter *adapter = wiphy_to_adapter(wiphy);
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
        ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
 
        return ret;
@@ -3399,9 +3680,9 @@ static int        cfg80211_rtw_set_beacon(struct wiphy *wiphy, struct net_device *ndev,
        _adapter *padapter = wiphy_to_adapter(wiphy);
        struct mlme_ext_priv    *pmlmeext = &(padapter->mlmeextpriv);
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
-       pmlmeext->bstart_bss = true;
+       pmlmeext->bstart_bss = _TRUE;
 
        cfg80211_rtw_add_beacon(wiphy, ndev, info);
 
@@ -3410,7 +3691,7 @@ static int        cfg80211_rtw_set_beacon(struct wiphy *wiphy, struct net_device *ndev,
 
 static int     cfg80211_rtw_del_beacon(struct wiphy *wiphy, struct net_device *ndev)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        return 0;
 }
@@ -3421,11 +3702,34 @@ static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
        int ret = 0;
        _adapter *adapter = wiphy_to_adapter(wiphy);
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT" hidden_ssid:%d, auth_type:%d\n", FUNC_NDEV_ARG(ndev),
+               settings->hidden_ssid, settings->auth_type);
 
        ret = rtw_add_beacon(adapter, settings->beacon.head, settings->beacon.head_len,
                settings->beacon.tail, settings->beacon.tail_len);
 
+       adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid;
+
+       if (settings->ssid && settings->ssid_len) {
+               WLAN_BSSID_EX *pbss_network = &adapter->mlmepriv.cur_network.network;
+               WLAN_BSSID_EX *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network;
+
+               if(0)
+               DBG_8723A(FUNC_ADPT_FMT" ssid:(%s,%d), from ie:(%s,%d)\n", FUNC_ADPT_ARG(adapter),
+                       settings->ssid, settings->ssid_len,
+                       pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
+
+               memcpy(pbss_network->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
+               pbss_network->Ssid.SsidLength = settings->ssid_len;
+               memcpy(pbss_network_ext->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
+               pbss_network_ext->Ssid.SsidLength = settings->ssid_len;
+
+               if(0)
+               DBG_8723A(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
+                       pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
+                       pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
+       }
+
        return ret;
 }
 
@@ -3435,7 +3739,7 @@ static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *nd
        int ret = 0;
        _adapter *adapter = wiphy_to_adapter(wiphy);
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
 
@@ -3444,7 +3748,7 @@ static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *nd
 
 static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
        return 0;
 }
 
@@ -3453,7 +3757,7 @@ static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
 static int     cfg80211_rtw_add_station(struct wiphy *wiphy, struct net_device *ndev,
                               u8 *mac, struct station_parameters *params)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        return 0;
 }
@@ -3462,7 +3766,7 @@ static int        cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
                               u8 *mac)
 {
        int ret=0;
-       unsigned long irqL;
+       _irqL irqL;
        _list   *phead, *plist;
        u8 updated;
        struct sta_info *psta = NULL;
@@ -3470,18 +3774,18 @@ static int      cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
        struct sta_priv *pstapriv = &padapter->stapriv;
 
-       DBG_871X("+"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A("+"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
-       if (check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != true)
+       if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != _TRUE)
        {
-               DBG_8192C("%s, fw_state != FW_LINKED|WIFI_AP_STATE\n", __func__);
+               DBG_8723A("%s, fw_state != FW_LINKED|WIFI_AP_STATE\n", __func__);
                return -EINVAL;
        }
 
 
-       if (!mac)
+       if(!mac)
        {
-               DBG_8192C("flush all sta, and cam_entry\n");
+               DBG_8723A("flush all sta, and cam_entry\n");
 
                flush_all_cam_entry(padapter);  //clear CAM
 
@@ -3491,7 +3795,7 @@ static int        cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
        }
 
 
-       DBG_8192C("free sta macaddr =" MAC_FMT "\n", MAC_ARG(mac));
+       DBG_8723A("free sta macaddr =" MAC_FMT "\n", MAC_ARG(mac));
 
        if (mac[0] == 0xff && mac[1] == 0xff &&
            mac[2] == 0xff && mac[3] == 0xff &&
@@ -3501,33 +3805,34 @@ static int      cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
        }
 
 
-       _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+       spin_lock_bh(&pstapriv->asoc_list_lock);
 
        phead = &pstapriv->asoc_list;
        plist = get_next(phead);
 
        //check asoc_queue
-       while ((rtw_end_of_queue_search(phead, plist)) == false)
+       while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
        {
                psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
 
                plist = get_next(plist);
 
-               if (_rtw_memcmp(mac, psta->hwaddr, ETH_ALEN))
+               if (!memcmp(mac, psta->hwaddr, ETH_ALEN))
                {
-                       if (psta->dot8021xalg == 1 && psta->bpairwise_key_installed == false)
+                       if(psta->dot8021xalg == 1 && psta->bpairwise_key_installed == _FALSE)
                        {
-                               DBG_8192C("%s, sta's dot8021xalg = 1 and key_installed = false\n", __func__);
+                               DBG_8723A("%s, sta's dot8021xalg = 1 and key_installed = _FALSE\n", __func__);
                        }
                        else
                        {
-                               DBG_8192C("free psta=%p, aid=%d\n", psta, psta->aid);
+                               DBG_8723A("free psta=%p, aid=%d\n", psta, psta->aid);
 
                                rtw_list_delete(&psta->asoc_list);
+                               pstapriv->asoc_list_cnt--;
 
-                               //_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
-                               updated = ap_free_sta(padapter, psta);
-                               //_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+                               //spin_unlock_bh(&pstapriv->asoc_list_lock);
+                               updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING);
+                               //spin_lock_bh(&pstapriv->asoc_list_lock);
 
                                psta = NULL;
 
@@ -3538,11 +3843,11 @@ static int      cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
 
        }
 
-       _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
+       spin_unlock_bh(&pstapriv->asoc_list_lock);
 
        associated_clients_update(padapter, updated);
 
-       DBG_871X("-"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A("-"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        return ret;
 
@@ -3551,7 +3856,7 @@ static int        cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
 static int     cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *ndev,
                                  u8 *mac, struct station_parameters *params)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        return 0;
 }
@@ -3559,7 +3864,7 @@ static int        cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *n
 static int     cfg80211_rtw_dump_station(struct wiphy *wiphy, struct net_device *ndev,
                               int idx, u8 *mac, struct station_info *sinfo)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        //TODO: dump scanned queue
 
@@ -3571,8 +3876,22 @@ static int       cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
 {
        u8 i;
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+/*
+       DBG_8723A("use_cts_prot=%d\n", params->use_cts_prot);
+       DBG_8723A("use_short_preamble=%d\n", params->use_short_preamble);
+       DBG_8723A("use_short_slot_time=%d\n", params->use_short_slot_time);
+       DBG_8723A("ap_isolate=%d\n", params->ap_isolate);
+
+       DBG_8723A("basic_rates_len=%d\n", params->basic_rates_len);
+       for(i=0; i<params->basic_rates_len; i++)
+       {
+               DBG_8723A("basic_rates=%d\n", params->basic_rates[i]);
+
+       }
+*/
        return 0;
+
 }
 
 static int     cfg80211_rtw_set_channel(struct wiphy *wiphy
@@ -3582,7 +3901,7 @@ static int        cfg80211_rtw_set_channel(struct wiphy *wiphy
        , struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
 {
        #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
        #endif
 
        return 0;
@@ -3591,7 +3910,7 @@ static int        cfg80211_rtw_set_channel(struct wiphy *wiphy
 static int     cfg80211_rtw_auth(struct wiphy *wiphy, struct net_device *ndev,
                        struct cfg80211_auth_request *req)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        return 0;
 }
@@ -3599,7 +3918,7 @@ static int        cfg80211_rtw_auth(struct wiphy *wiphy, struct net_device *ndev,
 static int     cfg80211_rtw_assoc(struct wiphy *wiphy, struct net_device *ndev,
                         struct cfg80211_assoc_request *req)
 {
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
 
        return 0;
 }
@@ -3607,79 +3926,102 @@ static int     cfg80211_rtw_assoc(struct wiphy *wiphy, struct net_device *ndev,
 
 void rtw_cfg80211_rx_action_p2p(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
 {
+       int type;
        s32 freq;
        int channel;
        struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+       u8 category, action;
 
-#ifdef CONFIG_CONCURRENT_MODE
-       if (padapter->pcodatapriv)
-               channel = padapter->pcodatapriv->co_ch;
-#else
-       channel = pmlmeext->cur_channel;
-#endif
-
-#ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s, cur_ch=%d\n", __func__, channel);
-#endif
+       channel = rtw_get_oper_ch(padapter);
 
-#ifdef CONFIG_P2P
-       DBG_8192C("RTW_Rx:cur_ch=%d\n", channel);
-       rtw_p2p_check_frames(padapter, pmgmt_frame, frame_len, false);
-#endif //CONFIG_P2P
+       DBG_8723A("RTW_Rx:cur_ch=%d\n", channel);
+       #ifdef CONFIG_P2P
+       type = rtw_p2p_check_frames(padapter, pmgmt_frame, frame_len, _FALSE);
+       if (type >= 0)
+               goto indicate;
+       #endif
+       rtw_action_frame_parse(pmgmt_frame, frame_len, &category, &action);
+       DBG_8723A("RTW_Rx:category(%u), action(%u)\n", category, action);
 
+indicate:
        if (channel <= RTW_CH_MAX_2G_CHANNEL)
-       {
                freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
-       }
        else
-       {
                freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
-       }
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       rtw_cfg80211_rx_mgmt(padapter->pnetdev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
+       rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
 #else
        cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC);
 #endif
-
 }
 
 void rtw_cfg80211_rx_p2p_action_public(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
 {
+       int type;
        s32 freq;
        int channel;
        struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
+       u8 category, action;
 
-#ifdef CONFIG_CONCURRENT_MODE
-       if (padapter->pcodatapriv)
-               channel = padapter->pcodatapriv->co_ch;
-#else
-       channel = pmlmeext->cur_channel;
-#endif
-
-#ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s, cur_ch=%d\n", __func__, channel);
-#endif
+       channel = rtw_get_oper_ch(padapter);
 
+       DBG_8723A("RTW_Rx:cur_ch=%d\n", channel);
        #ifdef CONFIG_P2P
-       DBG_8192C("RTW_Rx:cur_ch=%d\n", channel);
-       rtw_p2p_check_frames(padapter, pmgmt_frame, frame_len, false);
+       type = rtw_p2p_check_frames(padapter, pmgmt_frame, frame_len, _FALSE);
+       if (type >= 0) {
+               switch (type) {
+               case P2P_GO_NEGO_CONF:
+               case P2P_PROVISION_DISC_RESP:
+                       rtw_clear_scan_deny(padapter);
+               }
+               goto indicate;
+       }
        #endif
+       rtw_action_frame_parse(pmgmt_frame, frame_len, &category, &action);
+       DBG_8723A("RTW_Rx:category(%u), action(%u)\n", category, action);
 
+indicate:
        if (channel <= RTW_CH_MAX_2G_CHANNEL)
-       {
                freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
-       }
        else
-       {
                freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
-       }
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       rtw_cfg80211_rx_mgmt(padapter->pnetdev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
+       rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
 #else
        cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC);
 #endif
+}
+
+void rtw_cfg80211_rx_action(_adapter *adapter, u8 *frame, uint frame_len, const char*msg)
+{
+       s32 freq;
+       int channel;
+       struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
+       struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(adapter->rtw_wdev);
+       u8 category, action;
+
+       channel = rtw_get_oper_ch(adapter);
+
+       rtw_action_frame_parse(frame, frame_len, &category, &action);
+
+       DBG_8723A("RTW_Rx:cur_ch=%d\n", channel);
+       if (msg)
+               DBG_8723A("RTW_Rx:%s\n", msg);
+       else
+               DBG_8723A("RTW_Rx:category(%u), action(%u)\n", category, action);
+
+       if (channel <= RTW_CH_MAX_2G_CHANNEL)
+               freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
+       else
+               freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
+       rtw_cfg80211_rx_mgmt(adapter, freq, 0, frame, frame_len, GFP_ATOMIC);
+#else
+       cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
+#endif
 
 }
 
@@ -3720,7 +4062,7 @@ void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf,
        size_t frame_body_len = len - sizeof(struct rtw_ieee80211_hdr_3addr);
 
 
-       DBG_871X( "[%s] In\n", __FUNCTION__ );
+       DBG_8723A( "[%s] In\n", __FUNCTION__ );
 
        //prepare for building provision_request frame
        memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr1Ptr(buf), ETH_ALEN);
@@ -3732,7 +4074,7 @@ void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf,
        rtw_get_wps_attr_content( wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8*) &wps_devicepassword_id, &wps_devicepassword_id_len);
        wps_devicepassword_id = be16_to_cpu( wps_devicepassword_id );
 
-       switch (wps_devicepassword_id)
+       switch(wps_devicepassword_id)
        {
                case WPS_DPID_PIN:
                        pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
@@ -3899,19 +4241,26 @@ void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf,
 
        //dump_mgntframe(padapter, pmgntframe);
        if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS)
-               DBG_8192C("%s, ack to\n", __func__);
+               DBG_8723A("%s, ack to\n", __func__);
 
-       //if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
+       //if(wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
        //{
-       //      DBG_8192C("waiting for p2p peer key-in PIN CODE\n");
+       //      DBG_8723A("waiting for p2p peer key-in PIN CODE\n");
        //      rtw_msleep_os(15000); // 15 sec for key in PIN CODE, workaround for GS2 before issuing Nego Req.
        //}
 
 }
 
-static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy, struct net_device *ndev,
+static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+       struct wireless_dev *wdev,
+#else
+       struct net_device *ndev,
+#endif
        struct ieee80211_channel * channel,
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
        enum nl80211_channel_type channel_type,
+#endif
        unsigned int duration, u64 *cookie)
 {
        s32 err = 0;
@@ -3921,39 +4270,53 @@ static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy, struct net_device
        struct wifidirect_info *pwdinfo = &padapter->wdinfo;
        struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
        u8 remain_ch = (u8) ieee80211_frequency_to_channel(channel->center_freq);
-       u8 ready_on_channel = false;
+       u8 ready_on_channel = _FALSE;
+
+       DBG_8723A(FUNC_ADPT_FMT" ch:%u duration:%d\n", FUNC_ADPT_ARG(padapter), remain_ch, duration);
 
-       DBG_871X(FUNC_NDEV_FMT" ch:%u duration:%d\n", FUNC_NDEV_ARG(ndev), remain_ch, duration);
+       if(pcfg80211_wdinfo->is_ro_ch == _TRUE)
+       {
+               DBG_8723A("%s, cancel ro ch timer\n", __func__);
+
+               _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
+
+#ifdef CONFIG_CONCURRENT_MODE
+                ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
+#endif //CONFIG_CONCURRENT_MODE
+
+               p2p_protocol_wk_hdl(padapter, P2P_RO_CH_WK);
+       }
 
-       pcfg80211_wdinfo->is_ro_ch = true;
+       pcfg80211_wdinfo->is_ro_ch = _TRUE;
 
-       if (_FAIL == rtw_pwr_wakeup(padapter)) {
+       if(_FAIL == rtw_pwr_wakeup(padapter)) {
                err = -EFAULT;
                goto exit;
        }
 
-       pcfg80211_wdinfo->remain_on_ch_dev = ndev;
        memcpy(&pcfg80211_wdinfo->remain_on_ch_channel, channel, sizeof(struct ieee80211_channel));
+       #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
        pcfg80211_wdinfo->remain_on_ch_type= channel_type;
+       #endif
        pcfg80211_wdinfo->remain_on_ch_cookie= *cookie;
 
        rtw_scan_abort(padapter);
 #ifdef CONFIG_CONCURRENT_MODE
-       if (rtw_buddy_adapter_up(padapter))
+       if(rtw_buddy_adapter_up(padapter))
                rtw_scan_abort(padapter->pbuddy_adapter);
 #endif //CONFIG_CONCURRENT_MODE
 
-       //if (!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
-       if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+       //if(!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
+       if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
        {
                rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
-               wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = true;
+               wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = _TRUE;
        }
        else
        {
                rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
 #ifdef CONFIG_DEBUG_CFG80211
-               DBG_8192C("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
+               DBG_8723A("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
 #endif
        }
 
@@ -3961,12 +4324,12 @@ static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy, struct net_device
        rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
 
 
-       if (duration < 400)
+       if(duration < 400)
                duration = duration*3;//extend from exper.
 
 
 #ifdef CONFIG_CONCURRENT_MODE
-       if (check_buddy_fwstate(padapter, _FW_LINKED) &&
+       if(check_buddy_fwstate(padapter, _FW_LINKED) &&
                (duration<pwdinfo->ext_listen_interval))
        {
                duration = duration +   pwdinfo->ext_listen_interval;
@@ -3975,85 +4338,87 @@ static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy, struct net_device
 
        pcfg80211_wdinfo->restore_channel = pmlmeext->cur_channel;
 
-       if (rtw_is_channel_set_contains_channel(pmlmeext->channel_set, remain_ch)) {
+       if(rtw_ch_set_search_ch(pmlmeext->channel_set, remain_ch) >= 0) {
 #ifdef CONFIG_CONCURRENT_MODE
                if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
                {
                        PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
                        struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
 
-                       if (remain_ch != pbuddy_mlmeext->cur_channel)
+                       if(remain_ch != pbuddy_mlmeext->cur_channel)
                        {
-                               if (ATOMIC_READ(&pwdev_priv->switch_ch_to)==1 ||
+                               if(ATOMIC_READ(&pwdev_priv->switch_ch_to)==1 ||
                                        (remain_ch != pmlmeext->cur_channel))
                                {
-                                       DBG_8192C("%s, issue nulldata pwrbit=1\n", __func__);
+                                       DBG_8723A("%s, issue nulldata pwrbit=1\n", __func__);
                                        issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
 
                                        ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
 
-                                       DBG_8192C("%s, set switch ch timer, duration=%d\n", __func__, duration-pwdinfo->ext_listen_interval);
+                                       DBG_8723A("%s, set switch ch timer, duration=%d\n", __func__, duration-pwdinfo->ext_listen_interval);
                                        _set_timer(&pwdinfo->ap_p2p_switch_timer, duration-pwdinfo->ext_listen_interval);
                                }
                        }
 
-                       ready_on_channel = true;
+                       ready_on_channel = _TRUE;
                        //pmlmeext->cur_channel = remain_ch;
                        //set_channel_bwmode(padapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
                }else
 #endif //CONFIG_CONCURRENT_MODE
-               if (remain_ch != pmlmeext->cur_channel )
+               if(remain_ch != pmlmeext->cur_channel )
                {
-                       ready_on_channel = true;
+                       ready_on_channel = _TRUE;
                        //pmlmeext->cur_channel = remain_ch;
                        //set_channel_bwmode(padapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
                }
        } else {
-               DBG_871X("%s remain_ch:%u not in channel plan!!!!\n", __FUNCTION__, remain_ch);
+               DBG_8723A("%s remain_ch:%u not in channel plan!!!!\n", __FUNCTION__, remain_ch);
        }
 
 
        //call this after other things have been done
 #ifdef CONFIG_CONCURRENT_MODE
-       if (ATOMIC_READ(&pwdev_priv->ro_ch_to)==1 ||
+       if(ATOMIC_READ(&pwdev_priv->ro_ch_to)==1 ||
                (remain_ch != pmlmeext->cur_channel))
        {
                u8 co_channel = 0xff;
                ATOMIC_SET(&pwdev_priv->ro_ch_to, 0);
 #endif
 
-               if (ready_on_channel == true)
+               if(ready_on_channel == _TRUE)
                {
-                       pmlmeext->cur_channel = remain_ch;
+                       if ( !check_fwstate(&padapter->mlmepriv, _FW_LINKED ) )
+                       {
+                               pmlmeext->cur_channel = remain_ch;
 
-#ifdef CONFIG_CONCURRENT_MODE
-                       if (padapter->pcodatapriv)
-                               co_channel = padapter->pcodatapriv->co_ch;
 
-                       if (co_channel !=remain_ch)
-#endif
                                set_channel_bwmode(padapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
+                       }
                }
-
-               DBG_8192C("%s, set ro ch timer, duration=%d\n", __func__, duration);
+               DBG_8723A("%s, set ro ch timer, duration=%d\n", __func__, duration);
                _set_timer( &pcfg80211_wdinfo->remain_on_ch_timer, duration);
 
 #ifdef CONFIG_CONCURRENT_MODE
        }
 #endif
 
-       cfg80211_ready_on_channel(ndev, *cookie, channel, channel_type, duration, GFP_KERNEL);
+       rtw_cfg80211_ready_on_channel(padapter, *cookie, channel, channel_type, duration, GFP_KERNEL);
 
        pwdinfo->listen_channel = pmlmeext->cur_channel;
 
 exit:
        if (err)
-               pcfg80211_wdinfo->is_ro_ch = false;
+               pcfg80211_wdinfo->is_ro_ch = _FALSE;
 
        return err;
 }
 
-static s32 cfg80211_rtw_cancel_remain_on_channel(struct wiphy *wiphy, struct net_device *ndev,
+static s32 cfg80211_rtw_cancel_remain_on_channel(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+       struct wireless_dev *wdev,
+#else
+       struct net_device *ndev,
+#endif
        u64 cookie)
 {
        s32 err = 0;
@@ -4063,41 +4428,54 @@ static s32 cfg80211_rtw_cancel_remain_on_channel(struct wiphy *wiphy, struct net
        struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
        struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
 
-       DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
+       DBG_8723A(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
 
-       //Modified bu Kurt 20120114
-       _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
-#ifdef CONFIG_CONCURRENT_MODE
-       ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
-#endif
+       if (pcfg80211_wdinfo->is_ro_ch == _TRUE) {
+               DBG_8723A("%s, cancel ro ch timer\n", __func__);
+               _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
+               #ifdef CONFIG_CONCURRENT_MODE
+               ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
+               #endif
+               p2p_protocol_wk_hdl(padapter, P2P_RO_CH_WK);
+       }
 
+       #if 0
+       //      Disable P2P Listen State
+       if(!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
+       {
+               if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
+               {
+                       _cancel_timer_ex( &pwdinfo->find_phase_timer );
+                       _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
+                       _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
+
+                       rtw_p2p_set_state(pwdinfo, P2P_STATE_NONE);
+                       memset(pwdinfo, 0x00, sizeof(struct wifidirect_info));
+               }
+       }
+       else
+       #endif
        {
                 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
 #ifdef CONFIG_DEBUG_CFG80211
-                DBG_8192C("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
+                DBG_8723A("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
 #endif
        }
-       pcfg80211_wdinfo->is_ro_ch = false;
+       pcfg80211_wdinfo->is_ro_ch = _FALSE;
 
        return err;
 }
 
 #endif //CONFIG_P2P
 
-#if 1
-static int     _cfg80211_rtw_mgmt_tx(struct net_device *ndev, u8 tx_ch,
-                       const u8 *buf, size_t len, u32 *dump_limit)
+static int _cfg80211_rtw_mgmt_tx(_adapter *padapter, u8 tx_ch, const u8 *buf, size_t len)
 {
        struct xmit_frame       *pmgntframe;
        struct pkt_attrib       *pattrib;
        unsigned char   *pframe;
-       const struct ieee80211_mgmt *mgmt;
-       int ret = 0;
-       int type = (-1);
-       u16 fc;
-       bool ack = true;
+       int ret = _FAIL;
+       bool ack = _TRUE;
        struct rtw_ieee80211_hdr *pwlanhdr;
-       _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
        struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
        struct xmit_priv        *pxmitpriv = &(padapter->xmitpriv);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
@@ -4105,123 +4483,78 @@ static int     _cfg80211_rtw_mgmt_tx(struct net_device *ndev, u8 tx_ch,
        struct wifidirect_info *pwdinfo = &padapter->wdinfo;
        //struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
 
-       if (_FAIL == rtw_pwr_wakeup(padapter)) {
+       if(_FAIL == rtw_pwr_wakeup(padapter)) {
                ret = -EFAULT;
                goto exit;
        }
 
-#ifdef CONFIG_SET_SCAN_DENY_TIMER
-       rtw_set_scan_deny(pmlmepriv, 1000);
-#endif //CONFIG_SET_SCAN_DENY_TIMER
-
-
-       mgmt = (const struct ieee80211_mgmt *) buf;
-       fc = mgmt->frame_control;
-       if (fc != IEEE80211_STYPE_ACTION)
-       {
-               if (fc == IEEE80211_STYPE_PROBE_RESP)
-               {
-                       DBG_8192C("%s, fc == IEEE80211_STYPE_PROBE_RESP\n", __func__);
-               }
-               else
-               {
-                       DBG_8192C("%s, frame_control == 0x%x\n", __func__, fc);
-               }
-
-               //cfg80211_mgmt_tx_status(dev, *cookie, buf, len, ack, GFP_KERNEL);
-
-               *dump_limit = 0;
-
-               goto exit;
-
-       }
-       else
-       {
-               #ifdef CONFIG_DEBUG_CFG80211
-               DBG_8192C("%s, do: scan_abort\n", __func__);
-               #endif
-
-           /* Abort the dwell time of any previous off-channel action frame that may
-            * be still in effect.  Sending off-channel action frames relies on the
-            * driver's scan engine.  If a previous off-channel action frame tx is
-            * still in progress (including the dwell time), then this new action
-            * frame will not be sent out.
-            */
-
-               rtw_scan_abort(padapter);
-#ifdef CONFIG_CONCURRENT_MODE
-               if (rtw_buddy_adapter_up(padapter))
-                       rtw_scan_abort(padapter->pbuddy_adapter);
-#endif //CONFIG_CONCURRENT_MODE
+       rtw_set_scan_deny(padapter, 1000);
 
-               if (padapter->cfg80211_wdinfo.is_ro_ch == true)
-               {
-                       DBG_8192C("%s, cancel ro ch timer\n", __func__);
-                       _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
-                       padapter->cfg80211_wdinfo.is_ro_ch = false;
-               }
+       rtw_scan_abort(padapter);
+       #ifdef CONFIG_CONCURRENT_MODE
+       if(rtw_buddy_adapter_up(padapter))
+               rtw_scan_abort(padapter->pbuddy_adapter);
+       #endif /* CONFIG_CONCURRENT_MODE */
 
+       if (padapter->cfg80211_wdinfo.is_ro_ch == _TRUE) {
+               //DBG_8723A("%s, cancel ro ch timer\n", __func__);
+               //_cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
+               //padapter->cfg80211_wdinfo.is_ro_ch = _FALSE;
+               #ifdef CONFIG_CONCURRENT_MODE
+               DBG_8723A("%s, extend ro ch time\n", __func__);
+               _set_timer( &padapter->cfg80211_wdinfo.remain_on_ch_timer, pwdinfo->ext_listen_period);
+               #endif //CONFIG_CONCURRENT_MODE
        }
 
 #ifdef CONFIG_CONCURRENT_MODE
-       if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
-       {
+       if (check_buddy_fwstate(padapter, _FW_LINKED )) {
                u8 co_channel=0xff;
                PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
                struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
 
-               if (padapter->pcodatapriv)
-                       co_channel = padapter->pcodatapriv->co_ch;
+               co_channel = rtw_get_oper_ch(padapter);
 
-               if (tx_ch != pbuddy_mlmeext->cur_channel)
-               {
-                       if (ATOMIC_READ(&pwdev_priv->switch_ch_to)==1)
-                       {
-                               DBG_8192C("%s, issue nulldata pwrbit=1\n", __func__);
+               if (tx_ch != pbuddy_mlmeext->cur_channel) {
+                       if (ATOMIC_READ(&pwdev_priv->switch_ch_to)==1) {
+                               DBG_8723A("%s, issue nulldata pwrbit=1\n", __func__);
                                issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
 
-
                                ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
 
-                               DBG_8192C("%s, set switch ch timer, period=%d\n", __func__, pwdinfo->ext_listen_period);
-                               _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
+                               //DBG_8723A("%s, set switch ch timer, period=%d\n", __func__, pwdinfo->ext_listen_period);
+                               //_set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
                        }
+
+                       DBG_8723A("%s, set switch ch timer, period=%d\n", __func__, pwdinfo->ext_listen_period);
+                       _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
                }
 
-               pmlmeext->cur_channel = tx_ch;
+               if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED ))
+                       pmlmeext->cur_channel = tx_ch;
 
                if (tx_ch != co_channel)
                        set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
-
        }else
 #endif //CONFIG_CONCURRENT_MODE
-       if ( tx_ch != pmlmeext->cur_channel )
-       {
-               pmlmeext->cur_channel = tx_ch;
+       //if (tx_ch != pmlmeext->cur_channel) {
+       if(tx_ch != rtw_get_oper_ch(padapter)) {
+               if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED ))
+                       pmlmeext->cur_channel = tx_ch;
                set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
        }
 
-       #ifdef CONFIG_P2P
-       DBG_8192C("RTW_Tx:tx_ch=%d\n", tx_ch);
-       if ( (type = rtw_p2p_check_frames(padapter, buf, len, true)) < 0)
-       {
-               *dump_limit = 0;
-               goto exit;
-       }
-       #endif
-
-
        //starting alloc mgmt frame to dump it
        if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
        {
                //ret = -ENOMEM;
+               ret = _FAIL;
                goto exit;
        }
 
        //update attribute
        pattrib = &pmgntframe->attrib;
        update_mgntframe_attrib(padapter, pattrib);
-       pattrib->retry_ctrl = false;
+       pattrib->retry_ctrl = _FALSE;
 
        memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
@@ -4242,7 +4575,7 @@ static int        _cfg80211_rtw_mgmt_tx(struct net_device *ndev, u8 tx_ch,
 
                pwfd_info = padapter->wdinfo.wfd_info;
 
-               if ( true == pwfd_info->wfd_enable )
+               if ( _TRUE == pwfd_info->wfd_enable )
                {
                        rtw_append_wfd_ie( padapter, pframe, &pattrib->pktlen );
                }
@@ -4253,317 +4586,160 @@ static int    _cfg80211_rtw_mgmt_tx(struct net_device *ndev, u8 tx_ch,
 
        if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS)
        {
-               ack = false;
-               DBG_8192C("%s, ack to (%d)!\n", __func__, ack);
+               ack = _FALSE;
+               ret = _FAIL;
 
-               switch (type) {
-                       case P2P_GO_NEGO_CONF:
-                       *dump_limit = 5;
-                       break;
-               }
+               #ifdef CONFIG_DEBUG_CFG80211
+               DBG_8723A("%s, ack == _FAIL\n", __func__);
+               #endif
        }
        else
        {
                #ifdef CONFIG_DEBUG_CFG80211
-               DBG_8192C("%s, ack=%d, ok!\n", __func__, ack);
+               DBG_8723A("%s, ack=%d, ok!\n", __func__, ack);
                #endif
-
-               *dump_limit = 0;
+               ret = _SUCCESS;
        }
 
 exit:
 
        #ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s, ret=%d\n", __func__, ret);
+       DBG_8723A("%s, ret=%d\n", __func__, ret);
        #endif
 
        return ret;
 
 }
 
-static int     cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, struct net_device *ndev,
+static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
+       struct wireless_dev *wdev,
+#else
+       struct net_device *ndev,
+#endif
+       struct ieee80211_channel *chan,
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
-                       struct ieee80211_channel *chan, bool offchan,
-                       enum nl80211_channel_type channel_type,
-                       bool channel_type_valid, unsigned int wait,
-#else  //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-                       struct ieee80211_channel *chan,
-                       enum nl80211_channel_type channel_type,
-               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-                       bool channel_type_valid,
-               #endif
-#endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-                       const u8 *buf, size_t len,
-               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
-                       bool no_cck,
-               #endif
-               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
-                       bool dont_wait_for_ack,
-               #endif
-                       u64 *cookie)
+       bool offchan,
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
+       enum nl80211_channel_type channel_type,
+       #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
+       bool channel_type_valid,
+       #endif
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
+       unsigned int wait,
+#endif
+       const u8 *buf, size_t len,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
+       bool no_cck,
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
+       bool dont_wait_for_ack,
+#endif
+       u64 *cookie)
 {
+       _adapter *padapter = (_adapter *)wiphy_to_adapter(wiphy);
+       struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
        int ret = 0;
+       int tx_ret;
        u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
        u32 dump_cnt = 0;
-       bool ack = true;
+       bool ack = _TRUE;
        u8 tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq);
+       u8 category, action;
+       int type = (-1);
+       u32 start = rtw_get_current_time();
 
        /* cookie generation */
        *cookie = (unsigned long) buf;
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_871X(FUNC_NDEV_FMT" len=%zu, ch=%d, ch_type=%d\n", FUNC_NDEV_ARG(ndev),
-               len, tx_ch, channel_type);
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       DBG_8192C("channel_type_valid=%d\n", channel_type_valid);
-#endif //
-#endif //CONFIG_DEBUG_CFG80211
+       DBG_8723A(FUNC_ADPT_FMT" len=%zu, ch=%d"
+       #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
+               ", ch_type=%d"
+               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
+               ", channel_type_valid=%d"
+               #endif
+       #endif
+               "\n", FUNC_ADPT_ARG(padapter),
+               len, tx_ch
+       #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
+               , channel_type
+               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
+               , channel_type_valid
+               #endif
+       #endif
+       );
+#endif /* CONFIG_DEBUG_CFG80211 */
 
-       //indicate ack before issue frame to avoid racing with rsp frame
+       /* indicate ack before issue frame to avoid racing with rsp frame */
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       cfg80211_mgmt_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
+       rtw_cfg80211_mgmt_tx_status(padapter, *cookie, buf, len, ack, GFP_KERNEL);
 #elif  (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,34) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,35))
        cfg80211_action_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
 #endif
 
-       do{
-               ret = _cfg80211_rtw_mgmt_tx(ndev, tx_ch, buf, len, &dump_limit);
-               if (ret)
-                       break;
-
-               ++dump_cnt;
-
-       }while (dump_cnt < dump_limit);
-
-       if (dump_cnt == dump_limit)
-               DBG_8192C("mgmt tx timeout to limit=%d\n", dump_cnt);
-
-       return ret;
-
-}
-#else
-static int     cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, struct net_device *ndev,
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
-                       struct ieee80211_channel *chan, bool offchan,
-                       enum nl80211_channel_type channel_type,
-                       bool channel_type_valid, unsigned int wait,
-#else  //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-                       struct ieee80211_channel *chan,
-                       enum nl80211_channel_type channel_type,
-               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-                       bool channel_type_valid,
-               #endif
-#endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38))
-                       const u8 *buf, size_t len,
-               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
-                       bool no_cck,
-               #endif
-               #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
-                       bool dont_wait_for_ack,
-               #endif
-                       u64 *cookie)
-{
-       struct xmit_frame               *pmgntframe;
-       struct pkt_attrib       *pattrib;
-       unsigned char   *pframe;
-       const struct ieee80211_mgmt *mgmt;
-       //u8 category, action, OUI_Subtype, dialogToken=0;
-       //unsigned char *frame_body;
-       int ret = 0;
-       int type = (-1);
-       u16 fc;
-       bool ack = true;
-       struct rtw_ieee80211_hdr *pwlanhdr;
-       _adapter *padapter = wiphy_to_adapter(wiphy);
-       struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
-       struct xmit_priv        *pxmitpriv = &(padapter->xmitpriv);
-       struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
-       struct mlme_ext_priv    *pmlmeext = &(padapter->mlmeextpriv);
-       struct wifidirect_info *pwdinfo = &padapter->wdinfo;
-       struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
-       u8 tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq);
-       int dump_cnt = -1, dump_limit = 1;
-
-       if (_FAIL == rtw_pwr_wakeup(padapter)) {
-               ret = -EFAULT;
+       if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
+               DBG_8723A(FUNC_ADPT_FMT" frame_control:0x%x\n", FUNC_ADPT_ARG(padapter),
+                       le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
                goto exit;
        }
 
-#ifdef CONFIG_SET_SCAN_DENY_TIMER
-       rtw_set_scan_deny(pmlmepriv, 1000);
-#endif //CONFIG_SET_SCAN_DENY_TIMER
-
-
-       /* cookie generation */
-       *cookie = (unsigned long) buf;
-
-#ifdef CONFIG_DEBUG_CFG80211
-       DBG_871X(FUNC_NDEV_FMT" len=%zu, ch=%d, ch_type=%d\n", FUNC_NDEV_ARG(ndev),
-               len, tx_ch, channel_type);
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       DBG_8192C("channel_type_valid=%d\n", channel_type_valid);
-#endif //
-#endif //CONFIG_DEBUG_CFG80211
-
-       mgmt = (const struct ieee80211_mgmt *) buf;
-       fc = mgmt->frame_control;
-       if (fc != IEEE80211_STYPE_ACTION)
-       {
-               if (fc == IEEE80211_STYPE_PROBE_RESP)
-               {
-                       DBG_8192C("%s, fc == IEEE80211_STYPE_PROBE_RESP\n", __func__);
-               }
-               else
-               {
-                       DBG_8192C("%s, frame_control == 0x%x\n", __func__, fc);
-               }
-
-               //cfg80211_mgmt_tx_status(dev, *cookie, buf, len, ack, GFP_KERNEL);
-
-               goto exit;
-
-       }
+       DBG_8723A("RTW_Tx:tx_ch=%d, da="MAC_FMT"\n", tx_ch, MAC_ARG(GetAddr1Ptr(buf)));
+       #ifdef CONFIG_P2P
+       if((type = rtw_p2p_check_frames(padapter, buf, len, _TRUE)) >= 0)
+               goto dump;
+       #endif
+       if (category == RTW_WLAN_CATEGORY_PUBLIC)
+               DBG_8723A("RTW_Tx:%s\n", action_public_str(action));
        else
-       {
-               #ifdef CONFIG_DEBUG_CFG80211
-               DBG_8192C("%s, do: scan_abort\n", __func__);
-               #endif
-
-           /* Abort the dwell time of any previous off-channel action frame that may
-            * be still in effect.  Sending off-channel action frames relies on the
-            * driver's scan engine.  If a previous off-channel action frame tx is
-            * still in progress (including the dwell time), then this new action
-            * frame will not be sent out.
-            */
+               DBG_8723A("RTW_Tx:category(%u), action(%u)\n", category, action);
 
-               rtw_scan_abort(padapter);
-       }
-
-#ifdef CONFIG_CONCURRENT_MODE
-       if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
-       {
-               u8 co_channel=0xff;
-               PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
-               struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
-
-               if (padapter->pcodatapriv)
-                       co_channel = padapter->pcodatapriv->co_ch;
-
-               if (tx_ch != pbuddy_mlmeext->cur_channel)
-               {
-                       if (ATOMIC_READ(&pwdev_priv->switch_ch_to)==1)
-                       {
-                               DBG_8192C("%s, issue nulldata pwrbit=1\n", __func__);
-                               issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
-
-                               ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
-
-                               DBG_8192C("%s, set switch ch timer\n", __func__);
-                               _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
-                       }
-               }
-
-               pmlmeext->cur_channel = tx_ch;
-
-               if (tx_ch != co_channel)
-                       set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
-
-       }else
-#endif //CONFIG_CONCURRENT_MODE
-       if ( tx_ch != pmlmeext->cur_channel )
-       {
-               pmlmeext->cur_channel = tx_ch;
-               set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
-       }
+dump:
+       do {
+               dump_cnt++;
+               tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len);
+       } while (dump_cnt < dump_limit && tx_ret != _SUCCESS);
 
-       #ifdef CONFIG_P2P
-       DBG_8192C("RTW_Tx:tx_ch=%d\n", tx_ch);
-       if ((type = rtw_p2p_check_frames(padapter, buf, len, true)) < 0) {
-               ack = false;
-               goto exit;
+       if (tx_ret != _SUCCESS || dump_cnt > 1) {
+               DBG_8723A(FUNC_ADPT_FMT" %s (%d/%d) in %d ms\n", FUNC_ADPT_ARG(padapter),
+                       tx_ret==_SUCCESS?"OK":"FAIL", dump_cnt, dump_limit, rtw_get_passing_time_ms(start));
        }
-       #endif
 
        switch (type) {
        case P2P_GO_NEGO_CONF:
-               dump_limit = 5;
+               rtw_clear_scan_deny(padapter);
                break;
-       }
-
-       dump_cnt = 0;
-       do {
-               //starting alloc mgmt frame to dump it
-               if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL) {
-                       ack = false;
-                       ret = -ENOMEM;
-                       goto exit;
-               }
-
-               //update attribute
-               pattrib = &pmgntframe->attrib;
-               update_mgntframe_attrib(padapter, pattrib);
-               pattrib->retry_ctrl = false;
-
-               memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
-
-               pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
-
-               memcpy(pframe, (void*)buf, len);
-               pattrib->pktlen = len;
-
-               pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
-               //update seq number
-               pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
-               pattrib->seqnum = pmlmeext->mgnt_seq;
-               pmlmeext->mgnt_seq++;
-
-#ifdef CONFIG_WFD
+       case P2P_INVIT_RESP:
+               if (pwdev_priv->invit_info.flags & BIT(0)
+                       && pwdev_priv->invit_info.status == 0)
                {
-                       struct wifi_display_info                *pwfd_info;
-
-                       pwfd_info = padapter->wdinfo.wfd_info;
-
-                       if ( true == pwfd_info->wfd_enable )
-                       {
-                               rtw_append_wfd_ie( padapter, pframe, &pattrib->pktlen );
-                       }
+                       DBG_8723A(FUNC_ADPT_FMT" agree with invitation of persistent group\n",
+                               FUNC_ADPT_ARG(padapter));
+                       rtw_set_scan_deny(padapter, 5000);
+                       rtw_pwr_wakeup_ex(padapter, 5000);
+                       rtw_clear_scan_deny(padapter);
                }
-#endif // CONFIG_WFD
-
-               pattrib->last_txcmdsz = pattrib->pktlen;
-
-               if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) {
-                       ack = false;
-               } else {
-                       ack = true;
-               }
-       } while (++dump_cnt < dump_limit && ack == false);
-
-exit:
-       if (dump_cnt != -1 && (dump_cnt > 1 || ack == false)) {
-               DBG_871X(FUNC_NDEV_FMT" ack=%d, dump_cnt=%d\n", FUNC_NDEV_ARG(ndev), ack, dump_cnt);
-       } else if (ack == true) {
-               #ifdef CONFIG_DEBUG_CFG80211
-               DBG_871X(FUNC_NDEV_FMT" ack=%d, ok!\n", FUNC_NDEV_ARG(ndev), ack);
-               #endif
+               break;
        }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
-       cfg80211_mgmt_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
-#elif  (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,34) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,35))
-       cfg80211_action_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
-#endif
-
+exit:
        return ret;
 }
-#endif
 
-static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy, struct net_device *ndev,
+static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
+       struct wireless_dev *wdev,
+#else
+       struct net_device *ndev,
+#endif
        u16 frame_type, bool reg)
 {
+       _adapter *adapter = wiphy_to_adapter(wiphy);
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_871X(FUNC_NDEV_FMT" frame_type: %x, reg: %d\n", FUNC_NDEV_ARG(ndev),
+       DBG_8723A(FUNC_ADPT_FMT" frame_type:%x, reg:%d\n", FUNC_ADPT_ARG(adapter),
                frame_type, reg);
 #endif
 
@@ -4581,31 +4757,34 @@ static int rtw_cfg80211_set_beacon_wpsp2pie(struct net_device *ndev, char *buf,
        u32     p2p_ielen = 0;
        u8 wps_oui[8]={0x0,0x50,0xf2,0x04};
        u8 *p2p_ie;
+       u32     wfd_ielen = 0;
+       u8 *wfd_ie;
        _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
        struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
 
-       DBG_871X(FUNC_NDEV_FMT" ielen=%d\n", FUNC_NDEV_ARG(ndev), len);
+       DBG_8723A(FUNC_NDEV_FMT" ielen=%d\n", FUNC_NDEV_ARG(ndev), len);
 
-       if (len>0)
+       if(len>0)
        {
-               if ((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
+               if((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
                {
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("bcn_wps_ielen=%d\n", wps_ielen);
+                       DBG_8723A("bcn_wps_ielen=%d\n", wps_ielen);
                        #endif
 
-                       if (pmlmepriv->wps_beacon_ie)
+                       if(pmlmepriv->wps_beacon_ie)
                        {
                                u32 free_len = pmlmepriv->wps_beacon_ie_len;
                                pmlmepriv->wps_beacon_ie_len = 0;
-                               rtw_mfree(pmlmepriv->wps_beacon_ie, free_len);
+                               kfree(pmlmepriv->wps_beacon_ie);
                                pmlmepriv->wps_beacon_ie = NULL;
                        }
 
-                       pmlmepriv->wps_beacon_ie = rtw_malloc(wps_ielen);
+                       pmlmepriv->wps_beacon_ie =
+                               kmalloc(wps_ielen, GFP_KERNEL);
                        if ( pmlmepriv->wps_beacon_ie == NULL) {
-                               DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                return -EINVAL;
 
                        }
@@ -4613,31 +4792,32 @@ static int rtw_cfg80211_set_beacon_wpsp2pie(struct net_device *ndev, char *buf,
                        memcpy(pmlmepriv->wps_beacon_ie, wps_ie, wps_ielen);
                        pmlmepriv->wps_beacon_ie_len = wps_ielen;
 
-                       update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, true);
+                       update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE);
 
                }
 
-               buf += wps_ielen;
-               len -= wps_ielen;
+               //buf += wps_ielen;
+               //len -= wps_ielen;
 
                #ifdef CONFIG_P2P
-               if ((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
+               if((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
                {
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("bcn_p2p_ielen=%d\n", p2p_ielen);
+                       DBG_8723A("bcn_p2p_ielen=%d\n", p2p_ielen);
                        #endif
 
-                       if (pmlmepriv->p2p_beacon_ie)
+                       if(pmlmepriv->p2p_beacon_ie)
                        {
                                u32 free_len = pmlmepriv->p2p_beacon_ie_len;
                                pmlmepriv->p2p_beacon_ie_len = 0;
-                               rtw_mfree(pmlmepriv->p2p_beacon_ie, free_len);
+                               kfree(pmlmepriv->p2p_beacon_ie);
                                pmlmepriv->p2p_beacon_ie = NULL;
                        }
 
-                       pmlmepriv->p2p_beacon_ie = rtw_malloc(p2p_ielen);
+                       pmlmepriv->p2p_beacon_ie =
+                               kmalloc(p2p_ielen, GFP_KERNEL);
                        if ( pmlmepriv->p2p_beacon_ie == NULL) {
-                               DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                return -EINVAL;
 
                        }
@@ -4648,7 +4828,35 @@ static int rtw_cfg80211_set_beacon_wpsp2pie(struct net_device *ndev, char *buf,
                }
                #endif //CONFIG_P2P
 
-               pmlmeext->bstart_bss = true;
+               //buf += p2p_ielen;
+               //len -= p2p_ielen;
+
+               #ifdef CONFIG_WFD
+               if(rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen))
+               {
+                       #ifdef CONFIG_DEBUG_CFG80211
+                       DBG_8723A("bcn_wfd_ielen=%d\n", wfd_ielen);
+                       #endif
+
+                       if(pmlmepriv->wfd_beacon_ie)
+                       {
+                               u32 free_len = pmlmepriv->wfd_beacon_ie_len;
+                               pmlmepriv->wfd_beacon_ie_len = 0;
+                               kfree(pmlmepriv->wfd_beacon_ie);
+                               pmlmepriv->wfd_beacon_ie = NULL;
+                       }
+
+                       pmlmepriv->wfd_beacon_ie = kmalloc(wfd_ielen);
+                       if ( pmlmepriv->wfd_beacon_ie == NULL) {
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               return -EINVAL;
+
+                       }
+                       rtw_get_wfd_ie(buf, len, pmlmepriv->wfd_beacon_ie, &pmlmepriv->wfd_beacon_ie_len);
+               }
+               #endif //CONFIG_WFD
+
+               pmlmeext->bstart_bss = _TRUE;
 
        }
 
@@ -4663,35 +4871,37 @@ static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *bu
        u8 *wps_ie;
        u32     p2p_ielen = 0;
        u8 *p2p_ie;
+       u32     wfd_ielen = 0;
+       u8 *wfd_ie;
        _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s, ielen=%d\n", __func__, len);
+       DBG_8723A("%s, ielen=%d\n", __func__, len);
 #endif
 
-       if (len>0)
+       if(len>0)
        {
-               if ((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
+               if((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
                {
                        uint    attr_contentlen = 0;
                        u16     uconfig_method, *puconfig_method = NULL;
 
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("probe_resp_wps_ielen=%d\n", wps_ielen);
+                       DBG_8723A("probe_resp_wps_ielen=%d\n", wps_ielen);
                        #endif
 
-                       if (pmlmepriv->wps_probe_resp_ie)
+                       if(pmlmepriv->wps_probe_resp_ie)
                        {
                                u32 free_len = pmlmepriv->wps_probe_resp_ie_len;
                                pmlmepriv->wps_probe_resp_ie_len = 0;
-                               rtw_mfree(pmlmepriv->wps_probe_resp_ie, free_len);
+                               kfree(pmlmepriv->wps_probe_resp_ie);
                                pmlmepriv->wps_probe_resp_ie = NULL;
                        }
 
-                       pmlmepriv->wps_probe_resp_ie = rtw_malloc(wps_ielen);
+                       pmlmepriv->wps_probe_resp_ie = kmalloc(wps_ielen);
                        if ( pmlmepriv->wps_probe_resp_ie == NULL) {
-                               DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                return -EINVAL;
 
                        }
@@ -4714,48 +4924,48 @@ static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *bu
 
                }
 
-               buf += wps_ielen;
-               len -= wps_ielen;
+               //buf += wps_ielen;
+               //len -= wps_ielen;
 
                #ifdef CONFIG_P2P
-               if ((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
+               if((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
                {
-                       u8 is_GO = false;
+                       u8 is_GO = _FALSE;
                        u32 attr_contentlen = 0;
                        u16 cap_attr=0;
 
                        #ifdef CONFIG_DEBUG_CFG80211
-                       DBG_8192C("probe_resp_p2p_ielen=%d\n", p2p_ielen);
+                       DBG_8723A("probe_resp_p2p_ielen=%d\n", p2p_ielen);
                        #endif
 
                        //Check P2P Capability ATTR
-                       if ( rtw_get_p2p_attr_content( p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8*)&cap_attr, (uint*) &attr_contentlen) )
+                       if( rtw_get_p2p_attr_content( p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8*)&cap_attr, (uint*) &attr_contentlen) )
                        {
                                u8 grp_cap=0;
-                               //DBG_8192C( "[%s] Got P2P Capability Attr!!\n", __FUNCTION__ );
+                               //DBG_8723A( "[%s] Got P2P Capability Attr!!\n", __FUNCTION__ );
                                cap_attr = le16_to_cpu(cap_attr);
                                grp_cap = (u8)((cap_attr >> 8)&0xff);
 
-                               is_GO = (grp_cap&BIT(0)) ? true:false;
+                               is_GO = (grp_cap&BIT(0)) ? _TRUE:_FALSE;
 
-                               if (is_GO)
-                                       DBG_8192C("Got P2P Capability Attr, grp_cap=0x%x, is_GO\n", grp_cap);
+                               if(is_GO)
+                                       DBG_8723A("Got P2P Capability Attr, grp_cap=0x%x, is_GO\n", grp_cap);
                        }
 
 
-                       if (is_GO == false)
+                       if(is_GO == _FALSE)
                        {
-                               if (pmlmepriv->p2p_probe_resp_ie)
+                               if(pmlmepriv->p2p_probe_resp_ie)
                                {
                                        u32 free_len = pmlmepriv->p2p_probe_resp_ie_len;
                                        pmlmepriv->p2p_probe_resp_ie_len = 0;
-                                       rtw_mfree(pmlmepriv->p2p_probe_resp_ie, free_len);
+                                       kfree(pmlmepriv->p2p_probe_resp_ie);
                                        pmlmepriv->p2p_probe_resp_ie = NULL;
                                }
 
-                               pmlmepriv->p2p_probe_resp_ie = rtw_malloc(p2p_ielen);
+                               pmlmepriv->p2p_probe_resp_ie = kmalloc(p2p_ielen);
                                if ( pmlmepriv->p2p_probe_resp_ie == NULL) {
-                                       DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                                       DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                        return -EINVAL;
 
                                }
@@ -4764,17 +4974,17 @@ static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *bu
                        }
                        else
                        {
-                               if (pmlmepriv->p2p_go_probe_resp_ie)
+                               if(pmlmepriv->p2p_go_probe_resp_ie)
                                {
                                        u32 free_len = pmlmepriv->p2p_go_probe_resp_ie_len;
                                        pmlmepriv->p2p_go_probe_resp_ie_len = 0;
-                                       rtw_mfree(pmlmepriv->p2p_go_probe_resp_ie, free_len);
+                                       kfree(pmlmepriv->p2p_go_probe_resp_ie);
                                        pmlmepriv->p2p_go_probe_resp_ie = NULL;
                                }
 
-                               pmlmepriv->p2p_go_probe_resp_ie = rtw_malloc(p2p_ielen);
+                               pmlmepriv->p2p_go_probe_resp_ie = kmalloc(p2p_ielen);
                                if ( pmlmepriv->p2p_go_probe_resp_ie == NULL) {
-                                       DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                                       DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                                        return -EINVAL;
 
                                }
@@ -4785,6 +4995,34 @@ static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *bu
                }
                #endif //CONFIG_P2P
 
+               //buf += p2p_ielen;
+               //len -= p2p_ielen;
+
+               #ifdef CONFIG_WFD
+               if(rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen))
+               {
+                       #ifdef CONFIG_DEBUG_CFG80211
+                       DBG_8723A("probe_resp_wfd_ielen=%d\n", wfd_ielen);
+                       #endif
+
+                       if(pmlmepriv->wfd_probe_resp_ie)
+                       {
+                               u32 free_len = pmlmepriv->wfd_probe_resp_ie_len;
+                               pmlmepriv->wfd_probe_resp_ie_len = 0;
+                               kfree(pmlmepriv->wfd_probe_resp_ie);
+                               pmlmepriv->wfd_probe_resp_ie = NULL;
+                       }
+
+                       pmlmepriv->wfd_probe_resp_ie = kmalloc(wfd_ielen);
+                       if ( pmlmepriv->wfd_probe_resp_ie == NULL) {
+                               DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
+                               return -EINVAL;
+
+                       }
+                       rtw_get_wfd_ie(buf, len, pmlmepriv->wfd_probe_resp_ie, &pmlmepriv->wfd_probe_resp_ie_len);
+               }
+               #endif //CONFIG_WFD
+
        }
 
        return ret;
@@ -4797,21 +5035,21 @@ static int rtw_cfg80211_set_assoc_resp_wpsp2pie(struct net_device *net, char *bu
        _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
-       DBG_8192C("%s, ielen=%d\n", __func__, len);
+       DBG_8723A("%s, ielen=%d\n", __func__, len);
 
-       if (len>0)
+       if(len>0)
        {
-               if (pmlmepriv->wps_assoc_resp_ie)
+               if(pmlmepriv->wps_assoc_resp_ie)
                {
                        u32 free_len = pmlmepriv->wps_assoc_resp_ie_len;
                        pmlmepriv->wps_assoc_resp_ie_len = 0;
-                       rtw_mfree(pmlmepriv->wps_assoc_resp_ie, free_len);
+                       kfree(pmlmepriv->wps_assoc_resp_ie);
                        pmlmepriv->wps_assoc_resp_ie = NULL;
                }
 
-               pmlmepriv->wps_assoc_resp_ie = rtw_malloc(len);
+               pmlmepriv->wps_assoc_resp_ie = kmalloc(len);
                if ( pmlmepriv->wps_assoc_resp_ie == NULL) {
-                       DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
+                       DBG_8723A("%s()-%d: kmalloc() ERROR!\n", __FUNCTION__, __LINE__);
                        return -EINVAL;
 
                }
@@ -4831,10 +5069,10 @@ int rtw_cfg80211_set_mgnt_wpsp2pie(struct net_device *net, char *buf, int len,
        u32     p2p_ielen = 0;
 
 #ifdef CONFIG_DEBUG_CFG80211
-       DBG_8192C("%s, ielen=%d\n", __func__, len);
+       DBG_8723A("%s, ielen=%d\n", __func__, len);
 #endif
 
-       if (    (rtw_get_wps_ie(buf, len, NULL, &wps_ielen) && (wps_ielen>0))
+       if    (rtw_get_wps_ie(buf, len, NULL, &wps_ielen) && (wps_ielen>0))
                #ifdef CONFIG_P2P
                || (rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen) && (p2p_ielen>0))
                #endif
@@ -4926,7 +5164,7 @@ static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum
 #define MAX_BIT_RATE_40MHZ_MCS15       300     /* Mbps */
 #define MAX_BIT_RATE_40MHZ_MCS7                150     /* Mbps */
 
-       ht_cap->ht_supported = true;
+       ht_cap->ht_supported = _TRUE;
 
        ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
                                        IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
@@ -4953,7 +5191,7 @@ static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum
         *if BW_40 rx_mask[4]=0x01;
         *highest supported RX rate
         */
-       if (rf_type == RF_1T1R)
+       if(rf_type == RF_1T1R)
        {
                ht_cap->mcs.rx_mask[0] = 0xFF;
                ht_cap->mcs.rx_mask[1] = 0x00;
@@ -4961,7 +5199,7 @@ static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum
 
                ht_cap->mcs.rx_highest = MAX_BIT_RATE_40MHZ_MCS7;
        }
-       else if ((rf_type == RF_1T2R) || (rf_type==RF_2T2R))
+       else if((rf_type == RF_1T2R) || (rf_type==RF_2T2R))
        {
                ht_cap->mcs.rx_mask[0] = 0xFF;
                ht_cap->mcs.rx_mask[1] = 0xFF;
@@ -4971,7 +5209,7 @@ static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum
        }
        else
        {
-               DBG_8192C("%s, error rf_type=%d\n", __func__, rf_type);
+               DBG_8723A("%s, error rf_type=%d\n", __func__, rf_type);
        }
 
 }
@@ -4985,17 +5223,46 @@ void rtw_cfg80211_init_wiphy(_adapter *padapter)
 
        rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
 
-       DBG_8192C("%s:rf_type=%d\n", __func__, rf_type);
+       DBG_8723A("%s:rf_type=%d\n", __func__, rf_type);
 
-       bands = wiphy->bands[IEEE80211_BAND_2GHZ];
-       if (bands)
-               rtw_cfg80211_init_ht_capab(&bands->ht_cap, IEEE80211_BAND_2GHZ, rf_type);
+       /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
+       {
+               bands = wiphy->bands[IEEE80211_BAND_2GHZ];
+               if(bands)
+                       rtw_cfg80211_init_ht_capab(&bands->ht_cap, IEEE80211_BAND_2GHZ, rf_type);
+       }
 
-       bands = wiphy->bands[IEEE80211_BAND_5GHZ];
-       if (bands)
-               rtw_cfg80211_init_ht_capab(&bands->ht_cap, IEEE80211_BAND_5GHZ, rf_type);
+       /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
+       {
+               bands = wiphy->bands[IEEE80211_BAND_5GHZ];
+               if(bands)
+                       rtw_cfg80211_init_ht_capab(&bands->ht_cap, IEEE80211_BAND_5GHZ, rf_type);
+       }
 }
 
+/*
+struct ieee80211_iface_limit rtw_limits[] = {
+       { .max = 1, .types = BIT(NL80211_IFTYPE_STATION)
+                                       | BIT(NL80211_IFTYPE_ADHOC)
+#ifdef CONFIG_AP_MODE
+                                       | BIT(NL80211_IFTYPE_AP)
+#endif
+#if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE))
+                                       | BIT(NL80211_IFTYPE_P2P_CLIENT)
+                                       | BIT(NL80211_IFTYPE_P2P_GO)
+#endif
+       },
+       {.max = 1, .types = BIT(NL80211_IFTYPE_MONITOR)},
+};
+
+struct ieee80211_iface_combination rtw_combinations = {
+       .limits = rtw_limits,
+       .n_limits = ARRAY_SIZE(rtw_limits),
+       .max_interfaces = 2,
+       .num_different_channels = 1,
+};
+*/
+
 static void rtw_cfg80211_preinit_wiphy(_adapter *padapter, struct wiphy *wiphy)
 {
 
@@ -5027,11 +5294,22 @@ static void rtw_cfg80211_preinit_wiphy(_adapter *padapter, struct wiphy *wiphy)
 #endif //CONFIG_AP_MODE
 #endif
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
+       wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
+#endif
+
+       /*
+       wiphy->iface_combinations = &rtw_combinations;
+       wiphy->n_iface_combinations = 1;
+       */
+
        wiphy->cipher_suites = rtw_cipher_suites;
        wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
 
-       wiphy->bands[IEEE80211_BAND_2GHZ] = rtw_spt_band_alloc(IEEE80211_BAND_2GHZ);
-       wiphy->bands[IEEE80211_BAND_5GHZ] = rtw_spt_band_alloc(IEEE80211_BAND_5GHZ);
+       /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
+               wiphy->bands[IEEE80211_BAND_2GHZ] = rtw_spt_band_alloc(IEEE80211_BAND_2GHZ);
+       /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
+               wiphy->bands[IEEE80211_BAND_5GHZ] = rtw_spt_band_alloc(IEEE80211_BAND_5GHZ);
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) && LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
        wiphy->flags |= WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS;
@@ -5042,7 +5320,7 @@ static void rtw_cfg80211_preinit_wiphy(_adapter *padapter, struct wiphy *wiphy)
        wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME;
 #endif
 
-       if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
+       if(padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
                wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
        else
                wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
@@ -5051,107 +5329,118 @@ static void rtw_cfg80211_preinit_wiphy(_adapter *padapter, struct wiphy *wiphy)
 int rtw_wdev_alloc(_adapter *padapter, struct device *dev)
 {
        int ret = 0;
+       struct wiphy *wiphy;
        struct wireless_dev *wdev;
        struct rtw_wdev_priv *pwdev_priv;
        struct net_device *pnetdev = padapter->pnetdev;
 
-       DBG_8192C("%s(padapter=%p)\n", __func__, padapter);
+       DBG_8723A("%s(padapter=%p)\n", __func__, padapter);
 
-       wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
-       if (!wdev) {
-               DBG_8192C("Couldn't allocate wireless device\n");
-               return (-ENOMEM);
-       }
-
-       wdev->wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wdev_priv));
-       if (!wdev->wiphy) {
-               DBG_8192C("Couldn't allocate wiphy device\n");
+       /* wiphy */
+       wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wdev_priv));
+       if (!wiphy) {
+               DBG_8723A("Couldn't allocate wiphy device\n");
                ret = -ENOMEM;
-               goto out_err_new;
+               goto exit;
        }
+       set_wiphy_dev(wiphy, dev);
+       rtw_cfg80211_preinit_wiphy(padapter, wiphy);
 
-       set_wiphy_dev(wdev->wiphy, dev);
+       ret = wiphy_register(wiphy);
+       if (ret < 0) {
+               DBG_8723A("Couldn't register wiphy device\n");
+               goto free_wiphy;
+       }
 
-       //
+       /*  wdev */
+       wdev = (struct wireless_dev *)kzalloc(sizeof(struct wireless_dev));
+       if (!wdev) {
+               DBG_8723A("Couldn't allocate wireless device\n");
+               ret = -ENOMEM;
+               goto unregister_wiphy;
+       }
+       wdev->wiphy = wiphy;
+       wdev->netdev = pnetdev;
+       //wdev->iftype = NL80211_IFTYPE_STATION;
+       wdev->iftype = NL80211_IFTYPE_MONITOR; // for rtw_setopmode_cmd() in cfg80211_rtw_change_iface()
        padapter->rtw_wdev = wdev;
        pnetdev->ieee80211_ptr = wdev;
 
        //init pwdev_priv
        pwdev_priv = wdev_to_priv(wdev);
+       pwdev_priv->rtw_wdev = wdev;
        pwdev_priv->pmon_ndev = NULL;
        pwdev_priv->ifname_mon[0] = '\0';
-       pwdev_priv->rtw_wdev = wdev;
        pwdev_priv->padapter = padapter;
        pwdev_priv->scan_request = NULL;
-       _rtw_spinlock_init(&pwdev_priv->scan_req_lock);
+       spin_lock_init(&pwdev_priv->scan_req_lock);
 
-       pwdev_priv->p2p_enabled = false;
-       pwdev_priv->provdisc_req_issued = false;
+       pwdev_priv->p2p_enabled = _FALSE;
+       pwdev_priv->provdisc_req_issued = _FALSE;
+       rtw_wdev_invit_info_init(&pwdev_priv->invit_info);
 
-       pwdev_priv->bandroid_scan = false;
+       pwdev_priv->bandroid_scan = _FALSE;
+
+       if(padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
+               pwdev_priv->power_mgmt = _TRUE;
+       else
+               pwdev_priv->power_mgmt = _FALSE;
 
 #ifdef CONFIG_CONCURRENT_MODE
        ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
        ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
 #endif
 
-       wdev->netdev = pnetdev;
-       //wdev->iftype = NL80211_IFTYPE_STATION;
-       wdev->iftype = NL80211_IFTYPE_MONITOR; // for rtw_setopmode_cmd() in cfg80211_rtw_change_iface()
+       return ret;
 
-       rtw_cfg80211_preinit_wiphy(padapter, wdev->wiphy);
+       kfree(wdev);
+unregister_wiphy:
+       wiphy_unregister(wiphy);
+ free_wiphy:
+       wiphy_free(wiphy);
+exit:
+       return ret;
 
-       ret = wiphy_register(wdev->wiphy);
-       if (ret < 0) {
-               DBG_8192C("Couldn't register wiphy device\n");
-               goto out_err_register;
-       }
+}
 
-       SET_NETDEV_DEV(pnetdev, wiphy_dev(wdev->wiphy));
+void rtw_wdev_free(struct wireless_dev *wdev)
+{
+       struct rtw_wdev_priv *pwdev_priv;
 
-       return ret;
+       DBG_8723A("%s(wdev=%p)\n", __func__, wdev);
 
- out_err_register:
-       wiphy_free(wdev->wiphy);
+       if (!wdev)
+               return;
 
- out_err_new:
-       rtw_mfree((u8*)wdev, sizeof(struct wireless_dev));
+       pwdev_priv = wdev_to_priv(wdev);
 
-       return ret;
+       rtw_spt_band_free(wdev->wiphy->bands[IEEE80211_BAND_2GHZ]);
+       rtw_spt_band_free(wdev->wiphy->bands[IEEE80211_BAND_5GHZ]);
 
+       wiphy_free(wdev->wiphy);
+
+       kfree(wdev);
 }
 
-void rtw_wdev_free(struct wireless_dev *wdev)
+void rtw_wdev_unregister(struct wireless_dev *wdev)
 {
        struct rtw_wdev_priv *pwdev_priv;
 
-       DBG_8192C("%s(wdev=%p)\n", __func__, wdev);
+       DBG_8723A("%s(wdev=%p)\n", __func__, wdev);
 
        if (!wdev)
                return;
 
        pwdev_priv = wdev_to_priv(wdev);
 
-       DBG_8192C("%s, scan abort when device remove\n", __func__);
-       rtw_cfg80211_indicate_scan_done(pwdev_priv, true);
+       rtw_cfg80211_indicate_scan_done(pwdev_priv, _TRUE);
 
        if (pwdev_priv->pmon_ndev) {
-               DBG_8192C("%s, unregister monitor interface\n", __func__);
-
+               DBG_8723A("%s, unregister monitor interface\n", __func__);
                unregister_netdev(pwdev_priv->pmon_ndev);
-
-               free_netdev(pwdev_priv->pmon_ndev);
        }
 
-
        wiphy_unregister(wdev->wiphy);
-
-       rtw_spt_band_free(wdev->wiphy->bands[IEEE80211_BAND_2GHZ]);
-       rtw_spt_band_free(wdev->wiphy->bands[IEEE80211_BAND_5GHZ]);
-
-       wiphy_free(wdev->wiphy);
-
-       rtw_mfree((u8*)wdev, sizeof(struct wireless_dev));
 }
 
 #endif //CONFIG_IOCTL_CFG80211