Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * File: hostap.c |
| 20 | * |
| 21 | * Purpose: handle hostap deamon ioctl input/out functions |
| 22 | * |
| 23 | * Author: Lyndon Chen |
| 24 | * |
| 25 | * Date: Oct. 20, 2003 |
| 26 | * |
| 27 | * Functions: |
| 28 | * |
| 29 | * Revision History: |
| 30 | * |
| 31 | */ |
| 32 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 33 | #include "hostap.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 34 | #include "iocmd.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 35 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 36 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 37 | #include "baseband.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 38 | #include "wpactl.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 39 | #include "key.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | |
| 41 | #define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024 |
| 42 | #define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0 |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 43 | #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3 |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 44 | #define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5 |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 45 | |
| 46 | /*--------------------- Static Definitions -------------------------*/ |
| 47 | |
| 48 | /*--------------------- Static Classes ----------------------------*/ |
| 49 | |
| 50 | /*--------------------- Static Variables --------------------------*/ |
| 51 | //static int msglevel =MSG_LEVEL_DEBUG; |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 52 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 53 | |
| 54 | /*--------------------- Static Functions --------------------------*/ |
| 55 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 56 | /*--------------------- Export Variables --------------------------*/ |
| 57 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 58 | /* |
| 59 | * Description: |
| 60 | * register net_device (AP) for hostap deamon |
| 61 | * |
| 62 | * Parameters: |
| 63 | * In: |
| 64 | * pDevice - |
| 65 | * rtnl_locked - |
| 66 | * Out: |
| 67 | * |
| 68 | * Return Value: |
| 69 | * |
| 70 | */ |
| 71 | |
| 72 | static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) |
| 73 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 74 | PSDevice apdev_priv; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 75 | struct net_device *dev = pDevice->dev; |
| 76 | int ret; |
Jim Lieb | db6cb90 | 2009-07-23 17:20:49 -0700 | [diff] [blame] | 77 | const struct net_device_ops apdev_netdev_ops = { |
| 78 | .ndo_start_xmit = pDevice->tx_80211, |
| 79 | }; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 80 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 81 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 82 | |
Hema Prathaban | 3523a90 | 2013-05-17 11:14:56 +0530 | [diff] [blame] | 83 | pDevice->apdev = alloc_etherdev(sizeof(*apdev_priv)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 84 | if (pDevice->apdev == NULL) |
| 85 | return -ENOMEM; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 86 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 87 | apdev_priv = netdev_priv(pDevice->apdev); |
| 88 | *apdev_priv = *pDevice; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 89 | memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN); |
Forest Bond | 5721135 | 2009-06-02 14:44:33 -0400 | [diff] [blame] | 90 | |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 91 | pDevice->apdev->netdev_ops = &apdev_netdev_ops; |
Forest Bond | 5721135 | 2009-06-02 14:44:33 -0400 | [diff] [blame] | 92 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 93 | pDevice->apdev->type = ARPHRD_IEEE80211; |
| 94 | |
| 95 | pDevice->apdev->base_addr = dev->base_addr; |
| 96 | pDevice->apdev->irq = dev->irq; |
| 97 | pDevice->apdev->mem_start = dev->mem_start; |
| 98 | pDevice->apdev->mem_end = dev->mem_end; |
| 99 | sprintf(pDevice->apdev->name, "%sap", dev->name); |
| 100 | if (rtnl_locked) |
| 101 | ret = register_netdevice(pDevice->apdev); |
| 102 | else |
| 103 | ret = register_netdev(pDevice->apdev); |
| 104 | if (ret) { |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 105 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n", |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 106 | dev->name); |
Wei Yongjun | 3147cf5 | 2013-05-23 17:28:05 +0800 | [diff] [blame] | 107 | free_netdev(pDevice->apdev); |
| 108 | pDevice->apdev = NULL; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 109 | return -1; |
| 110 | } |
| 111 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 112 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n", |
| 113 | dev->name, pDevice->apdev->name); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 114 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 115 | KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Description: |
| 122 | * unregister net_device(AP) |
| 123 | * |
| 124 | * Parameters: |
| 125 | * In: |
| 126 | * pDevice - |
| 127 | * rtnl_locked - |
| 128 | * Out: |
| 129 | * |
| 130 | * Return Value: |
| 131 | * |
| 132 | */ |
| 133 | |
| 134 | static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) |
| 135 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 136 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 137 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 138 | if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 139 | if (rtnl_locked) |
| 140 | unregister_netdevice(pDevice->apdev); |
| 141 | else |
| 142 | unregister_netdev(pDevice->apdev); |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 143 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", |
| 144 | pDevice->dev->name, pDevice->apdev->name); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 145 | } |
Hema Prathaban | 3030d40 | 2013-05-15 21:21:17 +0530 | [diff] [blame] | 146 | free_netdev(pDevice->apdev); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 147 | pDevice->apdev = NULL; |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 148 | pDevice->bEnable8021x = false; |
| 149 | pDevice->bEnableHostWEP = false; |
| 150 | pDevice->bEncryptionEnable = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 151 | |
| 152 | //4.2007-0118-03,<Add> by EinsnLiu |
| 153 | //execute some clear work |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 154 | pDevice->pMgmt->byCSSPK = KEY_CTL_NONE; |
| 155 | pDevice->pMgmt->byCSSGK = KEY_CTL_NONE; |
| 156 | KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 161 | /* |
| 162 | * Description: |
| 163 | * Set enable/disable hostapd mode |
| 164 | * |
| 165 | * Parameters: |
| 166 | * In: |
| 167 | * pDevice - |
| 168 | * rtnl_locked - |
| 169 | * Out: |
| 170 | * |
| 171 | * Return Value: |
| 172 | * |
| 173 | */ |
| 174 | |
Forest Bond | ecf739e | 2010-04-17 11:03:47 -0400 | [diff] [blame] | 175 | int vt6655_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 176 | { |
| 177 | if (val < 0 || val > 1) |
| 178 | return -EINVAL; |
| 179 | |
| 180 | if (pDevice->bEnableHostapd == val) |
| 181 | return 0; |
| 182 | |
| 183 | pDevice->bEnableHostapd = val; |
| 184 | |
| 185 | if (val) |
| 186 | return hostap_enable_hostapd(pDevice, rtnl_locked); |
| 187 | else |
| 188 | return hostap_disable_hostapd(pDevice, rtnl_locked); |
| 189 | } |
| 190 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 191 | /* |
| 192 | * Description: |
| 193 | * remove station function supported for hostap deamon |
| 194 | * |
| 195 | * Parameters: |
| 196 | * In: |
| 197 | * pDevice - |
| 198 | * param - |
| 199 | * Out: |
| 200 | * |
| 201 | * Return Value: |
| 202 | * |
| 203 | */ |
| 204 | static int hostap_remove_sta(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 205 | struct viawget_hostapd_param *param) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 206 | { |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 207 | unsigned int uNodeIndex; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 208 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 209 | if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) { |
| 210 | BSSvRemoveOneNode(pDevice, uNodeIndex); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 211 | } else { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 212 | return -ENOENT; |
| 213 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Description: |
| 219 | * add a station from hostap deamon |
| 220 | * |
| 221 | * Parameters: |
| 222 | * In: |
| 223 | * pDevice - |
| 224 | * param - |
| 225 | * Out: |
| 226 | * |
| 227 | * Return Value: |
| 228 | * |
| 229 | */ |
| 230 | static int hostap_add_sta(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 231 | struct viawget_hostapd_param *param) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 232 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 233 | PSMgmtObject pMgmt = pDevice->pMgmt; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 234 | unsigned int uNodeIndex; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 235 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 236 | if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) { |
| 237 | BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); |
| 238 | } |
| 239 | memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN); |
| 240 | pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC; |
| 241 | pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 242 | // TODO listenInterval |
| 243 | // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1; |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 244 | pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false; |
| 245 | pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 246 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 247 | // set max tx rate |
| 248 | pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = |
| 249 | pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate; |
| 250 | // set max basic rate |
| 251 | pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M; |
| 252 | // Todo: check sta preamble, if ap can't support, set status code |
| 253 | pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = |
| 254 | WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 255 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 256 | pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)param->u.add_sta.aid; |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 257 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 258 | pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies; |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 259 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 260 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID); |
| 261 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n", |
| 262 | param->sta_addr[0], |
| 263 | param->sta_addr[1], |
| 264 | param->sta_addr[2], |
| 265 | param->sta_addr[3], |
| 266 | param->sta_addr[4], |
| 267 | param->sta_addr[5] |
| 268 | ); |
| 269 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n", |
| 270 | pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * Description: |
| 277 | * get station info |
| 278 | * |
| 279 | * Parameters: |
| 280 | * In: |
| 281 | * pDevice - |
| 282 | * param - |
| 283 | * Out: |
| 284 | * |
| 285 | * Return Value: |
| 286 | * |
| 287 | */ |
| 288 | |
| 289 | static int hostap_get_info_sta(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 290 | struct viawget_hostapd_param *param) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 291 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 292 | PSMgmtObject pMgmt = pDevice->pMgmt; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 293 | unsigned int uNodeIndex; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 294 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 295 | if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) { |
| 296 | param->u.get_info_sta.inactive_sec = |
| 297 | (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ; |
Jim Lieb | 612822f | 2009-08-12 14:54:03 -0700 | [diff] [blame] | 298 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 299 | //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 300 | } else { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 301 | return -ENOENT; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Description: |
| 309 | * reset txexec |
| 310 | * |
| 311 | * Parameters: |
| 312 | * In: |
| 313 | * pDevice - |
| 314 | * param - |
| 315 | * Out: |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 316 | * true, false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 317 | * |
| 318 | * Return Value: |
| 319 | * |
| 320 | */ |
| 321 | /* |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 322 | static int hostap_reset_txexc_sta(PSDevice pDevice, |
| 323 | struct viawget_hostapd_param *param) |
| 324 | { |
| 325 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 326 | unsigned int uNodeIndex; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 327 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 328 | if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) { |
| 329 | pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 330 | } else { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 331 | return -ENOENT; |
| 332 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 333 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 334 | return 0; |
| 335 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 336 | */ |
| 337 | |
| 338 | /* |
| 339 | * Description: |
| 340 | * set station flag |
| 341 | * |
| 342 | * Parameters: |
| 343 | * In: |
| 344 | * pDevice - |
| 345 | * param - |
| 346 | * Out: |
| 347 | * |
| 348 | * Return Value: |
| 349 | * |
| 350 | */ |
| 351 | static int hostap_set_flags_sta(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 352 | struct viawget_hostapd_param *param) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 353 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 354 | PSMgmtObject pMgmt = pDevice->pMgmt; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 355 | unsigned int uNodeIndex; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 356 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 357 | if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 358 | pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or; |
| 359 | pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 360 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n", |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 361 | (unsigned int)pMgmt->sNodeDBTable[uNodeIndex].dwFlags); |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 362 | } else { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 363 | return -ENOENT; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 369 | /* |
| 370 | * Description: |
| 371 | * set generic element (wpa ie) |
| 372 | * |
| 373 | * Parameters: |
| 374 | * In: |
| 375 | * pDevice - |
| 376 | * param - |
| 377 | * Out: |
| 378 | * |
| 379 | * Return Value: |
| 380 | * |
| 381 | */ |
| 382 | static int hostap_set_generic_element(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 383 | struct viawget_hostapd_param *param) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 384 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 385 | PSMgmtObject pMgmt = pDevice->pMgmt; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 386 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 387 | memcpy(pMgmt->abyWPAIE, |
| 388 | param->u.generic_elem.data, |
| 389 | param->u.generic_elem.len |
| 390 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 391 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 392 | pMgmt->wWPAIELen = param->u.generic_elem.len; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 393 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 394 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 395 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 396 | // disable wpa |
| 397 | if (pMgmt->wWPAIELen == 0) { |
| 398 | pMgmt->eAuthenMode = WMAC_AUTH_OPEN; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 399 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n"); |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 400 | } else { |
| 401 | // enable wpa |
| 402 | if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) || |
| 403 | (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) { |
| 404 | pMgmt->eAuthenMode = WMAC_AUTH_WPANONE; |
| 405 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n"); |
| 406 | } else |
| 407 | return -EINVAL; |
| 408 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Description: |
| 415 | * flush station nodes table. |
| 416 | * |
| 417 | * Parameters: |
| 418 | * In: |
| 419 | * pDevice - |
| 420 | * Out: |
| 421 | * |
| 422 | * Return Value: |
| 423 | * |
| 424 | */ |
| 425 | |
| 426 | static void hostap_flush_sta(PSDevice pDevice) |
| 427 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 428 | // reserved node index =0 for multicast node. |
| 429 | BSSvClearNodeDBTable(pDevice, 1); |
| 430 | pDevice->uAssocCount = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 431 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 432 | return; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Description: |
| 437 | * set each stations encryption key |
| 438 | * |
| 439 | * Parameters: |
| 440 | * In: |
| 441 | * pDevice - |
| 442 | * param - |
| 443 | * Out: |
| 444 | * |
| 445 | * Return Value: |
| 446 | * |
| 447 | */ |
| 448 | static int hostap_set_encryption(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 449 | struct viawget_hostapd_param *param, |
| 450 | int param_len) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 451 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 452 | PSMgmtObject pMgmt = pDevice->pMgmt; |
| 453 | unsigned long dwKeyIndex = 0; |
| 454 | unsigned char abyKey[MAX_KEY_LEN]; |
| 455 | unsigned char abySeq[MAX_KEY_LEN]; |
| 456 | NDIS_802_11_KEY_RSC KeyRSC; |
| 457 | unsigned char byKeyDecMode = KEY_CTL_WEP; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 458 | int ret = 0; |
| 459 | int iNodeIndex = -1; |
| 460 | int ii; |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 461 | bool bKeyTableFull = false; |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 462 | unsigned short wKeyCtl = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 463 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 464 | param->u.crypt.err = 0; |
| 465 | /* |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 466 | if (param_len != |
| 467 | (int) ((char *) param->u.crypt.key - (char *) param) + |
| 468 | param->u.crypt.key_len) |
| 469 | return -EINVAL; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 470 | */ |
| 471 | |
| 472 | if (param->u.crypt.alg > WPA_ALG_CCMP) |
| 473 | return -EINVAL; |
| 474 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 475 | if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) { |
| 476 | param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED; |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 477 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 478 | return -EINVAL; |
| 479 | } |
| 480 | |
Wei Yongjun | 78b3114 | 2012-08-26 09:02:16 +0800 | [diff] [blame] | 481 | if (is_broadcast_ether_addr(param->sta_addr)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 482 | if (param->u.crypt.idx >= MAX_GROUP_KEY) |
| 483 | return -EINVAL; |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 484 | iNodeIndex = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 485 | |
| 486 | } else { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 487 | if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) { |
| 488 | param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; |
| 489 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); |
| 490 | return -EINVAL; |
| 491 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 492 | } |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 493 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex); |
| 494 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 495 | |
| 496 | if (param->u.crypt.alg == WPA_ALG_NONE) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 497 | if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) { |
| 498 | if (KeybRemoveKey(&(pDevice->sKey), |
| 499 | param->sta_addr, |
| 500 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex, |
| 501 | pDevice->PortOffset) == false) { |
| 502 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n"); |
| 503 | } |
| 504 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; |
| 505 | } |
| 506 | pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0; |
| 507 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0; |
| 508 | pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0; |
| 509 | pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0; |
| 510 | pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0; |
| 511 | pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0; |
| 512 | pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0; |
| 513 | memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0], |
| 514 | 0, |
| 515 | MAX_KEY_LEN |
| 516 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 517 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 518 | return ret; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 521 | memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len); |
| 522 | // copy to node key tbl |
| 523 | pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx; |
| 524 | pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len; |
| 525 | memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0], |
| 526 | param->u.crypt.key, |
| 527 | param->u.crypt.key_len |
| 528 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 529 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 530 | dwKeyIndex = (unsigned long)(param->u.crypt.idx); |
| 531 | if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) { |
| 532 | pDevice->byKeyIndex = (unsigned char)dwKeyIndex; |
| 533 | pDevice->bTransmitKey = true; |
| 534 | dwKeyIndex |= (1 << 31); |
| 535 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 536 | |
| 537 | if (param->u.crypt.alg == WPA_ALG_WEP) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 538 | if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) { |
| 539 | KeybSetDefaultKey(&(pDevice->sKey), |
| 540 | dwKeyIndex & ~(BIT30 | USE_KEYRSC), |
| 541 | param->u.crypt.key_len, |
| 542 | NULL, |
| 543 | abyKey, |
| 544 | KEY_CTL_WEP, |
| 545 | pDevice->PortOffset, |
| 546 | pDevice->byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 547 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 548 | } else { |
| 549 | // 8021x enable, individual key |
| 550 | dwKeyIndex |= (1 << 30); // set pairwise key |
| 551 | if (KeybSetKey(&(pDevice->sKey), |
| 552 | ¶m->sta_addr[0], |
| 553 | dwKeyIndex & ~(USE_KEYRSC), |
| 554 | param->u.crypt.key_len, |
| 555 | (PQWORD) &(KeyRSC), |
| 556 | (unsigned char *)abyKey, |
| 557 | KEY_CTL_WEP, |
| 558 | pDevice->PortOffset, |
| 559 | pDevice->byLocalID) == true) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 560 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 561 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 562 | } else { |
| 563 | // Key Table Full |
| 564 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; |
| 565 | bKeyTableFull = true; |
| 566 | } |
| 567 | } |
| 568 | pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; |
| 569 | pDevice->bEncryptionEnable = true; |
| 570 | pMgmt->byCSSPK = KEY_CTL_WEP; |
| 571 | pMgmt->byCSSGK = KEY_CTL_WEP; |
| 572 | pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP; |
| 573 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex; |
| 574 | return ret; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | if (param->u.crypt.seq) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 578 | memcpy(&abySeq, param->u.crypt.seq, 8); |
| 579 | for (ii = 0; ii < 8; ii++) |
Dan Carpenter | c25015c | 2012-10-11 09:55:25 +0300 | [diff] [blame] | 580 | KeyRSC |= (unsigned long)abySeq[ii] << (ii * 8); |
| 581 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 582 | dwKeyIndex |= 1 << 29; |
| 583 | pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC; |
| 584 | } |
| 585 | |
| 586 | if (param->u.crypt.alg == WPA_ALG_TKIP) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 587 | if (param->u.crypt.key_len != MAX_KEY_LEN) |
| 588 | return -EINVAL; |
| 589 | pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; |
| 590 | byKeyDecMode = KEY_CTL_TKIP; |
| 591 | pMgmt->byCSSPK = KEY_CTL_TKIP; |
| 592 | pMgmt->byCSSGK = KEY_CTL_TKIP; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | if (param->u.crypt.alg == WPA_ALG_CCMP) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 596 | if ((param->u.crypt.key_len != AES_KEY_LEN) || |
| 597 | (pDevice->byLocalID <= REV_ID_VT3253_A1)) |
| 598 | return -EINVAL; |
| 599 | pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; |
| 600 | byKeyDecMode = KEY_CTL_CCMP; |
| 601 | pMgmt->byCSSPK = KEY_CTL_CCMP; |
| 602 | pMgmt->byCSSGK = KEY_CTL_CCMP; |
| 603 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 604 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 605 | if (iNodeIndex == 0) { |
| 606 | KeybSetDefaultKey(&(pDevice->sKey), |
| 607 | dwKeyIndex, |
| 608 | param->u.crypt.key_len, |
| 609 | (PQWORD) &(KeyRSC), |
| 610 | abyKey, |
| 611 | byKeyDecMode, |
| 612 | pDevice->PortOffset, |
| 613 | pDevice->byLocalID); |
| 614 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 615 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 616 | } else { |
| 617 | dwKeyIndex |= (1 << 30); // set pairwise key |
| 618 | if (KeybSetKey(&(pDevice->sKey), |
| 619 | ¶m->sta_addr[0], |
| 620 | dwKeyIndex, |
| 621 | param->u.crypt.key_len, |
| 622 | (PQWORD) &(KeyRSC), |
| 623 | (unsigned char *)abyKey, |
| 624 | byKeyDecMode, |
| 625 | pDevice->PortOffset, |
| 626 | pDevice->byLocalID) == true) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 627 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 628 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 629 | } else { |
| 630 | // Key Table Full |
| 631 | pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false; |
| 632 | bKeyTableFull = true; |
| 633 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n"); |
| 634 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 635 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 636 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 637 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 638 | if (bKeyTableFull == true) { |
| 639 | wKeyCtl &= 0x7F00; // clear all key control filed |
| 640 | wKeyCtl |= (byKeyDecMode << 4); |
| 641 | wKeyCtl |= (byKeyDecMode); |
| 642 | wKeyCtl |= 0x0044; // use group key for all address |
| 643 | wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int |
| 644 | MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID); |
| 645 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 646 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 647 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex); |
| 648 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx, |
| 649 | param->u.crypt.key_len); |
| 650 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n", |
| 651 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0], |
| 652 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1], |
| 653 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2], |
| 654 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3], |
| 655 | pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4] |
| 656 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 657 | |
| 658 | // set wep key |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 659 | pDevice->bEncryptionEnable = true; |
| 660 | pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode; |
| 661 | pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex; |
| 662 | pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0; |
| 663 | pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 664 | |
| 665 | return ret; |
| 666 | } |
| 667 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 668 | /* |
| 669 | * Description: |
| 670 | * get each stations encryption key |
| 671 | * |
| 672 | * Parameters: |
| 673 | * In: |
| 674 | * pDevice - |
| 675 | * param - |
| 676 | * Out: |
| 677 | * |
| 678 | * Return Value: |
| 679 | * |
| 680 | */ |
| 681 | static int hostap_get_encryption(PSDevice pDevice, |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 682 | struct viawget_hostapd_param *param, |
| 683 | int param_len) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 684 | { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 685 | PSMgmtObject pMgmt = pDevice->pMgmt; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 686 | int ret = 0; |
| 687 | int ii; |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 688 | int iNodeIndex = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 689 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 690 | param->u.crypt.err = 0; |
| 691 | |
Wei Yongjun | 78b3114 | 2012-08-26 09:02:16 +0800 | [diff] [blame] | 692 | if (is_broadcast_ether_addr(param->sta_addr)) { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 693 | iNodeIndex = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 694 | } else { |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 695 | if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) { |
| 696 | param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; |
| 697 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); |
| 698 | return -EINVAL; |
| 699 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 700 | } |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 701 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex); |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 702 | memset(param->u.crypt.seq, 0, 8); |
| 703 | for (ii = 0; ii < 8; ii++) { |
| 704 | param->u.crypt.seq[ii] = (unsigned char)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8); |
| 705 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 706 | |
| 707 | return ret; |
| 708 | } |
| 709 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 710 | /* |
| 711 | * Description: |
Forest Bond | ecf739e | 2010-04-17 11:03:47 -0400 | [diff] [blame] | 712 | * vt6655_hostap_ioctl main function supported for hostap deamon. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 713 | * |
| 714 | * Parameters: |
| 715 | * In: |
| 716 | * pDevice - |
| 717 | * iw_point - |
| 718 | * Out: |
| 719 | * |
| 720 | * Return Value: |
| 721 | * |
| 722 | */ |
| 723 | |
Forest Bond | ecf739e | 2010-04-17 11:03:47 -0400 | [diff] [blame] | 724 | int vt6655_hostap_ioctl(PSDevice pDevice, struct iw_point *p) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 725 | { |
| 726 | struct viawget_hostapd_param *param; |
| 727 | int ret = 0; |
| 728 | int ap_ioctl = 0; |
| 729 | |
| 730 | if (p->length < sizeof(struct viawget_hostapd_param) || |
| 731 | p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer) |
| 732 | return -EINVAL; |
| 733 | |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 734 | param = kmalloc((int)p->length, (int)GFP_KERNEL); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 735 | if (param == NULL) |
| 736 | return -ENOMEM; |
| 737 | |
| 738 | if (copy_from_user(param, p->pointer, p->length)) { |
| 739 | ret = -EFAULT; |
| 740 | goto out; |
| 741 | } |
| 742 | |
| 743 | switch (param->cmd) { |
| 744 | case VIAWGET_HOSTAPD_SET_ENCRYPTION: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 745 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n"); |
| 746 | spin_lock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 747 | ret = hostap_set_encryption(pDevice, param, p->length); |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 748 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 749 | break; |
| 750 | case VIAWGET_HOSTAPD_GET_ENCRYPTION: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 751 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n"); |
| 752 | spin_lock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 753 | ret = hostap_get_encryption(pDevice, param, p->length); |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 754 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 755 | break; |
| 756 | case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 757 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 758 | return -EOPNOTSUPP; |
| 759 | break; |
| 760 | case VIAWGET_HOSTAPD_FLUSH: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 761 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n"); |
| 762 | spin_lock_irq(&pDevice->lock); |
| 763 | hostap_flush_sta(pDevice); |
| 764 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 765 | break; |
| 766 | case VIAWGET_HOSTAPD_ADD_STA: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 767 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n"); |
| 768 | spin_lock_irq(&pDevice->lock); |
| 769 | ret = hostap_add_sta(pDevice, param); |
| 770 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 771 | break; |
| 772 | case VIAWGET_HOSTAPD_REMOVE_STA: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 773 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n"); |
| 774 | spin_lock_irq(&pDevice->lock); |
| 775 | ret = hostap_remove_sta(pDevice, param); |
| 776 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 777 | break; |
| 778 | case VIAWGET_HOSTAPD_GET_INFO_STA: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 779 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n"); |
| 780 | ret = hostap_get_info_sta(pDevice, param); |
| 781 | ap_ioctl = 1; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 782 | break; |
| 783 | /* |
| 784 | case VIAWGET_HOSTAPD_RESET_TXEXC_STA: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 785 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n"); |
| 786 | ret = hostap_reset_txexc_sta(pDevice, param); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 787 | break; |
| 788 | */ |
| 789 | case VIAWGET_HOSTAPD_SET_FLAGS_STA: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 790 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n"); |
| 791 | ret = hostap_set_flags_sta(pDevice, param); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case VIAWGET_HOSTAPD_MLME: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 795 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n"); |
| 796 | return -EOPNOTSUPP; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 797 | |
| 798 | case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 799 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 800 | ret = hostap_set_generic_element(pDevice, param); |
| 801 | break; |
| 802 | |
| 803 | case VIAWGET_HOSTAPD_SCAN_REQ: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 804 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n"); |
| 805 | return -EOPNOTSUPP; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 806 | |
| 807 | case VIAWGET_HOSTAPD_STA_CLEAR_STATS: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 808 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n"); |
| 809 | return -EOPNOTSUPP; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 810 | |
| 811 | default: |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 812 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6655_hostap_ioctl: unknown cmd=%d\n", |
| 813 | (int)param->cmd); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 814 | return -EOPNOTSUPP; |
| 815 | break; |
| 816 | } |
| 817 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 818 | if ((ret == 0) && ap_ioctl) { |
| 819 | if (copy_to_user(p->pointer, param, p->length)) { |
| 820 | ret = -EFAULT; |
| 821 | goto out; |
| 822 | } |
| 823 | } |
| 824 | |
Joe Perches | 4b61d80 | 2013-03-18 10:44:49 -0700 | [diff] [blame] | 825 | out: |
Ilia Mirkin | 6403bb7 | 2011-03-13 00:29:14 -0500 | [diff] [blame] | 826 | kfree(param); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 827 | |
| 828 | return ret; |
| 829 | } |