Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1 | /* |
| 2 | * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211 |
| 3 | * Copyright (c) 2008, Jouni Malinen <j@w1.fi> |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 4 | * Copyright (c) 2011, Javier Lopez <jlopex@gmail.com> |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 5 | * Copyright (c) 2016 - 2017 Intel Deutschland GmbH |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 6 | * Copyright (C) 2018 Intel Corporation |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * TODO: |
Johannes Berg | 2b2d779 | 2010-08-17 12:08:07 +0200 | [diff] [blame] | 15 | * - Add TSF sync and fix IBSS beacon transmission by adding |
| 16 | * competition for "air time" at TBTT |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 17 | * - RX filtering based on filter configuration (data->rx_filter) |
| 18 | */ |
| 19 | |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 20 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 22 | #include <linux/spinlock.h> |
Johannes Berg | 90e3012 | 2009-06-18 14:51:12 +0200 | [diff] [blame] | 23 | #include <net/dst.h> |
| 24 | #include <net/xfrm.h> |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 25 | #include <net/mac80211.h> |
| 26 | #include <net/ieee80211_radiotap.h> |
| 27 | #include <linux/if_arp.h> |
| 28 | #include <linux/rtnetlink.h> |
| 29 | #include <linux/etherdevice.h> |
Martin Pitt | 9ea92774 | 2013-04-08 11:30:01 +0200 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 33 | #include <linux/ktime.h> |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 34 | #include <net/genetlink.h> |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 35 | #include <net/net_namespace.h> |
| 36 | #include <net/netns/generic.h> |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 37 | #include <linux/rhashtable.h> |
Jinbum Park | 3a2af7c | 2018-07-31 23:10:40 +0900 | [diff] [blame] | 38 | #include <linux/nospec.h> |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 39 | #include "mac80211_hwsim.h" |
| 40 | |
| 41 | #define WARN_QUEUE 100 |
| 42 | #define MAX_QUEUE 200 |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 43 | |
| 44 | MODULE_AUTHOR("Jouni Malinen"); |
| 45 | MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211"); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | |
| 48 | static int radios = 2; |
| 49 | module_param(radios, int, 0444); |
| 50 | MODULE_PARM_DESC(radios, "Number of simulated radios"); |
| 51 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 52 | static int channels = 1; |
| 53 | module_param(channels, int, 0444); |
| 54 | MODULE_PARM_DESC(channels, "Number of concurrent channels"); |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 55 | |
Johannes Berg | a357d7f | 2012-12-10 11:57:42 +0100 | [diff] [blame] | 56 | static bool paged_rx = false; |
| 57 | module_param(paged_rx, bool, 0644); |
| 58 | MODULE_PARM_DESC(paged_rx, "Use paged SKBs for RX instead of linear ones"); |
| 59 | |
Karl Beldan | 1eb3217 | 2013-04-19 14:44:52 +0200 | [diff] [blame] | 60 | static bool rctbl = false; |
| 61 | module_param(rctbl, bool, 0444); |
| 62 | MODULE_PARM_DESC(rctbl, "Handle rate control table"); |
| 63 | |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 64 | static bool support_p2p_device = true; |
| 65 | module_param(support_p2p_device, bool, 0444); |
| 66 | MODULE_PARM_DESC(support_p2p_device, "Support P2P-Device interface type"); |
| 67 | |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 68 | /** |
| 69 | * enum hwsim_regtest - the type of regulatory tests we offer |
| 70 | * |
| 71 | * These are the different values you can use for the regtest |
| 72 | * module parameter. This is useful to help test world roaming |
| 73 | * and the driver regulatory_hint() call and combinations of these. |
| 74 | * If you want to do specific alpha2 regulatory domain tests simply |
| 75 | * use the userspace regulatory request as that will be respected as |
| 76 | * well without the need of this module parameter. This is designed |
| 77 | * only for testing the driver regulatory request, world roaming |
| 78 | * and all possible combinations. |
| 79 | * |
| 80 | * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed, |
| 81 | * this is the default value. |
| 82 | * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory |
| 83 | * hint, only one driver regulatory hint will be sent as such the |
| 84 | * secondary radios are expected to follow. |
| 85 | * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory |
| 86 | * request with all radios reporting the same regulatory domain. |
| 87 | * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling |
| 88 | * different regulatory domains requests. Expected behaviour is for |
| 89 | * an intersection to occur but each device will still use their |
| 90 | * respective regulatory requested domains. Subsequent radios will |
| 91 | * use the resulting intersection. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 92 | * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We accomplish |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 93 | * this by using a custom beacon-capable regulatory domain for the first |
| 94 | * radio. All other device world roam. |
| 95 | * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory |
| 96 | * domain requests. All radios will adhere to this custom world regulatory |
| 97 | * domain. |
| 98 | * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory |
| 99 | * domain requests. The first radio will adhere to the first custom world |
| 100 | * regulatory domain, the second one to the second custom world regulatory |
| 101 | * domain. All other devices will world roam. |
| 102 | * @HWSIM_REGTEST_STRICT_FOLLOW_: Used for testing strict regulatory domain |
| 103 | * settings, only the first radio will send a regulatory domain request |
| 104 | * and use strict settings. The rest of the radios are expected to follow. |
| 105 | * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain |
| 106 | * settings. All radios will adhere to this. |
| 107 | * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory |
| 108 | * domain settings, combined with secondary driver regulatory domain |
| 109 | * settings. The first radio will get a strict regulatory domain setting |
| 110 | * using the first driver regulatory request and the second radio will use |
| 111 | * non-strict settings using the second driver regulatory request. All |
| 112 | * other devices should follow the intersection created between the |
| 113 | * first two. |
| 114 | * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need |
| 115 | * at least 6 radios for a complete test. We will test in this order: |
| 116 | * 1 - driver custom world regulatory domain |
| 117 | * 2 - second custom world regulatory domain |
| 118 | * 3 - first driver regulatory domain request |
| 119 | * 4 - second driver regulatory domain request |
| 120 | * 5 - strict regulatory domain settings using the third driver regulatory |
| 121 | * domain request |
| 122 | * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio |
| 123 | * regulatory requests. |
| 124 | */ |
| 125 | enum hwsim_regtest { |
| 126 | HWSIM_REGTEST_DISABLED = 0, |
| 127 | HWSIM_REGTEST_DRIVER_REG_FOLLOW = 1, |
| 128 | HWSIM_REGTEST_DRIVER_REG_ALL = 2, |
| 129 | HWSIM_REGTEST_DIFF_COUNTRY = 3, |
| 130 | HWSIM_REGTEST_WORLD_ROAM = 4, |
| 131 | HWSIM_REGTEST_CUSTOM_WORLD = 5, |
| 132 | HWSIM_REGTEST_CUSTOM_WORLD_2 = 6, |
| 133 | HWSIM_REGTEST_STRICT_FOLLOW = 7, |
| 134 | HWSIM_REGTEST_STRICT_ALL = 8, |
| 135 | HWSIM_REGTEST_STRICT_AND_DRIVER_REG = 9, |
| 136 | HWSIM_REGTEST_ALL = 10, |
| 137 | }; |
| 138 | |
| 139 | /* Set to one of the HWSIM_REGTEST_* values above */ |
| 140 | static int regtest = HWSIM_REGTEST_DISABLED; |
| 141 | module_param(regtest, int, 0444); |
| 142 | MODULE_PARM_DESC(regtest, "The type of regulatory test we want to run"); |
| 143 | |
| 144 | static const char *hwsim_alpha2s[] = { |
| 145 | "FI", |
| 146 | "AL", |
| 147 | "US", |
| 148 | "DE", |
| 149 | "JP", |
| 150 | "AL", |
| 151 | }; |
| 152 | |
| 153 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_01 = { |
| 154 | .n_reg_rules = 4, |
| 155 | .alpha2 = "99", |
| 156 | .reg_rules = { |
| 157 | REG_RULE(2412-10, 2462+10, 40, 0, 20, 0), |
| 158 | REG_RULE(2484-10, 2484+10, 40, 0, 20, 0), |
| 159 | REG_RULE(5150-10, 5240+10, 40, 0, 30, 0), |
| 160 | REG_RULE(5745-10, 5825+10, 40, 0, 30, 0), |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = { |
| 165 | .n_reg_rules = 2, |
| 166 | .alpha2 = "99", |
| 167 | .reg_rules = { |
| 168 | REG_RULE(2412-10, 2462+10, 40, 0, 20, 0), |
| 169 | REG_RULE(5725-10, 5850+10, 40, 0, 30, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 170 | NL80211_RRF_NO_IR), |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 171 | } |
| 172 | }; |
| 173 | |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 174 | static const struct ieee80211_regdomain *hwsim_world_regdom_custom[] = { |
| 175 | &hwsim_world_regdom_custom_01, |
| 176 | &hwsim_world_regdom_custom_02, |
| 177 | }; |
| 178 | |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 179 | struct hwsim_vif_priv { |
| 180 | u32 magic; |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 181 | u8 bssid[ETH_ALEN]; |
| 182 | bool assoc; |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 183 | bool bcn_en; |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 184 | u16 aid; |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | #define HWSIM_VIF_MAGIC 0x69537748 |
| 188 | |
| 189 | static inline void hwsim_check_magic(struct ieee80211_vif *vif) |
| 190 | { |
| 191 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 192 | WARN(vp->magic != HWSIM_VIF_MAGIC, |
| 193 | "Invalid VIF (%p) magic %#x, %pM, %d/%d\n", |
| 194 | vif, vp->magic, vif->addr, vif->type, vif->p2p); |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static inline void hwsim_set_magic(struct ieee80211_vif *vif) |
| 198 | { |
| 199 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
| 200 | vp->magic = HWSIM_VIF_MAGIC; |
| 201 | } |
| 202 | |
| 203 | static inline void hwsim_clear_magic(struct ieee80211_vif *vif) |
| 204 | { |
| 205 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
| 206 | vp->magic = 0; |
| 207 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 208 | |
Johannes Berg | 81c0652 | 2008-09-11 02:17:01 +0200 | [diff] [blame] | 209 | struct hwsim_sta_priv { |
| 210 | u32 magic; |
| 211 | }; |
| 212 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 213 | #define HWSIM_STA_MAGIC 0x6d537749 |
Johannes Berg | 81c0652 | 2008-09-11 02:17:01 +0200 | [diff] [blame] | 214 | |
| 215 | static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta) |
| 216 | { |
| 217 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; |
Rami Rosen | 5d6924e | 2008-10-08 11:18:27 +0200 | [diff] [blame] | 218 | WARN_ON(sp->magic != HWSIM_STA_MAGIC); |
Johannes Berg | 81c0652 | 2008-09-11 02:17:01 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta) |
| 222 | { |
| 223 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; |
Rami Rosen | 5d6924e | 2008-10-08 11:18:27 +0200 | [diff] [blame] | 224 | sp->magic = HWSIM_STA_MAGIC; |
Johannes Berg | 81c0652 | 2008-09-11 02:17:01 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta) |
| 228 | { |
| 229 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; |
| 230 | sp->magic = 0; |
| 231 | } |
| 232 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 233 | struct hwsim_chanctx_priv { |
| 234 | u32 magic; |
| 235 | }; |
| 236 | |
| 237 | #define HWSIM_CHANCTX_MAGIC 0x6d53774a |
| 238 | |
| 239 | static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf *c) |
| 240 | { |
| 241 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; |
| 242 | WARN_ON(cp->magic != HWSIM_CHANCTX_MAGIC); |
| 243 | } |
| 244 | |
| 245 | static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf *c) |
| 246 | { |
| 247 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; |
| 248 | cp->magic = HWSIM_CHANCTX_MAGIC; |
| 249 | } |
| 250 | |
| 251 | static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c) |
| 252 | { |
| 253 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; |
| 254 | cp->magic = 0; |
| 255 | } |
| 256 | |
Alexey Dobriyan | c7d03a0 | 2016-11-17 04:58:21 +0300 | [diff] [blame] | 257 | static unsigned int hwsim_net_id; |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 258 | |
Matthew Wilcox | 60a0527 | 2018-04-10 16:36:33 -0700 | [diff] [blame] | 259 | static DEFINE_IDA(hwsim_netgroup_ida); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 260 | |
| 261 | struct hwsim_net { |
| 262 | int netgroup; |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 263 | u32 wmediumd; |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | static inline int hwsim_net_get_netgroup(struct net *net) |
| 267 | { |
| 268 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); |
| 269 | |
| 270 | return hwsim_net->netgroup; |
| 271 | } |
| 272 | |
Kirill Tkhai | 0369554 | 2018-03-01 14:30:09 +0300 | [diff] [blame] | 273 | static inline int hwsim_net_set_netgroup(struct net *net) |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 274 | { |
| 275 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); |
| 276 | |
Kirill Tkhai | 0369554 | 2018-03-01 14:30:09 +0300 | [diff] [blame] | 277 | hwsim_net->netgroup = ida_simple_get(&hwsim_netgroup_ida, |
| 278 | 0, 0, GFP_KERNEL); |
| 279 | return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM; |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 282 | static inline u32 hwsim_net_get_wmediumd(struct net *net) |
| 283 | { |
| 284 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); |
| 285 | |
| 286 | return hwsim_net->wmediumd; |
| 287 | } |
| 288 | |
| 289 | static inline void hwsim_net_set_wmediumd(struct net *net, u32 portid) |
| 290 | { |
| 291 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); |
| 292 | |
| 293 | hwsim_net->wmediumd = portid; |
| 294 | } |
| 295 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 296 | static struct class *hwsim_class; |
| 297 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 298 | static struct net_device *hwsim_mon; /* global monitor netdev */ |
| 299 | |
Luis R. Rodriguez | 22cad73 | 2009-03-05 21:13:06 -0800 | [diff] [blame] | 300 | #define CHAN2G(_freq) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 301 | .band = NL80211_BAND_2GHZ, \ |
Luis R. Rodriguez | 22cad73 | 2009-03-05 21:13:06 -0800 | [diff] [blame] | 302 | .center_freq = (_freq), \ |
| 303 | .hw_value = (_freq), \ |
| 304 | .max_power = 20, \ |
| 305 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 306 | |
Luis R. Rodriguez | 22cad73 | 2009-03-05 21:13:06 -0800 | [diff] [blame] | 307 | #define CHAN5G(_freq) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 308 | .band = NL80211_BAND_5GHZ, \ |
Luis R. Rodriguez | 22cad73 | 2009-03-05 21:13:06 -0800 | [diff] [blame] | 309 | .center_freq = (_freq), \ |
| 310 | .hw_value = (_freq), \ |
| 311 | .max_power = 20, \ |
| 312 | } |
| 313 | |
| 314 | static const struct ieee80211_channel hwsim_channels_2ghz[] = { |
| 315 | CHAN2G(2412), /* Channel 1 */ |
| 316 | CHAN2G(2417), /* Channel 2 */ |
| 317 | CHAN2G(2422), /* Channel 3 */ |
| 318 | CHAN2G(2427), /* Channel 4 */ |
| 319 | CHAN2G(2432), /* Channel 5 */ |
| 320 | CHAN2G(2437), /* Channel 6 */ |
| 321 | CHAN2G(2442), /* Channel 7 */ |
| 322 | CHAN2G(2447), /* Channel 8 */ |
| 323 | CHAN2G(2452), /* Channel 9 */ |
| 324 | CHAN2G(2457), /* Channel 10 */ |
| 325 | CHAN2G(2462), /* Channel 11 */ |
| 326 | CHAN2G(2467), /* Channel 12 */ |
| 327 | CHAN2G(2472), /* Channel 13 */ |
| 328 | CHAN2G(2484), /* Channel 14 */ |
| 329 | }; |
| 330 | |
| 331 | static const struct ieee80211_channel hwsim_channels_5ghz[] = { |
| 332 | CHAN5G(5180), /* Channel 36 */ |
| 333 | CHAN5G(5200), /* Channel 40 */ |
| 334 | CHAN5G(5220), /* Channel 44 */ |
| 335 | CHAN5G(5240), /* Channel 48 */ |
| 336 | |
| 337 | CHAN5G(5260), /* Channel 52 */ |
| 338 | CHAN5G(5280), /* Channel 56 */ |
| 339 | CHAN5G(5300), /* Channel 60 */ |
| 340 | CHAN5G(5320), /* Channel 64 */ |
| 341 | |
| 342 | CHAN5G(5500), /* Channel 100 */ |
| 343 | CHAN5G(5520), /* Channel 104 */ |
| 344 | CHAN5G(5540), /* Channel 108 */ |
| 345 | CHAN5G(5560), /* Channel 112 */ |
| 346 | CHAN5G(5580), /* Channel 116 */ |
| 347 | CHAN5G(5600), /* Channel 120 */ |
| 348 | CHAN5G(5620), /* Channel 124 */ |
| 349 | CHAN5G(5640), /* Channel 128 */ |
| 350 | CHAN5G(5660), /* Channel 132 */ |
| 351 | CHAN5G(5680), /* Channel 136 */ |
| 352 | CHAN5G(5700), /* Channel 140 */ |
| 353 | |
| 354 | CHAN5G(5745), /* Channel 149 */ |
| 355 | CHAN5G(5765), /* Channel 153 */ |
| 356 | CHAN5G(5785), /* Channel 157 */ |
| 357 | CHAN5G(5805), /* Channel 161 */ |
| 358 | CHAN5G(5825), /* Channel 165 */ |
Jouni Malinen | 85bbd80 | 2017-03-06 11:56:06 +0200 | [diff] [blame] | 359 | CHAN5G(5845), /* Channel 169 */ |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | static const struct ieee80211_rate hwsim_rates[] = { |
| 363 | { .bitrate = 10 }, |
| 364 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 365 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 366 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 367 | { .bitrate = 60 }, |
| 368 | { .bitrate = 90 }, |
| 369 | { .bitrate = 120 }, |
| 370 | { .bitrate = 180 }, |
| 371 | { .bitrate = 240 }, |
| 372 | { .bitrate = 360 }, |
| 373 | { .bitrate = 480 }, |
| 374 | { .bitrate = 540 } |
| 375 | }; |
| 376 | |
Jouni Malinen | d5d011b | 2015-02-26 15:26:54 +0200 | [diff] [blame] | 377 | #define OUI_QCA 0x001374 |
| 378 | #define QCA_NL80211_SUBCMD_TEST 1 |
| 379 | enum qca_nl80211_vendor_subcmds { |
| 380 | QCA_WLAN_VENDOR_ATTR_TEST = 8, |
| 381 | QCA_WLAN_VENDOR_ATTR_MAX = QCA_WLAN_VENDOR_ATTR_TEST |
| 382 | }; |
| 383 | |
| 384 | static const struct nla_policy |
| 385 | hwsim_vendor_test_policy[QCA_WLAN_VENDOR_ATTR_MAX + 1] = { |
| 386 | [QCA_WLAN_VENDOR_ATTR_MAX] = { .type = NLA_U32 }, |
| 387 | }; |
| 388 | |
| 389 | static int mac80211_hwsim_vendor_cmd_test(struct wiphy *wiphy, |
| 390 | struct wireless_dev *wdev, |
| 391 | const void *data, int data_len) |
| 392 | { |
| 393 | struct sk_buff *skb; |
| 394 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 395 | int err; |
| 396 | u32 val; |
| 397 | |
| 398 | err = nla_parse(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, data_len, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 399 | hwsim_vendor_test_policy, NULL); |
Jouni Malinen | d5d011b | 2015-02-26 15:26:54 +0200 | [diff] [blame] | 400 | if (err) |
| 401 | return err; |
| 402 | if (!tb[QCA_WLAN_VENDOR_ATTR_TEST]) |
| 403 | return -EINVAL; |
| 404 | val = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_TEST]); |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 405 | wiphy_dbg(wiphy, "%s: test=%u\n", __func__, val); |
Jouni Malinen | d5d011b | 2015-02-26 15:26:54 +0200 | [diff] [blame] | 406 | |
| 407 | /* Send a vendor event as a test. Note that this would not normally be |
| 408 | * done within a command handler, but rather, based on some other |
| 409 | * trigger. For simplicity, this command is used to trigger the event |
| 410 | * here. |
| 411 | * |
| 412 | * event_idx = 0 (index in mac80211_hwsim_vendor_commands) |
| 413 | */ |
| 414 | skb = cfg80211_vendor_event_alloc(wiphy, wdev, 100, 0, GFP_KERNEL); |
| 415 | if (skb) { |
| 416 | /* skb_put() or nla_put() will fill up data within |
| 417 | * NL80211_ATTR_VENDOR_DATA. |
| 418 | */ |
| 419 | |
| 420 | /* Add vendor data */ |
| 421 | nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 1); |
| 422 | |
| 423 | /* Send the event - this will call nla_nest_end() */ |
| 424 | cfg80211_vendor_event(skb, GFP_KERNEL); |
| 425 | } |
| 426 | |
| 427 | /* Send a response to the command */ |
| 428 | skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, 10); |
| 429 | if (!skb) |
| 430 | return -ENOMEM; |
| 431 | |
| 432 | /* skb_put() or nla_put() will fill up data within |
| 433 | * NL80211_ATTR_VENDOR_DATA |
| 434 | */ |
| 435 | nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 2); |
| 436 | |
| 437 | return cfg80211_vendor_cmd_reply(skb); |
| 438 | } |
| 439 | |
| 440 | static struct wiphy_vendor_command mac80211_hwsim_vendor_commands[] = { |
| 441 | { |
| 442 | .info = { .vendor_id = OUI_QCA, |
| 443 | .subcmd = QCA_NL80211_SUBCMD_TEST }, |
| 444 | .flags = WIPHY_VENDOR_CMD_NEED_NETDEV, |
| 445 | .doit = mac80211_hwsim_vendor_cmd_test, |
| 446 | } |
| 447 | }; |
| 448 | |
| 449 | /* Advertise support vendor specific events */ |
| 450 | static const struct nl80211_vendor_cmd_info mac80211_hwsim_vendor_events[] = { |
| 451 | { .vendor_id = OUI_QCA, .subcmd = 1 }, |
| 452 | }; |
| 453 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 454 | static const struct ieee80211_iface_limit hwsim_if_limits[] = { |
| 455 | { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) }, |
| 456 | { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) | |
| 457 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 458 | #ifdef CONFIG_MAC80211_MESH |
| 459 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 460 | #endif |
| 461 | BIT(NL80211_IFTYPE_AP) | |
| 462 | BIT(NL80211_IFTYPE_P2P_GO) }, |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 463 | /* must be last, see hwsim_if_comb */ |
| 464 | { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) } |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 465 | }; |
| 466 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 467 | static const struct ieee80211_iface_combination hwsim_if_comb[] = { |
| 468 | { |
| 469 | .limits = hwsim_if_limits, |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 470 | /* remove the last entry which is P2P_DEVICE */ |
| 471 | .n_limits = ARRAY_SIZE(hwsim_if_limits) - 1, |
| 472 | .max_interfaces = 2048, |
| 473 | .num_different_channels = 1, |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 474 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 475 | BIT(NL80211_CHAN_WIDTH_20) | |
| 476 | BIT(NL80211_CHAN_WIDTH_40) | |
| 477 | BIT(NL80211_CHAN_WIDTH_80) | |
| 478 | BIT(NL80211_CHAN_WIDTH_160), |
Ilan Peer | f7736f5 | 2016-07-05 15:23:09 +0300 | [diff] [blame] | 479 | }, |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 480 | }; |
| 481 | |
| 482 | static const struct ieee80211_iface_combination hwsim_if_comb_p2p_dev[] = { |
| 483 | { |
| 484 | .limits = hwsim_if_limits, |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 485 | .n_limits = ARRAY_SIZE(hwsim_if_limits), |
| 486 | .max_interfaces = 2048, |
| 487 | .num_different_channels = 1, |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 488 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 489 | BIT(NL80211_CHAN_WIDTH_20) | |
| 490 | BIT(NL80211_CHAN_WIDTH_40) | |
| 491 | BIT(NL80211_CHAN_WIDTH_80) | |
| 492 | BIT(NL80211_CHAN_WIDTH_160), |
Ilan Peer | f7736f5 | 2016-07-05 15:23:09 +0300 | [diff] [blame] | 493 | }, |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 494 | }; |
| 495 | |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 496 | static spinlock_t hwsim_radio_lock; |
Johannes Berg | b59abfb | 2016-09-15 16:30:03 +0300 | [diff] [blame] | 497 | static LIST_HEAD(hwsim_radios); |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 498 | static struct rhashtable hwsim_radios_rht; |
Johannes Berg | 2d68992 | 2014-01-06 22:56:30 +0100 | [diff] [blame] | 499 | static int hwsim_radio_idx; |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 500 | static int hwsim_radios_generation = 1; |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 501 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 502 | static struct platform_driver mac80211_hwsim_driver = { |
| 503 | .driver = { |
| 504 | .name = "mac80211_hwsim", |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 505 | }, |
| 506 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 507 | |
| 508 | struct mac80211_hwsim_data { |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 509 | struct list_head list; |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 510 | struct rhash_head rht; |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 511 | struct ieee80211_hw *hw; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 512 | struct device *dev; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 513 | struct ieee80211_supported_band bands[NUM_NL80211_BANDS]; |
Luis R. Rodriguez | 22cad73 | 2009-03-05 21:13:06 -0800 | [diff] [blame] | 514 | struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)]; |
| 515 | struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)]; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 516 | struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)]; |
Johannes Berg | 38ed504 | 2014-01-06 22:11:06 +0100 | [diff] [blame] | 517 | struct ieee80211_iface_combination if_combination; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 518 | |
Johannes Berg | ef15aac | 2010-01-20 12:02:33 +0100 | [diff] [blame] | 519 | struct mac_address addresses[2]; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 520 | int channels, idx; |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 521 | bool use_chanctx; |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 522 | bool destroy_on_close; |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 523 | u32 portid; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 524 | char alpha2[2]; |
| 525 | const struct ieee80211_regdomain *regd; |
Johannes Berg | ef15aac | 2010-01-20 12:02:33 +0100 | [diff] [blame] | 526 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 527 | struct ieee80211_channel *tmp_chan; |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 528 | struct ieee80211_channel *roc_chan; |
| 529 | u32 roc_duration; |
| 530 | struct delayed_work roc_start; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 531 | struct delayed_work roc_done; |
| 532 | struct delayed_work hw_scan; |
| 533 | struct cfg80211_scan_request *hw_scan_request; |
| 534 | struct ieee80211_vif *hw_scan_vif; |
| 535 | int scan_chan_idx; |
Johannes Berg | 339467b | 2014-06-12 22:41:00 +0200 | [diff] [blame] | 536 | u8 scan_addr[ETH_ALEN]; |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 537 | struct { |
| 538 | struct ieee80211_channel *channel; |
| 539 | unsigned long next_start, start, end; |
| 540 | } survey_data[ARRAY_SIZE(hwsim_channels_2ghz) + |
| 541 | ARRAY_SIZE(hwsim_channels_5ghz)]; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 542 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 543 | struct ieee80211_channel *channel; |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 544 | u64 beacon_int /* beacon interval in us */; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 545 | unsigned int rx_filter; |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 546 | bool started, idle, scanning; |
| 547 | struct mutex mutex; |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 548 | struct tasklet_hrtimer beacon_timer; |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 549 | enum ps_mode { |
| 550 | PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL |
| 551 | } ps; |
| 552 | bool ps_poll_pending; |
| 553 | struct dentry *debugfs; |
Daniel Wagner | 73606d0 | 2009-05-18 19:49:25 +0200 | [diff] [blame] | 554 | |
Johannes Berg | 959eb2f | 2015-11-06 11:57:23 +0100 | [diff] [blame] | 555 | uintptr_t pending_cookie; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 556 | struct sk_buff_head pending; /* packets pending */ |
Daniel Wagner | 73606d0 | 2009-05-18 19:49:25 +0200 | [diff] [blame] | 557 | /* |
| 558 | * Only radios in the same group can communicate together (the |
| 559 | * channel has to match too). Each bit represents a group. A |
Ben Greear | 9ebac15 | 2014-09-25 14:22:20 -0700 | [diff] [blame] | 560 | * radio can be in more than one group. |
Daniel Wagner | 73606d0 | 2009-05-18 19:49:25 +0200 | [diff] [blame] | 561 | */ |
| 562 | u64 group; |
Blaise Gassend | bdd7bd1 | 2010-10-28 02:01:24 -0700 | [diff] [blame] | 563 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 564 | /* group shared by radios created in the same netns */ |
| 565 | int netgroup; |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 566 | /* wmediumd portid responsible for netgroup of this radio */ |
| 567 | u32 wmediumd; |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 568 | |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 569 | /* difference between this hw's clock and the real clock, in usecs */ |
Thomas Pedersen | 45034bf | 2013-01-02 14:55:16 -0800 | [diff] [blame] | 570 | s64 tsf_offset; |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 571 | s64 bcn_delta; |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 572 | /* absolute beacon transmission time. Used to cover up "tx" delay. */ |
| 573 | u64 abs_bcn_ts; |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 574 | |
| 575 | /* Stats */ |
| 576 | u64 tx_pkts; |
| 577 | u64 rx_pkts; |
| 578 | u64 tx_bytes; |
| 579 | u64 rx_bytes; |
| 580 | u64 tx_dropped; |
| 581 | u64 tx_failed; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 582 | }; |
| 583 | |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 584 | static const struct rhashtable_params hwsim_rht_params = { |
| 585 | .nelem_hint = 2, |
| 586 | .automatic_shrinking = true, |
| 587 | .key_len = ETH_ALEN, |
| 588 | .key_offset = offsetof(struct mac80211_hwsim_data, addresses[1]), |
| 589 | .head_offset = offsetof(struct mac80211_hwsim_data, rht), |
| 590 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 591 | |
| 592 | struct hwsim_radiotap_hdr { |
| 593 | struct ieee80211_radiotap_header hdr; |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 594 | __le64 rt_tsft; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 595 | u8 rt_flags; |
| 596 | u8 rt_rate; |
| 597 | __le16 rt_channel; |
| 598 | __le16 rt_chbitmask; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 599 | } __packed; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 600 | |
Jouni Malinen | 76a56eb | 2013-11-02 15:57:36 +0200 | [diff] [blame] | 601 | struct hwsim_radiotap_ack_hdr { |
| 602 | struct ieee80211_radiotap_header hdr; |
| 603 | u8 rt_flags; |
| 604 | u8 pad; |
| 605 | __le16 rt_channel; |
| 606 | __le16 rt_chbitmask; |
| 607 | } __packed; |
| 608 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 609 | /* MAC80211_HWSIM netlink family */ |
| 610 | static struct genl_family hwsim_genl_family; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 611 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 612 | enum hwsim_multicast_groups { |
| 613 | HWSIM_MCGRP_CONFIG, |
| 614 | }; |
| 615 | |
| 616 | static const struct genl_multicast_group hwsim_mcgrps[] = { |
| 617 | [HWSIM_MCGRP_CONFIG] = { .name = "config", }, |
| 618 | }; |
| 619 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 620 | /* MAC80211_HWSIM netlink policy */ |
| 621 | |
Johannes Berg | 205d242 | 2014-01-21 00:06:29 +0100 | [diff] [blame] | 622 | static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 623 | [HWSIM_ATTR_ADDR_RECEIVER] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, |
| 624 | [HWSIM_ATTR_ADDR_TRANSMITTER] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 625 | [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY, |
| 626 | .len = IEEE80211_MAX_DATA_LEN }, |
| 627 | [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 }, |
| 628 | [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 }, |
| 629 | [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 }, |
| 630 | [HWSIM_ATTR_TX_INFO] = { .type = NLA_UNSPEC, |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 631 | .len = IEEE80211_TX_MAX_RATES * |
| 632 | sizeof(struct hwsim_tx_rate)}, |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 633 | [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 }, |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 634 | [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 }, |
| 635 | [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 }, |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 636 | [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 637 | [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 }, |
| 638 | [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG }, |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 639 | [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG }, |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 640 | [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE] = { .type = NLA_FLAG }, |
Johannes Berg | de29eda | 2014-10-31 09:25:43 +0100 | [diff] [blame] | 641 | [HWSIM_ATTR_RADIO_NAME] = { .type = NLA_STRING }, |
| 642 | [HWSIM_ATTR_NO_VIF] = { .type = NLA_FLAG }, |
| 643 | [HWSIM_ATTR_FREQ] = { .type = NLA_U32 }, |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 644 | [HWSIM_ATTR_PERM_ADDR] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 645 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 646 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 647 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, |
| 648 | struct sk_buff *skb, |
| 649 | struct ieee80211_channel *chan); |
| 650 | |
| 651 | /* sysfs attributes */ |
| 652 | static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif) |
| 653 | { |
| 654 | struct mac80211_hwsim_data *data = dat; |
| 655 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
| 656 | struct sk_buff *skb; |
| 657 | struct ieee80211_pspoll *pspoll; |
| 658 | |
| 659 | if (!vp->assoc) |
| 660 | return; |
| 661 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 662 | wiphy_dbg(data->hw->wiphy, |
| 663 | "%s: send PS-Poll to %pM for aid %d\n", |
| 664 | __func__, vp->bssid, vp->aid); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 665 | |
| 666 | skb = dev_alloc_skb(sizeof(*pspoll)); |
| 667 | if (!skb) |
| 668 | return; |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 669 | pspoll = skb_put(skb, sizeof(*pspoll)); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 670 | pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 671 | IEEE80211_STYPE_PSPOLL | |
| 672 | IEEE80211_FCTL_PM); |
| 673 | pspoll->aid = cpu_to_le16(0xc000 | vp->aid); |
| 674 | memcpy(pspoll->bssid, vp->bssid, ETH_ALEN); |
| 675 | memcpy(pspoll->ta, mac, ETH_ALEN); |
| 676 | |
| 677 | rcu_read_lock(); |
| 678 | mac80211_hwsim_tx_frame(data->hw, skb, |
| 679 | rcu_dereference(vif->chanctx_conf)->def.chan); |
| 680 | rcu_read_unlock(); |
| 681 | } |
| 682 | |
| 683 | static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac, |
| 684 | struct ieee80211_vif *vif, int ps) |
| 685 | { |
| 686 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
| 687 | struct sk_buff *skb; |
| 688 | struct ieee80211_hdr *hdr; |
| 689 | |
| 690 | if (!vp->assoc) |
| 691 | return; |
| 692 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 693 | wiphy_dbg(data->hw->wiphy, |
| 694 | "%s: send data::nullfunc to %pM ps=%d\n", |
| 695 | __func__, vp->bssid, ps); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 696 | |
| 697 | skb = dev_alloc_skb(sizeof(*hdr)); |
| 698 | if (!skb) |
| 699 | return; |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 700 | hdr = skb_put(skb, sizeof(*hdr) - ETH_ALEN); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 701 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 702 | IEEE80211_STYPE_NULLFUNC | |
Adiel Aloni | b65c7b8 | 2017-12-18 12:14:04 +0200 | [diff] [blame] | 703 | IEEE80211_FCTL_TODS | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 704 | (ps ? IEEE80211_FCTL_PM : 0)); |
| 705 | hdr->duration_id = cpu_to_le16(0); |
| 706 | memcpy(hdr->addr1, vp->bssid, ETH_ALEN); |
| 707 | memcpy(hdr->addr2, mac, ETH_ALEN); |
| 708 | memcpy(hdr->addr3, vp->bssid, ETH_ALEN); |
| 709 | |
| 710 | rcu_read_lock(); |
| 711 | mac80211_hwsim_tx_frame(data->hw, skb, |
| 712 | rcu_dereference(vif->chanctx_conf)->def.chan); |
| 713 | rcu_read_unlock(); |
| 714 | } |
| 715 | |
| 716 | |
| 717 | static void hwsim_send_nullfunc_ps(void *dat, u8 *mac, |
| 718 | struct ieee80211_vif *vif) |
| 719 | { |
| 720 | struct mac80211_hwsim_data *data = dat; |
| 721 | hwsim_send_nullfunc(data, mac, vif, 1); |
| 722 | } |
| 723 | |
| 724 | static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac, |
| 725 | struct ieee80211_vif *vif) |
| 726 | { |
| 727 | struct mac80211_hwsim_data *data = dat; |
| 728 | hwsim_send_nullfunc(data, mac, vif, 0); |
| 729 | } |
| 730 | |
| 731 | static int hwsim_fops_ps_read(void *dat, u64 *val) |
| 732 | { |
| 733 | struct mac80211_hwsim_data *data = dat; |
| 734 | *val = data->ps; |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int hwsim_fops_ps_write(void *dat, u64 val) |
| 739 | { |
| 740 | struct mac80211_hwsim_data *data = dat; |
| 741 | enum ps_mode old_ps; |
| 742 | |
| 743 | if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL && |
| 744 | val != PS_MANUAL_POLL) |
| 745 | return -EINVAL; |
| 746 | |
Adiel Aloni | e16ea4b | 2017-12-01 13:50:53 +0200 | [diff] [blame] | 747 | if (val == PS_MANUAL_POLL) { |
| 748 | if (data->ps != PS_ENABLED) |
| 749 | return -EINVAL; |
| 750 | local_bh_disable(); |
| 751 | ieee80211_iterate_active_interfaces_atomic( |
| 752 | data->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 753 | hwsim_send_ps_poll, data); |
| 754 | local_bh_enable(); |
| 755 | return 0; |
| 756 | } |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 757 | old_ps = data->ps; |
| 758 | data->ps = val; |
| 759 | |
Johannes Berg | a809ca5 | 2015-01-09 11:29:50 +0100 | [diff] [blame] | 760 | local_bh_disable(); |
Adiel Aloni | e16ea4b | 2017-12-01 13:50:53 +0200 | [diff] [blame] | 761 | if (old_ps == PS_DISABLED && val != PS_DISABLED) { |
Johannes Berg | a809ca5 | 2015-01-09 11:29:50 +0100 | [diff] [blame] | 762 | ieee80211_iterate_active_interfaces_atomic( |
| 763 | data->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 764 | hwsim_send_nullfunc_ps, data); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 765 | } else if (old_ps != PS_DISABLED && val == PS_DISABLED) { |
Johannes Berg | a809ca5 | 2015-01-09 11:29:50 +0100 | [diff] [blame] | 766 | ieee80211_iterate_active_interfaces_atomic( |
| 767 | data->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 768 | hwsim_send_nullfunc_no_ps, data); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 769 | } |
Johannes Berg | a809ca5 | 2015-01-09 11:29:50 +0100 | [diff] [blame] | 770 | local_bh_enable(); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, |
| 776 | "%llu\n"); |
| 777 | |
| 778 | static int hwsim_write_simulate_radar(void *dat, u64 val) |
| 779 | { |
| 780 | struct mac80211_hwsim_data *data = dat; |
| 781 | |
| 782 | ieee80211_radar_detected(data->hw); |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_simulate_radar, NULL, |
| 788 | hwsim_write_simulate_radar, "%llu\n"); |
| 789 | |
| 790 | static int hwsim_fops_group_read(void *dat, u64 *val) |
| 791 | { |
| 792 | struct mac80211_hwsim_data *data = dat; |
| 793 | *val = data->group; |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | static int hwsim_fops_group_write(void *dat, u64 val) |
| 798 | { |
| 799 | struct mac80211_hwsim_data *data = dat; |
| 800 | data->group = val; |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group, |
| 805 | hwsim_fops_group_read, hwsim_fops_group_write, |
| 806 | "%llx\n"); |
| 807 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 808 | static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb, |
| 809 | struct net_device *dev) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 810 | { |
| 811 | /* TODO: allow packet injection */ |
| 812 | dev_kfree_skb(skb); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 813 | return NETDEV_TX_OK; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 814 | } |
| 815 | |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 816 | static inline u64 mac80211_hwsim_get_tsf_raw(void) |
| 817 | { |
| 818 | return ktime_to_us(ktime_get_real()); |
| 819 | } |
| 820 | |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 821 | static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data) |
| 822 | { |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 823 | u64 now = mac80211_hwsim_get_tsf_raw(); |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 824 | return cpu_to_le64(now + data->tsf_offset); |
| 825 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 826 | |
Javier Cardona | 12ce8ba | 2012-03-05 17:20:38 -0800 | [diff] [blame] | 827 | static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw, |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 828 | struct ieee80211_vif *vif) |
Javier Cardona | 12ce8ba | 2012-03-05 17:20:38 -0800 | [diff] [blame] | 829 | { |
| 830 | struct mac80211_hwsim_data *data = hw->priv; |
| 831 | return le64_to_cpu(__mac80211_hwsim_get_tsf(data)); |
| 832 | } |
| 833 | |
| 834 | static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, |
| 835 | struct ieee80211_vif *vif, u64 tsf) |
| 836 | { |
| 837 | struct mac80211_hwsim_data *data = hw->priv; |
Thomas Pedersen | 45034bf | 2013-01-02 14:55:16 -0800 | [diff] [blame] | 838 | u64 now = mac80211_hwsim_get_tsf(hw, vif); |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 839 | u32 bcn_int = data->beacon_int; |
Andrew Morton | 79211c8 | 2015-11-09 14:58:13 -0800 | [diff] [blame] | 840 | u64 delta = abs(tsf - now); |
Thomas Pedersen | 45034bf | 2013-01-02 14:55:16 -0800 | [diff] [blame] | 841 | |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 842 | /* adjust after beaconing with new timestamp at old TBTT */ |
Andrew Bresticker | 5d26b50 | 2014-07-22 14:43:51 -0700 | [diff] [blame] | 843 | if (tsf > now) { |
| 844 | data->tsf_offset += delta; |
| 845 | data->bcn_delta = do_div(delta, bcn_int); |
| 846 | } else { |
| 847 | data->tsf_offset -= delta; |
Benjamin Beichler | 4fb7f8a | 2016-11-11 17:37:56 +0100 | [diff] [blame] | 848 | data->bcn_delta = -(s64)do_div(delta, bcn_int); |
Andrew Bresticker | 5d26b50 | 2014-07-22 14:43:51 -0700 | [diff] [blame] | 849 | } |
Javier Cardona | 12ce8ba | 2012-03-05 17:20:38 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 852 | static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 853 | struct sk_buff *tx_skb, |
| 854 | struct ieee80211_channel *chan) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 855 | { |
| 856 | struct mac80211_hwsim_data *data = hw->priv; |
| 857 | struct sk_buff *skb; |
| 858 | struct hwsim_radiotap_hdr *hdr; |
| 859 | u16 flags; |
| 860 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb); |
| 861 | struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info); |
| 862 | |
Amit Khatri | 89f44d8 | 2015-11-30 12:46:52 +0530 | [diff] [blame] | 863 | if (WARN_ON(!txrate)) |
| 864 | return; |
| 865 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 866 | if (!netif_running(hwsim_mon)) |
| 867 | return; |
| 868 | |
| 869 | skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC); |
| 870 | if (skb == NULL) |
| 871 | return; |
| 872 | |
Johannes Berg | d58ff35 | 2017-06-16 14:29:23 +0200 | [diff] [blame] | 873 | hdr = skb_push(skb, sizeof(*hdr)); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 874 | hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 875 | hdr->hdr.it_pad = 0; |
| 876 | hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr)); |
Jouni Malinen | f248f10 | 2008-06-13 19:44:47 +0300 | [diff] [blame] | 877 | hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 878 | (1 << IEEE80211_RADIOTAP_RATE) | |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 879 | (1 << IEEE80211_RADIOTAP_TSFT) | |
Jouni Malinen | f248f10 | 2008-06-13 19:44:47 +0300 | [diff] [blame] | 880 | (1 << IEEE80211_RADIOTAP_CHANNEL)); |
Javier Cardona | 2f40b94 | 2012-03-05 17:20:37 -0800 | [diff] [blame] | 881 | hdr->rt_tsft = __mac80211_hwsim_get_tsf(data); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 882 | hdr->rt_flags = 0; |
| 883 | hdr->rt_rate = txrate->bitrate / 5; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 884 | hdr->rt_channel = cpu_to_le16(chan->center_freq); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 885 | flags = IEEE80211_CHAN_2GHZ; |
| 886 | if (txrate->flags & IEEE80211_RATE_ERP_G) |
| 887 | flags |= IEEE80211_CHAN_OFDM; |
| 888 | else |
| 889 | flags |= IEEE80211_CHAN_CCK; |
| 890 | hdr->rt_chbitmask = cpu_to_le16(flags); |
| 891 | |
| 892 | skb->dev = hwsim_mon; |
Zhang Shengju | 6b163a8 | 2016-03-03 01:16:55 +0000 | [diff] [blame] | 893 | skb_reset_mac_header(skb); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 894 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 895 | skb->pkt_type = PACKET_OTHERHOST; |
Jouni Malinen | f248f10 | 2008-06-13 19:44:47 +0300 | [diff] [blame] | 896 | skb->protocol = htons(ETH_P_802_2); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 897 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 898 | netif_rx(skb); |
| 899 | } |
| 900 | |
| 901 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 902 | static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan, |
| 903 | const u8 *addr) |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 904 | { |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 905 | struct sk_buff *skb; |
Jouni Malinen | 76a56eb | 2013-11-02 15:57:36 +0200 | [diff] [blame] | 906 | struct hwsim_radiotap_ack_hdr *hdr; |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 907 | u16 flags; |
| 908 | struct ieee80211_hdr *hdr11; |
| 909 | |
| 910 | if (!netif_running(hwsim_mon)) |
| 911 | return; |
| 912 | |
| 913 | skb = dev_alloc_skb(100); |
| 914 | if (skb == NULL) |
| 915 | return; |
| 916 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 917 | hdr = skb_put(skb, sizeof(*hdr)); |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 918 | hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 919 | hdr->hdr.it_pad = 0; |
| 920 | hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr)); |
| 921 | hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 922 | (1 << IEEE80211_RADIOTAP_CHANNEL)); |
| 923 | hdr->rt_flags = 0; |
Jouni Malinen | 76a56eb | 2013-11-02 15:57:36 +0200 | [diff] [blame] | 924 | hdr->pad = 0; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 925 | hdr->rt_channel = cpu_to_le16(chan->center_freq); |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 926 | flags = IEEE80211_CHAN_2GHZ; |
| 927 | hdr->rt_chbitmask = cpu_to_le16(flags); |
| 928 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 929 | hdr11 = skb_put(skb, 10); |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 930 | hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 931 | IEEE80211_STYPE_ACK); |
| 932 | hdr11->duration_id = cpu_to_le16(0); |
| 933 | memcpy(hdr11->addr1, addr, ETH_ALEN); |
| 934 | |
| 935 | skb->dev = hwsim_mon; |
Zhang Shengju | 6b163a8 | 2016-03-03 01:16:55 +0000 | [diff] [blame] | 936 | skb_reset_mac_header(skb); |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 937 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 938 | skb->pkt_type = PACKET_OTHERHOST; |
| 939 | skb->protocol = htons(ETH_P_802_2); |
| 940 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 941 | netif_rx(skb); |
| 942 | } |
| 943 | |
Johannes Berg | 3283e286 | 2014-06-12 22:34:49 +0200 | [diff] [blame] | 944 | struct mac80211_hwsim_addr_match_data { |
| 945 | u8 addr[ETH_ALEN]; |
| 946 | bool ret; |
| 947 | }; |
| 948 | |
| 949 | static void mac80211_hwsim_addr_iter(void *data, u8 *mac, |
| 950 | struct ieee80211_vif *vif) |
| 951 | { |
| 952 | struct mac80211_hwsim_addr_match_data *md = data; |
| 953 | |
| 954 | if (memcmp(mac, md->addr, ETH_ALEN) == 0) |
| 955 | md->ret = true; |
| 956 | } |
| 957 | |
| 958 | static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data, |
| 959 | const u8 *addr) |
| 960 | { |
| 961 | struct mac80211_hwsim_addr_match_data md = { |
| 962 | .ret = false, |
| 963 | }; |
| 964 | |
Johannes Berg | 339467b | 2014-06-12 22:41:00 +0200 | [diff] [blame] | 965 | if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0) |
| 966 | return true; |
| 967 | |
Johannes Berg | 3283e286 | 2014-06-12 22:34:49 +0200 | [diff] [blame] | 968 | memcpy(md.addr, addr, ETH_ALEN); |
| 969 | |
| 970 | ieee80211_iterate_active_interfaces_atomic(data->hw, |
| 971 | IEEE80211_IFACE_ITER_NORMAL, |
| 972 | mac80211_hwsim_addr_iter, |
| 973 | &md); |
| 974 | |
| 975 | return md.ret; |
| 976 | } |
Jouni Malinen | 6c08522 | 2009-11-01 11:31:45 +0200 | [diff] [blame] | 977 | |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 978 | static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data, |
| 979 | struct sk_buff *skb) |
| 980 | { |
| 981 | switch (data->ps) { |
| 982 | case PS_DISABLED: |
| 983 | return true; |
| 984 | case PS_ENABLED: |
| 985 | return false; |
| 986 | case PS_AUTO_POLL: |
| 987 | /* TODO: accept (some) Beacons by default and other frames only |
| 988 | * if pending PS-Poll has been sent */ |
| 989 | return true; |
| 990 | case PS_MANUAL_POLL: |
| 991 | /* Allow unicast frames to own address if there is a pending |
| 992 | * PS-Poll */ |
| 993 | if (data->ps_poll_pending && |
Johannes Berg | 3283e286 | 2014-06-12 22:34:49 +0200 | [diff] [blame] | 994 | mac80211_hwsim_addr_match(data, skb->data + 4)) { |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 995 | data->ps_poll_pending = false; |
| 996 | return true; |
| 997 | } |
| 998 | return false; |
| 999 | } |
| 1000 | |
| 1001 | return true; |
| 1002 | } |
| 1003 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 1004 | static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data, |
| 1005 | struct sk_buff *skb, int portid) |
| 1006 | { |
| 1007 | struct net *net; |
| 1008 | bool found = false; |
| 1009 | int res = -ENOENT; |
| 1010 | |
| 1011 | rcu_read_lock(); |
| 1012 | for_each_net_rcu(net) { |
| 1013 | if (data->netgroup == hwsim_net_get_netgroup(net)) { |
| 1014 | res = genlmsg_unicast(net, skb, portid); |
| 1015 | found = true; |
| 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | rcu_read_unlock(); |
| 1020 | |
| 1021 | if (!found) |
| 1022 | nlmsg_free(skb); |
| 1023 | |
| 1024 | return res; |
| 1025 | } |
| 1026 | |
Benjamin Beichler | 6e3d6ca1 | 2018-01-10 17:42:55 +0100 | [diff] [blame] | 1027 | static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate) |
| 1028 | { |
| 1029 | u16 result = 0; |
| 1030 | |
| 1031 | if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) |
| 1032 | result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS; |
| 1033 | if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) |
| 1034 | result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT; |
| 1035 | if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 1036 | result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE; |
| 1037 | if (rate->flags & IEEE80211_TX_RC_MCS) |
| 1038 | result |= MAC80211_HWSIM_TX_RC_MCS; |
| 1039 | if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD) |
| 1040 | result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD; |
| 1041 | if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
| 1042 | result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH; |
| 1043 | if (rate->flags & IEEE80211_TX_RC_DUP_DATA) |
| 1044 | result |= MAC80211_HWSIM_TX_RC_DUP_DATA; |
| 1045 | if (rate->flags & IEEE80211_TX_RC_SHORT_GI) |
| 1046 | result |= MAC80211_HWSIM_TX_RC_SHORT_GI; |
| 1047 | if (rate->flags & IEEE80211_TX_RC_VHT_MCS) |
| 1048 | result |= MAC80211_HWSIM_TX_RC_VHT_MCS; |
| 1049 | if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) |
| 1050 | result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH; |
| 1051 | if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) |
| 1052 | result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH; |
| 1053 | |
| 1054 | return result; |
| 1055 | } |
| 1056 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1057 | static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, |
| 1058 | struct sk_buff *my_skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1059 | int dst_portid) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1060 | { |
| 1061 | struct sk_buff *skb; |
| 1062 | struct mac80211_hwsim_data *data = hw->priv; |
| 1063 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) my_skb->data; |
| 1064 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(my_skb); |
| 1065 | void *msg_head; |
| 1066 | unsigned int hwsim_flags = 0; |
| 1067 | int i; |
| 1068 | struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES]; |
Benjamin Beichler | 6e3d6ca1 | 2018-01-10 17:42:55 +0100 | [diff] [blame] | 1069 | struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES]; |
Johannes Berg | 959eb2f | 2015-11-06 11:57:23 +0100 | [diff] [blame] | 1070 | uintptr_t cookie; |
Jouni Malinen | 265dc7f | 2009-12-04 19:10:34 +0200 | [diff] [blame] | 1071 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1072 | if (data->ps != PS_DISABLED) |
| 1073 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 1074 | /* If the queue contains MAX_QUEUE skb's drop some */ |
| 1075 | if (skb_queue_len(&data->pending) >= MAX_QUEUE) { |
| 1076 | /* Droping until WARN_QUEUE level */ |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 1077 | while (skb_queue_len(&data->pending) >= WARN_QUEUE) { |
Ben Greear | b7bc967 | 2014-09-25 14:22:18 -0700 | [diff] [blame] | 1078 | ieee80211_free_txskb(hw, skb_dequeue(&data->pending)); |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 1079 | data->tx_dropped++; |
| 1080 | } |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 1083 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1084 | if (skb == NULL) |
| 1085 | goto nla_put_failure; |
| 1086 | |
| 1087 | msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, |
| 1088 | HWSIM_CMD_FRAME); |
| 1089 | if (msg_head == NULL) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1090 | pr_debug("mac80211_hwsim: problem with msg_head\n"); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1091 | goto nla_put_failure; |
| 1092 | } |
| 1093 | |
Bob Copeland | 354210f | 2015-12-19 09:59:37 -0500 | [diff] [blame] | 1094 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, |
| 1095 | ETH_ALEN, data->addresses[1].addr)) |
David S. Miller | 633c938 | 2012-04-01 21:03:30 -0400 | [diff] [blame] | 1096 | goto nla_put_failure; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1097 | |
| 1098 | /* We get the skb->data */ |
David S. Miller | 633c938 | 2012-04-01 21:03:30 -0400 | [diff] [blame] | 1099 | if (nla_put(skb, HWSIM_ATTR_FRAME, my_skb->len, my_skb->data)) |
| 1100 | goto nla_put_failure; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1101 | |
| 1102 | /* We get the flags for this transmission, and we translate them to |
| 1103 | wmediumd flags */ |
| 1104 | |
| 1105 | if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) |
| 1106 | hwsim_flags |= HWSIM_TX_CTL_REQ_TX_STATUS; |
| 1107 | |
| 1108 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 1109 | hwsim_flags |= HWSIM_TX_CTL_NO_ACK; |
| 1110 | |
David S. Miller | 633c938 | 2012-04-01 21:03:30 -0400 | [diff] [blame] | 1111 | if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags)) |
| 1112 | goto nla_put_failure; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1113 | |
Ben Greear | 4f86ed8 | 2014-10-27 15:04:46 -0700 | [diff] [blame] | 1114 | if (nla_put_u32(skb, HWSIM_ATTR_FREQ, data->channel->center_freq)) |
| 1115 | goto nla_put_failure; |
| 1116 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1117 | /* We get the tx control (rate and retries) info*/ |
| 1118 | |
| 1119 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { |
| 1120 | tx_attempts[i].idx = info->status.rates[i].idx; |
Benjamin Beichler | 6e3d6ca1 | 2018-01-10 17:42:55 +0100 | [diff] [blame] | 1121 | tx_attempts_flags[i].idx = info->status.rates[i].idx; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1122 | tx_attempts[i].count = info->status.rates[i].count; |
Benjamin Beichler | 6e3d6ca1 | 2018-01-10 17:42:55 +0100 | [diff] [blame] | 1123 | tx_attempts_flags[i].flags = |
| 1124 | trans_tx_rate_flags_ieee2hwsim( |
| 1125 | &info->status.rates[i]); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1126 | } |
| 1127 | |
David S. Miller | 633c938 | 2012-04-01 21:03:30 -0400 | [diff] [blame] | 1128 | if (nla_put(skb, HWSIM_ATTR_TX_INFO, |
| 1129 | sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES, |
| 1130 | tx_attempts)) |
| 1131 | goto nla_put_failure; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1132 | |
Benjamin Beichler | 6e3d6ca1 | 2018-01-10 17:42:55 +0100 | [diff] [blame] | 1133 | if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS, |
| 1134 | sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES, |
| 1135 | tx_attempts_flags)) |
| 1136 | goto nla_put_failure; |
| 1137 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1138 | /* We create a cookie to identify this skb */ |
Johannes Berg | 959eb2f | 2015-11-06 11:57:23 +0100 | [diff] [blame] | 1139 | data->pending_cookie++; |
| 1140 | cookie = data->pending_cookie; |
| 1141 | info->rate_driver_data[0] = (void *)cookie; |
Nicolas Dichtel | 08f4cbb | 2016-04-26 10:06:12 +0200 | [diff] [blame] | 1142 | if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD)) |
David S. Miller | 633c938 | 2012-04-01 21:03:30 -0400 | [diff] [blame] | 1143 | goto nla_put_failure; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1144 | |
| 1145 | genlmsg_end(skb, msg_head); |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 1146 | if (hwsim_unicast_netgroup(data, skb, dst_portid)) |
Bob Copeland | f2831e2 | 2015-02-05 08:45:43 -0500 | [diff] [blame] | 1147 | goto err_free_txskb; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1148 | |
| 1149 | /* Enqueue the packet */ |
| 1150 | skb_queue_tail(&data->pending, my_skb); |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 1151 | data->tx_pkts++; |
| 1152 | data->tx_bytes += my_skb->len; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1153 | return; |
| 1154 | |
| 1155 | nla_put_failure: |
Bob Copeland | f2831e2 | 2015-02-05 08:45:43 -0500 | [diff] [blame] | 1156 | nlmsg_free(skb); |
| 1157 | err_free_txskb: |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1158 | pr_debug("mac80211_hwsim: error occurred in %s\n", __func__); |
Ben Greear | b7bc967 | 2014-09-25 14:22:18 -0700 | [diff] [blame] | 1159 | ieee80211_free_txskb(hw, my_skb); |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 1160 | data->tx_failed++; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1161 | } |
| 1162 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1163 | static bool hwsim_chans_compat(struct ieee80211_channel *c1, |
| 1164 | struct ieee80211_channel *c2) |
| 1165 | { |
| 1166 | if (!c1 || !c2) |
| 1167 | return false; |
| 1168 | |
| 1169 | return c1->center_freq == c2->center_freq; |
| 1170 | } |
| 1171 | |
| 1172 | struct tx_iter_data { |
| 1173 | struct ieee80211_channel *channel; |
| 1174 | bool receive; |
| 1175 | }; |
| 1176 | |
| 1177 | static void mac80211_hwsim_tx_iter(void *_data, u8 *addr, |
| 1178 | struct ieee80211_vif *vif) |
| 1179 | { |
| 1180 | struct tx_iter_data *data = _data; |
| 1181 | |
| 1182 | if (!vif->chanctx_conf) |
| 1183 | return; |
| 1184 | |
| 1185 | if (!hwsim_chans_compat(data->channel, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 1186 | rcu_dereference(vif->chanctx_conf)->def.chan)) |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1187 | return; |
| 1188 | |
| 1189 | data->receive = true; |
| 1190 | } |
| 1191 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 1192 | static void mac80211_hwsim_add_vendor_rtap(struct sk_buff *skb) |
| 1193 | { |
| 1194 | /* |
| 1195 | * To enable this code, #define the HWSIM_RADIOTAP_OUI, |
| 1196 | * e.g. like this: |
| 1197 | * #define HWSIM_RADIOTAP_OUI "\x02\x00\x00" |
| 1198 | * (but you should use a valid OUI, not that) |
| 1199 | * |
| 1200 | * If anyone wants to 'donate' a radiotap OUI/subns code |
| 1201 | * please send a patch removing this #ifdef and changing |
| 1202 | * the values accordingly. |
| 1203 | */ |
| 1204 | #ifdef HWSIM_RADIOTAP_OUI |
| 1205 | struct ieee80211_vendor_radiotap *rtap; |
| 1206 | |
| 1207 | /* |
| 1208 | * Note that this code requires the headroom in the SKB |
| 1209 | * that was allocated earlier. |
| 1210 | */ |
Johannes Berg | d58ff35 | 2017-06-16 14:29:23 +0200 | [diff] [blame] | 1211 | rtap = skb_push(skb, sizeof(*rtap) + 8 + 4); |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 1212 | rtap->oui[0] = HWSIM_RADIOTAP_OUI[0]; |
| 1213 | rtap->oui[1] = HWSIM_RADIOTAP_OUI[1]; |
| 1214 | rtap->oui[2] = HWSIM_RADIOTAP_OUI[2]; |
| 1215 | rtap->subns = 127; |
| 1216 | |
| 1217 | /* |
| 1218 | * Radiotap vendor namespaces can (and should) also be |
| 1219 | * split into fields by using the standard radiotap |
| 1220 | * presence bitmap mechanism. Use just BIT(0) here for |
| 1221 | * the presence bitmap. |
| 1222 | */ |
| 1223 | rtap->present = BIT(0); |
| 1224 | /* We have 8 bytes of (dummy) data */ |
| 1225 | rtap->len = 8; |
| 1226 | /* For testing, also require it to be aligned */ |
| 1227 | rtap->align = 8; |
| 1228 | /* And also test that padding works, 4 bytes */ |
| 1229 | rtap->pad = 4; |
| 1230 | /* push the data */ |
| 1231 | memcpy(rtap->data, "ABCDEFGH", 8); |
| 1232 | /* make sure to clear padding, mac80211 doesn't */ |
| 1233 | memset(rtap->data + 8, 0, 4); |
| 1234 | |
| 1235 | IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_RADIOTAP_VENDOR_DATA; |
| 1236 | #endif |
| 1237 | } |
| 1238 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1239 | static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1240 | struct sk_buff *skb, |
| 1241 | struct ieee80211_channel *chan) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1242 | { |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1243 | struct mac80211_hwsim_data *data = hw->priv, *data2; |
| 1244 | bool ack = false; |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1245 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1246 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1247 | struct ieee80211_rx_status rx_status; |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1248 | u64 now; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1249 | |
| 1250 | memset(&rx_status, 0, sizeof(rx_status)); |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 1251 | rx_status.flag |= RX_FLAG_MACTIME_START; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1252 | rx_status.freq = chan->center_freq; |
| 1253 | rx_status.band = chan->band; |
Karl Beldan | dad6330 | 2013-04-15 17:09:30 +0200 | [diff] [blame] | 1254 | if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) { |
| 1255 | rx_status.rate_idx = |
| 1256 | ieee80211_rate_get_vht_mcs(&info->control.rates[0]); |
Johannes Berg | 8613c94 | 2017-04-26 13:51:41 +0200 | [diff] [blame] | 1257 | rx_status.nss = |
Karl Beldan | dad6330 | 2013-04-15 17:09:30 +0200 | [diff] [blame] | 1258 | ieee80211_rate_get_vht_nss(&info->control.rates[0]); |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 1259 | rx_status.encoding = RX_ENC_VHT; |
Karl Beldan | dad6330 | 2013-04-15 17:09:30 +0200 | [diff] [blame] | 1260 | } else { |
| 1261 | rx_status.rate_idx = info->control.rates[0].idx; |
| 1262 | if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS) |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 1263 | rx_status.encoding = RX_ENC_HT; |
Karl Beldan | dad6330 | 2013-04-15 17:09:30 +0200 | [diff] [blame] | 1264 | } |
Jouni Malinen | 281ed29 | 2011-08-06 23:07:00 +0300 | [diff] [blame] | 1265 | if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
Johannes Berg | 2f242bf | 2017-05-05 11:53:19 +0200 | [diff] [blame] | 1266 | rx_status.bw = RATE_INFO_BW_40; |
| 1267 | else if (info->control.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH) |
| 1268 | rx_status.bw = RATE_INFO_BW_80; |
| 1269 | else if (info->control.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH) |
| 1270 | rx_status.bw = RATE_INFO_BW_160; |
| 1271 | else |
| 1272 | rx_status.bw = RATE_INFO_BW_20; |
Jouni Malinen | 281ed29 | 2011-08-06 23:07:00 +0300 | [diff] [blame] | 1273 | if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI) |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 1274 | rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI; |
Johannes Berg | 4b14c96 | 2009-07-10 16:56:59 +0200 | [diff] [blame] | 1275 | /* TODO: simulate real signal strength (and optional packet loss) */ |
Johannes Berg | 1d5e9f8 | 2017-04-13 10:31:16 +0200 | [diff] [blame] | 1276 | rx_status.signal = -50; |
| 1277 | if (info->control.vif) |
| 1278 | rx_status.signal += info->control.vif->bss_conf.txpower; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1279 | |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 1280 | if (data->ps != PS_DISABLED) |
| 1281 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 1282 | |
Johannes Berg | 90e3012 | 2009-06-18 14:51:12 +0200 | [diff] [blame] | 1283 | /* release the skb's source info */ |
| 1284 | skb_orphan(skb); |
John W. Linville | c0acf38 | 2009-06-30 16:55:52 -0400 | [diff] [blame] | 1285 | skb_dst_drop(skb); |
Johannes Berg | 90e3012 | 2009-06-18 14:51:12 +0200 | [diff] [blame] | 1286 | skb->mark = 0; |
| 1287 | secpath_reset(skb); |
| 1288 | nf_reset(skb); |
| 1289 | |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1290 | /* |
| 1291 | * Get absolute mactime here so all HWs RX at the "same time", and |
| 1292 | * absolute TX time for beacon mactime so the timestamp matches. |
| 1293 | * Giving beacons a different mactime than non-beacons looks messy, but |
| 1294 | * it helps the Toffset be exact and a ~10us mactime discrepancy |
| 1295 | * probably doesn't really matter. |
| 1296 | */ |
| 1297 | if (ieee80211_is_beacon(hdr->frame_control) || |
| 1298 | ieee80211_is_probe_resp(hdr->frame_control)) |
| 1299 | now = data->abs_bcn_ts; |
| 1300 | else |
| 1301 | now = mac80211_hwsim_get_tsf_raw(); |
| 1302 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1303 | /* Copy skb to all enabled radios that are on the current frequency */ |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1304 | spin_lock(&hwsim_radio_lock); |
| 1305 | list_for_each_entry(data2, &hwsim_radios, list) { |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1306 | struct sk_buff *nskb; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1307 | struct tx_iter_data tx_iter_data = { |
| 1308 | .receive = false, |
| 1309 | .channel = chan, |
| 1310 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1311 | |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1312 | if (data == data2) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1313 | continue; |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1314 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1315 | if (!data2->started || (data2->idle && !data2->tmp_chan) || |
| 1316 | !hwsim_ps_rx_ok(data2, skb)) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1317 | continue; |
| 1318 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1319 | if (!(data->group & data2->group)) |
| 1320 | continue; |
| 1321 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 1322 | if (data->netgroup != data2->netgroup) |
| 1323 | continue; |
| 1324 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1325 | if (!hwsim_chans_compat(chan, data2->tmp_chan) && |
| 1326 | !hwsim_chans_compat(chan, data2->channel)) { |
| 1327 | ieee80211_iterate_active_interfaces_atomic( |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 1328 | data2->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1329 | mac80211_hwsim_tx_iter, &tx_iter_data); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1330 | if (!tx_iter_data.receive) |
| 1331 | continue; |
| 1332 | } |
| 1333 | |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 1334 | /* |
| 1335 | * reserve some space for our vendor and the normal |
| 1336 | * radiotap header, since we're copying anyway |
| 1337 | */ |
Johannes Berg | a357d7f | 2012-12-10 11:57:42 +0100 | [diff] [blame] | 1338 | if (skb->len < PAGE_SIZE && paged_rx) { |
| 1339 | struct page *page = alloc_page(GFP_ATOMIC); |
| 1340 | |
| 1341 | if (!page) |
| 1342 | continue; |
| 1343 | |
| 1344 | nskb = dev_alloc_skb(128); |
| 1345 | if (!nskb) { |
| 1346 | __free_page(page); |
| 1347 | continue; |
| 1348 | } |
| 1349 | |
| 1350 | memcpy(page_address(page), skb->data, skb->len); |
| 1351 | skb_add_rx_frag(nskb, 0, page, 0, skb->len, skb->len); |
| 1352 | } else { |
| 1353 | nskb = skb_copy(skb, GFP_ATOMIC); |
| 1354 | if (!nskb) |
| 1355 | continue; |
| 1356 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1357 | |
Jouni Malinen | 265dc7f | 2009-12-04 19:10:34 +0200 | [diff] [blame] | 1358 | if (mac80211_hwsim_addr_match(data2, hdr->addr1)) |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1359 | ack = true; |
Javier Cardona | f483ad2 | 2012-03-31 11:31:30 -0700 | [diff] [blame] | 1360 | |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1361 | rx_status.mactime = now + data2->tsf_offset; |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 1362 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 1363 | memcpy(IEEE80211_SKB_RXCB(nskb), &rx_status, sizeof(rx_status)); |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 1364 | |
| 1365 | mac80211_hwsim_add_vendor_rtap(nskb); |
| 1366 | |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 1367 | data2->rx_pkts++; |
| 1368 | data2->rx_bytes += nskb->len; |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 1369 | ieee80211_rx_irqsafe(data2->hw, nskb); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1370 | } |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1371 | spin_unlock(&hwsim_radio_lock); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1372 | |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1373 | return ack; |
| 1374 | } |
| 1375 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1376 | static void mac80211_hwsim_tx(struct ieee80211_hw *hw, |
| 1377 | struct ieee80211_tx_control *control, |
| 1378 | struct sk_buff *skb) |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1379 | { |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1380 | struct mac80211_hwsim_data *data = hw->priv; |
| 1381 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); |
Jouni Malinen | 732b539 | 2015-11-26 20:50:12 +0200 | [diff] [blame] | 1382 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1383 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 1384 | struct ieee80211_channel *channel; |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 1385 | bool ack; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1386 | u32 _portid; |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1387 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1388 | if (WARN_ON(skb->len < 10)) { |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1389 | /* Should not happen; just a sanity check for addr1 use */ |
Johannes Berg | fe0f3cd | 2013-07-14 23:37:14 +0300 | [diff] [blame] | 1390 | ieee80211_free_txskb(hw, skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1391 | return; |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1392 | } |
| 1393 | |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 1394 | if (!data->use_chanctx) { |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1395 | channel = data->channel; |
| 1396 | } else if (txi->hw_queue == 4) { |
| 1397 | channel = data->tmp_chan; |
| 1398 | } else { |
| 1399 | chanctx_conf = rcu_dereference(txi->control.vif->chanctx_conf); |
| 1400 | if (chanctx_conf) |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 1401 | channel = chanctx_conf->def.chan; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1402 | else |
| 1403 | channel = NULL; |
| 1404 | } |
| 1405 | |
| 1406 | if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) { |
Johannes Berg | fe0f3cd | 2013-07-14 23:37:14 +0300 | [diff] [blame] | 1407 | ieee80211_free_txskb(hw, skb); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1408 | return; |
| 1409 | } |
| 1410 | |
| 1411 | if (data->idle && !data->tmp_chan) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1412 | wiphy_dbg(hw->wiphy, "Trying to TX when idle - reject\n"); |
Johannes Berg | fe0f3cd | 2013-07-14 23:37:14 +0300 | [diff] [blame] | 1413 | ieee80211_free_txskb(hw, skb); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1414 | return; |
| 1415 | } |
| 1416 | |
| 1417 | if (txi->control.vif) |
| 1418 | hwsim_check_magic(txi->control.vif); |
| 1419 | if (control->sta) |
| 1420 | hwsim_check_sta_magic(control->sta); |
| 1421 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1422 | if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) |
Karl Beldan | 1eb3217 | 2013-04-19 14:44:52 +0200 | [diff] [blame] | 1423 | ieee80211_get_tx_rates(txi->control.vif, control->sta, skb, |
| 1424 | txi->control.rates, |
| 1425 | ARRAY_SIZE(txi->control.rates)); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1426 | |
Jouni Malinen | 732b539 | 2015-11-26 20:50:12 +0200 | [diff] [blame] | 1427 | if (skb->len >= 24 + 8 && |
| 1428 | ieee80211_is_probe_resp(hdr->frame_control)) { |
| 1429 | /* fake header transmission time */ |
| 1430 | struct ieee80211_mgmt *mgmt; |
| 1431 | struct ieee80211_rate *txrate; |
| 1432 | u64 ts; |
| 1433 | |
| 1434 | mgmt = (struct ieee80211_mgmt *)skb->data; |
| 1435 | txrate = ieee80211_get_tx_rate(hw, txi); |
| 1436 | ts = mac80211_hwsim_get_tsf_raw(); |
| 1437 | mgmt->u.probe_resp.timestamp = |
| 1438 | cpu_to_le64(ts + data->tsf_offset + |
| 1439 | 24 * 8 * 10 / txrate->bitrate); |
| 1440 | } |
| 1441 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1442 | mac80211_hwsim_monitor_rx(hw, skb, channel); |
| 1443 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1444 | /* wmediumd mode check */ |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1445 | _portid = READ_ONCE(data->wmediumd); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1446 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1447 | if (_portid) |
| 1448 | return mac80211_hwsim_tx_frame_nl(hw, skb, _portid); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1449 | |
| 1450 | /* NO wmediumd detected, perfect medium simulation */ |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 1451 | data->tx_pkts++; |
| 1452 | data->tx_bytes += skb->len; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1453 | ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 1454 | |
Johannes Berg | f06b7ab | 2016-01-13 14:21:01 +0100 | [diff] [blame] | 1455 | if (ack && skb->len >= 16) |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1456 | mac80211_hwsim_monitor_ack(channel, hdr->addr2); |
Jouni Malinen | e36cfdc | 2008-06-13 19:44:48 +0300 | [diff] [blame] | 1457 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1458 | ieee80211_tx_info_clear_status(txi); |
Javier Cardona | 2a4ffa4 | 2012-05-01 03:01:28 -0700 | [diff] [blame] | 1459 | |
| 1460 | /* frame was transmitted at most favorable rate at first attempt */ |
| 1461 | txi->control.rates[0].count = 1; |
| 1462 | txi->control.rates[1].idx = -1; |
| 1463 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1464 | if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack) |
| 1465 | txi->flags |= IEEE80211_TX_STAT_ACK; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1466 | ieee80211_tx_status_irqsafe(hw, skb); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | static int mac80211_hwsim_start(struct ieee80211_hw *hw) |
| 1471 | { |
| 1472 | struct mac80211_hwsim_data *data = hw->priv; |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1473 | wiphy_dbg(hw->wiphy, "%s\n", __func__); |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1474 | data->started = true; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | static void mac80211_hwsim_stop(struct ieee80211_hw *hw) |
| 1480 | { |
| 1481 | struct mac80211_hwsim_data *data = hw->priv; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1482 | data->started = false; |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1483 | tasklet_hrtimer_cancel(&data->beacon_timer); |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1484 | wiphy_dbg(hw->wiphy, "%s\n", __func__); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1489 | struct ieee80211_vif *vif) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1490 | { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1491 | wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n", |
| 1492 | __func__, ieee80211_vif_type_p2p(vif), |
| 1493 | vif->addr); |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1494 | hwsim_set_magic(vif); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1495 | |
| 1496 | vif->cab_queue = 0; |
| 1497 | vif->hw_queue[IEEE80211_AC_VO] = 0; |
| 1498 | vif->hw_queue[IEEE80211_AC_VI] = 1; |
| 1499 | vif->hw_queue[IEEE80211_AC_BE] = 2; |
| 1500 | vif->hw_queue[IEEE80211_AC_BK] = 3; |
| 1501 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1502 | return 0; |
| 1503 | } |
| 1504 | |
| 1505 | |
Johannes Berg | c35d027 | 2010-08-27 12:35:59 +0200 | [diff] [blame] | 1506 | static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw, |
| 1507 | struct ieee80211_vif *vif, |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1508 | enum nl80211_iftype newtype, |
| 1509 | bool newp2p) |
Johannes Berg | c35d027 | 2010-08-27 12:35:59 +0200 | [diff] [blame] | 1510 | { |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1511 | newtype = ieee80211_iftype_p2p(newtype, newp2p); |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1512 | wiphy_dbg(hw->wiphy, |
| 1513 | "%s (old type=%d, new type=%d, mac_addr=%pM)\n", |
| 1514 | __func__, ieee80211_vif_type_p2p(vif), |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1515 | newtype, vif->addr); |
Johannes Berg | c35d027 | 2010-08-27 12:35:59 +0200 | [diff] [blame] | 1516 | hwsim_check_magic(vif); |
| 1517 | |
Johannes Berg | 3eb92f6 | 2013-03-18 22:13:18 +0100 | [diff] [blame] | 1518 | /* |
| 1519 | * interface may change from non-AP to AP in |
| 1520 | * which case this needs to be set up again |
| 1521 | */ |
| 1522 | vif->cab_queue = 0; |
| 1523 | |
Johannes Berg | c35d027 | 2010-08-27 12:35:59 +0200 | [diff] [blame] | 1524 | return 0; |
| 1525 | } |
| 1526 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1527 | static void mac80211_hwsim_remove_interface( |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1528 | struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1529 | { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1530 | wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n", |
| 1531 | __func__, ieee80211_vif_type_p2p(vif), |
| 1532 | vif->addr); |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1533 | hwsim_check_magic(vif); |
| 1534 | hwsim_clear_magic(vif); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1535 | } |
| 1536 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1537 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, |
| 1538 | struct sk_buff *skb, |
| 1539 | struct ieee80211_channel *chan) |
| 1540 | { |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 1541 | struct mac80211_hwsim_data *data = hw->priv; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1542 | u32 _pid = READ_ONCE(data->wmediumd); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1543 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1544 | if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) { |
Karl Beldan | 1eb3217 | 2013-04-19 14:44:52 +0200 | [diff] [blame] | 1545 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); |
| 1546 | ieee80211_get_tx_rates(txi->control.vif, NULL, skb, |
| 1547 | txi->control.rates, |
| 1548 | ARRAY_SIZE(txi->control.rates)); |
| 1549 | } |
| 1550 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1551 | mac80211_hwsim_monitor_rx(hw, skb, chan); |
| 1552 | |
| 1553 | if (_pid) |
| 1554 | return mac80211_hwsim_tx_frame_nl(hw, skb, _pid); |
| 1555 | |
| 1556 | mac80211_hwsim_tx_frame_no_nl(hw, skb, chan); |
| 1557 | dev_kfree_skb(skb); |
| 1558 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1559 | |
| 1560 | static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac, |
| 1561 | struct ieee80211_vif *vif) |
| 1562 | { |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1563 | struct mac80211_hwsim_data *data = arg; |
| 1564 | struct ieee80211_hw *hw = data->hw; |
| 1565 | struct ieee80211_tx_info *info; |
| 1566 | struct ieee80211_rate *txrate; |
| 1567 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1568 | struct sk_buff *skb; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1569 | |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1570 | hwsim_check_magic(vif); |
| 1571 | |
Andrey Yurovsky | 55b3961 | 2008-10-31 23:23:35 -0700 | [diff] [blame] | 1572 | if (vif->type != NL80211_IFTYPE_AP && |
Johannes Berg | 2b2d779 | 2010-08-17 12:08:07 +0200 | [diff] [blame] | 1573 | vif->type != NL80211_IFTYPE_MESH_POINT && |
| 1574 | vif->type != NL80211_IFTYPE_ADHOC) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1575 | return; |
| 1576 | |
| 1577 | skb = ieee80211_beacon_get(hw, vif); |
| 1578 | if (skb == NULL) |
| 1579 | return; |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1580 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1581 | if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) |
Karl Beldan | 1eb3217 | 2013-04-19 14:44:52 +0200 | [diff] [blame] | 1582 | ieee80211_get_tx_rates(vif, NULL, skb, |
| 1583 | info->control.rates, |
| 1584 | ARRAY_SIZE(info->control.rates)); |
| 1585 | |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1586 | txrate = ieee80211_get_tx_rate(hw, info); |
| 1587 | |
| 1588 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1589 | /* fake header transmission time */ |
| 1590 | data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw(); |
| 1591 | mgmt->u.beacon.timestamp = cpu_to_le64(data->abs_bcn_ts + |
| 1592 | data->tsf_offset + |
| 1593 | 24 * 8 * 10 / txrate->bitrate); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1594 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1595 | mac80211_hwsim_tx_frame(hw, skb, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 1596 | rcu_dereference(vif->chanctx_conf)->def.chan); |
Andrei Otcheretianski | 0037db6 | 2013-11-18 09:46:24 +0200 | [diff] [blame] | 1597 | |
| 1598 | if (vif->csa_active && ieee80211_csa_is_complete(vif)) |
| 1599 | ieee80211_csa_finish(vif); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1600 | } |
| 1601 | |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1602 | static enum hrtimer_restart |
| 1603 | mac80211_hwsim_beacon(struct hrtimer *timer) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1604 | { |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1605 | struct mac80211_hwsim_data *data = |
| 1606 | container_of(timer, struct mac80211_hwsim_data, |
| 1607 | beacon_timer.timer); |
| 1608 | struct ieee80211_hw *hw = data->hw; |
| 1609 | u64 bcn_int = data->beacon_int; |
| 1610 | ktime_t next_bcn; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1611 | |
Johannes Berg | 4c4c671 | 2009-06-01 14:29:52 +0200 | [diff] [blame] | 1612 | if (!data->started) |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1613 | goto out; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1614 | |
Jouni Malinen | f248f10 | 2008-06-13 19:44:47 +0300 | [diff] [blame] | 1615 | ieee80211_iterate_active_interfaces_atomic( |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 1616 | hw, IEEE80211_IFACE_ITER_NORMAL, |
Thomas Pedersen | b66851c | 2013-01-07 14:48:07 -0800 | [diff] [blame] | 1617 | mac80211_hwsim_beacon_tx, data); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1618 | |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 1619 | /* beacon at new TBTT + beacon interval */ |
| 1620 | if (data->bcn_delta) { |
| 1621 | bcn_int -= data->bcn_delta; |
| 1622 | data->bcn_delta = 0; |
| 1623 | } |
| 1624 | |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1625 | next_bcn = ktime_add(hrtimer_get_expires(timer), |
| 1626 | ns_to_ktime(bcn_int * 1000)); |
| 1627 | tasklet_hrtimer_start(&data->beacon_timer, next_bcn, HRTIMER_MODE_ABS); |
| 1628 | out: |
| 1629 | return HRTIMER_NORESTART; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1630 | } |
| 1631 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1632 | static const char * const hwsim_chanwidths[] = { |
| 1633 | [NL80211_CHAN_WIDTH_20_NOHT] = "noht", |
| 1634 | [NL80211_CHAN_WIDTH_20] = "ht20", |
| 1635 | [NL80211_CHAN_WIDTH_40] = "ht40", |
| 1636 | [NL80211_CHAN_WIDTH_80] = "vht80", |
| 1637 | [NL80211_CHAN_WIDTH_80P80] = "vht80p80", |
| 1638 | [NL80211_CHAN_WIDTH_160] = "vht160", |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1639 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1640 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1641 | static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1642 | { |
| 1643 | struct mac80211_hwsim_data *data = hw->priv; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1644 | struct ieee80211_conf *conf = &hw->conf; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1645 | static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = { |
| 1646 | [IEEE80211_SMPS_AUTOMATIC] = "auto", |
| 1647 | [IEEE80211_SMPS_OFF] = "off", |
| 1648 | [IEEE80211_SMPS_STATIC] = "static", |
| 1649 | [IEEE80211_SMPS_DYNAMIC] = "dynamic", |
| 1650 | }; |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1651 | int idx; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1652 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1653 | if (conf->chandef.chan) |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1654 | wiphy_dbg(hw->wiphy, |
| 1655 | "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n", |
| 1656 | __func__, |
| 1657 | conf->chandef.chan->center_freq, |
| 1658 | conf->chandef.center_freq1, |
| 1659 | conf->chandef.center_freq2, |
| 1660 | hwsim_chanwidths[conf->chandef.width], |
| 1661 | !!(conf->flags & IEEE80211_CONF_IDLE), |
| 1662 | !!(conf->flags & IEEE80211_CONF_PS), |
| 1663 | smps_modes[conf->smps_mode]); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1664 | else |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1665 | wiphy_dbg(hw->wiphy, |
| 1666 | "%s (freq=0 idle=%d ps=%d smps=%s)\n", |
| 1667 | __func__, |
| 1668 | !!(conf->flags & IEEE80211_CONF_IDLE), |
| 1669 | !!(conf->flags & IEEE80211_CONF_PS), |
| 1670 | smps_modes[conf->smps_mode]); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1671 | |
Jouni Malinen | 7054183 | 2009-11-01 11:30:48 +0200 | [diff] [blame] | 1672 | data->idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
| 1673 | |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1674 | WARN_ON(conf->chandef.chan && data->use_chanctx); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1675 | |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1676 | mutex_lock(&data->mutex); |
| 1677 | if (data->scanning && conf->chandef.chan) { |
| 1678 | for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) { |
| 1679 | if (data->survey_data[idx].channel == data->channel) { |
| 1680 | data->survey_data[idx].start = |
| 1681 | data->survey_data[idx].next_start; |
| 1682 | data->survey_data[idx].end = jiffies; |
| 1683 | break; |
| 1684 | } |
| 1685 | } |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 1686 | |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1687 | data->channel = conf->chandef.chan; |
| 1688 | |
| 1689 | for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) { |
| 1690 | if (data->survey_data[idx].channel && |
| 1691 | data->survey_data[idx].channel != data->channel) |
| 1692 | continue; |
| 1693 | data->survey_data[idx].channel = data->channel; |
| 1694 | data->survey_data[idx].next_start = jiffies; |
| 1695 | break; |
| 1696 | } |
| 1697 | } else { |
| 1698 | data->channel = conf->chandef.chan; |
| 1699 | } |
| 1700 | mutex_unlock(&data->mutex); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1701 | |
Johannes Berg | 4c4c671 | 2009-06-01 14:29:52 +0200 | [diff] [blame] | 1702 | if (!data->started || !data->beacon_int) |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1703 | tasklet_hrtimer_cancel(&data->beacon_timer); |
| 1704 | else if (!hrtimer_is_queued(&data->beacon_timer.timer)) { |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 1705 | u64 tsf = mac80211_hwsim_get_tsf(hw, NULL); |
| 1706 | u32 bcn_int = data->beacon_int; |
| 1707 | u64 until_tbtt = bcn_int - do_div(tsf, bcn_int); |
| 1708 | |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1709 | tasklet_hrtimer_start(&data->beacon_timer, |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 1710 | ns_to_ktime(until_tbtt * 1000), |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1711 | HRTIMER_MODE_REL); |
| 1712 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1713 | |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | |
| 1718 | static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw, |
| 1719 | unsigned int changed_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1720 | unsigned int *total_flags,u64 multicast) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1721 | { |
| 1722 | struct mac80211_hwsim_data *data = hw->priv; |
| 1723 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1724 | wiphy_dbg(hw->wiphy, "%s\n", __func__); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1725 | |
| 1726 | data->rx_filter = 0; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1727 | if (*total_flags & FIF_ALLMULTI) |
| 1728 | data->rx_filter |= FIF_ALLMULTI; |
| 1729 | |
| 1730 | *total_flags = data->rx_filter; |
| 1731 | } |
| 1732 | |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 1733 | static void mac80211_hwsim_bcn_en_iter(void *data, u8 *mac, |
| 1734 | struct ieee80211_vif *vif) |
| 1735 | { |
| 1736 | unsigned int *count = data; |
| 1737 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
| 1738 | |
| 1739 | if (vp->bcn_en) |
| 1740 | (*count)++; |
| 1741 | } |
| 1742 | |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1743 | static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw, |
| 1744 | struct ieee80211_vif *vif, |
| 1745 | struct ieee80211_bss_conf *info, |
| 1746 | u32 changed) |
| 1747 | { |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 1748 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1749 | struct mac80211_hwsim_data *data = hw->priv; |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 1750 | |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1751 | hwsim_check_magic(vif); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1752 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1753 | wiphy_dbg(hw->wiphy, "%s(changed=0x%x vif->addr=%pM)\n", |
| 1754 | __func__, changed, vif->addr); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1755 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1756 | if (changed & BSS_CHANGED_BSSID) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1757 | wiphy_dbg(hw->wiphy, "%s: BSSID changed: %pM\n", |
| 1758 | __func__, info->bssid); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1759 | memcpy(vp->bssid, info->bssid, ETH_ALEN); |
| 1760 | } |
| 1761 | |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1762 | if (changed & BSS_CHANGED_ASSOC) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1763 | wiphy_dbg(hw->wiphy, " ASSOC: assoc=%d aid=%d\n", |
| 1764 | info->assoc, info->aid); |
Jouni Malinen | fc6971d | 2008-10-30 19:59:05 +0200 | [diff] [blame] | 1765 | vp->assoc = info->assoc; |
| 1766 | vp->aid = info->aid; |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1767 | } |
| 1768 | |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1769 | if (changed & BSS_CHANGED_BEACON_ENABLED) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1770 | wiphy_dbg(hw->wiphy, " BCN EN: %d (BI=%u)\n", |
| 1771 | info->enable_beacon, info->beacon_int); |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 1772 | vp->bcn_en = info->enable_beacon; |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1773 | if (data->started && |
| 1774 | !hrtimer_is_queued(&data->beacon_timer.timer) && |
| 1775 | info->enable_beacon) { |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 1776 | u64 tsf, until_tbtt; |
| 1777 | u32 bcn_int; |
Johannes Berg | 5606762 | 2015-03-03 22:09:05 +0100 | [diff] [blame] | 1778 | data->beacon_int = info->beacon_int * 1024; |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 1779 | tsf = mac80211_hwsim_get_tsf(hw, vif); |
| 1780 | bcn_int = data->beacon_int; |
| 1781 | until_tbtt = bcn_int - do_div(tsf, bcn_int); |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1782 | tasklet_hrtimer_start(&data->beacon_timer, |
Thomas Pedersen | c51f878 | 2013-01-02 14:55:18 -0800 | [diff] [blame] | 1783 | ns_to_ktime(until_tbtt * 1000), |
Thomas Pedersen | 01e59e4 | 2013-01-02 14:55:17 -0800 | [diff] [blame] | 1784 | HRTIMER_MODE_REL); |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 1785 | } else if (!info->enable_beacon) { |
| 1786 | unsigned int count = 0; |
Jouni Malinen | cdb1b80 | 2013-11-06 12:06:30 +0200 | [diff] [blame] | 1787 | ieee80211_iterate_active_interfaces_atomic( |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 1788 | data->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1789 | mac80211_hwsim_bcn_en_iter, &count); |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1790 | wiphy_dbg(hw->wiphy, " beaconing vifs remaining: %u", |
| 1791 | count); |
Johannes Berg | 5606762 | 2015-03-03 22:09:05 +0100 | [diff] [blame] | 1792 | if (count == 0) { |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 1793 | tasklet_hrtimer_cancel(&data->beacon_timer); |
Johannes Berg | 5606762 | 2015-03-03 22:09:05 +0100 | [diff] [blame] | 1794 | data->beacon_int = 0; |
| 1795 | } |
Jouni Malinen | 0bb861e | 2013-10-22 14:11:17 +0300 | [diff] [blame] | 1796 | } |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1797 | } |
| 1798 | |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1799 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1800 | wiphy_dbg(hw->wiphy, " ERP_CTS_PROT: %d\n", |
| 1801 | info->use_cts_prot); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1805 | wiphy_dbg(hw->wiphy, " ERP_PREAMBLE: %d\n", |
| 1806 | info->use_short_preamble); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1810 | wiphy_dbg(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | if (changed & BSS_CHANGED_HT) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1814 | wiphy_dbg(hw->wiphy, " HT: op_mode=0x%x\n", |
| 1815 | info->ht_operation_mode); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | if (changed & BSS_CHANGED_BASIC_RATES) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1819 | wiphy_dbg(hw->wiphy, " BASIC_RATES: 0x%llx\n", |
| 1820 | (unsigned long long) info->basic_rates); |
Jouni Malinen | fe63bfa | 2008-10-30 16:59:21 +0200 | [diff] [blame] | 1821 | } |
Johannes Berg | cbc668a | 2012-10-24 11:54:31 +0200 | [diff] [blame] | 1822 | |
| 1823 | if (changed & BSS_CHANGED_TXPOWER) |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1824 | wiphy_dbg(hw->wiphy, " TX Power: %d dBm\n", info->txpower); |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1825 | } |
| 1826 | |
Johannes Berg | 1d669cb | 2010-02-19 19:06:55 +0100 | [diff] [blame] | 1827 | static int mac80211_hwsim_sta_add(struct ieee80211_hw *hw, |
| 1828 | struct ieee80211_vif *vif, |
| 1829 | struct ieee80211_sta *sta) |
| 1830 | { |
| 1831 | hwsim_check_magic(vif); |
| 1832 | hwsim_set_sta_magic(sta); |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
| 1837 | static int mac80211_hwsim_sta_remove(struct ieee80211_hw *hw, |
| 1838 | struct ieee80211_vif *vif, |
| 1839 | struct ieee80211_sta *sta) |
| 1840 | { |
| 1841 | hwsim_check_magic(vif); |
| 1842 | hwsim_clear_sta_magic(sta); |
| 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1847 | static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw, |
| 1848 | struct ieee80211_vif *vif, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1849 | enum sta_notify_cmd cmd, |
| 1850 | struct ieee80211_sta *sta) |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1851 | { |
| 1852 | hwsim_check_magic(vif); |
Johannes Berg | 1d669cb | 2010-02-19 19:06:55 +0100 | [diff] [blame] | 1853 | |
Johannes Berg | 81c0652 | 2008-09-11 02:17:01 +0200 | [diff] [blame] | 1854 | switch (cmd) { |
Christian Lamparter | 89fad57 | 2008-12-09 16:28:06 +0100 | [diff] [blame] | 1855 | case STA_NOTIFY_SLEEP: |
| 1856 | case STA_NOTIFY_AWAKE: |
| 1857 | /* TODO: make good use of these flags */ |
| 1858 | break; |
Johannes Berg | 1d669cb | 2010-02-19 19:06:55 +0100 | [diff] [blame] | 1859 | default: |
| 1860 | WARN(1, "Invalid sta notify: %d\n", cmd); |
| 1861 | break; |
Johannes Berg | 81c0652 | 2008-09-11 02:17:01 +0200 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw, |
| 1866 | struct ieee80211_sta *sta, |
| 1867 | bool set) |
| 1868 | { |
| 1869 | hwsim_check_sta_magic(sta); |
| 1870 | return 0; |
Johannes Berg | 8aa21e6 | 2008-09-11 02:16:36 +0200 | [diff] [blame] | 1871 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 1872 | |
Jouni Malinen | 1e898ff8 | 2008-10-30 16:59:23 +0200 | [diff] [blame] | 1873 | static int mac80211_hwsim_conf_tx( |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 1874 | struct ieee80211_hw *hw, |
| 1875 | struct ieee80211_vif *vif, u16 queue, |
Jouni Malinen | 1e898ff8 | 2008-10-30 16:59:23 +0200 | [diff] [blame] | 1876 | const struct ieee80211_tx_queue_params *params) |
| 1877 | { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 1878 | wiphy_dbg(hw->wiphy, |
| 1879 | "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n", |
| 1880 | __func__, queue, |
| 1881 | params->txop, params->cw_min, |
| 1882 | params->cw_max, params->aifs); |
Jouni Malinen | 1e898ff8 | 2008-10-30 16:59:23 +0200 | [diff] [blame] | 1883 | return 0; |
| 1884 | } |
| 1885 | |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1886 | static int mac80211_hwsim_get_survey(struct ieee80211_hw *hw, int idx, |
| 1887 | struct survey_info *survey) |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1888 | { |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1889 | struct mac80211_hwsim_data *hwsim = hw->priv; |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1890 | |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1891 | if (idx < 0 || idx >= ARRAY_SIZE(hwsim->survey_data)) |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1892 | return -ENOENT; |
| 1893 | |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1894 | mutex_lock(&hwsim->mutex); |
| 1895 | survey->channel = hwsim->survey_data[idx].channel; |
| 1896 | if (!survey->channel) { |
| 1897 | mutex_unlock(&hwsim->mutex); |
| 1898 | return -ENOENT; |
| 1899 | } |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1900 | |
| 1901 | /* |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1902 | * Magically conjured dummy values --- this is only ok for simulated hardware. |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1903 | * |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1904 | * A real driver which cannot determine real values noise MUST NOT |
| 1905 | * report any, especially not a magically conjured ones :-) |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1906 | */ |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1907 | survey->filled = SURVEY_INFO_NOISE_DBM | |
| 1908 | SURVEY_INFO_TIME | |
| 1909 | SURVEY_INFO_TIME_BUSY; |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1910 | survey->noise = -92; |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 1911 | survey->time = |
| 1912 | jiffies_to_msecs(hwsim->survey_data[idx].end - |
| 1913 | hwsim->survey_data[idx].start); |
| 1914 | /* report 12.5% of channel time is used */ |
| 1915 | survey->time_busy = survey->time/8; |
| 1916 | mutex_unlock(&hwsim->mutex); |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1917 | |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1921 | #ifdef CONFIG_NL80211_TESTMODE |
| 1922 | /* |
| 1923 | * This section contains example code for using netlink |
| 1924 | * attributes with the testmode command in nl80211. |
| 1925 | */ |
| 1926 | |
| 1927 | /* These enums need to be kept in sync with userspace */ |
| 1928 | enum hwsim_testmode_attr { |
| 1929 | __HWSIM_TM_ATTR_INVALID = 0, |
| 1930 | HWSIM_TM_ATTR_CMD = 1, |
| 1931 | HWSIM_TM_ATTR_PS = 2, |
| 1932 | |
| 1933 | /* keep last */ |
| 1934 | __HWSIM_TM_ATTR_AFTER_LAST, |
| 1935 | HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1 |
| 1936 | }; |
| 1937 | |
| 1938 | enum hwsim_testmode_cmd { |
| 1939 | HWSIM_TM_CMD_SET_PS = 0, |
| 1940 | HWSIM_TM_CMD_GET_PS = 1, |
Johannes Berg | 4d6d0ae | 2012-07-04 12:58:40 +0200 | [diff] [blame] | 1941 | HWSIM_TM_CMD_STOP_QUEUES = 2, |
| 1942 | HWSIM_TM_CMD_WAKE_QUEUES = 3, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1943 | }; |
| 1944 | |
| 1945 | static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = { |
| 1946 | [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 }, |
| 1947 | [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 }, |
| 1948 | }; |
| 1949 | |
Johannes Berg | 5bc3819 | 2009-07-07 11:00:55 +0200 | [diff] [blame] | 1950 | static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw, |
David Spinadel | 52981cd | 2013-07-31 18:06:22 +0300 | [diff] [blame] | 1951 | struct ieee80211_vif *vif, |
Johannes Berg | 5bc3819 | 2009-07-07 11:00:55 +0200 | [diff] [blame] | 1952 | void *data, int len) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1953 | { |
| 1954 | struct mac80211_hwsim_data *hwsim = hw->priv; |
| 1955 | struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1]; |
| 1956 | struct sk_buff *skb; |
| 1957 | int err, ps; |
| 1958 | |
| 1959 | err = nla_parse(tb, HWSIM_TM_ATTR_MAX, data, len, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 1960 | hwsim_testmode_policy, NULL); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1961 | if (err) |
| 1962 | return err; |
| 1963 | |
| 1964 | if (!tb[HWSIM_TM_ATTR_CMD]) |
| 1965 | return -EINVAL; |
| 1966 | |
| 1967 | switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) { |
| 1968 | case HWSIM_TM_CMD_SET_PS: |
| 1969 | if (!tb[HWSIM_TM_ATTR_PS]) |
| 1970 | return -EINVAL; |
| 1971 | ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]); |
| 1972 | return hwsim_fops_ps_write(hwsim, ps); |
| 1973 | case HWSIM_TM_CMD_GET_PS: |
| 1974 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, |
| 1975 | nla_total_size(sizeof(u32))); |
| 1976 | if (!skb) |
| 1977 | return -ENOMEM; |
David S. Miller | 633c938 | 2012-04-01 21:03:30 -0400 | [diff] [blame] | 1978 | if (nla_put_u32(skb, HWSIM_TM_ATTR_PS, hwsim->ps)) |
| 1979 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1980 | return cfg80211_testmode_reply(skb); |
Johannes Berg | 4d6d0ae | 2012-07-04 12:58:40 +0200 | [diff] [blame] | 1981 | case HWSIM_TM_CMD_STOP_QUEUES: |
| 1982 | ieee80211_stop_queues(hw); |
| 1983 | return 0; |
| 1984 | case HWSIM_TM_CMD_WAKE_QUEUES: |
| 1985 | ieee80211_wake_queues(hw); |
| 1986 | return 0; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1987 | default: |
| 1988 | return -EOPNOTSUPP; |
| 1989 | } |
| 1990 | |
| 1991 | nla_put_failure: |
| 1992 | kfree_skb(skb); |
| 1993 | return -ENOBUFS; |
| 1994 | } |
| 1995 | #endif |
| 1996 | |
Johannes Berg | 8b73d13 | 2009-12-01 14:24:24 +0100 | [diff] [blame] | 1997 | static int mac80211_hwsim_ampdu_action(struct ieee80211_hw *hw, |
| 1998 | struct ieee80211_vif *vif, |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 1999 | struct ieee80211_ampdu_params *params) |
Johannes Berg | 8b73d13 | 2009-12-01 14:24:24 +0100 | [diff] [blame] | 2000 | { |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 2001 | struct ieee80211_sta *sta = params->sta; |
| 2002 | enum ieee80211_ampdu_mlme_action action = params->action; |
| 2003 | u16 tid = params->tid; |
| 2004 | |
Johannes Berg | 8b73d13 | 2009-12-01 14:24:24 +0100 | [diff] [blame] | 2005 | switch (action) { |
| 2006 | case IEEE80211_AMPDU_TX_START: |
| 2007 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2008 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 2009 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 2010 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 2011 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Johannes Berg | 8b73d13 | 2009-12-01 14:24:24 +0100 | [diff] [blame] | 2012 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2013 | break; |
| 2014 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 2015 | break; |
| 2016 | case IEEE80211_AMPDU_RX_START: |
| 2017 | case IEEE80211_AMPDU_RX_STOP: |
| 2018 | break; |
| 2019 | default: |
| 2020 | return -EOPNOTSUPP; |
| 2021 | } |
| 2022 | |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
Emmanuel Grumbach | 77be2c5 | 2014-03-27 11:30:29 +0200 | [diff] [blame] | 2026 | static void mac80211_hwsim_flush(struct ieee80211_hw *hw, |
| 2027 | struct ieee80211_vif *vif, |
| 2028 | u32 queues, bool drop) |
Johannes Berg | a80f7c0 | 2009-12-23 13:15:32 +0100 | [diff] [blame] | 2029 | { |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 2030 | /* Not implemented, queues only on kernel side */ |
Johannes Berg | a80f7c0 | 2009-12-23 13:15:32 +0100 | [diff] [blame] | 2031 | } |
| 2032 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2033 | static void hw_scan_work(struct work_struct *work) |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2034 | { |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2035 | struct mac80211_hwsim_data *hwsim = |
| 2036 | container_of(work, struct mac80211_hwsim_data, hw_scan.work); |
| 2037 | struct cfg80211_scan_request *req = hwsim->hw_scan_request; |
| 2038 | int dwell, i; |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2039 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2040 | mutex_lock(&hwsim->mutex); |
| 2041 | if (hwsim->scan_chan_idx >= req->n_channels) { |
Avraham Stern | 7947d3e | 2016-07-05 15:23:12 +0300 | [diff] [blame] | 2042 | struct cfg80211_scan_info info = { |
| 2043 | .aborted = false, |
| 2044 | }; |
| 2045 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2046 | wiphy_dbg(hwsim->hw->wiphy, "hw scan complete\n"); |
Avraham Stern | 7947d3e | 2016-07-05 15:23:12 +0300 | [diff] [blame] | 2047 | ieee80211_scan_completed(hwsim->hw, &info); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2048 | hwsim->hw_scan_request = NULL; |
| 2049 | hwsim->hw_scan_vif = NULL; |
| 2050 | hwsim->tmp_chan = NULL; |
| 2051 | mutex_unlock(&hwsim->mutex); |
| 2052 | return; |
| 2053 | } |
| 2054 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2055 | wiphy_dbg(hwsim->hw->wiphy, "hw scan %d MHz\n", |
| 2056 | req->channels[hwsim->scan_chan_idx]->center_freq); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2057 | |
| 2058 | hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx]; |
Johannes Berg | a8e828d | 2015-11-26 17:59:27 +0100 | [diff] [blame] | 2059 | if (hwsim->tmp_chan->flags & (IEEE80211_CHAN_NO_IR | |
| 2060 | IEEE80211_CHAN_RADAR) || |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2061 | !req->n_ssids) { |
| 2062 | dwell = 120; |
| 2063 | } else { |
| 2064 | dwell = 30; |
| 2065 | /* send probes */ |
| 2066 | for (i = 0; i < req->n_ssids; i++) { |
| 2067 | struct sk_buff *probe; |
Jouni Malinen | 12880d1 | 2016-02-26 22:12:49 +0200 | [diff] [blame] | 2068 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2069 | |
| 2070 | probe = ieee80211_probereq_get(hwsim->hw, |
Johannes Berg | 339467b | 2014-06-12 22:41:00 +0200 | [diff] [blame] | 2071 | hwsim->scan_addr, |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2072 | req->ssids[i].ssid, |
| 2073 | req->ssids[i].ssid_len, |
Johannes Berg | b9a9ada | 2012-11-29 13:00:10 +0100 | [diff] [blame] | 2074 | req->ie_len); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2075 | if (!probe) |
| 2076 | continue; |
Johannes Berg | b9a9ada | 2012-11-29 13:00:10 +0100 | [diff] [blame] | 2077 | |
Jouni Malinen | 12880d1 | 2016-02-26 22:12:49 +0200 | [diff] [blame] | 2078 | mgmt = (struct ieee80211_mgmt *) probe->data; |
| 2079 | memcpy(mgmt->da, req->bssid, ETH_ALEN); |
| 2080 | memcpy(mgmt->bssid, req->bssid, ETH_ALEN); |
| 2081 | |
Johannes Berg | b9a9ada | 2012-11-29 13:00:10 +0100 | [diff] [blame] | 2082 | if (req->ie_len) |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 2083 | skb_put_data(probe, req->ie, req->ie_len); |
Johannes Berg | b9a9ada | 2012-11-29 13:00:10 +0100 | [diff] [blame] | 2084 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2085 | local_bh_disable(); |
| 2086 | mac80211_hwsim_tx_frame(hwsim->hw, probe, |
| 2087 | hwsim->tmp_chan); |
| 2088 | local_bh_enable(); |
| 2089 | } |
| 2090 | } |
| 2091 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, |
| 2092 | msecs_to_jiffies(dwell)); |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 2093 | hwsim->survey_data[hwsim->scan_chan_idx].channel = hwsim->tmp_chan; |
| 2094 | hwsim->survey_data[hwsim->scan_chan_idx].start = jiffies; |
| 2095 | hwsim->survey_data[hwsim->scan_chan_idx].end = |
| 2096 | jiffies + msecs_to_jiffies(dwell); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2097 | hwsim->scan_chan_idx++; |
| 2098 | mutex_unlock(&hwsim->mutex); |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw, |
Johannes Berg | a060bbf | 2010-04-27 11:59:34 +0200 | [diff] [blame] | 2102 | struct ieee80211_vif *vif, |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 2103 | struct ieee80211_scan_request *hw_req) |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2104 | { |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2105 | struct mac80211_hwsim_data *hwsim = hw->priv; |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 2106 | struct cfg80211_scan_request *req = &hw_req->req; |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2107 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2108 | mutex_lock(&hwsim->mutex); |
| 2109 | if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) { |
| 2110 | mutex_unlock(&hwsim->mutex); |
| 2111 | return -EBUSY; |
| 2112 | } |
| 2113 | hwsim->hw_scan_request = req; |
| 2114 | hwsim->hw_scan_vif = vif; |
| 2115 | hwsim->scan_chan_idx = 0; |
Johannes Berg | 339467b | 2014-06-12 22:41:00 +0200 | [diff] [blame] | 2116 | if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) |
| 2117 | get_random_mask_addr(hwsim->scan_addr, |
| 2118 | hw_req->req.mac_addr, |
| 2119 | hw_req->req.mac_addr_mask); |
| 2120 | else |
| 2121 | memcpy(hwsim->scan_addr, vif->addr, ETH_ALEN); |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 2122 | memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data)); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2123 | mutex_unlock(&hwsim->mutex); |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2124 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2125 | wiphy_dbg(hw->wiphy, "hwsim hw_scan request\n"); |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2126 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2127 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, 0); |
Johannes Berg | 6906803 | 2010-02-03 10:47:55 +0100 | [diff] [blame] | 2128 | |
| 2129 | return 0; |
| 2130 | } |
| 2131 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2132 | static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw *hw, |
| 2133 | struct ieee80211_vif *vif) |
| 2134 | { |
| 2135 | struct mac80211_hwsim_data *hwsim = hw->priv; |
Avraham Stern | 7947d3e | 2016-07-05 15:23:12 +0300 | [diff] [blame] | 2136 | struct cfg80211_scan_info info = { |
| 2137 | .aborted = true, |
| 2138 | }; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2139 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2140 | wiphy_dbg(hw->wiphy, "hwsim cancel_hw_scan\n"); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2141 | |
| 2142 | cancel_delayed_work_sync(&hwsim->hw_scan); |
| 2143 | |
| 2144 | mutex_lock(&hwsim->mutex); |
Avraham Stern | 7947d3e | 2016-07-05 15:23:12 +0300 | [diff] [blame] | 2145 | ieee80211_scan_completed(hwsim->hw, &info); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2146 | hwsim->tmp_chan = NULL; |
| 2147 | hwsim->hw_scan_request = NULL; |
| 2148 | hwsim->hw_scan_vif = NULL; |
| 2149 | mutex_unlock(&hwsim->mutex); |
| 2150 | } |
| 2151 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 2152 | static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw, |
| 2153 | struct ieee80211_vif *vif, |
| 2154 | const u8 *mac_addr) |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2155 | { |
| 2156 | struct mac80211_hwsim_data *hwsim = hw->priv; |
| 2157 | |
| 2158 | mutex_lock(&hwsim->mutex); |
| 2159 | |
| 2160 | if (hwsim->scanning) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2161 | pr_debug("two hwsim sw_scans detected!\n"); |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2162 | goto out; |
| 2163 | } |
| 2164 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2165 | pr_debug("hwsim sw_scan request, prepping stuff\n"); |
Johannes Berg | 339467b | 2014-06-12 22:41:00 +0200 | [diff] [blame] | 2166 | |
| 2167 | memcpy(hwsim->scan_addr, mac_addr, ETH_ALEN); |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2168 | hwsim->scanning = true; |
Johannes Berg | 7f813ce | 2013-11-06 10:37:34 +0100 | [diff] [blame] | 2169 | memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data)); |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2170 | |
| 2171 | out: |
| 2172 | mutex_unlock(&hwsim->mutex); |
| 2173 | } |
| 2174 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 2175 | static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw, |
| 2176 | struct ieee80211_vif *vif) |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2177 | { |
| 2178 | struct mac80211_hwsim_data *hwsim = hw->priv; |
| 2179 | |
| 2180 | mutex_lock(&hwsim->mutex); |
| 2181 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2182 | pr_debug("hwsim sw_scan_complete\n"); |
Johannes Berg | 23ff98f | 2010-05-03 09:21:14 +0200 | [diff] [blame] | 2183 | hwsim->scanning = false; |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 2184 | eth_zero_addr(hwsim->scan_addr); |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2185 | |
| 2186 | mutex_unlock(&hwsim->mutex); |
| 2187 | } |
| 2188 | |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 2189 | static void hw_roc_start(struct work_struct *work) |
| 2190 | { |
| 2191 | struct mac80211_hwsim_data *hwsim = |
| 2192 | container_of(work, struct mac80211_hwsim_data, roc_start.work); |
| 2193 | |
| 2194 | mutex_lock(&hwsim->mutex); |
| 2195 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2196 | wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC begins\n"); |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 2197 | hwsim->tmp_chan = hwsim->roc_chan; |
| 2198 | ieee80211_ready_on_channel(hwsim->hw); |
| 2199 | |
| 2200 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->roc_done, |
| 2201 | msecs_to_jiffies(hwsim->roc_duration)); |
| 2202 | |
| 2203 | mutex_unlock(&hwsim->mutex); |
| 2204 | } |
| 2205 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2206 | static void hw_roc_done(struct work_struct *work) |
| 2207 | { |
| 2208 | struct mac80211_hwsim_data *hwsim = |
| 2209 | container_of(work, struct mac80211_hwsim_data, roc_done.work); |
| 2210 | |
| 2211 | mutex_lock(&hwsim->mutex); |
| 2212 | ieee80211_remain_on_channel_expired(hwsim->hw); |
| 2213 | hwsim->tmp_chan = NULL; |
| 2214 | mutex_unlock(&hwsim->mutex); |
| 2215 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2216 | wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC expired\n"); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | static int mac80211_hwsim_roc(struct ieee80211_hw *hw, |
Eliad Peller | 4988456 | 2012-11-19 17:05:09 +0200 | [diff] [blame] | 2220 | struct ieee80211_vif *vif, |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2221 | struct ieee80211_channel *chan, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 2222 | int duration, |
| 2223 | enum ieee80211_roc_type type) |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2224 | { |
| 2225 | struct mac80211_hwsim_data *hwsim = hw->priv; |
| 2226 | |
| 2227 | mutex_lock(&hwsim->mutex); |
| 2228 | if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) { |
| 2229 | mutex_unlock(&hwsim->mutex); |
| 2230 | return -EBUSY; |
| 2231 | } |
| 2232 | |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 2233 | hwsim->roc_chan = chan; |
| 2234 | hwsim->roc_duration = duration; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2235 | mutex_unlock(&hwsim->mutex); |
| 2236 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2237 | wiphy_dbg(hw->wiphy, "hwsim ROC (%d MHz, %d ms)\n", |
| 2238 | chan->center_freq, duration); |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 2239 | ieee80211_queue_delayed_work(hw, &hwsim->roc_start, HZ/50); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2240 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2241 | return 0; |
| 2242 | } |
| 2243 | |
| 2244 | static int mac80211_hwsim_croc(struct ieee80211_hw *hw) |
| 2245 | { |
| 2246 | struct mac80211_hwsim_data *hwsim = hw->priv; |
| 2247 | |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 2248 | cancel_delayed_work_sync(&hwsim->roc_start); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2249 | cancel_delayed_work_sync(&hwsim->roc_done); |
| 2250 | |
| 2251 | mutex_lock(&hwsim->mutex); |
| 2252 | hwsim->tmp_chan = NULL; |
| 2253 | mutex_unlock(&hwsim->mutex); |
| 2254 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2255 | wiphy_dbg(hw->wiphy, "hwsim ROC canceled\n"); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2256 | |
| 2257 | return 0; |
| 2258 | } |
| 2259 | |
| 2260 | static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw, |
| 2261 | struct ieee80211_chanctx_conf *ctx) |
| 2262 | { |
| 2263 | hwsim_set_chanctx_magic(ctx); |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2264 | wiphy_dbg(hw->wiphy, |
| 2265 | "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", |
| 2266 | ctx->def.chan->center_freq, ctx->def.width, |
| 2267 | ctx->def.center_freq1, ctx->def.center_freq2); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2268 | return 0; |
| 2269 | } |
| 2270 | |
| 2271 | static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw, |
| 2272 | struct ieee80211_chanctx_conf *ctx) |
| 2273 | { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2274 | wiphy_dbg(hw->wiphy, |
| 2275 | "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", |
| 2276 | ctx->def.chan->center_freq, ctx->def.width, |
| 2277 | ctx->def.center_freq1, ctx->def.center_freq2); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2278 | hwsim_check_chanctx_magic(ctx); |
| 2279 | hwsim_clear_chanctx_magic(ctx); |
| 2280 | } |
| 2281 | |
| 2282 | static void mac80211_hwsim_change_chanctx(struct ieee80211_hw *hw, |
| 2283 | struct ieee80211_chanctx_conf *ctx, |
| 2284 | u32 changed) |
| 2285 | { |
| 2286 | hwsim_check_chanctx_magic(ctx); |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2287 | wiphy_dbg(hw->wiphy, |
| 2288 | "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", |
| 2289 | ctx->def.chan->center_freq, ctx->def.width, |
| 2290 | ctx->def.center_freq1, ctx->def.center_freq2); |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 2294 | struct ieee80211_vif *vif, |
| 2295 | struct ieee80211_chanctx_conf *ctx) |
| 2296 | { |
| 2297 | hwsim_check_magic(vif); |
| 2298 | hwsim_check_chanctx_magic(ctx); |
| 2299 | |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
| 2303 | static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 2304 | struct ieee80211_vif *vif, |
| 2305 | struct ieee80211_chanctx_conf *ctx) |
| 2306 | { |
| 2307 | hwsim_check_magic(vif); |
| 2308 | hwsim_check_chanctx_magic(ctx); |
| 2309 | } |
| 2310 | |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 2311 | static const char mac80211_hwsim_gstrings_stats[][ETH_GSTRING_LEN] = { |
| 2312 | "tx_pkts_nic", |
| 2313 | "tx_bytes_nic", |
| 2314 | "rx_pkts_nic", |
| 2315 | "rx_bytes_nic", |
| 2316 | "d_tx_dropped", |
| 2317 | "d_tx_failed", |
| 2318 | "d_ps_mode", |
| 2319 | "d_group", |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 2320 | }; |
| 2321 | |
| 2322 | #define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats) |
| 2323 | |
| 2324 | static void mac80211_hwsim_get_et_strings(struct ieee80211_hw *hw, |
| 2325 | struct ieee80211_vif *vif, |
| 2326 | u32 sset, u8 *data) |
| 2327 | { |
| 2328 | if (sset == ETH_SS_STATS) |
| 2329 | memcpy(data, *mac80211_hwsim_gstrings_stats, |
| 2330 | sizeof(mac80211_hwsim_gstrings_stats)); |
| 2331 | } |
| 2332 | |
| 2333 | static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw *hw, |
| 2334 | struct ieee80211_vif *vif, int sset) |
| 2335 | { |
| 2336 | if (sset == ETH_SS_STATS) |
| 2337 | return MAC80211_HWSIM_SSTATS_LEN; |
| 2338 | return 0; |
| 2339 | } |
| 2340 | |
| 2341 | static void mac80211_hwsim_get_et_stats(struct ieee80211_hw *hw, |
| 2342 | struct ieee80211_vif *vif, |
| 2343 | struct ethtool_stats *stats, u64 *data) |
| 2344 | { |
| 2345 | struct mac80211_hwsim_data *ar = hw->priv; |
| 2346 | int i = 0; |
| 2347 | |
| 2348 | data[i++] = ar->tx_pkts; |
| 2349 | data[i++] = ar->tx_bytes; |
| 2350 | data[i++] = ar->rx_pkts; |
| 2351 | data[i++] = ar->rx_bytes; |
| 2352 | data[i++] = ar->tx_dropped; |
| 2353 | data[i++] = ar->tx_failed; |
| 2354 | data[i++] = ar->ps; |
| 2355 | data[i++] = ar->group; |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 2356 | |
| 2357 | WARN_ON(i != MAC80211_HWSIM_SSTATS_LEN); |
| 2358 | } |
| 2359 | |
Johannes Berg | 246ad56 | 2016-10-10 12:09:52 +0200 | [diff] [blame] | 2360 | #define HWSIM_COMMON_OPS \ |
| 2361 | .tx = mac80211_hwsim_tx, \ |
| 2362 | .start = mac80211_hwsim_start, \ |
| 2363 | .stop = mac80211_hwsim_stop, \ |
| 2364 | .add_interface = mac80211_hwsim_add_interface, \ |
| 2365 | .change_interface = mac80211_hwsim_change_interface, \ |
| 2366 | .remove_interface = mac80211_hwsim_remove_interface, \ |
| 2367 | .config = mac80211_hwsim_config, \ |
| 2368 | .configure_filter = mac80211_hwsim_configure_filter, \ |
| 2369 | .bss_info_changed = mac80211_hwsim_bss_info_changed, \ |
| 2370 | .sta_add = mac80211_hwsim_sta_add, \ |
| 2371 | .sta_remove = mac80211_hwsim_sta_remove, \ |
| 2372 | .sta_notify = mac80211_hwsim_sta_notify, \ |
| 2373 | .set_tim = mac80211_hwsim_set_tim, \ |
| 2374 | .conf_tx = mac80211_hwsim_conf_tx, \ |
| 2375 | .get_survey = mac80211_hwsim_get_survey, \ |
| 2376 | CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) \ |
| 2377 | .ampdu_action = mac80211_hwsim_ampdu_action, \ |
| 2378 | .flush = mac80211_hwsim_flush, \ |
| 2379 | .get_tsf = mac80211_hwsim_get_tsf, \ |
| 2380 | .set_tsf = mac80211_hwsim_set_tsf, \ |
| 2381 | .get_et_sset_count = mac80211_hwsim_get_et_sset_count, \ |
| 2382 | .get_et_stats = mac80211_hwsim_get_et_stats, \ |
| 2383 | .get_et_strings = mac80211_hwsim_get_et_strings, |
| 2384 | |
Johannes Berg | 38ed504 | 2014-01-06 22:11:06 +0100 | [diff] [blame] | 2385 | static const struct ieee80211_ops mac80211_hwsim_ops = { |
Johannes Berg | 246ad56 | 2016-10-10 12:09:52 +0200 | [diff] [blame] | 2386 | HWSIM_COMMON_OPS |
Luis R. Rodriguez | f74cb0f | 2010-04-08 11:50:47 -0400 | [diff] [blame] | 2387 | .sw_scan_start = mac80211_hwsim_sw_scan, |
| 2388 | .sw_scan_complete = mac80211_hwsim_sw_scan_complete, |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 2389 | }; |
| 2390 | |
Johannes Berg | 246ad56 | 2016-10-10 12:09:52 +0200 | [diff] [blame] | 2391 | static const struct ieee80211_ops mac80211_hwsim_mchan_ops = { |
| 2392 | HWSIM_COMMON_OPS |
| 2393 | .hw_scan = mac80211_hwsim_hw_scan, |
| 2394 | .cancel_hw_scan = mac80211_hwsim_cancel_hw_scan, |
| 2395 | .sw_scan_start = NULL, |
| 2396 | .sw_scan_complete = NULL, |
| 2397 | .remain_on_channel = mac80211_hwsim_roc, |
| 2398 | .cancel_remain_on_channel = mac80211_hwsim_croc, |
| 2399 | .add_chanctx = mac80211_hwsim_add_chanctx, |
| 2400 | .remove_chanctx = mac80211_hwsim_remove_chanctx, |
| 2401 | .change_chanctx = mac80211_hwsim_change_chanctx, |
| 2402 | .assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx, |
| 2403 | .unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx, |
| 2404 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 2405 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2406 | struct hwsim_new_radio_params { |
| 2407 | unsigned int channels; |
| 2408 | const char *reg_alpha2; |
| 2409 | const struct ieee80211_regdomain *regd; |
| 2410 | bool reg_strict; |
| 2411 | bool p2p_device; |
| 2412 | bool use_chanctx; |
| 2413 | bool destroy_on_close; |
| 2414 | const char *hwname; |
| 2415 | bool no_vif; |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 2416 | const u8 *perm_addr; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2417 | }; |
| 2418 | |
| 2419 | static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb, |
| 2420 | struct genl_info *info) |
| 2421 | { |
| 2422 | if (info) |
Jiri Benc | 92c14d9 | 2015-09-22 18:56:43 +0200 | [diff] [blame] | 2423 | genl_notify(&hwsim_genl_family, mcast_skb, info, |
| 2424 | HWSIM_MCGRP_CONFIG, GFP_KERNEL); |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2425 | else |
| 2426 | genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0, |
| 2427 | HWSIM_MCGRP_CONFIG, GFP_KERNEL); |
| 2428 | } |
| 2429 | |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2430 | static int append_radio_msg(struct sk_buff *skb, int id, |
| 2431 | struct hwsim_new_radio_params *param) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2432 | { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2433 | int ret; |
| 2434 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2435 | ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id); |
| 2436 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2437 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2438 | |
| 2439 | if (param->channels) { |
| 2440 | ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels); |
| 2441 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2442 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | if (param->reg_alpha2) { |
| 2446 | ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2, |
| 2447 | param->reg_alpha2); |
| 2448 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2449 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | if (param->regd) { |
| 2453 | int i; |
| 2454 | |
Johannes Berg | 5875755 | 2014-12-22 12:51:25 +0100 | [diff] [blame] | 2455 | for (i = 0; i < ARRAY_SIZE(hwsim_world_regdom_custom); i++) { |
| 2456 | if (hwsim_world_regdom_custom[i] != param->regd) |
| 2457 | continue; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2458 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2459 | ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i); |
| 2460 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2461 | return ret; |
Johannes Berg | 5875755 | 2014-12-22 12:51:25 +0100 | [diff] [blame] | 2462 | break; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | if (param->reg_strict) { |
| 2467 | ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG); |
| 2468 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2469 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | if (param->p2p_device) { |
| 2473 | ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE); |
| 2474 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2475 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | if (param->use_chanctx) { |
| 2479 | ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX); |
| 2480 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2481 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | if (param->hwname) { |
| 2485 | ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, |
| 2486 | strlen(param->hwname), param->hwname); |
| 2487 | if (ret < 0) |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2488 | return ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2491 | return 0; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2492 | } |
| 2493 | |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2494 | static void hwsim_mcast_new_radio(int id, struct genl_info *info, |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2495 | struct hwsim_new_radio_params *param) |
| 2496 | { |
| 2497 | struct sk_buff *mcast_skb; |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2498 | void *data; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2499 | |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2500 | mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2501 | if (!mcast_skb) |
| 2502 | return; |
| 2503 | |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2504 | data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0, |
| 2505 | HWSIM_CMD_NEW_RADIO); |
| 2506 | if (!data) |
| 2507 | goto out_err; |
| 2508 | |
| 2509 | if (append_radio_msg(mcast_skb, id, param) < 0) |
| 2510 | goto out_err; |
| 2511 | |
| 2512 | genlmsg_end(mcast_skb, data); |
| 2513 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2514 | hwsim_mcast_config_msg(mcast_skb, info); |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2515 | return; |
| 2516 | |
| 2517 | out_err: |
Patrik Flykt | c449981 | 2014-11-12 16:42:39 +0200 | [diff] [blame] | 2518 | nlmsg_free(mcast_skb); |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2519 | } |
| 2520 | |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2521 | static const struct ieee80211_sband_iftype_data he_capa_2ghz = { |
| 2522 | /* TODO: should we support other types, e.g., P2P?*/ |
| 2523 | .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP), |
| 2524 | .he_cap = { |
| 2525 | .has_he = true, |
| 2526 | .he_cap_elem = { |
| 2527 | .mac_cap_info[0] = |
| 2528 | IEEE80211_HE_MAC_CAP0_HTC_HE, |
| 2529 | .mac_cap_info[1] = |
| 2530 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 2531 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2532 | .mac_cap_info[2] = |
| 2533 | IEEE80211_HE_MAC_CAP2_BSR | |
| 2534 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | |
| 2535 | IEEE80211_HE_MAC_CAP2_ACK_EN, |
| 2536 | .mac_cap_info[3] = |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2537 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 2538 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2539 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2540 | .phy_cap_info[1] = |
| 2541 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | |
| 2542 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | |
| 2543 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 2544 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2545 | .phy_cap_info[2] = |
| 2546 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | |
| 2547 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | |
| 2548 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | |
| 2549 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | |
| 2550 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, |
| 2551 | |
| 2552 | /* Leave all the other PHY capability bytes unset, as |
| 2553 | * DCM, beam forming, RU and PPE threshold information |
| 2554 | * are not supported |
| 2555 | */ |
| 2556 | }, |
| 2557 | .he_mcs_nss_supp = { |
| 2558 | .rx_mcs_80 = cpu_to_le16(0xfffa), |
| 2559 | .tx_mcs_80 = cpu_to_le16(0xfffa), |
| 2560 | .rx_mcs_160 = cpu_to_le16(0xffff), |
| 2561 | .tx_mcs_160 = cpu_to_le16(0xffff), |
| 2562 | .rx_mcs_80p80 = cpu_to_le16(0xffff), |
| 2563 | .tx_mcs_80p80 = cpu_to_le16(0xffff), |
| 2564 | }, |
| 2565 | }, |
| 2566 | }; |
| 2567 | |
| 2568 | static const struct ieee80211_sband_iftype_data he_capa_5ghz = { |
| 2569 | /* TODO: should we support other types, e.g., P2P?*/ |
| 2570 | .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP), |
| 2571 | .he_cap = { |
| 2572 | .has_he = true, |
| 2573 | .he_cap_elem = { |
| 2574 | .mac_cap_info[0] = |
| 2575 | IEEE80211_HE_MAC_CAP0_HTC_HE, |
| 2576 | .mac_cap_info[1] = |
| 2577 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 2578 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2579 | .mac_cap_info[2] = |
| 2580 | IEEE80211_HE_MAC_CAP2_BSR | |
| 2581 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | |
| 2582 | IEEE80211_HE_MAC_CAP2_ACK_EN, |
| 2583 | .mac_cap_info[3] = |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2584 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 2585 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2586 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU, |
| 2587 | .phy_cap_info[0] = |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2588 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | |
| 2589 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | |
| 2590 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, |
| 2591 | .phy_cap_info[1] = |
| 2592 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | |
| 2593 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | |
| 2594 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | |
Shaul Triebitz | add7453 | 2018-09-05 08:06:08 +0300 | [diff] [blame] | 2595 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2596 | .phy_cap_info[2] = |
| 2597 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | |
| 2598 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | |
| 2599 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | |
| 2600 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | |
| 2601 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, |
| 2602 | |
| 2603 | /* Leave all the other PHY capability bytes unset, as |
| 2604 | * DCM, beam forming, RU and PPE threshold information |
| 2605 | * are not supported |
| 2606 | */ |
| 2607 | }, |
| 2608 | .he_mcs_nss_supp = { |
| 2609 | .rx_mcs_80 = cpu_to_le16(0xfffa), |
| 2610 | .tx_mcs_80 = cpu_to_le16(0xfffa), |
| 2611 | .rx_mcs_160 = cpu_to_le16(0xfffa), |
| 2612 | .tx_mcs_160 = cpu_to_le16(0xfffa), |
| 2613 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), |
| 2614 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), |
| 2615 | }, |
| 2616 | }, |
| 2617 | }; |
| 2618 | |
| 2619 | static void mac80211_hswim_he_capab(struct ieee80211_supported_band *sband) |
| 2620 | { |
| 2621 | if (sband->band == NL80211_BAND_2GHZ) |
| 2622 | sband->iftype_data = |
| 2623 | (struct ieee80211_sband_iftype_data *)&he_capa_2ghz; |
| 2624 | else if (sband->band == NL80211_BAND_5GHZ) |
| 2625 | sband->iftype_data = |
| 2626 | (struct ieee80211_sband_iftype_data *)&he_capa_5ghz; |
| 2627 | else |
| 2628 | return; |
| 2629 | |
| 2630 | sband->n_iftype_data = 1; |
| 2631 | } |
| 2632 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2633 | static int mac80211_hwsim_new_radio(struct genl_info *info, |
| 2634 | struct hwsim_new_radio_params *param) |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2635 | { |
| 2636 | int err; |
| 2637 | u8 addr[ETH_ALEN]; |
| 2638 | struct mac80211_hwsim_data *data; |
| 2639 | struct ieee80211_hw *hw; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2640 | enum nl80211_band band; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2641 | const struct ieee80211_ops *ops = &mac80211_hwsim_ops; |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 2642 | struct net *net; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2643 | int idx; |
| 2644 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2645 | if (WARN_ON(param->channels > 1 && !param->use_chanctx)) |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 2646 | return -EINVAL; |
| 2647 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2648 | spin_lock_bh(&hwsim_radio_lock); |
| 2649 | idx = hwsim_radio_idx++; |
| 2650 | spin_unlock_bh(&hwsim_radio_lock); |
| 2651 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2652 | if (param->use_chanctx) |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2653 | ops = &mac80211_hwsim_mchan_ops; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2654 | hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2655 | if (!hw) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2656 | pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n"); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2657 | err = -ENOMEM; |
| 2658 | goto failed; |
| 2659 | } |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 2660 | |
Andrew Zaborowski | f7d3b4f | 2017-02-23 13:02:10 +0100 | [diff] [blame] | 2661 | /* ieee80211_alloc_hw_nm may have used a default name */ |
| 2662 | param->hwname = wiphy_name(hw->wiphy); |
| 2663 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 2664 | if (info) |
| 2665 | net = genl_info_net(info); |
| 2666 | else |
| 2667 | net = &init_net; |
| 2668 | wiphy_net_set(hw->wiphy, net); |
| 2669 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2670 | data = hw->priv; |
| 2671 | data->hw = hw; |
| 2672 | |
| 2673 | data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx); |
| 2674 | if (IS_ERR(data->dev)) { |
| 2675 | printk(KERN_DEBUG |
| 2676 | "mac80211_hwsim: device_create failed (%ld)\n", |
| 2677 | PTR_ERR(data->dev)); |
| 2678 | err = -ENOMEM; |
| 2679 | goto failed_drvdata; |
| 2680 | } |
| 2681 | data->dev->driver = &mac80211_hwsim_driver.driver; |
| 2682 | err = device_bind_driver(data->dev); |
| 2683 | if (err != 0) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2684 | pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n", |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2685 | err); |
Junjie Mao | 805dbe1 | 2014-10-28 09:31:47 +0800 | [diff] [blame] | 2686 | goto failed_bind; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | skb_queue_head_init(&data->pending); |
| 2690 | |
| 2691 | SET_IEEE80211_DEV(hw, data->dev); |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 2692 | if (!param->perm_addr) { |
| 2693 | eth_zero_addr(addr); |
| 2694 | addr[0] = 0x02; |
| 2695 | addr[3] = idx >> 8; |
| 2696 | addr[4] = idx; |
| 2697 | memcpy(data->addresses[0].addr, addr, ETH_ALEN); |
| 2698 | /* Why need here second address ? */ |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 2699 | memcpy(data->addresses[1].addr, addr, ETH_ALEN); |
Johannes Berg | 796e111 | 2018-03-21 09:07:02 +0100 | [diff] [blame] | 2700 | data->addresses[1].addr[0] |= 0x40; |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 2701 | hw->wiphy->n_addresses = 2; |
| 2702 | hw->wiphy->addresses = data->addresses; |
| 2703 | /* possible address clash is checked at hash table insertion */ |
| 2704 | } else { |
| 2705 | memcpy(data->addresses[0].addr, param->perm_addr, ETH_ALEN); |
| 2706 | /* compatibility with automatically generated mac addr */ |
| 2707 | memcpy(data->addresses[1].addr, param->perm_addr, ETH_ALEN); |
| 2708 | hw->wiphy->n_addresses = 2; |
| 2709 | hw->wiphy->addresses = data->addresses; |
| 2710 | } |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2711 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2712 | data->channels = param->channels; |
| 2713 | data->use_chanctx = param->use_chanctx; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 2714 | data->idx = idx; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2715 | data->destroy_on_close = param->destroy_on_close; |
| 2716 | if (info) |
| 2717 | data->portid = info->snd_portid; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2718 | |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 2719 | if (data->use_chanctx) { |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2720 | hw->wiphy->max_scan_ssids = 255; |
| 2721 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; |
| 2722 | hw->wiphy->max_remain_on_channel_duration = 1000; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2723 | hw->wiphy->iface_combinations = &data->if_combination; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2724 | if (param->p2p_device) |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 2725 | data->if_combination = hwsim_if_comb_p2p_dev[0]; |
| 2726 | else |
| 2727 | data->if_combination = hwsim_if_comb[0]; |
Ilan Peer | f7736f5 | 2016-07-05 15:23:09 +0300 | [diff] [blame] | 2728 | hw->wiphy->n_iface_combinations = 1; |
| 2729 | /* For channels > 1 DFS is not allowed */ |
| 2730 | data->if_combination.radar_detect_widths = 0; |
Johannes Berg | b59ec8d | 2014-02-07 10:44:50 +0100 | [diff] [blame] | 2731 | data->if_combination.num_different_channels = data->channels; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2732 | } else if (param->p2p_device) { |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 2733 | hw->wiphy->iface_combinations = hwsim_if_comb_p2p_dev; |
| 2734 | hw->wiphy->n_iface_combinations = |
| 2735 | ARRAY_SIZE(hwsim_if_comb_p2p_dev); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2736 | } else { |
| 2737 | hw->wiphy->iface_combinations = hwsim_if_comb; |
| 2738 | hw->wiphy->n_iface_combinations = ARRAY_SIZE(hwsim_if_comb); |
| 2739 | } |
| 2740 | |
Johannes Berg | 661ef47 | 2015-11-24 18:29:45 +0100 | [diff] [blame] | 2741 | INIT_DELAYED_WORK(&data->roc_start, hw_roc_start); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2742 | INIT_DELAYED_WORK(&data->roc_done, hw_roc_done); |
| 2743 | INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work); |
| 2744 | |
| 2745 | hw->queues = 5; |
| 2746 | hw->offchannel_tx_hw_queue = 4; |
| 2747 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 2748 | BIT(NL80211_IFTYPE_AP) | |
| 2749 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 2750 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 2751 | BIT(NL80211_IFTYPE_ADHOC) | |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 2752 | BIT(NL80211_IFTYPE_MESH_POINT); |
| 2753 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2754 | if (param->p2p_device) |
Johannes Berg | 8c66a3d | 2014-01-10 20:07:49 +0100 | [diff] [blame] | 2755 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_DEVICE); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2756 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2757 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); |
| 2758 | ieee80211_hw_set(hw, CHANCTX_STA_CSA); |
| 2759 | ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES); |
| 2760 | ieee80211_hw_set(hw, QUEUE_CONTROL); |
| 2761 | ieee80211_hw_set(hw, WANT_MONITOR_VIF); |
| 2762 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
| 2763 | ieee80211_hw_set(hw, MFP_CAPABLE); |
| 2764 | ieee80211_hw_set(hw, SIGNAL_DBM); |
Bjoern Johansson | e4a2eb8 | 2018-04-11 11:41:56 -0700 | [diff] [blame] | 2765 | ieee80211_hw_set(hw, SUPPORTS_PS); |
Johannes Berg | 33c2f53 | 2015-06-17 13:07:14 +0200 | [diff] [blame] | 2766 | ieee80211_hw_set(hw, TDLS_WIDER_BW); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2767 | if (rctbl) |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2768 | ieee80211_hw_set(hw, SUPPORTS_RC_TABLE); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2769 | |
| 2770 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | |
| 2771 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | |
Andrei Otcheretianski | 0037db6 | 2013-11-18 09:46:24 +0200 | [diff] [blame] | 2772 | WIPHY_FLAG_AP_UAPSD | |
| 2773 | WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 2774 | hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR | |
| 2775 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
| 2776 | NL80211_FEATURE_STATIC_SMPS | |
Johannes Berg | 339467b | 2014-06-12 22:41:00 +0200 | [diff] [blame] | 2777 | NL80211_FEATURE_DYNAMIC_SMPS | |
| 2778 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
Jouni Malinen | 00eeccc | 2015-11-26 20:51:04 +0200 | [diff] [blame] | 2779 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2780 | |
| 2781 | /* ask mac80211 to reserve space for magic */ |
| 2782 | hw->vif_data_size = sizeof(struct hwsim_vif_priv); |
| 2783 | hw->sta_data_size = sizeof(struct hwsim_sta_priv); |
| 2784 | hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv); |
| 2785 | |
| 2786 | memcpy(data->channels_2ghz, hwsim_channels_2ghz, |
| 2787 | sizeof(hwsim_channels_2ghz)); |
| 2788 | memcpy(data->channels_5ghz, hwsim_channels_5ghz, |
| 2789 | sizeof(hwsim_channels_5ghz)); |
| 2790 | memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates)); |
| 2791 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2792 | for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2793 | struct ieee80211_supported_band *sband = &data->bands[band]; |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2794 | |
| 2795 | sband->band = band; |
| 2796 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2797 | switch (band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2798 | case NL80211_BAND_2GHZ: |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2799 | sband->channels = data->channels_2ghz; |
| 2800 | sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz); |
| 2801 | sband->bitrates = data->rates; |
| 2802 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates); |
| 2803 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2804 | case NL80211_BAND_5GHZ: |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2805 | sband->channels = data->channels_5ghz; |
| 2806 | sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz); |
| 2807 | sband->bitrates = data->rates + 4; |
| 2808 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4; |
Ilan Peer | f33f848 | 2015-04-07 19:05:21 +0300 | [diff] [blame] | 2809 | |
| 2810 | sband->vht_cap.vht_supported = true; |
| 2811 | sband->vht_cap.cap = |
| 2812 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | |
| 2813 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ | |
| 2814 | IEEE80211_VHT_CAP_RXLDPC | |
| 2815 | IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 2816 | IEEE80211_VHT_CAP_SHORT_GI_160 | |
| 2817 | IEEE80211_VHT_CAP_TXSTBC | |
Ilan Peer | f33f848 | 2015-04-07 19:05:21 +0300 | [diff] [blame] | 2818 | IEEE80211_VHT_CAP_RXSTBC_4 | |
| 2819 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 2820 | sband->vht_cap.vht_mcs.rx_mcs_map = |
Ilan Peer | 8aca9b2 | 2015-04-07 19:05:22 +0300 | [diff] [blame] | 2821 | cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
| 2822 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | |
Ilan Peer | f33f848 | 2015-04-07 19:05:21 +0300 | [diff] [blame] | 2823 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 | |
Ilan Peer | 8aca9b2 | 2015-04-07 19:05:22 +0300 | [diff] [blame] | 2824 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 6 | |
| 2825 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 8 | |
Ilan Peer | f33f848 | 2015-04-07 19:05:21 +0300 | [diff] [blame] | 2826 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 | |
| 2827 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 | |
Ilan Peer | 8aca9b2 | 2015-04-07 19:05:22 +0300 | [diff] [blame] | 2828 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 14); |
Ilan Peer | f33f848 | 2015-04-07 19:05:21 +0300 | [diff] [blame] | 2829 | sband->vht_cap.vht_mcs.tx_mcs_map = |
| 2830 | sband->vht_cap.vht_mcs.rx_mcs_map; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2831 | break; |
| 2832 | default: |
| 2833 | continue; |
| 2834 | } |
| 2835 | |
| 2836 | sband->ht_cap.ht_supported = true; |
| 2837 | sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
| 2838 | IEEE80211_HT_CAP_GRN_FLD | |
Ben Greear | e49786d | 2014-10-24 11:12:08 -0700 | [diff] [blame] | 2839 | IEEE80211_HT_CAP_SGI_20 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2840 | IEEE80211_HT_CAP_SGI_40 | |
| 2841 | IEEE80211_HT_CAP_DSSSCCK40; |
| 2842 | sband->ht_cap.ampdu_factor = 0x3; |
| 2843 | sband->ht_cap.ampdu_density = 0x6; |
| 2844 | memset(&sband->ht_cap.mcs, 0, |
| 2845 | sizeof(sband->ht_cap.mcs)); |
| 2846 | sband->ht_cap.mcs.rx_mask[0] = 0xff; |
| 2847 | sband->ht_cap.mcs.rx_mask[1] = 0xff; |
| 2848 | sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 2849 | |
Ilan Peer | 518ea3c | 2018-07-06 15:29:05 +0300 | [diff] [blame] | 2850 | mac80211_hswim_he_capab(sband); |
| 2851 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2852 | hw->wiphy->bands[band] = sband; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | /* By default all radios belong to the first group */ |
| 2856 | data->group = 1; |
| 2857 | mutex_init(&data->mutex); |
| 2858 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 2859 | data->netgroup = hwsim_net_get_netgroup(net); |
Andrew Zaborowski | 4ea5aca | 2018-03-21 08:05:18 +0100 | [diff] [blame] | 2860 | data->wmediumd = hwsim_net_get_wmediumd(net); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 2861 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2862 | /* Enable frame retransmissions for lossy channels */ |
| 2863 | hw->max_rates = 4; |
| 2864 | hw->max_rate_tries = 11; |
| 2865 | |
Jouni Malinen | d5d011b | 2015-02-26 15:26:54 +0200 | [diff] [blame] | 2866 | hw->wiphy->vendor_commands = mac80211_hwsim_vendor_commands; |
| 2867 | hw->wiphy->n_vendor_commands = |
| 2868 | ARRAY_SIZE(mac80211_hwsim_vendor_commands); |
| 2869 | hw->wiphy->vendor_events = mac80211_hwsim_vendor_events; |
| 2870 | hw->wiphy->n_vendor_events = ARRAY_SIZE(mac80211_hwsim_vendor_events); |
| 2871 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2872 | if (param->reg_strict) |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 2873 | hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2874 | if (param->regd) { |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 2875 | data->regd = param->regd; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 2876 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2877 | wiphy_apply_custom_regulatory(hw->wiphy, param->regd); |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 2878 | /* give the regulatory workqueue a chance to run */ |
| 2879 | schedule_timeout_interruptible(1); |
| 2880 | } |
| 2881 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2882 | if (param->no_vif) |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2883 | ieee80211_hw_set(hw, NO_AUTO_VIF); |
Ben Greear | 9a0cb89 | 2014-10-22 12:23:04 -0700 | [diff] [blame] | 2884 | |
Andrew Zaborowski | ae44b50 | 2017-02-10 04:50:23 +0100 | [diff] [blame] | 2885 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); |
| 2886 | |
Vasyl Vavrychuk | a1881c9 | 2018-10-18 01:02:12 +0300 | [diff] [blame] | 2887 | tasklet_hrtimer_init(&data->beacon_timer, |
| 2888 | mac80211_hwsim_beacon, |
| 2889 | CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
| 2890 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2891 | err = ieee80211_register_hw(hw); |
| 2892 | if (err < 0) { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2893 | pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n", |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2894 | err); |
| 2895 | goto failed_hw; |
| 2896 | } |
| 2897 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 2898 | wiphy_dbg(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2899 | |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 2900 | if (param->reg_alpha2) { |
| 2901 | data->alpha2[0] = param->reg_alpha2[0]; |
| 2902 | data->alpha2[1] = param->reg_alpha2[1]; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2903 | regulatory_hint(hw->wiphy, param->reg_alpha2); |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 2904 | } |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 2905 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2906 | data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir); |
| 2907 | debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps); |
| 2908 | debugfs_create_file("group", 0666, data->debugfs, data, |
| 2909 | &hwsim_fops_group); |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 2910 | if (!data->use_chanctx) |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2911 | debugfs_create_file("dfs_simulate_radar", 0222, |
| 2912 | data->debugfs, |
| 2913 | data, &hwsim_simulate_radar); |
| 2914 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2915 | spin_lock_bh(&hwsim_radio_lock); |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 2916 | err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht, |
| 2917 | hwsim_rht_params); |
| 2918 | if (err < 0) { |
Benjamin Beichler | 301b040 | 2018-01-22 18:04:36 +0100 | [diff] [blame] | 2919 | if (info) { |
| 2920 | GENL_SET_ERR_MSG(info, "perm addr already present"); |
| 2921 | NL_SET_BAD_ATTR(info->extack, |
| 2922 | info->attrs[HWSIM_ATTR_PERM_ADDR]); |
| 2923 | } |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 2924 | spin_unlock_bh(&hwsim_radio_lock); |
| 2925 | goto failed_final_insert; |
| 2926 | } |
| 2927 | |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2928 | list_add_tail(&data->list, &hwsim_radios); |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 2929 | hwsim_radios_generation++; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2930 | spin_unlock_bh(&hwsim_radio_lock); |
| 2931 | |
Martin Willi | 28ef8b4 | 2018-09-25 09:51:02 +0200 | [diff] [blame] | 2932 | hwsim_mcast_new_radio(idx, info, param); |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 2933 | |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 2934 | return idx; |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2935 | |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 2936 | failed_final_insert: |
| 2937 | debugfs_remove_recursive(data->debugfs); |
| 2938 | ieee80211_unregister_hw(data->hw); |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2939 | failed_hw: |
Junjie Mao | 805dbe1 | 2014-10-28 09:31:47 +0800 | [diff] [blame] | 2940 | device_release_driver(data->dev); |
| 2941 | failed_bind: |
Johannes Berg | de0421d | 2014-01-06 23:12:12 +0100 | [diff] [blame] | 2942 | device_unregister(data->dev); |
| 2943 | failed_drvdata: |
| 2944 | ieee80211_free_hw(hw); |
| 2945 | failed: |
| 2946 | return err; |
| 2947 | } |
| 2948 | |
Jukka Rissanen | 579a05f | 2014-10-31 14:48:48 +0200 | [diff] [blame] | 2949 | static void hwsim_mcast_del_radio(int id, const char *hwname, |
| 2950 | struct genl_info *info) |
Johannes Berg | e4afb60 | 2014-01-06 22:43:11 +0100 | [diff] [blame] | 2951 | { |
Jukka Rissanen | 579a05f | 2014-10-31 14:48:48 +0200 | [diff] [blame] | 2952 | struct sk_buff *skb; |
| 2953 | void *data; |
| 2954 | int ret; |
| 2955 | |
| 2956 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2957 | if (!skb) |
| 2958 | return; |
| 2959 | |
| 2960 | data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, |
| 2961 | HWSIM_CMD_DEL_RADIO); |
| 2962 | if (!data) |
| 2963 | goto error; |
| 2964 | |
| 2965 | ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id); |
| 2966 | if (ret < 0) |
| 2967 | goto error; |
| 2968 | |
Jukka Rissanen | b9995f8 | 2014-11-14 13:16:34 +0200 | [diff] [blame] | 2969 | ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname), |
| 2970 | hwname); |
| 2971 | if (ret < 0) |
| 2972 | goto error; |
Jukka Rissanen | 579a05f | 2014-10-31 14:48:48 +0200 | [diff] [blame] | 2973 | |
| 2974 | genlmsg_end(skb, data); |
| 2975 | |
| 2976 | hwsim_mcast_config_msg(skb, info); |
| 2977 | |
| 2978 | return; |
| 2979 | |
| 2980 | error: |
| 2981 | nlmsg_free(skb); |
| 2982 | } |
| 2983 | |
| 2984 | static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data, |
| 2985 | const char *hwname, |
| 2986 | struct genl_info *info) |
| 2987 | { |
| 2988 | hwsim_mcast_del_radio(data->idx, hwname, info); |
Johannes Berg | e4afb60 | 2014-01-06 22:43:11 +0100 | [diff] [blame] | 2989 | debugfs_remove_recursive(data->debugfs); |
| 2990 | ieee80211_unregister_hw(data->hw); |
| 2991 | device_release_driver(data->dev); |
| 2992 | device_unregister(data->dev); |
| 2993 | ieee80211_free_hw(data->hw); |
| 2994 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 2995 | |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 2996 | static int mac80211_hwsim_get_radio(struct sk_buff *skb, |
| 2997 | struct mac80211_hwsim_data *data, |
| 2998 | u32 portid, u32 seq, |
| 2999 | struct netlink_callback *cb, int flags) |
| 3000 | { |
| 3001 | void *hdr; |
| 3002 | struct hwsim_new_radio_params param = { }; |
| 3003 | int res = -EMSGSIZE; |
| 3004 | |
| 3005 | hdr = genlmsg_put(skb, portid, seq, &hwsim_genl_family, flags, |
| 3006 | HWSIM_CMD_GET_RADIO); |
| 3007 | if (!hdr) |
| 3008 | return -EMSGSIZE; |
| 3009 | |
| 3010 | if (cb) |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 3011 | genl_dump_check_consistent(cb, hdr); |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3012 | |
Patrik Flykt | b0ad5e8 | 2014-11-21 15:08:02 +0200 | [diff] [blame] | 3013 | if (data->alpha2[0] && data->alpha2[1]) |
| 3014 | param.reg_alpha2 = data->alpha2; |
| 3015 | |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3016 | param.reg_strict = !!(data->hw->wiphy->regulatory_flags & |
| 3017 | REGULATORY_STRICT_REG); |
| 3018 | param.p2p_device = !!(data->hw->wiphy->interface_modes & |
| 3019 | BIT(NL80211_IFTYPE_P2P_DEVICE)); |
| 3020 | param.use_chanctx = data->use_chanctx; |
| 3021 | param.regd = data->regd; |
| 3022 | param.channels = data->channels; |
| 3023 | param.hwname = wiphy_name(data->hw->wiphy); |
| 3024 | |
| 3025 | res = append_radio_msg(skb, data->idx, ¶m); |
| 3026 | if (res < 0) |
| 3027 | goto out_err; |
| 3028 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3029 | genlmsg_end(skb, hdr); |
| 3030 | return 0; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3031 | |
| 3032 | out_err: |
| 3033 | genlmsg_cancel(skb, hdr); |
| 3034 | return res; |
| 3035 | } |
| 3036 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3037 | static void mac80211_hwsim_free(void) |
| 3038 | { |
Johannes Berg | e4afb60 | 2014-01-06 22:43:11 +0100 | [diff] [blame] | 3039 | struct mac80211_hwsim_data *data; |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 3040 | |
| 3041 | spin_lock_bh(&hwsim_radio_lock); |
Johannes Berg | e4afb60 | 2014-01-06 22:43:11 +0100 | [diff] [blame] | 3042 | while ((data = list_first_entry_or_null(&hwsim_radios, |
| 3043 | struct mac80211_hwsim_data, |
| 3044 | list))) { |
| 3045 | list_del(&data->list); |
| 3046 | spin_unlock_bh(&hwsim_radio_lock); |
Jukka Rissanen | b9995f8 | 2014-11-14 13:16:34 +0200 | [diff] [blame] | 3047 | mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy), |
| 3048 | NULL); |
Johannes Berg | e4afb60 | 2014-01-06 22:43:11 +0100 | [diff] [blame] | 3049 | spin_lock_bh(&hwsim_radio_lock); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3050 | } |
Johannes Berg | e4afb60 | 2014-01-06 22:43:11 +0100 | [diff] [blame] | 3051 | spin_unlock_bh(&hwsim_radio_lock); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3052 | class_destroy(hwsim_class); |
| 3053 | } |
| 3054 | |
Stephen Hemminger | 98d2faa | 2009-03-20 19:36:33 +0000 | [diff] [blame] | 3055 | static const struct net_device_ops hwsim_netdev_ops = { |
| 3056 | .ndo_start_xmit = hwsim_mon_xmit, |
Stephen Hemminger | 98d2faa | 2009-03-20 19:36:33 +0000 | [diff] [blame] | 3057 | .ndo_set_mac_address = eth_mac_addr, |
| 3058 | .ndo_validate_addr = eth_validate_addr, |
| 3059 | }; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3060 | |
| 3061 | static void hwsim_mon_setup(struct net_device *dev) |
| 3062 | { |
Stephen Hemminger | 98d2faa | 2009-03-20 19:36:33 +0000 | [diff] [blame] | 3063 | dev->netdev_ops = &hwsim_netdev_ops; |
David S. Miller | cf124db | 2017-05-08 12:52:56 -0400 | [diff] [blame] | 3064 | dev->needs_free_netdev = true; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3065 | ether_setup(dev); |
Phil Sutter | 3db6da1 | 2015-08-18 10:30:43 +0200 | [diff] [blame] | 3066 | dev->priv_flags |= IFF_NO_QUEUE; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3067 | dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 3068 | eth_zero_addr(dev->dev_addr); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3069 | dev->dev_addr[0] = 0x12; |
| 3070 | } |
| 3071 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3072 | static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3073 | { |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 3074 | return rhashtable_lookup_fast(&hwsim_radios_rht, |
| 3075 | addr, |
| 3076 | hwsim_rht_params); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3077 | } |
| 3078 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3079 | static void hwsim_register_wmediumd(struct net *net, u32 portid) |
| 3080 | { |
| 3081 | struct mac80211_hwsim_data *data; |
| 3082 | |
| 3083 | hwsim_net_set_wmediumd(net, portid); |
| 3084 | |
| 3085 | spin_lock_bh(&hwsim_radio_lock); |
| 3086 | list_for_each_entry(data, &hwsim_radios, list) { |
| 3087 | if (data->netgroup == hwsim_net_get_netgroup(net)) |
| 3088 | data->wmediumd = portid; |
| 3089 | } |
| 3090 | spin_unlock_bh(&hwsim_radio_lock); |
| 3091 | } |
| 3092 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3093 | static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, |
| 3094 | struct genl_info *info) |
| 3095 | { |
| 3096 | |
| 3097 | struct ieee80211_hdr *hdr; |
| 3098 | struct mac80211_hwsim_data *data2; |
| 3099 | struct ieee80211_tx_info *txi; |
| 3100 | struct hwsim_tx_rate *tx_attempts; |
Johannes Berg | 959eb2f | 2015-11-06 11:57:23 +0100 | [diff] [blame] | 3101 | u64 ret_skb_cookie; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3102 | struct sk_buff *skb, *tmp; |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3103 | const u8 *src; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3104 | unsigned int hwsim_flags; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3105 | int i; |
| 3106 | bool found = false; |
| 3107 | |
| 3108 | if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3109 | !info->attrs[HWSIM_ATTR_FLAGS] || |
| 3110 | !info->attrs[HWSIM_ATTR_COOKIE] || |
Martin Willi | 62397da | 2016-05-13 12:41:48 +0200 | [diff] [blame] | 3111 | !info->attrs[HWSIM_ATTR_SIGNAL] || |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3112 | !info->attrs[HWSIM_ATTR_TX_INFO]) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3113 | goto out; |
| 3114 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3115 | src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3116 | hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); |
Johannes Berg | 959eb2f | 2015-11-06 11:57:23 +0100 | [diff] [blame] | 3117 | ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3118 | |
| 3119 | data2 = get_hwsim_data_ref_from_addr(src); |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3120 | if (!data2) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3121 | goto out; |
| 3122 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3123 | if (hwsim_net_get_netgroup(genl_info_net(info)) != data2->netgroup) |
| 3124 | goto out; |
| 3125 | |
| 3126 | if (info->snd_portid != data2->wmediumd) |
| 3127 | goto out; |
| 3128 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3129 | /* look for the skb matching the cookie passed back from user */ |
| 3130 | skb_queue_walk_safe(&data2->pending, skb, tmp) { |
Johannes Berg | 959eb2f | 2015-11-06 11:57:23 +0100 | [diff] [blame] | 3131 | u64 skb_cookie; |
| 3132 | |
| 3133 | txi = IEEE80211_SKB_CB(skb); |
| 3134 | skb_cookie = (u64)(uintptr_t)txi->rate_driver_data[0]; |
| 3135 | |
| 3136 | if (skb_cookie == ret_skb_cookie) { |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3137 | skb_unlink(skb, &data2->pending); |
| 3138 | found = true; |
| 3139 | break; |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | /* not found */ |
| 3144 | if (!found) |
| 3145 | goto out; |
| 3146 | |
| 3147 | /* Tx info received because the frame was broadcasted on user space, |
| 3148 | so we get all the necessary info: tx attempts and skb control buff */ |
| 3149 | |
| 3150 | tx_attempts = (struct hwsim_tx_rate *)nla_data( |
| 3151 | info->attrs[HWSIM_ATTR_TX_INFO]); |
| 3152 | |
| 3153 | /* now send back TX status */ |
| 3154 | txi = IEEE80211_SKB_CB(skb); |
| 3155 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3156 | ieee80211_tx_info_clear_status(txi); |
| 3157 | |
| 3158 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { |
| 3159 | txi->status.rates[i].idx = tx_attempts[i].idx; |
| 3160 | txi->status.rates[i].count = tx_attempts[i].count; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); |
| 3164 | |
| 3165 | if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) && |
| 3166 | (hwsim_flags & HWSIM_TX_STAT_ACK)) { |
| 3167 | if (skb->len >= 16) { |
| 3168 | hdr = (struct ieee80211_hdr *) skb->data; |
Javier Lopez | c0e3076 | 2013-12-16 10:01:07 -0800 | [diff] [blame] | 3169 | mac80211_hwsim_monitor_ack(data2->channel, |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 3170 | hdr->addr2); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3171 | } |
Qasim Javed | 06cf5c4 | 2012-06-05 01:25:44 -0500 | [diff] [blame] | 3172 | txi->flags |= IEEE80211_TX_STAT_ACK; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3173 | } |
| 3174 | ieee80211_tx_status_irqsafe(data2->hw, skb); |
| 3175 | return 0; |
| 3176 | out: |
| 3177 | return -EINVAL; |
| 3178 | |
| 3179 | } |
| 3180 | |
| 3181 | static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, |
| 3182 | struct genl_info *info) |
| 3183 | { |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 3184 | struct mac80211_hwsim_data *data2; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3185 | struct ieee80211_rx_status rx_status; |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3186 | const u8 *dst; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3187 | int frame_data_len; |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3188 | void *frame_data; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3189 | struct sk_buff *skb = NULL; |
| 3190 | |
| 3191 | if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] || |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 3192 | !info->attrs[HWSIM_ATTR_FRAME] || |
| 3193 | !info->attrs[HWSIM_ATTR_RX_RATE] || |
| 3194 | !info->attrs[HWSIM_ATTR_SIGNAL]) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3195 | goto out; |
| 3196 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3197 | dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3198 | frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]); |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3199 | frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3200 | |
| 3201 | /* Allocate new skb here */ |
| 3202 | skb = alloc_skb(frame_data_len, GFP_KERNEL); |
| 3203 | if (skb == NULL) |
| 3204 | goto err; |
| 3205 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3206 | if (frame_data_len > IEEE80211_MAX_DATA_LEN) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3207 | goto err; |
| 3208 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3209 | /* Copy the data */ |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 3210 | skb_put_data(skb, frame_data, frame_data_len); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3211 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3212 | data2 = get_hwsim_data_ref_from_addr(dst); |
| 3213 | if (!data2) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3214 | goto out; |
| 3215 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3216 | if (hwsim_net_get_netgroup(genl_info_net(info)) != data2->netgroup) |
| 3217 | goto out; |
| 3218 | |
| 3219 | if (info->snd_portid != data2->wmediumd) |
| 3220 | goto out; |
| 3221 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3222 | /* check if radio is configured properly */ |
| 3223 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 3224 | if (data2->idle || !data2->started) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3225 | goto out; |
| 3226 | |
Johannes Berg | 9ddd12a | 2014-01-06 23:03:02 +0100 | [diff] [blame] | 3227 | /* A frame is received from user space */ |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3228 | memset(&rx_status, 0, sizeof(rx_status)); |
Adam Welle | 641cf2a | 2015-12-01 17:13:52 -0500 | [diff] [blame] | 3229 | if (info->attrs[HWSIM_ATTR_FREQ]) { |
| 3230 | /* throw away off-channel packets, but allow both the temporary |
| 3231 | * ("hw" scan/remain-on-channel) and regular channel, since the |
| 3232 | * internal datapath also allows this |
| 3233 | */ |
| 3234 | mutex_lock(&data2->mutex); |
| 3235 | rx_status.freq = nla_get_u32(info->attrs[HWSIM_ATTR_FREQ]); |
| 3236 | |
| 3237 | if (rx_status.freq != data2->channel->center_freq && |
| 3238 | (!data2->tmp_chan || |
| 3239 | rx_status.freq != data2->tmp_chan->center_freq)) { |
| 3240 | mutex_unlock(&data2->mutex); |
| 3241 | goto out; |
| 3242 | } |
| 3243 | mutex_unlock(&data2->mutex); |
| 3244 | } else { |
| 3245 | rx_status.freq = data2->channel->center_freq; |
| 3246 | } |
| 3247 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3248 | rx_status.band = data2->channel->band; |
| 3249 | rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]); |
| 3250 | rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); |
| 3251 | |
| 3252 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); |
Ben Greear | 2155c3f | 2014-10-22 12:22:58 -0700 | [diff] [blame] | 3253 | data2->rx_pkts++; |
| 3254 | data2->rx_bytes += skb->len; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3255 | ieee80211_rx_irqsafe(data2->hw, skb); |
| 3256 | |
| 3257 | return 0; |
| 3258 | err: |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 3259 | pr_debug("mac80211_hwsim: error occurred in %s\n", __func__); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3260 | out: |
| 3261 | dev_kfree_skb(skb); |
| 3262 | return -EINVAL; |
| 3263 | } |
| 3264 | |
| 3265 | static int hwsim_register_received_nl(struct sk_buff *skb_2, |
| 3266 | struct genl_info *info) |
| 3267 | { |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3268 | struct net *net = genl_info_net(info); |
Johannes Berg | c5ac085 | 2014-01-07 23:28:08 +0100 | [diff] [blame] | 3269 | struct mac80211_hwsim_data *data; |
| 3270 | int chans = 1; |
| 3271 | |
| 3272 | spin_lock_bh(&hwsim_radio_lock); |
| 3273 | list_for_each_entry(data, &hwsim_radios, list) |
| 3274 | chans = max(chans, data->channels); |
| 3275 | spin_unlock_bh(&hwsim_radio_lock); |
| 3276 | |
| 3277 | /* In the future we should revise the userspace API and allow it |
| 3278 | * to set a flag that it does support multi-channel, then we can |
| 3279 | * let this pass conditionally on the flag. |
| 3280 | * For current userspace, prohibit it since it won't work right. |
| 3281 | */ |
| 3282 | if (chans > 1) |
| 3283 | return -EOPNOTSUPP; |
| 3284 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3285 | if (hwsim_net_get_wmediumd(net)) |
Johannes Berg | 85ca8fc | 2014-01-07 23:21:34 +0100 | [diff] [blame] | 3286 | return -EBUSY; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3287 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3288 | hwsim_register_wmediumd(net, info->snd_portid); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3289 | |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 3290 | pr_debug("mac80211_hwsim: received a REGISTER, " |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3291 | "switching to wmediumd mode with pid %d\n", info->snd_portid); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3292 | |
| 3293 | return 0; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3294 | } |
| 3295 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3296 | static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info) |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3297 | { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3298 | struct hwsim_new_radio_params param = { 0 }; |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3299 | const char *hwname = NULL; |
Ben Hutchings | 67bd523 | 2017-11-10 18:48:50 +0000 | [diff] [blame] | 3300 | int ret; |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3301 | |
| 3302 | param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG]; |
| 3303 | param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE]; |
| 3304 | param.channels = channels; |
| 3305 | param.destroy_on_close = |
| 3306 | info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE]; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3307 | |
| 3308 | if (info->attrs[HWSIM_ATTR_CHANNELS]) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3309 | param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]); |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3310 | |
Johannes Berg | 4840043 | 2018-08-15 18:17:03 +0200 | [diff] [blame] | 3311 | if (param.channels < 1) { |
| 3312 | GENL_SET_ERR_MSG(info, "must have at least one channel"); |
| 3313 | return -EINVAL; |
| 3314 | } |
| 3315 | |
Johannes Berg | 51a1aaa | 2018-01-15 09:32:36 +0100 | [diff] [blame] | 3316 | if (param.channels > CFG80211_MAX_NUM_DIFFERENT_CHANNELS) { |
| 3317 | GENL_SET_ERR_MSG(info, "too many channels specified"); |
| 3318 | return -EINVAL; |
| 3319 | } |
| 3320 | |
Ben Greear | 9a0cb89 | 2014-10-22 12:23:04 -0700 | [diff] [blame] | 3321 | if (info->attrs[HWSIM_ATTR_NO_VIF]) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3322 | param.no_vif = true; |
Ben Greear | 9a0cb89 | 2014-10-22 12:23:04 -0700 | [diff] [blame] | 3323 | |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3324 | if (info->attrs[HWSIM_ATTR_RADIO_NAME]) { |
| 3325 | hwname = kasprintf(GFP_KERNEL, "%.*s", |
| 3326 | nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]), |
| 3327 | (char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME])); |
| 3328 | if (!hwname) |
| 3329 | return -ENOMEM; |
| 3330 | param.hwname = hwname; |
| 3331 | } |
Ben Greear | 5cd8926 | 2014-10-22 12:23:02 -0700 | [diff] [blame] | 3332 | |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 3333 | if (info->attrs[HWSIM_ATTR_USE_CHANCTX]) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3334 | param.use_chanctx = true; |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 3335 | else |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3336 | param.use_chanctx = (param.channels > 1); |
Luciano Coelho | 361c3e0 | 2014-02-10 15:23:03 +0200 | [diff] [blame] | 3337 | |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3338 | if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3339 | param.reg_alpha2 = |
| 3340 | nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]); |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3341 | |
| 3342 | if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) { |
| 3343 | u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]); |
| 3344 | |
weiyongjun (A) | 0ddcff4 | 2018-01-18 02:23:34 +0000 | [diff] [blame] | 3345 | if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom)) { |
| 3346 | kfree(hwname); |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3347 | return -EINVAL; |
weiyongjun (A) | 0ddcff4 | 2018-01-18 02:23:34 +0000 | [diff] [blame] | 3348 | } |
Jinbum Park | 3a2af7c | 2018-07-31 23:10:40 +0900 | [diff] [blame] | 3349 | |
| 3350 | idx = array_index_nospec(idx, |
| 3351 | ARRAY_SIZE(hwsim_world_regdom_custom)); |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3352 | param.regd = hwsim_world_regdom_custom[idx]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3353 | } |
| 3354 | |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 3355 | if (info->attrs[HWSIM_ATTR_PERM_ADDR]) { |
| 3356 | if (!is_valid_ether_addr( |
| 3357 | nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]))) { |
| 3358 | GENL_SET_ERR_MSG(info,"MAC is no valid source addr"); |
| 3359 | NL_SET_BAD_ATTR(info->extack, |
| 3360 | info->attrs[HWSIM_ATTR_PERM_ADDR]); |
YueHaibing | e8f90c7 | 2018-04-24 11:08:35 +0800 | [diff] [blame] | 3361 | kfree(hwname); |
Benjamin Beichler | cb1a5ba | 2018-01-22 18:04:35 +0100 | [diff] [blame] | 3362 | return -EINVAL; |
| 3363 | } |
| 3364 | |
| 3365 | |
| 3366 | param.perm_addr = nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]); |
| 3367 | } |
| 3368 | |
Ben Hutchings | 67bd523 | 2017-11-10 18:48:50 +0000 | [diff] [blame] | 3369 | ret = mac80211_hwsim_new_radio(info, ¶m); |
| 3370 | kfree(hwname); |
| 3371 | return ret; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3372 | } |
| 3373 | |
Jukka Rissanen | 579a05f | 2014-10-31 14:48:48 +0200 | [diff] [blame] | 3374 | static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info) |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3375 | { |
| 3376 | struct mac80211_hwsim_data *data; |
Ben Greear | 8cdd9e1c | 2014-10-22 12:22:59 -0700 | [diff] [blame] | 3377 | s64 idx = -1; |
| 3378 | const char *hwname = NULL; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3379 | |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3380 | if (info->attrs[HWSIM_ATTR_RADIO_ID]) { |
Ben Greear | 8cdd9e1c | 2014-10-22 12:22:59 -0700 | [diff] [blame] | 3381 | idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3382 | } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) { |
| 3383 | hwname = kasprintf(GFP_KERNEL, "%.*s", |
| 3384 | nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]), |
| 3385 | (char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME])); |
| 3386 | if (!hwname) |
| 3387 | return -ENOMEM; |
| 3388 | } else |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3389 | return -EINVAL; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3390 | |
| 3391 | spin_lock_bh(&hwsim_radio_lock); |
| 3392 | list_for_each_entry(data, &hwsim_radios, list) { |
Ben Greear | 8cdd9e1c | 2014-10-22 12:22:59 -0700 | [diff] [blame] | 3393 | if (idx >= 0) { |
| 3394 | if (data->idx != idx) |
| 3395 | continue; |
| 3396 | } else { |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3397 | if (!hwname || |
| 3398 | strcmp(hwname, wiphy_name(data->hw->wiphy))) |
Ben Greear | 8cdd9e1c | 2014-10-22 12:22:59 -0700 | [diff] [blame] | 3399 | continue; |
| 3400 | } |
| 3401 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3402 | if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info))) |
| 3403 | continue; |
| 3404 | |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3405 | list_del(&data->list); |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 3406 | rhashtable_remove_fast(&hwsim_radios_rht, &data->rht, |
| 3407 | hwsim_rht_params); |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3408 | hwsim_radios_generation++; |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3409 | spin_unlock_bh(&hwsim_radio_lock); |
Jukka Rissanen | b9995f8 | 2014-11-14 13:16:34 +0200 | [diff] [blame] | 3410 | mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy), |
| 3411 | info); |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3412 | kfree(hwname); |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3413 | return 0; |
| 3414 | } |
| 3415 | spin_unlock_bh(&hwsim_radio_lock); |
| 3416 | |
Johannes Berg | ff4dd73 | 2017-02-27 17:15:28 +0100 | [diff] [blame] | 3417 | kfree(hwname); |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3418 | return -ENODEV; |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3419 | } |
| 3420 | |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3421 | static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info) |
| 3422 | { |
| 3423 | struct mac80211_hwsim_data *data; |
| 3424 | struct sk_buff *skb; |
| 3425 | int idx, res = -ENODEV; |
| 3426 | |
| 3427 | if (!info->attrs[HWSIM_ATTR_RADIO_ID]) |
| 3428 | return -EINVAL; |
| 3429 | idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); |
| 3430 | |
| 3431 | spin_lock_bh(&hwsim_radio_lock); |
| 3432 | list_for_each_entry(data, &hwsim_radios, list) { |
| 3433 | if (data->idx != idx) |
| 3434 | continue; |
| 3435 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3436 | if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info))) |
| 3437 | continue; |
| 3438 | |
Jia-Ju Bai | 162bd5e | 2017-12-12 17:26:36 +0800 | [diff] [blame] | 3439 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3440 | if (!skb) { |
| 3441 | res = -ENOMEM; |
| 3442 | goto out_err; |
| 3443 | } |
| 3444 | |
| 3445 | res = mac80211_hwsim_get_radio(skb, data, info->snd_portid, |
| 3446 | info->snd_seq, NULL, 0); |
| 3447 | if (res < 0) { |
| 3448 | nlmsg_free(skb); |
| 3449 | goto out_err; |
| 3450 | } |
| 3451 | |
| 3452 | genlmsg_reply(skb, info); |
| 3453 | break; |
| 3454 | } |
| 3455 | |
| 3456 | out_err: |
| 3457 | spin_unlock_bh(&hwsim_radio_lock); |
| 3458 | |
| 3459 | return res; |
| 3460 | } |
| 3461 | |
| 3462 | static int hwsim_dump_radio_nl(struct sk_buff *skb, |
| 3463 | struct netlink_callback *cb) |
| 3464 | { |
Andrew Zaborowski | fed4825 | 2018-05-22 02:43:56 +0200 | [diff] [blame] | 3465 | int last_idx = cb->args[0] - 1; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3466 | struct mac80211_hwsim_data *data = NULL; |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3467 | int res = 0; |
| 3468 | void *hdr; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3469 | |
| 3470 | spin_lock_bh(&hwsim_radio_lock); |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3471 | cb->seq = hwsim_radios_generation; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3472 | |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3473 | if (last_idx >= hwsim_radio_idx-1) |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3474 | goto done; |
| 3475 | |
| 3476 | list_for_each_entry(data, &hwsim_radios, list) { |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3477 | if (data->idx <= last_idx) |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3478 | continue; |
| 3479 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3480 | if (!net_eq(wiphy_net(data->hw->wiphy), sock_net(skb->sk))) |
| 3481 | continue; |
| 3482 | |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3483 | res = mac80211_hwsim_get_radio(skb, data, |
| 3484 | NETLINK_CB(cb->skb).portid, |
| 3485 | cb->nlh->nlmsg_seq, cb, |
| 3486 | NLM_F_MULTI); |
| 3487 | if (res < 0) |
| 3488 | break; |
| 3489 | |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3490 | last_idx = data->idx; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3491 | } |
| 3492 | |
Andrew Zaborowski | fed4825 | 2018-05-22 02:43:56 +0200 | [diff] [blame] | 3493 | cb->args[0] = last_idx + 1; |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3494 | |
| 3495 | /* list changed, but no new element sent, set interrupted flag */ |
| 3496 | if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) { |
| 3497 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, |
| 3498 | cb->nlh->nlmsg_seq, &hwsim_genl_family, |
| 3499 | NLM_F_MULTI, HWSIM_CMD_GET_RADIO); |
| 3500 | if (!hdr) |
| 3501 | res = -EMSGSIZE; |
| 3502 | genl_dump_check_consistent(cb, hdr); |
| 3503 | genlmsg_end(skb, hdr); |
| 3504 | } |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3505 | |
| 3506 | done: |
| 3507 | spin_unlock_bh(&hwsim_radio_lock); |
Benjamin Beichler | 6335698 | 2018-01-22 18:04:37 +0100 | [diff] [blame] | 3508 | return res ?: skb->len; |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3509 | } |
| 3510 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3511 | /* Generic Netlink operations array */ |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 3512 | static const struct genl_ops hwsim_ops[] = { |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3513 | { |
| 3514 | .cmd = HWSIM_CMD_REGISTER, |
| 3515 | .policy = hwsim_genl_policy, |
| 3516 | .doit = hwsim_register_received_nl, |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3517 | .flags = GENL_UNS_ADMIN_PERM, |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3518 | }, |
| 3519 | { |
| 3520 | .cmd = HWSIM_CMD_FRAME, |
| 3521 | .policy = hwsim_genl_policy, |
| 3522 | .doit = hwsim_cloned_frame_received_nl, |
| 3523 | }, |
| 3524 | { |
| 3525 | .cmd = HWSIM_CMD_TX_INFO_FRAME, |
| 3526 | .policy = hwsim_genl_policy, |
| 3527 | .doit = hwsim_tx_info_frame_received_nl, |
| 3528 | }, |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3529 | { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3530 | .cmd = HWSIM_CMD_NEW_RADIO, |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3531 | .policy = hwsim_genl_policy, |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3532 | .doit = hwsim_new_radio_nl, |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3533 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3534 | }, |
| 3535 | { |
Jukka Rissanen | 579a05f | 2014-10-31 14:48:48 +0200 | [diff] [blame] | 3536 | .cmd = HWSIM_CMD_DEL_RADIO, |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3537 | .policy = hwsim_genl_policy, |
Jukka Rissanen | 579a05f | 2014-10-31 14:48:48 +0200 | [diff] [blame] | 3538 | .doit = hwsim_del_radio_nl, |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3539 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3540 | }, |
Patrik Flykt | 93d638d | 2014-11-12 16:42:40 +0200 | [diff] [blame] | 3541 | { |
| 3542 | .cmd = HWSIM_CMD_GET_RADIO, |
| 3543 | .policy = hwsim_genl_policy, |
| 3544 | .doit = hwsim_get_radio_nl, |
| 3545 | .dumpit = hwsim_dump_radio_nl, |
| 3546 | }, |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3547 | }; |
| 3548 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 3549 | static struct genl_family hwsim_genl_family __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 3550 | .name = "MAC80211_HWSIM", |
| 3551 | .version = 1, |
| 3552 | .maxattr = HWSIM_ATTR_MAX, |
| 3553 | .netnsok = true, |
| 3554 | .module = THIS_MODULE, |
| 3555 | .ops = hwsim_ops, |
| 3556 | .n_ops = ARRAY_SIZE(hwsim_ops), |
| 3557 | .mcgrps = hwsim_mcgrps, |
| 3558 | .n_mcgrps = ARRAY_SIZE(hwsim_mcgrps), |
| 3559 | }; |
| 3560 | |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 3561 | static void remove_user_radios(u32 portid) |
| 3562 | { |
| 3563 | struct mac80211_hwsim_data *entry, *tmp; |
Martin Willi | f1c47eb | 2018-09-25 09:41:14 +0200 | [diff] [blame] | 3564 | LIST_HEAD(list); |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 3565 | |
| 3566 | spin_lock_bh(&hwsim_radio_lock); |
| 3567 | list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) { |
| 3568 | if (entry->destroy_on_close && entry->portid == portid) { |
Martin Willi | f1c47eb | 2018-09-25 09:41:14 +0200 | [diff] [blame] | 3569 | list_move(&entry->list, &list); |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 3570 | rhashtable_remove_fast(&hwsim_radios_rht, &entry->rht, |
| 3571 | hwsim_rht_params); |
Martin Willi | f1c47eb | 2018-09-25 09:41:14 +0200 | [diff] [blame] | 3572 | hwsim_radios_generation++; |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 3573 | } |
| 3574 | } |
| 3575 | spin_unlock_bh(&hwsim_radio_lock); |
Martin Willi | f1c47eb | 2018-09-25 09:41:14 +0200 | [diff] [blame] | 3576 | |
| 3577 | list_for_each_entry_safe(entry, tmp, &list, list) { |
| 3578 | list_del(&entry->list); |
| 3579 | mac80211_hwsim_del_radio(entry, wiphy_name(entry->hw->wiphy), |
| 3580 | NULL); |
| 3581 | } |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 3582 | } |
| 3583 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3584 | static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, |
| 3585 | unsigned long state, |
| 3586 | void *_notify) |
| 3587 | { |
| 3588 | struct netlink_notify *notify = _notify; |
| 3589 | |
| 3590 | if (state != NETLINK_URELEASE) |
| 3591 | return NOTIFY_DONE; |
| 3592 | |
Jukka Rissanen | e9ed49b | 2014-10-09 15:27:51 +0300 | [diff] [blame] | 3593 | remove_user_radios(notify->portid); |
| 3594 | |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3595 | if (notify->portid == hwsim_net_get_wmediumd(notify->net)) { |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3596 | printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink" |
| 3597 | " socket, switching to perfect channel medium\n"); |
Martin Willi | f21e4d8 | 2016-05-14 10:34:44 +0200 | [diff] [blame] | 3598 | hwsim_register_wmediumd(notify->net, 0); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3599 | } |
| 3600 | return NOTIFY_DONE; |
| 3601 | |
| 3602 | } |
| 3603 | |
| 3604 | static struct notifier_block hwsim_netlink_notifier = { |
| 3605 | .notifier_call = mac80211_hwsim_netlink_notify, |
| 3606 | }; |
| 3607 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 3608 | static int __init hwsim_init_netlink(void) |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3609 | { |
| 3610 | int rc; |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 3611 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3612 | printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); |
| 3613 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 3614 | rc = genl_register_family(&hwsim_genl_family); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3615 | if (rc) |
| 3616 | goto failure; |
| 3617 | |
| 3618 | rc = netlink_register_notifier(&hwsim_netlink_notifier); |
Su Kang Yin | 2459cd8 | 2015-08-07 16:54:10 +0800 | [diff] [blame] | 3619 | if (rc) { |
| 3620 | genl_unregister_family(&hwsim_genl_family); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3621 | goto failure; |
Su Kang Yin | 2459cd8 | 2015-08-07 16:54:10 +0800 | [diff] [blame] | 3622 | } |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3623 | |
| 3624 | return 0; |
| 3625 | |
| 3626 | failure: |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 3627 | pr_debug("mac80211_hwsim: error occurred in %s\n", __func__); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3628 | return -EINVAL; |
| 3629 | } |
| 3630 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3631 | static __net_init int hwsim_init_net(struct net *net) |
| 3632 | { |
Kirill Tkhai | 0369554 | 2018-03-01 14:30:09 +0300 | [diff] [blame] | 3633 | return hwsim_net_set_netgroup(net); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | static void __net_exit hwsim_exit_net(struct net *net) |
| 3637 | { |
| 3638 | struct mac80211_hwsim_data *data, *tmp; |
Martin Willi | 628980e | 2018-09-25 09:41:13 +0200 | [diff] [blame] | 3639 | LIST_HEAD(list); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3640 | |
| 3641 | spin_lock_bh(&hwsim_radio_lock); |
| 3642 | list_for_each_entry_safe(data, tmp, &hwsim_radios, list) { |
| 3643 | if (!net_eq(wiphy_net(data->hw->wiphy), net)) |
| 3644 | continue; |
| 3645 | |
| 3646 | /* Radios created in init_net are returned to init_net. */ |
| 3647 | if (data->netgroup == hwsim_net_get_netgroup(&init_net)) |
| 3648 | continue; |
| 3649 | |
Martin Willi | 628980e | 2018-09-25 09:41:13 +0200 | [diff] [blame] | 3650 | list_move(&data->list, &list); |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 3651 | rhashtable_remove_fast(&hwsim_radios_rht, &data->rht, |
| 3652 | hwsim_rht_params); |
Benjamin Beichler | 8cfd36a | 2018-03-07 18:11:07 +0100 | [diff] [blame] | 3653 | hwsim_radios_generation++; |
Martin Willi | 628980e | 2018-09-25 09:41:13 +0200 | [diff] [blame] | 3654 | } |
| 3655 | spin_unlock_bh(&hwsim_radio_lock); |
| 3656 | |
| 3657 | list_for_each_entry_safe(data, tmp, &list, list) { |
| 3658 | list_del(&data->list); |
Benjamin Beichler | 8cfd36a | 2018-03-07 18:11:07 +0100 | [diff] [blame] | 3659 | mac80211_hwsim_del_radio(data, |
| 3660 | wiphy_name(data->hw->wiphy), |
| 3661 | NULL); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3662 | } |
Kirill Tkhai | 0369554 | 2018-03-01 14:30:09 +0300 | [diff] [blame] | 3663 | |
| 3664 | ida_simple_remove(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net)); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | static struct pernet_operations hwsim_net_ops = { |
| 3668 | .init = hwsim_init_net, |
| 3669 | .exit = hwsim_exit_net, |
| 3670 | .id = &hwsim_net_id, |
| 3671 | .size = sizeof(struct hwsim_net), |
| 3672 | }; |
| 3673 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3674 | static void hwsim_exit_netlink(void) |
| 3675 | { |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3676 | /* unregister the notifier */ |
| 3677 | netlink_unregister_notifier(&hwsim_netlink_notifier); |
| 3678 | /* unregister the family */ |
Johannes Berg | cf7a6b2 | 2014-01-06 21:55:14 +0100 | [diff] [blame] | 3679 | genl_unregister_family(&hwsim_genl_family); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3680 | } |
| 3681 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3682 | static int __init init_mac80211_hwsim(void) |
| 3683 | { |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3684 | int i, err; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3685 | |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3686 | if (radios < 0 || radios > 100) |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3687 | return -EINVAL; |
| 3688 | |
Johannes Berg | e826117 | 2012-07-27 19:48:26 +0200 | [diff] [blame] | 3689 | if (channels < 1) |
| 3690 | return -EINVAL; |
| 3691 | |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 3692 | spin_lock_init(&hwsim_radio_lock); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3693 | |
Johannes Berg | 3f61b7a | 2018-05-29 12:04:51 +0200 | [diff] [blame] | 3694 | err = rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params); |
| 3695 | if (err) |
Martin Willi | 1edcfc2 | 2018-09-25 09:41:15 +0200 | [diff] [blame] | 3696 | return err; |
Benjamin Beichler | b71d856 | 2018-01-10 17:42:51 +0100 | [diff] [blame] | 3697 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3698 | err = register_pernet_device(&hwsim_net_ops); |
Martin Pitt | 9ea92774 | 2013-04-08 11:30:01 +0200 | [diff] [blame] | 3699 | if (err) |
Johannes Berg | 3f61b7a | 2018-05-29 12:04:51 +0200 | [diff] [blame] | 3700 | goto out_free_rht; |
Martin Pitt | 9ea92774 | 2013-04-08 11:30:01 +0200 | [diff] [blame] | 3701 | |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3702 | err = platform_driver_register(&mac80211_hwsim_driver); |
| 3703 | if (err) |
| 3704 | goto out_unregister_pernet; |
| 3705 | |
Alexey Khoroshilov | 05cc09d | 2018-10-05 23:22:06 +0300 | [diff] [blame] | 3706 | err = hwsim_init_netlink(); |
| 3707 | if (err) |
| 3708 | goto out_unregister_driver; |
| 3709 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3710 | hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim"); |
Martin Pitt | 9ea92774 | 2013-04-08 11:30:01 +0200 | [diff] [blame] | 3711 | if (IS_ERR(hwsim_class)) { |
| 3712 | err = PTR_ERR(hwsim_class); |
Alexey Khoroshilov | 05cc09d | 2018-10-05 23:22:06 +0300 | [diff] [blame] | 3713 | goto out_exit_netlink; |
Martin Pitt | 9ea92774 | 2013-04-08 11:30:01 +0200 | [diff] [blame] | 3714 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3715 | |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 3716 | for (i = 0; i < radios; i++) { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3717 | struct hwsim_new_radio_params param = { 0 }; |
| 3718 | |
| 3719 | param.channels = channels; |
Johannes Berg | 0e057d73 | 2008-09-12 00:39:22 +0200 | [diff] [blame] | 3720 | |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3721 | switch (regtest) { |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3722 | case HWSIM_REGTEST_DIFF_COUNTRY: |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3723 | if (i < ARRAY_SIZE(hwsim_alpha2s)) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3724 | param.reg_alpha2 = hwsim_alpha2s[i]; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3725 | break; |
| 3726 | case HWSIM_REGTEST_DRIVER_REG_FOLLOW: |
| 3727 | if (!i) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3728 | param.reg_alpha2 = hwsim_alpha2s[0]; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3729 | break; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3730 | case HWSIM_REGTEST_STRICT_ALL: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3731 | param.reg_strict = true; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3732 | case HWSIM_REGTEST_DRIVER_REG_ALL: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3733 | param.reg_alpha2 = hwsim_alpha2s[0]; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3734 | break; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3735 | case HWSIM_REGTEST_WORLD_ROAM: |
| 3736 | if (i == 0) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3737 | param.regd = &hwsim_world_regdom_custom_01; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3738 | break; |
| 3739 | case HWSIM_REGTEST_CUSTOM_WORLD: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3740 | param.regd = &hwsim_world_regdom_custom_01; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3741 | break; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3742 | case HWSIM_REGTEST_CUSTOM_WORLD_2: |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3743 | if (i == 0) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3744 | param.regd = &hwsim_world_regdom_custom_01; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3745 | else if (i == 1) |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3746 | param.regd = &hwsim_world_regdom_custom_02; |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3747 | break; |
| 3748 | case HWSIM_REGTEST_STRICT_FOLLOW: |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3749 | if (i == 0) { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3750 | param.reg_strict = true; |
| 3751 | param.reg_alpha2 = hwsim_alpha2s[0]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3752 | } |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3753 | break; |
| 3754 | case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3755 | if (i == 0) { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3756 | param.reg_strict = true; |
| 3757 | param.reg_alpha2 = hwsim_alpha2s[0]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3758 | } else if (i == 1) { |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3759 | param.reg_alpha2 = hwsim_alpha2s[1]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3760 | } |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3761 | break; |
| 3762 | case HWSIM_REGTEST_ALL: |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3763 | switch (i) { |
| 3764 | case 0: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3765 | param.regd = &hwsim_world_regdom_custom_01; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3766 | break; |
| 3767 | case 1: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3768 | param.regd = &hwsim_world_regdom_custom_02; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3769 | break; |
| 3770 | case 2: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3771 | param.reg_alpha2 = hwsim_alpha2s[0]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3772 | break; |
| 3773 | case 3: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3774 | param.reg_alpha2 = hwsim_alpha2s[1]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3775 | break; |
| 3776 | case 4: |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3777 | param.reg_strict = true; |
| 3778 | param.reg_alpha2 = hwsim_alpha2s[2]; |
Johannes Berg | 26b0e41 | 2014-01-10 13:37:38 +0100 | [diff] [blame] | 3779 | break; |
| 3780 | } |
Luis R. Rodriguez | 4a5af9c | 2009-03-09 22:08:27 -0400 | [diff] [blame] | 3781 | break; |
| 3782 | default: |
| 3783 | break; |
| 3784 | } |
| 3785 | |
Jukka Rissanen | 6275936 | 2014-10-31 14:48:47 +0200 | [diff] [blame] | 3786 | param.p2p_device = support_p2p_device; |
| 3787 | param.use_chanctx = channels > 1; |
| 3788 | |
| 3789 | err = mac80211_hwsim_new_radio(NULL, ¶m); |
Johannes Berg | bc791098 | 2014-01-06 23:29:20 +0100 | [diff] [blame] | 3790 | if (err < 0) |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3791 | goto out_free_radios; |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3792 | } |
| 3793 | |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 3794 | hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN, |
| 3795 | hwsim_mon_setup); |
Wei Yongjun | bcdd822 | 2013-08-26 15:32:58 +0800 | [diff] [blame] | 3796 | if (hwsim_mon == NULL) { |
| 3797 | err = -ENOMEM; |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3798 | goto out_free_radios; |
Wei Yongjun | bcdd822 | 2013-08-26 15:32:58 +0800 | [diff] [blame] | 3799 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3800 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3801 | rtnl_lock(); |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3802 | err = dev_alloc_name(hwsim_mon, hwsim_mon->name); |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3803 | if (err < 0) { |
| 3804 | rtnl_unlock(); |
| 3805 | goto out_free_radios; |
| 3806 | } |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3807 | |
| 3808 | err = register_netdevice(hwsim_mon); |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3809 | if (err < 0) { |
| 3810 | rtnl_unlock(); |
| 3811 | goto out_free_mon; |
| 3812 | } |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3813 | rtnl_unlock(); |
| 3814 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3815 | return 0; |
| 3816 | |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3817 | out_free_mon: |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3818 | free_netdev(hwsim_mon); |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3819 | out_free_radios: |
Ian Schram | 3a33cc1 | 2008-07-21 13:19:35 -0700 | [diff] [blame] | 3820 | mac80211_hwsim_free(); |
Alexey Khoroshilov | 05cc09d | 2018-10-05 23:22:06 +0300 | [diff] [blame] | 3821 | out_exit_netlink: |
| 3822 | hwsim_exit_netlink(); |
Johannes Berg | f39c2bf | 2014-01-06 22:39:27 +0100 | [diff] [blame] | 3823 | out_unregister_driver: |
Sasha Levin | c07fe5a | 2013-04-24 00:40:05 -0400 | [diff] [blame] | 3824 | platform_driver_unregister(&mac80211_hwsim_driver); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3825 | out_unregister_pernet: |
| 3826 | unregister_pernet_device(&hwsim_net_ops); |
Johannes Berg | 3f61b7a | 2018-05-29 12:04:51 +0200 | [diff] [blame] | 3827 | out_free_rht: |
| 3828 | rhashtable_destroy(&hwsim_radios_rht); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3829 | return err; |
| 3830 | } |
Johannes Berg | f8fffc7 | 2012-07-27 15:16:02 +0200 | [diff] [blame] | 3831 | module_init(init_mac80211_hwsim); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3832 | |
| 3833 | static void __exit exit_mac80211_hwsim(void) |
| 3834 | { |
Lubomir Rintel | 62b093b | 2017-09-18 15:56:51 +0200 | [diff] [blame] | 3835 | pr_debug("mac80211_hwsim: unregister radios\n"); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3836 | |
Javier Lopez | 7882513 | 2011-06-01 11:26:13 +0200 | [diff] [blame] | 3837 | hwsim_exit_netlink(); |
| 3838 | |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3839 | mac80211_hwsim_free(); |
Benjamin Beichler | b71d856 | 2018-01-10 17:42:51 +0100 | [diff] [blame] | 3840 | |
Benjamin Beichler | c6509cc | 2018-01-10 17:42:52 +0100 | [diff] [blame] | 3841 | rhashtable_destroy(&hwsim_radios_rht); |
Johannes Berg | 5d41635 | 2009-07-13 13:04:30 +0200 | [diff] [blame] | 3842 | unregister_netdev(hwsim_mon); |
Sasha Levin | c07fe5a | 2013-04-24 00:40:05 -0400 | [diff] [blame] | 3843 | platform_driver_unregister(&mac80211_hwsim_driver); |
Martin Willi | 100cb9f | 2016-05-09 18:33:59 +0200 | [diff] [blame] | 3844 | unregister_pernet_device(&hwsim_net_ops); |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3845 | } |
Jouni Malinen | acc1e7a | 2008-06-11 10:42:31 +0300 | [diff] [blame] | 3846 | module_exit(exit_mac80211_hwsim); |