Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file contains our _wx handlers. Make sure you EXPORT_SYMBOL_GPL them |
Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 3 | * |
Johannes Berg | 7985905 | 2006-01-31 19:31:41 +0100 | [diff] [blame] | 4 | * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Joseph Jezak <josejx@gentoo.org> |
| 6 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 7 | * Danny van Dyk <kugelfang@gentoo.org> |
| 8 | * Michael Buesch <mbuesch@freenet.de> |
Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * |
| 23 | * The full GNU General Public License is included in this distribution in the |
| 24 | * file called COPYING. |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include "ieee80211softmac_priv.h" |
| 28 | |
| 29 | #include <net/iw_handler.h> |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 30 | /* for is_broadcast_ether_addr and is_zero_ether_addr */ |
| 31 | #include <linux/etherdevice.h> |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 32 | |
| 33 | int |
| 34 | ieee80211softmac_wx_trigger_scan(struct net_device *net_dev, |
| 35 | struct iw_request_info *info, |
| 36 | union iwreq_data *data, |
| 37 | char *extra) |
| 38 | { |
| 39 | struct ieee80211softmac_device *sm = ieee80211_priv(net_dev); |
| 40 | return ieee80211softmac_start_scan(sm); |
| 41 | } |
| 42 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_trigger_scan); |
| 43 | |
| 44 | |
johannes@sipsolutions.net | ba2f8c1 | 2006-04-11 10:58:06 +0200 | [diff] [blame] | 45 | /* if we're still scanning, return -EAGAIN so that userspace tools |
| 46 | * can get the complete scan results, otherwise return 0. */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 47 | int |
| 48 | ieee80211softmac_wx_get_scan_results(struct net_device *net_dev, |
| 49 | struct iw_request_info *info, |
| 50 | union iwreq_data *data, |
| 51 | char *extra) |
| 52 | { |
johannes@sipsolutions.net | ba2f8c1 | 2006-04-11 10:58:06 +0200 | [diff] [blame] | 53 | unsigned long flags; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 54 | struct ieee80211softmac_device *sm = ieee80211_priv(net_dev); |
johannes@sipsolutions.net | ba2f8c1 | 2006-04-11 10:58:06 +0200 | [diff] [blame] | 55 | |
| 56 | spin_lock_irqsave(&sm->lock, flags); |
| 57 | if (sm->scanning) { |
| 58 | spin_unlock_irqrestore(&sm->lock, flags); |
| 59 | return -EAGAIN; |
| 60 | } |
| 61 | spin_unlock_irqrestore(&sm->lock, flags); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 62 | return ieee80211_wx_get_scan(sm->ieee, info, data, extra); |
| 63 | } |
| 64 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_scan_results); |
| 65 | |
| 66 | int |
| 67 | ieee80211softmac_wx_set_essid(struct net_device *net_dev, |
| 68 | struct iw_request_info *info, |
| 69 | union iwreq_data *data, |
| 70 | char *extra) |
| 71 | { |
| 72 | struct ieee80211softmac_device *sm = ieee80211_priv(net_dev); |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 73 | struct ieee80211softmac_auth_queue_item *authptr; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 74 | int length = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 75 | DECLARE_MAC_BUF(mac); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 76 | |
Michael Buesch | fdc8f43 | 2007-07-31 20:41:04 +0200 | [diff] [blame] | 77 | check_assoc_again: |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 78 | mutex_lock(&sm->associnfo.mutex); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 79 | if((sm->associnfo.associating || sm->associnfo.associated) && |
Larry Finger | b978d02 | 2006-08-31 10:01:39 -0500 | [diff] [blame] | 80 | (data->essid.flags && data->essid.length)) { |
Larry Finger | efe870f | 2007-09-18 22:00:52 -0500 | [diff] [blame] | 81 | dprintk(KERN_INFO PFX "Canceling existing associate request!\n"); |
| 82 | /* Cancel assoc work */ |
| 83 | cancel_delayed_work(&sm->associnfo.work); |
| 84 | /* We don't have to do this, but it's a little cleaner */ |
| 85 | list_for_each_entry(authptr, &sm->auth_queue, list) |
| 86 | cancel_delayed_work(&authptr->work); |
| 87 | sm->associnfo.bssvalid = 0; |
| 88 | sm->associnfo.bssfixed = 0; |
| 89 | sm->associnfo.associating = 0; |
| 90 | sm->associnfo.associated = 0; |
| 91 | /* We must unlock to avoid deadlocks with the assoc workqueue |
| 92 | * on the associnfo.mutex */ |
| 93 | mutex_unlock(&sm->associnfo.mutex); |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 94 | flush_workqueue(sm->wq); |
Larry Finger | efe870f | 2007-09-18 22:00:52 -0500 | [diff] [blame] | 95 | /* Avoid race! Check assoc status again. Maybe someone started an |
| 96 | * association while we flushed. */ |
| 97 | goto check_assoc_again; |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 100 | sm->associnfo.static_essid = 0; |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 101 | sm->associnfo.assoc_wait = 0; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 102 | |
Larry Finger | b978d02 | 2006-08-31 10:01:39 -0500 | [diff] [blame] | 103 | if (data->essid.flags && data->essid.length) { |
| 104 | length = min((int)data->essid.length, IW_ESSID_MAX_SIZE); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 105 | if (length) { |
| 106 | memcpy(sm->associnfo.req_essid.data, extra, length); |
| 107 | sm->associnfo.static_essid = 1; |
| 108 | } |
| 109 | } |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 110 | |
| 111 | /* set our requested ESSID length. |
| 112 | * If applicable, we have already copied the data in */ |
| 113 | sm->associnfo.req_essid.len = length; |
| 114 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 115 | sm->associnfo.associating = 1; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 116 | /* queue lower level code to do work (if necessary) */ |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 117 | queue_delayed_work(sm->wq, &sm->associnfo.work, 0); |
Richard Knutsson | ee0a816 | 2007-10-01 02:24:38 +0200 | [diff] [blame] | 118 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 119 | mutex_unlock(&sm->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 120 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_essid); |
| 124 | |
| 125 | int |
| 126 | ieee80211softmac_wx_get_essid(struct net_device *net_dev, |
| 127 | struct iw_request_info *info, |
| 128 | union iwreq_data *data, |
| 129 | char *extra) |
| 130 | { |
| 131 | struct ieee80211softmac_device *sm = ieee80211_priv(net_dev); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 132 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 133 | mutex_lock(&sm->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 134 | /* If all fails, return ANY (empty) */ |
| 135 | data->essid.length = 0; |
| 136 | data->essid.flags = 0; /* active */ |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 137 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 138 | /* If we have a statically configured ESSID then return it */ |
| 139 | if (sm->associnfo.static_essid) { |
| 140 | data->essid.length = sm->associnfo.req_essid.len; |
| 141 | data->essid.flags = 1; /* active */ |
| 142 | memcpy(extra, sm->associnfo.req_essid.data, sm->associnfo.req_essid.len); |
Larry Finger | efe870f | 2007-09-18 22:00:52 -0500 | [diff] [blame] | 143 | dprintk(KERN_INFO PFX "Getting essid from req_essid\n"); |
| 144 | } else if (sm->associnfo.associated || sm->associnfo.associating) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 145 | /* If we're associating/associated, return that */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 146 | data->essid.length = sm->associnfo.associate_essid.len; |
| 147 | data->essid.flags = 1; /* active */ |
| 148 | memcpy(extra, sm->associnfo.associate_essid.data, sm->associnfo.associate_essid.len); |
Larry Finger | efe870f | 2007-09-18 22:00:52 -0500 | [diff] [blame] | 149 | dprintk(KERN_INFO PFX "Getting essid from associate_essid\n"); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 150 | } |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 151 | mutex_unlock(&sm->associnfo.mutex); |
| 152 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_essid); |
| 156 | |
| 157 | int |
| 158 | ieee80211softmac_wx_set_rate(struct net_device *net_dev, |
| 159 | struct iw_request_info *info, |
| 160 | union iwreq_data *data, |
| 161 | char *extra) |
| 162 | { |
| 163 | struct ieee80211softmac_device *mac = ieee80211_priv(net_dev); |
| 164 | struct ieee80211_device *ieee = mac->ieee; |
| 165 | unsigned long flags; |
| 166 | s32 in_rate = data->bitrate.value; |
| 167 | u8 rate; |
| 168 | int is_ofdm = 0; |
| 169 | int err = -EINVAL; |
| 170 | |
| 171 | if (in_rate == -1) { |
Larry Finger | bb52a65 | 2007-02-13 18:58:03 -0600 | [diff] [blame] | 172 | if (ieee->modulation & IEEE80211_OFDM_MODULATION) |
| 173 | in_rate = 24000000; |
David Woodhouse | 2638fed | 2006-03-23 22:43:38 +0000 | [diff] [blame] | 174 | else |
Larry Finger | bb52a65 | 2007-02-13 18:58:03 -0600 | [diff] [blame] | 175 | in_rate = 11000000; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | switch (in_rate) { |
| 179 | case 1000000: |
| 180 | rate = IEEE80211_CCK_RATE_1MB; |
| 181 | break; |
| 182 | case 2000000: |
| 183 | rate = IEEE80211_CCK_RATE_2MB; |
| 184 | break; |
| 185 | case 5500000: |
| 186 | rate = IEEE80211_CCK_RATE_5MB; |
| 187 | break; |
| 188 | case 11000000: |
| 189 | rate = IEEE80211_CCK_RATE_11MB; |
| 190 | break; |
| 191 | case 6000000: |
| 192 | rate = IEEE80211_OFDM_RATE_6MB; |
| 193 | is_ofdm = 1; |
| 194 | break; |
| 195 | case 9000000: |
| 196 | rate = IEEE80211_OFDM_RATE_9MB; |
| 197 | is_ofdm = 1; |
| 198 | break; |
| 199 | case 12000000: |
| 200 | rate = IEEE80211_OFDM_RATE_12MB; |
| 201 | is_ofdm = 1; |
| 202 | break; |
| 203 | case 18000000: |
| 204 | rate = IEEE80211_OFDM_RATE_18MB; |
| 205 | is_ofdm = 1; |
| 206 | break; |
| 207 | case 24000000: |
| 208 | rate = IEEE80211_OFDM_RATE_24MB; |
| 209 | is_ofdm = 1; |
| 210 | break; |
| 211 | case 36000000: |
| 212 | rate = IEEE80211_OFDM_RATE_36MB; |
| 213 | is_ofdm = 1; |
| 214 | break; |
| 215 | case 48000000: |
| 216 | rate = IEEE80211_OFDM_RATE_48MB; |
| 217 | is_ofdm = 1; |
| 218 | break; |
| 219 | case 54000000: |
| 220 | rate = IEEE80211_OFDM_RATE_54MB; |
| 221 | is_ofdm = 1; |
| 222 | break; |
| 223 | default: |
| 224 | goto out; |
| 225 | } |
| 226 | |
| 227 | spin_lock_irqsave(&mac->lock, flags); |
| 228 | |
| 229 | /* Check if correct modulation for this PHY. */ |
| 230 | if (is_ofdm && !(ieee->modulation & IEEE80211_OFDM_MODULATION)) |
| 231 | goto out_unlock; |
| 232 | |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 233 | mac->txrates.user_rate = rate; |
| 234 | ieee80211softmac_recalc_txrates(mac); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 235 | err = 0; |
| 236 | |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 237 | out_unlock: |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 238 | spin_unlock_irqrestore(&mac->lock, flags); |
| 239 | out: |
| 240 | return err; |
| 241 | } |
| 242 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_rate); |
| 243 | |
| 244 | int |
| 245 | ieee80211softmac_wx_get_rate(struct net_device *net_dev, |
| 246 | struct iw_request_info *info, |
| 247 | union iwreq_data *data, |
| 248 | char *extra) |
| 249 | { |
| 250 | struct ieee80211softmac_device *mac = ieee80211_priv(net_dev); |
| 251 | unsigned long flags; |
| 252 | int err = -EINVAL; |
| 253 | |
| 254 | spin_lock_irqsave(&mac->lock, flags); |
John W. Linville | 6bbdce5 | 2007-01-02 21:22:05 -0500 | [diff] [blame] | 255 | |
| 256 | if (unlikely(!mac->running)) { |
| 257 | err = -ENODEV; |
| 258 | goto out_unlock; |
| 259 | } |
| 260 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 261 | switch (mac->txrates.default_rate) { |
| 262 | case IEEE80211_CCK_RATE_1MB: |
| 263 | data->bitrate.value = 1000000; |
| 264 | break; |
| 265 | case IEEE80211_CCK_RATE_2MB: |
| 266 | data->bitrate.value = 2000000; |
| 267 | break; |
| 268 | case IEEE80211_CCK_RATE_5MB: |
| 269 | data->bitrate.value = 5500000; |
| 270 | break; |
| 271 | case IEEE80211_CCK_RATE_11MB: |
| 272 | data->bitrate.value = 11000000; |
| 273 | break; |
| 274 | case IEEE80211_OFDM_RATE_6MB: |
| 275 | data->bitrate.value = 6000000; |
| 276 | break; |
| 277 | case IEEE80211_OFDM_RATE_9MB: |
| 278 | data->bitrate.value = 9000000; |
| 279 | break; |
| 280 | case IEEE80211_OFDM_RATE_12MB: |
| 281 | data->bitrate.value = 12000000; |
| 282 | break; |
| 283 | case IEEE80211_OFDM_RATE_18MB: |
| 284 | data->bitrate.value = 18000000; |
| 285 | break; |
| 286 | case IEEE80211_OFDM_RATE_24MB: |
| 287 | data->bitrate.value = 24000000; |
| 288 | break; |
| 289 | case IEEE80211_OFDM_RATE_36MB: |
| 290 | data->bitrate.value = 36000000; |
| 291 | break; |
| 292 | case IEEE80211_OFDM_RATE_48MB: |
| 293 | data->bitrate.value = 48000000; |
| 294 | break; |
| 295 | case IEEE80211_OFDM_RATE_54MB: |
| 296 | data->bitrate.value = 54000000; |
| 297 | break; |
| 298 | default: |
| 299 | assert(0); |
| 300 | goto out_unlock; |
| 301 | } |
| 302 | err = 0; |
| 303 | out_unlock: |
| 304 | spin_unlock_irqrestore(&mac->lock, flags); |
| 305 | |
| 306 | return err; |
| 307 | } |
| 308 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_rate); |
| 309 | |
| 310 | int |
| 311 | ieee80211softmac_wx_get_wap(struct net_device *net_dev, |
| 312 | struct iw_request_info *info, |
| 313 | union iwreq_data *data, |
| 314 | char *extra) |
| 315 | { |
| 316 | struct ieee80211softmac_device *mac = ieee80211_priv(net_dev); |
| 317 | int err = 0; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 318 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 319 | mutex_lock(&mac->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 320 | if (mac->associnfo.bssvalid) |
| 321 | memcpy(data->ap_addr.sa_data, mac->associnfo.bssid, ETH_ALEN); |
| 322 | else |
| 323 | memset(data->ap_addr.sa_data, 0xff, ETH_ALEN); |
| 324 | data->ap_addr.sa_family = ARPHRD_ETHER; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 325 | mutex_unlock(&mac->associnfo.mutex); |
| 326 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 327 | return err; |
| 328 | } |
| 329 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_wap); |
| 330 | |
| 331 | int |
| 332 | ieee80211softmac_wx_set_wap(struct net_device *net_dev, |
| 333 | struct iw_request_info *info, |
| 334 | union iwreq_data *data, |
| 335 | char *extra) |
| 336 | { |
| 337 | struct ieee80211softmac_device *mac = ieee80211_priv(net_dev); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 338 | |
| 339 | /* sanity check */ |
| 340 | if (data->ap_addr.sa_family != ARPHRD_ETHER) { |
| 341 | return -EINVAL; |
| 342 | } |
| 343 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 344 | mutex_lock(&mac->associnfo.mutex); |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 345 | if (is_broadcast_ether_addr(data->ap_addr.sa_data)) { |
| 346 | /* the bssid we have is not to be fixed any longer, |
| 347 | * and we should reassociate to the best AP. */ |
| 348 | mac->associnfo.bssfixed = 0; |
| 349 | /* force reassociation */ |
| 350 | mac->associnfo.bssvalid = 0; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 351 | if (mac->associnfo.associated) |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 352 | queue_delayed_work(mac->wq, &mac->associnfo.work, 0); |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 353 | } else if (is_zero_ether_addr(data->ap_addr.sa_data)) { |
| 354 | /* the bssid we have is no longer fixed */ |
| 355 | mac->associnfo.bssfixed = 0; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 356 | } else { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 357 | if (!memcmp(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN)) { |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 358 | if (mac->associnfo.associating || mac->associnfo.associated) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 359 | /* bssid unchanged and associated or associating - just return */ |
| 360 | goto out; |
| 361 | } |
| 362 | } else { |
| 363 | /* copy new value in data->ap_addr.sa_data to bssid */ |
| 364 | memcpy(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN); |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 365 | } |
| 366 | /* tell the other code that this bssid should be used no matter what */ |
| 367 | mac->associnfo.bssfixed = 1; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 368 | /* queue associate if new bssid or (old one again and not associated) */ |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 369 | queue_delayed_work(mac->wq, &mac->associnfo.work, 0); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 370 | } |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 371 | |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 372 | out: |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 373 | mutex_unlock(&mac->associnfo.mutex); |
| 374 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_wap); |
| 378 | |
| 379 | int |
| 380 | ieee80211softmac_wx_set_genie(struct net_device *dev, |
| 381 | struct iw_request_info *info, |
| 382 | union iwreq_data *wrqu, |
| 383 | char *extra) |
| 384 | { |
| 385 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 386 | unsigned long flags; |
| 387 | int err = 0; |
| 388 | char *buf; |
| 389 | int i; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 390 | |
| 391 | mutex_lock(&mac->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 392 | spin_lock_irqsave(&mac->lock, flags); |
| 393 | /* bleh. shouldn't be locked for that kmalloc... */ |
| 394 | |
| 395 | if (wrqu->data.length) { |
| 396 | if ((wrqu->data.length < 2) || (extra[1]+2 != wrqu->data.length)) { |
| 397 | /* this is an IE, so the length must be |
| 398 | * correct. Is it possible though that |
| 399 | * more than one IE is passed in? |
| 400 | */ |
| 401 | err = -EINVAL; |
| 402 | goto out; |
| 403 | } |
| 404 | if (mac->wpa.IEbuflen <= wrqu->data.length) { |
| 405 | buf = kmalloc(wrqu->data.length, GFP_ATOMIC); |
| 406 | if (!buf) { |
| 407 | err = -ENOMEM; |
| 408 | goto out; |
| 409 | } |
| 410 | kfree(mac->wpa.IE); |
| 411 | mac->wpa.IE = buf; |
| 412 | mac->wpa.IEbuflen = wrqu->data.length; |
| 413 | } |
| 414 | memcpy(mac->wpa.IE, extra, wrqu->data.length); |
| 415 | dprintk(KERN_INFO PFX "generic IE set to "); |
| 416 | for (i=0;i<wrqu->data.length;i++) |
Larry Finger | 7bd6b91 | 2006-06-08 09:47:42 -0500 | [diff] [blame] | 417 | dprintk("%.2x", (u8)mac->wpa.IE[i]); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 418 | dprintk("\n"); |
| 419 | mac->wpa.IElen = wrqu->data.length; |
| 420 | } else { |
| 421 | kfree(mac->wpa.IE); |
| 422 | mac->wpa.IE = NULL; |
| 423 | mac->wpa.IElen = 0; |
| 424 | mac->wpa.IEbuflen = 0; |
| 425 | } |
| 426 | |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 427 | out: |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 428 | spin_unlock_irqrestore(&mac->lock, flags); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 429 | mutex_unlock(&mac->associnfo.mutex); |
| 430 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 431 | return err; |
| 432 | } |
| 433 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_genie); |
| 434 | |
| 435 | int |
| 436 | ieee80211softmac_wx_get_genie(struct net_device *dev, |
| 437 | struct iw_request_info *info, |
| 438 | union iwreq_data *wrqu, |
| 439 | char *extra) |
| 440 | { |
| 441 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 442 | unsigned long flags; |
| 443 | int err = 0; |
| 444 | int space = wrqu->data.length; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 445 | |
| 446 | mutex_lock(&mac->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 447 | spin_lock_irqsave(&mac->lock, flags); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 448 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 449 | wrqu->data.length = 0; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 450 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 451 | if (mac->wpa.IE && mac->wpa.IElen) { |
| 452 | wrqu->data.length = mac->wpa.IElen; |
| 453 | if (mac->wpa.IElen <= space) |
| 454 | memcpy(extra, mac->wpa.IE, mac->wpa.IElen); |
| 455 | else |
| 456 | err = -E2BIG; |
| 457 | } |
| 458 | spin_unlock_irqrestore(&mac->lock, flags); |
Ulrich Kunitz | 0c234ae | 2006-12-10 18:27:01 +0100 | [diff] [blame] | 459 | mutex_unlock(&mac->associnfo.mutex); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 460 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 461 | return err; |
| 462 | } |
| 463 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_genie); |
| 464 | |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 465 | int |
| 466 | ieee80211softmac_wx_set_mlme(struct net_device *dev, |
| 467 | struct iw_request_info *info, |
| 468 | union iwreq_data *wrqu, |
| 469 | char *extra) |
| 470 | { |
| 471 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 472 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 473 | u16 reason = cpu_to_le16(mlme->reason_code); |
| 474 | struct ieee80211softmac_network *net; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 475 | int err = -EINVAL; |
| 476 | |
| 477 | mutex_lock(&mac->associnfo.mutex); |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 478 | |
| 479 | if (memcmp(mac->associnfo.bssid, mlme->addr.sa_data, ETH_ALEN)) { |
| 480 | printk(KERN_DEBUG PFX "wx_set_mlme: requested operation on net we don't use\n"); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 481 | goto out; |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | switch (mlme->cmd) { |
| 485 | case IW_MLME_DEAUTH: |
| 486 | net = ieee80211softmac_get_network_by_bssid_locked(mac, mlme->addr.sa_data); |
| 487 | if (!net) { |
| 488 | printk(KERN_DEBUG PFX "wx_set_mlme: we should know the net here...\n"); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 489 | goto out; |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 490 | } |
Maxime Austruy | cc8ce99 | 2006-12-03 10:40:01 -0600 | [diff] [blame] | 491 | err = ieee80211softmac_deauth_req(mac, net, reason); |
| 492 | goto out; |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 493 | case IW_MLME_DISASSOC: |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 494 | ieee80211softmac_send_disassoc_req(mac, reason); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 495 | mac->associnfo.associated = 0; |
| 496 | mac->associnfo.associating = 0; |
| 497 | err = 0; |
| 498 | goto out; |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 499 | default: |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 500 | err = -EOPNOTSUPP; |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 501 | } |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 502 | |
| 503 | out: |
| 504 | mutex_unlock(&mac->associnfo.mutex); |
| 505 | |
| 506 | return err; |
Johannes Berg | 9a1771e | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 507 | } |
| 508 | EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_mlme); |