Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * mlme_linux.c |
| 3 | * |
| 4 | * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. |
| 5 | * Linux device driver for RTL8192SU |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 19 | * |
| 20 | * Modifications for inclusion into the Linux staging tree are |
| 21 | * Copyright(c) 2010 Larry Finger. All rights reserved. |
| 22 | * |
| 23 | * Contact information: |
| 24 | * WLAN FAE <wlanfae@realtek.com>. |
| 25 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 26 | * |
| 27 | ******************************************************************************/ |
| 28 | |
| 29 | #define _MLME_OSDEP_C_ |
| 30 | |
| 31 | #include "osdep_service.h" |
| 32 | #include "drv_types.h" |
| 33 | #include "mlme_osdep.h" |
| 34 | |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 35 | static void sitesurvey_ctrl_handler(unsigned long data) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 36 | { |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 37 | struct _adapter *adapter = (struct _adapter *)data; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 38 | |
| 39 | _r8712_sitesurvey_ctrl_handler(adapter); |
Vaishali Thakkar | c703c75 | 2015-02-27 23:25:48 +0530 | [diff] [blame] | 40 | mod_timer(&adapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer, |
| 41 | jiffies + msecs_to_jiffies(3000)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 44 | static void join_timeout_handler (unsigned long data) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 45 | { |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 46 | struct _adapter *adapter = (struct _adapter *)data; |
Santiago Torres | 89a07bd | 2014-07-27 17:02:47 -0400 | [diff] [blame] | 47 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 48 | _r8712_join_timeout_handler(adapter); |
| 49 | } |
| 50 | |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 51 | static void _scan_timeout_handler (unsigned long data) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 52 | { |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 53 | struct _adapter *adapter = (struct _adapter *)data; |
Santiago Torres | 89a07bd | 2014-07-27 17:02:47 -0400 | [diff] [blame] | 54 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 55 | r8712_scan_timeout_handler(adapter); |
| 56 | } |
| 57 | |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 58 | static void dhcp_timeout_handler (unsigned long data) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 59 | { |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 60 | struct _adapter *adapter = (struct _adapter *)data; |
Santiago Torres | 89a07bd | 2014-07-27 17:02:47 -0400 | [diff] [blame] | 61 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 62 | _r8712_dhcp_timeout_handler(adapter); |
| 63 | } |
| 64 | |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 65 | static void wdg_timeout_handler (unsigned long data) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 66 | { |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 67 | struct _adapter *adapter = (struct _adapter *)data; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 68 | |
| 69 | _r8712_wdg_timeout_handler(adapter); |
| 70 | |
Vaishali Thakkar | c703c75 | 2015-02-27 23:25:48 +0530 | [diff] [blame] | 71 | mod_timer(&adapter->mlmepriv.wdg_timer, |
| 72 | jiffies + msecs_to_jiffies(2000)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void r8712_init_mlme_timer(struct _adapter *padapter) |
| 76 | { |
| 77 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 78 | |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 79 | setup_timer(&pmlmepriv->assoc_timer, join_timeout_handler, |
| 80 | (unsigned long)padapter); |
| 81 | setup_timer(&pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer, |
| 82 | sitesurvey_ctrl_handler, |
| 83 | (unsigned long)padapter); |
| 84 | setup_timer(&pmlmepriv->scan_to_timer, _scan_timeout_handler, |
| 85 | (unsigned long)padapter); |
| 86 | setup_timer(&pmlmepriv->dhcp_timer, dhcp_timeout_handler, |
| 87 | (unsigned long)padapter); |
| 88 | setup_timer(&pmlmepriv->wdg_timer, wdg_timeout_handler, |
| 89 | (unsigned long)padapter); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void r8712_os_indicate_connect(struct _adapter *adapter) |
| 93 | { |
| 94 | r8712_indicate_wx_assoc_event(adapter); |
| 95 | netif_carrier_on(adapter->pnetdev); |
| 96 | } |
| 97 | |
| 98 | static struct RT_PMKID_LIST backupPMKIDList[NUM_PMKID_CACHE]; |
| 99 | void r8712_os_indicate_disconnect(struct _adapter *adapter) |
| 100 | { |
| 101 | u8 backupPMKIDIndex = 0; |
| 102 | u8 backupTKIPCountermeasure = 0x00; |
| 103 | |
| 104 | r8712_indicate_wx_disassoc_event(adapter); |
| 105 | netif_carrier_off(adapter->pnetdev); |
| 106 | if (adapter->securitypriv.AuthAlgrthm == 2) { /*/802.1x*/ |
| 107 | /* We have to backup the PMK information for WiFi PMK Caching |
| 108 | * test item. Backup the btkip_countermeasure information. |
| 109 | * When the countermeasure is trigger, the driver have to |
| 110 | * disconnect with AP for 60 seconds. |
| 111 | */ |
| 112 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 113 | memcpy(&backupPMKIDList[0], &adapter->securitypriv. |
| 114 | PMKIDList[0], sizeof(struct RT_PMKID_LIST) * |
| 115 | NUM_PMKID_CACHE); |
| 116 | backupPMKIDIndex = adapter->securitypriv.PMKIDIndex; |
| 117 | backupTKIPCountermeasure = adapter->securitypriv. |
| 118 | btkip_countermeasure; |
| 119 | memset((unsigned char *)&adapter->securitypriv, 0, |
| 120 | sizeof(struct security_priv)); |
Vaishali Thakkar | e922df7 | 2015-03-03 22:34:22 +0530 | [diff] [blame] | 121 | setup_timer(&adapter->securitypriv.tkip_timer, |
| 122 | r8712_use_tkipkey_handler, |
| 123 | (unsigned long)adapter); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 124 | /* Restore the PMK information to securitypriv structure |
Punit Vara | 98a5248 | 2015-09-20 16:55:29 +0530 | [diff] [blame] | 125 | * for the following connection. |
| 126 | */ |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 127 | memcpy(&adapter->securitypriv.PMKIDList[0], |
| 128 | &backupPMKIDList[0], |
| 129 | sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE); |
| 130 | adapter->securitypriv.PMKIDIndex = backupPMKIDIndex; |
| 131 | adapter->securitypriv.btkip_countermeasure = |
| 132 | backupTKIPCountermeasure; |
| 133 | } else { /*reset values in securitypriv*/ |
| 134 | struct security_priv *psec_priv = &adapter->securitypriv; |
| 135 | |
| 136 | psec_priv->AuthAlgrthm = 0; /*open system*/ |
| 137 | psec_priv->PrivacyAlgrthm = _NO_PRIVACY_; |
| 138 | psec_priv->PrivacyKeyIndex = 0; |
| 139 | psec_priv->XGrpPrivacy = _NO_PRIVACY_; |
| 140 | psec_priv->XGrpKeyid = 1; |
| 141 | psec_priv->ndisauthtype = Ndis802_11AuthModeOpen; |
| 142 | psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled; |
| 143 | psec_priv->wps_phase = false; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void r8712_report_sec_ie(struct _adapter *adapter, u8 authmode, u8 *sec_ie) |
| 148 | { |
| 149 | uint len; |
| 150 | u8 *buff, *p, i; |
| 151 | union iwreq_data wrqu; |
| 152 | |
| 153 | buff = NULL; |
| 154 | if (authmode == _WPA_IE_ID_) { |
Vitaly Osipov | 91d435f | 2014-05-24 18:19:27 +1000 | [diff] [blame] | 155 | buff = kzalloc(IW_CUSTOM_MAX, GFP_ATOMIC); |
Bhaktipriya Shridhar | 4d97b69 | 2016-03-22 20:29:13 +0530 | [diff] [blame] | 156 | if (!buff) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 157 | return; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 158 | p = buff; |
| 159 | p += sprintf(p, "ASSOCINFO(ReqIEs="); |
| 160 | len = sec_ie[1] + 2; |
Larry Finger | 8b7a13c | 2012-11-27 12:08:44 -0600 | [diff] [blame] | 161 | len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX - 1; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 162 | for (i = 0; i < len; i++) |
| 163 | p += sprintf(p, "%02x", sec_ie[i]); |
| 164 | p += sprintf(p, ")"); |
| 165 | memset(&wrqu, 0, sizeof(wrqu)); |
Luis de Bethencourt | 4ef2de5 | 2015-10-19 18:16:01 +0100 | [diff] [blame] | 166 | wrqu.data.length = p - buff; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 167 | wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? |
| 168 | wrqu.data.length : IW_CUSTOM_MAX; |
| 169 | wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff); |
| 170 | kfree(buff); |
| 171 | } |
| 172 | } |