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