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 | 3be61a3 | 2010-07-22 13:59:15 +0200 | [diff] [blame] | 250 | if (wdev->wext.keys) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 251 | wdev->wext.keys->def = wdev->wext.default_key; |
Johannes Berg | 3be61a3 | 2010-07-22 13:59:15 +0200 | [diff] [blame] | 252 | wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; |
| 253 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 254 | |
| 255 | wdev->wext.ibss.privacy = wdev->wext.default_key != -1; |
| 256 | |
| 257 | if (wdev->wext.keys) { |
| 258 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); |
| 259 | if (!ck) |
| 260 | return -ENOMEM; |
| 261 | for (i = 0; i < 6; i++) |
| 262 | ck->params[i].key = ck->data[i]; |
| 263 | } |
| 264 | err = __cfg80211_join_ibss(rdev, wdev->netdev, |
| 265 | &wdev->wext.ibss, ck); |
| 266 | if (err) |
| 267 | kfree(ck); |
| 268 | |
| 269 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | int cfg80211_ibss_wext_siwfreq(struct net_device *dev, |
| 273 | struct iw_request_info *info, |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 274 | struct iw_freq *wextfreq, char *extra) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 275 | { |
| 276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 277 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 278 | struct ieee80211_channel *chan = NULL; |
| 279 | int err, freq; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 280 | |
| 281 | /* call only for ibss! */ |
| 282 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 283 | return -EINVAL; |
| 284 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 285 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 286 | return -EOPNOTSUPP; |
| 287 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 288 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); |
| 289 | if (freq < 0) |
| 290 | return freq; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 291 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 292 | if (freq) { |
| 293 | chan = ieee80211_get_channel(wdev->wiphy, freq); |
| 294 | if (!chan) |
| 295 | return -EINVAL; |
| 296 | if (chan->flags & IEEE80211_CHAN_NO_IBSS || |
| 297 | chan->flags & IEEE80211_CHAN_DISABLED) |
| 298 | return -EINVAL; |
| 299 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 300 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 301 | if (wdev->wext.ibss.channel == chan) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 302 | return 0; |
| 303 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 304 | wdev_lock(wdev); |
| 305 | err = 0; |
| 306 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 307 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 308 | wdev_unlock(wdev); |
| 309 | |
| 310 | if (err) |
| 311 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 312 | |
| 313 | if (chan) { |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 314 | wdev->wext.ibss.channel = chan; |
| 315 | wdev->wext.ibss.channel_fixed = true; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 316 | } else { |
| 317 | /* cfg80211_ibss_wext_join will pick one if needed */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 318 | wdev->wext.ibss.channel_fixed = false; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 321 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 322 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 323 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 324 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 325 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 326 | |
| 327 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 328 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 329 | |
| 330 | int cfg80211_ibss_wext_giwfreq(struct net_device *dev, |
| 331 | struct iw_request_info *info, |
| 332 | struct iw_freq *freq, char *extra) |
| 333 | { |
| 334 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 335 | struct ieee80211_channel *chan = NULL; |
| 336 | |
| 337 | /* call only for ibss! */ |
| 338 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 339 | return -EINVAL; |
| 340 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 341 | wdev_lock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 342 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 343 | chan = wdev->current_bss->pub.channel; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 344 | else if (wdev->wext.ibss.channel) |
| 345 | chan = wdev->wext.ibss.channel; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 346 | wdev_unlock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 347 | |
| 348 | if (chan) { |
| 349 | freq->m = chan->center_freq; |
| 350 | freq->e = 6; |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /* no channel if not joining */ |
| 355 | return -EINVAL; |
| 356 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 357 | |
| 358 | int cfg80211_ibss_wext_siwessid(struct net_device *dev, |
| 359 | struct iw_request_info *info, |
| 360 | struct iw_point *data, char *ssid) |
| 361 | { |
| 362 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 363 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 364 | size_t len = data->length; |
| 365 | int err; |
| 366 | |
| 367 | /* call only for ibss! */ |
| 368 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 369 | return -EINVAL; |
| 370 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 371 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 372 | return -EOPNOTSUPP; |
| 373 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 374 | wdev_lock(wdev); |
| 375 | err = 0; |
| 376 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 377 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 378 | wdev_unlock(wdev); |
| 379 | |
| 380 | if (err) |
| 381 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 382 | |
| 383 | /* iwconfig uses nul termination in SSID.. */ |
| 384 | if (len > 0 && ssid[len - 1] == '\0') |
| 385 | len--; |
| 386 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 387 | wdev->wext.ibss.ssid = wdev->ssid; |
| 388 | memcpy(wdev->wext.ibss.ssid, ssid, len); |
| 389 | wdev->wext.ibss.ssid_len = len; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 390 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 391 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 392 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 393 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 394 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 395 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 396 | |
| 397 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 398 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 399 | |
| 400 | int cfg80211_ibss_wext_giwessid(struct net_device *dev, |
| 401 | struct iw_request_info *info, |
| 402 | struct iw_point *data, char *ssid) |
| 403 | { |
| 404 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 405 | |
| 406 | /* call only for ibss! */ |
| 407 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | data->flags = 0; |
| 411 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 412 | wdev_lock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 413 | if (wdev->ssid_len) { |
| 414 | data->flags = 1; |
| 415 | data->length = wdev->ssid_len; |
| 416 | memcpy(ssid, wdev->ssid, data->length); |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 417 | } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 418 | data->flags = 1; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 419 | data->length = wdev->wext.ibss.ssid_len; |
| 420 | memcpy(ssid, wdev->wext.ibss.ssid, data->length); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 421 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 422 | wdev_unlock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 423 | |
| 424 | return 0; |
| 425 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 426 | |
| 427 | int cfg80211_ibss_wext_siwap(struct net_device *dev, |
| 428 | struct iw_request_info *info, |
| 429 | struct sockaddr *ap_addr, char *extra) |
| 430 | { |
| 431 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 432 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 433 | u8 *bssid = ap_addr->sa_data; |
| 434 | int err; |
| 435 | |
| 436 | /* call only for ibss! */ |
| 437 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 438 | return -EINVAL; |
| 439 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 440 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 441 | return -EOPNOTSUPP; |
| 442 | |
| 443 | if (ap_addr->sa_family != ARPHRD_ETHER) |
| 444 | return -EINVAL; |
| 445 | |
| 446 | /* automatic mode */ |
| 447 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) |
| 448 | bssid = NULL; |
| 449 | |
| 450 | /* both automatic */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 451 | if (!bssid && !wdev->wext.ibss.bssid) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 452 | return 0; |
| 453 | |
| 454 | /* fixed already - and no change */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 455 | if (wdev->wext.ibss.bssid && bssid && |
| 456 | compare_ether_addr(bssid, wdev->wext.ibss.bssid) == 0) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 457 | return 0; |
| 458 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 459 | wdev_lock(wdev); |
| 460 | err = 0; |
| 461 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 462 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 463 | wdev_unlock(wdev); |
| 464 | |
| 465 | if (err) |
| 466 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 467 | |
| 468 | if (bssid) { |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 469 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
| 470 | wdev->wext.ibss.bssid = wdev->wext.bssid; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 471 | } else |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 472 | wdev->wext.ibss.bssid = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 473 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 474 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 475 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 476 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 477 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 478 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 479 | |
| 480 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 481 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 482 | |
| 483 | int cfg80211_ibss_wext_giwap(struct net_device *dev, |
| 484 | struct iw_request_info *info, |
| 485 | struct sockaddr *ap_addr, char *extra) |
| 486 | { |
| 487 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 488 | |
| 489 | /* call only for ibss! */ |
| 490 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 491 | return -EINVAL; |
| 492 | |
| 493 | ap_addr->sa_family = ARPHRD_ETHER; |
| 494 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 495 | wdev_lock(wdev); |
Johannes Berg | 7ebbe6b | 2009-07-01 21:26:48 +0200 | [diff] [blame] | 496 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 497 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 498 | else if (wdev->wext.ibss.bssid) |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 499 | memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 500 | else |
| 501 | memset(ap_addr->sa_data, 0, ETH_ALEN); |
| 502 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 503 | wdev_unlock(wdev); |
| 504 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 505 | return 0; |
| 506 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 507 | #endif |