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