1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. i*/
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/mlme_osdep.h"
10 void rtw_join_timeout_handler (struct timer_list *t)
12 struct adapter *adapter = from_timer(adapter, t, mlmepriv.assoc_timer);
14 _rtw_join_timeout_handler(adapter);
17 void _rtw_scan_timeout_handler (struct timer_list *t)
19 struct adapter *adapter = from_timer(adapter, t, mlmepriv.scan_to_timer);
21 rtw_scan_timeout_handler(adapter);
24 static void _dynamic_check_timer_handlder(struct timer_list *t)
26 struct adapter *adapter = from_timer(adapter, t, mlmepriv.dynamic_chk_timer);
28 rtw_dynamic_check_timer_handlder(adapter);
29 _set_timer(&adapter->mlmepriv.dynamic_chk_timer, 2000);
32 void rtw_init_mlme_timer(struct adapter *padapter)
34 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
36 timer_setup(&pmlmepriv->assoc_timer, rtw_join_timeout_handler, 0);
37 timer_setup(&pmlmepriv->scan_to_timer, _rtw_scan_timeout_handler, 0);
38 timer_setup(&pmlmepriv->dynamic_chk_timer, _dynamic_check_timer_handlder, 0);
41 void rtw_os_indicate_connect(struct adapter *adapter)
44 rtw_indicate_wx_assoc_event(adapter);
45 netif_carrier_on(adapter->pnetdev);
46 if (adapter->pid[2] != 0)
47 rtw_signal_process(adapter->pid[2], SIGALRM);
51 void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
53 indicate_wx_scan_complete_event(padapter);
56 static struct rt_pmkid_list backup_pmkid[NUM_PMKID_CACHE];
58 void rtw_reset_securitypriv(struct adapter *adapter)
61 u8 backup_counter = 0x00;
64 if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
66 /* We have to backup the PMK information for WiFi PMK Caching test item. */
67 /* Backup the btkip_countermeasure information. */
68 /* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
69 memcpy(&backup_pmkid[0], &adapter->securitypriv.PMKIDList[0], sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
70 backup_index = adapter->securitypriv.PMKIDIndex;
71 backup_counter = adapter->securitypriv.btkip_countermeasure;
72 backup_time = adapter->securitypriv.btkip_countermeasure_time;
73 memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
75 /* Restore the PMK information to securitypriv structure for the following connection. */
76 memcpy(&adapter->securitypriv.PMKIDList[0],
78 sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
79 adapter->securitypriv.PMKIDIndex = backup_index;
80 adapter->securitypriv.btkip_countermeasure = backup_counter;
81 adapter->securitypriv.btkip_countermeasure_time = backup_time;
82 adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
83 adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
85 /* reset values in securitypriv */
86 struct security_priv *psec_priv = &adapter->securitypriv;
88 psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
89 psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
90 psec_priv->dot11PrivacyKeyIndex = 0;
91 psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
92 psec_priv->dot118021XGrpKeyid = 1;
93 psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
94 psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
98 void rtw_os_indicate_disconnect(struct adapter *adapter)
101 netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */
102 rtw_indicate_wx_disassoc_event(adapter);
103 rtw_reset_securitypriv(adapter);
106 void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
110 union iwreq_data wrqu;
113 if (authmode == _WPA_IE_ID_) {
114 buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
118 p += sprintf(p, "ASSOCINFO(ReqIEs =");
120 len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
121 for (i = 0; i < len; i++)
122 p += sprintf(p, "%02x", sec_ie[i]);
123 p += sprintf(p, ")");
124 memset(&wrqu, 0, sizeof(wrqu));
125 wrqu.data.length = p - buff;
126 wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
127 wrqu.data.length : IW_CUSTOM_MAX;
128 wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
133 static void _survey_timer_hdl(struct timer_list *t)
135 struct adapter *padapter = from_timer(padapter, t, mlmeextpriv.survey_timer);
137 survey_timer_hdl(padapter);
140 static void _link_timer_hdl(struct timer_list *t)
142 struct adapter *padapter = from_timer(padapter, t, mlmeextpriv.link_timer);
143 link_timer_hdl(padapter);
146 static void _addba_timer_hdl(struct timer_list *t)
148 struct sta_info *psta = from_timer(psta, t, addba_retry_timer);
149 addba_timer_hdl(psta);
152 void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta)
154 timer_setup(&psta->addba_retry_timer, _addba_timer_hdl, 0);
157 void init_mlme_ext_timer(struct adapter *padapter)
159 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
161 timer_setup(&pmlmeext->survey_timer, _survey_timer_hdl, 0);
162 timer_setup(&pmlmeext->link_timer, _link_timer_hdl, 0);
165 void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *psta)
167 union iwreq_data wrqu;
168 struct sta_priv *pstapriv = &padapter->stapriv;
173 if (psta->aid > NUM_STA)
176 if (pstapriv->sta_aid[psta->aid - 1] != psta)
179 wrqu.addr.sa_family = ARPHRD_ETHER;
181 memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
183 wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
186 void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *psta)
188 union iwreq_data wrqu;
189 struct sta_priv *pstapriv = &padapter->stapriv;
194 if (psta->aid > NUM_STA)
197 if (pstapriv->sta_aid[psta->aid - 1] != psta)
200 wrqu.addr.sa_family = ARPHRD_ETHER;
202 memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
204 wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);