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