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