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