Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Some IBSS support code for cfg80211. |
| 3 | * |
| 4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/etherdevice.h> |
| 8 | #include <linux/if_arp.h> |
| 9 | #include <net/cfg80211.h> |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 10 | #include "wext-compat.h" |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11 | #include "nl80211.h" |
| 12 | |
| 13 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 14 | void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15 | { |
| 16 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17 | struct cfg80211_bss *bss; |
| 18 | #ifdef CONFIG_WIRELESS_EXT |
| 19 | union iwreq_data wrqu; |
| 20 | #endif |
| 21 | |
| 22 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 23 | return; |
| 24 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 25 | if (!wdev->ssid_len) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 26 | return; |
| 27 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 28 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 29 | wdev->ssid, wdev->ssid_len, |
| 30 | WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS); |
| 31 | |
| 32 | if (WARN_ON(!bss)) |
| 33 | return; |
| 34 | |
| 35 | if (wdev->current_bss) { |
| 36 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 37 | cfg80211_put_bss(&wdev->current_bss->pub); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 40 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 41 | wdev->current_bss = bss_from_pub(bss); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 42 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 43 | cfg80211_upload_connect_keys(wdev); |
| 44 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 45 | nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, |
| 46 | GFP_KERNEL); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_WIRELESS_EXT |
| 48 | memset(&wrqu, 0, sizeof(wrqu)); |
| 49 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
| 50 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 51 | #endif |
| 52 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 53 | |
| 54 | void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp) |
| 55 | { |
| 56 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 57 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 58 | struct cfg80211_event *ev; |
| 59 | unsigned long flags; |
| 60 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 61 | CFG80211_DEV_WARN_ON(!wdev->ssid_len); |
| 62 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 63 | ev = kzalloc(sizeof(*ev), gfp); |
| 64 | if (!ev) |
| 65 | return; |
| 66 | |
| 67 | ev->type = EVENT_IBSS_JOINED; |
| 68 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
| 69 | |
| 70 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 71 | list_add_tail(&ev->list, &wdev->event_list); |
| 72 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 73 | schedule_work(&rdev->event_work); |
| 74 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 75 | EXPORT_SYMBOL(cfg80211_ibss_joined); |
| 76 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 77 | int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev, |
| 78 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 79 | struct cfg80211_ibss_params *params, |
| 80 | struct cfg80211_cached_keys *connkeys) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 81 | { |
| 82 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 83 | struct ieee80211_channel *chan; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 84 | int err; |
| 85 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 86 | ASSERT_WDEV_LOCK(wdev); |
| 87 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 88 | chan = rdev_fixed_channel(rdev, wdev); |
| 89 | if (chan && chan != params->channel) |
| 90 | return -EBUSY; |
| 91 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 92 | if (wdev->ssid_len) |
| 93 | return -EALREADY; |
| 94 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 95 | if (WARN_ON(wdev->connect_keys)) |
| 96 | kfree(wdev->connect_keys); |
| 97 | wdev->connect_keys = connkeys; |
| 98 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_WIRELESS_EXT |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 100 | wdev->wext.ibss.channel = params->channel; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 101 | #endif |
| 102 | err = rdev->ops->join_ibss(&rdev->wiphy, dev, params); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 103 | if (err) { |
| 104 | wdev->connect_keys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 105 | return err; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 106 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 107 | |
| 108 | memcpy(wdev->ssid, params->ssid, params->ssid_len); |
| 109 | wdev->ssid_len = params->ssid_len; |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 114 | int cfg80211_join_ibss(struct cfg80211_registered_device *rdev, |
| 115 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 116 | struct cfg80211_ibss_params *params, |
| 117 | struct cfg80211_cached_keys *connkeys) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 118 | { |
| 119 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 120 | int err; |
| 121 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 122 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 123 | wdev_lock(wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 124 | err = __cfg80211_join_ibss(rdev, dev, params, connkeys); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 125 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 126 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 127 | |
| 128 | return err; |
| 129 | } |
| 130 | |
| 131 | static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext) |
| 132 | { |
| 133 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 134 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 135 | int i; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 136 | |
| 137 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 138 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 139 | kfree(wdev->connect_keys); |
| 140 | wdev->connect_keys = NULL; |
| 141 | |
| 142 | /* |
| 143 | * Delete all the keys ... pairwise keys can't really |
| 144 | * exist any more anyway, but default keys might. |
| 145 | */ |
| 146 | if (rdev->ops->del_key) |
| 147 | for (i = 0; i < 6; i++) |
| 148 | rdev->ops->del_key(wdev->wiphy, dev, i, NULL); |
| 149 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 150 | if (wdev->current_bss) { |
| 151 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 152 | cfg80211_put_bss(&wdev->current_bss->pub); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | wdev->current_bss = NULL; |
| 156 | wdev->ssid_len = 0; |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 157 | #ifdef CONFIG_WIRELESS_EXT |
| 158 | if (!nowext) |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 159 | wdev->wext.ibss.ssid_len = 0; |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 160 | #endif |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 163 | void cfg80211_clear_ibss(struct net_device *dev, bool nowext) |
| 164 | { |
| 165 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 166 | |
| 167 | wdev_lock(wdev); |
| 168 | __cfg80211_clear_ibss(dev, nowext); |
| 169 | wdev_unlock(wdev); |
| 170 | } |
| 171 | |
| 172 | static int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, |
| 173 | struct net_device *dev, bool nowext) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 174 | { |
Johannes Berg | 7848547 | 2009-07-07 03:56:05 +0200 | [diff] [blame] | 175 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 176 | int err; |
| 177 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 178 | ASSERT_WDEV_LOCK(wdev); |
| 179 | |
Johannes Berg | 7848547 | 2009-07-07 03:56:05 +0200 | [diff] [blame] | 180 | if (!wdev->ssid_len) |
| 181 | return -ENOLINK; |
| 182 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 183 | err = rdev->ops->leave_ibss(&rdev->wiphy, dev); |
| 184 | |
| 185 | if (err) |
| 186 | return err; |
| 187 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 188 | __cfg80211_clear_ibss(dev, nowext); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 193 | int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, |
| 194 | struct net_device *dev, bool nowext) |
| 195 | { |
| 196 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 197 | int err; |
| 198 | |
| 199 | wdev_lock(wdev); |
| 200 | err = __cfg80211_leave_ibss(rdev, dev, nowext); |
| 201 | wdev_unlock(wdev); |
| 202 | |
| 203 | return err; |
| 204 | } |
| 205 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 206 | #ifdef CONFIG_WIRELESS_EXT |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 207 | int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, |
| 208 | struct wireless_dev *wdev) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 209 | { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 210 | struct cfg80211_cached_keys *ck = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 211 | enum ieee80211_band band; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 212 | int i, err; |
| 213 | |
| 214 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 215 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 216 | if (!wdev->wext.ibss.beacon_interval) |
| 217 | wdev->wext.ibss.beacon_interval = 100; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 218 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 219 | /* try to find an IBSS channel if none requested ... */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 220 | if (!wdev->wext.ibss.channel) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 221 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 222 | struct ieee80211_supported_band *sband; |
| 223 | struct ieee80211_channel *chan; |
| 224 | |
| 225 | sband = rdev->wiphy.bands[band]; |
| 226 | if (!sband) |
| 227 | continue; |
| 228 | |
| 229 | for (i = 0; i < sband->n_channels; i++) { |
| 230 | chan = &sband->channels[i]; |
| 231 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 232 | continue; |
| 233 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 234 | continue; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 235 | wdev->wext.ibss.channel = chan; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 236 | break; |
| 237 | } |
| 238 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 239 | if (wdev->wext.ibss.channel) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 240 | break; |
| 241 | } |
| 242 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 243 | if (!wdev->wext.ibss.channel) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 244 | return -EINVAL; |
| 245 | } |
| 246 | |
| 247 | /* don't join -- SSID is not there */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 248 | if (!wdev->wext.ibss.ssid_len) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 249 | return 0; |
| 250 | |
| 251 | if (!netif_running(wdev->netdev)) |
| 252 | return 0; |
| 253 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 254 | if (wdev->wext.keys) |
| 255 | wdev->wext.keys->def = wdev->wext.default_key; |
| 256 | |
| 257 | wdev->wext.ibss.privacy = wdev->wext.default_key != -1; |
| 258 | |
| 259 | if (wdev->wext.keys) { |
| 260 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); |
| 261 | if (!ck) |
| 262 | return -ENOMEM; |
| 263 | for (i = 0; i < 6; i++) |
| 264 | ck->params[i].key = ck->data[i]; |
| 265 | } |
| 266 | err = __cfg80211_join_ibss(rdev, wdev->netdev, |
| 267 | &wdev->wext.ibss, ck); |
| 268 | if (err) |
| 269 | kfree(ck); |
| 270 | |
| 271 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | int cfg80211_ibss_wext_siwfreq(struct net_device *dev, |
| 275 | struct iw_request_info *info, |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 276 | struct iw_freq *wextfreq, char *extra) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 277 | { |
| 278 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 279 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 280 | struct ieee80211_channel *chan = NULL; |
| 281 | int err, freq; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 282 | |
| 283 | /* call only for ibss! */ |
| 284 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 285 | return -EINVAL; |
| 286 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 287 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | return -EOPNOTSUPP; |
| 289 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 290 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); |
| 291 | if (freq < 0) |
| 292 | return freq; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 293 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 294 | if (freq) { |
| 295 | chan = ieee80211_get_channel(wdev->wiphy, freq); |
| 296 | if (!chan) |
| 297 | return -EINVAL; |
| 298 | if (chan->flags & IEEE80211_CHAN_NO_IBSS || |
| 299 | chan->flags & IEEE80211_CHAN_DISABLED) |
| 300 | return -EINVAL; |
| 301 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 302 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 303 | if (wdev->wext.ibss.channel == chan) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 304 | return 0; |
| 305 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 306 | wdev_lock(wdev); |
| 307 | err = 0; |
| 308 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 309 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 310 | wdev_unlock(wdev); |
| 311 | |
| 312 | if (err) |
| 313 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 314 | |
| 315 | if (chan) { |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 316 | wdev->wext.ibss.channel = chan; |
| 317 | wdev->wext.ibss.channel_fixed = true; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 318 | } else { |
| 319 | /* cfg80211_ibss_wext_join will pick one if needed */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 320 | wdev->wext.ibss.channel_fixed = false; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 323 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 324 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 325 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 326 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 327 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 328 | |
| 329 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 330 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 331 | |
| 332 | int cfg80211_ibss_wext_giwfreq(struct net_device *dev, |
| 333 | struct iw_request_info *info, |
| 334 | struct iw_freq *freq, char *extra) |
| 335 | { |
| 336 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 337 | struct ieee80211_channel *chan = NULL; |
| 338 | |
| 339 | /* call only for ibss! */ |
| 340 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 341 | return -EINVAL; |
| 342 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 343 | wdev_lock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 344 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 345 | chan = wdev->current_bss->pub.channel; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 346 | else if (wdev->wext.ibss.channel) |
| 347 | chan = wdev->wext.ibss.channel; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 348 | wdev_unlock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 349 | |
| 350 | if (chan) { |
| 351 | freq->m = chan->center_freq; |
| 352 | freq->e = 6; |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | /* no channel if not joining */ |
| 357 | return -EINVAL; |
| 358 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 359 | |
| 360 | int cfg80211_ibss_wext_siwessid(struct net_device *dev, |
| 361 | struct iw_request_info *info, |
| 362 | struct iw_point *data, char *ssid) |
| 363 | { |
| 364 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 365 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 366 | size_t len = data->length; |
| 367 | int err; |
| 368 | |
| 369 | /* call only for ibss! */ |
| 370 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 371 | return -EINVAL; |
| 372 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 373 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 374 | return -EOPNOTSUPP; |
| 375 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 376 | wdev_lock(wdev); |
| 377 | err = 0; |
| 378 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 379 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 380 | wdev_unlock(wdev); |
| 381 | |
| 382 | if (err) |
| 383 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 384 | |
| 385 | /* iwconfig uses nul termination in SSID.. */ |
| 386 | if (len > 0 && ssid[len - 1] == '\0') |
| 387 | len--; |
| 388 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 389 | wdev->wext.ibss.ssid = wdev->ssid; |
| 390 | memcpy(wdev->wext.ibss.ssid, ssid, len); |
| 391 | wdev->wext.ibss.ssid_len = len; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 392 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 393 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 394 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 395 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 396 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 397 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 398 | |
| 399 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 400 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 401 | |
| 402 | int cfg80211_ibss_wext_giwessid(struct net_device *dev, |
| 403 | struct iw_request_info *info, |
| 404 | struct iw_point *data, char *ssid) |
| 405 | { |
| 406 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 407 | |
| 408 | /* call only for ibss! */ |
| 409 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 410 | return -EINVAL; |
| 411 | |
| 412 | data->flags = 0; |
| 413 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 414 | wdev_lock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 415 | if (wdev->ssid_len) { |
| 416 | data->flags = 1; |
| 417 | data->length = wdev->ssid_len; |
| 418 | memcpy(ssid, wdev->ssid, data->length); |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 419 | } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 420 | data->flags = 1; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 421 | data->length = wdev->wext.ibss.ssid_len; |
| 422 | memcpy(ssid, wdev->wext.ibss.ssid, data->length); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 423 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 424 | wdev_unlock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 425 | |
| 426 | return 0; |
| 427 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 428 | |
| 429 | int cfg80211_ibss_wext_siwap(struct net_device *dev, |
| 430 | struct iw_request_info *info, |
| 431 | struct sockaddr *ap_addr, char *extra) |
| 432 | { |
| 433 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 434 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 435 | u8 *bssid = ap_addr->sa_data; |
| 436 | int err; |
| 437 | |
| 438 | /* call only for ibss! */ |
| 439 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 440 | return -EINVAL; |
| 441 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 442 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 443 | return -EOPNOTSUPP; |
| 444 | |
| 445 | if (ap_addr->sa_family != ARPHRD_ETHER) |
| 446 | return -EINVAL; |
| 447 | |
| 448 | /* automatic mode */ |
| 449 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) |
| 450 | bssid = NULL; |
| 451 | |
| 452 | /* both automatic */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 453 | if (!bssid && !wdev->wext.ibss.bssid) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 454 | return 0; |
| 455 | |
| 456 | /* fixed already - and no change */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 457 | if (wdev->wext.ibss.bssid && bssid && |
| 458 | compare_ether_addr(bssid, wdev->wext.ibss.bssid) == 0) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 459 | return 0; |
| 460 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 461 | wdev_lock(wdev); |
| 462 | err = 0; |
| 463 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 464 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 465 | wdev_unlock(wdev); |
| 466 | |
| 467 | if (err) |
| 468 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 469 | |
| 470 | if (bssid) { |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 471 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
| 472 | wdev->wext.ibss.bssid = wdev->wext.bssid; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 473 | } else |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 474 | wdev->wext.ibss.bssid = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 475 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 476 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 477 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 478 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 479 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 480 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 481 | |
| 482 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 483 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 484 | |
| 485 | int cfg80211_ibss_wext_giwap(struct net_device *dev, |
| 486 | struct iw_request_info *info, |
| 487 | struct sockaddr *ap_addr, char *extra) |
| 488 | { |
| 489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 490 | |
| 491 | /* call only for ibss! */ |
| 492 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 493 | return -EINVAL; |
| 494 | |
| 495 | ap_addr->sa_family = ARPHRD_ETHER; |
| 496 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 497 | wdev_lock(wdev); |
Johannes Berg | 7ebbe6b | 2009-07-01 21:26:48 +0200 | [diff] [blame] | 498 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 499 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 500 | else if (wdev->wext.ibss.bssid) |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 501 | memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 502 | else |
| 503 | memset(ap_addr->sa_data, 0, ETH_ALEN); |
| 504 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 505 | wdev_unlock(wdev); |
| 506 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 507 | return 0; |
| 508 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 509 | #endif |