int rtl_net80211_setkey(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { struct rtl8192cd_priv *priv = (struct rtl8192cd_priv *)dev->priv; struct ieee80211req_key *wk = (struct ieee80211req_key *)wrqu->data.pointer; struct wifi_mib *pmib = priv->pmib; struct Dot11EncryptKey *pEncryptKey = NULL; struct stat_info *pstat = NULL; unsigned char MULTICAST_ADD[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; int cipher =0; int retVal = 0; int group_key = 0; HAPD_MSG("rtl_net80211_setkey +++\n"); HAPD_MSG("keyid = %d, mac = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n" , wk->ik_keyix, wk->ik_macaddr[0], wk->ik_macaddr[1], wk->ik_macaddr[2], wk->ik_macaddr[3], wk->ik_macaddr[4], wk->ik_macaddr[5]); HAPD_MSG("type = 0x%x, flags = 0x%x, keylen = 0x%x \n" , wk->ik_type, wk->ik_flags, wk->ik_keylen); //check if the interface is down if (!netif_running(priv->dev)) { if(wk->ik_type == IEEE80211_CIPHER_WEP) { HAPD_MSG("set WEP Key in driver DOWN\n"); memcpy(&priv->pmib->dot11DefaultKeysTable.keytype[wk->ik_keyix].skey[0], wk->ik_keydata, wk->ik_keylen); return 0; } HAPD_MSG("\nFail: interface not opened\n"); return 0; } if(!memcmp(wk->ik_macaddr, MULTICAST_ADD, 6)) group_key = 1; if(wk->ik_type == IEEE80211_CIPHER_WEP) { if(priv->pmib->dot1180211AuthEntry.dot11PrivacyAlgrthm == _WEP_40_PRIVACY_) cipher = (DOT11_ENC_WEP40); else if(priv->pmib->dot1180211AuthEntry.dot11PrivacyAlgrthm == _WEP_104_PRIVACY_) cipher = (DOT11_ENC_WEP104); else return -EINVAL; } else if(wk->ik_type == IEEE80211_CIPHER_TKIP) cipher = (DOT11_ENC_TKIP); else if(wk->ik_type == IEEE80211_CIPHER_AES_CCM) cipher = (DOT11_ENC_CCMP); else { HAPD_MSG("unknown encAlg !!!\n"); return -EINVAL; } //_Eric ?? if call DOT11_Process_Set_Key //CamAddOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, cipher, 0, wk->ik_keydata); if(group_key) { int set_gkey_to_cam = 1; HAPD_MSG("set group key !!\n"); #ifdef UNIVERSAL_REPEATER if (IS_VXD_INTERFACE(priv)) set_gkey_to_cam = 0; else { if (IS_ROOT_INTERFACE(priv)) { if (IS_DRV_OPEN(GET_VXD_PRIV(priv))) set_gkey_to_cam = 0; } } #endif #ifdef MBSSID if (GET_ROOT(priv)->pmib->miscEntry.vap_enable) { // No matter root or vap, don't set key to cam if vap is enabled. set_gkey_to_cam = 0; } #endif #ifdef CONFIG_RTK_MESH //modify by Joule for SECURITY if (dev == priv->mesh_dev) { pmib->dot11sKeysTable.dot11Privacy = cipher; pEncryptKey = &pmib->dot11sKeysTable.dot11EncryptKey; pmib->dot11sKeysTable.keyid = (UINT)wk->ik_keyix; } else #endif { pmib->dot11GroupKeysTable.dot11Privacy = cipher; pEncryptKey = &pmib->dot11GroupKeysTable.dot11EncryptKey; pmib->dot11GroupKeysTable.keyid = (UINT)wk->ik_keyix; } switch(cipher) { case DOT11_ENC_TKIP: set_ttkeylen(pEncryptKey, 16); set_tmickeylen(pEncryptKey, 8); set_tkip_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set TKIP group key! id %X\n", (UINT)wk->ik_keyix); if (!SWCRYPTO) { if (set_gkey_to_cam) { retVal = CamDeleteOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; pmib->dot11GroupKeysTable.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, DOT11_ENC_TKIP<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; pmib->dot11GroupKeysTable.keyInCam = TRUE; } } } break; case DOT11_ENC_WEP40: set_ttkeylen(pEncryptKey, 5); set_tmickeylen(pEncryptKey, 0); set_wep40_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set WEP40 group key!\n"); if (!SWCRYPTO) { if (set_gkey_to_cam) { retVal = CamDeleteOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; pmib->dot11GroupKeysTable.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, DOT11_ENC_WEP40<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; pmib->dot11GroupKeysTable.keyInCam = TRUE; } } } break; case DOT11_ENC_WEP104: set_ttkeylen(pEncryptKey, 13); set_tmickeylen(pEncryptKey, 0); set_wep104_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set WEP104 group key!\n"); if (!SWCRYPTO) { if (set_gkey_to_cam) { retVal = CamDeleteOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; pmib->dot11GroupKeysTable.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, DOT11_ENC_WEP104<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; pmib->dot11GroupKeysTable.keyInCam = TRUE; } } } break; case DOT11_ENC_CCMP: set_ttkeylen(pEncryptKey, 16); set_tmickeylen(pEncryptKey, 16); set_aes_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set CCMP-AES group key!\n"); #ifdef CONFIG_RTK_MESH if (dev == priv->mesh_dev) pmib->dot11sKeysTable.keyInCam = TRUE; // keyInCam means key in driver else #endif if (!SWCRYPTO) { if (set_gkey_to_cam) { retVal = CamDeleteOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; pmib->dot11GroupKeysTable.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, MULTICAST_ADD, wk->ik_keyix, DOT11_ENC_CCMP<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; pmib->dot11GroupKeysTable.keyInCam = TRUE; } } } break; case DOT11_ENC_NONE: default: HAPD_MSG("No group encryption key is set!\n"); set_ttkeylen(pEncryptKey, 0); set_tmickeylen(pEncryptKey, 0); break; } } else { pstat = get_stainfo(priv, wk->ik_macaddr); if (pstat == NULL) { DEBUG_ERR("Set key failed, invalid mac address: %02x%02x%02x%02x%02x%02x\n", wk->ik_macaddr[0], wk->ik_macaddr[1], wk->ik_macaddr[2], wk->ik_macaddr[3], wk->ik_macaddr[4], wk->ik_macaddr[5]); return (-1); } pstat->dot11KeyMapping.dot11Privacy = cipher; pEncryptKey = &pstat->dot11KeyMapping.dot11EncryptKey; pstat->keyid = wk->ik_keyix; #if defined(__DRAYTEK_OS__) && defined(WDS) if (pstat->state & WIFI_WDS) priv->pmib->dot11WdsInfo.wdsPrivacy = cipher; #endif switch(cipher) { case DOT11_ENC_TKIP: set_ttkeylen(pEncryptKey, 16); set_tmickeylen(pEncryptKey, 8); set_tkip_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set TKIP Unicast key for sta %02X%02X%02X%02X%02X%02X, id=%d\n", wk->ik_macaddr[0], wk->ik_macaddr[1], wk->ik_macaddr[2], wk->ik_macaddr[3], wk->ik_macaddr[4], wk->ik_macaddr[5], pstat->keyid); if (!SWCRYPTO) { retVal = CamDeleteOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; if (pstat) pstat->dot11KeyMapping.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, DOT11_ENC_TKIP<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; if (pstat) pstat->dot11KeyMapping.keyInCam = TRUE; } else { if (pstat->aggre_mthd != AGGRE_MTHD_NONE) pstat->aggre_mthd = AGGRE_MTHD_NONE; } } break; case DOT11_ENC_WEP40: set_ttkeylen(pEncryptKey, 5); set_tmickeylen(pEncryptKey, 0); set_wep40_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set WEP40 unicast key for sta %02X%02X%02X%02X%02X%02X, id=%d\n", wk->ik_macaddr[0], wk->ik_macaddr[1], wk->ik_macaddr[2], wk->ik_macaddr[3], wk->ik_macaddr[4], wk->ik_macaddr[5], pstat->keyid); if (!SWCRYPTO) { retVal = CamDeleteOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; if (pstat) pstat->dot11KeyMapping.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, DOT11_ENC_WEP40<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; if (pstat) pstat->dot11KeyMapping.keyInCam = TRUE; } else { if (pstat->aggre_mthd != AGGRE_MTHD_NONE) pstat->aggre_mthd = AGGRE_MTHD_NONE; } } break; case DOT11_ENC_WEP104: set_ttkeylen(pEncryptKey, 13); set_tmickeylen(pEncryptKey, 0); set_wep104_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set WEP104 unicast key for sta %02X%02X%02X%02X%02X%02X, id=%d\n", wk->ik_macaddr[0], wk->ik_macaddr[1], wk->ik_macaddr[2], wk->ik_macaddr[3], wk->ik_macaddr[4], wk->ik_macaddr[5], pstat->keyid); if (!SWCRYPTO) { retVal = CamDeleteOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; if (pstat) pstat->dot11KeyMapping.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, DOT11_ENC_WEP104<<2, 0, wk->ik_keydata); if (retVal) { priv->pshare->CamEntryOccupied++; if (pstat) pstat->dot11KeyMapping.keyInCam = TRUE; } else { if (pstat->aggre_mthd != AGGRE_MTHD_NONE) pstat->aggre_mthd = AGGRE_MTHD_NONE; } } break; case DOT11_ENC_CCMP: set_ttkeylen(pEncryptKey, 16); set_tmickeylen(pEncryptKey, 16); set_aes_key(pEncryptKey, wk->ik_keydata); HAPD_MSG("going to set CCMP-AES unicast key for sta %02X%02X%02X%02X%02X%02X, id=%d\n", wk->ik_macaddr[0], wk->ik_macaddr[1], wk->ik_macaddr[2], wk->ik_macaddr[3], wk->ik_macaddr[4], wk->ik_macaddr[5], pstat->keyid); if (!SWCRYPTO) { retVal = CamDeleteOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, 0); if (retVal) { priv->pshare->CamEntryOccupied--; if (pstat) pstat->dot11KeyMapping.keyInCam = FALSE; } retVal = CamAddOneEntry(priv, wk->ik_macaddr, wk->ik_keyix, DOT11_ENC_CCMP<<2, 0, wk->ik_keydata); if (retVal) { HAPD_MSG("CamAddOneEntry of CCMP OK\n"); priv->pshare->CamEntryOccupied++; if (pstat) pstat->dot11KeyMapping.keyInCam = TRUE; assign_aggre_mthod(priv, pstat); } else { HAPD_MSG("CamAddOneEntry of CCMP FAIL\n"); if (pstat->aggre_mthd != AGGRE_MTHD_NONE) pstat->aggre_mthd = AGGRE_MTHD_NONE; } } break; case DOT11_ENC_NONE: default: DEBUG_ERR("No pairewise encryption key is set!\n"); set_ttkeylen(pEncryptKey, 0); set_tmickeylen(pEncryptKey, 0); break; } } HAPD_MSG("rtl_net80211_setkey ---\n"); return 0; }
void rtl8192cd_dfs_det_chk(struct rtl8192cd_priv *priv) { unsigned int regf98_value; unsigned int reg918_value; unsigned int reg91c_value; unsigned int reg920_value; unsigned int reg924_value; unsigned int FA_count_cur=0, FA_count_inc=0; unsigned int VHT_CRC_ok_cnt_cur=0, VHT_CRC_ok_cnt_inc=0; unsigned int HT_CRC_ok_cnt_cur=0, HT_CRC_ok_cnt_inc=0; unsigned int LEG_CRC_ok_cnt_cur=0, LEG_CRC_ok_cnt_inc=0; unsigned int Total_CRC_OK_cnt_inc=0, FA_CRCOK_ratio=0; unsigned char DFS_tri_short_pulse=0, DFS_tri_long_pulse=0, fa_mask_mid_th=0, fa_mask_lower_th=0; unsigned char radar_type = 0; /* 0 for short, 1 for long */ unsigned int short_pulse_cnt_cur=0, short_pulse_cnt_inc=0; unsigned int long_pulse_cnt_cur=0, long_pulse_cnt_inc=0; unsigned int total_pulse_count_inc=0, max_sht_pusle_cnt_th=0; unsigned int sum, k, fa_flag=0; unsigned int st_L2H_new=0, st_L2H_tmp, index=0, fault_flag_det, fault_flag_psd; int flags=0; unsigned long throughput = 0; int j; int i, PSD_report_right[20], PSD_report_left[20]; int max_right, max_left; int max_fa_in_hist=0, total_fa_in_hist=0, pre_post_now_acc_fa_in_hist=0; if (priv->det_asoc_clear > 0) { priv->det_asoc_clear--; priv->pmib->dot11DFSEntry.DFS_detected = 0; priv->FA_count_pre = 0; priv->VHT_CRC_ok_cnt_pre = 0; priv->HT_CRC_ok_cnt_pre = 0; priv->LEG_CRC_ok_cnt_pre = 0; priv->mask_idx = 0; priv->mask_hist_checked = 0; memset(priv->radar_det_mask_hist, 0, sizeof(priv->radar_det_mask_hist)); memset(priv->pulse_flag_hist, 0, sizeof(priv->pulse_flag_hist)); mod_timer(&priv->dfs_det_chk_timer, jiffies + RTL_MILISECONDS_TO_JIFFIES(priv->pshare->rf_ft_var.dfs_det_period*10)); return; } throughput = priv->ext_stats.tx_avarage+priv->ext_stats.rx_avarage; #ifdef MBSSID if (priv->pmib->miscEntry.vap_enable) { for (j=0; j<RTL8192CD_NUM_VWLAN; j++) { if (IS_DRV_OPEN(priv->pvap_priv[j])) { throughput += priv->pvap_priv[j]->ext_stats.tx_avarage+priv->pvap_priv[j]->ext_stats.rx_avarage; } } } #endif // Get FA count during past 100ms FA_count_cur = PHY_QueryBBReg(priv, 0xf48, 0x0000ffff); if (priv->FA_count_pre == 0) FA_count_inc = 0; else if (FA_count_cur >= priv->FA_count_pre) FA_count_inc = FA_count_cur - priv->FA_count_pre; else FA_count_inc = FA_count_cur; priv->FA_count_pre = FA_count_cur; priv->fa_inc_hist[priv->mask_idx] = FA_count_inc; for (i=0; i<5; i++) { total_fa_in_hist = total_fa_in_hist + priv->fa_inc_hist[i]; if (priv->fa_inc_hist[i] > max_fa_in_hist) max_fa_in_hist = priv->fa_inc_hist[i]; } if (priv->mask_idx >= priv->pshare->rf_ft_var.dfs_det_flag_offset) index = priv->mask_idx - priv->pshare->rf_ft_var.dfs_det_flag_offset; else index = priv->pshare->rf_ft_var.dfs_det_hist_len + priv->mask_idx - priv->pshare->rf_ft_var.dfs_det_flag_offset; if (index == 0) pre_post_now_acc_fa_in_hist = priv->fa_inc_hist[index] + priv->fa_inc_hist[index+1] + priv->fa_inc_hist[4]; else if (index == 4) pre_post_now_acc_fa_in_hist = priv->fa_inc_hist[index] + priv->fa_inc_hist[0] + priv->fa_inc_hist[index-1]; else pre_post_now_acc_fa_in_hist = priv->fa_inc_hist[index] + priv->fa_inc_hist[index+1] + priv->fa_inc_hist[index-1]; // Get VHT CRC32 ok count during past 100ms VHT_CRC_ok_cnt_cur = PHY_QueryBBReg(priv, 0xf0c, 0x00003fff); if (VHT_CRC_ok_cnt_cur >= priv->VHT_CRC_ok_cnt_pre) VHT_CRC_ok_cnt_inc = VHT_CRC_ok_cnt_cur - priv->VHT_CRC_ok_cnt_pre; else VHT_CRC_ok_cnt_inc = VHT_CRC_ok_cnt_cur; priv->VHT_CRC_ok_cnt_pre = VHT_CRC_ok_cnt_cur; // Get HT CRC32 ok count during past 100ms HT_CRC_ok_cnt_cur = PHY_QueryBBReg(priv, 0xf10, 0x00003fff); if (HT_CRC_ok_cnt_cur >= priv->HT_CRC_ok_cnt_pre) HT_CRC_ok_cnt_inc = HT_CRC_ok_cnt_cur - priv->HT_CRC_ok_cnt_pre; else HT_CRC_ok_cnt_inc = HT_CRC_ok_cnt_cur; priv->HT_CRC_ok_cnt_pre = HT_CRC_ok_cnt_cur; // Get Legacy CRC32 ok count during past 100ms LEG_CRC_ok_cnt_cur = PHY_QueryBBReg(priv, 0xf14, 0x00003fff); if (LEG_CRC_ok_cnt_cur >= priv->LEG_CRC_ok_cnt_pre) LEG_CRC_ok_cnt_inc = LEG_CRC_ok_cnt_cur - priv->LEG_CRC_ok_cnt_pre; else LEG_CRC_ok_cnt_inc = LEG_CRC_ok_cnt_cur; priv->LEG_CRC_ok_cnt_pre = LEG_CRC_ok_cnt_cur; if ((VHT_CRC_ok_cnt_cur == 0x3fff) || (HT_CRC_ok_cnt_cur == 0x3fff) || (LEG_CRC_ok_cnt_cur == 0x3fff)) { PHY_SetBBReg(priv, 0xb58, BIT(0), 1); PHY_SetBBReg(priv, 0xb58, BIT(0), 0); } Total_CRC_OK_cnt_inc = VHT_CRC_ok_cnt_inc + HT_CRC_ok_cnt_inc + LEG_CRC_ok_cnt_inc; // check if the FA occrus frequencly during 100ms // FA_count_inc is divided by Total_CRC_OK_cnt_inc, which helps to distinguish normal trasmission from interference if (Total_CRC_OK_cnt_inc > 0) FA_CRCOK_ratio = FA_count_inc / Total_CRC_OK_cnt_inc; //=====dynamic power threshold (DPT) ======== // Get short pulse count, need carefully handle the counter overflow regf98_value = PHY_QueryBBReg(priv, 0xf98, 0xffffffff); short_pulse_cnt_cur = regf98_value & 0x000000ff; if (short_pulse_cnt_cur >= priv->short_pulse_cnt_pre) short_pulse_cnt_inc = short_pulse_cnt_cur - priv->short_pulse_cnt_pre; else short_pulse_cnt_inc = short_pulse_cnt_cur; priv->short_pulse_cnt_pre = short_pulse_cnt_cur; // Get long pulse count, need carefully handle the counter overflow long_pulse_cnt_cur = (regf98_value & 0x0000ff00) >> 8; if (long_pulse_cnt_cur >= priv->long_pulse_cnt_pre) long_pulse_cnt_inc = long_pulse_cnt_cur - priv->long_pulse_cnt_pre; else long_pulse_cnt_inc = long_pulse_cnt_cur; priv->long_pulse_cnt_pre = long_pulse_cnt_cur; total_pulse_count_inc = short_pulse_cnt_inc + long_pulse_cnt_inc; if (priv->pshare->rf_ft_var.dfs_det_print) { panic_printk("=====================================================================\n"); panic_printk("Total_CRC_OK_cnt_inc[%d] VHT_CRC_ok_cnt_inc[%d] HT_CRC_ok_cnt_inc[%d] LEG_CRC_ok_cnt_inc[%d] FA_count_inc[%d] FA_CRCOK_ratio[%d]\n", Total_CRC_OK_cnt_inc, VHT_CRC_ok_cnt_inc, HT_CRC_ok_cnt_inc, LEG_CRC_ok_cnt_inc, FA_count_inc, FA_CRCOK_ratio); panic_printk("Init_Gain[%x] 0x91c[%x] 0xf98[%08x] short_pulse_cnt_inc[%d] long_pulse_cnt_inc[%d]\n", priv->ini_gain_cur, priv->st_L2H_cur, regf98_value, short_pulse_cnt_inc, long_pulse_cnt_inc); panic_printk("Throughput: %luMbps\n", (throughput>>17)); reg918_value = PHY_QueryBBReg(priv, 0x918, 0xffffffff); reg91c_value = PHY_QueryBBReg(priv, 0x91c, 0xffffffff); reg920_value = PHY_QueryBBReg(priv, 0x920, 0xffffffff); reg924_value = PHY_QueryBBReg(priv, 0x924, 0xffffffff); printk("0x918[%08x] 0x91c[%08x] 0x920[%08x] 0x924[%08x]\n", reg918_value, reg91c_value, reg920_value, reg924_value); }