1 // SPDX-License-Identifier: GPL-2.0 2 /****************************************************************************** 3 * 4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. 5 * 6 ******************************************************************************/ 7 #include <drv_types.h> 8 #include <rtw_debug.h> 9 10 static void _dynamic_check_timer_handler(struct timer_list *t) 11 { 12 struct adapter *adapter = 13 from_timer(adapter, t, mlmepriv.dynamic_chk_timer); 14 15 rtw_dynamic_check_timer_handler(adapter); 16 17 _set_timer(&adapter->mlmepriv.dynamic_chk_timer, 2000); 18 } 19 20 static void _rtw_set_scan_deny_timer_hdl(struct timer_list *t) 21 { 22 struct adapter *adapter = 23 from_timer(adapter, t, mlmepriv.set_scan_deny_timer); 24 25 rtw_clear_scan_deny(adapter); 26 } 27 28 void rtw_init_mlme_timer(struct adapter *padapter) 29 { 30 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 31 32 timer_setup(&pmlmepriv->assoc_timer, _rtw_join_timeout_handler, 0); 33 timer_setup(&pmlmepriv->scan_to_timer, rtw_scan_timeout_handler, 0); 34 timer_setup(&pmlmepriv->dynamic_chk_timer, 35 _dynamic_check_timer_handler, 0); 36 timer_setup(&pmlmepriv->set_scan_deny_timer, 37 _rtw_set_scan_deny_timer_hdl, 0); 38 } 39 40 void rtw_os_indicate_connect(struct adapter *adapter) 41 { 42 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv); 43 44 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) || 45 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) { 46 rtw_cfg80211_ibss_indicate_connect(adapter); 47 } else { 48 rtw_cfg80211_indicate_connect(adapter); 49 } 50 51 rtw_indicate_wx_assoc_event(adapter); 52 netif_carrier_on(adapter->pnetdev); 53 54 if (adapter->pid[2] != 0) 55 rtw_signal_process(adapter->pid[2], SIGALRM); 56 } 57 58 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted) 59 { 60 rtw_cfg80211_indicate_scan_done(padapter, aborted); 61 indicate_wx_scan_complete_event(padapter); 62 } 63 64 static struct rt_pmkid_list backupPMKIDList[NUM_PMKID_CACHE]; 65 void rtw_reset_securitypriv(struct adapter *adapter) 66 { 67 u8 backupPMKIDIndex = 0; 68 u8 backupTKIPCountermeasure = 0x00; 69 u32 backupTKIPcountermeasure_time = 0; 70 /* add for CONFIG_IEEE80211W, none 11w also can use */ 71 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; 72 73 spin_lock_bh(&adapter->security_key_mutex); 74 75 if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { 76 /* 802.1x */ 77 /* Added by Albert 2009/02/18 */ 78 /* We have to backup the PMK information for WiFi PMK Caching test item. */ 79 /* */ 80 /* Backup the btkip_countermeasure information. */ 81 /* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */ 82 83 memcpy(&backupPMKIDList[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); 84 backupPMKIDIndex = adapter->securitypriv.PMKIDIndex; 85 backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure; 86 backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time; 87 88 /* reset RX BIP packet number */ 89 pmlmeext->mgnt_80211w_IPN_rx = 0; 90 91 memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv)); 92 93 /* Added by Albert 2009/02/18 */ 94 /* Restore the PMK information to securitypriv structure for the following connection. */ 95 memcpy(&adapter->securitypriv.PMKIDList[0], &backupPMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); 96 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex; 97 adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure; 98 adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time; 99 100 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen; 101 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled; 102 103 } else { 104 /* reset values in securitypriv */ 105 /* if (adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */ 106 /* */ 107 struct security_priv *psec_priv = &adapter->securitypriv; 108 109 psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ 110 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_; 111 psec_priv->dot11PrivacyKeyIndex = 0; 112 113 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_; 114 psec_priv->dot118021XGrpKeyid = 1; 115 116 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen; 117 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled; 118 /* */ 119 } 120 /* add for CONFIG_IEEE80211W, none 11w also can use */ 121 spin_unlock_bh(&adapter->security_key_mutex); 122 } 123 124 void rtw_os_indicate_disconnect(struct adapter *adapter) 125 { 126 /* struct rt_pmkid_list backupPMKIDList[ NUM_PMKID_CACHE ]; */ 127 128 netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */ 129 130 rtw_cfg80211_indicate_disconnect(adapter); 131 132 rtw_indicate_wx_disassoc_event(adapter); 133 134 /* modify for CONFIG_IEEE80211W, none 11w also can use the same command */ 135 rtw_reset_securitypriv_cmd(adapter); 136 } 137 138 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie) 139 { 140 uint len; 141 u8 *buff, *p, i; 142 union iwreq_data wrqu; 143 144 buff = NULL; 145 if (authmode == WLAN_EID_VENDOR_SPECIFIC) { 146 buff = rtw_zmalloc(IW_CUSTOM_MAX); 147 if (!buff) 148 return; 149 150 p = buff; 151 152 p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), "ASSOCINFO(ReqIEs ="); 153 154 len = sec_ie[1] + 2; 155 len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX; 156 157 for (i = 0; i < len; i++) 158 p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), "%02x", sec_ie[i]); 159 160 p += scnprintf(p, IW_CUSTOM_MAX - (p - buff), ")"); 161 162 memset(&wrqu, 0, sizeof(wrqu)); 163 164 wrqu.data.length = p - buff; 165 166 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? wrqu.data.length : IW_CUSTOM_MAX; 167 168 kfree(buff); 169 } 170 } 171 172 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta) 173 { 174 timer_setup(&psta->addba_retry_timer, addba_timer_hdl, 0); 175 } 176 177 void init_mlme_ext_timer(struct adapter *padapter) 178 { 179 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 180 181 timer_setup(&pmlmeext->survey_timer, survey_timer_hdl, 0); 182 timer_setup(&pmlmeext->link_timer, link_timer_hdl, 0); 183 timer_setup(&pmlmeext->sa_query_timer, sa_query_timer_hdl, 0); 184 } 185