1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * This is the new netlink-based wireless configuration interface. 4 * 5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> 6 * Copyright 2013-2014 Intel Mobile Communications GmbH 7 * Copyright 2015-2017 Intel Deutschland GmbH 8 * Copyright (C) 2018-2021 Intel Corporation 9 */ 10 11 #include <linux/if.h> 12 #include <linux/module.h> 13 #include <linux/err.h> 14 #include <linux/slab.h> 15 #include <linux/list.h> 16 #include <linux/if_ether.h> 17 #include <linux/ieee80211.h> 18 #include <linux/nl80211.h> 19 #include <linux/rtnetlink.h> 20 #include <linux/netlink.h> 21 #include <linux/nospec.h> 22 #include <linux/etherdevice.h> 23 #include <linux/if_vlan.h> 24 #include <net/net_namespace.h> 25 #include <net/genetlink.h> 26 #include <net/cfg80211.h> 27 #include <net/sock.h> 28 #include <net/inet_connection_sock.h> 29 #include "core.h" 30 #include "nl80211.h" 31 #include "reg.h" 32 #include "rdev-ops.h" 33 34 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 35 struct genl_info *info, 36 struct cfg80211_crypto_settings *settings, 37 int cipher_limit); 38 39 /* the netlink family */ 40 static struct genl_family nl80211_fam; 41 42 /* multicast groups */ 43 enum nl80211_multicast_groups { 44 NL80211_MCGRP_CONFIG, 45 NL80211_MCGRP_SCAN, 46 NL80211_MCGRP_REGULATORY, 47 NL80211_MCGRP_MLME, 48 NL80211_MCGRP_VENDOR, 49 NL80211_MCGRP_NAN, 50 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ 51 }; 52 53 static const struct genl_multicast_group nl80211_mcgrps[] = { 54 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, 55 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, 56 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, 57 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, 58 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, 59 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, 60 #ifdef CONFIG_NL80211_TESTMODE 61 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } 62 #endif 63 }; 64 65 /* returns ERR_PTR values */ 66 static struct wireless_dev * 67 __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, 68 struct net *netns, struct nlattr **attrs) 69 { 70 struct wireless_dev *result = NULL; 71 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; 72 bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; 73 u64 wdev_id = 0; 74 int wiphy_idx = -1; 75 int ifidx = -1; 76 77 if (!have_ifidx && !have_wdev_id) 78 return ERR_PTR(-EINVAL); 79 80 if (have_ifidx) 81 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 82 if (have_wdev_id) { 83 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 84 wiphy_idx = wdev_id >> 32; 85 } 86 87 if (rdev) { 88 struct wireless_dev *wdev; 89 90 lockdep_assert_held(&rdev->wiphy.mtx); 91 92 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 93 if (have_ifidx && wdev->netdev && 94 wdev->netdev->ifindex == ifidx) { 95 result = wdev; 96 break; 97 } 98 if (have_wdev_id && wdev->identifier == (u32)wdev_id) { 99 result = wdev; 100 break; 101 } 102 } 103 104 return result ?: ERR_PTR(-ENODEV); 105 } 106 107 ASSERT_RTNL(); 108 109 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 110 struct wireless_dev *wdev; 111 112 if (wiphy_net(&rdev->wiphy) != netns) 113 continue; 114 115 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) 116 continue; 117 118 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 119 if (have_ifidx && wdev->netdev && 120 wdev->netdev->ifindex == ifidx) { 121 result = wdev; 122 break; 123 } 124 if (have_wdev_id && wdev->identifier == (u32)wdev_id) { 125 result = wdev; 126 break; 127 } 128 } 129 130 if (result) 131 break; 132 } 133 134 if (result) 135 return result; 136 return ERR_PTR(-ENODEV); 137 } 138 139 static struct cfg80211_registered_device * 140 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) 141 { 142 struct cfg80211_registered_device *rdev = NULL, *tmp; 143 struct net_device *netdev; 144 145 ASSERT_RTNL(); 146 147 if (!attrs[NL80211_ATTR_WIPHY] && 148 !attrs[NL80211_ATTR_IFINDEX] && 149 !attrs[NL80211_ATTR_WDEV]) 150 return ERR_PTR(-EINVAL); 151 152 if (attrs[NL80211_ATTR_WIPHY]) 153 rdev = cfg80211_rdev_by_wiphy_idx( 154 nla_get_u32(attrs[NL80211_ATTR_WIPHY])); 155 156 if (attrs[NL80211_ATTR_WDEV]) { 157 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 158 struct wireless_dev *wdev; 159 bool found = false; 160 161 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); 162 if (tmp) { 163 /* make sure wdev exists */ 164 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { 165 if (wdev->identifier != (u32)wdev_id) 166 continue; 167 found = true; 168 break; 169 } 170 171 if (!found) 172 tmp = NULL; 173 174 if (rdev && tmp != rdev) 175 return ERR_PTR(-EINVAL); 176 rdev = tmp; 177 } 178 } 179 180 if (attrs[NL80211_ATTR_IFINDEX]) { 181 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 182 183 netdev = __dev_get_by_index(netns, ifindex); 184 if (netdev) { 185 if (netdev->ieee80211_ptr) 186 tmp = wiphy_to_rdev( 187 netdev->ieee80211_ptr->wiphy); 188 else 189 tmp = NULL; 190 191 /* not wireless device -- return error */ 192 if (!tmp) 193 return ERR_PTR(-EINVAL); 194 195 /* mismatch -- return error */ 196 if (rdev && tmp != rdev) 197 return ERR_PTR(-EINVAL); 198 199 rdev = tmp; 200 } 201 } 202 203 if (!rdev) 204 return ERR_PTR(-ENODEV); 205 206 if (netns != wiphy_net(&rdev->wiphy)) 207 return ERR_PTR(-ENODEV); 208 209 return rdev; 210 } 211 212 /* 213 * This function returns a pointer to the driver 214 * that the genl_info item that is passed refers to. 215 * 216 * The result of this can be a PTR_ERR and hence must 217 * be checked with IS_ERR() for errors. 218 */ 219 static struct cfg80211_registered_device * 220 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) 221 { 222 return __cfg80211_rdev_from_attrs(netns, info->attrs); 223 } 224 225 static int validate_beacon_head(const struct nlattr *attr, 226 struct netlink_ext_ack *extack) 227 { 228 const u8 *data = nla_data(attr); 229 unsigned int len = nla_len(attr); 230 const struct element *elem; 231 const struct ieee80211_mgmt *mgmt = (void *)data; 232 unsigned int fixedlen, hdrlen; 233 bool s1g_bcn; 234 235 if (len < offsetofend(typeof(*mgmt), frame_control)) 236 goto err; 237 238 s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); 239 if (s1g_bcn) { 240 fixedlen = offsetof(struct ieee80211_ext, 241 u.s1g_beacon.variable); 242 hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); 243 } else { 244 fixedlen = offsetof(struct ieee80211_mgmt, 245 u.beacon.variable); 246 hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); 247 } 248 249 if (len < fixedlen) 250 goto err; 251 252 if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) 253 goto err; 254 255 data += fixedlen; 256 len -= fixedlen; 257 258 for_each_element(elem, data, len) { 259 /* nothing */ 260 } 261 262 if (for_each_element_completed(elem, data, len)) 263 return 0; 264 265 err: 266 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); 267 return -EINVAL; 268 } 269 270 static int validate_ie_attr(const struct nlattr *attr, 271 struct netlink_ext_ack *extack) 272 { 273 const u8 *data = nla_data(attr); 274 unsigned int len = nla_len(attr); 275 const struct element *elem; 276 277 for_each_element(elem, data, len) { 278 /* nothing */ 279 } 280 281 if (for_each_element_completed(elem, data, len)) 282 return 0; 283 284 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); 285 return -EINVAL; 286 } 287 288 /* policy for the attributes */ 289 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; 290 291 static const struct nla_policy 292 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { 293 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, 294 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, 295 .len = U8_MAX }, 296 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, 297 .len = U8_MAX }, 298 }; 299 300 static const struct nla_policy 301 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { 302 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, 303 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, 304 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = 305 NLA_POLICY_MAX(NLA_U8, 15), 306 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, 307 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = 308 NLA_POLICY_MAX(NLA_U8, 15), 309 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = 310 NLA_POLICY_MAX(NLA_U8, 31), 311 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, 312 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, 313 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, 314 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, 315 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, 316 [NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK] = { .type = NLA_FLAG }, 317 }; 318 319 static const struct nla_policy 320 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { 321 [NL80211_PMSR_TYPE_FTM] = 322 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), 323 }; 324 325 static const struct nla_policy 326 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { 327 [NL80211_PMSR_REQ_ATTR_DATA] = 328 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), 329 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, 330 }; 331 332 static const struct nla_policy 333 nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { 334 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, 335 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), 336 [NL80211_PMSR_PEER_ATTR_REQ] = 337 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), 338 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, 339 }; 340 341 static const struct nla_policy 342 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { 343 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, 344 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, 345 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, 346 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, 347 [NL80211_PMSR_ATTR_PEERS] = 348 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), 349 }; 350 351 static const struct nla_policy 352 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { 353 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = 354 NLA_POLICY_RANGE(NLA_U8, 1, 20), 355 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = 356 NLA_POLICY_RANGE(NLA_U8, 1, 20), 357 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = 358 NLA_POLICY_RANGE(NLA_U8, 1, 20), 359 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = 360 NLA_POLICY_EXACT_LEN(8), 361 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = 362 NLA_POLICY_EXACT_LEN(8), 363 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, 364 }; 365 366 static const struct nla_policy 367 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { 368 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), 369 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, 370 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, 371 }; 372 373 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { 374 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, 375 .len = NL80211_MAX_SUPP_RATES }, 376 [NL80211_TXRATE_HT] = { .type = NLA_BINARY, 377 .len = NL80211_MAX_SUPP_HT_RATES }, 378 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), 379 [NL80211_TXRATE_GI] = { .type = NLA_U8 }, 380 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), 381 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, 382 NL80211_RATE_INFO_HE_GI_0_8, 383 NL80211_RATE_INFO_HE_GI_3_2), 384 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, 385 NL80211_RATE_INFO_HE_1XLTF, 386 NL80211_RATE_INFO_HE_4XLTF), 387 }; 388 389 static const struct nla_policy 390 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { 391 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, 392 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, 393 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, 394 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), 395 [NL80211_TID_CONFIG_ATTR_NOACK] = 396 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 397 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 398 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 399 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = 400 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 401 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = 402 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 403 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = 404 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 405 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = 406 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), 407 [NL80211_TID_CONFIG_ATTR_TX_RATE] = 408 NLA_POLICY_NESTED(nl80211_txattr_policy), 409 }; 410 411 static const struct nla_policy 412 nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { 413 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), 414 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), 415 [NL80211_FILS_DISCOVERY_ATTR_TMPL] = 416 NLA_POLICY_RANGE(NLA_BINARY, 417 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, 418 IEEE80211_MAX_DATA_LEN), 419 }; 420 421 static const struct nla_policy 422 nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { 423 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), 424 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, 425 .len = IEEE80211_MAX_DATA_LEN } 426 }; 427 428 static const struct nla_policy 429 sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = { 430 [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 }, 431 [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 }, 432 }; 433 434 static const struct nla_policy 435 sar_policy[NL80211_SAR_ATTR_MAX + 1] = { 436 [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE), 437 [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy), 438 }; 439 440 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { 441 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, 442 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 443 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 444 .len = 20-1 }, 445 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, 446 447 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, 448 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, 449 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, 450 NL80211_EDMG_CHANNELS_MIN, 451 NL80211_EDMG_CHANNELS_MAX), 452 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, 453 NL80211_EDMG_BW_CONFIG_MIN, 454 NL80211_EDMG_BW_CONFIG_MAX), 455 456 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, 457 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, 458 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 459 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, 460 461 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 462 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 463 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, 464 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, 465 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, 466 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, 467 468 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), 469 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 470 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, 471 472 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 473 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 474 475 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, 476 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, 477 .len = WLAN_MAX_KEY_LEN }, 478 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), 479 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, 480 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, 481 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 482 [NL80211_ATTR_KEY_TYPE] = 483 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), 484 485 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 486 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 487 [NL80211_ATTR_BEACON_HEAD] = 488 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, 489 IEEE80211_MAX_DATA_LEN), 490 [NL80211_ATTR_BEACON_TAIL] = 491 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 492 IEEE80211_MAX_DATA_LEN), 493 [NL80211_ATTR_STA_AID] = 494 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 495 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, 496 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, 497 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, 498 .len = NL80211_MAX_SUPP_RATES }, 499 [NL80211_ATTR_STA_PLINK_ACTION] = 500 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), 501 [NL80211_ATTR_STA_TX_POWER_SETTING] = 502 NLA_POLICY_RANGE(NLA_U8, 503 NL80211_TX_POWER_AUTOMATIC, 504 NL80211_TX_POWER_FIXED), 505 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, 506 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 507 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 508 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 509 .len = IEEE80211_MAX_MESH_ID_LEN }, 510 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, 511 512 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, 513 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, 514 515 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 516 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 517 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 518 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 519 .len = NL80211_MAX_SUPP_RATES }, 520 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, 521 522 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, 523 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, 524 525 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), 526 527 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, 528 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, 529 validate_ie_attr, 530 IEEE80211_MAX_DATA_LEN), 531 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, 532 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, 533 534 [NL80211_ATTR_SSID] = { .type = NLA_BINARY, 535 .len = IEEE80211_MAX_SSID_LEN }, 536 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, 537 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, 538 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, 539 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, 540 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, 541 NL80211_MFP_NO, 542 NL80211_MFP_OPTIONAL), 543 [NL80211_ATTR_STA_FLAGS2] = { 544 .len = sizeof(struct nl80211_sta_flag_update), 545 }, 546 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 547 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, 548 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, 549 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, 550 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, 551 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, 552 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 553 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 554 [NL80211_ATTR_PID] = { .type = NLA_U32 }, 555 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, 556 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), 557 [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, 558 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, 559 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, 560 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, 561 .len = IEEE80211_MAX_DATA_LEN }, 562 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, 563 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, 564 NL80211_PS_DISABLED, 565 NL80211_PS_ENABLED), 566 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, 567 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, 568 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, 569 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, 570 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, 571 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, 572 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, 573 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, 574 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, 575 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, 576 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 577 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, 578 [NL80211_ATTR_STA_PLINK_STATE] = 579 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), 580 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, 581 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, 582 [NL80211_ATTR_MESH_PEER_AID] = 583 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 584 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, 585 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, 586 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, 587 [NL80211_ATTR_HIDDEN_SSID] = 588 NLA_POLICY_RANGE(NLA_U32, 589 NL80211_HIDDEN_SSID_NOT_IN_USE, 590 NL80211_HIDDEN_SSID_ZERO_CONTENTS), 591 [NL80211_ATTR_IE_PROBE_RESP] = 592 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 593 IEEE80211_MAX_DATA_LEN), 594 [NL80211_ATTR_IE_ASSOC_RESP] = 595 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 596 IEEE80211_MAX_DATA_LEN), 597 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, 598 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, 599 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, 600 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, 601 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, 602 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, 603 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, 604 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, 605 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, 606 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, 607 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, 608 .len = IEEE80211_MAX_DATA_LEN }, 609 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, 610 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, 611 [NL80211_ATTR_HT_CAPABILITY_MASK] = { 612 .len = NL80211_HT_CAPABILITY_LEN 613 }, 614 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, 615 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, 616 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, 617 [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, 618 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, 619 620 /* need to include at least Auth Transaction and Status Code */ 621 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), 622 623 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), 624 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, 625 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), 626 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), 627 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = 628 NLA_POLICY_RANGE(NLA_U32, 629 NL80211_MESH_POWER_UNKNOWN + 1, 630 NL80211_MESH_POWER_MAX), 631 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, 632 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, 633 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, 634 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, 635 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, 636 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, 637 [NL80211_ATTR_VHT_CAPABILITY_MASK] = { 638 .len = NL80211_VHT_CAPABILITY_LEN, 639 }, 640 [NL80211_ATTR_MDID] = { .type = NLA_U16 }, 641 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, 642 .len = IEEE80211_MAX_DATA_LEN }, 643 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, 644 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = 645 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), 646 [NL80211_ATTR_PEER_AID] = 647 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 648 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, 649 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, 650 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, 651 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, 652 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, 653 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), 654 /* 655 * The value of the Length field of the Supported Operating 656 * Classes element is between 2 and 253. 657 */ 658 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = 659 NLA_POLICY_RANGE(NLA_BINARY, 2, 253), 660 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, 661 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, 662 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, 663 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, 664 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, 665 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, 666 IEEE80211_QOS_MAP_LEN_MIN, 667 IEEE80211_QOS_MAP_LEN_MAX), 668 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 669 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, 670 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, 671 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, 672 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, 673 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, 674 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), 675 [NL80211_ATTR_USER_PRIO] = 676 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), 677 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, 678 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, 679 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, 680 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 681 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, 682 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, 683 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, 684 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, 685 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, 686 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, 687 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = 688 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), 689 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { 690 .len = VHT_MUMIMO_GROUPS_DATA_LEN 691 }, 692 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 693 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), 694 [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, 695 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, 696 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, 697 .len = FILS_MAX_KEK_LEN }, 698 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), 699 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, 700 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 701 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, 702 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { 703 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 704 }, 705 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, 706 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, 707 .len = FILS_ERP_MAX_USERNAME_LEN }, 708 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, 709 .len = FILS_ERP_MAX_REALM_LEN }, 710 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, 711 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, 712 .len = FILS_ERP_MAX_RRK_LEN }, 713 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), 714 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, 715 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), 716 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, 717 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, 718 719 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, 720 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, 721 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, 722 [NL80211_ATTR_HE_CAPABILITY] = 723 NLA_POLICY_RANGE(NLA_BINARY, 724 NL80211_HE_MIN_CAPABILITY_LEN, 725 NL80211_HE_MAX_CAPABILITY_LEN), 726 [NL80211_ATTR_FTM_RESPONDER] = 727 NLA_POLICY_NESTED(nl80211_ftm_responder_policy), 728 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), 729 [NL80211_ATTR_PEER_MEASUREMENTS] = 730 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), 731 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), 732 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, 733 .len = SAE_PASSWORD_MAX_LEN }, 734 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, 735 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), 736 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), 737 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), 738 [NL80211_ATTR_TID_CONFIG] = 739 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), 740 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, 741 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), 742 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), 743 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, 744 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 745 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, 746 [NL80211_ATTR_HE_6GHZ_CAPABILITY] = 747 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), 748 [NL80211_ATTR_FILS_DISCOVERY] = 749 NLA_POLICY_NESTED(nl80211_fils_discovery_policy), 750 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = 751 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), 752 [NL80211_ATTR_S1G_CAPABILITY] = 753 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), 754 [NL80211_ATTR_S1G_CAPABILITY_MASK] = 755 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), 756 [NL80211_ATTR_SAE_PWE] = 757 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK, 758 NL80211_SAE_PWE_BOTH), 759 [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT }, 760 [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy), 761 [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG }, 762 }; 763 764 /* policy for the key attributes */ 765 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { 766 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 767 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 768 [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, 769 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 770 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, 771 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 772 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), 773 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 774 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), 775 }; 776 777 /* policy for the key default flags */ 778 static const struct nla_policy 779 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { 780 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, 781 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, 782 }; 783 784 #ifdef CONFIG_PM 785 /* policy for WoWLAN attributes */ 786 static const struct nla_policy 787 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { 788 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, 789 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, 790 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, 791 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, 792 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, 793 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, 794 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, 795 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, 796 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, 797 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, 798 }; 799 800 static const struct nla_policy 801 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { 802 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, 803 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, 804 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 805 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, 806 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, 807 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), 808 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { 809 .len = sizeof(struct nl80211_wowlan_tcp_data_seq) 810 }, 811 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { 812 .len = sizeof(struct nl80211_wowlan_tcp_data_token) 813 }, 814 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, 815 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), 816 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), 817 }; 818 #endif /* CONFIG_PM */ 819 820 /* policy for coalesce rule attributes */ 821 static const struct nla_policy 822 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { 823 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, 824 [NL80211_ATTR_COALESCE_RULE_CONDITION] = 825 NLA_POLICY_RANGE(NLA_U32, 826 NL80211_COALESCE_CONDITION_MATCH, 827 NL80211_COALESCE_CONDITION_NO_MATCH), 828 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, 829 }; 830 831 /* policy for GTK rekey offload attributes */ 832 static const struct nla_policy 833 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { 834 [NL80211_REKEY_DATA_KEK] = { 835 .type = NLA_BINARY, 836 .len = NL80211_KEK_EXT_LEN 837 }, 838 [NL80211_REKEY_DATA_KCK] = { 839 .type = NLA_BINARY, 840 .len = NL80211_KCK_EXT_LEN 841 }, 842 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), 843 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, 844 }; 845 846 static const struct nla_policy 847 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { 848 [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, 849 [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, 850 [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, 851 [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, 852 }; 853 854 static const struct nla_policy 855 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { 856 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, 857 .len = IEEE80211_MAX_SSID_LEN }, 858 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 859 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, 860 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = 861 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), 862 }; 863 864 static const struct nla_policy 865 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { 866 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, 867 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, 868 }; 869 870 static const struct nla_policy 871 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { 872 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, 873 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, 874 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { 875 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 876 }, 877 }; 878 879 /* policy for NAN function attributes */ 880 static const struct nla_policy 881 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { 882 [NL80211_NAN_FUNC_TYPE] = 883 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), 884 [NL80211_NAN_FUNC_SERVICE_ID] = { 885 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, 886 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, 887 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, 888 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, 889 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, 890 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, 891 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 892 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, 893 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, 894 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, 895 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, 896 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, 897 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, 898 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, 899 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, 900 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, 901 }; 902 903 /* policy for Service Response Filter attributes */ 904 static const struct nla_policy 905 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { 906 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, 907 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, 908 .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, 909 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, 910 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, 911 }; 912 913 /* policy for packet pattern attributes */ 914 static const struct nla_policy 915 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { 916 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, 917 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, 918 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, 919 }; 920 921 int nl80211_prepare_wdev_dump(struct netlink_callback *cb, 922 struct cfg80211_registered_device **rdev, 923 struct wireless_dev **wdev) 924 { 925 int err; 926 927 if (!cb->args[0]) { 928 struct nlattr **attrbuf; 929 930 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 931 GFP_KERNEL); 932 if (!attrbuf) 933 return -ENOMEM; 934 935 err = nlmsg_parse_deprecated(cb->nlh, 936 GENL_HDRLEN + nl80211_fam.hdrsize, 937 attrbuf, nl80211_fam.maxattr, 938 nl80211_policy, NULL); 939 if (err) { 940 kfree(attrbuf); 941 return err; 942 } 943 944 rtnl_lock(); 945 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk), 946 attrbuf); 947 kfree(attrbuf); 948 if (IS_ERR(*wdev)) { 949 rtnl_unlock(); 950 return PTR_ERR(*wdev); 951 } 952 *rdev = wiphy_to_rdev((*wdev)->wiphy); 953 mutex_lock(&(*rdev)->wiphy.mtx); 954 rtnl_unlock(); 955 /* 0 is the first index - add 1 to parse only once */ 956 cb->args[0] = (*rdev)->wiphy_idx + 1; 957 cb->args[1] = (*wdev)->identifier; 958 } else { 959 /* subtract the 1 again here */ 960 struct wiphy *wiphy; 961 struct wireless_dev *tmp; 962 963 rtnl_lock(); 964 wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 965 if (!wiphy) { 966 rtnl_unlock(); 967 return -ENODEV; 968 } 969 *rdev = wiphy_to_rdev(wiphy); 970 *wdev = NULL; 971 972 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { 973 if (tmp->identifier == cb->args[1]) { 974 *wdev = tmp; 975 break; 976 } 977 } 978 979 if (!*wdev) { 980 rtnl_unlock(); 981 return -ENODEV; 982 } 983 mutex_lock(&(*rdev)->wiphy.mtx); 984 rtnl_unlock(); 985 } 986 987 return 0; 988 } 989 990 /* message building helper */ 991 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, 992 int flags, u8 cmd) 993 { 994 /* since there is no private header just add the generic one */ 995 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); 996 } 997 998 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, 999 const struct ieee80211_reg_rule *rule) 1000 { 1001 int j; 1002 struct nlattr *nl_wmm_rules = 1003 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); 1004 1005 if (!nl_wmm_rules) 1006 goto nla_put_failure; 1007 1008 for (j = 0; j < IEEE80211_NUM_ACS; j++) { 1009 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); 1010 1011 if (!nl_wmm_rule) 1012 goto nla_put_failure; 1013 1014 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, 1015 rule->wmm_rule.client[j].cw_min) || 1016 nla_put_u16(msg, NL80211_WMMR_CW_MAX, 1017 rule->wmm_rule.client[j].cw_max) || 1018 nla_put_u8(msg, NL80211_WMMR_AIFSN, 1019 rule->wmm_rule.client[j].aifsn) || 1020 nla_put_u16(msg, NL80211_WMMR_TXOP, 1021 rule->wmm_rule.client[j].cot)) 1022 goto nla_put_failure; 1023 1024 nla_nest_end(msg, nl_wmm_rule); 1025 } 1026 nla_nest_end(msg, nl_wmm_rules); 1027 1028 return 0; 1029 1030 nla_put_failure: 1031 return -ENOBUFS; 1032 } 1033 1034 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, 1035 struct ieee80211_channel *chan, 1036 bool large) 1037 { 1038 /* Some channels must be completely excluded from the 1039 * list to protect old user-space tools from breaking 1040 */ 1041 if (!large && chan->flags & 1042 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) 1043 return 0; 1044 if (!large && chan->freq_offset) 1045 return 0; 1046 1047 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, 1048 chan->center_freq)) 1049 goto nla_put_failure; 1050 1051 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) 1052 goto nla_put_failure; 1053 1054 if ((chan->flags & IEEE80211_CHAN_DISABLED) && 1055 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) 1056 goto nla_put_failure; 1057 if (chan->flags & IEEE80211_CHAN_NO_IR) { 1058 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) 1059 goto nla_put_failure; 1060 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) 1061 goto nla_put_failure; 1062 } 1063 if (chan->flags & IEEE80211_CHAN_RADAR) { 1064 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) 1065 goto nla_put_failure; 1066 if (large) { 1067 u32 time; 1068 1069 time = elapsed_jiffies_msecs(chan->dfs_state_entered); 1070 1071 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, 1072 chan->dfs_state)) 1073 goto nla_put_failure; 1074 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, 1075 time)) 1076 goto nla_put_failure; 1077 if (nla_put_u32(msg, 1078 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, 1079 chan->dfs_cac_ms)) 1080 goto nla_put_failure; 1081 } 1082 } 1083 1084 if (large) { 1085 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && 1086 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) 1087 goto nla_put_failure; 1088 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && 1089 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) 1090 goto nla_put_failure; 1091 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && 1092 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) 1093 goto nla_put_failure; 1094 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && 1095 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) 1096 goto nla_put_failure; 1097 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && 1098 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) 1099 goto nla_put_failure; 1100 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && 1101 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) 1102 goto nla_put_failure; 1103 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && 1104 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) 1105 goto nla_put_failure; 1106 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && 1107 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) 1108 goto nla_put_failure; 1109 if ((chan->flags & IEEE80211_CHAN_NO_HE) && 1110 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) 1111 goto nla_put_failure; 1112 if ((chan->flags & IEEE80211_CHAN_1MHZ) && 1113 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) 1114 goto nla_put_failure; 1115 if ((chan->flags & IEEE80211_CHAN_2MHZ) && 1116 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) 1117 goto nla_put_failure; 1118 if ((chan->flags & IEEE80211_CHAN_4MHZ) && 1119 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) 1120 goto nla_put_failure; 1121 if ((chan->flags & IEEE80211_CHAN_8MHZ) && 1122 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) 1123 goto nla_put_failure; 1124 if ((chan->flags & IEEE80211_CHAN_16MHZ) && 1125 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) 1126 goto nla_put_failure; 1127 } 1128 1129 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 1130 DBM_TO_MBM(chan->max_power))) 1131 goto nla_put_failure; 1132 1133 if (large) { 1134 const struct ieee80211_reg_rule *rule = 1135 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); 1136 1137 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { 1138 if (nl80211_msg_put_wmm_rules(msg, rule)) 1139 goto nla_put_failure; 1140 } 1141 } 1142 1143 return 0; 1144 1145 nla_put_failure: 1146 return -ENOBUFS; 1147 } 1148 1149 static bool nl80211_put_txq_stats(struct sk_buff *msg, 1150 struct cfg80211_txq_stats *txqstats, 1151 int attrtype) 1152 { 1153 struct nlattr *txqattr; 1154 1155 #define PUT_TXQVAL_U32(attr, memb) do { \ 1156 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ 1157 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ 1158 return false; \ 1159 } while (0) 1160 1161 txqattr = nla_nest_start_noflag(msg, attrtype); 1162 if (!txqattr) 1163 return false; 1164 1165 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); 1166 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); 1167 PUT_TXQVAL_U32(FLOWS, flows); 1168 PUT_TXQVAL_U32(DROPS, drops); 1169 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); 1170 PUT_TXQVAL_U32(OVERLIMIT, overlimit); 1171 PUT_TXQVAL_U32(OVERMEMORY, overmemory); 1172 PUT_TXQVAL_U32(COLLISIONS, collisions); 1173 PUT_TXQVAL_U32(TX_BYTES, tx_bytes); 1174 PUT_TXQVAL_U32(TX_PACKETS, tx_packets); 1175 PUT_TXQVAL_U32(MAX_FLOWS, max_flows); 1176 nla_nest_end(msg, txqattr); 1177 1178 #undef PUT_TXQVAL_U32 1179 return true; 1180 } 1181 1182 /* netlink command implementations */ 1183 1184 struct key_parse { 1185 struct key_params p; 1186 int idx; 1187 int type; 1188 bool def, defmgmt, defbeacon; 1189 bool def_uni, def_multi; 1190 }; 1191 1192 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, 1193 struct key_parse *k) 1194 { 1195 struct nlattr *tb[NL80211_KEY_MAX + 1]; 1196 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, 1197 nl80211_key_policy, 1198 info->extack); 1199 if (err) 1200 return err; 1201 1202 k->def = !!tb[NL80211_KEY_DEFAULT]; 1203 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 1204 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; 1205 1206 if (k->def) { 1207 k->def_uni = true; 1208 k->def_multi = true; 1209 } 1210 if (k->defmgmt || k->defbeacon) 1211 k->def_multi = true; 1212 1213 if (tb[NL80211_KEY_IDX]) 1214 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 1215 1216 if (tb[NL80211_KEY_DATA]) { 1217 k->p.key = nla_data(tb[NL80211_KEY_DATA]); 1218 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); 1219 } 1220 1221 if (tb[NL80211_KEY_SEQ]) { 1222 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); 1223 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); 1224 } 1225 1226 if (tb[NL80211_KEY_CIPHER]) 1227 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 1228 1229 if (tb[NL80211_KEY_TYPE]) 1230 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); 1231 1232 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 1233 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1234 1235 err = nla_parse_nested_deprecated(kdt, 1236 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1237 tb[NL80211_KEY_DEFAULT_TYPES], 1238 nl80211_key_default_policy, 1239 info->extack); 1240 if (err) 1241 return err; 1242 1243 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1244 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1245 } 1246 1247 if (tb[NL80211_KEY_MODE]) 1248 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); 1249 1250 return 0; 1251 } 1252 1253 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) 1254 { 1255 if (info->attrs[NL80211_ATTR_KEY_DATA]) { 1256 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); 1257 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); 1258 } 1259 1260 if (info->attrs[NL80211_ATTR_KEY_SEQ]) { 1261 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); 1262 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); 1263 } 1264 1265 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1266 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1267 1268 if (info->attrs[NL80211_ATTR_KEY_CIPHER]) 1269 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); 1270 1271 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 1272 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 1273 1274 if (k->def) { 1275 k->def_uni = true; 1276 k->def_multi = true; 1277 } 1278 if (k->defmgmt) 1279 k->def_multi = true; 1280 1281 if (info->attrs[NL80211_ATTR_KEY_TYPE]) 1282 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 1283 1284 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1285 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1286 int err = nla_parse_nested_deprecated(kdt, 1287 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1288 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1289 nl80211_key_default_policy, 1290 info->extack); 1291 if (err) 1292 return err; 1293 1294 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1295 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1296 } 1297 1298 return 0; 1299 } 1300 1301 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) 1302 { 1303 int err; 1304 1305 memset(k, 0, sizeof(*k)); 1306 k->idx = -1; 1307 k->type = -1; 1308 1309 if (info->attrs[NL80211_ATTR_KEY]) 1310 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); 1311 else 1312 err = nl80211_parse_key_old(info, k); 1313 1314 if (err) 1315 return err; 1316 1317 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + 1318 (k->defbeacon ? 1 : 0) > 1) { 1319 GENL_SET_ERR_MSG(info, 1320 "key with multiple default flags is invalid"); 1321 return -EINVAL; 1322 } 1323 1324 if (k->defmgmt || k->defbeacon) { 1325 if (k->def_uni || !k->def_multi) { 1326 GENL_SET_ERR_MSG(info, 1327 "defmgmt/defbeacon key must be mcast"); 1328 return -EINVAL; 1329 } 1330 } 1331 1332 if (k->idx != -1) { 1333 if (k->defmgmt) { 1334 if (k->idx < 4 || k->idx > 5) { 1335 GENL_SET_ERR_MSG(info, 1336 "defmgmt key idx not 4 or 5"); 1337 return -EINVAL; 1338 } 1339 } else if (k->defbeacon) { 1340 if (k->idx < 6 || k->idx > 7) { 1341 GENL_SET_ERR_MSG(info, 1342 "defbeacon key idx not 6 or 7"); 1343 return -EINVAL; 1344 } 1345 } else if (k->def) { 1346 if (k->idx < 0 || k->idx > 3) { 1347 GENL_SET_ERR_MSG(info, "def key idx not 0-3"); 1348 return -EINVAL; 1349 } 1350 } else { 1351 if (k->idx < 0 || k->idx > 7) { 1352 GENL_SET_ERR_MSG(info, "key idx not 0-7"); 1353 return -EINVAL; 1354 } 1355 } 1356 } 1357 1358 return 0; 1359 } 1360 1361 static struct cfg80211_cached_keys * 1362 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, 1363 struct genl_info *info, bool *no_ht) 1364 { 1365 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; 1366 struct key_parse parse; 1367 struct nlattr *key; 1368 struct cfg80211_cached_keys *result; 1369 int rem, err, def = 0; 1370 bool have_key = false; 1371 1372 nla_for_each_nested(key, keys, rem) { 1373 have_key = true; 1374 break; 1375 } 1376 1377 if (!have_key) 1378 return NULL; 1379 1380 result = kzalloc(sizeof(*result), GFP_KERNEL); 1381 if (!result) 1382 return ERR_PTR(-ENOMEM); 1383 1384 result->def = -1; 1385 1386 nla_for_each_nested(key, keys, rem) { 1387 memset(&parse, 0, sizeof(parse)); 1388 parse.idx = -1; 1389 1390 err = nl80211_parse_key_new(info, key, &parse); 1391 if (err) 1392 goto error; 1393 err = -EINVAL; 1394 if (!parse.p.key) 1395 goto error; 1396 if (parse.idx < 0 || parse.idx > 3) { 1397 GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); 1398 goto error; 1399 } 1400 if (parse.def) { 1401 if (def) { 1402 GENL_SET_ERR_MSG(info, 1403 "only one key can be default"); 1404 goto error; 1405 } 1406 def = 1; 1407 result->def = parse.idx; 1408 if (!parse.def_uni || !parse.def_multi) 1409 goto error; 1410 } else if (parse.defmgmt) 1411 goto error; 1412 err = cfg80211_validate_key_settings(rdev, &parse.p, 1413 parse.idx, false, NULL); 1414 if (err) 1415 goto error; 1416 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && 1417 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { 1418 GENL_SET_ERR_MSG(info, "connect key must be WEP"); 1419 err = -EINVAL; 1420 goto error; 1421 } 1422 result->params[parse.idx].cipher = parse.p.cipher; 1423 result->params[parse.idx].key_len = parse.p.key_len; 1424 result->params[parse.idx].key = result->data[parse.idx]; 1425 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); 1426 1427 /* must be WEP key if we got here */ 1428 if (no_ht) 1429 *no_ht = true; 1430 } 1431 1432 if (result->def < 0) { 1433 err = -EINVAL; 1434 GENL_SET_ERR_MSG(info, "need a default/TX key"); 1435 goto error; 1436 } 1437 1438 return result; 1439 error: 1440 kfree(result); 1441 return ERR_PTR(err); 1442 } 1443 1444 static int nl80211_key_allowed(struct wireless_dev *wdev) 1445 { 1446 ASSERT_WDEV_LOCK(wdev); 1447 1448 switch (wdev->iftype) { 1449 case NL80211_IFTYPE_AP: 1450 case NL80211_IFTYPE_AP_VLAN: 1451 case NL80211_IFTYPE_P2P_GO: 1452 case NL80211_IFTYPE_MESH_POINT: 1453 break; 1454 case NL80211_IFTYPE_ADHOC: 1455 case NL80211_IFTYPE_STATION: 1456 case NL80211_IFTYPE_P2P_CLIENT: 1457 if (!wdev->current_bss) 1458 return -ENOLINK; 1459 break; 1460 case NL80211_IFTYPE_UNSPECIFIED: 1461 case NL80211_IFTYPE_OCB: 1462 case NL80211_IFTYPE_MONITOR: 1463 case NL80211_IFTYPE_NAN: 1464 case NL80211_IFTYPE_P2P_DEVICE: 1465 case NL80211_IFTYPE_WDS: 1466 case NUM_NL80211_IFTYPES: 1467 return -EINVAL; 1468 } 1469 1470 return 0; 1471 } 1472 1473 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, 1474 u32 freq) 1475 { 1476 struct ieee80211_channel *chan; 1477 1478 chan = ieee80211_get_channel_khz(wiphy, freq); 1479 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 1480 return NULL; 1481 return chan; 1482 } 1483 1484 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1485 { 1486 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); 1487 int i; 1488 1489 if (!nl_modes) 1490 goto nla_put_failure; 1491 1492 i = 0; 1493 while (ifmodes) { 1494 if ((ifmodes & 1) && nla_put_flag(msg, i)) 1495 goto nla_put_failure; 1496 ifmodes >>= 1; 1497 i++; 1498 } 1499 1500 nla_nest_end(msg, nl_modes); 1501 return 0; 1502 1503 nla_put_failure: 1504 return -ENOBUFS; 1505 } 1506 1507 static int nl80211_put_iface_combinations(struct wiphy *wiphy, 1508 struct sk_buff *msg, 1509 bool large) 1510 { 1511 struct nlattr *nl_combis; 1512 int i, j; 1513 1514 nl_combis = nla_nest_start_noflag(msg, 1515 NL80211_ATTR_INTERFACE_COMBINATIONS); 1516 if (!nl_combis) 1517 goto nla_put_failure; 1518 1519 for (i = 0; i < wiphy->n_iface_combinations; i++) { 1520 const struct ieee80211_iface_combination *c; 1521 struct nlattr *nl_combi, *nl_limits; 1522 1523 c = &wiphy->iface_combinations[i]; 1524 1525 nl_combi = nla_nest_start_noflag(msg, i + 1); 1526 if (!nl_combi) 1527 goto nla_put_failure; 1528 1529 nl_limits = nla_nest_start_noflag(msg, 1530 NL80211_IFACE_COMB_LIMITS); 1531 if (!nl_limits) 1532 goto nla_put_failure; 1533 1534 for (j = 0; j < c->n_limits; j++) { 1535 struct nlattr *nl_limit; 1536 1537 nl_limit = nla_nest_start_noflag(msg, j + 1); 1538 if (!nl_limit) 1539 goto nla_put_failure; 1540 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1541 c->limits[j].max)) 1542 goto nla_put_failure; 1543 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, 1544 c->limits[j].types)) 1545 goto nla_put_failure; 1546 nla_nest_end(msg, nl_limit); 1547 } 1548 1549 nla_nest_end(msg, nl_limits); 1550 1551 if (c->beacon_int_infra_match && 1552 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) 1553 goto nla_put_failure; 1554 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, 1555 c->num_different_channels) || 1556 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 1557 c->max_interfaces)) 1558 goto nla_put_failure; 1559 if (large && 1560 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, 1561 c->radar_detect_widths) || 1562 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, 1563 c->radar_detect_regions))) 1564 goto nla_put_failure; 1565 if (c->beacon_int_min_gcd && 1566 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, 1567 c->beacon_int_min_gcd)) 1568 goto nla_put_failure; 1569 1570 nla_nest_end(msg, nl_combi); 1571 } 1572 1573 nla_nest_end(msg, nl_combis); 1574 1575 return 0; 1576 nla_put_failure: 1577 return -ENOBUFS; 1578 } 1579 1580 #ifdef CONFIG_PM 1581 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, 1582 struct sk_buff *msg) 1583 { 1584 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; 1585 struct nlattr *nl_tcp; 1586 1587 if (!tcp) 1588 return 0; 1589 1590 nl_tcp = nla_nest_start_noflag(msg, 1591 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1592 if (!nl_tcp) 1593 return -ENOBUFS; 1594 1595 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1596 tcp->data_payload_max)) 1597 return -ENOBUFS; 1598 1599 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1600 tcp->data_payload_max)) 1601 return -ENOBUFS; 1602 1603 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) 1604 return -ENOBUFS; 1605 1606 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 1607 sizeof(*tcp->tok), tcp->tok)) 1608 return -ENOBUFS; 1609 1610 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 1611 tcp->data_interval_max)) 1612 return -ENOBUFS; 1613 1614 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 1615 tcp->wake_payload_max)) 1616 return -ENOBUFS; 1617 1618 nla_nest_end(msg, nl_tcp); 1619 return 0; 1620 } 1621 1622 static int nl80211_send_wowlan(struct sk_buff *msg, 1623 struct cfg80211_registered_device *rdev, 1624 bool large) 1625 { 1626 struct nlattr *nl_wowlan; 1627 1628 if (!rdev->wiphy.wowlan) 1629 return 0; 1630 1631 nl_wowlan = nla_nest_start_noflag(msg, 1632 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1633 if (!nl_wowlan) 1634 return -ENOBUFS; 1635 1636 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && 1637 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 1638 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && 1639 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 1640 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && 1641 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 1642 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && 1643 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || 1644 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 1645 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 1646 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && 1647 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 1648 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && 1649 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 1650 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && 1651 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 1652 return -ENOBUFS; 1653 1654 if (rdev->wiphy.wowlan->n_patterns) { 1655 struct nl80211_pattern_support pat = { 1656 .max_patterns = rdev->wiphy.wowlan->n_patterns, 1657 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, 1658 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, 1659 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, 1660 }; 1661 1662 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 1663 sizeof(pat), &pat)) 1664 return -ENOBUFS; 1665 } 1666 1667 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && 1668 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, 1669 rdev->wiphy.wowlan->max_nd_match_sets)) 1670 return -ENOBUFS; 1671 1672 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) 1673 return -ENOBUFS; 1674 1675 nla_nest_end(msg, nl_wowlan); 1676 1677 return 0; 1678 } 1679 #endif 1680 1681 static int nl80211_send_coalesce(struct sk_buff *msg, 1682 struct cfg80211_registered_device *rdev) 1683 { 1684 struct nl80211_coalesce_rule_support rule; 1685 1686 if (!rdev->wiphy.coalesce) 1687 return 0; 1688 1689 rule.max_rules = rdev->wiphy.coalesce->n_rules; 1690 rule.max_delay = rdev->wiphy.coalesce->max_delay; 1691 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; 1692 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; 1693 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; 1694 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; 1695 1696 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) 1697 return -ENOBUFS; 1698 1699 return 0; 1700 } 1701 1702 static int 1703 nl80211_send_iftype_data(struct sk_buff *msg, 1704 const struct ieee80211_supported_band *sband, 1705 const struct ieee80211_sband_iftype_data *iftdata) 1706 { 1707 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; 1708 1709 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, 1710 iftdata->types_mask)) 1711 return -ENOBUFS; 1712 1713 if (he_cap->has_he) { 1714 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, 1715 sizeof(he_cap->he_cap_elem.mac_cap_info), 1716 he_cap->he_cap_elem.mac_cap_info) || 1717 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, 1718 sizeof(he_cap->he_cap_elem.phy_cap_info), 1719 he_cap->he_cap_elem.phy_cap_info) || 1720 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, 1721 sizeof(he_cap->he_mcs_nss_supp), 1722 &he_cap->he_mcs_nss_supp) || 1723 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, 1724 sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) 1725 return -ENOBUFS; 1726 } 1727 1728 if (sband->band == NL80211_BAND_6GHZ && 1729 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, 1730 sizeof(iftdata->he_6ghz_capa), 1731 &iftdata->he_6ghz_capa)) 1732 return -ENOBUFS; 1733 1734 return 0; 1735 } 1736 1737 static int nl80211_send_band_rateinfo(struct sk_buff *msg, 1738 struct ieee80211_supported_band *sband, 1739 bool large) 1740 { 1741 struct nlattr *nl_rates, *nl_rate; 1742 struct ieee80211_rate *rate; 1743 int i; 1744 1745 /* add HT info */ 1746 if (sband->ht_cap.ht_supported && 1747 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, 1748 sizeof(sband->ht_cap.mcs), 1749 &sband->ht_cap.mcs) || 1750 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, 1751 sband->ht_cap.cap) || 1752 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, 1753 sband->ht_cap.ampdu_factor) || 1754 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, 1755 sband->ht_cap.ampdu_density))) 1756 return -ENOBUFS; 1757 1758 /* add VHT info */ 1759 if (sband->vht_cap.vht_supported && 1760 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, 1761 sizeof(sband->vht_cap.vht_mcs), 1762 &sband->vht_cap.vht_mcs) || 1763 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, 1764 sband->vht_cap.cap))) 1765 return -ENOBUFS; 1766 1767 if (large && sband->n_iftype_data) { 1768 struct nlattr *nl_iftype_data = 1769 nla_nest_start_noflag(msg, 1770 NL80211_BAND_ATTR_IFTYPE_DATA); 1771 int err; 1772 1773 if (!nl_iftype_data) 1774 return -ENOBUFS; 1775 1776 for (i = 0; i < sband->n_iftype_data; i++) { 1777 struct nlattr *iftdata; 1778 1779 iftdata = nla_nest_start_noflag(msg, i + 1); 1780 if (!iftdata) 1781 return -ENOBUFS; 1782 1783 err = nl80211_send_iftype_data(msg, sband, 1784 &sband->iftype_data[i]); 1785 if (err) 1786 return err; 1787 1788 nla_nest_end(msg, iftdata); 1789 } 1790 1791 nla_nest_end(msg, nl_iftype_data); 1792 } 1793 1794 /* add EDMG info */ 1795 if (large && sband->edmg_cap.channels && 1796 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, 1797 sband->edmg_cap.channels) || 1798 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, 1799 sband->edmg_cap.bw_config))) 1800 1801 return -ENOBUFS; 1802 1803 /* add bitrates */ 1804 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); 1805 if (!nl_rates) 1806 return -ENOBUFS; 1807 1808 for (i = 0; i < sband->n_bitrates; i++) { 1809 nl_rate = nla_nest_start_noflag(msg, i); 1810 if (!nl_rate) 1811 return -ENOBUFS; 1812 1813 rate = &sband->bitrates[i]; 1814 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, 1815 rate->bitrate)) 1816 return -ENOBUFS; 1817 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && 1818 nla_put_flag(msg, 1819 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) 1820 return -ENOBUFS; 1821 1822 nla_nest_end(msg, nl_rate); 1823 } 1824 1825 nla_nest_end(msg, nl_rates); 1826 1827 return 0; 1828 } 1829 1830 static int 1831 nl80211_send_mgmt_stypes(struct sk_buff *msg, 1832 const struct ieee80211_txrx_stypes *mgmt_stypes) 1833 { 1834 u16 stypes; 1835 struct nlattr *nl_ftypes, *nl_ifs; 1836 enum nl80211_iftype ift; 1837 int i; 1838 1839 if (!mgmt_stypes) 1840 return 0; 1841 1842 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); 1843 if (!nl_ifs) 1844 return -ENOBUFS; 1845 1846 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1847 nl_ftypes = nla_nest_start_noflag(msg, ift); 1848 if (!nl_ftypes) 1849 return -ENOBUFS; 1850 i = 0; 1851 stypes = mgmt_stypes[ift].tx; 1852 while (stypes) { 1853 if ((stypes & 1) && 1854 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1855 (i << 4) | IEEE80211_FTYPE_MGMT)) 1856 return -ENOBUFS; 1857 stypes >>= 1; 1858 i++; 1859 } 1860 nla_nest_end(msg, nl_ftypes); 1861 } 1862 1863 nla_nest_end(msg, nl_ifs); 1864 1865 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); 1866 if (!nl_ifs) 1867 return -ENOBUFS; 1868 1869 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1870 nl_ftypes = nla_nest_start_noflag(msg, ift); 1871 if (!nl_ftypes) 1872 return -ENOBUFS; 1873 i = 0; 1874 stypes = mgmt_stypes[ift].rx; 1875 while (stypes) { 1876 if ((stypes & 1) && 1877 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1878 (i << 4) | IEEE80211_FTYPE_MGMT)) 1879 return -ENOBUFS; 1880 stypes >>= 1; 1881 i++; 1882 } 1883 nla_nest_end(msg, nl_ftypes); 1884 } 1885 nla_nest_end(msg, nl_ifs); 1886 1887 return 0; 1888 } 1889 1890 #define CMD(op, n) \ 1891 do { \ 1892 if (rdev->ops->op) { \ 1893 i++; \ 1894 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ 1895 goto nla_put_failure; \ 1896 } \ 1897 } while (0) 1898 1899 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, 1900 struct sk_buff *msg) 1901 { 1902 int i = 0; 1903 1904 /* 1905 * do *NOT* add anything into this function, new things need to be 1906 * advertised only to new versions of userspace that can deal with 1907 * the split (and they can't possibly care about new features... 1908 */ 1909 CMD(add_virtual_intf, NEW_INTERFACE); 1910 CMD(change_virtual_intf, SET_INTERFACE); 1911 CMD(add_key, NEW_KEY); 1912 CMD(start_ap, START_AP); 1913 CMD(add_station, NEW_STATION); 1914 CMD(add_mpath, NEW_MPATH); 1915 CMD(update_mesh_config, SET_MESH_CONFIG); 1916 CMD(change_bss, SET_BSS); 1917 CMD(auth, AUTHENTICATE); 1918 CMD(assoc, ASSOCIATE); 1919 CMD(deauth, DEAUTHENTICATE); 1920 CMD(disassoc, DISASSOCIATE); 1921 CMD(join_ibss, JOIN_IBSS); 1922 CMD(join_mesh, JOIN_MESH); 1923 CMD(set_pmksa, SET_PMKSA); 1924 CMD(del_pmksa, DEL_PMKSA); 1925 CMD(flush_pmksa, FLUSH_PMKSA); 1926 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) 1927 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 1928 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 1929 CMD(mgmt_tx, FRAME); 1930 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); 1931 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 1932 i++; 1933 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 1934 goto nla_put_failure; 1935 } 1936 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || 1937 rdev->ops->join_mesh) { 1938 i++; 1939 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) 1940 goto nla_put_failure; 1941 } 1942 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 1943 CMD(tdls_mgmt, TDLS_MGMT); 1944 CMD(tdls_oper, TDLS_OPER); 1945 } 1946 if (rdev->wiphy.max_sched_scan_reqs) 1947 CMD(sched_scan_start, START_SCHED_SCAN); 1948 CMD(probe_client, PROBE_CLIENT); 1949 CMD(set_noack_map, SET_NOACK_MAP); 1950 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { 1951 i++; 1952 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) 1953 goto nla_put_failure; 1954 } 1955 CMD(start_p2p_device, START_P2P_DEVICE); 1956 CMD(set_mcast_rate, SET_MCAST_RATE); 1957 #ifdef CONFIG_NL80211_TESTMODE 1958 CMD(testmode_cmd, TESTMODE); 1959 #endif 1960 1961 if (rdev->ops->connect || rdev->ops->auth) { 1962 i++; 1963 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) 1964 goto nla_put_failure; 1965 } 1966 1967 if (rdev->ops->disconnect || rdev->ops->deauth) { 1968 i++; 1969 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) 1970 goto nla_put_failure; 1971 } 1972 1973 return i; 1974 nla_put_failure: 1975 return -ENOBUFS; 1976 } 1977 1978 static int 1979 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, 1980 struct sk_buff *msg) 1981 { 1982 struct nlattr *ftm; 1983 1984 if (!cap->ftm.supported) 1985 return 0; 1986 1987 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); 1988 if (!ftm) 1989 return -ENOBUFS; 1990 1991 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) 1992 return -ENOBUFS; 1993 if (cap->ftm.non_asap && 1994 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) 1995 return -ENOBUFS; 1996 if (cap->ftm.request_lci && 1997 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) 1998 return -ENOBUFS; 1999 if (cap->ftm.request_civicloc && 2000 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) 2001 return -ENOBUFS; 2002 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, 2003 cap->ftm.preambles)) 2004 return -ENOBUFS; 2005 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, 2006 cap->ftm.bandwidths)) 2007 return -ENOBUFS; 2008 if (cap->ftm.max_bursts_exponent >= 0 && 2009 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, 2010 cap->ftm.max_bursts_exponent)) 2011 return -ENOBUFS; 2012 if (cap->ftm.max_ftms_per_burst && 2013 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, 2014 cap->ftm.max_ftms_per_burst)) 2015 return -ENOBUFS; 2016 if (cap->ftm.trigger_based && 2017 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) 2018 return -ENOBUFS; 2019 if (cap->ftm.non_trigger_based && 2020 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) 2021 return -ENOBUFS; 2022 2023 nla_nest_end(msg, ftm); 2024 return 0; 2025 } 2026 2027 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, 2028 struct sk_buff *msg) 2029 { 2030 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; 2031 struct nlattr *pmsr, *caps; 2032 2033 if (!cap) 2034 return 0; 2035 2036 /* 2037 * we don't need to clean up anything here since the caller 2038 * will genlmsg_cancel() if we fail 2039 */ 2040 2041 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 2042 if (!pmsr) 2043 return -ENOBUFS; 2044 2045 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) 2046 return -ENOBUFS; 2047 2048 if (cap->report_ap_tsf && 2049 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) 2050 return -ENOBUFS; 2051 2052 if (cap->randomize_mac_addr && 2053 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 2054 return -ENOBUFS; 2055 2056 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 2057 if (!caps) 2058 return -ENOBUFS; 2059 2060 if (nl80211_send_pmsr_ftm_capa(cap, msg)) 2061 return -ENOBUFS; 2062 2063 nla_nest_end(msg, caps); 2064 nla_nest_end(msg, pmsr); 2065 2066 return 0; 2067 } 2068 2069 static int 2070 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, 2071 struct sk_buff *msg) 2072 { 2073 int i; 2074 struct nlattr *nested, *nested_akms; 2075 const struct wiphy_iftype_akm_suites *iftype_akms; 2076 2077 if (!rdev->wiphy.num_iftype_akm_suites || 2078 !rdev->wiphy.iftype_akm_suites) 2079 return 0; 2080 2081 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); 2082 if (!nested) 2083 return -ENOBUFS; 2084 2085 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { 2086 nested_akms = nla_nest_start(msg, i + 1); 2087 if (!nested_akms) 2088 return -ENOBUFS; 2089 2090 iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; 2091 2092 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, 2093 iftype_akms->iftypes_mask)) 2094 return -ENOBUFS; 2095 2096 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, 2097 sizeof(u32) * iftype_akms->n_akm_suites, 2098 iftype_akms->akm_suites)) { 2099 return -ENOBUFS; 2100 } 2101 nla_nest_end(msg, nested_akms); 2102 } 2103 2104 nla_nest_end(msg, nested); 2105 2106 return 0; 2107 } 2108 2109 static int 2110 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, 2111 struct sk_buff *msg) 2112 { 2113 struct nlattr *supp; 2114 2115 if (!rdev->wiphy.tid_config_support.vif && 2116 !rdev->wiphy.tid_config_support.peer) 2117 return 0; 2118 2119 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); 2120 if (!supp) 2121 return -ENOSPC; 2122 2123 if (rdev->wiphy.tid_config_support.vif && 2124 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, 2125 rdev->wiphy.tid_config_support.vif, 2126 NL80211_TID_CONFIG_ATTR_PAD)) 2127 goto fail; 2128 2129 if (rdev->wiphy.tid_config_support.peer && 2130 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, 2131 rdev->wiphy.tid_config_support.peer, 2132 NL80211_TID_CONFIG_ATTR_PAD)) 2133 goto fail; 2134 2135 /* for now we just use the same value ... makes more sense */ 2136 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, 2137 rdev->wiphy.tid_config_support.max_retry)) 2138 goto fail; 2139 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, 2140 rdev->wiphy.tid_config_support.max_retry)) 2141 goto fail; 2142 2143 nla_nest_end(msg, supp); 2144 2145 return 0; 2146 fail: 2147 nla_nest_cancel(msg, supp); 2148 return -ENOBUFS; 2149 } 2150 2151 static int 2152 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev, 2153 struct sk_buff *msg) 2154 { 2155 struct nlattr *sar_capa, *specs, *sub_freq_range; 2156 u8 num_freq_ranges; 2157 int i; 2158 2159 if (!rdev->wiphy.sar_capa) 2160 return 0; 2161 2162 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges; 2163 2164 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC); 2165 if (!sar_capa) 2166 return -ENOSPC; 2167 2168 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type)) 2169 goto fail; 2170 2171 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS); 2172 if (!specs) 2173 goto fail; 2174 2175 /* report supported freq_ranges */ 2176 for (i = 0; i < num_freq_ranges; i++) { 2177 sub_freq_range = nla_nest_start(msg, i + 1); 2178 if (!sub_freq_range) 2179 goto fail; 2180 2181 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ, 2182 rdev->wiphy.sar_capa->freq_ranges[i].start_freq)) 2183 goto fail; 2184 2185 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ, 2186 rdev->wiphy.sar_capa->freq_ranges[i].end_freq)) 2187 goto fail; 2188 2189 nla_nest_end(msg, sub_freq_range); 2190 } 2191 2192 nla_nest_end(msg, specs); 2193 nla_nest_end(msg, sar_capa); 2194 2195 return 0; 2196 fail: 2197 nla_nest_cancel(msg, sar_capa); 2198 return -ENOBUFS; 2199 } 2200 2201 struct nl80211_dump_wiphy_state { 2202 s64 filter_wiphy; 2203 long start; 2204 long split_start, band_start, chan_start, capa_start; 2205 bool split; 2206 }; 2207 2208 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 2209 enum nl80211_commands cmd, 2210 struct sk_buff *msg, u32 portid, u32 seq, 2211 int flags, struct nl80211_dump_wiphy_state *state) 2212 { 2213 void *hdr; 2214 struct nlattr *nl_bands, *nl_band; 2215 struct nlattr *nl_freqs, *nl_freq; 2216 struct nlattr *nl_cmds; 2217 enum nl80211_band band; 2218 struct ieee80211_channel *chan; 2219 int i; 2220 const struct ieee80211_txrx_stypes *mgmt_stypes = 2221 rdev->wiphy.mgmt_stypes; 2222 u32 features; 2223 2224 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 2225 if (!hdr) 2226 return -ENOBUFS; 2227 2228 if (WARN_ON(!state)) 2229 return -EINVAL; 2230 2231 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 2232 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, 2233 wiphy_name(&rdev->wiphy)) || 2234 nla_put_u32(msg, NL80211_ATTR_GENERATION, 2235 cfg80211_rdev_list_generation)) 2236 goto nla_put_failure; 2237 2238 if (cmd != NL80211_CMD_NEW_WIPHY) 2239 goto finish; 2240 2241 switch (state->split_start) { 2242 case 0: 2243 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 2244 rdev->wiphy.retry_short) || 2245 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, 2246 rdev->wiphy.retry_long) || 2247 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, 2248 rdev->wiphy.frag_threshold) || 2249 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 2250 rdev->wiphy.rts_threshold) || 2251 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 2252 rdev->wiphy.coverage_class) || 2253 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 2254 rdev->wiphy.max_scan_ssids) || 2255 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, 2256 rdev->wiphy.max_sched_scan_ssids) || 2257 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 2258 rdev->wiphy.max_scan_ie_len) || 2259 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, 2260 rdev->wiphy.max_sched_scan_ie_len) || 2261 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, 2262 rdev->wiphy.max_match_sets)) 2263 goto nla_put_failure; 2264 2265 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && 2266 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) 2267 goto nla_put_failure; 2268 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && 2269 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) 2270 goto nla_put_failure; 2271 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && 2272 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) 2273 goto nla_put_failure; 2274 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 2275 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) 2276 goto nla_put_failure; 2277 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && 2278 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) 2279 goto nla_put_failure; 2280 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && 2281 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) 2282 goto nla_put_failure; 2283 state->split_start++; 2284 if (state->split) 2285 break; 2286 fallthrough; 2287 case 1: 2288 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, 2289 sizeof(u32) * rdev->wiphy.n_cipher_suites, 2290 rdev->wiphy.cipher_suites)) 2291 goto nla_put_failure; 2292 2293 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 2294 rdev->wiphy.max_num_pmkids)) 2295 goto nla_put_failure; 2296 2297 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 2298 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) 2299 goto nla_put_failure; 2300 2301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, 2302 rdev->wiphy.available_antennas_tx) || 2303 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, 2304 rdev->wiphy.available_antennas_rx)) 2305 goto nla_put_failure; 2306 2307 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && 2308 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, 2309 rdev->wiphy.probe_resp_offload)) 2310 goto nla_put_failure; 2311 2312 if ((rdev->wiphy.available_antennas_tx || 2313 rdev->wiphy.available_antennas_rx) && 2314 rdev->ops->get_antenna) { 2315 u32 tx_ant = 0, rx_ant = 0; 2316 int res; 2317 2318 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); 2319 if (!res) { 2320 if (nla_put_u32(msg, 2321 NL80211_ATTR_WIPHY_ANTENNA_TX, 2322 tx_ant) || 2323 nla_put_u32(msg, 2324 NL80211_ATTR_WIPHY_ANTENNA_RX, 2325 rx_ant)) 2326 goto nla_put_failure; 2327 } 2328 } 2329 2330 state->split_start++; 2331 if (state->split) 2332 break; 2333 fallthrough; 2334 case 2: 2335 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, 2336 rdev->wiphy.interface_modes)) 2337 goto nla_put_failure; 2338 state->split_start++; 2339 if (state->split) 2340 break; 2341 fallthrough; 2342 case 3: 2343 nl_bands = nla_nest_start_noflag(msg, 2344 NL80211_ATTR_WIPHY_BANDS); 2345 if (!nl_bands) 2346 goto nla_put_failure; 2347 2348 for (band = state->band_start; 2349 band < NUM_NL80211_BANDS; band++) { 2350 struct ieee80211_supported_band *sband; 2351 2352 /* omit higher bands for ancient software */ 2353 if (band > NL80211_BAND_5GHZ && !state->split) 2354 break; 2355 2356 sband = rdev->wiphy.bands[band]; 2357 2358 if (!sband) 2359 continue; 2360 2361 nl_band = nla_nest_start_noflag(msg, band); 2362 if (!nl_band) 2363 goto nla_put_failure; 2364 2365 switch (state->chan_start) { 2366 case 0: 2367 if (nl80211_send_band_rateinfo(msg, sband, 2368 state->split)) 2369 goto nla_put_failure; 2370 state->chan_start++; 2371 if (state->split) 2372 break; 2373 fallthrough; 2374 default: 2375 /* add frequencies */ 2376 nl_freqs = nla_nest_start_noflag(msg, 2377 NL80211_BAND_ATTR_FREQS); 2378 if (!nl_freqs) 2379 goto nla_put_failure; 2380 2381 for (i = state->chan_start - 1; 2382 i < sband->n_channels; 2383 i++) { 2384 nl_freq = nla_nest_start_noflag(msg, 2385 i); 2386 if (!nl_freq) 2387 goto nla_put_failure; 2388 2389 chan = &sband->channels[i]; 2390 2391 if (nl80211_msg_put_channel( 2392 msg, &rdev->wiphy, chan, 2393 state->split)) 2394 goto nla_put_failure; 2395 2396 nla_nest_end(msg, nl_freq); 2397 if (state->split) 2398 break; 2399 } 2400 if (i < sband->n_channels) 2401 state->chan_start = i + 2; 2402 else 2403 state->chan_start = 0; 2404 nla_nest_end(msg, nl_freqs); 2405 } 2406 2407 nla_nest_end(msg, nl_band); 2408 2409 if (state->split) { 2410 /* start again here */ 2411 if (state->chan_start) 2412 band--; 2413 break; 2414 } 2415 } 2416 nla_nest_end(msg, nl_bands); 2417 2418 if (band < NUM_NL80211_BANDS) 2419 state->band_start = band + 1; 2420 else 2421 state->band_start = 0; 2422 2423 /* if bands & channels are done, continue outside */ 2424 if (state->band_start == 0 && state->chan_start == 0) 2425 state->split_start++; 2426 if (state->split) 2427 break; 2428 fallthrough; 2429 case 4: 2430 nl_cmds = nla_nest_start_noflag(msg, 2431 NL80211_ATTR_SUPPORTED_COMMANDS); 2432 if (!nl_cmds) 2433 goto nla_put_failure; 2434 2435 i = nl80211_add_commands_unsplit(rdev, msg); 2436 if (i < 0) 2437 goto nla_put_failure; 2438 if (state->split) { 2439 CMD(crit_proto_start, CRIT_PROTOCOL_START); 2440 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); 2441 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 2442 CMD(channel_switch, CHANNEL_SWITCH); 2443 CMD(set_qos_map, SET_QOS_MAP); 2444 if (rdev->wiphy.features & 2445 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 2446 CMD(add_tx_ts, ADD_TX_TS); 2447 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); 2448 CMD(update_connect_params, UPDATE_CONNECT_PARAMS); 2449 CMD(update_ft_ies, UPDATE_FT_IES); 2450 if (rdev->wiphy.sar_capa) 2451 CMD(set_sar_specs, SET_SAR_SPECS); 2452 } 2453 #undef CMD 2454 2455 nla_nest_end(msg, nl_cmds); 2456 state->split_start++; 2457 if (state->split) 2458 break; 2459 fallthrough; 2460 case 5: 2461 if (rdev->ops->remain_on_channel && 2462 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && 2463 nla_put_u32(msg, 2464 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, 2465 rdev->wiphy.max_remain_on_channel_duration)) 2466 goto nla_put_failure; 2467 2468 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && 2469 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) 2470 goto nla_put_failure; 2471 2472 state->split_start++; 2473 if (state->split) 2474 break; 2475 fallthrough; 2476 case 6: 2477 #ifdef CONFIG_PM 2478 if (nl80211_send_wowlan(msg, rdev, state->split)) 2479 goto nla_put_failure; 2480 state->split_start++; 2481 if (state->split) 2482 break; 2483 #else 2484 state->split_start++; 2485 #endif 2486 fallthrough; 2487 case 7: 2488 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, 2489 rdev->wiphy.software_iftypes)) 2490 goto nla_put_failure; 2491 2492 if (nl80211_put_iface_combinations(&rdev->wiphy, msg, 2493 state->split)) 2494 goto nla_put_failure; 2495 2496 state->split_start++; 2497 if (state->split) 2498 break; 2499 fallthrough; 2500 case 8: 2501 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && 2502 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, 2503 rdev->wiphy.ap_sme_capa)) 2504 goto nla_put_failure; 2505 2506 features = rdev->wiphy.features; 2507 /* 2508 * We can only add the per-channel limit information if the 2509 * dump is split, otherwise it makes it too big. Therefore 2510 * only advertise it in that case. 2511 */ 2512 if (state->split) 2513 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; 2514 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) 2515 goto nla_put_failure; 2516 2517 if (rdev->wiphy.ht_capa_mod_mask && 2518 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, 2519 sizeof(*rdev->wiphy.ht_capa_mod_mask), 2520 rdev->wiphy.ht_capa_mod_mask)) 2521 goto nla_put_failure; 2522 2523 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && 2524 rdev->wiphy.max_acl_mac_addrs && 2525 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, 2526 rdev->wiphy.max_acl_mac_addrs)) 2527 goto nla_put_failure; 2528 2529 /* 2530 * Any information below this point is only available to 2531 * applications that can deal with it being split. This 2532 * helps ensure that newly added capabilities don't break 2533 * older tools by overrunning their buffers. 2534 * 2535 * We still increment split_start so that in the split 2536 * case we'll continue with more data in the next round, 2537 * but break unconditionally so unsplit data stops here. 2538 */ 2539 if (state->split) 2540 state->split_start++; 2541 else 2542 state->split_start = 0; 2543 break; 2544 case 9: 2545 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) 2546 goto nla_put_failure; 2547 2548 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, 2549 rdev->wiphy.max_sched_scan_plans) || 2550 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, 2551 rdev->wiphy.max_sched_scan_plan_interval) || 2552 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, 2553 rdev->wiphy.max_sched_scan_plan_iterations)) 2554 goto nla_put_failure; 2555 2556 if (rdev->wiphy.extended_capabilities && 2557 (nla_put(msg, NL80211_ATTR_EXT_CAPA, 2558 rdev->wiphy.extended_capabilities_len, 2559 rdev->wiphy.extended_capabilities) || 2560 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2561 rdev->wiphy.extended_capabilities_len, 2562 rdev->wiphy.extended_capabilities_mask))) 2563 goto nla_put_failure; 2564 2565 if (rdev->wiphy.vht_capa_mod_mask && 2566 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, 2567 sizeof(*rdev->wiphy.vht_capa_mod_mask), 2568 rdev->wiphy.vht_capa_mod_mask)) 2569 goto nla_put_failure; 2570 2571 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 2572 rdev->wiphy.perm_addr)) 2573 goto nla_put_failure; 2574 2575 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && 2576 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, 2577 rdev->wiphy.addr_mask)) 2578 goto nla_put_failure; 2579 2580 if (rdev->wiphy.n_addresses > 1) { 2581 void *attr; 2582 2583 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); 2584 if (!attr) 2585 goto nla_put_failure; 2586 2587 for (i = 0; i < rdev->wiphy.n_addresses; i++) 2588 if (nla_put(msg, i + 1, ETH_ALEN, 2589 rdev->wiphy.addresses[i].addr)) 2590 goto nla_put_failure; 2591 2592 nla_nest_end(msg, attr); 2593 } 2594 2595 state->split_start++; 2596 break; 2597 case 10: 2598 if (nl80211_send_coalesce(msg, rdev)) 2599 goto nla_put_failure; 2600 2601 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && 2602 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || 2603 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) 2604 goto nla_put_failure; 2605 2606 if (rdev->wiphy.max_ap_assoc_sta && 2607 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, 2608 rdev->wiphy.max_ap_assoc_sta)) 2609 goto nla_put_failure; 2610 2611 state->split_start++; 2612 break; 2613 case 11: 2614 if (rdev->wiphy.n_vendor_commands) { 2615 const struct nl80211_vendor_cmd_info *info; 2616 struct nlattr *nested; 2617 2618 nested = nla_nest_start_noflag(msg, 2619 NL80211_ATTR_VENDOR_DATA); 2620 if (!nested) 2621 goto nla_put_failure; 2622 2623 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 2624 info = &rdev->wiphy.vendor_commands[i].info; 2625 if (nla_put(msg, i + 1, sizeof(*info), info)) 2626 goto nla_put_failure; 2627 } 2628 nla_nest_end(msg, nested); 2629 } 2630 2631 if (rdev->wiphy.n_vendor_events) { 2632 const struct nl80211_vendor_cmd_info *info; 2633 struct nlattr *nested; 2634 2635 nested = nla_nest_start_noflag(msg, 2636 NL80211_ATTR_VENDOR_EVENTS); 2637 if (!nested) 2638 goto nla_put_failure; 2639 2640 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { 2641 info = &rdev->wiphy.vendor_events[i]; 2642 if (nla_put(msg, i + 1, sizeof(*info), info)) 2643 goto nla_put_failure; 2644 } 2645 nla_nest_end(msg, nested); 2646 } 2647 state->split_start++; 2648 break; 2649 case 12: 2650 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && 2651 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, 2652 rdev->wiphy.max_num_csa_counters)) 2653 goto nla_put_failure; 2654 2655 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 2656 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 2657 goto nla_put_failure; 2658 2659 if (rdev->wiphy.max_sched_scan_reqs && 2660 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, 2661 rdev->wiphy.max_sched_scan_reqs)) 2662 goto nla_put_failure; 2663 2664 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, 2665 sizeof(rdev->wiphy.ext_features), 2666 rdev->wiphy.ext_features)) 2667 goto nla_put_failure; 2668 2669 if (rdev->wiphy.bss_select_support) { 2670 struct nlattr *nested; 2671 u32 bss_select_support = rdev->wiphy.bss_select_support; 2672 2673 nested = nla_nest_start_noflag(msg, 2674 NL80211_ATTR_BSS_SELECT); 2675 if (!nested) 2676 goto nla_put_failure; 2677 2678 i = 0; 2679 while (bss_select_support) { 2680 if ((bss_select_support & 1) && 2681 nla_put_flag(msg, i)) 2682 goto nla_put_failure; 2683 i++; 2684 bss_select_support >>= 1; 2685 } 2686 nla_nest_end(msg, nested); 2687 } 2688 2689 state->split_start++; 2690 break; 2691 case 13: 2692 if (rdev->wiphy.num_iftype_ext_capab && 2693 rdev->wiphy.iftype_ext_capab) { 2694 struct nlattr *nested_ext_capab, *nested; 2695 2696 nested = nla_nest_start_noflag(msg, 2697 NL80211_ATTR_IFTYPE_EXT_CAPA); 2698 if (!nested) 2699 goto nla_put_failure; 2700 2701 for (i = state->capa_start; 2702 i < rdev->wiphy.num_iftype_ext_capab; i++) { 2703 const struct wiphy_iftype_ext_capab *capab; 2704 2705 capab = &rdev->wiphy.iftype_ext_capab[i]; 2706 2707 nested_ext_capab = nla_nest_start_noflag(msg, 2708 i); 2709 if (!nested_ext_capab || 2710 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2711 capab->iftype) || 2712 nla_put(msg, NL80211_ATTR_EXT_CAPA, 2713 capab->extended_capabilities_len, 2714 capab->extended_capabilities) || 2715 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2716 capab->extended_capabilities_len, 2717 capab->extended_capabilities_mask)) 2718 goto nla_put_failure; 2719 2720 nla_nest_end(msg, nested_ext_capab); 2721 if (state->split) 2722 break; 2723 } 2724 nla_nest_end(msg, nested); 2725 if (i < rdev->wiphy.num_iftype_ext_capab) { 2726 state->capa_start = i + 1; 2727 break; 2728 } 2729 } 2730 2731 if (nla_put_u32(msg, NL80211_ATTR_BANDS, 2732 rdev->wiphy.nan_supported_bands)) 2733 goto nla_put_failure; 2734 2735 if (wiphy_ext_feature_isset(&rdev->wiphy, 2736 NL80211_EXT_FEATURE_TXQS)) { 2737 struct cfg80211_txq_stats txqstats = {}; 2738 int res; 2739 2740 res = rdev_get_txq_stats(rdev, NULL, &txqstats); 2741 if (!res && 2742 !nl80211_put_txq_stats(msg, &txqstats, 2743 NL80211_ATTR_TXQ_STATS)) 2744 goto nla_put_failure; 2745 2746 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, 2747 rdev->wiphy.txq_limit)) 2748 goto nla_put_failure; 2749 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, 2750 rdev->wiphy.txq_memory_limit)) 2751 goto nla_put_failure; 2752 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, 2753 rdev->wiphy.txq_quantum)) 2754 goto nla_put_failure; 2755 } 2756 2757 state->split_start++; 2758 break; 2759 case 14: 2760 if (nl80211_send_pmsr_capa(rdev, msg)) 2761 goto nla_put_failure; 2762 2763 state->split_start++; 2764 break; 2765 case 15: 2766 if (rdev->wiphy.akm_suites && 2767 nla_put(msg, NL80211_ATTR_AKM_SUITES, 2768 sizeof(u32) * rdev->wiphy.n_akm_suites, 2769 rdev->wiphy.akm_suites)) 2770 goto nla_put_failure; 2771 2772 if (nl80211_put_iftype_akm_suites(rdev, msg)) 2773 goto nla_put_failure; 2774 2775 if (nl80211_put_tid_config_support(rdev, msg)) 2776 goto nla_put_failure; 2777 state->split_start++; 2778 break; 2779 case 16: 2780 if (nl80211_put_sar_specs(rdev, msg)) 2781 goto nla_put_failure; 2782 2783 /* done */ 2784 state->split_start = 0; 2785 break; 2786 } 2787 finish: 2788 genlmsg_end(msg, hdr); 2789 return 0; 2790 2791 nla_put_failure: 2792 genlmsg_cancel(msg, hdr); 2793 return -EMSGSIZE; 2794 } 2795 2796 static int nl80211_dump_wiphy_parse(struct sk_buff *skb, 2797 struct netlink_callback *cb, 2798 struct nl80211_dump_wiphy_state *state) 2799 { 2800 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 2801 int ret; 2802 2803 if (!tb) 2804 return -ENOMEM; 2805 2806 ret = nlmsg_parse_deprecated(cb->nlh, 2807 GENL_HDRLEN + nl80211_fam.hdrsize, 2808 tb, nl80211_fam.maxattr, 2809 nl80211_policy, NULL); 2810 /* ignore parse errors for backward compatibility */ 2811 if (ret) { 2812 ret = 0; 2813 goto out; 2814 } 2815 2816 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; 2817 if (tb[NL80211_ATTR_WIPHY]) 2818 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 2819 if (tb[NL80211_ATTR_WDEV]) 2820 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; 2821 if (tb[NL80211_ATTR_IFINDEX]) { 2822 struct net_device *netdev; 2823 struct cfg80211_registered_device *rdev; 2824 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); 2825 2826 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); 2827 if (!netdev) { 2828 ret = -ENODEV; 2829 goto out; 2830 } 2831 if (netdev->ieee80211_ptr) { 2832 rdev = wiphy_to_rdev( 2833 netdev->ieee80211_ptr->wiphy); 2834 state->filter_wiphy = rdev->wiphy_idx; 2835 } 2836 } 2837 2838 ret = 0; 2839 out: 2840 kfree(tb); 2841 return ret; 2842 } 2843 2844 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) 2845 { 2846 int idx = 0, ret; 2847 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; 2848 struct cfg80211_registered_device *rdev; 2849 2850 rtnl_lock(); 2851 if (!state) { 2852 state = kzalloc(sizeof(*state), GFP_KERNEL); 2853 if (!state) { 2854 rtnl_unlock(); 2855 return -ENOMEM; 2856 } 2857 state->filter_wiphy = -1; 2858 ret = nl80211_dump_wiphy_parse(skb, cb, state); 2859 if (ret) { 2860 kfree(state); 2861 rtnl_unlock(); 2862 return ret; 2863 } 2864 cb->args[0] = (long)state; 2865 } 2866 2867 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 2868 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 2869 continue; 2870 if (++idx <= state->start) 2871 continue; 2872 if (state->filter_wiphy != -1 && 2873 state->filter_wiphy != rdev->wiphy_idx) 2874 continue; 2875 /* attempt to fit multiple wiphy data chunks into the skb */ 2876 do { 2877 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, 2878 skb, 2879 NETLINK_CB(cb->skb).portid, 2880 cb->nlh->nlmsg_seq, 2881 NLM_F_MULTI, state); 2882 if (ret < 0) { 2883 /* 2884 * If sending the wiphy data didn't fit (ENOBUFS 2885 * or EMSGSIZE returned), this SKB is still 2886 * empty (so it's not too big because another 2887 * wiphy dataset is already in the skb) and 2888 * we've not tried to adjust the dump allocation 2889 * yet ... then adjust the alloc size to be 2890 * bigger, and return 1 but with the empty skb. 2891 * This results in an empty message being RX'ed 2892 * in userspace, but that is ignored. 2893 * 2894 * We can then retry with the larger buffer. 2895 */ 2896 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 2897 !skb->len && !state->split && 2898 cb->min_dump_alloc < 4096) { 2899 cb->min_dump_alloc = 4096; 2900 state->split_start = 0; 2901 rtnl_unlock(); 2902 return 1; 2903 } 2904 idx--; 2905 break; 2906 } 2907 } while (state->split_start > 0); 2908 break; 2909 } 2910 rtnl_unlock(); 2911 2912 state->start = idx; 2913 2914 return skb->len; 2915 } 2916 2917 static int nl80211_dump_wiphy_done(struct netlink_callback *cb) 2918 { 2919 kfree((void *)cb->args[0]); 2920 return 0; 2921 } 2922 2923 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 2924 { 2925 struct sk_buff *msg; 2926 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2927 struct nl80211_dump_wiphy_state state = {}; 2928 2929 msg = nlmsg_new(4096, GFP_KERNEL); 2930 if (!msg) 2931 return -ENOMEM; 2932 2933 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, 2934 info->snd_portid, info->snd_seq, 0, 2935 &state) < 0) { 2936 nlmsg_free(msg); 2937 return -ENOBUFS; 2938 } 2939 2940 return genlmsg_reply(msg, info); 2941 } 2942 2943 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 2944 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, 2945 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, 2946 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, 2947 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, 2948 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, 2949 }; 2950 2951 static int parse_txq_params(struct nlattr *tb[], 2952 struct ieee80211_txq_params *txq_params) 2953 { 2954 u8 ac; 2955 2956 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || 2957 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || 2958 !tb[NL80211_TXQ_ATTR_AIFS]) 2959 return -EINVAL; 2960 2961 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); 2962 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); 2963 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); 2964 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); 2965 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); 2966 2967 if (ac >= NL80211_NUM_ACS) 2968 return -EINVAL; 2969 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); 2970 return 0; 2971 } 2972 2973 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 2974 { 2975 /* 2976 * You can only set the channel explicitly for some interfaces, 2977 * most have their channel managed via their respective 2978 * "establish a connection" command (connect, join, ...) 2979 * 2980 * For AP/GO and mesh mode, the channel can be set with the 2981 * channel userspace API, but is only stored and passed to the 2982 * low-level driver when the AP starts or the mesh is joined. 2983 * This is for backward compatibility, userspace can also give 2984 * the channel in the start-ap or join-mesh commands instead. 2985 * 2986 * Monitors are special as they are normally slaved to 2987 * whatever else is going on, so they have their own special 2988 * operation to set the monitor channel if possible. 2989 */ 2990 return !wdev || 2991 wdev->iftype == NL80211_IFTYPE_AP || 2992 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 2993 wdev->iftype == NL80211_IFTYPE_MONITOR || 2994 wdev->iftype == NL80211_IFTYPE_P2P_GO; 2995 } 2996 2997 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, 2998 struct genl_info *info, 2999 struct cfg80211_chan_def *chandef) 3000 { 3001 struct netlink_ext_ack *extack = info->extack; 3002 struct nlattr **attrs = info->attrs; 3003 u32 control_freq; 3004 3005 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) 3006 return -EINVAL; 3007 3008 control_freq = MHZ_TO_KHZ( 3009 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 3010 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 3011 control_freq += 3012 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 3013 3014 memset(chandef, 0, sizeof(*chandef)); 3015 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); 3016 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 3017 chandef->center_freq1 = KHZ_TO_MHZ(control_freq); 3018 chandef->freq1_offset = control_freq % 1000; 3019 chandef->center_freq2 = 0; 3020 3021 /* Primary channel not allowed */ 3022 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { 3023 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 3024 "Channel is disabled"); 3025 return -EINVAL; 3026 } 3027 3028 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 3029 enum nl80211_channel_type chantype; 3030 3031 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); 3032 3033 switch (chantype) { 3034 case NL80211_CHAN_NO_HT: 3035 case NL80211_CHAN_HT20: 3036 case NL80211_CHAN_HT40PLUS: 3037 case NL80211_CHAN_HT40MINUS: 3038 cfg80211_chandef_create(chandef, chandef->chan, 3039 chantype); 3040 /* user input for center_freq is incorrect */ 3041 if (attrs[NL80211_ATTR_CENTER_FREQ1] && 3042 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { 3043 NL_SET_ERR_MSG_ATTR(extack, 3044 attrs[NL80211_ATTR_CENTER_FREQ1], 3045 "bad center frequency 1"); 3046 return -EINVAL; 3047 } 3048 /* center_freq2 must be zero */ 3049 if (attrs[NL80211_ATTR_CENTER_FREQ2] && 3050 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { 3051 NL_SET_ERR_MSG_ATTR(extack, 3052 attrs[NL80211_ATTR_CENTER_FREQ2], 3053 "center frequency 2 can't be used"); 3054 return -EINVAL; 3055 } 3056 break; 3057 default: 3058 NL_SET_ERR_MSG_ATTR(extack, 3059 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], 3060 "invalid channel type"); 3061 return -EINVAL; 3062 } 3063 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { 3064 chandef->width = 3065 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); 3066 if (attrs[NL80211_ATTR_CENTER_FREQ1]) { 3067 chandef->center_freq1 = 3068 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 3069 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) 3070 chandef->freq1_offset = nla_get_u32( 3071 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); 3072 else 3073 chandef->freq1_offset = 0; 3074 } 3075 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 3076 chandef->center_freq2 = 3077 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); 3078 } 3079 3080 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 3081 chandef->edmg.channels = 3082 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 3083 3084 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 3085 chandef->edmg.bw_config = 3086 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 3087 } else { 3088 chandef->edmg.bw_config = 0; 3089 chandef->edmg.channels = 0; 3090 } 3091 3092 if (!cfg80211_chandef_valid(chandef)) { 3093 NL_SET_ERR_MSG(extack, "invalid channel definition"); 3094 return -EINVAL; 3095 } 3096 3097 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, 3098 IEEE80211_CHAN_DISABLED)) { 3099 NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); 3100 return -EINVAL; 3101 } 3102 3103 if ((chandef->width == NL80211_CHAN_WIDTH_5 || 3104 chandef->width == NL80211_CHAN_WIDTH_10) && 3105 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { 3106 NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); 3107 return -EINVAL; 3108 } 3109 3110 return 0; 3111 } 3112 3113 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 3114 struct net_device *dev, 3115 struct genl_info *info) 3116 { 3117 struct cfg80211_chan_def chandef; 3118 int result; 3119 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; 3120 struct wireless_dev *wdev = NULL; 3121 3122 if (dev) 3123 wdev = dev->ieee80211_ptr; 3124 if (!nl80211_can_set_dev_channel(wdev)) 3125 return -EOPNOTSUPP; 3126 if (wdev) 3127 iftype = wdev->iftype; 3128 3129 result = nl80211_parse_chandef(rdev, info, &chandef); 3130 if (result) 3131 return result; 3132 3133 switch (iftype) { 3134 case NL80211_IFTYPE_AP: 3135 case NL80211_IFTYPE_P2P_GO: 3136 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 3137 iftype)) { 3138 result = -EINVAL; 3139 break; 3140 } 3141 if (wdev->beacon_interval) { 3142 if (!dev || !rdev->ops->set_ap_chanwidth || 3143 !(rdev->wiphy.features & 3144 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { 3145 result = -EBUSY; 3146 break; 3147 } 3148 3149 /* Only allow dynamic channel width changes */ 3150 if (chandef.chan != wdev->preset_chandef.chan) { 3151 result = -EBUSY; 3152 break; 3153 } 3154 result = rdev_set_ap_chanwidth(rdev, dev, &chandef); 3155 if (result) 3156 break; 3157 } 3158 wdev->preset_chandef = chandef; 3159 result = 0; 3160 break; 3161 case NL80211_IFTYPE_MESH_POINT: 3162 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); 3163 break; 3164 case NL80211_IFTYPE_MONITOR: 3165 result = cfg80211_set_monitor_channel(rdev, &chandef); 3166 break; 3167 default: 3168 result = -EINVAL; 3169 } 3170 3171 return result; 3172 } 3173 3174 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 3175 { 3176 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3177 struct net_device *netdev = info->user_ptr[1]; 3178 3179 return __nl80211_set_channel(rdev, netdev, info); 3180 } 3181 3182 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 3183 { 3184 struct cfg80211_registered_device *rdev = NULL; 3185 struct net_device *netdev = NULL; 3186 struct wireless_dev *wdev; 3187 int result = 0, rem_txq_params = 0; 3188 struct nlattr *nl_txq_params; 3189 u32 changed; 3190 u8 retry_short = 0, retry_long = 0; 3191 u32 frag_threshold = 0, rts_threshold = 0; 3192 u8 coverage_class = 0; 3193 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; 3194 3195 rtnl_lock(); 3196 /* 3197 * Try to find the wiphy and netdev. Normally this 3198 * function shouldn't need the netdev, but this is 3199 * done for backward compatibility -- previously 3200 * setting the channel was done per wiphy, but now 3201 * it is per netdev. Previous userland like hostapd 3202 * also passed a netdev to set_wiphy, so that it is 3203 * possible to let that go to the right netdev! 3204 */ 3205 3206 if (info->attrs[NL80211_ATTR_IFINDEX]) { 3207 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 3208 3209 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 3210 if (netdev && netdev->ieee80211_ptr) 3211 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); 3212 else 3213 netdev = NULL; 3214 } 3215 3216 if (!netdev) { 3217 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), 3218 info->attrs); 3219 if (IS_ERR(rdev)) { 3220 rtnl_unlock(); 3221 return PTR_ERR(rdev); 3222 } 3223 wdev = NULL; 3224 netdev = NULL; 3225 result = 0; 3226 } else 3227 wdev = netdev->ieee80211_ptr; 3228 3229 wiphy_lock(&rdev->wiphy); 3230 3231 /* 3232 * end workaround code, by now the rdev is available 3233 * and locked, and wdev may or may not be NULL. 3234 */ 3235 3236 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) 3237 result = cfg80211_dev_rename( 3238 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 3239 rtnl_unlock(); 3240 3241 if (result) 3242 goto out; 3243 3244 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 3245 struct ieee80211_txq_params txq_params; 3246 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 3247 3248 if (!rdev->ops->set_txq_params) { 3249 result = -EOPNOTSUPP; 3250 goto out; 3251 } 3252 3253 if (!netdev) { 3254 result = -EINVAL; 3255 goto out; 3256 } 3257 3258 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3259 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 3260 result = -EINVAL; 3261 goto out; 3262 } 3263 3264 if (!netif_running(netdev)) { 3265 result = -ENETDOWN; 3266 goto out; 3267 } 3268 3269 nla_for_each_nested(nl_txq_params, 3270 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 3271 rem_txq_params) { 3272 result = nla_parse_nested_deprecated(tb, 3273 NL80211_TXQ_ATTR_MAX, 3274 nl_txq_params, 3275 txq_params_policy, 3276 info->extack); 3277 if (result) 3278 goto out; 3279 result = parse_txq_params(tb, &txq_params); 3280 if (result) 3281 goto out; 3282 3283 result = rdev_set_txq_params(rdev, netdev, 3284 &txq_params); 3285 if (result) 3286 goto out; 3287 } 3288 } 3289 3290 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3291 result = __nl80211_set_channel( 3292 rdev, 3293 nl80211_can_set_dev_channel(wdev) ? netdev : NULL, 3294 info); 3295 if (result) 3296 goto out; 3297 } 3298 3299 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { 3300 struct wireless_dev *txp_wdev = wdev; 3301 enum nl80211_tx_power_setting type; 3302 int idx, mbm = 0; 3303 3304 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 3305 txp_wdev = NULL; 3306 3307 if (!rdev->ops->set_tx_power) { 3308 result = -EOPNOTSUPP; 3309 goto out; 3310 } 3311 3312 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 3313 type = nla_get_u32(info->attrs[idx]); 3314 3315 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 3316 (type != NL80211_TX_POWER_AUTOMATIC)) { 3317 result = -EINVAL; 3318 goto out; 3319 } 3320 3321 if (type != NL80211_TX_POWER_AUTOMATIC) { 3322 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; 3323 mbm = nla_get_u32(info->attrs[idx]); 3324 } 3325 3326 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 3327 if (result) 3328 goto out; 3329 } 3330 3331 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && 3332 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { 3333 u32 tx_ant, rx_ant; 3334 3335 if ((!rdev->wiphy.available_antennas_tx && 3336 !rdev->wiphy.available_antennas_rx) || 3337 !rdev->ops->set_antenna) { 3338 result = -EOPNOTSUPP; 3339 goto out; 3340 } 3341 3342 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 3343 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); 3344 3345 /* reject antenna configurations which don't match the 3346 * available antenna masks, except for the "all" mask */ 3347 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 3348 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { 3349 result = -EINVAL; 3350 goto out; 3351 } 3352 3353 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 3354 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 3355 3356 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 3357 if (result) 3358 goto out; 3359 } 3360 3361 changed = 0; 3362 3363 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 3364 retry_short = nla_get_u8( 3365 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); 3366 3367 changed |= WIPHY_PARAM_RETRY_SHORT; 3368 } 3369 3370 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { 3371 retry_long = nla_get_u8( 3372 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); 3373 3374 changed |= WIPHY_PARAM_RETRY_LONG; 3375 } 3376 3377 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 3378 frag_threshold = nla_get_u32( 3379 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 3380 if (frag_threshold < 256) { 3381 result = -EINVAL; 3382 goto out; 3383 } 3384 3385 if (frag_threshold != (u32) -1) { 3386 /* 3387 * Fragments (apart from the last one) are required to 3388 * have even length. Make the fragmentation code 3389 * simpler by stripping LSB should someone try to use 3390 * odd threshold value. 3391 */ 3392 frag_threshold &= ~0x1; 3393 } 3394 changed |= WIPHY_PARAM_FRAG_THRESHOLD; 3395 } 3396 3397 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { 3398 rts_threshold = nla_get_u32( 3399 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); 3400 changed |= WIPHY_PARAM_RTS_THRESHOLD; 3401 } 3402 3403 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 3404 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3405 result = -EINVAL; 3406 goto out; 3407 } 3408 3409 coverage_class = nla_get_u8( 3410 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); 3411 changed |= WIPHY_PARAM_COVERAGE_CLASS; 3412 } 3413 3414 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3415 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { 3416 result = -EOPNOTSUPP; 3417 goto out; 3418 } 3419 3420 changed |= WIPHY_PARAM_DYN_ACK; 3421 } 3422 3423 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 3424 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3425 NL80211_EXT_FEATURE_TXQS)) { 3426 result = -EOPNOTSUPP; 3427 goto out; 3428 } 3429 txq_limit = nla_get_u32( 3430 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 3431 changed |= WIPHY_PARAM_TXQ_LIMIT; 3432 } 3433 3434 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 3435 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3436 NL80211_EXT_FEATURE_TXQS)) { 3437 result = -EOPNOTSUPP; 3438 goto out; 3439 } 3440 txq_memory_limit = nla_get_u32( 3441 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 3442 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; 3443 } 3444 3445 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 3446 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3447 NL80211_EXT_FEATURE_TXQS)) { 3448 result = -EOPNOTSUPP; 3449 goto out; 3450 } 3451 txq_quantum = nla_get_u32( 3452 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 3453 changed |= WIPHY_PARAM_TXQ_QUANTUM; 3454 } 3455 3456 if (changed) { 3457 u8 old_retry_short, old_retry_long; 3458 u32 old_frag_threshold, old_rts_threshold; 3459 u8 old_coverage_class; 3460 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 3461 3462 if (!rdev->ops->set_wiphy_params) { 3463 result = -EOPNOTSUPP; 3464 goto out; 3465 } 3466 3467 old_retry_short = rdev->wiphy.retry_short; 3468 old_retry_long = rdev->wiphy.retry_long; 3469 old_frag_threshold = rdev->wiphy.frag_threshold; 3470 old_rts_threshold = rdev->wiphy.rts_threshold; 3471 old_coverage_class = rdev->wiphy.coverage_class; 3472 old_txq_limit = rdev->wiphy.txq_limit; 3473 old_txq_memory_limit = rdev->wiphy.txq_memory_limit; 3474 old_txq_quantum = rdev->wiphy.txq_quantum; 3475 3476 if (changed & WIPHY_PARAM_RETRY_SHORT) 3477 rdev->wiphy.retry_short = retry_short; 3478 if (changed & WIPHY_PARAM_RETRY_LONG) 3479 rdev->wiphy.retry_long = retry_long; 3480 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 3481 rdev->wiphy.frag_threshold = frag_threshold; 3482 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 3483 rdev->wiphy.rts_threshold = rts_threshold; 3484 if (changed & WIPHY_PARAM_COVERAGE_CLASS) 3485 rdev->wiphy.coverage_class = coverage_class; 3486 if (changed & WIPHY_PARAM_TXQ_LIMIT) 3487 rdev->wiphy.txq_limit = txq_limit; 3488 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) 3489 rdev->wiphy.txq_memory_limit = txq_memory_limit; 3490 if (changed & WIPHY_PARAM_TXQ_QUANTUM) 3491 rdev->wiphy.txq_quantum = txq_quantum; 3492 3493 result = rdev_set_wiphy_params(rdev, changed); 3494 if (result) { 3495 rdev->wiphy.retry_short = old_retry_short; 3496 rdev->wiphy.retry_long = old_retry_long; 3497 rdev->wiphy.frag_threshold = old_frag_threshold; 3498 rdev->wiphy.rts_threshold = old_rts_threshold; 3499 rdev->wiphy.coverage_class = old_coverage_class; 3500 rdev->wiphy.txq_limit = old_txq_limit; 3501 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3502 rdev->wiphy.txq_quantum = old_txq_quantum; 3503 goto out; 3504 } 3505 } 3506 3507 result = 0; 3508 3509 out: 3510 wiphy_unlock(&rdev->wiphy); 3511 return result; 3512 } 3513 3514 static int nl80211_send_chandef(struct sk_buff *msg, 3515 const struct cfg80211_chan_def *chandef) 3516 { 3517 if (WARN_ON(!cfg80211_chandef_valid(chandef))) 3518 return -EINVAL; 3519 3520 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 3521 chandef->chan->center_freq)) 3522 return -ENOBUFS; 3523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 3524 chandef->chan->freq_offset)) 3525 return -ENOBUFS; 3526 switch (chandef->width) { 3527 case NL80211_CHAN_WIDTH_20_NOHT: 3528 case NL80211_CHAN_WIDTH_20: 3529 case NL80211_CHAN_WIDTH_40: 3530 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 3531 cfg80211_get_chandef_type(chandef))) 3532 return -ENOBUFS; 3533 break; 3534 default: 3535 break; 3536 } 3537 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) 3538 return -ENOBUFS; 3539 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) 3540 return -ENOBUFS; 3541 if (chandef->center_freq2 && 3542 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) 3543 return -ENOBUFS; 3544 return 0; 3545 } 3546 3547 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, 3548 struct cfg80211_registered_device *rdev, 3549 struct wireless_dev *wdev, 3550 enum nl80211_commands cmd) 3551 { 3552 struct net_device *dev = wdev->netdev; 3553 void *hdr; 3554 3555 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && 3556 cmd != NL80211_CMD_DEL_INTERFACE && 3557 cmd != NL80211_CMD_SET_INTERFACE); 3558 3559 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 3560 if (!hdr) 3561 return -1; 3562 3563 if (dev && 3564 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3565 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) 3566 goto nla_put_failure; 3567 3568 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3569 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || 3570 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3571 NL80211_ATTR_PAD) || 3572 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || 3573 nla_put_u32(msg, NL80211_ATTR_GENERATION, 3574 rdev->devlist_generation ^ 3575 (cfg80211_rdev_list_generation << 2)) || 3576 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) 3577 goto nla_put_failure; 3578 3579 if (rdev->ops->get_channel) { 3580 int ret; 3581 struct cfg80211_chan_def chandef = {}; 3582 3583 ret = rdev_get_channel(rdev, wdev, &chandef); 3584 if (ret == 0) { 3585 if (nl80211_send_chandef(msg, &chandef)) 3586 goto nla_put_failure; 3587 } 3588 } 3589 3590 if (rdev->ops->get_tx_power) { 3591 int dbm, ret; 3592 3593 ret = rdev_get_tx_power(rdev, wdev, &dbm); 3594 if (ret == 0 && 3595 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, 3596 DBM_TO_MBM(dbm))) 3597 goto nla_put_failure; 3598 } 3599 3600 wdev_lock(wdev); 3601 switch (wdev->iftype) { 3602 case NL80211_IFTYPE_AP: 3603 if (wdev->ssid_len && 3604 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) 3605 goto nla_put_failure_locked; 3606 break; 3607 case NL80211_IFTYPE_STATION: 3608 case NL80211_IFTYPE_P2P_CLIENT: 3609 case NL80211_IFTYPE_ADHOC: { 3610 const u8 *ssid_ie; 3611 if (!wdev->current_bss) 3612 break; 3613 rcu_read_lock(); 3614 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, 3615 WLAN_EID_SSID); 3616 if (ssid_ie && 3617 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) 3618 goto nla_put_failure_rcu_locked; 3619 rcu_read_unlock(); 3620 break; 3621 } 3622 default: 3623 /* nothing */ 3624 break; 3625 } 3626 wdev_unlock(wdev); 3627 3628 if (rdev->ops->get_txq_stats) { 3629 struct cfg80211_txq_stats txqstats = {}; 3630 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); 3631 3632 if (ret == 0 && 3633 !nl80211_put_txq_stats(msg, &txqstats, 3634 NL80211_ATTR_TXQ_STATS)) 3635 goto nla_put_failure; 3636 } 3637 3638 genlmsg_end(msg, hdr); 3639 return 0; 3640 3641 nla_put_failure_rcu_locked: 3642 rcu_read_unlock(); 3643 nla_put_failure_locked: 3644 wdev_unlock(wdev); 3645 nla_put_failure: 3646 genlmsg_cancel(msg, hdr); 3647 return -EMSGSIZE; 3648 } 3649 3650 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) 3651 { 3652 int wp_idx = 0; 3653 int if_idx = 0; 3654 int wp_start = cb->args[0]; 3655 int if_start = cb->args[1]; 3656 int filter_wiphy = -1; 3657 struct cfg80211_registered_device *rdev; 3658 struct wireless_dev *wdev; 3659 int ret; 3660 3661 rtnl_lock(); 3662 if (!cb->args[2]) { 3663 struct nl80211_dump_wiphy_state state = { 3664 .filter_wiphy = -1, 3665 }; 3666 3667 ret = nl80211_dump_wiphy_parse(skb, cb, &state); 3668 if (ret) 3669 goto out_unlock; 3670 3671 filter_wiphy = state.filter_wiphy; 3672 3673 /* 3674 * if filtering, set cb->args[2] to +1 since 0 is the default 3675 * value needed to determine that parsing is necessary. 3676 */ 3677 if (filter_wiphy >= 0) 3678 cb->args[2] = filter_wiphy + 1; 3679 else 3680 cb->args[2] = -1; 3681 } else if (cb->args[2] > 0) { 3682 filter_wiphy = cb->args[2] - 1; 3683 } 3684 3685 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3686 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3687 continue; 3688 if (wp_idx < wp_start) { 3689 wp_idx++; 3690 continue; 3691 } 3692 3693 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) 3694 continue; 3695 3696 if_idx = 0; 3697 3698 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 3699 if (if_idx < if_start) { 3700 if_idx++; 3701 continue; 3702 } 3703 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 3704 cb->nlh->nlmsg_seq, NLM_F_MULTI, 3705 rdev, wdev, 3706 NL80211_CMD_NEW_INTERFACE) < 0) { 3707 goto out; 3708 } 3709 if_idx++; 3710 } 3711 3712 wp_idx++; 3713 } 3714 out: 3715 cb->args[0] = wp_idx; 3716 cb->args[1] = if_idx; 3717 3718 ret = skb->len; 3719 out_unlock: 3720 rtnl_unlock(); 3721 3722 return ret; 3723 } 3724 3725 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 3726 { 3727 struct sk_buff *msg; 3728 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3729 struct wireless_dev *wdev = info->user_ptr[1]; 3730 3731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3732 if (!msg) 3733 return -ENOMEM; 3734 3735 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 3736 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 3737 nlmsg_free(msg); 3738 return -ENOBUFS; 3739 } 3740 3741 return genlmsg_reply(msg, info); 3742 } 3743 3744 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 3745 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, 3746 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, 3747 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, 3748 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, 3749 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, 3750 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, 3751 }; 3752 3753 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) 3754 { 3755 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; 3756 int flag; 3757 3758 *mntrflags = 0; 3759 3760 if (!nla) 3761 return -EINVAL; 3762 3763 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) 3764 return -EINVAL; 3765 3766 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 3767 if (flags[flag]) 3768 *mntrflags |= (1<<flag); 3769 3770 *mntrflags |= MONITOR_FLAG_CHANGED; 3771 3772 return 0; 3773 } 3774 3775 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, 3776 enum nl80211_iftype type, 3777 struct genl_info *info, 3778 struct vif_params *params) 3779 { 3780 bool change = false; 3781 int err; 3782 3783 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 3784 if (type != NL80211_IFTYPE_MONITOR) 3785 return -EINVAL; 3786 3787 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 3788 ¶ms->flags); 3789 if (err) 3790 return err; 3791 3792 change = true; 3793 } 3794 3795 if (params->flags & MONITOR_FLAG_ACTIVE && 3796 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 3797 return -EOPNOTSUPP; 3798 3799 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { 3800 const u8 *mumimo_groups; 3801 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 3802 3803 if (type != NL80211_IFTYPE_MONITOR) 3804 return -EINVAL; 3805 3806 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 3807 return -EOPNOTSUPP; 3808 3809 mumimo_groups = 3810 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); 3811 3812 /* bits 0 and 63 are reserved and must be zero */ 3813 if ((mumimo_groups[0] & BIT(0)) || 3814 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) 3815 return -EINVAL; 3816 3817 params->vht_mumimo_groups = mumimo_groups; 3818 change = true; 3819 } 3820 3821 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { 3822 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 3823 3824 if (type != NL80211_IFTYPE_MONITOR) 3825 return -EINVAL; 3826 3827 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 3828 return -EOPNOTSUPP; 3829 3830 params->vht_mumimo_follow_addr = 3831 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); 3832 change = true; 3833 } 3834 3835 return change ? 1 : 0; 3836 } 3837 3838 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, 3839 struct net_device *netdev, u8 use_4addr, 3840 enum nl80211_iftype iftype) 3841 { 3842 if (!use_4addr) { 3843 if (netdev && netif_is_bridge_port(netdev)) 3844 return -EBUSY; 3845 return 0; 3846 } 3847 3848 switch (iftype) { 3849 case NL80211_IFTYPE_AP_VLAN: 3850 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) 3851 return 0; 3852 break; 3853 case NL80211_IFTYPE_STATION: 3854 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) 3855 return 0; 3856 break; 3857 default: 3858 break; 3859 } 3860 3861 return -EOPNOTSUPP; 3862 } 3863 3864 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 3865 { 3866 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3867 struct vif_params params; 3868 int err; 3869 enum nl80211_iftype otype, ntype; 3870 struct net_device *dev = info->user_ptr[1]; 3871 bool change = false; 3872 3873 memset(¶ms, 0, sizeof(params)); 3874 3875 otype = ntype = dev->ieee80211_ptr->iftype; 3876 3877 if (info->attrs[NL80211_ATTR_IFTYPE]) { 3878 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 3879 if (otype != ntype) 3880 change = true; 3881 } 3882 3883 if (info->attrs[NL80211_ATTR_MESH_ID]) { 3884 struct wireless_dev *wdev = dev->ieee80211_ptr; 3885 3886 if (ntype != NL80211_IFTYPE_MESH_POINT) 3887 return -EINVAL; 3888 if (netif_running(dev)) 3889 return -EBUSY; 3890 3891 wdev_lock(wdev); 3892 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 3893 IEEE80211_MAX_MESH_ID_LEN); 3894 wdev->mesh_id_up_len = 3895 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 3896 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 3897 wdev->mesh_id_up_len); 3898 wdev_unlock(wdev); 3899 } 3900 3901 if (info->attrs[NL80211_ATTR_4ADDR]) { 3902 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 3903 change = true; 3904 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 3905 if (err) 3906 return err; 3907 } else { 3908 params.use_4addr = -1; 3909 } 3910 3911 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); 3912 if (err < 0) 3913 return err; 3914 if (err > 0) 3915 change = true; 3916 3917 if (change) 3918 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); 3919 else 3920 err = 0; 3921 3922 if (!err && params.use_4addr != -1) 3923 dev->ieee80211_ptr->use_4addr = params.use_4addr; 3924 3925 if (change && !err) { 3926 struct wireless_dev *wdev = dev->ieee80211_ptr; 3927 3928 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); 3929 } 3930 3931 return err; 3932 } 3933 3934 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 3935 { 3936 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3937 struct vif_params params; 3938 struct wireless_dev *wdev; 3939 struct sk_buff *msg; 3940 int err; 3941 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 3942 3943 /* to avoid failing a new interface creation due to pending removal */ 3944 cfg80211_destroy_ifaces(rdev); 3945 3946 memset(¶ms, 0, sizeof(params)); 3947 3948 if (!info->attrs[NL80211_ATTR_IFNAME]) 3949 return -EINVAL; 3950 3951 if (info->attrs[NL80211_ATTR_IFTYPE]) 3952 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 3953 3954 if (!rdev->ops->add_virtual_intf) 3955 return -EOPNOTSUPP; 3956 3957 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || 3958 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && 3959 info->attrs[NL80211_ATTR_MAC]) { 3960 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 3961 ETH_ALEN); 3962 if (!is_valid_ether_addr(params.macaddr)) 3963 return -EADDRNOTAVAIL; 3964 } 3965 3966 if (info->attrs[NL80211_ATTR_4ADDR]) { 3967 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 3968 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 3969 if (err) 3970 return err; 3971 } 3972 3973 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) 3974 return -EOPNOTSUPP; 3975 3976 err = nl80211_parse_mon_options(rdev, type, info, ¶ms); 3977 if (err < 0) 3978 return err; 3979 3980 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3981 if (!msg) 3982 return -ENOMEM; 3983 3984 wdev = rdev_add_virtual_intf(rdev, 3985 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 3986 NET_NAME_USER, type, ¶ms); 3987 if (WARN_ON(!wdev)) { 3988 nlmsg_free(msg); 3989 return -EPROTO; 3990 } else if (IS_ERR(wdev)) { 3991 nlmsg_free(msg); 3992 return PTR_ERR(wdev); 3993 } 3994 3995 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 3996 wdev->owner_nlportid = info->snd_portid; 3997 3998 switch (type) { 3999 case NL80211_IFTYPE_MESH_POINT: 4000 if (!info->attrs[NL80211_ATTR_MESH_ID]) 4001 break; 4002 wdev_lock(wdev); 4003 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4004 IEEE80211_MAX_MESH_ID_LEN); 4005 wdev->mesh_id_up_len = 4006 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4007 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4008 wdev->mesh_id_up_len); 4009 wdev_unlock(wdev); 4010 break; 4011 case NL80211_IFTYPE_NAN: 4012 case NL80211_IFTYPE_P2P_DEVICE: 4013 /* 4014 * P2P Device and NAN do not have a netdev, so don't go 4015 * through the netdev notifier and must be added here 4016 */ 4017 cfg80211_init_wdev(wdev); 4018 cfg80211_register_wdev(rdev, wdev); 4019 break; 4020 default: 4021 break; 4022 } 4023 4024 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 4025 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 4026 nlmsg_free(msg); 4027 return -ENOBUFS; 4028 } 4029 4030 return genlmsg_reply(msg, info); 4031 } 4032 4033 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 4034 { 4035 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4036 struct wireless_dev *wdev = info->user_ptr[1]; 4037 4038 if (!rdev->ops->del_virtual_intf) 4039 return -EOPNOTSUPP; 4040 4041 /* 4042 * We hold RTNL, so this is safe, without RTNL opencount cannot 4043 * reach 0, and thus the rdev cannot be deleted. 4044 * 4045 * We need to do it for the dev_close(), since that will call 4046 * the netdev notifiers, and we need to acquire the mutex there 4047 * but don't know if we get there from here or from some other 4048 * place (e.g. "ip link set ... down"). 4049 */ 4050 mutex_unlock(&rdev->wiphy.mtx); 4051 4052 /* 4053 * If we remove a wireless device without a netdev then clear 4054 * user_ptr[1] so that nl80211_post_doit won't dereference it 4055 * to check if it needs to do dev_put(). Otherwise it crashes 4056 * since the wdev has been freed, unlike with a netdev where 4057 * we need the dev_put() for the netdev to really be freed. 4058 */ 4059 if (!wdev->netdev) 4060 info->user_ptr[1] = NULL; 4061 else 4062 dev_close(wdev->netdev); 4063 4064 mutex_lock(&rdev->wiphy.mtx); 4065 4066 return rdev_del_virtual_intf(rdev, wdev); 4067 } 4068 4069 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) 4070 { 4071 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4072 struct net_device *dev = info->user_ptr[1]; 4073 u16 noack_map; 4074 4075 if (!info->attrs[NL80211_ATTR_NOACK_MAP]) 4076 return -EINVAL; 4077 4078 if (!rdev->ops->set_noack_map) 4079 return -EOPNOTSUPP; 4080 4081 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); 4082 4083 return rdev_set_noack_map(rdev, dev, noack_map); 4084 } 4085 4086 struct get_key_cookie { 4087 struct sk_buff *msg; 4088 int error; 4089 int idx; 4090 }; 4091 4092 static void get_key_callback(void *c, struct key_params *params) 4093 { 4094 struct nlattr *key; 4095 struct get_key_cookie *cookie = c; 4096 4097 if ((params->key && 4098 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, 4099 params->key_len, params->key)) || 4100 (params->seq && 4101 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, 4102 params->seq_len, params->seq)) || 4103 (params->cipher && 4104 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, 4105 params->cipher))) 4106 goto nla_put_failure; 4107 4108 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); 4109 if (!key) 4110 goto nla_put_failure; 4111 4112 if ((params->key && 4113 nla_put(cookie->msg, NL80211_KEY_DATA, 4114 params->key_len, params->key)) || 4115 (params->seq && 4116 nla_put(cookie->msg, NL80211_KEY_SEQ, 4117 params->seq_len, params->seq)) || 4118 (params->cipher && 4119 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, 4120 params->cipher))) 4121 goto nla_put_failure; 4122 4123 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) 4124 goto nla_put_failure; 4125 4126 nla_nest_end(cookie->msg, key); 4127 4128 return; 4129 nla_put_failure: 4130 cookie->error = 1; 4131 } 4132 4133 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 4134 { 4135 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4136 int err; 4137 struct net_device *dev = info->user_ptr[1]; 4138 u8 key_idx = 0; 4139 const u8 *mac_addr = NULL; 4140 bool pairwise; 4141 struct get_key_cookie cookie = { 4142 .error = 0, 4143 }; 4144 void *hdr; 4145 struct sk_buff *msg; 4146 bool bigtk_support = false; 4147 4148 if (wiphy_ext_feature_isset(&rdev->wiphy, 4149 NL80211_EXT_FEATURE_BEACON_PROTECTION)) 4150 bigtk_support = true; 4151 4152 if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || 4153 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && 4154 wiphy_ext_feature_isset(&rdev->wiphy, 4155 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) 4156 bigtk_support = true; 4157 4158 if (info->attrs[NL80211_ATTR_KEY_IDX]) { 4159 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 4160 4161 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { 4162 GENL_SET_ERR_MSG(info, "BIGTK not supported"); 4163 return -EINVAL; 4164 } 4165 } 4166 4167 if (info->attrs[NL80211_ATTR_MAC]) 4168 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4169 4170 pairwise = !!mac_addr; 4171 if (info->attrs[NL80211_ATTR_KEY_TYPE]) { 4172 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 4173 4174 if (kt != NL80211_KEYTYPE_GROUP && 4175 kt != NL80211_KEYTYPE_PAIRWISE) 4176 return -EINVAL; 4177 pairwise = kt == NL80211_KEYTYPE_PAIRWISE; 4178 } 4179 4180 if (!rdev->ops->get_key) 4181 return -EOPNOTSUPP; 4182 4183 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4184 return -ENOENT; 4185 4186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4187 if (!msg) 4188 return -ENOMEM; 4189 4190 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 4191 NL80211_CMD_NEW_KEY); 4192 if (!hdr) 4193 goto nla_put_failure; 4194 4195 cookie.msg = msg; 4196 cookie.idx = key_idx; 4197 4198 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 4199 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) 4200 goto nla_put_failure; 4201 if (mac_addr && 4202 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) 4203 goto nla_put_failure; 4204 4205 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, 4206 get_key_callback); 4207 4208 if (err) 4209 goto free_msg; 4210 4211 if (cookie.error) 4212 goto nla_put_failure; 4213 4214 genlmsg_end(msg, hdr); 4215 return genlmsg_reply(msg, info); 4216 4217 nla_put_failure: 4218 err = -ENOBUFS; 4219 free_msg: 4220 nlmsg_free(msg); 4221 return err; 4222 } 4223 4224 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 4225 { 4226 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4227 struct key_parse key; 4228 int err; 4229 struct net_device *dev = info->user_ptr[1]; 4230 4231 err = nl80211_parse_key(info, &key); 4232 if (err) 4233 return err; 4234 4235 if (key.idx < 0) 4236 return -EINVAL; 4237 4238 /* Only support setting default key and 4239 * Extended Key ID action NL80211_KEY_SET_TX. 4240 */ 4241 if (!key.def && !key.defmgmt && !key.defbeacon && 4242 !(key.p.mode == NL80211_KEY_SET_TX)) 4243 return -EINVAL; 4244 4245 wdev_lock(dev->ieee80211_ptr); 4246 4247 if (key.def) { 4248 if (!rdev->ops->set_default_key) { 4249 err = -EOPNOTSUPP; 4250 goto out; 4251 } 4252 4253 err = nl80211_key_allowed(dev->ieee80211_ptr); 4254 if (err) 4255 goto out; 4256 4257 err = rdev_set_default_key(rdev, dev, key.idx, 4258 key.def_uni, key.def_multi); 4259 4260 if (err) 4261 goto out; 4262 4263 #ifdef CONFIG_CFG80211_WEXT 4264 dev->ieee80211_ptr->wext.default_key = key.idx; 4265 #endif 4266 } else if (key.defmgmt) { 4267 if (key.def_uni || !key.def_multi) { 4268 err = -EINVAL; 4269 goto out; 4270 } 4271 4272 if (!rdev->ops->set_default_mgmt_key) { 4273 err = -EOPNOTSUPP; 4274 goto out; 4275 } 4276 4277 err = nl80211_key_allowed(dev->ieee80211_ptr); 4278 if (err) 4279 goto out; 4280 4281 err = rdev_set_default_mgmt_key(rdev, dev, key.idx); 4282 if (err) 4283 goto out; 4284 4285 #ifdef CONFIG_CFG80211_WEXT 4286 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; 4287 #endif 4288 } else if (key.defbeacon) { 4289 if (key.def_uni || !key.def_multi) { 4290 err = -EINVAL; 4291 goto out; 4292 } 4293 4294 if (!rdev->ops->set_default_beacon_key) { 4295 err = -EOPNOTSUPP; 4296 goto out; 4297 } 4298 4299 err = nl80211_key_allowed(dev->ieee80211_ptr); 4300 if (err) 4301 goto out; 4302 4303 err = rdev_set_default_beacon_key(rdev, dev, key.idx); 4304 if (err) 4305 goto out; 4306 } else if (key.p.mode == NL80211_KEY_SET_TX && 4307 wiphy_ext_feature_isset(&rdev->wiphy, 4308 NL80211_EXT_FEATURE_EXT_KEY_ID)) { 4309 u8 *mac_addr = NULL; 4310 4311 if (info->attrs[NL80211_ATTR_MAC]) 4312 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4313 4314 if (!mac_addr || key.idx < 0 || key.idx > 1) { 4315 err = -EINVAL; 4316 goto out; 4317 } 4318 4319 err = rdev_add_key(rdev, dev, key.idx, 4320 NL80211_KEYTYPE_PAIRWISE, 4321 mac_addr, &key.p); 4322 } else { 4323 err = -EINVAL; 4324 } 4325 out: 4326 wdev_unlock(dev->ieee80211_ptr); 4327 4328 return err; 4329 } 4330 4331 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 4332 { 4333 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4334 int err; 4335 struct net_device *dev = info->user_ptr[1]; 4336 struct key_parse key; 4337 const u8 *mac_addr = NULL; 4338 4339 err = nl80211_parse_key(info, &key); 4340 if (err) 4341 return err; 4342 4343 if (!key.p.key) { 4344 GENL_SET_ERR_MSG(info, "no key"); 4345 return -EINVAL; 4346 } 4347 4348 if (info->attrs[NL80211_ATTR_MAC]) 4349 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4350 4351 if (key.type == -1) { 4352 if (mac_addr) 4353 key.type = NL80211_KEYTYPE_PAIRWISE; 4354 else 4355 key.type = NL80211_KEYTYPE_GROUP; 4356 } 4357 4358 /* for now */ 4359 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4360 key.type != NL80211_KEYTYPE_GROUP) { 4361 GENL_SET_ERR_MSG(info, "key type not pairwise or group"); 4362 return -EINVAL; 4363 } 4364 4365 if (key.type == NL80211_KEYTYPE_GROUP && 4366 info->attrs[NL80211_ATTR_VLAN_ID]) 4367 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 4368 4369 if (!rdev->ops->add_key) 4370 return -EOPNOTSUPP; 4371 4372 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, 4373 key.type == NL80211_KEYTYPE_PAIRWISE, 4374 mac_addr)) { 4375 GENL_SET_ERR_MSG(info, "key setting validation failed"); 4376 return -EINVAL; 4377 } 4378 4379 wdev_lock(dev->ieee80211_ptr); 4380 err = nl80211_key_allowed(dev->ieee80211_ptr); 4381 if (err) 4382 GENL_SET_ERR_MSG(info, "key not allowed"); 4383 if (!err) { 4384 err = rdev_add_key(rdev, dev, key.idx, 4385 key.type == NL80211_KEYTYPE_PAIRWISE, 4386 mac_addr, &key.p); 4387 if (err) 4388 GENL_SET_ERR_MSG(info, "key addition failed"); 4389 } 4390 wdev_unlock(dev->ieee80211_ptr); 4391 4392 return err; 4393 } 4394 4395 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 4396 { 4397 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4398 int err; 4399 struct net_device *dev = info->user_ptr[1]; 4400 u8 *mac_addr = NULL; 4401 struct key_parse key; 4402 4403 err = nl80211_parse_key(info, &key); 4404 if (err) 4405 return err; 4406 4407 if (info->attrs[NL80211_ATTR_MAC]) 4408 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4409 4410 if (key.type == -1) { 4411 if (mac_addr) 4412 key.type = NL80211_KEYTYPE_PAIRWISE; 4413 else 4414 key.type = NL80211_KEYTYPE_GROUP; 4415 } 4416 4417 /* for now */ 4418 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4419 key.type != NL80211_KEYTYPE_GROUP) 4420 return -EINVAL; 4421 4422 if (!cfg80211_valid_key_idx(rdev, key.idx, 4423 key.type == NL80211_KEYTYPE_PAIRWISE)) 4424 return -EINVAL; 4425 4426 if (!rdev->ops->del_key) 4427 return -EOPNOTSUPP; 4428 4429 wdev_lock(dev->ieee80211_ptr); 4430 err = nl80211_key_allowed(dev->ieee80211_ptr); 4431 4432 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && 4433 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4434 err = -ENOENT; 4435 4436 if (!err) 4437 err = rdev_del_key(rdev, dev, key.idx, 4438 key.type == NL80211_KEYTYPE_PAIRWISE, 4439 mac_addr); 4440 4441 #ifdef CONFIG_CFG80211_WEXT 4442 if (!err) { 4443 if (key.idx == dev->ieee80211_ptr->wext.default_key) 4444 dev->ieee80211_ptr->wext.default_key = -1; 4445 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) 4446 dev->ieee80211_ptr->wext.default_mgmt_key = -1; 4447 } 4448 #endif 4449 wdev_unlock(dev->ieee80211_ptr); 4450 4451 return err; 4452 } 4453 4454 /* This function returns an error or the number of nested attributes */ 4455 static int validate_acl_mac_addrs(struct nlattr *nl_attr) 4456 { 4457 struct nlattr *attr; 4458 int n_entries = 0, tmp; 4459 4460 nla_for_each_nested(attr, nl_attr, tmp) { 4461 if (nla_len(attr) != ETH_ALEN) 4462 return -EINVAL; 4463 4464 n_entries++; 4465 } 4466 4467 return n_entries; 4468 } 4469 4470 /* 4471 * This function parses ACL information and allocates memory for ACL data. 4472 * On successful return, the calling function is responsible to free the 4473 * ACL buffer returned by this function. 4474 */ 4475 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, 4476 struct genl_info *info) 4477 { 4478 enum nl80211_acl_policy acl_policy; 4479 struct nlattr *attr; 4480 struct cfg80211_acl_data *acl; 4481 int i = 0, n_entries, tmp; 4482 4483 if (!wiphy->max_acl_mac_addrs) 4484 return ERR_PTR(-EOPNOTSUPP); 4485 4486 if (!info->attrs[NL80211_ATTR_ACL_POLICY]) 4487 return ERR_PTR(-EINVAL); 4488 4489 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); 4490 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && 4491 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) 4492 return ERR_PTR(-EINVAL); 4493 4494 if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) 4495 return ERR_PTR(-EINVAL); 4496 4497 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); 4498 if (n_entries < 0) 4499 return ERR_PTR(n_entries); 4500 4501 if (n_entries > wiphy->max_acl_mac_addrs) 4502 return ERR_PTR(-ENOTSUPP); 4503 4504 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); 4505 if (!acl) 4506 return ERR_PTR(-ENOMEM); 4507 4508 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { 4509 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); 4510 i++; 4511 } 4512 4513 acl->n_acl_entries = n_entries; 4514 acl->acl_policy = acl_policy; 4515 4516 return acl; 4517 } 4518 4519 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) 4520 { 4521 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4522 struct net_device *dev = info->user_ptr[1]; 4523 struct cfg80211_acl_data *acl; 4524 int err; 4525 4526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4527 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4528 return -EOPNOTSUPP; 4529 4530 if (!dev->ieee80211_ptr->beacon_interval) 4531 return -EINVAL; 4532 4533 acl = parse_acl_data(&rdev->wiphy, info); 4534 if (IS_ERR(acl)) 4535 return PTR_ERR(acl); 4536 4537 err = rdev_set_mac_acl(rdev, dev, acl); 4538 4539 kfree(acl); 4540 4541 return err; 4542 } 4543 4544 static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 4545 u8 *rates, u8 rates_len) 4546 { 4547 u8 i; 4548 u32 mask = 0; 4549 4550 for (i = 0; i < rates_len; i++) { 4551 int rate = (rates[i] & 0x7f) * 5; 4552 int ridx; 4553 4554 for (ridx = 0; ridx < sband->n_bitrates; ridx++) { 4555 struct ieee80211_rate *srate = 4556 &sband->bitrates[ridx]; 4557 if (rate == srate->bitrate) { 4558 mask |= 1 << ridx; 4559 break; 4560 } 4561 } 4562 if (ridx == sband->n_bitrates) 4563 return 0; /* rate not found */ 4564 } 4565 4566 return mask; 4567 } 4568 4569 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, 4570 u8 *rates, u8 rates_len, 4571 u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) 4572 { 4573 u8 i; 4574 4575 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); 4576 4577 for (i = 0; i < rates_len; i++) { 4578 int ridx, rbit; 4579 4580 ridx = rates[i] / 8; 4581 rbit = BIT(rates[i] % 8); 4582 4583 /* check validity */ 4584 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) 4585 return false; 4586 4587 /* check availability */ 4588 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); 4589 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) 4590 mcs[ridx] |= rbit; 4591 else 4592 return false; 4593 } 4594 4595 return true; 4596 } 4597 4598 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) 4599 { 4600 u16 mcs_mask = 0; 4601 4602 switch (vht_mcs_map) { 4603 case IEEE80211_VHT_MCS_NOT_SUPPORTED: 4604 break; 4605 case IEEE80211_VHT_MCS_SUPPORT_0_7: 4606 mcs_mask = 0x00FF; 4607 break; 4608 case IEEE80211_VHT_MCS_SUPPORT_0_8: 4609 mcs_mask = 0x01FF; 4610 break; 4611 case IEEE80211_VHT_MCS_SUPPORT_0_9: 4612 mcs_mask = 0x03FF; 4613 break; 4614 default: 4615 break; 4616 } 4617 4618 return mcs_mask; 4619 } 4620 4621 static void vht_build_mcs_mask(u16 vht_mcs_map, 4622 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) 4623 { 4624 u8 nss; 4625 4626 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 4627 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); 4628 vht_mcs_map >>= 2; 4629 } 4630 } 4631 4632 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, 4633 struct nl80211_txrate_vht *txrate, 4634 u16 mcs[NL80211_VHT_NSS_MAX]) 4635 { 4636 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4637 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; 4638 u8 i; 4639 4640 if (!sband->vht_cap.vht_supported) 4641 return false; 4642 4643 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); 4644 4645 /* Build vht_mcs_mask from VHT capabilities */ 4646 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 4647 4648 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4649 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 4650 mcs[i] = txrate->mcs[i]; 4651 else 4652 return false; 4653 } 4654 4655 return true; 4656 } 4657 4658 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) 4659 { 4660 switch (he_mcs_map) { 4661 case IEEE80211_HE_MCS_NOT_SUPPORTED: 4662 return 0; 4663 case IEEE80211_HE_MCS_SUPPORT_0_7: 4664 return 0x00FF; 4665 case IEEE80211_HE_MCS_SUPPORT_0_9: 4666 return 0x03FF; 4667 case IEEE80211_HE_MCS_SUPPORT_0_11: 4668 return 0xFFF; 4669 default: 4670 break; 4671 } 4672 return 0; 4673 } 4674 4675 static void he_build_mcs_mask(u16 he_mcs_map, 4676 u16 he_mcs_mask[NL80211_HE_NSS_MAX]) 4677 { 4678 u8 nss; 4679 4680 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { 4681 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); 4682 he_mcs_map >>= 2; 4683 } 4684 } 4685 4686 static u16 he_get_txmcsmap(struct genl_info *info, 4687 const struct ieee80211_sta_he_cap *he_cap) 4688 { 4689 struct net_device *dev = info->user_ptr[1]; 4690 struct wireless_dev *wdev = dev->ieee80211_ptr; 4691 __le16 tx_mcs; 4692 4693 switch (wdev->chandef.width) { 4694 case NL80211_CHAN_WIDTH_80P80: 4695 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; 4696 break; 4697 case NL80211_CHAN_WIDTH_160: 4698 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; 4699 break; 4700 default: 4701 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; 4702 break; 4703 } 4704 return le16_to_cpu(tx_mcs); 4705 } 4706 4707 static bool he_set_mcs_mask(struct genl_info *info, 4708 struct wireless_dev *wdev, 4709 struct ieee80211_supported_band *sband, 4710 struct nl80211_txrate_he *txrate, 4711 u16 mcs[NL80211_HE_NSS_MAX]) 4712 { 4713 const struct ieee80211_sta_he_cap *he_cap; 4714 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; 4715 u16 tx_mcs_map = 0; 4716 u8 i; 4717 4718 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 4719 if (!he_cap) 4720 return false; 4721 4722 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); 4723 4724 tx_mcs_map = he_get_txmcsmap(info, he_cap); 4725 4726 /* Build he_mcs_mask from HE capabilities */ 4727 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 4728 4729 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 4730 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 4731 mcs[i] = txrate->mcs[i]; 4732 else 4733 return false; 4734 } 4735 4736 return true; 4737 } 4738 4739 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, 4740 struct nlattr *attrs[], 4741 enum nl80211_attrs attr, 4742 struct cfg80211_bitrate_mask *mask, 4743 struct net_device *dev, 4744 bool default_all_enabled) 4745 { 4746 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 4747 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4748 struct wireless_dev *wdev = dev->ieee80211_ptr; 4749 int rem, i; 4750 struct nlattr *tx_rates; 4751 struct ieee80211_supported_band *sband; 4752 u16 vht_tx_mcs_map, he_tx_mcs_map; 4753 4754 memset(mask, 0, sizeof(*mask)); 4755 /* Default to all rates enabled */ 4756 for (i = 0; i < NUM_NL80211_BANDS; i++) { 4757 const struct ieee80211_sta_he_cap *he_cap; 4758 4759 if (!default_all_enabled) 4760 break; 4761 4762 sband = rdev->wiphy.bands[i]; 4763 4764 if (!sband) 4765 continue; 4766 4767 mask->control[i].legacy = (1 << sband->n_bitrates) - 1; 4768 memcpy(mask->control[i].ht_mcs, 4769 sband->ht_cap.mcs.rx_mask, 4770 sizeof(mask->control[i].ht_mcs)); 4771 4772 if (!sband->vht_cap.vht_supported) 4773 continue; 4774 4775 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4776 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); 4777 4778 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 4779 if (!he_cap) 4780 continue; 4781 4782 he_tx_mcs_map = he_get_txmcsmap(info, he_cap); 4783 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); 4784 4785 mask->control[i].he_gi = 0xFF; 4786 mask->control[i].he_ltf = 0xFF; 4787 } 4788 4789 /* if no rates are given set it back to the defaults */ 4790 if (!attrs[attr]) 4791 goto out; 4792 4793 /* The nested attribute uses enum nl80211_band as the index. This maps 4794 * directly to the enum nl80211_band values used in cfg80211. 4795 */ 4796 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); 4797 nla_for_each_nested(tx_rates, attrs[attr], rem) { 4798 enum nl80211_band band = nla_type(tx_rates); 4799 int err; 4800 4801 if (band < 0 || band >= NUM_NL80211_BANDS) 4802 return -EINVAL; 4803 sband = rdev->wiphy.bands[band]; 4804 if (sband == NULL) 4805 return -EINVAL; 4806 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, 4807 tx_rates, 4808 nl80211_txattr_policy, 4809 info->extack); 4810 if (err) 4811 return err; 4812 if (tb[NL80211_TXRATE_LEGACY]) { 4813 mask->control[band].legacy = rateset_to_mask( 4814 sband, 4815 nla_data(tb[NL80211_TXRATE_LEGACY]), 4816 nla_len(tb[NL80211_TXRATE_LEGACY])); 4817 if ((mask->control[band].legacy == 0) && 4818 nla_len(tb[NL80211_TXRATE_LEGACY])) 4819 return -EINVAL; 4820 } 4821 if (tb[NL80211_TXRATE_HT]) { 4822 if (!ht_rateset_to_mask( 4823 sband, 4824 nla_data(tb[NL80211_TXRATE_HT]), 4825 nla_len(tb[NL80211_TXRATE_HT]), 4826 mask->control[band].ht_mcs)) 4827 return -EINVAL; 4828 } 4829 4830 if (tb[NL80211_TXRATE_VHT]) { 4831 if (!vht_set_mcs_mask( 4832 sband, 4833 nla_data(tb[NL80211_TXRATE_VHT]), 4834 mask->control[band].vht_mcs)) 4835 return -EINVAL; 4836 } 4837 4838 if (tb[NL80211_TXRATE_GI]) { 4839 mask->control[band].gi = 4840 nla_get_u8(tb[NL80211_TXRATE_GI]); 4841 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) 4842 return -EINVAL; 4843 } 4844 if (tb[NL80211_TXRATE_HE] && 4845 !he_set_mcs_mask(info, wdev, sband, 4846 nla_data(tb[NL80211_TXRATE_HE]), 4847 mask->control[band].he_mcs)) 4848 return -EINVAL; 4849 4850 if (tb[NL80211_TXRATE_HE_GI]) 4851 mask->control[band].he_gi = 4852 nla_get_u8(tb[NL80211_TXRATE_HE_GI]); 4853 if (tb[NL80211_TXRATE_HE_LTF]) 4854 mask->control[band].he_ltf = 4855 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); 4856 4857 if (mask->control[band].legacy == 0) { 4858 /* don't allow empty legacy rates if HT, VHT or HE 4859 * are not even supported. 4860 */ 4861 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || 4862 rdev->wiphy.bands[band]->vht_cap.vht_supported || 4863 ieee80211_get_he_iftype_cap(sband, wdev->iftype))) 4864 return -EINVAL; 4865 4866 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) 4867 if (mask->control[band].ht_mcs[i]) 4868 goto out; 4869 4870 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) 4871 if (mask->control[band].vht_mcs[i]) 4872 goto out; 4873 4874 for (i = 0; i < NL80211_HE_NSS_MAX; i++) 4875 if (mask->control[band].he_mcs[i]) 4876 goto out; 4877 4878 /* legacy and mcs rates may not be both empty */ 4879 return -EINVAL; 4880 } 4881 } 4882 4883 out: 4884 return 0; 4885 } 4886 4887 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, 4888 enum nl80211_band band, 4889 struct cfg80211_bitrate_mask *beacon_rate) 4890 { 4891 u32 count_ht, count_vht, count_he, i; 4892 u32 rate = beacon_rate->control[band].legacy; 4893 4894 /* Allow only one rate */ 4895 if (hweight32(rate) > 1) 4896 return -EINVAL; 4897 4898 count_ht = 0; 4899 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 4900 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { 4901 return -EINVAL; 4902 } else if (beacon_rate->control[band].ht_mcs[i]) { 4903 count_ht++; 4904 if (count_ht > 1) 4905 return -EINVAL; 4906 } 4907 if (count_ht && rate) 4908 return -EINVAL; 4909 } 4910 4911 count_vht = 0; 4912 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4913 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { 4914 return -EINVAL; 4915 } else if (beacon_rate->control[band].vht_mcs[i]) { 4916 count_vht++; 4917 if (count_vht > 1) 4918 return -EINVAL; 4919 } 4920 if (count_vht && rate) 4921 return -EINVAL; 4922 } 4923 4924 count_he = 0; 4925 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 4926 if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) { 4927 return -EINVAL; 4928 } else if (beacon_rate->control[band].he_mcs[i]) { 4929 count_he++; 4930 if (count_he > 1) 4931 return -EINVAL; 4932 } 4933 if (count_he && rate) 4934 return -EINVAL; 4935 } 4936 4937 if ((count_ht && count_vht && count_he) || 4938 (!rate && !count_ht && !count_vht && !count_he)) 4939 return -EINVAL; 4940 4941 if (rate && 4942 !wiphy_ext_feature_isset(&rdev->wiphy, 4943 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 4944 return -EINVAL; 4945 if (count_ht && 4946 !wiphy_ext_feature_isset(&rdev->wiphy, 4947 NL80211_EXT_FEATURE_BEACON_RATE_HT)) 4948 return -EINVAL; 4949 if (count_vht && 4950 !wiphy_ext_feature_isset(&rdev->wiphy, 4951 NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 4952 return -EINVAL; 4953 if (count_he && 4954 !wiphy_ext_feature_isset(&rdev->wiphy, 4955 NL80211_EXT_FEATURE_BEACON_RATE_HE)) 4956 return -EINVAL; 4957 4958 return 0; 4959 } 4960 4961 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, 4962 struct nlattr *attrs[], 4963 struct cfg80211_beacon_data *bcn) 4964 { 4965 bool haveinfo = false; 4966 int err; 4967 4968 memset(bcn, 0, sizeof(*bcn)); 4969 4970 if (attrs[NL80211_ATTR_BEACON_HEAD]) { 4971 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); 4972 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); 4973 if (!bcn->head_len) 4974 return -EINVAL; 4975 haveinfo = true; 4976 } 4977 4978 if (attrs[NL80211_ATTR_BEACON_TAIL]) { 4979 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); 4980 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); 4981 haveinfo = true; 4982 } 4983 4984 if (!haveinfo) 4985 return -EINVAL; 4986 4987 if (attrs[NL80211_ATTR_IE]) { 4988 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); 4989 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); 4990 } 4991 4992 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { 4993 bcn->proberesp_ies = 4994 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); 4995 bcn->proberesp_ies_len = 4996 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); 4997 } 4998 4999 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { 5000 bcn->assocresp_ies = 5001 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5002 bcn->assocresp_ies_len = 5003 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5004 } 5005 5006 if (attrs[NL80211_ATTR_PROBE_RESP]) { 5007 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); 5008 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); 5009 } 5010 5011 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 5012 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 5013 5014 err = nla_parse_nested_deprecated(tb, 5015 NL80211_FTM_RESP_ATTR_MAX, 5016 attrs[NL80211_ATTR_FTM_RESPONDER], 5017 NULL, NULL); 5018 if (err) 5019 return err; 5020 5021 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && 5022 wiphy_ext_feature_isset(&rdev->wiphy, 5023 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 5024 bcn->ftm_responder = 1; 5025 else 5026 return -EOPNOTSUPP; 5027 5028 if (tb[NL80211_FTM_RESP_ATTR_LCI]) { 5029 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); 5030 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); 5031 } 5032 5033 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { 5034 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5035 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5036 } 5037 } else { 5038 bcn->ftm_responder = -1; 5039 } 5040 5041 return 0; 5042 } 5043 5044 static int nl80211_parse_he_obss_pd(struct nlattr *attrs, 5045 struct ieee80211_he_obss_pd *he_obss_pd) 5046 { 5047 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; 5048 int err; 5049 5050 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, 5051 he_obss_pd_policy, NULL); 5052 if (err) 5053 return err; 5054 5055 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) 5056 return -EINVAL; 5057 5058 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); 5059 5060 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) 5061 he_obss_pd->min_offset = 5062 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); 5063 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) 5064 he_obss_pd->max_offset = 5065 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); 5066 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) 5067 he_obss_pd->non_srg_max_offset = 5068 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); 5069 5070 if (he_obss_pd->min_offset > he_obss_pd->max_offset) 5071 return -EINVAL; 5072 5073 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) 5074 memcpy(he_obss_pd->bss_color_bitmap, 5075 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), 5076 sizeof(he_obss_pd->bss_color_bitmap)); 5077 5078 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) 5079 memcpy(he_obss_pd->partial_bssid_bitmap, 5080 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), 5081 sizeof(he_obss_pd->partial_bssid_bitmap)); 5082 5083 he_obss_pd->enable = true; 5084 5085 return 0; 5086 } 5087 5088 static int nl80211_parse_he_bss_color(struct nlattr *attrs, 5089 struct cfg80211_he_bss_color *he_bss_color) 5090 { 5091 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; 5092 int err; 5093 5094 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, 5095 he_bss_color_policy, NULL); 5096 if (err) 5097 return err; 5098 5099 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) 5100 return -EINVAL; 5101 5102 he_bss_color->color = 5103 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); 5104 he_bss_color->enabled = 5105 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); 5106 he_bss_color->partial = 5107 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); 5108 5109 return 0; 5110 } 5111 5112 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, 5113 struct nlattr *attrs, 5114 struct cfg80211_ap_settings *params) 5115 { 5116 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; 5117 int ret; 5118 struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; 5119 5120 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5121 NL80211_EXT_FEATURE_FILS_DISCOVERY)) 5122 return -EINVAL; 5123 5124 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, 5125 NULL, NULL); 5126 if (ret) 5127 return ret; 5128 5129 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || 5130 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || 5131 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) 5132 return -EINVAL; 5133 5134 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5135 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5136 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); 5137 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); 5138 5139 return 0; 5140 } 5141 5142 static int 5143 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, 5144 struct nlattr *attrs, 5145 struct cfg80211_ap_settings *params) 5146 { 5147 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; 5148 int ret; 5149 struct cfg80211_unsol_bcast_probe_resp *presp = 5150 ¶ms->unsol_bcast_probe_resp; 5151 5152 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5153 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) 5154 return -EINVAL; 5155 5156 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, 5157 attrs, NULL, NULL); 5158 if (ret) 5159 return ret; 5160 5161 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || 5162 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) 5163 return -EINVAL; 5164 5165 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5166 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5167 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); 5168 return 0; 5169 } 5170 5171 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, 5172 const u8 *rates) 5173 { 5174 int i; 5175 5176 if (!rates) 5177 return; 5178 5179 for (i = 0; i < rates[1]; i++) { 5180 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 5181 params->ht_required = true; 5182 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) 5183 params->vht_required = true; 5184 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) 5185 params->he_required = true; 5186 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E) 5187 params->sae_h2e_required = true; 5188 } 5189 } 5190 5191 /* 5192 * Since the nl80211 API didn't include, from the beginning, attributes about 5193 * HT/VHT requirements/capabilities, we parse them out of the IEs for the 5194 * benefit of drivers that rebuild IEs in the firmware. 5195 */ 5196 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) 5197 { 5198 const struct cfg80211_beacon_data *bcn = ¶ms->beacon; 5199 size_t ies_len = bcn->tail_len; 5200 const u8 *ies = bcn->tail; 5201 const u8 *rates; 5202 const u8 *cap; 5203 5204 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); 5205 nl80211_check_ap_rate_selectors(params, rates); 5206 5207 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); 5208 nl80211_check_ap_rate_selectors(params, rates); 5209 5210 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); 5211 if (cap && cap[1] >= sizeof(*params->ht_cap)) 5212 params->ht_cap = (void *)(cap + 2); 5213 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); 5214 if (cap && cap[1] >= sizeof(*params->vht_cap)) 5215 params->vht_cap = (void *)(cap + 2); 5216 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); 5217 if (cap && cap[1] >= sizeof(*params->he_cap) + 1) 5218 params->he_cap = (void *)(cap + 3); 5219 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); 5220 if (cap && cap[1] >= sizeof(*params->he_oper) + 1) 5221 params->he_oper = (void *)(cap + 3); 5222 } 5223 5224 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, 5225 struct cfg80211_ap_settings *params) 5226 { 5227 struct wireless_dev *wdev; 5228 bool ret = false; 5229 5230 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 5231 if (wdev->iftype != NL80211_IFTYPE_AP && 5232 wdev->iftype != NL80211_IFTYPE_P2P_GO) 5233 continue; 5234 5235 if (!wdev->preset_chandef.chan) 5236 continue; 5237 5238 params->chandef = wdev->preset_chandef; 5239 ret = true; 5240 break; 5241 } 5242 5243 return ret; 5244 } 5245 5246 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, 5247 enum nl80211_auth_type auth_type, 5248 enum nl80211_commands cmd) 5249 { 5250 if (auth_type > NL80211_AUTHTYPE_MAX) 5251 return false; 5252 5253 switch (cmd) { 5254 case NL80211_CMD_AUTHENTICATE: 5255 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5256 auth_type == NL80211_AUTHTYPE_SAE) 5257 return false; 5258 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5259 NL80211_EXT_FEATURE_FILS_STA) && 5260 (auth_type == NL80211_AUTHTYPE_FILS_SK || 5261 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5262 auth_type == NL80211_AUTHTYPE_FILS_PK)) 5263 return false; 5264 return true; 5265 case NL80211_CMD_CONNECT: 5266 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5267 !wiphy_ext_feature_isset(&rdev->wiphy, 5268 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 5269 auth_type == NL80211_AUTHTYPE_SAE) 5270 return false; 5271 5272 /* FILS with SK PFS or PK not supported yet */ 5273 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5274 auth_type == NL80211_AUTHTYPE_FILS_PK) 5275 return false; 5276 if (!wiphy_ext_feature_isset( 5277 &rdev->wiphy, 5278 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 5279 auth_type == NL80211_AUTHTYPE_FILS_SK) 5280 return false; 5281 return true; 5282 case NL80211_CMD_START_AP: 5283 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5284 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && 5285 auth_type == NL80211_AUTHTYPE_SAE) 5286 return false; 5287 /* FILS not supported yet */ 5288 if (auth_type == NL80211_AUTHTYPE_FILS_SK || 5289 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5290 auth_type == NL80211_AUTHTYPE_FILS_PK) 5291 return false; 5292 return true; 5293 default: 5294 return false; 5295 } 5296 } 5297 5298 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) 5299 { 5300 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5301 struct net_device *dev = info->user_ptr[1]; 5302 struct wireless_dev *wdev = dev->ieee80211_ptr; 5303 struct cfg80211_ap_settings params; 5304 int err; 5305 5306 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5307 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5308 return -EOPNOTSUPP; 5309 5310 if (!rdev->ops->start_ap) 5311 return -EOPNOTSUPP; 5312 5313 if (wdev->beacon_interval) 5314 return -EALREADY; 5315 5316 memset(¶ms, 0, sizeof(params)); 5317 5318 /* these are required for START_AP */ 5319 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 5320 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 5321 !info->attrs[NL80211_ATTR_BEACON_HEAD]) 5322 return -EINVAL; 5323 5324 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); 5325 if (err) 5326 return err; 5327 5328 params.beacon_interval = 5329 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 5330 params.dtim_period = 5331 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 5332 5333 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, 5334 params.beacon_interval); 5335 if (err) 5336 return err; 5337 5338 /* 5339 * In theory, some of these attributes should be required here 5340 * but since they were not used when the command was originally 5341 * added, keep them optional for old user space programs to let 5342 * them continue to work with drivers that do not need the 5343 * additional information -- drivers must check! 5344 */ 5345 if (info->attrs[NL80211_ATTR_SSID]) { 5346 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 5347 params.ssid_len = 5348 nla_len(info->attrs[NL80211_ATTR_SSID]); 5349 if (params.ssid_len == 0) 5350 return -EINVAL; 5351 } 5352 5353 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) 5354 params.hidden_ssid = nla_get_u32( 5355 info->attrs[NL80211_ATTR_HIDDEN_SSID]); 5356 5357 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 5358 5359 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 5360 params.auth_type = nla_get_u32( 5361 info->attrs[NL80211_ATTR_AUTH_TYPE]); 5362 if (!nl80211_valid_auth_type(rdev, params.auth_type, 5363 NL80211_CMD_START_AP)) 5364 return -EINVAL; 5365 } else 5366 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 5367 5368 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, 5369 NL80211_MAX_NR_CIPHER_SUITES); 5370 if (err) 5371 return err; 5372 5373 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { 5374 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) 5375 return -EOPNOTSUPP; 5376 params.inactivity_timeout = nla_get_u16( 5377 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 5378 } 5379 5380 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 5381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5382 return -EINVAL; 5383 params.p2p_ctwindow = 5384 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 5385 if (params.p2p_ctwindow != 0 && 5386 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 5387 return -EINVAL; 5388 } 5389 5390 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 5391 u8 tmp; 5392 5393 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5394 return -EINVAL; 5395 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 5396 params.p2p_opp_ps = tmp; 5397 if (params.p2p_opp_ps != 0 && 5398 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 5399 return -EINVAL; 5400 } 5401 5402 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 5403 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 5404 if (err) 5405 return err; 5406 } else if (wdev->preset_chandef.chan) { 5407 params.chandef = wdev->preset_chandef; 5408 } else if (!nl80211_get_ap_channel(rdev, ¶ms)) 5409 return -EINVAL; 5410 5411 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 5412 wdev->iftype)) 5413 return -EINVAL; 5414 5415 if (info->attrs[NL80211_ATTR_TX_RATES]) { 5416 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 5417 NL80211_ATTR_TX_RATES, 5418 ¶ms.beacon_rate, 5419 dev, false); 5420 if (err) 5421 return err; 5422 5423 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, 5424 ¶ms.beacon_rate); 5425 if (err) 5426 return err; 5427 } 5428 5429 if (info->attrs[NL80211_ATTR_SMPS_MODE]) { 5430 params.smps_mode = 5431 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); 5432 switch (params.smps_mode) { 5433 case NL80211_SMPS_OFF: 5434 break; 5435 case NL80211_SMPS_STATIC: 5436 if (!(rdev->wiphy.features & 5437 NL80211_FEATURE_STATIC_SMPS)) 5438 return -EINVAL; 5439 break; 5440 case NL80211_SMPS_DYNAMIC: 5441 if (!(rdev->wiphy.features & 5442 NL80211_FEATURE_DYNAMIC_SMPS)) 5443 return -EINVAL; 5444 break; 5445 default: 5446 return -EINVAL; 5447 } 5448 } else { 5449 params.smps_mode = NL80211_SMPS_OFF; 5450 } 5451 5452 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 5453 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) 5454 return -EOPNOTSUPP; 5455 5456 if (info->attrs[NL80211_ATTR_ACL_POLICY]) { 5457 params.acl = parse_acl_data(&rdev->wiphy, info); 5458 if (IS_ERR(params.acl)) 5459 return PTR_ERR(params.acl); 5460 } 5461 5462 params.twt_responder = 5463 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); 5464 5465 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { 5466 err = nl80211_parse_he_obss_pd( 5467 info->attrs[NL80211_ATTR_HE_OBSS_PD], 5468 ¶ms.he_obss_pd); 5469 if (err) 5470 goto out; 5471 } 5472 5473 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { 5474 err = nl80211_parse_he_bss_color( 5475 info->attrs[NL80211_ATTR_HE_BSS_COLOR], 5476 ¶ms.he_bss_color); 5477 if (err) 5478 goto out; 5479 } 5480 5481 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { 5482 err = nl80211_parse_fils_discovery(rdev, 5483 info->attrs[NL80211_ATTR_FILS_DISCOVERY], 5484 ¶ms); 5485 if (err) 5486 goto out; 5487 } 5488 5489 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { 5490 err = nl80211_parse_unsol_bcast_probe_resp( 5491 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], 5492 ¶ms); 5493 if (err) 5494 goto out; 5495 } 5496 5497 nl80211_calculate_ap_params(¶ms); 5498 5499 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) 5500 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; 5501 5502 wdev_lock(wdev); 5503 err = rdev_start_ap(rdev, dev, ¶ms); 5504 if (!err) { 5505 wdev->preset_chandef = params.chandef; 5506 wdev->beacon_interval = params.beacon_interval; 5507 wdev->chandef = params.chandef; 5508 wdev->ssid_len = params.ssid_len; 5509 memcpy(wdev->ssid, params.ssid, wdev->ssid_len); 5510 5511 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 5512 wdev->conn_owner_nlportid = info->snd_portid; 5513 } 5514 wdev_unlock(wdev); 5515 5516 out: 5517 kfree(params.acl); 5518 5519 return err; 5520 } 5521 5522 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) 5523 { 5524 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5525 struct net_device *dev = info->user_ptr[1]; 5526 struct wireless_dev *wdev = dev->ieee80211_ptr; 5527 struct cfg80211_beacon_data params; 5528 int err; 5529 5530 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5531 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5532 return -EOPNOTSUPP; 5533 5534 if (!rdev->ops->change_beacon) 5535 return -EOPNOTSUPP; 5536 5537 if (!wdev->beacon_interval) 5538 return -EINVAL; 5539 5540 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); 5541 if (err) 5542 return err; 5543 5544 wdev_lock(wdev); 5545 err = rdev_change_beacon(rdev, dev, ¶ms); 5546 wdev_unlock(wdev); 5547 5548 return err; 5549 } 5550 5551 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) 5552 { 5553 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5554 struct net_device *dev = info->user_ptr[1]; 5555 5556 return cfg80211_stop_ap(rdev, dev, false); 5557 } 5558 5559 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { 5560 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, 5561 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 5562 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 5563 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 5564 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, 5565 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, 5566 }; 5567 5568 static int parse_station_flags(struct genl_info *info, 5569 enum nl80211_iftype iftype, 5570 struct station_parameters *params) 5571 { 5572 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 5573 struct nlattr *nla; 5574 int flag; 5575 5576 /* 5577 * Try parsing the new attribute first so userspace 5578 * can specify both for older kernels. 5579 */ 5580 nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; 5581 if (nla) { 5582 struct nl80211_sta_flag_update *sta_flags; 5583 5584 sta_flags = nla_data(nla); 5585 params->sta_flags_mask = sta_flags->mask; 5586 params->sta_flags_set = sta_flags->set; 5587 params->sta_flags_set &= params->sta_flags_mask; 5588 if ((params->sta_flags_mask | 5589 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) 5590 return -EINVAL; 5591 return 0; 5592 } 5593 5594 /* if present, parse the old attribute */ 5595 5596 nla = info->attrs[NL80211_ATTR_STA_FLAGS]; 5597 if (!nla) 5598 return 0; 5599 5600 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) 5601 return -EINVAL; 5602 5603 /* 5604 * Only allow certain flags for interface types so that 5605 * other attributes are silently ignored. Remember that 5606 * this is backward compatibility code with old userspace 5607 * and shouldn't be hit in other cases anyway. 5608 */ 5609 switch (iftype) { 5610 case NL80211_IFTYPE_AP: 5611 case NL80211_IFTYPE_AP_VLAN: 5612 case NL80211_IFTYPE_P2P_GO: 5613 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 5614 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 5615 BIT(NL80211_STA_FLAG_WME) | 5616 BIT(NL80211_STA_FLAG_MFP); 5617 break; 5618 case NL80211_IFTYPE_P2P_CLIENT: 5619 case NL80211_IFTYPE_STATION: 5620 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 5621 BIT(NL80211_STA_FLAG_TDLS_PEER); 5622 break; 5623 case NL80211_IFTYPE_MESH_POINT: 5624 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5625 BIT(NL80211_STA_FLAG_MFP) | 5626 BIT(NL80211_STA_FLAG_AUTHORIZED); 5627 break; 5628 default: 5629 return -EINVAL; 5630 } 5631 5632 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { 5633 if (flags[flag]) { 5634 params->sta_flags_set |= (1<<flag); 5635 5636 /* no longer support new API additions in old API */ 5637 if (flag > NL80211_STA_FLAG_MAX_OLD_API) 5638 return -EINVAL; 5639 } 5640 } 5641 5642 return 0; 5643 } 5644 5645 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) 5646 { 5647 struct nlattr *rate; 5648 u32 bitrate; 5649 u16 bitrate_compat; 5650 enum nl80211_rate_info rate_flg; 5651 5652 rate = nla_nest_start_noflag(msg, attr); 5653 if (!rate) 5654 return false; 5655 5656 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ 5657 bitrate = cfg80211_calculate_bitrate(info); 5658 /* report 16-bit bitrate only if we can */ 5659 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; 5660 if (bitrate > 0 && 5661 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) 5662 return false; 5663 if (bitrate_compat > 0 && 5664 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) 5665 return false; 5666 5667 switch (info->bw) { 5668 case RATE_INFO_BW_5: 5669 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; 5670 break; 5671 case RATE_INFO_BW_10: 5672 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; 5673 break; 5674 default: 5675 WARN_ON(1); 5676 fallthrough; 5677 case RATE_INFO_BW_20: 5678 rate_flg = 0; 5679 break; 5680 case RATE_INFO_BW_40: 5681 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; 5682 break; 5683 case RATE_INFO_BW_80: 5684 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; 5685 break; 5686 case RATE_INFO_BW_160: 5687 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; 5688 break; 5689 case RATE_INFO_BW_HE_RU: 5690 rate_flg = 0; 5691 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); 5692 } 5693 5694 if (rate_flg && nla_put_flag(msg, rate_flg)) 5695 return false; 5696 5697 if (info->flags & RATE_INFO_FLAGS_MCS) { 5698 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) 5699 return false; 5700 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 5701 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 5702 return false; 5703 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { 5704 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) 5705 return false; 5706 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) 5707 return false; 5708 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 5709 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 5710 return false; 5711 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { 5712 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) 5713 return false; 5714 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) 5715 return false; 5716 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) 5717 return false; 5718 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) 5719 return false; 5720 if (info->bw == RATE_INFO_BW_HE_RU && 5721 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, 5722 info->he_ru_alloc)) 5723 return false; 5724 } 5725 5726 nla_nest_end(msg, rate); 5727 return true; 5728 } 5729 5730 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, 5731 int id) 5732 { 5733 void *attr; 5734 int i = 0; 5735 5736 if (!mask) 5737 return true; 5738 5739 attr = nla_nest_start_noflag(msg, id); 5740 if (!attr) 5741 return false; 5742 5743 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 5744 if (!(mask & BIT(i))) 5745 continue; 5746 5747 if (nla_put_u8(msg, i, signal[i])) 5748 return false; 5749 } 5750 5751 nla_nest_end(msg, attr); 5752 5753 return true; 5754 } 5755 5756 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, 5757 u32 seq, int flags, 5758 struct cfg80211_registered_device *rdev, 5759 struct net_device *dev, 5760 const u8 *mac_addr, struct station_info *sinfo) 5761 { 5762 void *hdr; 5763 struct nlattr *sinfoattr, *bss_param; 5764 5765 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 5766 if (!hdr) { 5767 cfg80211_sinfo_release_content(sinfo); 5768 return -1; 5769 } 5770 5771 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 5772 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 5773 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 5774 goto nla_put_failure; 5775 5776 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); 5777 if (!sinfoattr) 5778 goto nla_put_failure; 5779 5780 #define PUT_SINFO(attr, memb, type) do { \ 5781 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ 5782 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 5783 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ 5784 sinfo->memb)) \ 5785 goto nla_put_failure; \ 5786 } while (0) 5787 #define PUT_SINFO_U64(attr, memb) do { \ 5788 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 5789 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ 5790 sinfo->memb, NL80211_STA_INFO_PAD)) \ 5791 goto nla_put_failure; \ 5792 } while (0) 5793 5794 PUT_SINFO(CONNECTED_TIME, connected_time, u32); 5795 PUT_SINFO(INACTIVE_TIME, inactive_time, u32); 5796 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); 5797 5798 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | 5799 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && 5800 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, 5801 (u32)sinfo->rx_bytes)) 5802 goto nla_put_failure; 5803 5804 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 5805 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && 5806 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, 5807 (u32)sinfo->tx_bytes)) 5808 goto nla_put_failure; 5809 5810 PUT_SINFO_U64(RX_BYTES64, rx_bytes); 5811 PUT_SINFO_U64(TX_BYTES64, tx_bytes); 5812 PUT_SINFO(LLID, llid, u16); 5813 PUT_SINFO(PLID, plid, u16); 5814 PUT_SINFO(PLINK_STATE, plink_state, u8); 5815 PUT_SINFO_U64(RX_DURATION, rx_duration); 5816 PUT_SINFO_U64(TX_DURATION, tx_duration); 5817 5818 if (wiphy_ext_feature_isset(&rdev->wiphy, 5819 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 5820 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); 5821 5822 switch (rdev->wiphy.signal_type) { 5823 case CFG80211_SIGNAL_TYPE_MBM: 5824 PUT_SINFO(SIGNAL, signal, u8); 5825 PUT_SINFO(SIGNAL_AVG, signal_avg, u8); 5826 break; 5827 default: 5828 break; 5829 } 5830 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { 5831 if (!nl80211_put_signal(msg, sinfo->chains, 5832 sinfo->chain_signal, 5833 NL80211_STA_INFO_CHAIN_SIGNAL)) 5834 goto nla_put_failure; 5835 } 5836 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { 5837 if (!nl80211_put_signal(msg, sinfo->chains, 5838 sinfo->chain_signal_avg, 5839 NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) 5840 goto nla_put_failure; 5841 } 5842 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { 5843 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 5844 NL80211_STA_INFO_TX_BITRATE)) 5845 goto nla_put_failure; 5846 } 5847 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { 5848 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, 5849 NL80211_STA_INFO_RX_BITRATE)) 5850 goto nla_put_failure; 5851 } 5852 5853 PUT_SINFO(RX_PACKETS, rx_packets, u32); 5854 PUT_SINFO(TX_PACKETS, tx_packets, u32); 5855 PUT_SINFO(TX_RETRIES, tx_retries, u32); 5856 PUT_SINFO(TX_FAILED, tx_failed, u32); 5857 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 5858 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); 5859 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 5860 PUT_SINFO(LOCAL_PM, local_pm, u32); 5861 PUT_SINFO(PEER_PM, peer_pm, u32); 5862 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); 5863 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 5864 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); 5865 5866 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 5867 bss_param = nla_nest_start_noflag(msg, 5868 NL80211_STA_INFO_BSS_PARAM); 5869 if (!bss_param) 5870 goto nla_put_failure; 5871 5872 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && 5873 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || 5874 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && 5875 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || 5876 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && 5877 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || 5878 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, 5879 sinfo->bss_param.dtim_period) || 5880 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, 5881 sinfo->bss_param.beacon_interval)) 5882 goto nla_put_failure; 5883 5884 nla_nest_end(msg, bss_param); 5885 } 5886 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && 5887 nla_put(msg, NL80211_STA_INFO_STA_FLAGS, 5888 sizeof(struct nl80211_sta_flag_update), 5889 &sinfo->sta_flags)) 5890 goto nla_put_failure; 5891 5892 PUT_SINFO_U64(T_OFFSET, t_offset); 5893 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); 5894 PUT_SINFO_U64(BEACON_RX, rx_beacon); 5895 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); 5896 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); 5897 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); 5898 if (wiphy_ext_feature_isset(&rdev->wiphy, 5899 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { 5900 PUT_SINFO(ACK_SIGNAL, ack_signal, u8); 5901 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); 5902 } 5903 5904 #undef PUT_SINFO 5905 #undef PUT_SINFO_U64 5906 5907 if (sinfo->pertid) { 5908 struct nlattr *tidsattr; 5909 int tid; 5910 5911 tidsattr = nla_nest_start_noflag(msg, 5912 NL80211_STA_INFO_TID_STATS); 5913 if (!tidsattr) 5914 goto nla_put_failure; 5915 5916 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { 5917 struct cfg80211_tid_stats *tidstats; 5918 struct nlattr *tidattr; 5919 5920 tidstats = &sinfo->pertid[tid]; 5921 5922 if (!tidstats->filled) 5923 continue; 5924 5925 tidattr = nla_nest_start_noflag(msg, tid + 1); 5926 if (!tidattr) 5927 goto nla_put_failure; 5928 5929 #define PUT_TIDVAL_U64(attr, memb) do { \ 5930 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ 5931 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ 5932 tidstats->memb, NL80211_TID_STATS_PAD)) \ 5933 goto nla_put_failure; \ 5934 } while (0) 5935 5936 PUT_TIDVAL_U64(RX_MSDU, rx_msdu); 5937 PUT_TIDVAL_U64(TX_MSDU, tx_msdu); 5938 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); 5939 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); 5940 5941 #undef PUT_TIDVAL_U64 5942 if ((tidstats->filled & 5943 BIT(NL80211_TID_STATS_TXQ_STATS)) && 5944 !nl80211_put_txq_stats(msg, &tidstats->txq_stats, 5945 NL80211_TID_STATS_TXQ_STATS)) 5946 goto nla_put_failure; 5947 5948 nla_nest_end(msg, tidattr); 5949 } 5950 5951 nla_nest_end(msg, tidsattr); 5952 } 5953 5954 nla_nest_end(msg, sinfoattr); 5955 5956 if (sinfo->assoc_req_ies_len && 5957 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, 5958 sinfo->assoc_req_ies)) 5959 goto nla_put_failure; 5960 5961 cfg80211_sinfo_release_content(sinfo); 5962 genlmsg_end(msg, hdr); 5963 return 0; 5964 5965 nla_put_failure: 5966 cfg80211_sinfo_release_content(sinfo); 5967 genlmsg_cancel(msg, hdr); 5968 return -EMSGSIZE; 5969 } 5970 5971 static int nl80211_dump_station(struct sk_buff *skb, 5972 struct netlink_callback *cb) 5973 { 5974 struct station_info sinfo; 5975 struct cfg80211_registered_device *rdev; 5976 struct wireless_dev *wdev; 5977 u8 mac_addr[ETH_ALEN]; 5978 int sta_idx = cb->args[2]; 5979 int err; 5980 5981 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 5982 if (err) 5983 return err; 5984 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 5985 __acquire(&rdev->wiphy.mtx); 5986 5987 if (!wdev->netdev) { 5988 err = -EINVAL; 5989 goto out_err; 5990 } 5991 5992 if (!rdev->ops->dump_station) { 5993 err = -EOPNOTSUPP; 5994 goto out_err; 5995 } 5996 5997 while (1) { 5998 memset(&sinfo, 0, sizeof(sinfo)); 5999 err = rdev_dump_station(rdev, wdev->netdev, sta_idx, 6000 mac_addr, &sinfo); 6001 if (err == -ENOENT) 6002 break; 6003 if (err) 6004 goto out_err; 6005 6006 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, 6007 NETLINK_CB(cb->skb).portid, 6008 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6009 rdev, wdev->netdev, mac_addr, 6010 &sinfo) < 0) 6011 goto out; 6012 6013 sta_idx++; 6014 } 6015 6016 out: 6017 cb->args[2] = sta_idx; 6018 err = skb->len; 6019 out_err: 6020 wiphy_unlock(&rdev->wiphy); 6021 6022 return err; 6023 } 6024 6025 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 6026 { 6027 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6028 struct net_device *dev = info->user_ptr[1]; 6029 struct station_info sinfo; 6030 struct sk_buff *msg; 6031 u8 *mac_addr = NULL; 6032 int err; 6033 6034 memset(&sinfo, 0, sizeof(sinfo)); 6035 6036 if (!info->attrs[NL80211_ATTR_MAC]) 6037 return -EINVAL; 6038 6039 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6040 6041 if (!rdev->ops->get_station) 6042 return -EOPNOTSUPP; 6043 6044 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 6045 if (err) 6046 return err; 6047 6048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6049 if (!msg) { 6050 cfg80211_sinfo_release_content(&sinfo); 6051 return -ENOMEM; 6052 } 6053 6054 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 6055 info->snd_portid, info->snd_seq, 0, 6056 rdev, dev, mac_addr, &sinfo) < 0) { 6057 nlmsg_free(msg); 6058 return -ENOBUFS; 6059 } 6060 6061 return genlmsg_reply(msg, info); 6062 } 6063 6064 int cfg80211_check_station_change(struct wiphy *wiphy, 6065 struct station_parameters *params, 6066 enum cfg80211_station_type statype) 6067 { 6068 if (params->listen_interval != -1 && 6069 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6070 return -EINVAL; 6071 6072 if (params->support_p2p_ps != -1 && 6073 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6074 return -EINVAL; 6075 6076 if (params->aid && 6077 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && 6078 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6079 return -EINVAL; 6080 6081 /* When you run into this, adjust the code below for the new flag */ 6082 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 6083 6084 switch (statype) { 6085 case CFG80211_STA_MESH_PEER_KERNEL: 6086 case CFG80211_STA_MESH_PEER_USER: 6087 /* 6088 * No ignoring the TDLS flag here -- the userspace mesh 6089 * code doesn't have the bug of including TDLS in the 6090 * mask everywhere. 6091 */ 6092 if (params->sta_flags_mask & 6093 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6094 BIT(NL80211_STA_FLAG_MFP) | 6095 BIT(NL80211_STA_FLAG_AUTHORIZED))) 6096 return -EINVAL; 6097 break; 6098 case CFG80211_STA_TDLS_PEER_SETUP: 6099 case CFG80211_STA_TDLS_PEER_ACTIVE: 6100 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 6101 return -EINVAL; 6102 /* ignore since it can't change */ 6103 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6104 break; 6105 default: 6106 /* disallow mesh-specific things */ 6107 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) 6108 return -EINVAL; 6109 if (params->local_pm) 6110 return -EINVAL; 6111 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6112 return -EINVAL; 6113 } 6114 6115 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6116 statype != CFG80211_STA_TDLS_PEER_ACTIVE) { 6117 /* TDLS can't be set, ... */ 6118 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 6119 return -EINVAL; 6120 /* 6121 * ... but don't bother the driver with it. This works around 6122 * a hostapd/wpa_supplicant issue -- it always includes the 6123 * TLDS_PEER flag in the mask even for AP mode. 6124 */ 6125 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6126 } 6127 6128 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6129 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6130 /* reject other things that can't change */ 6131 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) 6132 return -EINVAL; 6133 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) 6134 return -EINVAL; 6135 if (params->supported_rates) 6136 return -EINVAL; 6137 if (params->ext_capab || params->ht_capa || params->vht_capa || 6138 params->he_capa) 6139 return -EINVAL; 6140 } 6141 6142 if (statype != CFG80211_STA_AP_CLIENT && 6143 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6144 if (params->vlan) 6145 return -EINVAL; 6146 } 6147 6148 switch (statype) { 6149 case CFG80211_STA_AP_MLME_CLIENT: 6150 /* Use this only for authorizing/unauthorizing a station */ 6151 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 6152 return -EOPNOTSUPP; 6153 break; 6154 case CFG80211_STA_AP_CLIENT: 6155 case CFG80211_STA_AP_CLIENT_UNASSOC: 6156 /* accept only the listed bits */ 6157 if (params->sta_flags_mask & 6158 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6159 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6160 BIT(NL80211_STA_FLAG_ASSOCIATED) | 6161 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6162 BIT(NL80211_STA_FLAG_WME) | 6163 BIT(NL80211_STA_FLAG_MFP))) 6164 return -EINVAL; 6165 6166 /* but authenticated/associated only if driver handles it */ 6167 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 6168 params->sta_flags_mask & 6169 (BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6170 BIT(NL80211_STA_FLAG_ASSOCIATED))) 6171 return -EINVAL; 6172 break; 6173 case CFG80211_STA_IBSS: 6174 case CFG80211_STA_AP_STA: 6175 /* reject any changes other than AUTHORIZED */ 6176 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 6177 return -EINVAL; 6178 break; 6179 case CFG80211_STA_TDLS_PEER_SETUP: 6180 /* reject any changes other than AUTHORIZED or WME */ 6181 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6182 BIT(NL80211_STA_FLAG_WME))) 6183 return -EINVAL; 6184 /* force (at least) rates when authorizing */ 6185 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && 6186 !params->supported_rates) 6187 return -EINVAL; 6188 break; 6189 case CFG80211_STA_TDLS_PEER_ACTIVE: 6190 /* reject any changes */ 6191 return -EINVAL; 6192 case CFG80211_STA_MESH_PEER_KERNEL: 6193 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6194 return -EINVAL; 6195 break; 6196 case CFG80211_STA_MESH_PEER_USER: 6197 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && 6198 params->plink_action != NL80211_PLINK_ACTION_BLOCK) 6199 return -EINVAL; 6200 break; 6201 } 6202 6203 /* 6204 * Older kernel versions ignored this attribute entirely, so don't 6205 * reject attempts to update it but mark it as unused instead so the 6206 * driver won't look at the data. 6207 */ 6208 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && 6209 statype != CFG80211_STA_TDLS_PEER_SETUP) 6210 params->opmode_notif_used = false; 6211 6212 return 0; 6213 } 6214 EXPORT_SYMBOL(cfg80211_check_station_change); 6215 6216 /* 6217 * Get vlan interface making sure it is running and on the right wiphy. 6218 */ 6219 static struct net_device *get_vlan(struct genl_info *info, 6220 struct cfg80211_registered_device *rdev) 6221 { 6222 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; 6223 struct net_device *v; 6224 int ret; 6225 6226 if (!vlanattr) 6227 return NULL; 6228 6229 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); 6230 if (!v) 6231 return ERR_PTR(-ENODEV); 6232 6233 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { 6234 ret = -EINVAL; 6235 goto error; 6236 } 6237 6238 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 6239 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6240 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 6241 ret = -EINVAL; 6242 goto error; 6243 } 6244 6245 if (!netif_running(v)) { 6246 ret = -ENETDOWN; 6247 goto error; 6248 } 6249 6250 return v; 6251 error: 6252 dev_put(v); 6253 return ERR_PTR(ret); 6254 } 6255 6256 static const struct nla_policy 6257 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { 6258 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, 6259 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, 6260 }; 6261 6262 static int nl80211_parse_sta_wme(struct genl_info *info, 6263 struct station_parameters *params) 6264 { 6265 struct nlattr *tb[NL80211_STA_WME_MAX + 1]; 6266 struct nlattr *nla; 6267 int err; 6268 6269 /* parse WME attributes if present */ 6270 if (!info->attrs[NL80211_ATTR_STA_WME]) 6271 return 0; 6272 6273 nla = info->attrs[NL80211_ATTR_STA_WME]; 6274 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, 6275 nl80211_sta_wme_policy, 6276 info->extack); 6277 if (err) 6278 return err; 6279 6280 if (tb[NL80211_STA_WME_UAPSD_QUEUES]) 6281 params->uapsd_queues = nla_get_u8( 6282 tb[NL80211_STA_WME_UAPSD_QUEUES]); 6283 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) 6284 return -EINVAL; 6285 6286 if (tb[NL80211_STA_WME_MAX_SP]) 6287 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); 6288 6289 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) 6290 return -EINVAL; 6291 6292 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; 6293 6294 return 0; 6295 } 6296 6297 static int nl80211_parse_sta_channel_info(struct genl_info *info, 6298 struct station_parameters *params) 6299 { 6300 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { 6301 params->supported_channels = 6302 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 6303 params->supported_channels_len = 6304 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 6305 /* 6306 * Need to include at least one (first channel, number of 6307 * channels) tuple for each subband (checked in policy), 6308 * and must have proper tuples for the rest of the data as well. 6309 */ 6310 if (params->supported_channels_len % 2) 6311 return -EINVAL; 6312 } 6313 6314 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { 6315 params->supported_oper_classes = 6316 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 6317 params->supported_oper_classes_len = 6318 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 6319 } 6320 return 0; 6321 } 6322 6323 static int nl80211_set_station_tdls(struct genl_info *info, 6324 struct station_parameters *params) 6325 { 6326 int err; 6327 /* Dummy STA entry gets updated once the peer capabilities are known */ 6328 if (info->attrs[NL80211_ATTR_PEER_AID]) 6329 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 6330 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 6331 params->ht_capa = 6332 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 6333 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 6334 params->vht_capa = 6335 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 6336 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 6337 params->he_capa = 6338 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6339 params->he_capa_len = 6340 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6341 } 6342 6343 err = nl80211_parse_sta_channel_info(info, params); 6344 if (err) 6345 return err; 6346 6347 return nl80211_parse_sta_wme(info, params); 6348 } 6349 6350 static int nl80211_parse_sta_txpower_setting(struct genl_info *info, 6351 struct station_parameters *params) 6352 { 6353 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6354 int idx; 6355 6356 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { 6357 if (!rdev->ops->set_tx_power || 6358 !wiphy_ext_feature_isset(&rdev->wiphy, 6359 NL80211_EXT_FEATURE_STA_TX_PWR)) 6360 return -EOPNOTSUPP; 6361 6362 idx = NL80211_ATTR_STA_TX_POWER_SETTING; 6363 params->txpwr.type = nla_get_u8(info->attrs[idx]); 6364 6365 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { 6366 idx = NL80211_ATTR_STA_TX_POWER; 6367 6368 if (info->attrs[idx]) 6369 params->txpwr.power = 6370 nla_get_s16(info->attrs[idx]); 6371 else 6372 return -EINVAL; 6373 } 6374 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; 6375 } 6376 6377 return 0; 6378 } 6379 6380 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 6381 { 6382 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6383 struct net_device *dev = info->user_ptr[1]; 6384 struct station_parameters params; 6385 u8 *mac_addr; 6386 int err; 6387 6388 memset(¶ms, 0, sizeof(params)); 6389 6390 if (!rdev->ops->change_station) 6391 return -EOPNOTSUPP; 6392 6393 /* 6394 * AID and listen_interval properties can be set only for unassociated 6395 * station. Include these parameters here and will check them in 6396 * cfg80211_check_station_change(). 6397 */ 6398 if (info->attrs[NL80211_ATTR_STA_AID]) 6399 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 6400 6401 if (info->attrs[NL80211_ATTR_VLAN_ID]) 6402 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 6403 6404 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 6405 params.listen_interval = 6406 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 6407 else 6408 params.listen_interval = -1; 6409 6410 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) 6411 params.support_p2p_ps = 6412 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 6413 else 6414 params.support_p2p_ps = -1; 6415 6416 if (!info->attrs[NL80211_ATTR_MAC]) 6417 return -EINVAL; 6418 6419 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6420 6421 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 6422 params.supported_rates = 6423 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 6424 params.supported_rates_len = 6425 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 6426 } 6427 6428 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 6429 params.capability = 6430 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 6431 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 6432 } 6433 6434 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 6435 params.ext_capab = 6436 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 6437 params.ext_capab_len = 6438 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 6439 } 6440 6441 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 6442 return -EINVAL; 6443 6444 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 6445 params.plink_action = 6446 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 6447 6448 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { 6449 params.plink_state = 6450 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 6451 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) 6452 params.peer_aid = nla_get_u16( 6453 info->attrs[NL80211_ATTR_MESH_PEER_AID]); 6454 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; 6455 } 6456 6457 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) 6458 params.local_pm = nla_get_u32( 6459 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); 6460 6461 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 6462 params.opmode_notif_used = true; 6463 params.opmode_notif = 6464 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 6465 } 6466 6467 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 6468 params.he_6ghz_capa = 6469 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 6470 6471 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 6472 params.airtime_weight = 6473 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 6474 6475 if (params.airtime_weight && 6476 !wiphy_ext_feature_isset(&rdev->wiphy, 6477 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6478 return -EOPNOTSUPP; 6479 6480 err = nl80211_parse_sta_txpower_setting(info, ¶ms); 6481 if (err) 6482 return err; 6483 6484 /* Include parameters for TDLS peer (will check later) */ 6485 err = nl80211_set_station_tdls(info, ¶ms); 6486 if (err) 6487 return err; 6488 6489 params.vlan = get_vlan(info, rdev); 6490 if (IS_ERR(params.vlan)) 6491 return PTR_ERR(params.vlan); 6492 6493 switch (dev->ieee80211_ptr->iftype) { 6494 case NL80211_IFTYPE_AP: 6495 case NL80211_IFTYPE_AP_VLAN: 6496 case NL80211_IFTYPE_P2P_GO: 6497 case NL80211_IFTYPE_P2P_CLIENT: 6498 case NL80211_IFTYPE_STATION: 6499 case NL80211_IFTYPE_ADHOC: 6500 case NL80211_IFTYPE_MESH_POINT: 6501 break; 6502 default: 6503 err = -EOPNOTSUPP; 6504 goto out_put_vlan; 6505 } 6506 6507 /* driver will call cfg80211_check_station_change() */ 6508 err = rdev_change_station(rdev, dev, mac_addr, ¶ms); 6509 6510 out_put_vlan: 6511 if (params.vlan) 6512 dev_put(params.vlan); 6513 6514 return err; 6515 } 6516 6517 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 6518 { 6519 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6520 int err; 6521 struct net_device *dev = info->user_ptr[1]; 6522 struct station_parameters params; 6523 u8 *mac_addr = NULL; 6524 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6525 BIT(NL80211_STA_FLAG_ASSOCIATED); 6526 6527 memset(¶ms, 0, sizeof(params)); 6528 6529 if (!rdev->ops->add_station) 6530 return -EOPNOTSUPP; 6531 6532 if (!info->attrs[NL80211_ATTR_MAC]) 6533 return -EINVAL; 6534 6535 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 6536 return -EINVAL; 6537 6538 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 6539 return -EINVAL; 6540 6541 if (!info->attrs[NL80211_ATTR_STA_AID] && 6542 !info->attrs[NL80211_ATTR_PEER_AID]) 6543 return -EINVAL; 6544 6545 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6546 params.supported_rates = 6547 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 6548 params.supported_rates_len = 6549 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 6550 params.listen_interval = 6551 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 6552 6553 if (info->attrs[NL80211_ATTR_VLAN_ID]) 6554 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 6555 6556 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { 6557 params.support_p2p_ps = 6558 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 6559 } else { 6560 /* 6561 * if not specified, assume it's supported for P2P GO interface, 6562 * and is NOT supported for AP interface 6563 */ 6564 params.support_p2p_ps = 6565 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; 6566 } 6567 6568 if (info->attrs[NL80211_ATTR_PEER_AID]) 6569 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 6570 else 6571 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 6572 6573 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 6574 params.capability = 6575 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 6576 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 6577 } 6578 6579 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 6580 params.ext_capab = 6581 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 6582 params.ext_capab_len = 6583 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 6584 } 6585 6586 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 6587 params.ht_capa = 6588 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 6589 6590 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 6591 params.vht_capa = 6592 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 6593 6594 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 6595 params.he_capa = 6596 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6597 params.he_capa_len = 6598 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6599 } 6600 6601 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 6602 params.he_6ghz_capa = 6603 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 6604 6605 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 6606 params.opmode_notif_used = true; 6607 params.opmode_notif = 6608 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 6609 } 6610 6611 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 6612 params.plink_action = 6613 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 6614 6615 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 6616 params.airtime_weight = 6617 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 6618 6619 if (params.airtime_weight && 6620 !wiphy_ext_feature_isset(&rdev->wiphy, 6621 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6622 return -EOPNOTSUPP; 6623 6624 err = nl80211_parse_sta_txpower_setting(info, ¶ms); 6625 if (err) 6626 return err; 6627 6628 err = nl80211_parse_sta_channel_info(info, ¶ms); 6629 if (err) 6630 return err; 6631 6632 err = nl80211_parse_sta_wme(info, ¶ms); 6633 if (err) 6634 return err; 6635 6636 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 6637 return -EINVAL; 6638 6639 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT 6640 * as userspace might just pass through the capabilities from the IEs 6641 * directly, rather than enforcing this restriction and returning an 6642 * error in this case. 6643 */ 6644 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { 6645 params.ht_capa = NULL; 6646 params.vht_capa = NULL; 6647 6648 /* HE requires WME */ 6649 if (params.he_capa_len || params.he_6ghz_capa) 6650 return -EINVAL; 6651 } 6652 6653 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ 6654 if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) 6655 return -EINVAL; 6656 6657 /* When you run into this, adjust the code below for the new flag */ 6658 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 6659 6660 switch (dev->ieee80211_ptr->iftype) { 6661 case NL80211_IFTYPE_AP: 6662 case NL80211_IFTYPE_AP_VLAN: 6663 case NL80211_IFTYPE_P2P_GO: 6664 /* ignore WME attributes if iface/sta is not capable */ 6665 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || 6666 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) 6667 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 6668 6669 /* TDLS peers cannot be added */ 6670 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 6671 info->attrs[NL80211_ATTR_PEER_AID]) 6672 return -EINVAL; 6673 /* but don't bother the driver with it */ 6674 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6675 6676 /* allow authenticated/associated only if driver handles it */ 6677 if (!(rdev->wiphy.features & 6678 NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 6679 params.sta_flags_mask & auth_assoc) 6680 return -EINVAL; 6681 6682 /* Older userspace, or userspace wanting to be compatible with 6683 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth 6684 * and assoc flags in the mask, but assumes the station will be 6685 * added as associated anyway since this was the required driver 6686 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was 6687 * introduced. 6688 * In order to not bother drivers with this quirk in the API 6689 * set the flags in both the mask and set for new stations in 6690 * this case. 6691 */ 6692 if (!(params.sta_flags_mask & auth_assoc)) { 6693 params.sta_flags_mask |= auth_assoc; 6694 params.sta_flags_set |= auth_assoc; 6695 } 6696 6697 /* must be last in here for error handling */ 6698 params.vlan = get_vlan(info, rdev); 6699 if (IS_ERR(params.vlan)) 6700 return PTR_ERR(params.vlan); 6701 break; 6702 case NL80211_IFTYPE_MESH_POINT: 6703 /* ignore uAPSD data */ 6704 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 6705 6706 /* associated is disallowed */ 6707 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) 6708 return -EINVAL; 6709 /* TDLS peers cannot be added */ 6710 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 6711 info->attrs[NL80211_ATTR_PEER_AID]) 6712 return -EINVAL; 6713 break; 6714 case NL80211_IFTYPE_STATION: 6715 case NL80211_IFTYPE_P2P_CLIENT: 6716 /* ignore uAPSD data */ 6717 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 6718 6719 /* these are disallowed */ 6720 if (params.sta_flags_mask & 6721 (BIT(NL80211_STA_FLAG_ASSOCIATED) | 6722 BIT(NL80211_STA_FLAG_AUTHENTICATED))) 6723 return -EINVAL; 6724 /* Only TDLS peers can be added */ 6725 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 6726 return -EINVAL; 6727 /* Can only add if TDLS ... */ 6728 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) 6729 return -EOPNOTSUPP; 6730 /* ... with external setup is supported */ 6731 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 6732 return -EOPNOTSUPP; 6733 /* 6734 * Older wpa_supplicant versions always mark the TDLS peer 6735 * as authorized, but it shouldn't yet be. 6736 */ 6737 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); 6738 break; 6739 default: 6740 return -EOPNOTSUPP; 6741 } 6742 6743 /* be aware of params.vlan when changing code here */ 6744 6745 err = rdev_add_station(rdev, dev, mac_addr, ¶ms); 6746 6747 if (params.vlan) 6748 dev_put(params.vlan); 6749 return err; 6750 } 6751 6752 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 6753 { 6754 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6755 struct net_device *dev = info->user_ptr[1]; 6756 struct station_del_parameters params; 6757 6758 memset(¶ms, 0, sizeof(params)); 6759 6760 if (info->attrs[NL80211_ATTR_MAC]) 6761 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 6762 6763 switch (dev->ieee80211_ptr->iftype) { 6764 case NL80211_IFTYPE_AP: 6765 case NL80211_IFTYPE_AP_VLAN: 6766 case NL80211_IFTYPE_MESH_POINT: 6767 case NL80211_IFTYPE_P2P_GO: 6768 /* always accept these */ 6769 break; 6770 case NL80211_IFTYPE_ADHOC: 6771 /* conditionally accept */ 6772 if (wiphy_ext_feature_isset(&rdev->wiphy, 6773 NL80211_EXT_FEATURE_DEL_IBSS_STA)) 6774 break; 6775 return -EINVAL; 6776 default: 6777 return -EINVAL; 6778 } 6779 6780 if (!rdev->ops->del_station) 6781 return -EOPNOTSUPP; 6782 6783 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { 6784 params.subtype = 6785 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); 6786 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && 6787 params.subtype != IEEE80211_STYPE_DEAUTH >> 4) 6788 return -EINVAL; 6789 } else { 6790 /* Default to Deauthentication frame */ 6791 params.subtype = IEEE80211_STYPE_DEAUTH >> 4; 6792 } 6793 6794 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 6795 params.reason_code = 6796 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 6797 if (params.reason_code == 0) 6798 return -EINVAL; /* 0 is reserved */ 6799 } else { 6800 /* Default to reason code 2 */ 6801 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; 6802 } 6803 6804 return rdev_del_station(rdev, dev, ¶ms); 6805 } 6806 6807 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 6808 int flags, struct net_device *dev, 6809 u8 *dst, u8 *next_hop, 6810 struct mpath_info *pinfo) 6811 { 6812 void *hdr; 6813 struct nlattr *pinfoattr; 6814 6815 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); 6816 if (!hdr) 6817 return -1; 6818 6819 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6820 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || 6821 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || 6822 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 6823 goto nla_put_failure; 6824 6825 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); 6826 if (!pinfoattr) 6827 goto nla_put_failure; 6828 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 6829 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 6830 pinfo->frame_qlen)) 6831 goto nla_put_failure; 6832 if (((pinfo->filled & MPATH_INFO_SN) && 6833 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || 6834 ((pinfo->filled & MPATH_INFO_METRIC) && 6835 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, 6836 pinfo->metric)) || 6837 ((pinfo->filled & MPATH_INFO_EXPTIME) && 6838 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, 6839 pinfo->exptime)) || 6840 ((pinfo->filled & MPATH_INFO_FLAGS) && 6841 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, 6842 pinfo->flags)) || 6843 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && 6844 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, 6845 pinfo->discovery_timeout)) || 6846 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && 6847 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, 6848 pinfo->discovery_retries)) || 6849 ((pinfo->filled & MPATH_INFO_HOP_COUNT) && 6850 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, 6851 pinfo->hop_count)) || 6852 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && 6853 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, 6854 pinfo->path_change_count))) 6855 goto nla_put_failure; 6856 6857 nla_nest_end(msg, pinfoattr); 6858 6859 genlmsg_end(msg, hdr); 6860 return 0; 6861 6862 nla_put_failure: 6863 genlmsg_cancel(msg, hdr); 6864 return -EMSGSIZE; 6865 } 6866 6867 static int nl80211_dump_mpath(struct sk_buff *skb, 6868 struct netlink_callback *cb) 6869 { 6870 struct mpath_info pinfo; 6871 struct cfg80211_registered_device *rdev; 6872 struct wireless_dev *wdev; 6873 u8 dst[ETH_ALEN]; 6874 u8 next_hop[ETH_ALEN]; 6875 int path_idx = cb->args[2]; 6876 int err; 6877 6878 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 6879 if (err) 6880 return err; 6881 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 6882 __acquire(&rdev->wiphy.mtx); 6883 6884 if (!rdev->ops->dump_mpath) { 6885 err = -EOPNOTSUPP; 6886 goto out_err; 6887 } 6888 6889 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 6890 err = -EOPNOTSUPP; 6891 goto out_err; 6892 } 6893 6894 while (1) { 6895 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, 6896 next_hop, &pinfo); 6897 if (err == -ENOENT) 6898 break; 6899 if (err) 6900 goto out_err; 6901 6902 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 6903 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6904 wdev->netdev, dst, next_hop, 6905 &pinfo) < 0) 6906 goto out; 6907 6908 path_idx++; 6909 } 6910 6911 out: 6912 cb->args[2] = path_idx; 6913 err = skb->len; 6914 out_err: 6915 wiphy_unlock(&rdev->wiphy); 6916 return err; 6917 } 6918 6919 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 6920 { 6921 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6922 int err; 6923 struct net_device *dev = info->user_ptr[1]; 6924 struct mpath_info pinfo; 6925 struct sk_buff *msg; 6926 u8 *dst = NULL; 6927 u8 next_hop[ETH_ALEN]; 6928 6929 memset(&pinfo, 0, sizeof(pinfo)); 6930 6931 if (!info->attrs[NL80211_ATTR_MAC]) 6932 return -EINVAL; 6933 6934 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6935 6936 if (!rdev->ops->get_mpath) 6937 return -EOPNOTSUPP; 6938 6939 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6940 return -EOPNOTSUPP; 6941 6942 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); 6943 if (err) 6944 return err; 6945 6946 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6947 if (!msg) 6948 return -ENOMEM; 6949 6950 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 6951 dev, dst, next_hop, &pinfo) < 0) { 6952 nlmsg_free(msg); 6953 return -ENOBUFS; 6954 } 6955 6956 return genlmsg_reply(msg, info); 6957 } 6958 6959 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 6960 { 6961 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6962 struct net_device *dev = info->user_ptr[1]; 6963 u8 *dst = NULL; 6964 u8 *next_hop = NULL; 6965 6966 if (!info->attrs[NL80211_ATTR_MAC]) 6967 return -EINVAL; 6968 6969 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 6970 return -EINVAL; 6971 6972 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6973 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 6974 6975 if (!rdev->ops->change_mpath) 6976 return -EOPNOTSUPP; 6977 6978 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6979 return -EOPNOTSUPP; 6980 6981 return rdev_change_mpath(rdev, dev, dst, next_hop); 6982 } 6983 6984 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 6985 { 6986 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6987 struct net_device *dev = info->user_ptr[1]; 6988 u8 *dst = NULL; 6989 u8 *next_hop = NULL; 6990 6991 if (!info->attrs[NL80211_ATTR_MAC]) 6992 return -EINVAL; 6993 6994 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 6995 return -EINVAL; 6996 6997 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6998 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 6999 7000 if (!rdev->ops->add_mpath) 7001 return -EOPNOTSUPP; 7002 7003 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7004 return -EOPNOTSUPP; 7005 7006 return rdev_add_mpath(rdev, dev, dst, next_hop); 7007 } 7008 7009 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 7010 { 7011 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7012 struct net_device *dev = info->user_ptr[1]; 7013 u8 *dst = NULL; 7014 7015 if (info->attrs[NL80211_ATTR_MAC]) 7016 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7017 7018 if (!rdev->ops->del_mpath) 7019 return -EOPNOTSUPP; 7020 7021 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7022 return -EOPNOTSUPP; 7023 7024 return rdev_del_mpath(rdev, dev, dst); 7025 } 7026 7027 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) 7028 { 7029 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7030 int err; 7031 struct net_device *dev = info->user_ptr[1]; 7032 struct mpath_info pinfo; 7033 struct sk_buff *msg; 7034 u8 *dst = NULL; 7035 u8 mpp[ETH_ALEN]; 7036 7037 memset(&pinfo, 0, sizeof(pinfo)); 7038 7039 if (!info->attrs[NL80211_ATTR_MAC]) 7040 return -EINVAL; 7041 7042 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7043 7044 if (!rdev->ops->get_mpp) 7045 return -EOPNOTSUPP; 7046 7047 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7048 return -EOPNOTSUPP; 7049 7050 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); 7051 if (err) 7052 return err; 7053 7054 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7055 if (!msg) 7056 return -ENOMEM; 7057 7058 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7059 dev, dst, mpp, &pinfo) < 0) { 7060 nlmsg_free(msg); 7061 return -ENOBUFS; 7062 } 7063 7064 return genlmsg_reply(msg, info); 7065 } 7066 7067 static int nl80211_dump_mpp(struct sk_buff *skb, 7068 struct netlink_callback *cb) 7069 { 7070 struct mpath_info pinfo; 7071 struct cfg80211_registered_device *rdev; 7072 struct wireless_dev *wdev; 7073 u8 dst[ETH_ALEN]; 7074 u8 mpp[ETH_ALEN]; 7075 int path_idx = cb->args[2]; 7076 int err; 7077 7078 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 7079 if (err) 7080 return err; 7081 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7082 __acquire(&rdev->wiphy.mtx); 7083 7084 if (!rdev->ops->dump_mpp) { 7085 err = -EOPNOTSUPP; 7086 goto out_err; 7087 } 7088 7089 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7090 err = -EOPNOTSUPP; 7091 goto out_err; 7092 } 7093 7094 while (1) { 7095 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, 7096 mpp, &pinfo); 7097 if (err == -ENOENT) 7098 break; 7099 if (err) 7100 goto out_err; 7101 7102 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7103 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7104 wdev->netdev, dst, mpp, 7105 &pinfo) < 0) 7106 goto out; 7107 7108 path_idx++; 7109 } 7110 7111 out: 7112 cb->args[2] = path_idx; 7113 err = skb->len; 7114 out_err: 7115 wiphy_unlock(&rdev->wiphy); 7116 return err; 7117 } 7118 7119 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 7120 { 7121 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7122 struct net_device *dev = info->user_ptr[1]; 7123 struct wireless_dev *wdev = dev->ieee80211_ptr; 7124 struct bss_parameters params; 7125 int err; 7126 7127 memset(¶ms, 0, sizeof(params)); 7128 /* default to not changing parameters */ 7129 params.use_cts_prot = -1; 7130 params.use_short_preamble = -1; 7131 params.use_short_slot_time = -1; 7132 params.ap_isolate = -1; 7133 params.ht_opmode = -1; 7134 params.p2p_ctwindow = -1; 7135 params.p2p_opp_ps = -1; 7136 7137 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 7138 params.use_cts_prot = 7139 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); 7140 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) 7141 params.use_short_preamble = 7142 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); 7143 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 7144 params.use_short_slot_time = 7145 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 7146 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 7147 params.basic_rates = 7148 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 7149 params.basic_rates_len = 7150 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 7151 } 7152 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 7153 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 7154 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) 7155 params.ht_opmode = 7156 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); 7157 7158 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 7159 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 7160 return -EINVAL; 7161 params.p2p_ctwindow = 7162 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 7163 if (params.p2p_ctwindow != 0 && 7164 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 7165 return -EINVAL; 7166 } 7167 7168 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 7169 u8 tmp; 7170 7171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 7172 return -EINVAL; 7173 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 7174 params.p2p_opp_ps = tmp; 7175 if (params.p2p_opp_ps && 7176 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 7177 return -EINVAL; 7178 } 7179 7180 if (!rdev->ops->change_bss) 7181 return -EOPNOTSUPP; 7182 7183 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 7184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 7185 return -EOPNOTSUPP; 7186 7187 wdev_lock(wdev); 7188 err = rdev_change_bss(rdev, dev, ¶ms); 7189 wdev_unlock(wdev); 7190 7191 return err; 7192 } 7193 7194 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) 7195 { 7196 char *data = NULL; 7197 bool is_indoor; 7198 enum nl80211_user_reg_hint_type user_reg_hint_type; 7199 u32 owner_nlportid; 7200 7201 /* 7202 * You should only get this when cfg80211 hasn't yet initialized 7203 * completely when built-in to the kernel right between the time 7204 * window between nl80211_init() and regulatory_init(), if that is 7205 * even possible. 7206 */ 7207 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 7208 return -EINPROGRESS; 7209 7210 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 7211 user_reg_hint_type = 7212 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 7213 else 7214 user_reg_hint_type = NL80211_USER_REG_HINT_USER; 7215 7216 switch (user_reg_hint_type) { 7217 case NL80211_USER_REG_HINT_USER: 7218 case NL80211_USER_REG_HINT_CELL_BASE: 7219 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 7220 return -EINVAL; 7221 7222 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 7223 return regulatory_hint_user(data, user_reg_hint_type); 7224 case NL80211_USER_REG_HINT_INDOOR: 7225 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 7226 owner_nlportid = info->snd_portid; 7227 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; 7228 } else { 7229 owner_nlportid = 0; 7230 is_indoor = true; 7231 } 7232 7233 return regulatory_hint_indoor(is_indoor, owner_nlportid); 7234 default: 7235 return -EINVAL; 7236 } 7237 } 7238 7239 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) 7240 { 7241 return reg_reload_regdb(); 7242 } 7243 7244 static int nl80211_get_mesh_config(struct sk_buff *skb, 7245 struct genl_info *info) 7246 { 7247 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7248 struct net_device *dev = info->user_ptr[1]; 7249 struct wireless_dev *wdev = dev->ieee80211_ptr; 7250 struct mesh_config cur_params; 7251 int err = 0; 7252 void *hdr; 7253 struct nlattr *pinfoattr; 7254 struct sk_buff *msg; 7255 7256 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 7257 return -EOPNOTSUPP; 7258 7259 if (!rdev->ops->get_mesh_config) 7260 return -EOPNOTSUPP; 7261 7262 wdev_lock(wdev); 7263 /* If not connected, get default parameters */ 7264 if (!wdev->mesh_id_len) 7265 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); 7266 else 7267 err = rdev_get_mesh_config(rdev, dev, &cur_params); 7268 wdev_unlock(wdev); 7269 7270 if (err) 7271 return err; 7272 7273 /* Draw up a netlink message to send back */ 7274 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7275 if (!msg) 7276 return -ENOMEM; 7277 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 7278 NL80211_CMD_GET_MESH_CONFIG); 7279 if (!hdr) 7280 goto out; 7281 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); 7282 if (!pinfoattr) 7283 goto nla_put_failure; 7284 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 7285 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, 7286 cur_params.dot11MeshRetryTimeout) || 7287 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, 7288 cur_params.dot11MeshConfirmTimeout) || 7289 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, 7290 cur_params.dot11MeshHoldingTimeout) || 7291 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, 7292 cur_params.dot11MeshMaxPeerLinks) || 7293 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, 7294 cur_params.dot11MeshMaxRetries) || 7295 nla_put_u8(msg, NL80211_MESHCONF_TTL, 7296 cur_params.dot11MeshTTL) || 7297 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, 7298 cur_params.element_ttl) || 7299 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 7300 cur_params.auto_open_plinks) || 7301 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 7302 cur_params.dot11MeshNbrOffsetMaxNeighbor) || 7303 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 7304 cur_params.dot11MeshHWMPmaxPREQretries) || 7305 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, 7306 cur_params.path_refresh_time) || 7307 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 7308 cur_params.min_discovery_timeout) || 7309 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 7310 cur_params.dot11MeshHWMPactivePathTimeout) || 7311 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 7312 cur_params.dot11MeshHWMPpreqMinInterval) || 7313 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 7314 cur_params.dot11MeshHWMPperrMinInterval) || 7315 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 7316 cur_params.dot11MeshHWMPnetDiameterTraversalTime) || 7317 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, 7318 cur_params.dot11MeshHWMPRootMode) || 7319 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, 7320 cur_params.dot11MeshHWMPRannInterval) || 7321 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 7322 cur_params.dot11MeshGateAnnouncementProtocol) || 7323 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, 7324 cur_params.dot11MeshForwarding) || 7325 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, 7326 cur_params.rssi_threshold) || 7327 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, 7328 cur_params.ht_opmode) || 7329 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 7330 cur_params.dot11MeshHWMPactivePathToRootTimeout) || 7331 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 7332 cur_params.dot11MeshHWMProotInterval) || 7333 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 7334 cur_params.dot11MeshHWMPconfirmationInterval) || 7335 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, 7336 cur_params.power_mode) || 7337 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, 7338 cur_params.dot11MeshAwakeWindowDuration) || 7339 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, 7340 cur_params.plink_timeout) || 7341 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, 7342 cur_params.dot11MeshConnectedToMeshGate) || 7343 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, 7344 cur_params.dot11MeshNolearn) || 7345 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, 7346 cur_params.dot11MeshConnectedToAuthServer)) 7347 goto nla_put_failure; 7348 nla_nest_end(msg, pinfoattr); 7349 genlmsg_end(msg, hdr); 7350 return genlmsg_reply(msg, info); 7351 7352 nla_put_failure: 7353 out: 7354 nlmsg_free(msg); 7355 return -ENOBUFS; 7356 } 7357 7358 static const struct nla_policy 7359 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 7360 [NL80211_MESHCONF_RETRY_TIMEOUT] = 7361 NLA_POLICY_RANGE(NLA_U16, 1, 255), 7362 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = 7363 NLA_POLICY_RANGE(NLA_U16, 1, 255), 7364 [NL80211_MESHCONF_HOLDING_TIMEOUT] = 7365 NLA_POLICY_RANGE(NLA_U16, 1, 255), 7366 [NL80211_MESHCONF_MAX_PEER_LINKS] = 7367 NLA_POLICY_RANGE(NLA_U16, 0, 255), 7368 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), 7369 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 7370 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 7371 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), 7372 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = 7373 NLA_POLICY_RANGE(NLA_U32, 1, 255), 7374 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 7375 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, 7376 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), 7377 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, 7378 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = 7379 NLA_POLICY_MIN(NLA_U16, 1), 7380 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = 7381 NLA_POLICY_MIN(NLA_U16, 1), 7382 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = 7383 NLA_POLICY_MIN(NLA_U16, 1), 7384 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), 7385 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = 7386 NLA_POLICY_MIN(NLA_U16, 1), 7387 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), 7388 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), 7389 [NL80211_MESHCONF_RSSI_THRESHOLD] = 7390 NLA_POLICY_RANGE(NLA_S32, -255, 0), 7391 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, 7392 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 7393 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = 7394 NLA_POLICY_MIN(NLA_U16, 1), 7395 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = 7396 NLA_POLICY_MIN(NLA_U16, 1), 7397 [NL80211_MESHCONF_POWER_MODE] = 7398 NLA_POLICY_RANGE(NLA_U32, 7399 NL80211_MESH_POWER_ACTIVE, 7400 NL80211_MESH_POWER_MAX), 7401 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, 7402 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, 7403 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 7404 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 7405 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 7406 }; 7407 7408 static const struct nla_policy 7409 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { 7410 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, 7411 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, 7412 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, 7413 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, 7414 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, 7415 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, 7416 [NL80211_MESH_SETUP_IE] = 7417 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 7418 IEEE80211_MAX_DATA_LEN), 7419 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, 7420 }; 7421 7422 static int nl80211_parse_mesh_config(struct genl_info *info, 7423 struct mesh_config *cfg, 7424 u32 *mask_out) 7425 { 7426 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 7427 u32 mask = 0; 7428 u16 ht_opmode; 7429 7430 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ 7431 do { \ 7432 if (tb[attr]) { \ 7433 cfg->param = fn(tb[attr]); \ 7434 mask |= BIT((attr) - 1); \ 7435 } \ 7436 } while (0) 7437 7438 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 7439 return -EINVAL; 7440 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) 7441 return -EINVAL; 7442 7443 /* This makes sure that there aren't more than 32 mesh config 7444 * parameters (otherwise our bitfield scheme would not work.) */ 7445 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 7446 7447 /* Fill in the params struct */ 7448 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, 7449 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 7450 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, 7451 NL80211_MESHCONF_CONFIRM_TIMEOUT, 7452 nla_get_u16); 7453 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, 7454 NL80211_MESHCONF_HOLDING_TIMEOUT, 7455 nla_get_u16); 7456 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, 7457 NL80211_MESHCONF_MAX_PEER_LINKS, 7458 nla_get_u16); 7459 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, 7460 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 7461 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, 7462 NL80211_MESHCONF_TTL, nla_get_u8); 7463 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, 7464 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); 7465 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, 7466 NL80211_MESHCONF_AUTO_OPEN_PLINKS, 7467 nla_get_u8); 7468 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, 7469 mask, 7470 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 7471 nla_get_u32); 7472 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, 7473 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 7474 nla_get_u8); 7475 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, 7476 NL80211_MESHCONF_PATH_REFRESH_TIME, 7477 nla_get_u32); 7478 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && 7479 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) 7480 return -EINVAL; 7481 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, 7482 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 7483 nla_get_u16); 7484 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, 7485 mask, 7486 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 7487 nla_get_u32); 7488 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && 7489 (cfg->dot11MeshHWMPactivePathTimeout < 1 || 7490 cfg->dot11MeshHWMPactivePathTimeout > 65535)) 7491 return -EINVAL; 7492 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, 7493 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 7494 nla_get_u16); 7495 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, 7496 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 7497 nla_get_u16); 7498 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 7499 dot11MeshHWMPnetDiameterTraversalTime, mask, 7500 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 7501 nla_get_u16); 7502 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 7503 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 7504 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 7505 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 7506 nla_get_u16); 7507 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, 7508 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 7509 nla_get_u8); 7510 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, 7511 NL80211_MESHCONF_FORWARDING, nla_get_u8); 7512 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, 7513 NL80211_MESHCONF_RSSI_THRESHOLD, 7514 nla_get_s32); 7515 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, 7516 NL80211_MESHCONF_CONNECTED_TO_GATE, 7517 nla_get_u8); 7518 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, 7519 NL80211_MESHCONF_CONNECTED_TO_AS, 7520 nla_get_u8); 7521 /* 7522 * Check HT operation mode based on 7523 * IEEE 802.11-2016 9.4.2.57 HT Operation element. 7524 */ 7525 if (tb[NL80211_MESHCONF_HT_OPMODE]) { 7526 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); 7527 7528 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | 7529 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | 7530 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) 7531 return -EINVAL; 7532 7533 /* NON_HT_STA bit is reserved, but some programs set it */ 7534 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; 7535 7536 cfg->ht_opmode = ht_opmode; 7537 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); 7538 } 7539 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 7540 dot11MeshHWMPactivePathToRootTimeout, mask, 7541 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 7542 nla_get_u32); 7543 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && 7544 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || 7545 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) 7546 return -EINVAL; 7547 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, 7548 NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 7549 nla_get_u16); 7550 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, 7551 mask, 7552 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 7553 nla_get_u16); 7554 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, 7555 NL80211_MESHCONF_POWER_MODE, nla_get_u32); 7556 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, 7557 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); 7558 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, 7559 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); 7560 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, 7561 NL80211_MESHCONF_NOLEARN, nla_get_u8); 7562 if (mask_out) 7563 *mask_out = mask; 7564 7565 return 0; 7566 7567 #undef FILL_IN_MESH_PARAM_IF_SET 7568 } 7569 7570 static int nl80211_parse_mesh_setup(struct genl_info *info, 7571 struct mesh_setup *setup) 7572 { 7573 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7574 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; 7575 7576 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 7577 return -EINVAL; 7578 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) 7579 return -EINVAL; 7580 7581 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 7582 setup->sync_method = 7583 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? 7584 IEEE80211_SYNC_METHOD_VENDOR : 7585 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; 7586 7587 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) 7588 setup->path_sel_proto = 7589 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? 7590 IEEE80211_PATH_PROTOCOL_VENDOR : 7591 IEEE80211_PATH_PROTOCOL_HWMP; 7592 7593 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) 7594 setup->path_metric = 7595 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? 7596 IEEE80211_PATH_METRIC_VENDOR : 7597 IEEE80211_PATH_METRIC_AIRTIME; 7598 7599 if (tb[NL80211_MESH_SETUP_IE]) { 7600 struct nlattr *ieattr = 7601 tb[NL80211_MESH_SETUP_IE]; 7602 setup->ie = nla_data(ieattr); 7603 setup->ie_len = nla_len(ieattr); 7604 } 7605 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && 7606 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) 7607 return -EINVAL; 7608 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); 7609 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); 7610 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); 7611 if (setup->is_secure) 7612 setup->user_mpm = true; 7613 7614 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { 7615 if (!setup->user_mpm) 7616 return -EINVAL; 7617 setup->auth_id = 7618 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); 7619 } 7620 7621 return 0; 7622 } 7623 7624 static int nl80211_update_mesh_config(struct sk_buff *skb, 7625 struct genl_info *info) 7626 { 7627 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7628 struct net_device *dev = info->user_ptr[1]; 7629 struct wireless_dev *wdev = dev->ieee80211_ptr; 7630 struct mesh_config cfg; 7631 u32 mask; 7632 int err; 7633 7634 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 7635 return -EOPNOTSUPP; 7636 7637 if (!rdev->ops->update_mesh_config) 7638 return -EOPNOTSUPP; 7639 7640 err = nl80211_parse_mesh_config(info, &cfg, &mask); 7641 if (err) 7642 return err; 7643 7644 wdev_lock(wdev); 7645 if (!wdev->mesh_id_len) 7646 err = -ENOLINK; 7647 7648 if (!err) 7649 err = rdev_update_mesh_config(rdev, dev, mask, &cfg); 7650 7651 wdev_unlock(wdev); 7652 7653 return err; 7654 } 7655 7656 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, 7657 struct sk_buff *msg) 7658 { 7659 struct nlattr *nl_reg_rules; 7660 unsigned int i; 7661 7662 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || 7663 (regdom->dfs_region && 7664 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 7665 goto nla_put_failure; 7666 7667 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); 7668 if (!nl_reg_rules) 7669 goto nla_put_failure; 7670 7671 for (i = 0; i < regdom->n_reg_rules; i++) { 7672 struct nlattr *nl_reg_rule; 7673 const struct ieee80211_reg_rule *reg_rule; 7674 const struct ieee80211_freq_range *freq_range; 7675 const struct ieee80211_power_rule *power_rule; 7676 unsigned int max_bandwidth_khz; 7677 7678 reg_rule = ®dom->reg_rules[i]; 7679 freq_range = ®_rule->freq_range; 7680 power_rule = ®_rule->power_rule; 7681 7682 nl_reg_rule = nla_nest_start_noflag(msg, i); 7683 if (!nl_reg_rule) 7684 goto nla_put_failure; 7685 7686 max_bandwidth_khz = freq_range->max_bandwidth_khz; 7687 if (!max_bandwidth_khz) 7688 max_bandwidth_khz = reg_get_max_bandwidth(regdom, 7689 reg_rule); 7690 7691 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 7692 reg_rule->flags) || 7693 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, 7694 freq_range->start_freq_khz) || 7695 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, 7696 freq_range->end_freq_khz) || 7697 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, 7698 max_bandwidth_khz) || 7699 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, 7700 power_rule->max_antenna_gain) || 7701 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 7702 power_rule->max_eirp) || 7703 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 7704 reg_rule->dfs_cac_ms)) 7705 goto nla_put_failure; 7706 7707 nla_nest_end(msg, nl_reg_rule); 7708 } 7709 7710 nla_nest_end(msg, nl_reg_rules); 7711 return 0; 7712 7713 nla_put_failure: 7714 return -EMSGSIZE; 7715 } 7716 7717 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) 7718 { 7719 const struct ieee80211_regdomain *regdom = NULL; 7720 struct cfg80211_registered_device *rdev; 7721 struct wiphy *wiphy = NULL; 7722 struct sk_buff *msg; 7723 void *hdr; 7724 7725 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7726 if (!msg) 7727 return -ENOBUFS; 7728 7729 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 7730 NL80211_CMD_GET_REG); 7731 if (!hdr) 7732 goto put_failure; 7733 7734 rtnl_lock(); 7735 7736 if (info->attrs[NL80211_ATTR_WIPHY]) { 7737 bool self_managed; 7738 7739 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 7740 if (IS_ERR(rdev)) { 7741 nlmsg_free(msg); 7742 rtnl_unlock(); 7743 return PTR_ERR(rdev); 7744 } 7745 7746 wiphy = &rdev->wiphy; 7747 self_managed = wiphy->regulatory_flags & 7748 REGULATORY_WIPHY_SELF_MANAGED; 7749 regdom = get_wiphy_regdom(wiphy); 7750 7751 /* a self-managed-reg device must have a private regdom */ 7752 if (WARN_ON(!regdom && self_managed)) { 7753 nlmsg_free(msg); 7754 rtnl_unlock(); 7755 return -EINVAL; 7756 } 7757 7758 if (regdom && 7759 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 7760 goto nla_put_failure; 7761 } 7762 7763 if (!wiphy && reg_last_request_cell_base() && 7764 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 7765 NL80211_USER_REG_HINT_CELL_BASE)) 7766 goto nla_put_failure; 7767 7768 rcu_read_lock(); 7769 7770 if (!regdom) 7771 regdom = rcu_dereference(cfg80211_regdomain); 7772 7773 if (nl80211_put_regdom(regdom, msg)) 7774 goto nla_put_failure_rcu; 7775 7776 rcu_read_unlock(); 7777 7778 genlmsg_end(msg, hdr); 7779 rtnl_unlock(); 7780 return genlmsg_reply(msg, info); 7781 7782 nla_put_failure_rcu: 7783 rcu_read_unlock(); 7784 nla_put_failure: 7785 rtnl_unlock(); 7786 put_failure: 7787 nlmsg_free(msg); 7788 return -EMSGSIZE; 7789 } 7790 7791 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, 7792 u32 seq, int flags, struct wiphy *wiphy, 7793 const struct ieee80211_regdomain *regdom) 7794 { 7795 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 7796 NL80211_CMD_GET_REG); 7797 7798 if (!hdr) 7799 return -1; 7800 7801 genl_dump_check_consistent(cb, hdr); 7802 7803 if (nl80211_put_regdom(regdom, msg)) 7804 goto nla_put_failure; 7805 7806 if (!wiphy && reg_last_request_cell_base() && 7807 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 7808 NL80211_USER_REG_HINT_CELL_BASE)) 7809 goto nla_put_failure; 7810 7811 if (wiphy && 7812 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 7813 goto nla_put_failure; 7814 7815 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 7816 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 7817 goto nla_put_failure; 7818 7819 genlmsg_end(msg, hdr); 7820 return 0; 7821 7822 nla_put_failure: 7823 genlmsg_cancel(msg, hdr); 7824 return -EMSGSIZE; 7825 } 7826 7827 static int nl80211_get_reg_dump(struct sk_buff *skb, 7828 struct netlink_callback *cb) 7829 { 7830 const struct ieee80211_regdomain *regdom = NULL; 7831 struct cfg80211_registered_device *rdev; 7832 int err, reg_idx, start = cb->args[2]; 7833 7834 rtnl_lock(); 7835 7836 if (cfg80211_regdomain && start == 0) { 7837 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 7838 NLM_F_MULTI, NULL, 7839 rtnl_dereference(cfg80211_regdomain)); 7840 if (err < 0) 7841 goto out_err; 7842 } 7843 7844 /* the global regdom is idx 0 */ 7845 reg_idx = 1; 7846 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 7847 regdom = get_wiphy_regdom(&rdev->wiphy); 7848 if (!regdom) 7849 continue; 7850 7851 if (++reg_idx <= start) 7852 continue; 7853 7854 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 7855 NLM_F_MULTI, &rdev->wiphy, regdom); 7856 if (err < 0) { 7857 reg_idx--; 7858 break; 7859 } 7860 } 7861 7862 cb->args[2] = reg_idx; 7863 err = skb->len; 7864 out_err: 7865 rtnl_unlock(); 7866 return err; 7867 } 7868 7869 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 7870 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 7871 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 7872 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 7873 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 7874 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 7875 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 7876 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 7877 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, 7878 }; 7879 7880 static int parse_reg_rule(struct nlattr *tb[], 7881 struct ieee80211_reg_rule *reg_rule) 7882 { 7883 struct ieee80211_freq_range *freq_range = ®_rule->freq_range; 7884 struct ieee80211_power_rule *power_rule = ®_rule->power_rule; 7885 7886 if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) 7887 return -EINVAL; 7888 if (!tb[NL80211_ATTR_FREQ_RANGE_START]) 7889 return -EINVAL; 7890 if (!tb[NL80211_ATTR_FREQ_RANGE_END]) 7891 return -EINVAL; 7892 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 7893 return -EINVAL; 7894 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 7895 return -EINVAL; 7896 7897 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); 7898 7899 freq_range->start_freq_khz = 7900 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); 7901 freq_range->end_freq_khz = 7902 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); 7903 freq_range->max_bandwidth_khz = 7904 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); 7905 7906 power_rule->max_eirp = 7907 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); 7908 7909 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) 7910 power_rule->max_antenna_gain = 7911 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); 7912 7913 if (tb[NL80211_ATTR_DFS_CAC_TIME]) 7914 reg_rule->dfs_cac_ms = 7915 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); 7916 7917 return 0; 7918 } 7919 7920 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 7921 { 7922 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 7923 struct nlattr *nl_reg_rule; 7924 char *alpha2; 7925 int rem_reg_rules, r; 7926 u32 num_rules = 0, rule_idx = 0; 7927 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 7928 struct ieee80211_regdomain *rd; 7929 7930 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 7931 return -EINVAL; 7932 7933 if (!info->attrs[NL80211_ATTR_REG_RULES]) 7934 return -EINVAL; 7935 7936 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 7937 7938 if (info->attrs[NL80211_ATTR_DFS_REGION]) 7939 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 7940 7941 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7942 rem_reg_rules) { 7943 num_rules++; 7944 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 7945 return -EINVAL; 7946 } 7947 7948 rtnl_lock(); 7949 if (!reg_is_valid_request(alpha2)) { 7950 r = -EINVAL; 7951 goto out; 7952 } 7953 7954 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); 7955 if (!rd) { 7956 r = -ENOMEM; 7957 goto out; 7958 } 7959 7960 rd->n_reg_rules = num_rules; 7961 rd->alpha2[0] = alpha2[0]; 7962 rd->alpha2[1] = alpha2[1]; 7963 7964 /* 7965 * Disable DFS master mode if the DFS region was 7966 * not supported or known on this kernel. 7967 */ 7968 if (reg_supported_dfs_region(dfs_region)) 7969 rd->dfs_region = dfs_region; 7970 7971 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7972 rem_reg_rules) { 7973 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, 7974 nl_reg_rule, reg_rule_policy, 7975 info->extack); 7976 if (r) 7977 goto bad_reg; 7978 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 7979 if (r) 7980 goto bad_reg; 7981 7982 rule_idx++; 7983 7984 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { 7985 r = -EINVAL; 7986 goto bad_reg; 7987 } 7988 } 7989 7990 r = set_regdom(rd, REGD_SOURCE_CRDA); 7991 /* set_regdom takes ownership of rd */ 7992 rd = NULL; 7993 bad_reg: 7994 kfree(rd); 7995 out: 7996 rtnl_unlock(); 7997 return r; 7998 } 7999 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ 8000 8001 static int validate_scan_freqs(struct nlattr *freqs) 8002 { 8003 struct nlattr *attr1, *attr2; 8004 int n_channels = 0, tmp1, tmp2; 8005 8006 nla_for_each_nested(attr1, freqs, tmp1) 8007 if (nla_len(attr1) != sizeof(u32)) 8008 return 0; 8009 8010 nla_for_each_nested(attr1, freqs, tmp1) { 8011 n_channels++; 8012 /* 8013 * Some hardware has a limited channel list for 8014 * scanning, and it is pretty much nonsensical 8015 * to scan for a channel twice, so disallow that 8016 * and don't require drivers to check that the 8017 * channel list they get isn't longer than what 8018 * they can scan, as long as they can scan all 8019 * the channels they registered at once. 8020 */ 8021 nla_for_each_nested(attr2, freqs, tmp2) 8022 if (attr1 != attr2 && 8023 nla_get_u32(attr1) == nla_get_u32(attr2)) 8024 return 0; 8025 } 8026 8027 return n_channels; 8028 } 8029 8030 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) 8031 { 8032 return b < NUM_NL80211_BANDS && wiphy->bands[b]; 8033 } 8034 8035 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, 8036 struct cfg80211_bss_selection *bss_select) 8037 { 8038 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; 8039 struct nlattr *nest; 8040 int err; 8041 bool found = false; 8042 int i; 8043 8044 /* only process one nested attribute */ 8045 nest = nla_data(nla); 8046 if (!nla_ok(nest, nla_len(nest))) 8047 return -EINVAL; 8048 8049 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, 8050 nest, nl80211_bss_select_policy, 8051 NULL); 8052 if (err) 8053 return err; 8054 8055 /* only one attribute may be given */ 8056 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { 8057 if (attr[i]) { 8058 if (found) 8059 return -EINVAL; 8060 found = true; 8061 } 8062 } 8063 8064 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; 8065 8066 if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) 8067 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; 8068 8069 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { 8070 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; 8071 bss_select->param.band_pref = 8072 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); 8073 if (!is_band_valid(wiphy, bss_select->param.band_pref)) 8074 return -EINVAL; 8075 } 8076 8077 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { 8078 struct nl80211_bss_select_rssi_adjust *adj_param; 8079 8080 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); 8081 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; 8082 bss_select->param.adjust.band = adj_param->band; 8083 bss_select->param.adjust.delta = adj_param->delta; 8084 if (!is_band_valid(wiphy, bss_select->param.adjust.band)) 8085 return -EINVAL; 8086 } 8087 8088 /* user-space did not provide behaviour attribute */ 8089 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) 8090 return -EINVAL; 8091 8092 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) 8093 return -EINVAL; 8094 8095 return 0; 8096 } 8097 8098 int nl80211_parse_random_mac(struct nlattr **attrs, 8099 u8 *mac_addr, u8 *mac_addr_mask) 8100 { 8101 int i; 8102 8103 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { 8104 eth_zero_addr(mac_addr); 8105 eth_zero_addr(mac_addr_mask); 8106 mac_addr[0] = 0x2; 8107 mac_addr_mask[0] = 0x3; 8108 8109 return 0; 8110 } 8111 8112 /* need both or none */ 8113 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) 8114 return -EINVAL; 8115 8116 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); 8117 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); 8118 8119 /* don't allow or configure an mcast address */ 8120 if (!is_multicast_ether_addr(mac_addr_mask) || 8121 is_multicast_ether_addr(mac_addr)) 8122 return -EINVAL; 8123 8124 /* 8125 * allow users to pass a MAC address that has bits set outside 8126 * of the mask, but don't bother drivers with having to deal 8127 * with such bits 8128 */ 8129 for (i = 0; i < ETH_ALEN; i++) 8130 mac_addr[i] &= mac_addr_mask[i]; 8131 8132 return 0; 8133 } 8134 8135 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) 8136 { 8137 ASSERT_WDEV_LOCK(wdev); 8138 8139 if (!cfg80211_beaconing_iface_active(wdev)) 8140 return true; 8141 8142 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) 8143 return true; 8144 8145 return regulatory_pre_cac_allowed(wdev->wiphy); 8146 } 8147 8148 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, 8149 enum nl80211_ext_feature_index feat) 8150 { 8151 if (!(flags & flag)) 8152 return true; 8153 if (wiphy_ext_feature_isset(wiphy, feat)) 8154 return true; 8155 return false; 8156 } 8157 8158 static int 8159 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, 8160 void *request, struct nlattr **attrs, 8161 bool is_sched_scan) 8162 { 8163 u8 *mac_addr, *mac_addr_mask; 8164 u32 *flags; 8165 enum nl80211_feature_flags randomness_flag; 8166 8167 if (!attrs[NL80211_ATTR_SCAN_FLAGS]) 8168 return 0; 8169 8170 if (is_sched_scan) { 8171 struct cfg80211_sched_scan_request *req = request; 8172 8173 randomness_flag = wdev ? 8174 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : 8175 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 8176 flags = &req->flags; 8177 mac_addr = req->mac_addr; 8178 mac_addr_mask = req->mac_addr_mask; 8179 } else { 8180 struct cfg80211_scan_request *req = request; 8181 8182 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 8183 flags = &req->flags; 8184 mac_addr = req->mac_addr; 8185 mac_addr_mask = req->mac_addr_mask; 8186 } 8187 8188 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); 8189 8190 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && 8191 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || 8192 !nl80211_check_scan_feat(wiphy, *flags, 8193 NL80211_SCAN_FLAG_LOW_SPAN, 8194 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || 8195 !nl80211_check_scan_feat(wiphy, *flags, 8196 NL80211_SCAN_FLAG_LOW_POWER, 8197 NL80211_EXT_FEATURE_LOW_POWER_SCAN) || 8198 !nl80211_check_scan_feat(wiphy, *flags, 8199 NL80211_SCAN_FLAG_HIGH_ACCURACY, 8200 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || 8201 !nl80211_check_scan_feat(wiphy, *flags, 8202 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, 8203 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || 8204 !nl80211_check_scan_feat(wiphy, *flags, 8205 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, 8206 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || 8207 !nl80211_check_scan_feat(wiphy, *flags, 8208 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, 8209 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || 8210 !nl80211_check_scan_feat(wiphy, *flags, 8211 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, 8212 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || 8213 !nl80211_check_scan_feat(wiphy, *flags, 8214 NL80211_SCAN_FLAG_RANDOM_SN, 8215 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || 8216 !nl80211_check_scan_feat(wiphy, *flags, 8217 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, 8218 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) 8219 return -EOPNOTSUPP; 8220 8221 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 8222 int err; 8223 8224 if (!(wiphy->features & randomness_flag) || 8225 (wdev && wdev->current_bss)) 8226 return -EOPNOTSUPP; 8227 8228 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); 8229 if (err) 8230 return err; 8231 } 8232 8233 return 0; 8234 } 8235 8236 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 8237 { 8238 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8239 struct wireless_dev *wdev = info->user_ptr[1]; 8240 struct cfg80211_scan_request *request; 8241 struct nlattr *scan_freqs = NULL; 8242 bool scan_freqs_khz = false; 8243 struct nlattr *attr; 8244 struct wiphy *wiphy; 8245 int err, tmp, n_ssids = 0, n_channels, i; 8246 size_t ie_len; 8247 8248 wiphy = &rdev->wiphy; 8249 8250 if (wdev->iftype == NL80211_IFTYPE_NAN) 8251 return -EOPNOTSUPP; 8252 8253 if (!rdev->ops->scan) 8254 return -EOPNOTSUPP; 8255 8256 if (rdev->scan_req || rdev->scan_msg) 8257 return -EBUSY; 8258 8259 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { 8260 if (!wiphy_ext_feature_isset(wiphy, 8261 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) 8262 return -EOPNOTSUPP; 8263 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; 8264 scan_freqs_khz = true; 8265 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) 8266 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; 8267 8268 if (scan_freqs) { 8269 n_channels = validate_scan_freqs(scan_freqs); 8270 if (!n_channels) 8271 return -EINVAL; 8272 } else { 8273 n_channels = ieee80211_get_num_supported_channels(wiphy); 8274 } 8275 8276 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 8277 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 8278 n_ssids++; 8279 8280 if (n_ssids > wiphy->max_scan_ssids) 8281 return -EINVAL; 8282 8283 if (info->attrs[NL80211_ATTR_IE]) 8284 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 8285 else 8286 ie_len = 0; 8287 8288 if (ie_len > wiphy->max_scan_ie_len) 8289 return -EINVAL; 8290 8291 request = kzalloc(sizeof(*request) 8292 + sizeof(*request->ssids) * n_ssids 8293 + sizeof(*request->channels) * n_channels 8294 + ie_len, GFP_KERNEL); 8295 if (!request) 8296 return -ENOMEM; 8297 8298 if (n_ssids) 8299 request->ssids = (void *)&request->channels[n_channels]; 8300 request->n_ssids = n_ssids; 8301 if (ie_len) { 8302 if (n_ssids) 8303 request->ie = (void *)(request->ssids + n_ssids); 8304 else 8305 request->ie = (void *)(request->channels + n_channels); 8306 } 8307 8308 i = 0; 8309 if (scan_freqs) { 8310 /* user specified, bail out if channel not found */ 8311 nla_for_each_nested(attr, scan_freqs, tmp) { 8312 struct ieee80211_channel *chan; 8313 int freq = nla_get_u32(attr); 8314 8315 if (!scan_freqs_khz) 8316 freq = MHZ_TO_KHZ(freq); 8317 8318 chan = ieee80211_get_channel_khz(wiphy, freq); 8319 if (!chan) { 8320 err = -EINVAL; 8321 goto out_free; 8322 } 8323 8324 /* ignore disabled channels */ 8325 if (chan->flags & IEEE80211_CHAN_DISABLED) 8326 continue; 8327 8328 request->channels[i] = chan; 8329 i++; 8330 } 8331 } else { 8332 enum nl80211_band band; 8333 8334 /* all channels */ 8335 for (band = 0; band < NUM_NL80211_BANDS; band++) { 8336 int j; 8337 8338 if (!wiphy->bands[band]) 8339 continue; 8340 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 8341 struct ieee80211_channel *chan; 8342 8343 chan = &wiphy->bands[band]->channels[j]; 8344 8345 if (chan->flags & IEEE80211_CHAN_DISABLED) 8346 continue; 8347 8348 request->channels[i] = chan; 8349 i++; 8350 } 8351 } 8352 } 8353 8354 if (!i) { 8355 err = -EINVAL; 8356 goto out_free; 8357 } 8358 8359 request->n_channels = i; 8360 8361 wdev_lock(wdev); 8362 if (!cfg80211_off_channel_oper_allowed(wdev)) { 8363 struct ieee80211_channel *chan; 8364 8365 if (request->n_channels != 1) { 8366 wdev_unlock(wdev); 8367 err = -EBUSY; 8368 goto out_free; 8369 } 8370 8371 chan = request->channels[0]; 8372 if (chan->center_freq != wdev->chandef.chan->center_freq) { 8373 wdev_unlock(wdev); 8374 err = -EBUSY; 8375 goto out_free; 8376 } 8377 } 8378 wdev_unlock(wdev); 8379 8380 i = 0; 8381 if (n_ssids) { 8382 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 8383 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 8384 err = -EINVAL; 8385 goto out_free; 8386 } 8387 request->ssids[i].ssid_len = nla_len(attr); 8388 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); 8389 i++; 8390 } 8391 } 8392 8393 if (info->attrs[NL80211_ATTR_IE]) { 8394 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 8395 memcpy((void *)request->ie, 8396 nla_data(info->attrs[NL80211_ATTR_IE]), 8397 request->ie_len); 8398 } 8399 8400 for (i = 0; i < NUM_NL80211_BANDS; i++) 8401 if (wiphy->bands[i]) 8402 request->rates[i] = 8403 (1 << wiphy->bands[i]->n_bitrates) - 1; 8404 8405 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { 8406 nla_for_each_nested(attr, 8407 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], 8408 tmp) { 8409 enum nl80211_band band = nla_type(attr); 8410 8411 if (band < 0 || band >= NUM_NL80211_BANDS) { 8412 err = -EINVAL; 8413 goto out_free; 8414 } 8415 8416 if (!wiphy->bands[band]) 8417 continue; 8418 8419 err = ieee80211_get_ratemask(wiphy->bands[band], 8420 nla_data(attr), 8421 nla_len(attr), 8422 &request->rates[band]); 8423 if (err) 8424 goto out_free; 8425 } 8426 } 8427 8428 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { 8429 request->duration = 8430 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); 8431 request->duration_mandatory = 8432 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); 8433 } 8434 8435 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, 8436 false); 8437 if (err) 8438 goto out_free; 8439 8440 request->no_cck = 8441 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 8442 8443 /* Initial implementation used NL80211_ATTR_MAC to set the specific 8444 * BSSID to scan for. This was problematic because that same attribute 8445 * was already used for another purpose (local random MAC address). The 8446 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards 8447 * compatibility with older userspace components, also use the 8448 * NL80211_ATTR_MAC value here if it can be determined to be used for 8449 * the specific BSSID use case instead of the random MAC address 8450 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). 8451 */ 8452 if (info->attrs[NL80211_ATTR_BSSID]) 8453 memcpy(request->bssid, 8454 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); 8455 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && 8456 info->attrs[NL80211_ATTR_MAC]) 8457 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), 8458 ETH_ALEN); 8459 else 8460 eth_broadcast_addr(request->bssid); 8461 8462 request->wdev = wdev; 8463 request->wiphy = &rdev->wiphy; 8464 request->scan_start = jiffies; 8465 8466 rdev->scan_req = request; 8467 err = cfg80211_scan(rdev); 8468 8469 if (err) 8470 goto out_free; 8471 8472 nl80211_send_scan_start(rdev, wdev); 8473 if (wdev->netdev) 8474 dev_hold(wdev->netdev); 8475 8476 return 0; 8477 8478 out_free: 8479 rdev->scan_req = NULL; 8480 kfree(request); 8481 8482 return err; 8483 } 8484 8485 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) 8486 { 8487 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8488 struct wireless_dev *wdev = info->user_ptr[1]; 8489 8490 if (!rdev->ops->abort_scan) 8491 return -EOPNOTSUPP; 8492 8493 if (rdev->scan_msg) 8494 return 0; 8495 8496 if (!rdev->scan_req) 8497 return -ENOENT; 8498 8499 rdev_abort_scan(rdev, wdev); 8500 return 0; 8501 } 8502 8503 static int 8504 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, 8505 struct cfg80211_sched_scan_request *request, 8506 struct nlattr **attrs) 8507 { 8508 int tmp, err, i = 0; 8509 struct nlattr *attr; 8510 8511 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 8512 u32 interval; 8513 8514 /* 8515 * If scan plans are not specified, 8516 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this 8517 * case one scan plan will be set with the specified scan 8518 * interval and infinite number of iterations. 8519 */ 8520 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); 8521 if (!interval) 8522 return -EINVAL; 8523 8524 request->scan_plans[0].interval = 8525 DIV_ROUND_UP(interval, MSEC_PER_SEC); 8526 if (!request->scan_plans[0].interval) 8527 return -EINVAL; 8528 8529 if (request->scan_plans[0].interval > 8530 wiphy->max_sched_scan_plan_interval) 8531 request->scan_plans[0].interval = 8532 wiphy->max_sched_scan_plan_interval; 8533 8534 return 0; 8535 } 8536 8537 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { 8538 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; 8539 8540 if (WARN_ON(i >= n_plans)) 8541 return -EINVAL; 8542 8543 err = nla_parse_nested_deprecated(plan, 8544 NL80211_SCHED_SCAN_PLAN_MAX, 8545 attr, nl80211_plan_policy, 8546 NULL); 8547 if (err) 8548 return err; 8549 8550 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) 8551 return -EINVAL; 8552 8553 request->scan_plans[i].interval = 8554 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); 8555 if (!request->scan_plans[i].interval || 8556 request->scan_plans[i].interval > 8557 wiphy->max_sched_scan_plan_interval) 8558 return -EINVAL; 8559 8560 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { 8561 request->scan_plans[i].iterations = 8562 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); 8563 if (!request->scan_plans[i].iterations || 8564 (request->scan_plans[i].iterations > 8565 wiphy->max_sched_scan_plan_iterations)) 8566 return -EINVAL; 8567 } else if (i < n_plans - 1) { 8568 /* 8569 * All scan plans but the last one must specify 8570 * a finite number of iterations 8571 */ 8572 return -EINVAL; 8573 } 8574 8575 i++; 8576 } 8577 8578 /* 8579 * The last scan plan must not specify the number of 8580 * iterations, it is supposed to run infinitely 8581 */ 8582 if (request->scan_plans[n_plans - 1].iterations) 8583 return -EINVAL; 8584 8585 return 0; 8586 } 8587 8588 static int 8589 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, 8590 struct cfg80211_match_set *match_sets, 8591 struct nlattr *tb_band_rssi, 8592 s32 rssi_thold) 8593 { 8594 struct nlattr *attr; 8595 int i, tmp, ret = 0; 8596 8597 if (!wiphy_ext_feature_isset(wiphy, 8598 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { 8599 if (tb_band_rssi) 8600 ret = -EOPNOTSUPP; 8601 else 8602 for (i = 0; i < NUM_NL80211_BANDS; i++) 8603 match_sets->per_band_rssi_thold[i] = 8604 NL80211_SCAN_RSSI_THOLD_OFF; 8605 return ret; 8606 } 8607 8608 for (i = 0; i < NUM_NL80211_BANDS; i++) 8609 match_sets->per_band_rssi_thold[i] = rssi_thold; 8610 8611 nla_for_each_nested(attr, tb_band_rssi, tmp) { 8612 enum nl80211_band band = nla_type(attr); 8613 8614 if (band < 0 || band >= NUM_NL80211_BANDS) 8615 return -EINVAL; 8616 8617 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); 8618 } 8619 8620 return 0; 8621 } 8622 8623 static struct cfg80211_sched_scan_request * 8624 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 8625 struct nlattr **attrs, int max_match_sets) 8626 { 8627 struct cfg80211_sched_scan_request *request; 8628 struct nlattr *attr; 8629 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; 8630 enum nl80211_band band; 8631 size_t ie_len; 8632 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; 8633 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; 8634 8635 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 8636 n_channels = validate_scan_freqs( 8637 attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 8638 if (!n_channels) 8639 return ERR_PTR(-EINVAL); 8640 } else { 8641 n_channels = ieee80211_get_num_supported_channels(wiphy); 8642 } 8643 8644 if (attrs[NL80211_ATTR_SCAN_SSIDS]) 8645 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 8646 tmp) 8647 n_ssids++; 8648 8649 if (n_ssids > wiphy->max_sched_scan_ssids) 8650 return ERR_PTR(-EINVAL); 8651 8652 /* 8653 * First, count the number of 'real' matchsets. Due to an issue with 8654 * the old implementation, matchsets containing only the RSSI attribute 8655 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' 8656 * RSSI for all matchsets, rather than their own matchset for reporting 8657 * all APs with a strong RSSI. This is needed to be compatible with 8658 * older userspace that treated a matchset with only the RSSI as the 8659 * global RSSI for all other matchsets - if there are other matchsets. 8660 */ 8661 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 8662 nla_for_each_nested(attr, 8663 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 8664 tmp) { 8665 struct nlattr *rssi; 8666 8667 err = nla_parse_nested_deprecated(tb, 8668 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 8669 attr, 8670 nl80211_match_policy, 8671 NULL); 8672 if (err) 8673 return ERR_PTR(err); 8674 8675 /* SSID and BSSID are mutually exclusive */ 8676 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && 8677 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) 8678 return ERR_PTR(-EINVAL); 8679 8680 /* add other standalone attributes here */ 8681 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || 8682 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { 8683 n_match_sets++; 8684 continue; 8685 } 8686 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 8687 if (rssi) 8688 default_match_rssi = nla_get_s32(rssi); 8689 } 8690 } 8691 8692 /* However, if there's no other matchset, add the RSSI one */ 8693 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) 8694 n_match_sets = 1; 8695 8696 if (n_match_sets > max_match_sets) 8697 return ERR_PTR(-EINVAL); 8698 8699 if (attrs[NL80211_ATTR_IE]) 8700 ie_len = nla_len(attrs[NL80211_ATTR_IE]); 8701 else 8702 ie_len = 0; 8703 8704 if (ie_len > wiphy->max_sched_scan_ie_len) 8705 return ERR_PTR(-EINVAL); 8706 8707 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 8708 /* 8709 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since 8710 * each scan plan already specifies its own interval 8711 */ 8712 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 8713 return ERR_PTR(-EINVAL); 8714 8715 nla_for_each_nested(attr, 8716 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) 8717 n_plans++; 8718 } else { 8719 /* 8720 * The scan interval attribute is kept for backward 8721 * compatibility. If no scan plans are specified and sched scan 8722 * interval is specified, one scan plan will be set with this 8723 * scan interval and infinite number of iterations. 8724 */ 8725 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 8726 return ERR_PTR(-EINVAL); 8727 8728 n_plans = 1; 8729 } 8730 8731 if (!n_plans || n_plans > wiphy->max_sched_scan_plans) 8732 return ERR_PTR(-EINVAL); 8733 8734 if (!wiphy_ext_feature_isset( 8735 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && 8736 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || 8737 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) 8738 return ERR_PTR(-EINVAL); 8739 8740 request = kzalloc(sizeof(*request) 8741 + sizeof(*request->ssids) * n_ssids 8742 + sizeof(*request->match_sets) * n_match_sets 8743 + sizeof(*request->scan_plans) * n_plans 8744 + sizeof(*request->channels) * n_channels 8745 + ie_len, GFP_KERNEL); 8746 if (!request) 8747 return ERR_PTR(-ENOMEM); 8748 8749 if (n_ssids) 8750 request->ssids = (void *)&request->channels[n_channels]; 8751 request->n_ssids = n_ssids; 8752 if (ie_len) { 8753 if (n_ssids) 8754 request->ie = (void *)(request->ssids + n_ssids); 8755 else 8756 request->ie = (void *)(request->channels + n_channels); 8757 } 8758 8759 if (n_match_sets) { 8760 if (request->ie) 8761 request->match_sets = (void *)(request->ie + ie_len); 8762 else if (n_ssids) 8763 request->match_sets = 8764 (void *)(request->ssids + n_ssids); 8765 else 8766 request->match_sets = 8767 (void *)(request->channels + n_channels); 8768 } 8769 request->n_match_sets = n_match_sets; 8770 8771 if (n_match_sets) 8772 request->scan_plans = (void *)(request->match_sets + 8773 n_match_sets); 8774 else if (request->ie) 8775 request->scan_plans = (void *)(request->ie + ie_len); 8776 else if (n_ssids) 8777 request->scan_plans = (void *)(request->ssids + n_ssids); 8778 else 8779 request->scan_plans = (void *)(request->channels + n_channels); 8780 8781 request->n_scan_plans = n_plans; 8782 8783 i = 0; 8784 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 8785 /* user specified, bail out if channel not found */ 8786 nla_for_each_nested(attr, 8787 attrs[NL80211_ATTR_SCAN_FREQUENCIES], 8788 tmp) { 8789 struct ieee80211_channel *chan; 8790 8791 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 8792 8793 if (!chan) { 8794 err = -EINVAL; 8795 goto out_free; 8796 } 8797 8798 /* ignore disabled channels */ 8799 if (chan->flags & IEEE80211_CHAN_DISABLED) 8800 continue; 8801 8802 request->channels[i] = chan; 8803 i++; 8804 } 8805 } else { 8806 /* all channels */ 8807 for (band = 0; band < NUM_NL80211_BANDS; band++) { 8808 int j; 8809 8810 if (!wiphy->bands[band]) 8811 continue; 8812 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 8813 struct ieee80211_channel *chan; 8814 8815 chan = &wiphy->bands[band]->channels[j]; 8816 8817 if (chan->flags & IEEE80211_CHAN_DISABLED) 8818 continue; 8819 8820 request->channels[i] = chan; 8821 i++; 8822 } 8823 } 8824 } 8825 8826 if (!i) { 8827 err = -EINVAL; 8828 goto out_free; 8829 } 8830 8831 request->n_channels = i; 8832 8833 i = 0; 8834 if (n_ssids) { 8835 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 8836 tmp) { 8837 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 8838 err = -EINVAL; 8839 goto out_free; 8840 } 8841 request->ssids[i].ssid_len = nla_len(attr); 8842 memcpy(request->ssids[i].ssid, nla_data(attr), 8843 nla_len(attr)); 8844 i++; 8845 } 8846 } 8847 8848 i = 0; 8849 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 8850 nla_for_each_nested(attr, 8851 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 8852 tmp) { 8853 struct nlattr *ssid, *bssid, *rssi; 8854 8855 err = nla_parse_nested_deprecated(tb, 8856 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 8857 attr, 8858 nl80211_match_policy, 8859 NULL); 8860 if (err) 8861 goto out_free; 8862 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 8863 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 8864 8865 if (!ssid && !bssid) { 8866 i++; 8867 continue; 8868 } 8869 8870 if (WARN_ON(i >= n_match_sets)) { 8871 /* this indicates a programming error, 8872 * the loop above should have verified 8873 * things properly 8874 */ 8875 err = -EINVAL; 8876 goto out_free; 8877 } 8878 8879 if (ssid) { 8880 memcpy(request->match_sets[i].ssid.ssid, 8881 nla_data(ssid), nla_len(ssid)); 8882 request->match_sets[i].ssid.ssid_len = 8883 nla_len(ssid); 8884 } 8885 if (bssid) 8886 memcpy(request->match_sets[i].bssid, 8887 nla_data(bssid), ETH_ALEN); 8888 8889 /* special attribute - old implementation w/a */ 8890 request->match_sets[i].rssi_thold = default_match_rssi; 8891 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 8892 if (rssi) 8893 request->match_sets[i].rssi_thold = 8894 nla_get_s32(rssi); 8895 8896 /* Parse per band RSSI attribute */ 8897 err = nl80211_parse_sched_scan_per_band_rssi(wiphy, 8898 &request->match_sets[i], 8899 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], 8900 request->match_sets[i].rssi_thold); 8901 if (err) 8902 goto out_free; 8903 8904 i++; 8905 } 8906 8907 /* there was no other matchset, so the RSSI one is alone */ 8908 if (i == 0 && n_match_sets) 8909 request->match_sets[0].rssi_thold = default_match_rssi; 8910 8911 request->min_rssi_thold = INT_MAX; 8912 for (i = 0; i < n_match_sets; i++) 8913 request->min_rssi_thold = 8914 min(request->match_sets[i].rssi_thold, 8915 request->min_rssi_thold); 8916 } else { 8917 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; 8918 } 8919 8920 if (ie_len) { 8921 request->ie_len = ie_len; 8922 memcpy((void *)request->ie, 8923 nla_data(attrs[NL80211_ATTR_IE]), 8924 request->ie_len); 8925 } 8926 8927 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); 8928 if (err) 8929 goto out_free; 8930 8931 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) 8932 request->delay = 8933 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); 8934 8935 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { 8936 request->relative_rssi = nla_get_s8( 8937 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); 8938 request->relative_rssi_set = true; 8939 } 8940 8941 if (request->relative_rssi_set && 8942 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { 8943 struct nl80211_bss_select_rssi_adjust *rssi_adjust; 8944 8945 rssi_adjust = nla_data( 8946 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); 8947 request->rssi_adjust.band = rssi_adjust->band; 8948 request->rssi_adjust.delta = rssi_adjust->delta; 8949 if (!is_band_valid(wiphy, request->rssi_adjust.band)) { 8950 err = -EINVAL; 8951 goto out_free; 8952 } 8953 } 8954 8955 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); 8956 if (err) 8957 goto out_free; 8958 8959 request->scan_start = jiffies; 8960 8961 return request; 8962 8963 out_free: 8964 kfree(request); 8965 return ERR_PTR(err); 8966 } 8967 8968 static int nl80211_start_sched_scan(struct sk_buff *skb, 8969 struct genl_info *info) 8970 { 8971 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8972 struct net_device *dev = info->user_ptr[1]; 8973 struct wireless_dev *wdev = dev->ieee80211_ptr; 8974 struct cfg80211_sched_scan_request *sched_scan_req; 8975 bool want_multi; 8976 int err; 8977 8978 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) 8979 return -EOPNOTSUPP; 8980 8981 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; 8982 err = cfg80211_sched_scan_req_possible(rdev, want_multi); 8983 if (err) 8984 return err; 8985 8986 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, 8987 info->attrs, 8988 rdev->wiphy.max_match_sets); 8989 8990 err = PTR_ERR_OR_ZERO(sched_scan_req); 8991 if (err) 8992 goto out_err; 8993 8994 /* leave request id zero for legacy request 8995 * or if driver does not support multi-scheduled scan 8996 */ 8997 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) 8998 sched_scan_req->reqid = cfg80211_assign_cookie(rdev); 8999 9000 err = rdev_sched_scan_start(rdev, dev, sched_scan_req); 9001 if (err) 9002 goto out_free; 9003 9004 sched_scan_req->dev = dev; 9005 sched_scan_req->wiphy = &rdev->wiphy; 9006 9007 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 9008 sched_scan_req->owner_nlportid = info->snd_portid; 9009 9010 cfg80211_add_sched_scan_req(rdev, sched_scan_req); 9011 9012 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); 9013 return 0; 9014 9015 out_free: 9016 kfree(sched_scan_req); 9017 out_err: 9018 return err; 9019 } 9020 9021 static int nl80211_stop_sched_scan(struct sk_buff *skb, 9022 struct genl_info *info) 9023 { 9024 struct cfg80211_sched_scan_request *req; 9025 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9026 u64 cookie; 9027 9028 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) 9029 return -EOPNOTSUPP; 9030 9031 if (info->attrs[NL80211_ATTR_COOKIE]) { 9032 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 9033 return __cfg80211_stop_sched_scan(rdev, cookie, false); 9034 } 9035 9036 req = list_first_or_null_rcu(&rdev->sched_scan_req_list, 9037 struct cfg80211_sched_scan_request, 9038 list); 9039 if (!req || req->reqid || 9040 (req->owner_nlportid && 9041 req->owner_nlportid != info->snd_portid)) 9042 return -ENOENT; 9043 9044 return cfg80211_stop_sched_scan_req(rdev, req, false); 9045 } 9046 9047 static int nl80211_start_radar_detection(struct sk_buff *skb, 9048 struct genl_info *info) 9049 { 9050 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9051 struct net_device *dev = info->user_ptr[1]; 9052 struct wireless_dev *wdev = dev->ieee80211_ptr; 9053 struct wiphy *wiphy = wdev->wiphy; 9054 struct cfg80211_chan_def chandef; 9055 enum nl80211_dfs_regions dfs_region; 9056 unsigned int cac_time_ms; 9057 int err; 9058 9059 dfs_region = reg_get_dfs_region(wiphy); 9060 if (dfs_region == NL80211_DFS_UNSET) 9061 return -EINVAL; 9062 9063 err = nl80211_parse_chandef(rdev, info, &chandef); 9064 if (err) 9065 return err; 9066 9067 if (netif_carrier_ok(dev)) 9068 return -EBUSY; 9069 9070 if (wdev->cac_started) 9071 return -EBUSY; 9072 9073 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 9074 if (err < 0) 9075 return err; 9076 9077 if (err == 0) 9078 return -EINVAL; 9079 9080 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) 9081 return -EINVAL; 9082 9083 /* CAC start is offloaded to HW and can't be started manually */ 9084 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) 9085 return -EOPNOTSUPP; 9086 9087 if (!rdev->ops->start_radar_detection) 9088 return -EOPNOTSUPP; 9089 9090 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 9091 if (WARN_ON(!cac_time_ms)) 9092 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; 9093 9094 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); 9095 if (!err) { 9096 wdev->chandef = chandef; 9097 wdev->cac_started = true; 9098 wdev->cac_start_time = jiffies; 9099 wdev->cac_time_ms = cac_time_ms; 9100 } 9101 return err; 9102 } 9103 9104 static int nl80211_notify_radar_detection(struct sk_buff *skb, 9105 struct genl_info *info) 9106 { 9107 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9108 struct net_device *dev = info->user_ptr[1]; 9109 struct wireless_dev *wdev = dev->ieee80211_ptr; 9110 struct wiphy *wiphy = wdev->wiphy; 9111 struct cfg80211_chan_def chandef; 9112 enum nl80211_dfs_regions dfs_region; 9113 int err; 9114 9115 dfs_region = reg_get_dfs_region(wiphy); 9116 if (dfs_region == NL80211_DFS_UNSET) { 9117 GENL_SET_ERR_MSG(info, 9118 "DFS Region is not set. Unexpected Radar indication"); 9119 return -EINVAL; 9120 } 9121 9122 err = nl80211_parse_chandef(rdev, info, &chandef); 9123 if (err) { 9124 GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); 9125 return err; 9126 } 9127 9128 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 9129 if (err < 0) { 9130 GENL_SET_ERR_MSG(info, "chandef is invalid"); 9131 return err; 9132 } 9133 9134 if (err == 0) { 9135 GENL_SET_ERR_MSG(info, 9136 "Unexpected Radar indication for chandef/iftype"); 9137 return -EINVAL; 9138 } 9139 9140 /* Do not process this notification if radar is already detected 9141 * by kernel on this channel, and return success. 9142 */ 9143 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) 9144 return 0; 9145 9146 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); 9147 9148 cfg80211_sched_dfs_chan_update(rdev); 9149 9150 rdev->radar_chandef = chandef; 9151 9152 /* Propagate this notification to other radios as well */ 9153 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 9154 9155 return 0; 9156 } 9157 9158 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) 9159 { 9160 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9161 struct net_device *dev = info->user_ptr[1]; 9162 struct wireless_dev *wdev = dev->ieee80211_ptr; 9163 struct cfg80211_csa_settings params; 9164 struct nlattr **csa_attrs = NULL; 9165 int err; 9166 bool need_new_beacon = false; 9167 bool need_handle_dfs_flag = true; 9168 int len, i; 9169 u32 cs_count; 9170 9171 if (!rdev->ops->channel_switch || 9172 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 9173 return -EOPNOTSUPP; 9174 9175 switch (dev->ieee80211_ptr->iftype) { 9176 case NL80211_IFTYPE_AP: 9177 case NL80211_IFTYPE_P2P_GO: 9178 need_new_beacon = true; 9179 /* For all modes except AP the handle_dfs flag needs to be 9180 * supplied to tell the kernel that userspace will handle radar 9181 * events when they happen. Otherwise a switch to a channel 9182 * requiring DFS will be rejected. 9183 */ 9184 need_handle_dfs_flag = false; 9185 9186 /* useless if AP is not running */ 9187 if (!wdev->beacon_interval) 9188 return -ENOTCONN; 9189 break; 9190 case NL80211_IFTYPE_ADHOC: 9191 if (!wdev->ssid_len) 9192 return -ENOTCONN; 9193 break; 9194 case NL80211_IFTYPE_MESH_POINT: 9195 if (!wdev->mesh_id_len) 9196 return -ENOTCONN; 9197 break; 9198 default: 9199 return -EOPNOTSUPP; 9200 } 9201 9202 memset(¶ms, 0, sizeof(params)); 9203 params.beacon_csa.ftm_responder = -1; 9204 9205 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 9206 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) 9207 return -EINVAL; 9208 9209 /* only important for AP, IBSS and mesh create IEs internally */ 9210 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) 9211 return -EINVAL; 9212 9213 /* Even though the attribute is u32, the specification says 9214 * u8, so let's make sure we don't overflow. 9215 */ 9216 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); 9217 if (cs_count > 255) 9218 return -EINVAL; 9219 9220 params.count = cs_count; 9221 9222 if (!need_new_beacon) 9223 goto skip_beacons; 9224 9225 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); 9226 if (err) 9227 return err; 9228 9229 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs), 9230 GFP_KERNEL); 9231 if (!csa_attrs) 9232 return -ENOMEM; 9233 9234 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, 9235 info->attrs[NL80211_ATTR_CSA_IES], 9236 nl80211_policy, info->extack); 9237 if (err) 9238 goto free; 9239 9240 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); 9241 if (err) 9242 goto free; 9243 9244 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 9245 err = -EINVAL; 9246 goto free; 9247 } 9248 9249 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 9250 if (!len || (len % sizeof(u16))) { 9251 err = -EINVAL; 9252 goto free; 9253 } 9254 9255 params.n_counter_offsets_beacon = len / sizeof(u16); 9256 if (rdev->wiphy.max_num_csa_counters && 9257 (params.n_counter_offsets_beacon > 9258 rdev->wiphy.max_num_csa_counters)) { 9259 err = -EINVAL; 9260 goto free; 9261 } 9262 9263 params.counter_offsets_beacon = 9264 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 9265 9266 /* sanity checks - counters should fit and be the same */ 9267 for (i = 0; i < params.n_counter_offsets_beacon; i++) { 9268 u16 offset = params.counter_offsets_beacon[i]; 9269 9270 if (offset >= params.beacon_csa.tail_len) { 9271 err = -EINVAL; 9272 goto free; 9273 } 9274 9275 if (params.beacon_csa.tail[offset] != params.count) { 9276 err = -EINVAL; 9277 goto free; 9278 } 9279 } 9280 9281 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 9282 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 9283 if (!len || (len % sizeof(u16))) { 9284 err = -EINVAL; 9285 goto free; 9286 } 9287 9288 params.n_counter_offsets_presp = len / sizeof(u16); 9289 if (rdev->wiphy.max_num_csa_counters && 9290 (params.n_counter_offsets_presp > 9291 rdev->wiphy.max_num_csa_counters)) { 9292 err = -EINVAL; 9293 goto free; 9294 } 9295 9296 params.counter_offsets_presp = 9297 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 9298 9299 /* sanity checks - counters should fit and be the same */ 9300 for (i = 0; i < params.n_counter_offsets_presp; i++) { 9301 u16 offset = params.counter_offsets_presp[i]; 9302 9303 if (offset >= params.beacon_csa.probe_resp_len) { 9304 err = -EINVAL; 9305 goto free; 9306 } 9307 9308 if (params.beacon_csa.probe_resp[offset] != 9309 params.count) { 9310 err = -EINVAL; 9311 goto free; 9312 } 9313 } 9314 } 9315 9316 skip_beacons: 9317 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 9318 if (err) 9319 goto free; 9320 9321 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 9322 wdev->iftype)) { 9323 err = -EINVAL; 9324 goto free; 9325 } 9326 9327 err = cfg80211_chandef_dfs_required(wdev->wiphy, 9328 ¶ms.chandef, 9329 wdev->iftype); 9330 if (err < 0) 9331 goto free; 9332 9333 if (err > 0) { 9334 params.radar_required = true; 9335 if (need_handle_dfs_flag && 9336 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { 9337 err = -EINVAL; 9338 goto free; 9339 } 9340 } 9341 9342 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 9343 params.block_tx = true; 9344 9345 wdev_lock(wdev); 9346 err = rdev_channel_switch(rdev, dev, ¶ms); 9347 wdev_unlock(wdev); 9348 9349 free: 9350 kfree(csa_attrs); 9351 return err; 9352 } 9353 9354 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, 9355 u32 seq, int flags, 9356 struct cfg80211_registered_device *rdev, 9357 struct wireless_dev *wdev, 9358 struct cfg80211_internal_bss *intbss) 9359 { 9360 struct cfg80211_bss *res = &intbss->pub; 9361 const struct cfg80211_bss_ies *ies; 9362 void *hdr; 9363 struct nlattr *bss; 9364 9365 ASSERT_WDEV_LOCK(wdev); 9366 9367 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 9368 NL80211_CMD_NEW_SCAN_RESULTS); 9369 if (!hdr) 9370 return -1; 9371 9372 genl_dump_check_consistent(cb, hdr); 9373 9374 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) 9375 goto nla_put_failure; 9376 if (wdev->netdev && 9377 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) 9378 goto nla_put_failure; 9379 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 9380 NL80211_ATTR_PAD)) 9381 goto nla_put_failure; 9382 9383 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); 9384 if (!bss) 9385 goto nla_put_failure; 9386 if ((!is_zero_ether_addr(res->bssid) && 9387 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) 9388 goto nla_put_failure; 9389 9390 rcu_read_lock(); 9391 /* indicate whether we have probe response data or not */ 9392 if (rcu_access_pointer(res->proberesp_ies) && 9393 nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) 9394 goto fail_unlock_rcu; 9395 9396 /* this pointer prefers to be pointed to probe response data 9397 * but is always valid 9398 */ 9399 ies = rcu_dereference(res->ies); 9400 if (ies) { 9401 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, 9402 NL80211_BSS_PAD)) 9403 goto fail_unlock_rcu; 9404 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, 9405 ies->len, ies->data)) 9406 goto fail_unlock_rcu; 9407 } 9408 9409 /* and this pointer is always (unless driver didn't know) beacon data */ 9410 ies = rcu_dereference(res->beacon_ies); 9411 if (ies && ies->from_beacon) { 9412 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, 9413 NL80211_BSS_PAD)) 9414 goto fail_unlock_rcu; 9415 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, 9416 ies->len, ies->data)) 9417 goto fail_unlock_rcu; 9418 } 9419 rcu_read_unlock(); 9420 9421 if (res->beacon_interval && 9422 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) 9423 goto nla_put_failure; 9424 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || 9425 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || 9426 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, 9427 res->channel->freq_offset) || 9428 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || 9429 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, 9430 jiffies_to_msecs(jiffies - intbss->ts))) 9431 goto nla_put_failure; 9432 9433 if (intbss->parent_tsf && 9434 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, 9435 intbss->parent_tsf, NL80211_BSS_PAD) || 9436 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, 9437 intbss->parent_bssid))) 9438 goto nla_put_failure; 9439 9440 if (intbss->ts_boottime && 9441 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, 9442 intbss->ts_boottime, NL80211_BSS_PAD)) 9443 goto nla_put_failure; 9444 9445 if (!nl80211_put_signal(msg, intbss->pub.chains, 9446 intbss->pub.chain_signal, 9447 NL80211_BSS_CHAIN_SIGNAL)) 9448 goto nla_put_failure; 9449 9450 switch (rdev->wiphy.signal_type) { 9451 case CFG80211_SIGNAL_TYPE_MBM: 9452 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) 9453 goto nla_put_failure; 9454 break; 9455 case CFG80211_SIGNAL_TYPE_UNSPEC: 9456 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) 9457 goto nla_put_failure; 9458 break; 9459 default: 9460 break; 9461 } 9462 9463 switch (wdev->iftype) { 9464 case NL80211_IFTYPE_P2P_CLIENT: 9465 case NL80211_IFTYPE_STATION: 9466 if (intbss == wdev->current_bss && 9467 nla_put_u32(msg, NL80211_BSS_STATUS, 9468 NL80211_BSS_STATUS_ASSOCIATED)) 9469 goto nla_put_failure; 9470 break; 9471 case NL80211_IFTYPE_ADHOC: 9472 if (intbss == wdev->current_bss && 9473 nla_put_u32(msg, NL80211_BSS_STATUS, 9474 NL80211_BSS_STATUS_IBSS_JOINED)) 9475 goto nla_put_failure; 9476 break; 9477 default: 9478 break; 9479 } 9480 9481 nla_nest_end(msg, bss); 9482 9483 genlmsg_end(msg, hdr); 9484 return 0; 9485 9486 fail_unlock_rcu: 9487 rcu_read_unlock(); 9488 nla_put_failure: 9489 genlmsg_cancel(msg, hdr); 9490 return -EMSGSIZE; 9491 } 9492 9493 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) 9494 { 9495 struct cfg80211_registered_device *rdev; 9496 struct cfg80211_internal_bss *scan; 9497 struct wireless_dev *wdev; 9498 int start = cb->args[2], idx = 0; 9499 int err; 9500 9501 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 9502 if (err) 9503 return err; 9504 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 9505 __acquire(&rdev->wiphy.mtx); 9506 9507 wdev_lock(wdev); 9508 spin_lock_bh(&rdev->bss_lock); 9509 9510 /* 9511 * dump_scan will be called multiple times to break up the scan results 9512 * into multiple messages. It is unlikely that any more bss-es will be 9513 * expired after the first call, so only call only call this on the 9514 * first dump_scan invocation. 9515 */ 9516 if (start == 0) 9517 cfg80211_bss_expire(rdev); 9518 9519 cb->seq = rdev->bss_generation; 9520 9521 list_for_each_entry(scan, &rdev->bss_list, list) { 9522 if (++idx <= start) 9523 continue; 9524 if (nl80211_send_bss(skb, cb, 9525 cb->nlh->nlmsg_seq, NLM_F_MULTI, 9526 rdev, wdev, scan) < 0) { 9527 idx--; 9528 break; 9529 } 9530 } 9531 9532 spin_unlock_bh(&rdev->bss_lock); 9533 wdev_unlock(wdev); 9534 9535 cb->args[2] = idx; 9536 wiphy_unlock(&rdev->wiphy); 9537 9538 return skb->len; 9539 } 9540 9541 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, 9542 int flags, struct net_device *dev, 9543 bool allow_radio_stats, 9544 struct survey_info *survey) 9545 { 9546 void *hdr; 9547 struct nlattr *infoattr; 9548 9549 /* skip radio stats if userspace didn't request them */ 9550 if (!survey->channel && !allow_radio_stats) 9551 return 0; 9552 9553 hdr = nl80211hdr_put(msg, portid, seq, flags, 9554 NL80211_CMD_NEW_SURVEY_RESULTS); 9555 if (!hdr) 9556 return -ENOMEM; 9557 9558 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 9559 goto nla_put_failure; 9560 9561 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); 9562 if (!infoattr) 9563 goto nla_put_failure; 9564 9565 if (survey->channel && 9566 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, 9567 survey->channel->center_freq)) 9568 goto nla_put_failure; 9569 9570 if (survey->channel && survey->channel->freq_offset && 9571 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, 9572 survey->channel->freq_offset)) 9573 goto nla_put_failure; 9574 9575 if ((survey->filled & SURVEY_INFO_NOISE_DBM) && 9576 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) 9577 goto nla_put_failure; 9578 if ((survey->filled & SURVEY_INFO_IN_USE) && 9579 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) 9580 goto nla_put_failure; 9581 if ((survey->filled & SURVEY_INFO_TIME) && 9582 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, 9583 survey->time, NL80211_SURVEY_INFO_PAD)) 9584 goto nla_put_failure; 9585 if ((survey->filled & SURVEY_INFO_TIME_BUSY) && 9586 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, 9587 survey->time_busy, NL80211_SURVEY_INFO_PAD)) 9588 goto nla_put_failure; 9589 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && 9590 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, 9591 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) 9592 goto nla_put_failure; 9593 if ((survey->filled & SURVEY_INFO_TIME_RX) && 9594 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, 9595 survey->time_rx, NL80211_SURVEY_INFO_PAD)) 9596 goto nla_put_failure; 9597 if ((survey->filled & SURVEY_INFO_TIME_TX) && 9598 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, 9599 survey->time_tx, NL80211_SURVEY_INFO_PAD)) 9600 goto nla_put_failure; 9601 if ((survey->filled & SURVEY_INFO_TIME_SCAN) && 9602 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, 9603 survey->time_scan, NL80211_SURVEY_INFO_PAD)) 9604 goto nla_put_failure; 9605 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && 9606 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, 9607 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) 9608 goto nla_put_failure; 9609 9610 nla_nest_end(msg, infoattr); 9611 9612 genlmsg_end(msg, hdr); 9613 return 0; 9614 9615 nla_put_failure: 9616 genlmsg_cancel(msg, hdr); 9617 return -EMSGSIZE; 9618 } 9619 9620 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) 9621 { 9622 struct nlattr **attrbuf; 9623 struct survey_info survey; 9624 struct cfg80211_registered_device *rdev; 9625 struct wireless_dev *wdev; 9626 int survey_idx = cb->args[2]; 9627 int res; 9628 bool radio_stats; 9629 9630 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 9631 if (!attrbuf) 9632 return -ENOMEM; 9633 9634 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 9635 if (res) { 9636 kfree(attrbuf); 9637 return res; 9638 } 9639 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 9640 __acquire(&rdev->wiphy.mtx); 9641 9642 /* prepare_wdev_dump parsed the attributes */ 9643 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; 9644 9645 if (!wdev->netdev) { 9646 res = -EINVAL; 9647 goto out_err; 9648 } 9649 9650 if (!rdev->ops->dump_survey) { 9651 res = -EOPNOTSUPP; 9652 goto out_err; 9653 } 9654 9655 while (1) { 9656 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); 9657 if (res == -ENOENT) 9658 break; 9659 if (res) 9660 goto out_err; 9661 9662 /* don't send disabled channels, but do send non-channel data */ 9663 if (survey.channel && 9664 survey.channel->flags & IEEE80211_CHAN_DISABLED) { 9665 survey_idx++; 9666 continue; 9667 } 9668 9669 if (nl80211_send_survey(skb, 9670 NETLINK_CB(cb->skb).portid, 9671 cb->nlh->nlmsg_seq, NLM_F_MULTI, 9672 wdev->netdev, radio_stats, &survey) < 0) 9673 goto out; 9674 survey_idx++; 9675 } 9676 9677 out: 9678 cb->args[2] = survey_idx; 9679 res = skb->len; 9680 out_err: 9681 kfree(attrbuf); 9682 wiphy_unlock(&rdev->wiphy); 9683 return res; 9684 } 9685 9686 static bool nl80211_valid_wpa_versions(u32 wpa_versions) 9687 { 9688 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | 9689 NL80211_WPA_VERSION_2 | 9690 NL80211_WPA_VERSION_3)); 9691 } 9692 9693 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 9694 { 9695 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9696 struct net_device *dev = info->user_ptr[1]; 9697 struct ieee80211_channel *chan; 9698 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; 9699 int err, ssid_len, ie_len = 0, auth_data_len = 0; 9700 enum nl80211_auth_type auth_type; 9701 struct key_parse key; 9702 bool local_state_change; 9703 u32 freq; 9704 9705 if (!info->attrs[NL80211_ATTR_MAC]) 9706 return -EINVAL; 9707 9708 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 9709 return -EINVAL; 9710 9711 if (!info->attrs[NL80211_ATTR_SSID]) 9712 return -EINVAL; 9713 9714 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 9715 return -EINVAL; 9716 9717 err = nl80211_parse_key(info, &key); 9718 if (err) 9719 return err; 9720 9721 if (key.idx >= 0) { 9722 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) 9723 return -EINVAL; 9724 if (!key.p.key || !key.p.key_len) 9725 return -EINVAL; 9726 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 9727 key.p.key_len != WLAN_KEY_LEN_WEP40) && 9728 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || 9729 key.p.key_len != WLAN_KEY_LEN_WEP104)) 9730 return -EINVAL; 9731 if (key.idx > 3) 9732 return -EINVAL; 9733 } else { 9734 key.p.key_len = 0; 9735 key.p.key = NULL; 9736 } 9737 9738 if (key.idx >= 0) { 9739 int i; 9740 bool ok = false; 9741 9742 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { 9743 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { 9744 ok = true; 9745 break; 9746 } 9747 } 9748 if (!ok) 9749 return -EINVAL; 9750 } 9751 9752 if (!rdev->ops->auth) 9753 return -EOPNOTSUPP; 9754 9755 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9756 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9757 return -EOPNOTSUPP; 9758 9759 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9760 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 9761 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 9762 freq += 9763 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 9764 9765 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 9766 if (!chan) 9767 return -EINVAL; 9768 9769 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9770 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9771 9772 if (info->attrs[NL80211_ATTR_IE]) { 9773 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9774 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9775 } 9776 9777 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 9778 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) 9779 return -EINVAL; 9780 9781 if ((auth_type == NL80211_AUTHTYPE_SAE || 9782 auth_type == NL80211_AUTHTYPE_FILS_SK || 9783 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 9784 auth_type == NL80211_AUTHTYPE_FILS_PK) && 9785 !info->attrs[NL80211_ATTR_AUTH_DATA]) 9786 return -EINVAL; 9787 9788 if (info->attrs[NL80211_ATTR_AUTH_DATA]) { 9789 if (auth_type != NL80211_AUTHTYPE_SAE && 9790 auth_type != NL80211_AUTHTYPE_FILS_SK && 9791 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && 9792 auth_type != NL80211_AUTHTYPE_FILS_PK) 9793 return -EINVAL; 9794 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); 9795 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); 9796 } 9797 9798 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 9799 9800 /* 9801 * Since we no longer track auth state, ignore 9802 * requests to only change local state. 9803 */ 9804 if (local_state_change) 9805 return 0; 9806 9807 wdev_lock(dev->ieee80211_ptr); 9808 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, 9809 ssid, ssid_len, ie, ie_len, 9810 key.p.key, key.p.key_len, key.idx, 9811 auth_data, auth_data_len); 9812 wdev_unlock(dev->ieee80211_ptr); 9813 return err; 9814 } 9815 9816 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, 9817 struct genl_info *info) 9818 { 9819 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 9820 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); 9821 return -EINVAL; 9822 } 9823 9824 if (!rdev->ops->tx_control_port || 9825 !wiphy_ext_feature_isset(&rdev->wiphy, 9826 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 9827 return -EOPNOTSUPP; 9828 9829 return 0; 9830 } 9831 9832 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 9833 struct genl_info *info, 9834 struct cfg80211_crypto_settings *settings, 9835 int cipher_limit) 9836 { 9837 memset(settings, 0, sizeof(*settings)); 9838 9839 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 9840 9841 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 9842 u16 proto; 9843 9844 proto = nla_get_u16( 9845 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 9846 settings->control_port_ethertype = cpu_to_be16(proto); 9847 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 9848 proto != ETH_P_PAE) 9849 return -EINVAL; 9850 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) 9851 settings->control_port_no_encrypt = true; 9852 } else 9853 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); 9854 9855 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 9856 int r = validate_pae_over_nl80211(rdev, info); 9857 9858 if (r < 0) 9859 return r; 9860 9861 settings->control_port_over_nl80211 = true; 9862 9863 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) 9864 settings->control_port_no_preauth = true; 9865 } 9866 9867 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 9868 void *data; 9869 int len, i; 9870 9871 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 9872 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 9873 settings->n_ciphers_pairwise = len / sizeof(u32); 9874 9875 if (len % sizeof(u32)) 9876 return -EINVAL; 9877 9878 if (settings->n_ciphers_pairwise > cipher_limit) 9879 return -EINVAL; 9880 9881 memcpy(settings->ciphers_pairwise, data, len); 9882 9883 for (i = 0; i < settings->n_ciphers_pairwise; i++) 9884 if (!cfg80211_supported_cipher_suite( 9885 &rdev->wiphy, 9886 settings->ciphers_pairwise[i])) 9887 return -EINVAL; 9888 } 9889 9890 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { 9891 settings->cipher_group = 9892 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); 9893 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, 9894 settings->cipher_group)) 9895 return -EINVAL; 9896 } 9897 9898 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { 9899 settings->wpa_versions = 9900 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); 9901 if (!nl80211_valid_wpa_versions(settings->wpa_versions)) 9902 return -EINVAL; 9903 } 9904 9905 if (info->attrs[NL80211_ATTR_AKM_SUITES]) { 9906 void *data; 9907 int len; 9908 9909 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); 9910 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); 9911 settings->n_akm_suites = len / sizeof(u32); 9912 9913 if (len % sizeof(u32)) 9914 return -EINVAL; 9915 9916 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) 9917 return -EINVAL; 9918 9919 memcpy(settings->akm_suites, data, len); 9920 } 9921 9922 if (info->attrs[NL80211_ATTR_PMK]) { 9923 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) 9924 return -EINVAL; 9925 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9926 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && 9927 !wiphy_ext_feature_isset(&rdev->wiphy, 9928 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) 9929 return -EINVAL; 9930 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); 9931 } 9932 9933 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { 9934 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9935 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 9936 !wiphy_ext_feature_isset(&rdev->wiphy, 9937 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) 9938 return -EINVAL; 9939 settings->sae_pwd = 9940 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 9941 settings->sae_pwd_len = 9942 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 9943 } 9944 9945 if (info->attrs[NL80211_ATTR_SAE_PWE]) 9946 settings->sae_pwe = 9947 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); 9948 else 9949 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; 9950 9951 return 0; 9952 } 9953 9954 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 9955 { 9956 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9957 struct net_device *dev = info->user_ptr[1]; 9958 struct ieee80211_channel *chan; 9959 struct cfg80211_assoc_request req = {}; 9960 const u8 *bssid, *ssid; 9961 int err, ssid_len = 0; 9962 u32 freq; 9963 9964 if (dev->ieee80211_ptr->conn_owner_nlportid && 9965 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9966 return -EPERM; 9967 9968 if (!info->attrs[NL80211_ATTR_MAC] || 9969 !info->attrs[NL80211_ATTR_SSID] || 9970 !info->attrs[NL80211_ATTR_WIPHY_FREQ]) 9971 return -EINVAL; 9972 9973 if (!rdev->ops->assoc) 9974 return -EOPNOTSUPP; 9975 9976 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9977 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9978 return -EOPNOTSUPP; 9979 9980 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9981 9982 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 9983 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 9984 freq += 9985 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 9986 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 9987 if (!chan) 9988 return -EINVAL; 9989 9990 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9991 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9992 9993 if (info->attrs[NL80211_ATTR_IE]) { 9994 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9995 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9996 } 9997 9998 if (info->attrs[NL80211_ATTR_USE_MFP]) { 9999 enum nl80211_mfp mfp = 10000 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 10001 if (mfp == NL80211_MFP_REQUIRED) 10002 req.use_mfp = true; 10003 else if (mfp != NL80211_MFP_NO) 10004 return -EINVAL; 10005 } 10006 10007 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 10008 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 10009 10010 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 10011 req.flags |= ASSOC_REQ_DISABLE_HT; 10012 10013 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10014 memcpy(&req.ht_capa_mask, 10015 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 10016 sizeof(req.ht_capa_mask)); 10017 10018 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 10019 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10020 return -EINVAL; 10021 memcpy(&req.ht_capa, 10022 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 10023 sizeof(req.ht_capa)); 10024 } 10025 10026 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 10027 req.flags |= ASSOC_REQ_DISABLE_VHT; 10028 10029 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 10030 req.flags |= ASSOC_REQ_DISABLE_HE; 10031 10032 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 10033 memcpy(&req.vht_capa_mask, 10034 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 10035 sizeof(req.vht_capa_mask)); 10036 10037 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 10038 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 10039 return -EINVAL; 10040 memcpy(&req.vht_capa, 10041 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 10042 sizeof(req.vht_capa)); 10043 } 10044 10045 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 10046 if (!((rdev->wiphy.features & 10047 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 10048 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 10049 !wiphy_ext_feature_isset(&rdev->wiphy, 10050 NL80211_EXT_FEATURE_RRM)) 10051 return -EINVAL; 10052 req.flags |= ASSOC_REQ_USE_RRM; 10053 } 10054 10055 if (info->attrs[NL80211_ATTR_FILS_KEK]) { 10056 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 10057 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 10058 if (!info->attrs[NL80211_ATTR_FILS_NONCES]) 10059 return -EINVAL; 10060 req.fils_nonces = 10061 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 10062 } 10063 10064 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { 10065 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) 10066 return -EINVAL; 10067 memcpy(&req.s1g_capa_mask, 10068 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), 10069 sizeof(req.s1g_capa_mask)); 10070 } 10071 10072 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { 10073 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) 10074 return -EINVAL; 10075 memcpy(&req.s1g_capa, 10076 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), 10077 sizeof(req.s1g_capa)); 10078 } 10079 10080 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); 10081 if (!err) { 10082 wdev_lock(dev->ieee80211_ptr); 10083 10084 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, 10085 ssid, ssid_len, &req); 10086 10087 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10088 dev->ieee80211_ptr->conn_owner_nlportid = 10089 info->snd_portid; 10090 memcpy(dev->ieee80211_ptr->disconnect_bssid, 10091 bssid, ETH_ALEN); 10092 } 10093 10094 wdev_unlock(dev->ieee80211_ptr); 10095 } 10096 10097 return err; 10098 } 10099 10100 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 10101 { 10102 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10103 struct net_device *dev = info->user_ptr[1]; 10104 const u8 *ie = NULL, *bssid; 10105 int ie_len = 0, err; 10106 u16 reason_code; 10107 bool local_state_change; 10108 10109 if (dev->ieee80211_ptr->conn_owner_nlportid && 10110 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10111 return -EPERM; 10112 10113 if (!info->attrs[NL80211_ATTR_MAC]) 10114 return -EINVAL; 10115 10116 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 10117 return -EINVAL; 10118 10119 if (!rdev->ops->deauth) 10120 return -EOPNOTSUPP; 10121 10122 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10123 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10124 return -EOPNOTSUPP; 10125 10126 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10127 10128 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 10129 if (reason_code == 0) { 10130 /* Reason Code 0 is reserved */ 10131 return -EINVAL; 10132 } 10133 10134 if (info->attrs[NL80211_ATTR_IE]) { 10135 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10136 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10137 } 10138 10139 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 10140 10141 wdev_lock(dev->ieee80211_ptr); 10142 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 10143 local_state_change); 10144 wdev_unlock(dev->ieee80211_ptr); 10145 return err; 10146 } 10147 10148 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 10149 { 10150 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10151 struct net_device *dev = info->user_ptr[1]; 10152 const u8 *ie = NULL, *bssid; 10153 int ie_len = 0, err; 10154 u16 reason_code; 10155 bool local_state_change; 10156 10157 if (dev->ieee80211_ptr->conn_owner_nlportid && 10158 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10159 return -EPERM; 10160 10161 if (!info->attrs[NL80211_ATTR_MAC]) 10162 return -EINVAL; 10163 10164 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 10165 return -EINVAL; 10166 10167 if (!rdev->ops->disassoc) 10168 return -EOPNOTSUPP; 10169 10170 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10171 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10172 return -EOPNOTSUPP; 10173 10174 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10175 10176 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 10177 if (reason_code == 0) { 10178 /* Reason Code 0 is reserved */ 10179 return -EINVAL; 10180 } 10181 10182 if (info->attrs[NL80211_ATTR_IE]) { 10183 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10184 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10185 } 10186 10187 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 10188 10189 wdev_lock(dev->ieee80211_ptr); 10190 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 10191 local_state_change); 10192 wdev_unlock(dev->ieee80211_ptr); 10193 return err; 10194 } 10195 10196 static bool 10197 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, 10198 int mcast_rate[NUM_NL80211_BANDS], 10199 int rateval) 10200 { 10201 struct wiphy *wiphy = &rdev->wiphy; 10202 bool found = false; 10203 int band, i; 10204 10205 for (band = 0; band < NUM_NL80211_BANDS; band++) { 10206 struct ieee80211_supported_band *sband; 10207 10208 sband = wiphy->bands[band]; 10209 if (!sband) 10210 continue; 10211 10212 for (i = 0; i < sband->n_bitrates; i++) { 10213 if (sband->bitrates[i].bitrate == rateval) { 10214 mcast_rate[band] = i + 1; 10215 found = true; 10216 break; 10217 } 10218 } 10219 } 10220 10221 return found; 10222 } 10223 10224 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 10225 { 10226 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10227 struct net_device *dev = info->user_ptr[1]; 10228 struct cfg80211_ibss_params ibss; 10229 struct wiphy *wiphy; 10230 struct cfg80211_cached_keys *connkeys = NULL; 10231 int err; 10232 10233 memset(&ibss, 0, sizeof(ibss)); 10234 10235 if (!info->attrs[NL80211_ATTR_SSID] || 10236 !nla_len(info->attrs[NL80211_ATTR_SSID])) 10237 return -EINVAL; 10238 10239 ibss.beacon_interval = 100; 10240 10241 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) 10242 ibss.beacon_interval = 10243 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 10244 10245 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, 10246 ibss.beacon_interval); 10247 if (err) 10248 return err; 10249 10250 if (!rdev->ops->join_ibss) 10251 return -EOPNOTSUPP; 10252 10253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 10254 return -EOPNOTSUPP; 10255 10256 wiphy = &rdev->wiphy; 10257 10258 if (info->attrs[NL80211_ATTR_MAC]) { 10259 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10260 10261 if (!is_valid_ether_addr(ibss.bssid)) 10262 return -EINVAL; 10263 } 10264 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10265 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10266 10267 if (info->attrs[NL80211_ATTR_IE]) { 10268 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10269 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10270 } 10271 10272 err = nl80211_parse_chandef(rdev, info, &ibss.chandef); 10273 if (err) 10274 return err; 10275 10276 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, 10277 NL80211_IFTYPE_ADHOC)) 10278 return -EINVAL; 10279 10280 switch (ibss.chandef.width) { 10281 case NL80211_CHAN_WIDTH_5: 10282 case NL80211_CHAN_WIDTH_10: 10283 case NL80211_CHAN_WIDTH_20_NOHT: 10284 break; 10285 case NL80211_CHAN_WIDTH_20: 10286 case NL80211_CHAN_WIDTH_40: 10287 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 10288 return -EINVAL; 10289 break; 10290 case NL80211_CHAN_WIDTH_80: 10291 case NL80211_CHAN_WIDTH_80P80: 10292 case NL80211_CHAN_WIDTH_160: 10293 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 10294 return -EINVAL; 10295 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10296 NL80211_EXT_FEATURE_VHT_IBSS)) 10297 return -EINVAL; 10298 break; 10299 default: 10300 return -EINVAL; 10301 } 10302 10303 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 10304 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 10305 10306 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 10307 u8 *rates = 10308 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 10309 int n_rates = 10310 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 10311 struct ieee80211_supported_band *sband = 10312 wiphy->bands[ibss.chandef.chan->band]; 10313 10314 err = ieee80211_get_ratemask(sband, rates, n_rates, 10315 &ibss.basic_rates); 10316 if (err) 10317 return err; 10318 } 10319 10320 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10321 memcpy(&ibss.ht_capa_mask, 10322 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 10323 sizeof(ibss.ht_capa_mask)); 10324 10325 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 10326 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10327 return -EINVAL; 10328 memcpy(&ibss.ht_capa, 10329 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 10330 sizeof(ibss.ht_capa)); 10331 } 10332 10333 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 10334 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, 10335 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 10336 return -EINVAL; 10337 10338 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { 10339 bool no_ht = false; 10340 10341 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); 10342 if (IS_ERR(connkeys)) 10343 return PTR_ERR(connkeys); 10344 10345 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && 10346 no_ht) { 10347 kfree_sensitive(connkeys); 10348 return -EINVAL; 10349 } 10350 } 10351 10352 ibss.control_port = 10353 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); 10354 10355 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 10356 int r = validate_pae_over_nl80211(rdev, info); 10357 10358 if (r < 0) { 10359 kfree_sensitive(connkeys); 10360 return r; 10361 } 10362 10363 ibss.control_port_over_nl80211 = true; 10364 } 10365 10366 ibss.userspace_handles_dfs = 10367 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 10368 10369 wdev_lock(dev->ieee80211_ptr); 10370 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 10371 if (err) 10372 kfree_sensitive(connkeys); 10373 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 10374 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 10375 wdev_unlock(dev->ieee80211_ptr); 10376 10377 return err; 10378 } 10379 10380 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 10381 { 10382 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10383 struct net_device *dev = info->user_ptr[1]; 10384 10385 if (!rdev->ops->leave_ibss) 10386 return -EOPNOTSUPP; 10387 10388 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 10389 return -EOPNOTSUPP; 10390 10391 return cfg80211_leave_ibss(rdev, dev, false); 10392 } 10393 10394 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) 10395 { 10396 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10397 struct net_device *dev = info->user_ptr[1]; 10398 int mcast_rate[NUM_NL80211_BANDS]; 10399 u32 nla_rate; 10400 int err; 10401 10402 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && 10403 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 10404 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) 10405 return -EOPNOTSUPP; 10406 10407 if (!rdev->ops->set_mcast_rate) 10408 return -EOPNOTSUPP; 10409 10410 memset(mcast_rate, 0, sizeof(mcast_rate)); 10411 10412 if (!info->attrs[NL80211_ATTR_MCAST_RATE]) 10413 return -EINVAL; 10414 10415 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); 10416 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) 10417 return -EINVAL; 10418 10419 err = rdev_set_mcast_rate(rdev, dev, mcast_rate); 10420 10421 return err; 10422 } 10423 10424 static struct sk_buff * 10425 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, 10426 struct wireless_dev *wdev, int approxlen, 10427 u32 portid, u32 seq, enum nl80211_commands cmd, 10428 enum nl80211_attrs attr, 10429 const struct nl80211_vendor_cmd_info *info, 10430 gfp_t gfp) 10431 { 10432 struct sk_buff *skb; 10433 void *hdr; 10434 struct nlattr *data; 10435 10436 skb = nlmsg_new(approxlen + 100, gfp); 10437 if (!skb) 10438 return NULL; 10439 10440 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); 10441 if (!hdr) { 10442 kfree_skb(skb); 10443 return NULL; 10444 } 10445 10446 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 10447 goto nla_put_failure; 10448 10449 if (info) { 10450 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, 10451 info->vendor_id)) 10452 goto nla_put_failure; 10453 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, 10454 info->subcmd)) 10455 goto nla_put_failure; 10456 } 10457 10458 if (wdev) { 10459 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 10460 wdev_id(wdev), NL80211_ATTR_PAD)) 10461 goto nla_put_failure; 10462 if (wdev->netdev && 10463 nla_put_u32(skb, NL80211_ATTR_IFINDEX, 10464 wdev->netdev->ifindex)) 10465 goto nla_put_failure; 10466 } 10467 10468 data = nla_nest_start_noflag(skb, attr); 10469 if (!data) 10470 goto nla_put_failure; 10471 10472 ((void **)skb->cb)[0] = rdev; 10473 ((void **)skb->cb)[1] = hdr; 10474 ((void **)skb->cb)[2] = data; 10475 10476 return skb; 10477 10478 nla_put_failure: 10479 kfree_skb(skb); 10480 return NULL; 10481 } 10482 10483 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, 10484 struct wireless_dev *wdev, 10485 enum nl80211_commands cmd, 10486 enum nl80211_attrs attr, 10487 unsigned int portid, 10488 int vendor_event_idx, 10489 int approxlen, gfp_t gfp) 10490 { 10491 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 10492 const struct nl80211_vendor_cmd_info *info; 10493 10494 switch (cmd) { 10495 case NL80211_CMD_TESTMODE: 10496 if (WARN_ON(vendor_event_idx != -1)) 10497 return NULL; 10498 info = NULL; 10499 break; 10500 case NL80211_CMD_VENDOR: 10501 if (WARN_ON(vendor_event_idx < 0 || 10502 vendor_event_idx >= wiphy->n_vendor_events)) 10503 return NULL; 10504 info = &wiphy->vendor_events[vendor_event_idx]; 10505 break; 10506 default: 10507 WARN_ON(1); 10508 return NULL; 10509 } 10510 10511 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, 10512 cmd, attr, info, gfp); 10513 } 10514 EXPORT_SYMBOL(__cfg80211_alloc_event_skb); 10515 10516 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) 10517 { 10518 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 10519 void *hdr = ((void **)skb->cb)[1]; 10520 struct nlmsghdr *nlhdr = nlmsg_hdr(skb); 10521 struct nlattr *data = ((void **)skb->cb)[2]; 10522 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; 10523 10524 /* clear CB data for netlink core to own from now on */ 10525 memset(skb->cb, 0, sizeof(skb->cb)); 10526 10527 nla_nest_end(skb, data); 10528 genlmsg_end(skb, hdr); 10529 10530 if (nlhdr->nlmsg_pid) { 10531 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, 10532 nlhdr->nlmsg_pid); 10533 } else { 10534 if (data->nla_type == NL80211_ATTR_VENDOR_DATA) 10535 mcgrp = NL80211_MCGRP_VENDOR; 10536 10537 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 10538 skb, 0, mcgrp, gfp); 10539 } 10540 } 10541 EXPORT_SYMBOL(__cfg80211_send_event_skb); 10542 10543 #ifdef CONFIG_NL80211_TESTMODE 10544 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 10545 { 10546 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10547 struct wireless_dev *wdev; 10548 int err; 10549 10550 lockdep_assert_held(&rdev->wiphy.mtx); 10551 10552 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 10553 info->attrs); 10554 10555 if (!rdev->ops->testmode_cmd) 10556 return -EOPNOTSUPP; 10557 10558 if (IS_ERR(wdev)) { 10559 err = PTR_ERR(wdev); 10560 if (err != -EINVAL) 10561 return err; 10562 wdev = NULL; 10563 } else if (wdev->wiphy != &rdev->wiphy) { 10564 return -EINVAL; 10565 } 10566 10567 if (!info->attrs[NL80211_ATTR_TESTDATA]) 10568 return -EINVAL; 10569 10570 rdev->cur_cmd_info = info; 10571 err = rdev_testmode_cmd(rdev, wdev, 10572 nla_data(info->attrs[NL80211_ATTR_TESTDATA]), 10573 nla_len(info->attrs[NL80211_ATTR_TESTDATA])); 10574 rdev->cur_cmd_info = NULL; 10575 10576 return err; 10577 } 10578 10579 static int nl80211_testmode_dump(struct sk_buff *skb, 10580 struct netlink_callback *cb) 10581 { 10582 struct cfg80211_registered_device *rdev; 10583 struct nlattr **attrbuf = NULL; 10584 int err; 10585 long phy_idx; 10586 void *data = NULL; 10587 int data_len = 0; 10588 10589 rtnl_lock(); 10590 10591 if (cb->args[0]) { 10592 /* 10593 * 0 is a valid index, but not valid for args[0], 10594 * so we need to offset by 1. 10595 */ 10596 phy_idx = cb->args[0] - 1; 10597 10598 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); 10599 if (!rdev) { 10600 err = -ENOENT; 10601 goto out_err; 10602 } 10603 } else { 10604 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 10605 GFP_KERNEL); 10606 if (!attrbuf) { 10607 err = -ENOMEM; 10608 goto out_err; 10609 } 10610 10611 err = nlmsg_parse_deprecated(cb->nlh, 10612 GENL_HDRLEN + nl80211_fam.hdrsize, 10613 attrbuf, nl80211_fam.maxattr, 10614 nl80211_policy, NULL); 10615 if (err) 10616 goto out_err; 10617 10618 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 10619 if (IS_ERR(rdev)) { 10620 err = PTR_ERR(rdev); 10621 goto out_err; 10622 } 10623 phy_idx = rdev->wiphy_idx; 10624 10625 if (attrbuf[NL80211_ATTR_TESTDATA]) 10626 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; 10627 } 10628 10629 if (cb->args[1]) { 10630 data = nla_data((void *)cb->args[1]); 10631 data_len = nla_len((void *)cb->args[1]); 10632 } 10633 10634 if (!rdev->ops->testmode_dump) { 10635 err = -EOPNOTSUPP; 10636 goto out_err; 10637 } 10638 10639 while (1) { 10640 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 10641 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10642 NL80211_CMD_TESTMODE); 10643 struct nlattr *tmdata; 10644 10645 if (!hdr) 10646 break; 10647 10648 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { 10649 genlmsg_cancel(skb, hdr); 10650 break; 10651 } 10652 10653 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); 10654 if (!tmdata) { 10655 genlmsg_cancel(skb, hdr); 10656 break; 10657 } 10658 err = rdev_testmode_dump(rdev, skb, cb, data, data_len); 10659 nla_nest_end(skb, tmdata); 10660 10661 if (err == -ENOBUFS || err == -ENOENT) { 10662 genlmsg_cancel(skb, hdr); 10663 break; 10664 } else if (err) { 10665 genlmsg_cancel(skb, hdr); 10666 goto out_err; 10667 } 10668 10669 genlmsg_end(skb, hdr); 10670 } 10671 10672 err = skb->len; 10673 /* see above */ 10674 cb->args[0] = phy_idx + 1; 10675 out_err: 10676 kfree(attrbuf); 10677 rtnl_unlock(); 10678 return err; 10679 } 10680 #endif 10681 10682 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 10683 { 10684 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10685 struct net_device *dev = info->user_ptr[1]; 10686 struct cfg80211_connect_params connect; 10687 struct wiphy *wiphy; 10688 struct cfg80211_cached_keys *connkeys = NULL; 10689 u32 freq = 0; 10690 int err; 10691 10692 memset(&connect, 0, sizeof(connect)); 10693 10694 if (!info->attrs[NL80211_ATTR_SSID] || 10695 !nla_len(info->attrs[NL80211_ATTR_SSID])) 10696 return -EINVAL; 10697 10698 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 10699 connect.auth_type = 10700 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10701 if (!nl80211_valid_auth_type(rdev, connect.auth_type, 10702 NL80211_CMD_CONNECT)) 10703 return -EINVAL; 10704 } else 10705 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 10706 10707 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 10708 10709 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && 10710 !wiphy_ext_feature_isset(&rdev->wiphy, 10711 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 10712 return -EINVAL; 10713 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; 10714 10715 err = nl80211_crypto_settings(rdev, info, &connect.crypto, 10716 NL80211_MAX_NR_CIPHER_SUITES); 10717 if (err) 10718 return err; 10719 10720 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10721 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10722 return -EOPNOTSUPP; 10723 10724 wiphy = &rdev->wiphy; 10725 10726 connect.bg_scan_period = -1; 10727 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && 10728 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { 10729 connect.bg_scan_period = 10730 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); 10731 } 10732 10733 if (info->attrs[NL80211_ATTR_MAC]) 10734 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10735 else if (info->attrs[NL80211_ATTR_MAC_HINT]) 10736 connect.bssid_hint = 10737 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); 10738 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10739 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10740 10741 if (info->attrs[NL80211_ATTR_IE]) { 10742 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10743 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10744 } 10745 10746 if (info->attrs[NL80211_ATTR_USE_MFP]) { 10747 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 10748 if (connect.mfp == NL80211_MFP_OPTIONAL && 10749 !wiphy_ext_feature_isset(&rdev->wiphy, 10750 NL80211_EXT_FEATURE_MFP_OPTIONAL)) 10751 return -EOPNOTSUPP; 10752 } else { 10753 connect.mfp = NL80211_MFP_NO; 10754 } 10755 10756 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 10757 connect.prev_bssid = 10758 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 10759 10760 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10761 freq = MHZ_TO_KHZ(nla_get_u32( 10762 info->attrs[NL80211_ATTR_WIPHY_FREQ])); 10763 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10764 freq += 10765 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10766 10767 if (freq) { 10768 connect.channel = nl80211_get_valid_chan(wiphy, freq); 10769 if (!connect.channel) 10770 return -EINVAL; 10771 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { 10772 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); 10773 freq = MHZ_TO_KHZ(freq); 10774 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); 10775 if (!connect.channel_hint) 10776 return -EINVAL; 10777 } 10778 10779 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 10780 connect.edmg.channels = 10781 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 10782 10783 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 10784 connect.edmg.bw_config = 10785 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 10786 } 10787 10788 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 10789 connkeys = nl80211_parse_connkeys(rdev, info, NULL); 10790 if (IS_ERR(connkeys)) 10791 return PTR_ERR(connkeys); 10792 } 10793 10794 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 10795 connect.flags |= ASSOC_REQ_DISABLE_HT; 10796 10797 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10798 memcpy(&connect.ht_capa_mask, 10799 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 10800 sizeof(connect.ht_capa_mask)); 10801 10802 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 10803 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { 10804 kfree_sensitive(connkeys); 10805 return -EINVAL; 10806 } 10807 memcpy(&connect.ht_capa, 10808 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 10809 sizeof(connect.ht_capa)); 10810 } 10811 10812 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 10813 connect.flags |= ASSOC_REQ_DISABLE_VHT; 10814 10815 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 10816 connect.flags |= ASSOC_REQ_DISABLE_HE; 10817 10818 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 10819 memcpy(&connect.vht_capa_mask, 10820 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 10821 sizeof(connect.vht_capa_mask)); 10822 10823 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 10824 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { 10825 kfree_sensitive(connkeys); 10826 return -EINVAL; 10827 } 10828 memcpy(&connect.vht_capa, 10829 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 10830 sizeof(connect.vht_capa)); 10831 } 10832 10833 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 10834 if (!((rdev->wiphy.features & 10835 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 10836 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 10837 !wiphy_ext_feature_isset(&rdev->wiphy, 10838 NL80211_EXT_FEATURE_RRM)) { 10839 kfree_sensitive(connkeys); 10840 return -EINVAL; 10841 } 10842 connect.flags |= ASSOC_REQ_USE_RRM; 10843 } 10844 10845 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 10846 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 10847 kfree_sensitive(connkeys); 10848 return -EOPNOTSUPP; 10849 } 10850 10851 if (info->attrs[NL80211_ATTR_BSS_SELECT]) { 10852 /* bss selection makes no sense if bssid is set */ 10853 if (connect.bssid) { 10854 kfree_sensitive(connkeys); 10855 return -EINVAL; 10856 } 10857 10858 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], 10859 wiphy, &connect.bss_select); 10860 if (err) { 10861 kfree_sensitive(connkeys); 10862 return err; 10863 } 10864 } 10865 10866 if (wiphy_ext_feature_isset(&rdev->wiphy, 10867 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 10868 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 10869 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 10870 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 10871 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10872 connect.fils_erp_username = 10873 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10874 connect.fils_erp_username_len = 10875 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10876 connect.fils_erp_realm = 10877 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10878 connect.fils_erp_realm_len = 10879 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10880 connect.fils_erp_next_seq_num = 10881 nla_get_u16( 10882 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 10883 connect.fils_erp_rrk = 10884 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10885 connect.fils_erp_rrk_len = 10886 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10887 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 10888 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 10889 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 10890 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10891 kfree_sensitive(connkeys); 10892 return -EINVAL; 10893 } 10894 10895 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { 10896 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10897 kfree_sensitive(connkeys); 10898 GENL_SET_ERR_MSG(info, 10899 "external auth requires connection ownership"); 10900 return -EINVAL; 10901 } 10902 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; 10903 } 10904 10905 wdev_lock(dev->ieee80211_ptr); 10906 10907 err = cfg80211_connect(rdev, dev, &connect, connkeys, 10908 connect.prev_bssid); 10909 if (err) 10910 kfree_sensitive(connkeys); 10911 10912 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10913 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 10914 if (connect.bssid) 10915 memcpy(dev->ieee80211_ptr->disconnect_bssid, 10916 connect.bssid, ETH_ALEN); 10917 else 10918 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); 10919 } 10920 10921 wdev_unlock(dev->ieee80211_ptr); 10922 10923 return err; 10924 } 10925 10926 static int nl80211_update_connect_params(struct sk_buff *skb, 10927 struct genl_info *info) 10928 { 10929 struct cfg80211_connect_params connect = {}; 10930 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10931 struct net_device *dev = info->user_ptr[1]; 10932 struct wireless_dev *wdev = dev->ieee80211_ptr; 10933 bool fils_sk_offload; 10934 u32 auth_type; 10935 u32 changed = 0; 10936 int ret; 10937 10938 if (!rdev->ops->update_connect_params) 10939 return -EOPNOTSUPP; 10940 10941 if (info->attrs[NL80211_ATTR_IE]) { 10942 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10943 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10944 changed |= UPDATE_ASSOC_IES; 10945 } 10946 10947 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, 10948 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); 10949 10950 /* 10951 * when driver supports fils-sk offload all attributes must be 10952 * provided. So the else covers "fils-sk-not-all" and 10953 * "no-fils-sk-any". 10954 */ 10955 if (fils_sk_offload && 10956 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 10957 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 10958 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 10959 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10960 connect.fils_erp_username = 10961 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10962 connect.fils_erp_username_len = 10963 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10964 connect.fils_erp_realm = 10965 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10966 connect.fils_erp_realm_len = 10967 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10968 connect.fils_erp_next_seq_num = 10969 nla_get_u16( 10970 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 10971 connect.fils_erp_rrk = 10972 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10973 connect.fils_erp_rrk_len = 10974 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10975 changed |= UPDATE_FILS_ERP_INFO; 10976 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 10977 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 10978 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 10979 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10980 return -EINVAL; 10981 } 10982 10983 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 10984 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10985 if (!nl80211_valid_auth_type(rdev, auth_type, 10986 NL80211_CMD_CONNECT)) 10987 return -EINVAL; 10988 10989 if (auth_type == NL80211_AUTHTYPE_FILS_SK && 10990 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) 10991 return -EINVAL; 10992 10993 connect.auth_type = auth_type; 10994 changed |= UPDATE_AUTH_TYPE; 10995 } 10996 10997 wdev_lock(dev->ieee80211_ptr); 10998 if (!wdev->current_bss) 10999 ret = -ENOLINK; 11000 else 11001 ret = rdev_update_connect_params(rdev, dev, &connect, changed); 11002 wdev_unlock(dev->ieee80211_ptr); 11003 11004 return ret; 11005 } 11006 11007 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 11008 { 11009 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11010 struct net_device *dev = info->user_ptr[1]; 11011 u16 reason; 11012 int ret; 11013 11014 if (dev->ieee80211_ptr->conn_owner_nlportid && 11015 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11016 return -EPERM; 11017 11018 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11019 reason = WLAN_REASON_DEAUTH_LEAVING; 11020 else 11021 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11022 11023 if (reason == 0) 11024 return -EINVAL; 11025 11026 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11027 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11028 return -EOPNOTSUPP; 11029 11030 wdev_lock(dev->ieee80211_ptr); 11031 ret = cfg80211_disconnect(rdev, dev, reason, true); 11032 wdev_unlock(dev->ieee80211_ptr); 11033 return ret; 11034 } 11035 11036 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 11037 { 11038 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11039 struct net *net; 11040 int err; 11041 11042 if (info->attrs[NL80211_ATTR_PID]) { 11043 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 11044 11045 net = get_net_ns_by_pid(pid); 11046 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { 11047 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); 11048 11049 net = get_net_ns_by_fd(fd); 11050 } else { 11051 return -EINVAL; 11052 } 11053 11054 if (IS_ERR(net)) 11055 return PTR_ERR(net); 11056 11057 err = 0; 11058 11059 /* check if anything to do */ 11060 if (!net_eq(wiphy_net(&rdev->wiphy), net)) 11061 err = cfg80211_switch_netns(rdev, net); 11062 11063 put_net(net); 11064 return err; 11065 } 11066 11067 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 11068 { 11069 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11070 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 11071 struct cfg80211_pmksa *pmksa) = NULL; 11072 struct net_device *dev = info->user_ptr[1]; 11073 struct cfg80211_pmksa pmksa; 11074 11075 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 11076 11077 if (!info->attrs[NL80211_ATTR_PMKID]) 11078 return -EINVAL; 11079 11080 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 11081 11082 if (info->attrs[NL80211_ATTR_MAC]) { 11083 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11084 } else if (info->attrs[NL80211_ATTR_SSID] && 11085 info->attrs[NL80211_ATTR_FILS_CACHE_ID] && 11086 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || 11087 info->attrs[NL80211_ATTR_PMK])) { 11088 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11089 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11090 pmksa.cache_id = 11091 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); 11092 } else { 11093 return -EINVAL; 11094 } 11095 if (info->attrs[NL80211_ATTR_PMK]) { 11096 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 11097 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 11098 } 11099 11100 if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) 11101 pmksa.pmk_lifetime = 11102 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); 11103 11104 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) 11105 pmksa.pmk_reauth_threshold = 11106 nla_get_u8( 11107 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); 11108 11109 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11110 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && 11111 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && 11112 wiphy_ext_feature_isset(&rdev->wiphy, 11113 NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) 11114 return -EOPNOTSUPP; 11115 11116 switch (info->genlhdr->cmd) { 11117 case NL80211_CMD_SET_PMKSA: 11118 rdev_ops = rdev->ops->set_pmksa; 11119 break; 11120 case NL80211_CMD_DEL_PMKSA: 11121 rdev_ops = rdev->ops->del_pmksa; 11122 break; 11123 default: 11124 WARN_ON(1); 11125 break; 11126 } 11127 11128 if (!rdev_ops) 11129 return -EOPNOTSUPP; 11130 11131 return rdev_ops(&rdev->wiphy, dev, &pmksa); 11132 } 11133 11134 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 11135 { 11136 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11137 struct net_device *dev = info->user_ptr[1]; 11138 11139 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11140 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11141 return -EOPNOTSUPP; 11142 11143 if (!rdev->ops->flush_pmksa) 11144 return -EOPNOTSUPP; 11145 11146 return rdev_flush_pmksa(rdev, dev); 11147 } 11148 11149 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) 11150 { 11151 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11152 struct net_device *dev = info->user_ptr[1]; 11153 u8 action_code, dialog_token; 11154 u32 peer_capability = 0; 11155 u16 status_code; 11156 u8 *peer; 11157 bool initiator; 11158 11159 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 11160 !rdev->ops->tdls_mgmt) 11161 return -EOPNOTSUPP; 11162 11163 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || 11164 !info->attrs[NL80211_ATTR_STATUS_CODE] || 11165 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || 11166 !info->attrs[NL80211_ATTR_IE] || 11167 !info->attrs[NL80211_ATTR_MAC]) 11168 return -EINVAL; 11169 11170 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 11171 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); 11172 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 11173 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); 11174 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); 11175 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) 11176 peer_capability = 11177 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); 11178 11179 return rdev_tdls_mgmt(rdev, dev, peer, action_code, 11180 dialog_token, status_code, peer_capability, 11181 initiator, 11182 nla_data(info->attrs[NL80211_ATTR_IE]), 11183 nla_len(info->attrs[NL80211_ATTR_IE])); 11184 } 11185 11186 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) 11187 { 11188 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11189 struct net_device *dev = info->user_ptr[1]; 11190 enum nl80211_tdls_operation operation; 11191 u8 *peer; 11192 11193 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 11194 !rdev->ops->tdls_oper) 11195 return -EOPNOTSUPP; 11196 11197 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || 11198 !info->attrs[NL80211_ATTR_MAC]) 11199 return -EINVAL; 11200 11201 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); 11202 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 11203 11204 return rdev_tdls_oper(rdev, dev, peer, operation); 11205 } 11206 11207 static int nl80211_remain_on_channel(struct sk_buff *skb, 11208 struct genl_info *info) 11209 { 11210 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11211 struct wireless_dev *wdev = info->user_ptr[1]; 11212 struct cfg80211_chan_def chandef; 11213 const struct cfg80211_chan_def *compat_chandef; 11214 struct sk_buff *msg; 11215 void *hdr; 11216 u64 cookie; 11217 u32 duration; 11218 int err; 11219 11220 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 11221 !info->attrs[NL80211_ATTR_DURATION]) 11222 return -EINVAL; 11223 11224 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 11225 11226 if (!rdev->ops->remain_on_channel || 11227 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) 11228 return -EOPNOTSUPP; 11229 11230 /* 11231 * We should be on that channel for at least a minimum amount of 11232 * time (10ms) but no longer than the driver supports. 11233 */ 11234 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 11235 duration > rdev->wiphy.max_remain_on_channel_duration) 11236 return -EINVAL; 11237 11238 err = nl80211_parse_chandef(rdev, info, &chandef); 11239 if (err) 11240 return err; 11241 11242 wdev_lock(wdev); 11243 if (!cfg80211_off_channel_oper_allowed(wdev) && 11244 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { 11245 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, 11246 &chandef); 11247 if (compat_chandef != &chandef) { 11248 wdev_unlock(wdev); 11249 return -EBUSY; 11250 } 11251 } 11252 wdev_unlock(wdev); 11253 11254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 11255 if (!msg) 11256 return -ENOMEM; 11257 11258 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11259 NL80211_CMD_REMAIN_ON_CHANNEL); 11260 if (!hdr) { 11261 err = -ENOBUFS; 11262 goto free_msg; 11263 } 11264 11265 err = rdev_remain_on_channel(rdev, wdev, chandef.chan, 11266 duration, &cookie); 11267 11268 if (err) 11269 goto free_msg; 11270 11271 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 11272 NL80211_ATTR_PAD)) 11273 goto nla_put_failure; 11274 11275 genlmsg_end(msg, hdr); 11276 11277 return genlmsg_reply(msg, info); 11278 11279 nla_put_failure: 11280 err = -ENOBUFS; 11281 free_msg: 11282 nlmsg_free(msg); 11283 return err; 11284 } 11285 11286 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 11287 struct genl_info *info) 11288 { 11289 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11290 struct wireless_dev *wdev = info->user_ptr[1]; 11291 u64 cookie; 11292 11293 if (!info->attrs[NL80211_ATTR_COOKIE]) 11294 return -EINVAL; 11295 11296 if (!rdev->ops->cancel_remain_on_channel) 11297 return -EOPNOTSUPP; 11298 11299 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 11300 11301 return rdev_cancel_remain_on_channel(rdev, wdev, cookie); 11302 } 11303 11304 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, 11305 struct genl_info *info) 11306 { 11307 struct cfg80211_bitrate_mask mask; 11308 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11309 struct net_device *dev = info->user_ptr[1]; 11310 int err; 11311 11312 if (!rdev->ops->set_bitrate_mask) 11313 return -EOPNOTSUPP; 11314 11315 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 11316 NL80211_ATTR_TX_RATES, &mask, 11317 dev, true); 11318 if (err) 11319 return err; 11320 11321 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); 11322 } 11323 11324 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) 11325 { 11326 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11327 struct wireless_dev *wdev = info->user_ptr[1]; 11328 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; 11329 11330 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 11331 return -EINVAL; 11332 11333 if (info->attrs[NL80211_ATTR_FRAME_TYPE]) 11334 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); 11335 11336 switch (wdev->iftype) { 11337 case NL80211_IFTYPE_STATION: 11338 case NL80211_IFTYPE_ADHOC: 11339 case NL80211_IFTYPE_P2P_CLIENT: 11340 case NL80211_IFTYPE_AP: 11341 case NL80211_IFTYPE_AP_VLAN: 11342 case NL80211_IFTYPE_MESH_POINT: 11343 case NL80211_IFTYPE_P2P_GO: 11344 case NL80211_IFTYPE_P2P_DEVICE: 11345 break; 11346 case NL80211_IFTYPE_NAN: 11347 default: 11348 return -EOPNOTSUPP; 11349 } 11350 11351 /* not much point in registering if we can't reply */ 11352 if (!rdev->ops->mgmt_tx) 11353 return -EOPNOTSUPP; 11354 11355 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && 11356 !wiphy_ext_feature_isset(&rdev->wiphy, 11357 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { 11358 GENL_SET_ERR_MSG(info, 11359 "multicast RX registrations are not supported"); 11360 return -EOPNOTSUPP; 11361 } 11362 11363 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, 11364 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 11365 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), 11366 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], 11367 info->extack); 11368 } 11369 11370 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) 11371 { 11372 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11373 struct wireless_dev *wdev = info->user_ptr[1]; 11374 struct cfg80211_chan_def chandef; 11375 int err; 11376 void *hdr = NULL; 11377 u64 cookie; 11378 struct sk_buff *msg = NULL; 11379 struct cfg80211_mgmt_tx_params params = { 11380 .dont_wait_for_ack = 11381 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], 11382 }; 11383 11384 if (!info->attrs[NL80211_ATTR_FRAME]) 11385 return -EINVAL; 11386 11387 if (!rdev->ops->mgmt_tx) 11388 return -EOPNOTSUPP; 11389 11390 switch (wdev->iftype) { 11391 case NL80211_IFTYPE_P2P_DEVICE: 11392 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 11393 return -EINVAL; 11394 break; 11395 case NL80211_IFTYPE_STATION: 11396 case NL80211_IFTYPE_ADHOC: 11397 case NL80211_IFTYPE_P2P_CLIENT: 11398 case NL80211_IFTYPE_AP: 11399 case NL80211_IFTYPE_AP_VLAN: 11400 case NL80211_IFTYPE_MESH_POINT: 11401 case NL80211_IFTYPE_P2P_GO: 11402 break; 11403 case NL80211_IFTYPE_NAN: 11404 default: 11405 return -EOPNOTSUPP; 11406 } 11407 11408 if (info->attrs[NL80211_ATTR_DURATION]) { 11409 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 11410 return -EINVAL; 11411 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 11412 11413 /* 11414 * We should wait on the channel for at least a minimum amount 11415 * of time (10ms) but no longer than the driver supports. 11416 */ 11417 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 11418 params.wait > rdev->wiphy.max_remain_on_channel_duration) 11419 return -EINVAL; 11420 } 11421 11422 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; 11423 11424 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 11425 return -EINVAL; 11426 11427 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 11428 11429 /* get the channel if any has been specified, otherwise pass NULL to 11430 * the driver. The latter will use the current one 11431 */ 11432 chandef.chan = NULL; 11433 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 11434 err = nl80211_parse_chandef(rdev, info, &chandef); 11435 if (err) 11436 return err; 11437 } 11438 11439 if (!chandef.chan && params.offchan) 11440 return -EINVAL; 11441 11442 wdev_lock(wdev); 11443 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { 11444 wdev_unlock(wdev); 11445 return -EBUSY; 11446 } 11447 wdev_unlock(wdev); 11448 11449 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 11450 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 11451 11452 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { 11453 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 11454 int i; 11455 11456 if (len % sizeof(u16)) 11457 return -EINVAL; 11458 11459 params.n_csa_offsets = len / sizeof(u16); 11460 params.csa_offsets = 11461 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 11462 11463 /* check that all the offsets fit the frame */ 11464 for (i = 0; i < params.n_csa_offsets; i++) { 11465 if (params.csa_offsets[i] >= params.len) 11466 return -EINVAL; 11467 } 11468 } 11469 11470 if (!params.dont_wait_for_ack) { 11471 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 11472 if (!msg) 11473 return -ENOMEM; 11474 11475 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11476 NL80211_CMD_FRAME); 11477 if (!hdr) { 11478 err = -ENOBUFS; 11479 goto free_msg; 11480 } 11481 } 11482 11483 params.chan = chandef.chan; 11484 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); 11485 if (err) 11486 goto free_msg; 11487 11488 if (msg) { 11489 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 11490 NL80211_ATTR_PAD)) 11491 goto nla_put_failure; 11492 11493 genlmsg_end(msg, hdr); 11494 return genlmsg_reply(msg, info); 11495 } 11496 11497 return 0; 11498 11499 nla_put_failure: 11500 err = -ENOBUFS; 11501 free_msg: 11502 nlmsg_free(msg); 11503 return err; 11504 } 11505 11506 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) 11507 { 11508 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11509 struct wireless_dev *wdev = info->user_ptr[1]; 11510 u64 cookie; 11511 11512 if (!info->attrs[NL80211_ATTR_COOKIE]) 11513 return -EINVAL; 11514 11515 if (!rdev->ops->mgmt_tx_cancel_wait) 11516 return -EOPNOTSUPP; 11517 11518 switch (wdev->iftype) { 11519 case NL80211_IFTYPE_STATION: 11520 case NL80211_IFTYPE_ADHOC: 11521 case NL80211_IFTYPE_P2P_CLIENT: 11522 case NL80211_IFTYPE_AP: 11523 case NL80211_IFTYPE_AP_VLAN: 11524 case NL80211_IFTYPE_P2P_GO: 11525 case NL80211_IFTYPE_P2P_DEVICE: 11526 break; 11527 case NL80211_IFTYPE_NAN: 11528 default: 11529 return -EOPNOTSUPP; 11530 } 11531 11532 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 11533 11534 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); 11535 } 11536 11537 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 11538 { 11539 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11540 struct wireless_dev *wdev; 11541 struct net_device *dev = info->user_ptr[1]; 11542 u8 ps_state; 11543 bool state; 11544 int err; 11545 11546 if (!info->attrs[NL80211_ATTR_PS_STATE]) 11547 return -EINVAL; 11548 11549 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 11550 11551 wdev = dev->ieee80211_ptr; 11552 11553 if (!rdev->ops->set_power_mgmt) 11554 return -EOPNOTSUPP; 11555 11556 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 11557 11558 if (state == wdev->ps) 11559 return 0; 11560 11561 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); 11562 if (!err) 11563 wdev->ps = state; 11564 return err; 11565 } 11566 11567 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 11568 { 11569 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11570 enum nl80211_ps_state ps_state; 11571 struct wireless_dev *wdev; 11572 struct net_device *dev = info->user_ptr[1]; 11573 struct sk_buff *msg; 11574 void *hdr; 11575 int err; 11576 11577 wdev = dev->ieee80211_ptr; 11578 11579 if (!rdev->ops->set_power_mgmt) 11580 return -EOPNOTSUPP; 11581 11582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 11583 if (!msg) 11584 return -ENOMEM; 11585 11586 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11587 NL80211_CMD_GET_POWER_SAVE); 11588 if (!hdr) { 11589 err = -ENOBUFS; 11590 goto free_msg; 11591 } 11592 11593 if (wdev->ps) 11594 ps_state = NL80211_PS_ENABLED; 11595 else 11596 ps_state = NL80211_PS_DISABLED; 11597 11598 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) 11599 goto nla_put_failure; 11600 11601 genlmsg_end(msg, hdr); 11602 return genlmsg_reply(msg, info); 11603 11604 nla_put_failure: 11605 err = -ENOBUFS; 11606 free_msg: 11607 nlmsg_free(msg); 11608 return err; 11609 } 11610 11611 static const struct nla_policy 11612 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { 11613 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, 11614 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, 11615 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, 11616 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, 11617 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, 11618 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, 11619 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, 11620 }; 11621 11622 static int nl80211_set_cqm_txe(struct genl_info *info, 11623 u32 rate, u32 pkts, u32 intvl) 11624 { 11625 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11626 struct net_device *dev = info->user_ptr[1]; 11627 struct wireless_dev *wdev = dev->ieee80211_ptr; 11628 11629 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) 11630 return -EINVAL; 11631 11632 if (!rdev->ops->set_cqm_txe_config) 11633 return -EOPNOTSUPP; 11634 11635 if (wdev->iftype != NL80211_IFTYPE_STATION && 11636 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 11637 return -EOPNOTSUPP; 11638 11639 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); 11640 } 11641 11642 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, 11643 struct net_device *dev) 11644 { 11645 struct wireless_dev *wdev = dev->ieee80211_ptr; 11646 s32 last, low, high; 11647 u32 hyst; 11648 int i, n, low_index; 11649 int err; 11650 11651 /* RSSI reporting disabled? */ 11652 if (!wdev->cqm_config) 11653 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); 11654 11655 /* 11656 * Obtain current RSSI value if possible, if not and no RSSI threshold 11657 * event has been received yet, we should receive an event after a 11658 * connection is established and enough beacons received to calculate 11659 * the average. 11660 */ 11661 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && 11662 rdev->ops->get_station) { 11663 struct station_info sinfo = {}; 11664 u8 *mac_addr; 11665 11666 mac_addr = wdev->current_bss->pub.bssid; 11667 11668 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 11669 if (err) 11670 return err; 11671 11672 cfg80211_sinfo_release_content(&sinfo); 11673 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) 11674 wdev->cqm_config->last_rssi_event_value = 11675 (s8) sinfo.rx_beacon_signal_avg; 11676 } 11677 11678 last = wdev->cqm_config->last_rssi_event_value; 11679 hyst = wdev->cqm_config->rssi_hyst; 11680 n = wdev->cqm_config->n_rssi_thresholds; 11681 11682 for (i = 0; i < n; i++) { 11683 i = array_index_nospec(i, n); 11684 if (last < wdev->cqm_config->rssi_thresholds[i]) 11685 break; 11686 } 11687 11688 low_index = i - 1; 11689 if (low_index >= 0) { 11690 low_index = array_index_nospec(low_index, n); 11691 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; 11692 } else { 11693 low = S32_MIN; 11694 } 11695 if (i < n) { 11696 i = array_index_nospec(i, n); 11697 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; 11698 } else { 11699 high = S32_MAX; 11700 } 11701 11702 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); 11703 } 11704 11705 static int nl80211_set_cqm_rssi(struct genl_info *info, 11706 const s32 *thresholds, int n_thresholds, 11707 u32 hysteresis) 11708 { 11709 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11710 struct net_device *dev = info->user_ptr[1]; 11711 struct wireless_dev *wdev = dev->ieee80211_ptr; 11712 int i, err; 11713 s32 prev = S32_MIN; 11714 11715 /* Check all values negative and sorted */ 11716 for (i = 0; i < n_thresholds; i++) { 11717 if (thresholds[i] > 0 || thresholds[i] <= prev) 11718 return -EINVAL; 11719 11720 prev = thresholds[i]; 11721 } 11722 11723 if (wdev->iftype != NL80211_IFTYPE_STATION && 11724 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 11725 return -EOPNOTSUPP; 11726 11727 wdev_lock(wdev); 11728 cfg80211_cqm_config_free(wdev); 11729 wdev_unlock(wdev); 11730 11731 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { 11732 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ 11733 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); 11734 11735 return rdev_set_cqm_rssi_config(rdev, dev, 11736 thresholds[0], hysteresis); 11737 } 11738 11739 if (!wiphy_ext_feature_isset(&rdev->wiphy, 11740 NL80211_EXT_FEATURE_CQM_RSSI_LIST)) 11741 return -EOPNOTSUPP; 11742 11743 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ 11744 n_thresholds = 0; 11745 11746 wdev_lock(wdev); 11747 if (n_thresholds) { 11748 struct cfg80211_cqm_config *cqm_config; 11749 11750 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + 11751 n_thresholds * sizeof(s32), GFP_KERNEL); 11752 if (!cqm_config) { 11753 err = -ENOMEM; 11754 goto unlock; 11755 } 11756 11757 cqm_config->rssi_hyst = hysteresis; 11758 cqm_config->n_rssi_thresholds = n_thresholds; 11759 memcpy(cqm_config->rssi_thresholds, thresholds, 11760 n_thresholds * sizeof(s32)); 11761 11762 wdev->cqm_config = cqm_config; 11763 } 11764 11765 err = cfg80211_cqm_rssi_update(rdev, dev); 11766 11767 unlock: 11768 wdev_unlock(wdev); 11769 11770 return err; 11771 } 11772 11773 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 11774 { 11775 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; 11776 struct nlattr *cqm; 11777 int err; 11778 11779 cqm = info->attrs[NL80211_ATTR_CQM]; 11780 if (!cqm) 11781 return -EINVAL; 11782 11783 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, 11784 nl80211_attr_cqm_policy, 11785 info->extack); 11786 if (err) 11787 return err; 11788 11789 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && 11790 attrs[NL80211_ATTR_CQM_RSSI_HYST]) { 11791 const s32 *thresholds = 11792 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 11793 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 11794 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); 11795 11796 if (len % 4) 11797 return -EINVAL; 11798 11799 return nl80211_set_cqm_rssi(info, thresholds, len / 4, 11800 hysteresis); 11801 } 11802 11803 if (attrs[NL80211_ATTR_CQM_TXE_RATE] && 11804 attrs[NL80211_ATTR_CQM_TXE_PKTS] && 11805 attrs[NL80211_ATTR_CQM_TXE_INTVL]) { 11806 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); 11807 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); 11808 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); 11809 11810 return nl80211_set_cqm_txe(info, rate, pkts, intvl); 11811 } 11812 11813 return -EINVAL; 11814 } 11815 11816 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) 11817 { 11818 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11819 struct net_device *dev = info->user_ptr[1]; 11820 struct ocb_setup setup = {}; 11821 int err; 11822 11823 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 11824 if (err) 11825 return err; 11826 11827 return cfg80211_join_ocb(rdev, dev, &setup); 11828 } 11829 11830 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) 11831 { 11832 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11833 struct net_device *dev = info->user_ptr[1]; 11834 11835 return cfg80211_leave_ocb(rdev, dev); 11836 } 11837 11838 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 11839 { 11840 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11841 struct net_device *dev = info->user_ptr[1]; 11842 struct mesh_config cfg; 11843 struct mesh_setup setup; 11844 int err; 11845 11846 /* start with default */ 11847 memcpy(&cfg, &default_mesh_config, sizeof(cfg)); 11848 memcpy(&setup, &default_mesh_setup, sizeof(setup)); 11849 11850 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { 11851 /* and parse parameters if given */ 11852 err = nl80211_parse_mesh_config(info, &cfg, NULL); 11853 if (err) 11854 return err; 11855 } 11856 11857 if (!info->attrs[NL80211_ATTR_MESH_ID] || 11858 !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) 11859 return -EINVAL; 11860 11861 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 11862 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 11863 11864 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 11865 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, 11866 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 11867 return -EINVAL; 11868 11869 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { 11870 setup.beacon_interval = 11871 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 11872 11873 err = cfg80211_validate_beacon_int(rdev, 11874 NL80211_IFTYPE_MESH_POINT, 11875 setup.beacon_interval); 11876 if (err) 11877 return err; 11878 } 11879 11880 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 11881 setup.dtim_period = 11882 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 11883 if (setup.dtim_period < 1 || setup.dtim_period > 100) 11884 return -EINVAL; 11885 } 11886 11887 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 11888 /* parse additional setup parameters if given */ 11889 err = nl80211_parse_mesh_setup(info, &setup); 11890 if (err) 11891 return err; 11892 } 11893 11894 if (setup.user_mpm) 11895 cfg.auto_open_plinks = false; 11896 11897 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 11898 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 11899 if (err) 11900 return err; 11901 } else { 11902 /* __cfg80211_join_mesh() will sort it out */ 11903 setup.chandef.chan = NULL; 11904 } 11905 11906 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 11907 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11908 int n_rates = 11909 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11910 struct ieee80211_supported_band *sband; 11911 11912 if (!setup.chandef.chan) 11913 return -EINVAL; 11914 11915 sband = rdev->wiphy.bands[setup.chandef.chan->band]; 11916 11917 err = ieee80211_get_ratemask(sband, rates, n_rates, 11918 &setup.basic_rates); 11919 if (err) 11920 return err; 11921 } 11922 11923 if (info->attrs[NL80211_ATTR_TX_RATES]) { 11924 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 11925 NL80211_ATTR_TX_RATES, 11926 &setup.beacon_rate, 11927 dev, false); 11928 if (err) 11929 return err; 11930 11931 if (!setup.chandef.chan) 11932 return -EINVAL; 11933 11934 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, 11935 &setup.beacon_rate); 11936 if (err) 11937 return err; 11938 } 11939 11940 setup.userspace_handles_dfs = 11941 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 11942 11943 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 11944 int r = validate_pae_over_nl80211(rdev, info); 11945 11946 if (r < 0) 11947 return r; 11948 11949 setup.control_port_over_nl80211 = true; 11950 } 11951 11952 wdev_lock(dev->ieee80211_ptr); 11953 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); 11954 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) 11955 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 11956 wdev_unlock(dev->ieee80211_ptr); 11957 11958 return err; 11959 } 11960 11961 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) 11962 { 11963 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11964 struct net_device *dev = info->user_ptr[1]; 11965 11966 return cfg80211_leave_mesh(rdev, dev); 11967 } 11968 11969 #ifdef CONFIG_PM 11970 static int nl80211_send_wowlan_patterns(struct sk_buff *msg, 11971 struct cfg80211_registered_device *rdev) 11972 { 11973 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; 11974 struct nlattr *nl_pats, *nl_pat; 11975 int i, pat_len; 11976 11977 if (!wowlan->n_patterns) 11978 return 0; 11979 11980 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 11981 if (!nl_pats) 11982 return -ENOBUFS; 11983 11984 for (i = 0; i < wowlan->n_patterns; i++) { 11985 nl_pat = nla_nest_start_noflag(msg, i + 1); 11986 if (!nl_pat) 11987 return -ENOBUFS; 11988 pat_len = wowlan->patterns[i].pattern_len; 11989 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), 11990 wowlan->patterns[i].mask) || 11991 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 11992 wowlan->patterns[i].pattern) || 11993 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 11994 wowlan->patterns[i].pkt_offset)) 11995 return -ENOBUFS; 11996 nla_nest_end(msg, nl_pat); 11997 } 11998 nla_nest_end(msg, nl_pats); 11999 12000 return 0; 12001 } 12002 12003 static int nl80211_send_wowlan_tcp(struct sk_buff *msg, 12004 struct cfg80211_wowlan_tcp *tcp) 12005 { 12006 struct nlattr *nl_tcp; 12007 12008 if (!tcp) 12009 return 0; 12010 12011 nl_tcp = nla_nest_start_noflag(msg, 12012 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 12013 if (!nl_tcp) 12014 return -ENOBUFS; 12015 12016 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 12017 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 12018 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 12019 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 12020 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || 12021 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 12022 tcp->payload_len, tcp->payload) || 12023 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 12024 tcp->data_interval) || 12025 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 12026 tcp->wake_len, tcp->wake_data) || 12027 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, 12028 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) 12029 return -ENOBUFS; 12030 12031 if (tcp->payload_seq.len && 12032 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, 12033 sizeof(tcp->payload_seq), &tcp->payload_seq)) 12034 return -ENOBUFS; 12035 12036 if (tcp->payload_tok.len && 12037 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 12038 sizeof(tcp->payload_tok) + tcp->tokens_size, 12039 &tcp->payload_tok)) 12040 return -ENOBUFS; 12041 12042 nla_nest_end(msg, nl_tcp); 12043 12044 return 0; 12045 } 12046 12047 static int nl80211_send_wowlan_nd(struct sk_buff *msg, 12048 struct cfg80211_sched_scan_request *req) 12049 { 12050 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; 12051 int i; 12052 12053 if (!req) 12054 return 0; 12055 12056 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 12057 if (!nd) 12058 return -ENOBUFS; 12059 12060 if (req->n_scan_plans == 1 && 12061 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, 12062 req->scan_plans[0].interval * 1000)) 12063 return -ENOBUFS; 12064 12065 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) 12066 return -ENOBUFS; 12067 12068 if (req->relative_rssi_set) { 12069 struct nl80211_bss_select_rssi_adjust rssi_adjust; 12070 12071 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, 12072 req->relative_rssi)) 12073 return -ENOBUFS; 12074 12075 rssi_adjust.band = req->rssi_adjust.band; 12076 rssi_adjust.delta = req->rssi_adjust.delta; 12077 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, 12078 sizeof(rssi_adjust), &rssi_adjust)) 12079 return -ENOBUFS; 12080 } 12081 12082 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 12083 if (!freqs) 12084 return -ENOBUFS; 12085 12086 for (i = 0; i < req->n_channels; i++) { 12087 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 12088 return -ENOBUFS; 12089 } 12090 12091 nla_nest_end(msg, freqs); 12092 12093 if (req->n_match_sets) { 12094 matches = nla_nest_start_noflag(msg, 12095 NL80211_ATTR_SCHED_SCAN_MATCH); 12096 if (!matches) 12097 return -ENOBUFS; 12098 12099 for (i = 0; i < req->n_match_sets; i++) { 12100 match = nla_nest_start_noflag(msg, i); 12101 if (!match) 12102 return -ENOBUFS; 12103 12104 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, 12105 req->match_sets[i].ssid.ssid_len, 12106 req->match_sets[i].ssid.ssid)) 12107 return -ENOBUFS; 12108 nla_nest_end(msg, match); 12109 } 12110 nla_nest_end(msg, matches); 12111 } 12112 12113 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 12114 if (!scan_plans) 12115 return -ENOBUFS; 12116 12117 for (i = 0; i < req->n_scan_plans; i++) { 12118 scan_plan = nla_nest_start_noflag(msg, i + 1); 12119 if (!scan_plan) 12120 return -ENOBUFS; 12121 12122 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, 12123 req->scan_plans[i].interval) || 12124 (req->scan_plans[i].iterations && 12125 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, 12126 req->scan_plans[i].iterations))) 12127 return -ENOBUFS; 12128 nla_nest_end(msg, scan_plan); 12129 } 12130 nla_nest_end(msg, scan_plans); 12131 12132 nla_nest_end(msg, nd); 12133 12134 return 0; 12135 } 12136 12137 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) 12138 { 12139 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12140 struct sk_buff *msg; 12141 void *hdr; 12142 u32 size = NLMSG_DEFAULT_SIZE; 12143 12144 if (!rdev->wiphy.wowlan) 12145 return -EOPNOTSUPP; 12146 12147 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { 12148 /* adjust size to have room for all the data */ 12149 size += rdev->wiphy.wowlan_config->tcp->tokens_size + 12150 rdev->wiphy.wowlan_config->tcp->payload_len + 12151 rdev->wiphy.wowlan_config->tcp->wake_len + 12152 rdev->wiphy.wowlan_config->tcp->wake_len / 8; 12153 } 12154 12155 msg = nlmsg_new(size, GFP_KERNEL); 12156 if (!msg) 12157 return -ENOMEM; 12158 12159 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12160 NL80211_CMD_GET_WOWLAN); 12161 if (!hdr) 12162 goto nla_put_failure; 12163 12164 if (rdev->wiphy.wowlan_config) { 12165 struct nlattr *nl_wowlan; 12166 12167 nl_wowlan = nla_nest_start_noflag(msg, 12168 NL80211_ATTR_WOWLAN_TRIGGERS); 12169 if (!nl_wowlan) 12170 goto nla_put_failure; 12171 12172 if ((rdev->wiphy.wowlan_config->any && 12173 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 12174 (rdev->wiphy.wowlan_config->disconnect && 12175 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 12176 (rdev->wiphy.wowlan_config->magic_pkt && 12177 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 12178 (rdev->wiphy.wowlan_config->gtk_rekey_failure && 12179 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 12180 (rdev->wiphy.wowlan_config->eap_identity_req && 12181 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 12182 (rdev->wiphy.wowlan_config->four_way_handshake && 12183 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 12184 (rdev->wiphy.wowlan_config->rfkill_release && 12185 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 12186 goto nla_put_failure; 12187 12188 if (nl80211_send_wowlan_patterns(msg, rdev)) 12189 goto nla_put_failure; 12190 12191 if (nl80211_send_wowlan_tcp(msg, 12192 rdev->wiphy.wowlan_config->tcp)) 12193 goto nla_put_failure; 12194 12195 if (nl80211_send_wowlan_nd( 12196 msg, 12197 rdev->wiphy.wowlan_config->nd_config)) 12198 goto nla_put_failure; 12199 12200 nla_nest_end(msg, nl_wowlan); 12201 } 12202 12203 genlmsg_end(msg, hdr); 12204 return genlmsg_reply(msg, info); 12205 12206 nla_put_failure: 12207 nlmsg_free(msg); 12208 return -ENOBUFS; 12209 } 12210 12211 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, 12212 struct nlattr *attr, 12213 struct cfg80211_wowlan *trig) 12214 { 12215 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; 12216 struct cfg80211_wowlan_tcp *cfg; 12217 struct nl80211_wowlan_tcp_data_token *tok = NULL; 12218 struct nl80211_wowlan_tcp_data_seq *seq = NULL; 12219 u32 size; 12220 u32 data_size, wake_size, tokens_size = 0, wake_mask_size; 12221 int err, port; 12222 12223 if (!rdev->wiphy.wowlan->tcp) 12224 return -EINVAL; 12225 12226 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, 12227 nl80211_wowlan_tcp_policy, NULL); 12228 if (err) 12229 return err; 12230 12231 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || 12232 !tb[NL80211_WOWLAN_TCP_DST_IPV4] || 12233 !tb[NL80211_WOWLAN_TCP_DST_MAC] || 12234 !tb[NL80211_WOWLAN_TCP_DST_PORT] || 12235 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || 12236 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || 12237 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || 12238 !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) 12239 return -EINVAL; 12240 12241 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); 12242 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) 12243 return -EINVAL; 12244 12245 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > 12246 rdev->wiphy.wowlan->tcp->data_interval_max || 12247 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) 12248 return -EINVAL; 12249 12250 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); 12251 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) 12252 return -EINVAL; 12253 12254 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); 12255 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) 12256 return -EINVAL; 12257 12258 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { 12259 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 12260 12261 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 12262 tokens_size = tokln - sizeof(*tok); 12263 12264 if (!tok->len || tokens_size % tok->len) 12265 return -EINVAL; 12266 if (!rdev->wiphy.wowlan->tcp->tok) 12267 return -EINVAL; 12268 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) 12269 return -EINVAL; 12270 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) 12271 return -EINVAL; 12272 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) 12273 return -EINVAL; 12274 if (tok->offset + tok->len > data_size) 12275 return -EINVAL; 12276 } 12277 12278 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { 12279 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); 12280 if (!rdev->wiphy.wowlan->tcp->seq) 12281 return -EINVAL; 12282 if (seq->len == 0 || seq->len > 4) 12283 return -EINVAL; 12284 if (seq->len + seq->offset > data_size) 12285 return -EINVAL; 12286 } 12287 12288 size = sizeof(*cfg); 12289 size += data_size; 12290 size += wake_size + wake_mask_size; 12291 size += tokens_size; 12292 12293 cfg = kzalloc(size, GFP_KERNEL); 12294 if (!cfg) 12295 return -ENOMEM; 12296 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); 12297 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 12298 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 12299 ETH_ALEN); 12300 if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 12301 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 12302 else 12303 port = 0; 12304 #ifdef CONFIG_INET 12305 /* allocate a socket and port for it and use it */ 12306 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, 12307 IPPROTO_TCP, &cfg->sock, 1); 12308 if (err) { 12309 kfree(cfg); 12310 return err; 12311 } 12312 if (inet_csk_get_port(cfg->sock->sk, port)) { 12313 sock_release(cfg->sock); 12314 kfree(cfg); 12315 return -EADDRINUSE; 12316 } 12317 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; 12318 #else 12319 if (!port) { 12320 kfree(cfg); 12321 return -EINVAL; 12322 } 12323 cfg->src_port = port; 12324 #endif 12325 12326 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); 12327 cfg->payload_len = data_size; 12328 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; 12329 memcpy((void *)cfg->payload, 12330 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), 12331 data_size); 12332 if (seq) 12333 cfg->payload_seq = *seq; 12334 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); 12335 cfg->wake_len = wake_size; 12336 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; 12337 memcpy((void *)cfg->wake_data, 12338 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), 12339 wake_size); 12340 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + 12341 data_size + wake_size; 12342 memcpy((void *)cfg->wake_mask, 12343 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), 12344 wake_mask_size); 12345 if (tok) { 12346 cfg->tokens_size = tokens_size; 12347 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); 12348 } 12349 12350 trig->tcp = cfg; 12351 12352 return 0; 12353 } 12354 12355 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, 12356 const struct wiphy_wowlan_support *wowlan, 12357 struct nlattr *attr, 12358 struct cfg80211_wowlan *trig) 12359 { 12360 struct nlattr **tb; 12361 int err; 12362 12363 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 12364 if (!tb) 12365 return -ENOMEM; 12366 12367 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { 12368 err = -EOPNOTSUPP; 12369 goto out; 12370 } 12371 12372 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, 12373 nl80211_policy, NULL); 12374 if (err) 12375 goto out; 12376 12377 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, 12378 wowlan->max_nd_match_sets); 12379 err = PTR_ERR_OR_ZERO(trig->nd_config); 12380 if (err) 12381 trig->nd_config = NULL; 12382 12383 out: 12384 kfree(tb); 12385 return err; 12386 } 12387 12388 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) 12389 { 12390 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12391 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; 12392 struct cfg80211_wowlan new_triggers = {}; 12393 struct cfg80211_wowlan *ntrig; 12394 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; 12395 int err, i; 12396 bool prev_enabled = rdev->wiphy.wowlan_config; 12397 bool regular = false; 12398 12399 if (!wowlan) 12400 return -EOPNOTSUPP; 12401 12402 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { 12403 cfg80211_rdev_free_wowlan(rdev); 12404 rdev->wiphy.wowlan_config = NULL; 12405 goto set_wakeup; 12406 } 12407 12408 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, 12409 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 12410 nl80211_wowlan_policy, info->extack); 12411 if (err) 12412 return err; 12413 12414 if (tb[NL80211_WOWLAN_TRIG_ANY]) { 12415 if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) 12416 return -EINVAL; 12417 new_triggers.any = true; 12418 } 12419 12420 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { 12421 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) 12422 return -EINVAL; 12423 new_triggers.disconnect = true; 12424 regular = true; 12425 } 12426 12427 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { 12428 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) 12429 return -EINVAL; 12430 new_triggers.magic_pkt = true; 12431 regular = true; 12432 } 12433 12434 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) 12435 return -EINVAL; 12436 12437 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { 12438 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) 12439 return -EINVAL; 12440 new_triggers.gtk_rekey_failure = true; 12441 regular = true; 12442 } 12443 12444 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { 12445 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) 12446 return -EINVAL; 12447 new_triggers.eap_identity_req = true; 12448 regular = true; 12449 } 12450 12451 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { 12452 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) 12453 return -EINVAL; 12454 new_triggers.four_way_handshake = true; 12455 regular = true; 12456 } 12457 12458 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { 12459 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) 12460 return -EINVAL; 12461 new_triggers.rfkill_release = true; 12462 regular = true; 12463 } 12464 12465 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { 12466 struct nlattr *pat; 12467 int n_patterns = 0; 12468 int rem, pat_len, mask_len, pkt_offset; 12469 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 12470 12471 regular = true; 12472 12473 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 12474 rem) 12475 n_patterns++; 12476 if (n_patterns > wowlan->n_patterns) 12477 return -EINVAL; 12478 12479 new_triggers.patterns = kcalloc(n_patterns, 12480 sizeof(new_triggers.patterns[0]), 12481 GFP_KERNEL); 12482 if (!new_triggers.patterns) 12483 return -ENOMEM; 12484 12485 new_triggers.n_patterns = n_patterns; 12486 i = 0; 12487 12488 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 12489 rem) { 12490 u8 *mask_pat; 12491 12492 err = nla_parse_nested_deprecated(pat_tb, 12493 MAX_NL80211_PKTPAT, 12494 pat, 12495 nl80211_packet_pattern_policy, 12496 info->extack); 12497 if (err) 12498 goto error; 12499 12500 err = -EINVAL; 12501 if (!pat_tb[NL80211_PKTPAT_MASK] || 12502 !pat_tb[NL80211_PKTPAT_PATTERN]) 12503 goto error; 12504 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 12505 mask_len = DIV_ROUND_UP(pat_len, 8); 12506 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 12507 goto error; 12508 if (pat_len > wowlan->pattern_max_len || 12509 pat_len < wowlan->pattern_min_len) 12510 goto error; 12511 12512 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 12513 pkt_offset = 0; 12514 else 12515 pkt_offset = nla_get_u32( 12516 pat_tb[NL80211_PKTPAT_OFFSET]); 12517 if (pkt_offset > wowlan->max_pkt_offset) 12518 goto error; 12519 new_triggers.patterns[i].pkt_offset = pkt_offset; 12520 12521 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 12522 if (!mask_pat) { 12523 err = -ENOMEM; 12524 goto error; 12525 } 12526 new_triggers.patterns[i].mask = mask_pat; 12527 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 12528 mask_len); 12529 mask_pat += mask_len; 12530 new_triggers.patterns[i].pattern = mask_pat; 12531 new_triggers.patterns[i].pattern_len = pat_len; 12532 memcpy(mask_pat, 12533 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 12534 pat_len); 12535 i++; 12536 } 12537 } 12538 12539 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { 12540 regular = true; 12541 err = nl80211_parse_wowlan_tcp( 12542 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], 12543 &new_triggers); 12544 if (err) 12545 goto error; 12546 } 12547 12548 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { 12549 regular = true; 12550 err = nl80211_parse_wowlan_nd( 12551 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], 12552 &new_triggers); 12553 if (err) 12554 goto error; 12555 } 12556 12557 /* The 'any' trigger means the device continues operating more or less 12558 * as in its normal operation mode and wakes up the host on most of the 12559 * normal interrupts (like packet RX, ...) 12560 * It therefore makes little sense to combine with the more constrained 12561 * wakeup trigger modes. 12562 */ 12563 if (new_triggers.any && regular) { 12564 err = -EINVAL; 12565 goto error; 12566 } 12567 12568 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); 12569 if (!ntrig) { 12570 err = -ENOMEM; 12571 goto error; 12572 } 12573 cfg80211_rdev_free_wowlan(rdev); 12574 rdev->wiphy.wowlan_config = ntrig; 12575 12576 set_wakeup: 12577 if (rdev->ops->set_wakeup && 12578 prev_enabled != !!rdev->wiphy.wowlan_config) 12579 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); 12580 12581 return 0; 12582 error: 12583 for (i = 0; i < new_triggers.n_patterns; i++) 12584 kfree(new_triggers.patterns[i].mask); 12585 kfree(new_triggers.patterns); 12586 if (new_triggers.tcp && new_triggers.tcp->sock) 12587 sock_release(new_triggers.tcp->sock); 12588 kfree(new_triggers.tcp); 12589 kfree(new_triggers.nd_config); 12590 return err; 12591 } 12592 #endif 12593 12594 static int nl80211_send_coalesce_rules(struct sk_buff *msg, 12595 struct cfg80211_registered_device *rdev) 12596 { 12597 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; 12598 int i, j, pat_len; 12599 struct cfg80211_coalesce_rules *rule; 12600 12601 if (!rdev->coalesce->n_rules) 12602 return 0; 12603 12604 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); 12605 if (!nl_rules) 12606 return -ENOBUFS; 12607 12608 for (i = 0; i < rdev->coalesce->n_rules; i++) { 12609 nl_rule = nla_nest_start_noflag(msg, i + 1); 12610 if (!nl_rule) 12611 return -ENOBUFS; 12612 12613 rule = &rdev->coalesce->rules[i]; 12614 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, 12615 rule->delay)) 12616 return -ENOBUFS; 12617 12618 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, 12619 rule->condition)) 12620 return -ENOBUFS; 12621 12622 nl_pats = nla_nest_start_noflag(msg, 12623 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 12624 if (!nl_pats) 12625 return -ENOBUFS; 12626 12627 for (j = 0; j < rule->n_patterns; j++) { 12628 nl_pat = nla_nest_start_noflag(msg, j + 1); 12629 if (!nl_pat) 12630 return -ENOBUFS; 12631 pat_len = rule->patterns[j].pattern_len; 12632 if (nla_put(msg, NL80211_PKTPAT_MASK, 12633 DIV_ROUND_UP(pat_len, 8), 12634 rule->patterns[j].mask) || 12635 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 12636 rule->patterns[j].pattern) || 12637 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 12638 rule->patterns[j].pkt_offset)) 12639 return -ENOBUFS; 12640 nla_nest_end(msg, nl_pat); 12641 } 12642 nla_nest_end(msg, nl_pats); 12643 nla_nest_end(msg, nl_rule); 12644 } 12645 nla_nest_end(msg, nl_rules); 12646 12647 return 0; 12648 } 12649 12650 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) 12651 { 12652 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12653 struct sk_buff *msg; 12654 void *hdr; 12655 12656 if (!rdev->wiphy.coalesce) 12657 return -EOPNOTSUPP; 12658 12659 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12660 if (!msg) 12661 return -ENOMEM; 12662 12663 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12664 NL80211_CMD_GET_COALESCE); 12665 if (!hdr) 12666 goto nla_put_failure; 12667 12668 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) 12669 goto nla_put_failure; 12670 12671 genlmsg_end(msg, hdr); 12672 return genlmsg_reply(msg, info); 12673 12674 nla_put_failure: 12675 nlmsg_free(msg); 12676 return -ENOBUFS; 12677 } 12678 12679 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) 12680 { 12681 struct cfg80211_coalesce *coalesce = rdev->coalesce; 12682 int i, j; 12683 struct cfg80211_coalesce_rules *rule; 12684 12685 if (!coalesce) 12686 return; 12687 12688 for (i = 0; i < coalesce->n_rules; i++) { 12689 rule = &coalesce->rules[i]; 12690 for (j = 0; j < rule->n_patterns; j++) 12691 kfree(rule->patterns[j].mask); 12692 kfree(rule->patterns); 12693 } 12694 kfree(coalesce->rules); 12695 kfree(coalesce); 12696 rdev->coalesce = NULL; 12697 } 12698 12699 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, 12700 struct nlattr *rule, 12701 struct cfg80211_coalesce_rules *new_rule) 12702 { 12703 int err, i; 12704 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 12705 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; 12706 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 12707 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 12708 12709 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, 12710 rule, nl80211_coalesce_policy, NULL); 12711 if (err) 12712 return err; 12713 12714 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) 12715 new_rule->delay = 12716 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); 12717 if (new_rule->delay > coalesce->max_delay) 12718 return -EINVAL; 12719 12720 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) 12721 new_rule->condition = 12722 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); 12723 12724 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) 12725 return -EINVAL; 12726 12727 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 12728 rem) 12729 n_patterns++; 12730 if (n_patterns > coalesce->n_patterns) 12731 return -EINVAL; 12732 12733 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), 12734 GFP_KERNEL); 12735 if (!new_rule->patterns) 12736 return -ENOMEM; 12737 12738 new_rule->n_patterns = n_patterns; 12739 i = 0; 12740 12741 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 12742 rem) { 12743 u8 *mask_pat; 12744 12745 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, 12746 pat, 12747 nl80211_packet_pattern_policy, 12748 NULL); 12749 if (err) 12750 return err; 12751 12752 if (!pat_tb[NL80211_PKTPAT_MASK] || 12753 !pat_tb[NL80211_PKTPAT_PATTERN]) 12754 return -EINVAL; 12755 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 12756 mask_len = DIV_ROUND_UP(pat_len, 8); 12757 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 12758 return -EINVAL; 12759 if (pat_len > coalesce->pattern_max_len || 12760 pat_len < coalesce->pattern_min_len) 12761 return -EINVAL; 12762 12763 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 12764 pkt_offset = 0; 12765 else 12766 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 12767 if (pkt_offset > coalesce->max_pkt_offset) 12768 return -EINVAL; 12769 new_rule->patterns[i].pkt_offset = pkt_offset; 12770 12771 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 12772 if (!mask_pat) 12773 return -ENOMEM; 12774 12775 new_rule->patterns[i].mask = mask_pat; 12776 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 12777 mask_len); 12778 12779 mask_pat += mask_len; 12780 new_rule->patterns[i].pattern = mask_pat; 12781 new_rule->patterns[i].pattern_len = pat_len; 12782 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 12783 pat_len); 12784 i++; 12785 } 12786 12787 return 0; 12788 } 12789 12790 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) 12791 { 12792 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12793 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 12794 struct cfg80211_coalesce new_coalesce = {}; 12795 struct cfg80211_coalesce *n_coalesce; 12796 int err, rem_rule, n_rules = 0, i, j; 12797 struct nlattr *rule; 12798 struct cfg80211_coalesce_rules *tmp_rule; 12799 12800 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) 12801 return -EOPNOTSUPP; 12802 12803 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { 12804 cfg80211_rdev_free_coalesce(rdev); 12805 rdev_set_coalesce(rdev, NULL); 12806 return 0; 12807 } 12808 12809 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 12810 rem_rule) 12811 n_rules++; 12812 if (n_rules > coalesce->n_rules) 12813 return -EINVAL; 12814 12815 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), 12816 GFP_KERNEL); 12817 if (!new_coalesce.rules) 12818 return -ENOMEM; 12819 12820 new_coalesce.n_rules = n_rules; 12821 i = 0; 12822 12823 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 12824 rem_rule) { 12825 err = nl80211_parse_coalesce_rule(rdev, rule, 12826 &new_coalesce.rules[i]); 12827 if (err) 12828 goto error; 12829 12830 i++; 12831 } 12832 12833 err = rdev_set_coalesce(rdev, &new_coalesce); 12834 if (err) 12835 goto error; 12836 12837 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); 12838 if (!n_coalesce) { 12839 err = -ENOMEM; 12840 goto error; 12841 } 12842 cfg80211_rdev_free_coalesce(rdev); 12843 rdev->coalesce = n_coalesce; 12844 12845 return 0; 12846 error: 12847 for (i = 0; i < new_coalesce.n_rules; i++) { 12848 tmp_rule = &new_coalesce.rules[i]; 12849 for (j = 0; j < tmp_rule->n_patterns; j++) 12850 kfree(tmp_rule->patterns[j].mask); 12851 kfree(tmp_rule->patterns); 12852 } 12853 kfree(new_coalesce.rules); 12854 12855 return err; 12856 } 12857 12858 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) 12859 { 12860 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12861 struct net_device *dev = info->user_ptr[1]; 12862 struct wireless_dev *wdev = dev->ieee80211_ptr; 12863 struct nlattr *tb[NUM_NL80211_REKEY_DATA]; 12864 struct cfg80211_gtk_rekey_data rekey_data = {}; 12865 int err; 12866 12867 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 12868 return -EINVAL; 12869 12870 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, 12871 info->attrs[NL80211_ATTR_REKEY_DATA], 12872 nl80211_rekey_policy, info->extack); 12873 if (err) 12874 return err; 12875 12876 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || 12877 !tb[NL80211_REKEY_DATA_KCK]) 12878 return -EINVAL; 12879 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && 12880 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 12881 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) 12882 return -ERANGE; 12883 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && 12884 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 12885 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) 12886 return -ERANGE; 12887 12888 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); 12889 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); 12890 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); 12891 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); 12892 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); 12893 if (tb[NL80211_REKEY_DATA_AKM]) 12894 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); 12895 12896 wdev_lock(wdev); 12897 if (!wdev->current_bss) { 12898 err = -ENOTCONN; 12899 goto out; 12900 } 12901 12902 if (!rdev->ops->set_rekey_data) { 12903 err = -EOPNOTSUPP; 12904 goto out; 12905 } 12906 12907 err = rdev_set_rekey_data(rdev, dev, &rekey_data); 12908 out: 12909 wdev_unlock(wdev); 12910 return err; 12911 } 12912 12913 static int nl80211_register_unexpected_frame(struct sk_buff *skb, 12914 struct genl_info *info) 12915 { 12916 struct net_device *dev = info->user_ptr[1]; 12917 struct wireless_dev *wdev = dev->ieee80211_ptr; 12918 12919 if (wdev->iftype != NL80211_IFTYPE_AP && 12920 wdev->iftype != NL80211_IFTYPE_P2P_GO) 12921 return -EINVAL; 12922 12923 if (wdev->ap_unexpected_nlportid) 12924 return -EBUSY; 12925 12926 wdev->ap_unexpected_nlportid = info->snd_portid; 12927 return 0; 12928 } 12929 12930 static int nl80211_probe_client(struct sk_buff *skb, 12931 struct genl_info *info) 12932 { 12933 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12934 struct net_device *dev = info->user_ptr[1]; 12935 struct wireless_dev *wdev = dev->ieee80211_ptr; 12936 struct sk_buff *msg; 12937 void *hdr; 12938 const u8 *addr; 12939 u64 cookie; 12940 int err; 12941 12942 if (wdev->iftype != NL80211_IFTYPE_AP && 12943 wdev->iftype != NL80211_IFTYPE_P2P_GO) 12944 return -EOPNOTSUPP; 12945 12946 if (!info->attrs[NL80211_ATTR_MAC]) 12947 return -EINVAL; 12948 12949 if (!rdev->ops->probe_client) 12950 return -EOPNOTSUPP; 12951 12952 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12953 if (!msg) 12954 return -ENOMEM; 12955 12956 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12957 NL80211_CMD_PROBE_CLIENT); 12958 if (!hdr) { 12959 err = -ENOBUFS; 12960 goto free_msg; 12961 } 12962 12963 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 12964 12965 err = rdev_probe_client(rdev, dev, addr, &cookie); 12966 if (err) 12967 goto free_msg; 12968 12969 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12970 NL80211_ATTR_PAD)) 12971 goto nla_put_failure; 12972 12973 genlmsg_end(msg, hdr); 12974 12975 return genlmsg_reply(msg, info); 12976 12977 nla_put_failure: 12978 err = -ENOBUFS; 12979 free_msg: 12980 nlmsg_free(msg); 12981 return err; 12982 } 12983 12984 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) 12985 { 12986 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12987 struct cfg80211_beacon_registration *reg, *nreg; 12988 int rv; 12989 12990 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) 12991 return -EOPNOTSUPP; 12992 12993 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); 12994 if (!nreg) 12995 return -ENOMEM; 12996 12997 /* First, check if already registered. */ 12998 spin_lock_bh(&rdev->beacon_registrations_lock); 12999 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 13000 if (reg->nlportid == info->snd_portid) { 13001 rv = -EALREADY; 13002 goto out_err; 13003 } 13004 } 13005 /* Add it to the list */ 13006 nreg->nlportid = info->snd_portid; 13007 list_add(&nreg->list, &rdev->beacon_registrations); 13008 13009 spin_unlock_bh(&rdev->beacon_registrations_lock); 13010 13011 return 0; 13012 out_err: 13013 spin_unlock_bh(&rdev->beacon_registrations_lock); 13014 kfree(nreg); 13015 return rv; 13016 } 13017 13018 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) 13019 { 13020 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13021 struct wireless_dev *wdev = info->user_ptr[1]; 13022 int err; 13023 13024 if (!rdev->ops->start_p2p_device) 13025 return -EOPNOTSUPP; 13026 13027 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 13028 return -EOPNOTSUPP; 13029 13030 if (wdev_running(wdev)) 13031 return 0; 13032 13033 if (rfkill_blocked(rdev->rfkill)) 13034 return -ERFKILL; 13035 13036 err = rdev_start_p2p_device(rdev, wdev); 13037 if (err) 13038 return err; 13039 13040 wdev->is_running = true; 13041 rdev->opencount++; 13042 13043 return 0; 13044 } 13045 13046 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) 13047 { 13048 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13049 struct wireless_dev *wdev = info->user_ptr[1]; 13050 13051 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 13052 return -EOPNOTSUPP; 13053 13054 if (!rdev->ops->stop_p2p_device) 13055 return -EOPNOTSUPP; 13056 13057 cfg80211_stop_p2p_device(rdev, wdev); 13058 13059 return 0; 13060 } 13061 13062 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) 13063 { 13064 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13065 struct wireless_dev *wdev = info->user_ptr[1]; 13066 struct cfg80211_nan_conf conf = {}; 13067 int err; 13068 13069 if (wdev->iftype != NL80211_IFTYPE_NAN) 13070 return -EOPNOTSUPP; 13071 13072 if (wdev_running(wdev)) 13073 return -EEXIST; 13074 13075 if (rfkill_blocked(rdev->rfkill)) 13076 return -ERFKILL; 13077 13078 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) 13079 return -EINVAL; 13080 13081 conf.master_pref = 13082 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 13083 13084 if (info->attrs[NL80211_ATTR_BANDS]) { 13085 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 13086 13087 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 13088 return -EOPNOTSUPP; 13089 13090 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 13091 return -EINVAL; 13092 13093 conf.bands = bands; 13094 } 13095 13096 err = rdev_start_nan(rdev, wdev, &conf); 13097 if (err) 13098 return err; 13099 13100 wdev->is_running = true; 13101 rdev->opencount++; 13102 13103 return 0; 13104 } 13105 13106 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) 13107 { 13108 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13109 struct wireless_dev *wdev = info->user_ptr[1]; 13110 13111 if (wdev->iftype != NL80211_IFTYPE_NAN) 13112 return -EOPNOTSUPP; 13113 13114 cfg80211_stop_nan(rdev, wdev); 13115 13116 return 0; 13117 } 13118 13119 static int validate_nan_filter(struct nlattr *filter_attr) 13120 { 13121 struct nlattr *attr; 13122 int len = 0, n_entries = 0, rem; 13123 13124 nla_for_each_nested(attr, filter_attr, rem) { 13125 len += nla_len(attr); 13126 n_entries++; 13127 } 13128 13129 if (len >= U8_MAX) 13130 return -EINVAL; 13131 13132 return n_entries; 13133 } 13134 13135 static int handle_nan_filter(struct nlattr *attr_filter, 13136 struct cfg80211_nan_func *func, 13137 bool tx) 13138 { 13139 struct nlattr *attr; 13140 int n_entries, rem, i; 13141 struct cfg80211_nan_func_filter *filter; 13142 13143 n_entries = validate_nan_filter(attr_filter); 13144 if (n_entries < 0) 13145 return n_entries; 13146 13147 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); 13148 13149 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); 13150 if (!filter) 13151 return -ENOMEM; 13152 13153 i = 0; 13154 nla_for_each_nested(attr, attr_filter, rem) { 13155 filter[i].filter = nla_memdup(attr, GFP_KERNEL); 13156 filter[i].len = nla_len(attr); 13157 i++; 13158 } 13159 if (tx) { 13160 func->num_tx_filters = n_entries; 13161 func->tx_filters = filter; 13162 } else { 13163 func->num_rx_filters = n_entries; 13164 func->rx_filters = filter; 13165 } 13166 13167 return 0; 13168 } 13169 13170 static int nl80211_nan_add_func(struct sk_buff *skb, 13171 struct genl_info *info) 13172 { 13173 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13174 struct wireless_dev *wdev = info->user_ptr[1]; 13175 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; 13176 struct cfg80211_nan_func *func; 13177 struct sk_buff *msg = NULL; 13178 void *hdr = NULL; 13179 int err = 0; 13180 13181 if (wdev->iftype != NL80211_IFTYPE_NAN) 13182 return -EOPNOTSUPP; 13183 13184 if (!wdev_running(wdev)) 13185 return -ENOTCONN; 13186 13187 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 13188 return -EINVAL; 13189 13190 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, 13191 info->attrs[NL80211_ATTR_NAN_FUNC], 13192 nl80211_nan_func_policy, 13193 info->extack); 13194 if (err) 13195 return err; 13196 13197 func = kzalloc(sizeof(*func), GFP_KERNEL); 13198 if (!func) 13199 return -ENOMEM; 13200 13201 func->cookie = cfg80211_assign_cookie(rdev); 13202 13203 if (!tb[NL80211_NAN_FUNC_TYPE]) { 13204 err = -EINVAL; 13205 goto out; 13206 } 13207 13208 13209 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); 13210 13211 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { 13212 err = -EINVAL; 13213 goto out; 13214 } 13215 13216 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), 13217 sizeof(func->service_id)); 13218 13219 func->close_range = 13220 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); 13221 13222 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { 13223 func->serv_spec_info_len = 13224 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); 13225 func->serv_spec_info = 13226 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), 13227 func->serv_spec_info_len, 13228 GFP_KERNEL); 13229 if (!func->serv_spec_info) { 13230 err = -ENOMEM; 13231 goto out; 13232 } 13233 } 13234 13235 if (tb[NL80211_NAN_FUNC_TTL]) 13236 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); 13237 13238 switch (func->type) { 13239 case NL80211_NAN_FUNC_PUBLISH: 13240 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { 13241 err = -EINVAL; 13242 goto out; 13243 } 13244 13245 func->publish_type = 13246 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); 13247 func->publish_bcast = 13248 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); 13249 13250 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && 13251 func->publish_bcast) { 13252 err = -EINVAL; 13253 goto out; 13254 } 13255 break; 13256 case NL80211_NAN_FUNC_SUBSCRIBE: 13257 func->subscribe_active = 13258 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); 13259 break; 13260 case NL80211_NAN_FUNC_FOLLOW_UP: 13261 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || 13262 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || 13263 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { 13264 err = -EINVAL; 13265 goto out; 13266 } 13267 13268 func->followup_id = 13269 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); 13270 func->followup_reqid = 13271 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); 13272 memcpy(func->followup_dest.addr, 13273 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), 13274 sizeof(func->followup_dest.addr)); 13275 if (func->ttl) { 13276 err = -EINVAL; 13277 goto out; 13278 } 13279 break; 13280 default: 13281 err = -EINVAL; 13282 goto out; 13283 } 13284 13285 if (tb[NL80211_NAN_FUNC_SRF]) { 13286 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 13287 13288 err = nla_parse_nested_deprecated(srf_tb, 13289 NL80211_NAN_SRF_ATTR_MAX, 13290 tb[NL80211_NAN_FUNC_SRF], 13291 nl80211_nan_srf_policy, 13292 info->extack); 13293 if (err) 13294 goto out; 13295 13296 func->srf_include = 13297 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); 13298 13299 if (srf_tb[NL80211_NAN_SRF_BF]) { 13300 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || 13301 !srf_tb[NL80211_NAN_SRF_BF_IDX]) { 13302 err = -EINVAL; 13303 goto out; 13304 } 13305 13306 func->srf_bf_len = 13307 nla_len(srf_tb[NL80211_NAN_SRF_BF]); 13308 func->srf_bf = 13309 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), 13310 func->srf_bf_len, GFP_KERNEL); 13311 if (!func->srf_bf) { 13312 err = -ENOMEM; 13313 goto out; 13314 } 13315 13316 func->srf_bf_idx = 13317 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); 13318 } else { 13319 struct nlattr *attr, *mac_attr = 13320 srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; 13321 int n_entries, rem, i = 0; 13322 13323 if (!mac_attr) { 13324 err = -EINVAL; 13325 goto out; 13326 } 13327 13328 n_entries = validate_acl_mac_addrs(mac_attr); 13329 if (n_entries <= 0) { 13330 err = -EINVAL; 13331 goto out; 13332 } 13333 13334 func->srf_num_macs = n_entries; 13335 func->srf_macs = 13336 kcalloc(n_entries, sizeof(*func->srf_macs), 13337 GFP_KERNEL); 13338 if (!func->srf_macs) { 13339 err = -ENOMEM; 13340 goto out; 13341 } 13342 13343 nla_for_each_nested(attr, mac_attr, rem) 13344 memcpy(func->srf_macs[i++].addr, nla_data(attr), 13345 sizeof(*func->srf_macs)); 13346 } 13347 } 13348 13349 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { 13350 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], 13351 func, true); 13352 if (err) 13353 goto out; 13354 } 13355 13356 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { 13357 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], 13358 func, false); 13359 if (err) 13360 goto out; 13361 } 13362 13363 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13364 if (!msg) { 13365 err = -ENOMEM; 13366 goto out; 13367 } 13368 13369 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13370 NL80211_CMD_ADD_NAN_FUNCTION); 13371 /* This can't really happen - we just allocated 4KB */ 13372 if (WARN_ON(!hdr)) { 13373 err = -ENOMEM; 13374 goto out; 13375 } 13376 13377 err = rdev_add_nan_func(rdev, wdev, func); 13378 out: 13379 if (err < 0) { 13380 cfg80211_free_nan_func(func); 13381 nlmsg_free(msg); 13382 return err; 13383 } 13384 13385 /* propagate the instance id and cookie to userspace */ 13386 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, 13387 NL80211_ATTR_PAD)) 13388 goto nla_put_failure; 13389 13390 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 13391 if (!func_attr) 13392 goto nla_put_failure; 13393 13394 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, 13395 func->instance_id)) 13396 goto nla_put_failure; 13397 13398 nla_nest_end(msg, func_attr); 13399 13400 genlmsg_end(msg, hdr); 13401 return genlmsg_reply(msg, info); 13402 13403 nla_put_failure: 13404 nlmsg_free(msg); 13405 return -ENOBUFS; 13406 } 13407 13408 static int nl80211_nan_del_func(struct sk_buff *skb, 13409 struct genl_info *info) 13410 { 13411 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13412 struct wireless_dev *wdev = info->user_ptr[1]; 13413 u64 cookie; 13414 13415 if (wdev->iftype != NL80211_IFTYPE_NAN) 13416 return -EOPNOTSUPP; 13417 13418 if (!wdev_running(wdev)) 13419 return -ENOTCONN; 13420 13421 if (!info->attrs[NL80211_ATTR_COOKIE]) 13422 return -EINVAL; 13423 13424 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 13425 13426 rdev_del_nan_func(rdev, wdev, cookie); 13427 13428 return 0; 13429 } 13430 13431 static int nl80211_nan_change_config(struct sk_buff *skb, 13432 struct genl_info *info) 13433 { 13434 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13435 struct wireless_dev *wdev = info->user_ptr[1]; 13436 struct cfg80211_nan_conf conf = {}; 13437 u32 changed = 0; 13438 13439 if (wdev->iftype != NL80211_IFTYPE_NAN) 13440 return -EOPNOTSUPP; 13441 13442 if (!wdev_running(wdev)) 13443 return -ENOTCONN; 13444 13445 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { 13446 conf.master_pref = 13447 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 13448 if (conf.master_pref <= 1 || conf.master_pref == 255) 13449 return -EINVAL; 13450 13451 changed |= CFG80211_NAN_CONF_CHANGED_PREF; 13452 } 13453 13454 if (info->attrs[NL80211_ATTR_BANDS]) { 13455 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 13456 13457 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 13458 return -EOPNOTSUPP; 13459 13460 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 13461 return -EINVAL; 13462 13463 conf.bands = bands; 13464 changed |= CFG80211_NAN_CONF_CHANGED_BANDS; 13465 } 13466 13467 if (!changed) 13468 return -EINVAL; 13469 13470 return rdev_nan_change_conf(rdev, wdev, &conf, changed); 13471 } 13472 13473 void cfg80211_nan_match(struct wireless_dev *wdev, 13474 struct cfg80211_nan_match_params *match, gfp_t gfp) 13475 { 13476 struct wiphy *wiphy = wdev->wiphy; 13477 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 13478 struct nlattr *match_attr, *local_func_attr, *peer_func_attr; 13479 struct sk_buff *msg; 13480 void *hdr; 13481 13482 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) 13483 return; 13484 13485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 13486 if (!msg) 13487 return; 13488 13489 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); 13490 if (!hdr) { 13491 nlmsg_free(msg); 13492 return; 13493 } 13494 13495 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 13496 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 13497 wdev->netdev->ifindex)) || 13498 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 13499 NL80211_ATTR_PAD)) 13500 goto nla_put_failure; 13501 13502 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, 13503 NL80211_ATTR_PAD) || 13504 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 13505 goto nla_put_failure; 13506 13507 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); 13508 if (!match_attr) 13509 goto nla_put_failure; 13510 13511 local_func_attr = nla_nest_start_noflag(msg, 13512 NL80211_NAN_MATCH_FUNC_LOCAL); 13513 if (!local_func_attr) 13514 goto nla_put_failure; 13515 13516 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) 13517 goto nla_put_failure; 13518 13519 nla_nest_end(msg, local_func_attr); 13520 13521 peer_func_attr = nla_nest_start_noflag(msg, 13522 NL80211_NAN_MATCH_FUNC_PEER); 13523 if (!peer_func_attr) 13524 goto nla_put_failure; 13525 13526 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || 13527 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) 13528 goto nla_put_failure; 13529 13530 if (match->info && match->info_len && 13531 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, 13532 match->info)) 13533 goto nla_put_failure; 13534 13535 nla_nest_end(msg, peer_func_attr); 13536 nla_nest_end(msg, match_attr); 13537 genlmsg_end(msg, hdr); 13538 13539 if (!wdev->owner_nlportid) 13540 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 13541 msg, 0, NL80211_MCGRP_NAN, gfp); 13542 else 13543 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 13544 wdev->owner_nlportid); 13545 13546 return; 13547 13548 nla_put_failure: 13549 nlmsg_free(msg); 13550 } 13551 EXPORT_SYMBOL(cfg80211_nan_match); 13552 13553 void cfg80211_nan_func_terminated(struct wireless_dev *wdev, 13554 u8 inst_id, 13555 enum nl80211_nan_func_term_reason reason, 13556 u64 cookie, gfp_t gfp) 13557 { 13558 struct wiphy *wiphy = wdev->wiphy; 13559 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 13560 struct sk_buff *msg; 13561 struct nlattr *func_attr; 13562 void *hdr; 13563 13564 if (WARN_ON(!inst_id)) 13565 return; 13566 13567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 13568 if (!msg) 13569 return; 13570 13571 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); 13572 if (!hdr) { 13573 nlmsg_free(msg); 13574 return; 13575 } 13576 13577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 13578 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 13579 wdev->netdev->ifindex)) || 13580 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 13581 NL80211_ATTR_PAD)) 13582 goto nla_put_failure; 13583 13584 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 13585 NL80211_ATTR_PAD)) 13586 goto nla_put_failure; 13587 13588 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 13589 if (!func_attr) 13590 goto nla_put_failure; 13591 13592 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || 13593 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) 13594 goto nla_put_failure; 13595 13596 nla_nest_end(msg, func_attr); 13597 genlmsg_end(msg, hdr); 13598 13599 if (!wdev->owner_nlportid) 13600 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 13601 msg, 0, NL80211_MCGRP_NAN, gfp); 13602 else 13603 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 13604 wdev->owner_nlportid); 13605 13606 return; 13607 13608 nla_put_failure: 13609 nlmsg_free(msg); 13610 } 13611 EXPORT_SYMBOL(cfg80211_nan_func_terminated); 13612 13613 static int nl80211_get_protocol_features(struct sk_buff *skb, 13614 struct genl_info *info) 13615 { 13616 void *hdr; 13617 struct sk_buff *msg; 13618 13619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13620 if (!msg) 13621 return -ENOMEM; 13622 13623 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13624 NL80211_CMD_GET_PROTOCOL_FEATURES); 13625 if (!hdr) 13626 goto nla_put_failure; 13627 13628 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, 13629 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) 13630 goto nla_put_failure; 13631 13632 genlmsg_end(msg, hdr); 13633 return genlmsg_reply(msg, info); 13634 13635 nla_put_failure: 13636 kfree_skb(msg); 13637 return -ENOBUFS; 13638 } 13639 13640 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) 13641 { 13642 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13643 struct cfg80211_update_ft_ies_params ft_params; 13644 struct net_device *dev = info->user_ptr[1]; 13645 13646 if (!rdev->ops->update_ft_ies) 13647 return -EOPNOTSUPP; 13648 13649 if (!info->attrs[NL80211_ATTR_MDID] || 13650 !info->attrs[NL80211_ATTR_IE]) 13651 return -EINVAL; 13652 13653 memset(&ft_params, 0, sizeof(ft_params)); 13654 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); 13655 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 13656 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 13657 13658 return rdev_update_ft_ies(rdev, dev, &ft_params); 13659 } 13660 13661 static int nl80211_crit_protocol_start(struct sk_buff *skb, 13662 struct genl_info *info) 13663 { 13664 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13665 struct wireless_dev *wdev = info->user_ptr[1]; 13666 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; 13667 u16 duration; 13668 int ret; 13669 13670 if (!rdev->ops->crit_proto_start) 13671 return -EOPNOTSUPP; 13672 13673 if (WARN_ON(!rdev->ops->crit_proto_stop)) 13674 return -EINVAL; 13675 13676 if (rdev->crit_proto_nlportid) 13677 return -EBUSY; 13678 13679 /* determine protocol if provided */ 13680 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) 13681 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); 13682 13683 if (proto >= NUM_NL80211_CRIT_PROTO) 13684 return -EINVAL; 13685 13686 /* timeout must be provided */ 13687 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) 13688 return -EINVAL; 13689 13690 duration = 13691 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); 13692 13693 ret = rdev_crit_proto_start(rdev, wdev, proto, duration); 13694 if (!ret) 13695 rdev->crit_proto_nlportid = info->snd_portid; 13696 13697 return ret; 13698 } 13699 13700 static int nl80211_crit_protocol_stop(struct sk_buff *skb, 13701 struct genl_info *info) 13702 { 13703 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13704 struct wireless_dev *wdev = info->user_ptr[1]; 13705 13706 if (!rdev->ops->crit_proto_stop) 13707 return -EOPNOTSUPP; 13708 13709 if (rdev->crit_proto_nlportid) { 13710 rdev->crit_proto_nlportid = 0; 13711 rdev_crit_proto_stop(rdev, wdev); 13712 } 13713 return 0; 13714 } 13715 13716 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, 13717 struct nlattr *attr, 13718 struct netlink_ext_ack *extack) 13719 { 13720 if (vcmd->policy == VENDOR_CMD_RAW_DATA) { 13721 if (attr->nla_type & NLA_F_NESTED) { 13722 NL_SET_ERR_MSG_ATTR(extack, attr, 13723 "unexpected nested data"); 13724 return -EINVAL; 13725 } 13726 13727 return 0; 13728 } 13729 13730 if (!(attr->nla_type & NLA_F_NESTED)) { 13731 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); 13732 return -EINVAL; 13733 } 13734 13735 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); 13736 } 13737 13738 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) 13739 { 13740 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13741 struct wireless_dev *wdev = 13742 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 13743 info->attrs); 13744 int i, err; 13745 u32 vid, subcmd; 13746 13747 if (!rdev->wiphy.vendor_commands) 13748 return -EOPNOTSUPP; 13749 13750 if (IS_ERR(wdev)) { 13751 err = PTR_ERR(wdev); 13752 if (err != -EINVAL) 13753 return err; 13754 wdev = NULL; 13755 } else if (wdev->wiphy != &rdev->wiphy) { 13756 return -EINVAL; 13757 } 13758 13759 if (!info->attrs[NL80211_ATTR_VENDOR_ID] || 13760 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) 13761 return -EINVAL; 13762 13763 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); 13764 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); 13765 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 13766 const struct wiphy_vendor_command *vcmd; 13767 void *data = NULL; 13768 int len = 0; 13769 13770 vcmd = &rdev->wiphy.vendor_commands[i]; 13771 13772 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 13773 continue; 13774 13775 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 13776 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 13777 if (!wdev) 13778 return -EINVAL; 13779 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 13780 !wdev->netdev) 13781 return -EINVAL; 13782 13783 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 13784 if (!wdev_running(wdev)) 13785 return -ENETDOWN; 13786 } 13787 } else { 13788 wdev = NULL; 13789 } 13790 13791 if (!vcmd->doit) 13792 return -EOPNOTSUPP; 13793 13794 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { 13795 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); 13796 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); 13797 13798 err = nl80211_vendor_check_policy(vcmd, 13799 info->attrs[NL80211_ATTR_VENDOR_DATA], 13800 info->extack); 13801 if (err) 13802 return err; 13803 } 13804 13805 rdev->cur_cmd_info = info; 13806 err = vcmd->doit(&rdev->wiphy, wdev, data, len); 13807 rdev->cur_cmd_info = NULL; 13808 return err; 13809 } 13810 13811 return -EOPNOTSUPP; 13812 } 13813 13814 static int nl80211_prepare_vendor_dump(struct sk_buff *skb, 13815 struct netlink_callback *cb, 13816 struct cfg80211_registered_device **rdev, 13817 struct wireless_dev **wdev) 13818 { 13819 struct nlattr **attrbuf; 13820 u32 vid, subcmd; 13821 unsigned int i; 13822 int vcmd_idx = -1; 13823 int err; 13824 void *data = NULL; 13825 unsigned int data_len = 0; 13826 13827 if (cb->args[0]) { 13828 /* subtract the 1 again here */ 13829 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 13830 struct wireless_dev *tmp; 13831 13832 if (!wiphy) 13833 return -ENODEV; 13834 *rdev = wiphy_to_rdev(wiphy); 13835 *wdev = NULL; 13836 13837 if (cb->args[1]) { 13838 list_for_each_entry(tmp, &wiphy->wdev_list, list) { 13839 if (tmp->identifier == cb->args[1] - 1) { 13840 *wdev = tmp; 13841 break; 13842 } 13843 } 13844 } 13845 13846 /* keep rtnl locked in successful case */ 13847 return 0; 13848 } 13849 13850 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 13851 if (!attrbuf) 13852 return -ENOMEM; 13853 13854 err = nlmsg_parse_deprecated(cb->nlh, 13855 GENL_HDRLEN + nl80211_fam.hdrsize, 13856 attrbuf, nl80211_fam.maxattr, 13857 nl80211_policy, NULL); 13858 if (err) 13859 goto out; 13860 13861 if (!attrbuf[NL80211_ATTR_VENDOR_ID] || 13862 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { 13863 err = -EINVAL; 13864 goto out; 13865 } 13866 13867 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf); 13868 if (IS_ERR(*wdev)) 13869 *wdev = NULL; 13870 13871 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 13872 if (IS_ERR(*rdev)) { 13873 err = PTR_ERR(*rdev); 13874 goto out; 13875 } 13876 13877 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); 13878 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); 13879 13880 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { 13881 const struct wiphy_vendor_command *vcmd; 13882 13883 vcmd = &(*rdev)->wiphy.vendor_commands[i]; 13884 13885 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 13886 continue; 13887 13888 if (!vcmd->dumpit) { 13889 err = -EOPNOTSUPP; 13890 goto out; 13891 } 13892 13893 vcmd_idx = i; 13894 break; 13895 } 13896 13897 if (vcmd_idx < 0) { 13898 err = -EOPNOTSUPP; 13899 goto out; 13900 } 13901 13902 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { 13903 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); 13904 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); 13905 13906 err = nl80211_vendor_check_policy( 13907 &(*rdev)->wiphy.vendor_commands[vcmd_idx], 13908 attrbuf[NL80211_ATTR_VENDOR_DATA], 13909 cb->extack); 13910 if (err) 13911 goto out; 13912 } 13913 13914 /* 0 is the first index - add 1 to parse only once */ 13915 cb->args[0] = (*rdev)->wiphy_idx + 1; 13916 /* add 1 to know if it was NULL */ 13917 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; 13918 cb->args[2] = vcmd_idx; 13919 cb->args[3] = (unsigned long)data; 13920 cb->args[4] = data_len; 13921 13922 /* keep rtnl locked in successful case */ 13923 err = 0; 13924 out: 13925 kfree(attrbuf); 13926 return err; 13927 } 13928 13929 static int nl80211_vendor_cmd_dump(struct sk_buff *skb, 13930 struct netlink_callback *cb) 13931 { 13932 struct cfg80211_registered_device *rdev; 13933 struct wireless_dev *wdev; 13934 unsigned int vcmd_idx; 13935 const struct wiphy_vendor_command *vcmd; 13936 void *data; 13937 int data_len; 13938 int err; 13939 struct nlattr *vendor_data; 13940 13941 rtnl_lock(); 13942 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); 13943 if (err) 13944 goto out; 13945 13946 vcmd_idx = cb->args[2]; 13947 data = (void *)cb->args[3]; 13948 data_len = cb->args[4]; 13949 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; 13950 13951 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 13952 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 13953 if (!wdev) { 13954 err = -EINVAL; 13955 goto out; 13956 } 13957 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 13958 !wdev->netdev) { 13959 err = -EINVAL; 13960 goto out; 13961 } 13962 13963 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 13964 if (!wdev_running(wdev)) { 13965 err = -ENETDOWN; 13966 goto out; 13967 } 13968 } 13969 } 13970 13971 while (1) { 13972 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 13973 cb->nlh->nlmsg_seq, NLM_F_MULTI, 13974 NL80211_CMD_VENDOR); 13975 if (!hdr) 13976 break; 13977 13978 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 13979 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 13980 wdev_id(wdev), 13981 NL80211_ATTR_PAD))) { 13982 genlmsg_cancel(skb, hdr); 13983 break; 13984 } 13985 13986 vendor_data = nla_nest_start_noflag(skb, 13987 NL80211_ATTR_VENDOR_DATA); 13988 if (!vendor_data) { 13989 genlmsg_cancel(skb, hdr); 13990 break; 13991 } 13992 13993 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, 13994 (unsigned long *)&cb->args[5]); 13995 nla_nest_end(skb, vendor_data); 13996 13997 if (err == -ENOBUFS || err == -ENOENT) { 13998 genlmsg_cancel(skb, hdr); 13999 break; 14000 } else if (err <= 0) { 14001 genlmsg_cancel(skb, hdr); 14002 goto out; 14003 } 14004 14005 genlmsg_end(skb, hdr); 14006 } 14007 14008 err = skb->len; 14009 out: 14010 rtnl_unlock(); 14011 return err; 14012 } 14013 14014 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, 14015 enum nl80211_commands cmd, 14016 enum nl80211_attrs attr, 14017 int approxlen) 14018 { 14019 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14020 14021 if (WARN_ON(!rdev->cur_cmd_info)) 14022 return NULL; 14023 14024 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, 14025 rdev->cur_cmd_info->snd_portid, 14026 rdev->cur_cmd_info->snd_seq, 14027 cmd, attr, NULL, GFP_KERNEL); 14028 } 14029 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); 14030 14031 int cfg80211_vendor_cmd_reply(struct sk_buff *skb) 14032 { 14033 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 14034 void *hdr = ((void **)skb->cb)[1]; 14035 struct nlattr *data = ((void **)skb->cb)[2]; 14036 14037 /* clear CB data for netlink core to own from now on */ 14038 memset(skb->cb, 0, sizeof(skb->cb)); 14039 14040 if (WARN_ON(!rdev->cur_cmd_info)) { 14041 kfree_skb(skb); 14042 return -EINVAL; 14043 } 14044 14045 nla_nest_end(skb, data); 14046 genlmsg_end(skb, hdr); 14047 return genlmsg_reply(skb, rdev->cur_cmd_info); 14048 } 14049 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); 14050 14051 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) 14052 { 14053 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14054 14055 if (WARN_ON(!rdev->cur_cmd_info)) 14056 return 0; 14057 14058 return rdev->cur_cmd_info->snd_portid; 14059 } 14060 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); 14061 14062 static int nl80211_set_qos_map(struct sk_buff *skb, 14063 struct genl_info *info) 14064 { 14065 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14066 struct cfg80211_qos_map *qos_map = NULL; 14067 struct net_device *dev = info->user_ptr[1]; 14068 u8 *pos, len, num_des, des_len, des; 14069 int ret; 14070 14071 if (!rdev->ops->set_qos_map) 14072 return -EOPNOTSUPP; 14073 14074 if (info->attrs[NL80211_ATTR_QOS_MAP]) { 14075 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); 14076 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); 14077 14078 if (len % 2) 14079 return -EINVAL; 14080 14081 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); 14082 if (!qos_map) 14083 return -ENOMEM; 14084 14085 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; 14086 if (num_des) { 14087 des_len = num_des * 14088 sizeof(struct cfg80211_dscp_exception); 14089 memcpy(qos_map->dscp_exception, pos, des_len); 14090 qos_map->num_des = num_des; 14091 for (des = 0; des < num_des; des++) { 14092 if (qos_map->dscp_exception[des].up > 7) { 14093 kfree(qos_map); 14094 return -EINVAL; 14095 } 14096 } 14097 pos += des_len; 14098 } 14099 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); 14100 } 14101 14102 wdev_lock(dev->ieee80211_ptr); 14103 ret = nl80211_key_allowed(dev->ieee80211_ptr); 14104 if (!ret) 14105 ret = rdev_set_qos_map(rdev, dev, qos_map); 14106 wdev_unlock(dev->ieee80211_ptr); 14107 14108 kfree(qos_map); 14109 return ret; 14110 } 14111 14112 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) 14113 { 14114 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14115 struct net_device *dev = info->user_ptr[1]; 14116 struct wireless_dev *wdev = dev->ieee80211_ptr; 14117 const u8 *peer; 14118 u8 tsid, up; 14119 u16 admitted_time = 0; 14120 int err; 14121 14122 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) 14123 return -EOPNOTSUPP; 14124 14125 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 14126 !info->attrs[NL80211_ATTR_USER_PRIO]) 14127 return -EINVAL; 14128 14129 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 14130 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); 14131 14132 /* WMM uses TIDs 0-7 even for TSPEC */ 14133 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { 14134 /* TODO: handle 802.11 TSPEC/admission control 14135 * need more attributes for that (e.g. BA session requirement); 14136 * change the WMM adminssion test above to allow both then 14137 */ 14138 return -EINVAL; 14139 } 14140 14141 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 14142 14143 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { 14144 admitted_time = 14145 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); 14146 if (!admitted_time) 14147 return -EINVAL; 14148 } 14149 14150 wdev_lock(wdev); 14151 switch (wdev->iftype) { 14152 case NL80211_IFTYPE_STATION: 14153 case NL80211_IFTYPE_P2P_CLIENT: 14154 if (wdev->current_bss) 14155 break; 14156 err = -ENOTCONN; 14157 goto out; 14158 default: 14159 err = -EOPNOTSUPP; 14160 goto out; 14161 } 14162 14163 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); 14164 14165 out: 14166 wdev_unlock(wdev); 14167 return err; 14168 } 14169 14170 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) 14171 { 14172 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14173 struct net_device *dev = info->user_ptr[1]; 14174 struct wireless_dev *wdev = dev->ieee80211_ptr; 14175 const u8 *peer; 14176 u8 tsid; 14177 int err; 14178 14179 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) 14180 return -EINVAL; 14181 14182 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 14183 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 14184 14185 wdev_lock(wdev); 14186 err = rdev_del_tx_ts(rdev, dev, tsid, peer); 14187 wdev_unlock(wdev); 14188 14189 return err; 14190 } 14191 14192 static int nl80211_tdls_channel_switch(struct sk_buff *skb, 14193 struct genl_info *info) 14194 { 14195 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14196 struct net_device *dev = info->user_ptr[1]; 14197 struct wireless_dev *wdev = dev->ieee80211_ptr; 14198 struct cfg80211_chan_def chandef = {}; 14199 const u8 *addr; 14200 u8 oper_class; 14201 int err; 14202 14203 if (!rdev->ops->tdls_channel_switch || 14204 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 14205 return -EOPNOTSUPP; 14206 14207 switch (dev->ieee80211_ptr->iftype) { 14208 case NL80211_IFTYPE_STATION: 14209 case NL80211_IFTYPE_P2P_CLIENT: 14210 break; 14211 default: 14212 return -EOPNOTSUPP; 14213 } 14214 14215 if (!info->attrs[NL80211_ATTR_MAC] || 14216 !info->attrs[NL80211_ATTR_OPER_CLASS]) 14217 return -EINVAL; 14218 14219 err = nl80211_parse_chandef(rdev, info, &chandef); 14220 if (err) 14221 return err; 14222 14223 /* 14224 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 14225 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the 14226 * specification is not defined for them. 14227 */ 14228 if (chandef.chan->band == NL80211_BAND_2GHZ && 14229 chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 14230 chandef.width != NL80211_CHAN_WIDTH_20) 14231 return -EINVAL; 14232 14233 /* we will be active on the TDLS link */ 14234 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 14235 wdev->iftype)) 14236 return -EINVAL; 14237 14238 /* don't allow switching to DFS channels */ 14239 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) 14240 return -EINVAL; 14241 14242 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 14243 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); 14244 14245 wdev_lock(wdev); 14246 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); 14247 wdev_unlock(wdev); 14248 14249 return err; 14250 } 14251 14252 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, 14253 struct genl_info *info) 14254 { 14255 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14256 struct net_device *dev = info->user_ptr[1]; 14257 struct wireless_dev *wdev = dev->ieee80211_ptr; 14258 const u8 *addr; 14259 14260 if (!rdev->ops->tdls_channel_switch || 14261 !rdev->ops->tdls_cancel_channel_switch || 14262 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 14263 return -EOPNOTSUPP; 14264 14265 switch (dev->ieee80211_ptr->iftype) { 14266 case NL80211_IFTYPE_STATION: 14267 case NL80211_IFTYPE_P2P_CLIENT: 14268 break; 14269 default: 14270 return -EOPNOTSUPP; 14271 } 14272 14273 if (!info->attrs[NL80211_ATTR_MAC]) 14274 return -EINVAL; 14275 14276 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 14277 14278 wdev_lock(wdev); 14279 rdev_tdls_cancel_channel_switch(rdev, dev, addr); 14280 wdev_unlock(wdev); 14281 14282 return 0; 14283 } 14284 14285 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, 14286 struct genl_info *info) 14287 { 14288 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14289 struct net_device *dev = info->user_ptr[1]; 14290 struct wireless_dev *wdev = dev->ieee80211_ptr; 14291 const struct nlattr *nla; 14292 bool enabled; 14293 14294 if (!rdev->ops->set_multicast_to_unicast) 14295 return -EOPNOTSUPP; 14296 14297 if (wdev->iftype != NL80211_IFTYPE_AP && 14298 wdev->iftype != NL80211_IFTYPE_P2P_GO) 14299 return -EOPNOTSUPP; 14300 14301 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; 14302 enabled = nla_get_flag(nla); 14303 14304 return rdev_set_multicast_to_unicast(rdev, dev, enabled); 14305 } 14306 14307 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) 14308 { 14309 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14310 struct net_device *dev = info->user_ptr[1]; 14311 struct wireless_dev *wdev = dev->ieee80211_ptr; 14312 struct cfg80211_pmk_conf pmk_conf = {}; 14313 int ret; 14314 14315 if (wdev->iftype != NL80211_IFTYPE_STATION && 14316 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 14317 return -EOPNOTSUPP; 14318 14319 if (!wiphy_ext_feature_isset(&rdev->wiphy, 14320 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 14321 return -EOPNOTSUPP; 14322 14323 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) 14324 return -EINVAL; 14325 14326 wdev_lock(wdev); 14327 if (!wdev->current_bss) { 14328 ret = -ENOTCONN; 14329 goto out; 14330 } 14331 14332 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 14333 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { 14334 ret = -EINVAL; 14335 goto out; 14336 } 14337 14338 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 14339 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 14340 if (pmk_conf.pmk_len != WLAN_PMK_LEN && 14341 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { 14342 ret = -EINVAL; 14343 goto out; 14344 } 14345 14346 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) 14347 pmk_conf.pmk_r0_name = 14348 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); 14349 14350 ret = rdev_set_pmk(rdev, dev, &pmk_conf); 14351 out: 14352 wdev_unlock(wdev); 14353 return ret; 14354 } 14355 14356 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) 14357 { 14358 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14359 struct net_device *dev = info->user_ptr[1]; 14360 struct wireless_dev *wdev = dev->ieee80211_ptr; 14361 const u8 *aa; 14362 int ret; 14363 14364 if (wdev->iftype != NL80211_IFTYPE_STATION && 14365 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 14366 return -EOPNOTSUPP; 14367 14368 if (!wiphy_ext_feature_isset(&rdev->wiphy, 14369 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 14370 return -EOPNOTSUPP; 14371 14372 if (!info->attrs[NL80211_ATTR_MAC]) 14373 return -EINVAL; 14374 14375 wdev_lock(wdev); 14376 aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 14377 ret = rdev_del_pmk(rdev, dev, aa); 14378 wdev_unlock(wdev); 14379 14380 return ret; 14381 } 14382 14383 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) 14384 { 14385 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14386 struct net_device *dev = info->user_ptr[1]; 14387 struct cfg80211_external_auth_params params; 14388 14389 if (!rdev->ops->external_auth) 14390 return -EOPNOTSUPP; 14391 14392 if (!info->attrs[NL80211_ATTR_SSID] && 14393 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 14394 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 14395 return -EINVAL; 14396 14397 if (!info->attrs[NL80211_ATTR_BSSID]) 14398 return -EINVAL; 14399 14400 if (!info->attrs[NL80211_ATTR_STATUS_CODE]) 14401 return -EINVAL; 14402 14403 memset(¶ms, 0, sizeof(params)); 14404 14405 if (info->attrs[NL80211_ATTR_SSID]) { 14406 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 14407 if (params.ssid.ssid_len == 0) 14408 return -EINVAL; 14409 memcpy(params.ssid.ssid, 14410 nla_data(info->attrs[NL80211_ATTR_SSID]), 14411 params.ssid.ssid_len); 14412 } 14413 14414 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), 14415 ETH_ALEN); 14416 14417 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 14418 14419 if (info->attrs[NL80211_ATTR_PMKID]) 14420 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 14421 14422 return rdev_external_auth(rdev, dev, ¶ms); 14423 } 14424 14425 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) 14426 { 14427 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; 14428 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14429 struct net_device *dev = info->user_ptr[1]; 14430 struct wireless_dev *wdev = dev->ieee80211_ptr; 14431 const u8 *buf; 14432 size_t len; 14433 u8 *dest; 14434 u16 proto; 14435 bool noencrypt; 14436 u64 cookie = 0; 14437 int err; 14438 14439 if (!wiphy_ext_feature_isset(&rdev->wiphy, 14440 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 14441 return -EOPNOTSUPP; 14442 14443 if (!rdev->ops->tx_control_port) 14444 return -EOPNOTSUPP; 14445 14446 if (!info->attrs[NL80211_ATTR_FRAME] || 14447 !info->attrs[NL80211_ATTR_MAC] || 14448 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 14449 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); 14450 return -EINVAL; 14451 } 14452 14453 wdev_lock(wdev); 14454 14455 switch (wdev->iftype) { 14456 case NL80211_IFTYPE_AP: 14457 case NL80211_IFTYPE_P2P_GO: 14458 case NL80211_IFTYPE_MESH_POINT: 14459 break; 14460 case NL80211_IFTYPE_ADHOC: 14461 case NL80211_IFTYPE_STATION: 14462 case NL80211_IFTYPE_P2P_CLIENT: 14463 if (wdev->current_bss) 14464 break; 14465 err = -ENOTCONN; 14466 goto out; 14467 default: 14468 err = -EOPNOTSUPP; 14469 goto out; 14470 } 14471 14472 wdev_unlock(wdev); 14473 14474 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 14475 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 14476 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 14477 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 14478 noencrypt = 14479 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); 14480 14481 err = rdev_tx_control_port(rdev, dev, buf, len, 14482 dest, cpu_to_be16(proto), noencrypt, 14483 dont_wait_for_ack ? NULL : &cookie); 14484 if (!err && !dont_wait_for_ack) 14485 nl_set_extack_cookie_u64(info->extack, cookie); 14486 return err; 14487 out: 14488 wdev_unlock(wdev); 14489 return err; 14490 } 14491 14492 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, 14493 struct genl_info *info) 14494 { 14495 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14496 struct net_device *dev = info->user_ptr[1]; 14497 struct wireless_dev *wdev = dev->ieee80211_ptr; 14498 struct cfg80211_ftm_responder_stats ftm_stats = {}; 14499 struct sk_buff *msg; 14500 void *hdr; 14501 struct nlattr *ftm_stats_attr; 14502 int err; 14503 14504 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) 14505 return -EOPNOTSUPP; 14506 14507 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); 14508 if (err) 14509 return err; 14510 14511 if (!ftm_stats.filled) 14512 return -ENODATA; 14513 14514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14515 if (!msg) 14516 return -ENOMEM; 14517 14518 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14519 NL80211_CMD_GET_FTM_RESPONDER_STATS); 14520 if (!hdr) 14521 goto nla_put_failure; 14522 14523 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 14524 goto nla_put_failure; 14525 14526 ftm_stats_attr = nla_nest_start_noflag(msg, 14527 NL80211_ATTR_FTM_RESPONDER_STATS); 14528 if (!ftm_stats_attr) 14529 goto nla_put_failure; 14530 14531 #define SET_FTM(field, name, type) \ 14532 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 14533 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ 14534 ftm_stats.field)) \ 14535 goto nla_put_failure; } while (0) 14536 #define SET_FTM_U64(field, name) \ 14537 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 14538 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ 14539 ftm_stats.field, NL80211_FTM_STATS_PAD)) \ 14540 goto nla_put_failure; } while (0) 14541 14542 SET_FTM(success_num, SUCCESS_NUM, u32); 14543 SET_FTM(partial_num, PARTIAL_NUM, u32); 14544 SET_FTM(failed_num, FAILED_NUM, u32); 14545 SET_FTM(asap_num, ASAP_NUM, u32); 14546 SET_FTM(non_asap_num, NON_ASAP_NUM, u32); 14547 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); 14548 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); 14549 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); 14550 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); 14551 #undef SET_FTM 14552 14553 nla_nest_end(msg, ftm_stats_attr); 14554 14555 genlmsg_end(msg, hdr); 14556 return genlmsg_reply(msg, info); 14557 14558 nla_put_failure: 14559 nlmsg_free(msg); 14560 return -ENOBUFS; 14561 } 14562 14563 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) 14564 { 14565 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14566 struct cfg80211_update_owe_info owe_info; 14567 struct net_device *dev = info->user_ptr[1]; 14568 14569 if (!rdev->ops->update_owe_info) 14570 return -EOPNOTSUPP; 14571 14572 if (!info->attrs[NL80211_ATTR_STATUS_CODE] || 14573 !info->attrs[NL80211_ATTR_MAC]) 14574 return -EINVAL; 14575 14576 memset(&owe_info, 0, sizeof(owe_info)); 14577 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 14578 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); 14579 14580 if (info->attrs[NL80211_ATTR_IE]) { 14581 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 14582 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 14583 } 14584 14585 return rdev_update_owe_info(rdev, dev, &owe_info); 14586 } 14587 14588 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) 14589 { 14590 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14591 struct net_device *dev = info->user_ptr[1]; 14592 struct wireless_dev *wdev = dev->ieee80211_ptr; 14593 struct station_info sinfo = {}; 14594 const u8 *buf; 14595 size_t len; 14596 u8 *dest; 14597 int err; 14598 14599 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) 14600 return -EOPNOTSUPP; 14601 14602 if (!info->attrs[NL80211_ATTR_MAC] || 14603 !info->attrs[NL80211_ATTR_FRAME]) { 14604 GENL_SET_ERR_MSG(info, "Frame or MAC missing"); 14605 return -EINVAL; 14606 } 14607 14608 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 14609 return -EOPNOTSUPP; 14610 14611 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 14612 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 14613 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 14614 14615 if (len < sizeof(struct ethhdr)) 14616 return -EINVAL; 14617 14618 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || 14619 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) 14620 return -EINVAL; 14621 14622 err = rdev_get_station(rdev, dev, dest, &sinfo); 14623 if (err) 14624 return err; 14625 14626 cfg80211_sinfo_release_content(&sinfo); 14627 14628 return rdev_probe_mesh_link(rdev, dev, dest, buf, len); 14629 } 14630 14631 static int parse_tid_conf(struct cfg80211_registered_device *rdev, 14632 struct nlattr *attrs[], struct net_device *dev, 14633 struct cfg80211_tid_cfg *tid_conf, 14634 struct genl_info *info, const u8 *peer) 14635 { 14636 struct netlink_ext_ack *extack = info->extack; 14637 u64 mask; 14638 int err; 14639 14640 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) 14641 return -EINVAL; 14642 14643 tid_conf->config_override = 14644 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); 14645 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); 14646 14647 if (tid_conf->config_override) { 14648 if (rdev->ops->reset_tid_config) { 14649 err = rdev_reset_tid_config(rdev, dev, peer, 14650 tid_conf->tids); 14651 if (err) 14652 return err; 14653 } else { 14654 return -EINVAL; 14655 } 14656 } 14657 14658 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { 14659 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); 14660 tid_conf->noack = 14661 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); 14662 } 14663 14664 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { 14665 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); 14666 tid_conf->retry_short = 14667 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); 14668 14669 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) 14670 return -EINVAL; 14671 } 14672 14673 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { 14674 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); 14675 tid_conf->retry_long = 14676 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); 14677 14678 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) 14679 return -EINVAL; 14680 } 14681 14682 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { 14683 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); 14684 tid_conf->ampdu = 14685 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); 14686 } 14687 14688 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { 14689 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); 14690 tid_conf->rtscts = 14691 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); 14692 } 14693 14694 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { 14695 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); 14696 tid_conf->amsdu = 14697 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); 14698 } 14699 14700 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { 14701 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; 14702 14703 tid_conf->txrate_type = nla_get_u8(attrs[idx]); 14704 14705 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { 14706 attr = NL80211_TID_CONFIG_ATTR_TX_RATE; 14707 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, 14708 &tid_conf->txrate_mask, dev, 14709 true); 14710 if (err) 14711 return err; 14712 14713 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); 14714 } 14715 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); 14716 } 14717 14718 if (peer) 14719 mask = rdev->wiphy.tid_config_support.peer; 14720 else 14721 mask = rdev->wiphy.tid_config_support.vif; 14722 14723 if (tid_conf->mask & ~mask) { 14724 NL_SET_ERR_MSG(extack, "unsupported TID configuration"); 14725 return -ENOTSUPP; 14726 } 14727 14728 return 0; 14729 } 14730 14731 static int nl80211_set_tid_config(struct sk_buff *skb, 14732 struct genl_info *info) 14733 { 14734 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14735 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; 14736 struct net_device *dev = info->user_ptr[1]; 14737 struct cfg80211_tid_config *tid_config; 14738 struct nlattr *tid; 14739 int conf_idx = 0, rem_conf; 14740 int ret = -EINVAL; 14741 u32 num_conf = 0; 14742 14743 if (!info->attrs[NL80211_ATTR_TID_CONFIG]) 14744 return -EINVAL; 14745 14746 if (!rdev->ops->set_tid_config) 14747 return -EOPNOTSUPP; 14748 14749 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 14750 rem_conf) 14751 num_conf++; 14752 14753 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), 14754 GFP_KERNEL); 14755 if (!tid_config) 14756 return -ENOMEM; 14757 14758 tid_config->n_tid_conf = num_conf; 14759 14760 if (info->attrs[NL80211_ATTR_MAC]) 14761 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 14762 14763 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 14764 rem_conf) { 14765 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, 14766 tid, NULL, NULL); 14767 14768 if (ret) 14769 goto bad_tid_conf; 14770 14771 ret = parse_tid_conf(rdev, attrs, dev, 14772 &tid_config->tid_conf[conf_idx], 14773 info, tid_config->peer); 14774 if (ret) 14775 goto bad_tid_conf; 14776 14777 conf_idx++; 14778 } 14779 14780 ret = rdev_set_tid_config(rdev, dev, tid_config); 14781 14782 bad_tid_conf: 14783 kfree(tid_config); 14784 return ret; 14785 } 14786 14787 #define NL80211_FLAG_NEED_WIPHY 0x01 14788 #define NL80211_FLAG_NEED_NETDEV 0x02 14789 #define NL80211_FLAG_NEED_RTNL 0x04 14790 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 14791 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ 14792 NL80211_FLAG_CHECK_NETDEV_UP) 14793 #define NL80211_FLAG_NEED_WDEV 0x10 14794 /* If a netdev is associated, it must be UP, P2P must be started */ 14795 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ 14796 NL80211_FLAG_CHECK_NETDEV_UP) 14797 #define NL80211_FLAG_CLEAR_SKB 0x20 14798 #define NL80211_FLAG_NO_WIPHY_MTX 0x40 14799 14800 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, 14801 struct genl_info *info) 14802 { 14803 struct cfg80211_registered_device *rdev = NULL; 14804 struct wireless_dev *wdev; 14805 struct net_device *dev; 14806 14807 rtnl_lock(); 14808 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { 14809 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 14810 if (IS_ERR(rdev)) { 14811 rtnl_unlock(); 14812 return PTR_ERR(rdev); 14813 } 14814 info->user_ptr[0] = rdev; 14815 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || 14816 ops->internal_flags & NL80211_FLAG_NEED_WDEV) { 14817 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), 14818 info->attrs); 14819 if (IS_ERR(wdev)) { 14820 rtnl_unlock(); 14821 return PTR_ERR(wdev); 14822 } 14823 14824 dev = wdev->netdev; 14825 rdev = wiphy_to_rdev(wdev->wiphy); 14826 14827 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { 14828 if (!dev) { 14829 rtnl_unlock(); 14830 return -EINVAL; 14831 } 14832 14833 info->user_ptr[1] = dev; 14834 } else { 14835 info->user_ptr[1] = wdev; 14836 } 14837 14838 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && 14839 !wdev_running(wdev)) { 14840 rtnl_unlock(); 14841 return -ENETDOWN; 14842 } 14843 14844 if (dev) 14845 dev_hold(dev); 14846 14847 info->user_ptr[0] = rdev; 14848 } 14849 14850 if (rdev && !(ops->internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 14851 wiphy_lock(&rdev->wiphy); 14852 /* we keep the mutex locked until post_doit */ 14853 __release(&rdev->wiphy.mtx); 14854 } 14855 if (!(ops->internal_flags & NL80211_FLAG_NEED_RTNL)) 14856 rtnl_unlock(); 14857 14858 return 0; 14859 } 14860 14861 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, 14862 struct genl_info *info) 14863 { 14864 if (info->user_ptr[1]) { 14865 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { 14866 struct wireless_dev *wdev = info->user_ptr[1]; 14867 14868 if (wdev->netdev) 14869 dev_put(wdev->netdev); 14870 } else { 14871 dev_put(info->user_ptr[1]); 14872 } 14873 } 14874 14875 if (info->user_ptr[0] && 14876 !(ops->internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 14877 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14878 14879 /* we kept the mutex locked since pre_doit */ 14880 __acquire(&rdev->wiphy.mtx); 14881 wiphy_unlock(&rdev->wiphy); 14882 } 14883 14884 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) 14885 rtnl_unlock(); 14886 14887 /* If needed, clear the netlink message payload from the SKB 14888 * as it might contain key data that shouldn't stick around on 14889 * the heap after the SKB is freed. The netlink message header 14890 * is still needed for further processing, so leave it intact. 14891 */ 14892 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { 14893 struct nlmsghdr *nlh = nlmsg_hdr(skb); 14894 14895 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); 14896 } 14897 } 14898 14899 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev, 14900 struct cfg80211_sar_specs *sar_specs, 14901 struct nlattr *spec[], int index) 14902 { 14903 u32 range_index, i; 14904 14905 if (!sar_specs || !spec) 14906 return -EINVAL; 14907 14908 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] || 14909 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]) 14910 return -EINVAL; 14911 14912 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]); 14913 14914 /* check if range_index exceeds num_freq_ranges */ 14915 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges) 14916 return -EINVAL; 14917 14918 /* check if range_index duplicates */ 14919 for (i = 0; i < index; i++) { 14920 if (sar_specs->sub_specs[i].freq_range_index == range_index) 14921 return -EINVAL; 14922 } 14923 14924 sar_specs->sub_specs[index].power = 14925 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]); 14926 14927 sar_specs->sub_specs[index].freq_range_index = range_index; 14928 14929 return 0; 14930 } 14931 14932 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) 14933 { 14934 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14935 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1]; 14936 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1]; 14937 struct cfg80211_sar_specs *sar_spec; 14938 enum nl80211_sar_type type; 14939 struct nlattr *spec_list; 14940 u32 specs; 14941 int rem, err; 14942 14943 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs) 14944 return -EOPNOTSUPP; 14945 14946 if (!info->attrs[NL80211_ATTR_SAR_SPEC]) 14947 return -EINVAL; 14948 14949 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX, 14950 info->attrs[NL80211_ATTR_SAR_SPEC], 14951 NULL, NULL); 14952 14953 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS]) 14954 return -EINVAL; 14955 14956 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]); 14957 if (type != rdev->wiphy.sar_capa->type) 14958 return -EINVAL; 14959 14960 specs = 0; 14961 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) 14962 specs++; 14963 14964 if (specs > rdev->wiphy.sar_capa->num_freq_ranges) 14965 return -EINVAL; 14966 14967 sar_spec = kzalloc(sizeof(*sar_spec) + 14968 specs * sizeof(struct cfg80211_sar_sub_specs), 14969 GFP_KERNEL); 14970 if (!sar_spec) 14971 return -ENOMEM; 14972 14973 sar_spec->type = type; 14974 specs = 0; 14975 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) { 14976 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX, 14977 spec_list, NULL, NULL); 14978 14979 switch (type) { 14980 case NL80211_SAR_TYPE_POWER: 14981 if (nl80211_set_sar_sub_specs(rdev, sar_spec, 14982 spec, specs)) { 14983 err = -EINVAL; 14984 goto error; 14985 } 14986 break; 14987 default: 14988 err = -EINVAL; 14989 goto error; 14990 } 14991 specs++; 14992 } 14993 14994 sar_spec->num_sub_specs = specs; 14995 14996 rdev->cur_cmd_info = info; 14997 err = rdev_set_sar_specs(rdev, sar_spec); 14998 rdev->cur_cmd_info = NULL; 14999 error: 15000 kfree(sar_spec); 15001 return err; 15002 } 15003 15004 static const struct genl_ops nl80211_ops[] = { 15005 { 15006 .cmd = NL80211_CMD_GET_WIPHY, 15007 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15008 .doit = nl80211_get_wiphy, 15009 .dumpit = nl80211_dump_wiphy, 15010 .done = nl80211_dump_wiphy_done, 15011 /* can be retrieved by unprivileged users */ 15012 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15013 }, 15014 }; 15015 15016 static const struct genl_small_ops nl80211_small_ops[] = { 15017 { 15018 .cmd = NL80211_CMD_SET_WIPHY, 15019 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15020 .doit = nl80211_set_wiphy, 15021 .flags = GENL_UNS_ADMIN_PERM, 15022 }, 15023 { 15024 .cmd = NL80211_CMD_GET_INTERFACE, 15025 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15026 .doit = nl80211_get_interface, 15027 .dumpit = nl80211_dump_interface, 15028 /* can be retrieved by unprivileged users */ 15029 .internal_flags = NL80211_FLAG_NEED_WDEV, 15030 }, 15031 { 15032 .cmd = NL80211_CMD_SET_INTERFACE, 15033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15034 .doit = nl80211_set_interface, 15035 .flags = GENL_UNS_ADMIN_PERM, 15036 .internal_flags = NL80211_FLAG_NEED_NETDEV | 15037 NL80211_FLAG_NEED_RTNL, 15038 }, 15039 { 15040 .cmd = NL80211_CMD_NEW_INTERFACE, 15041 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15042 .doit = nl80211_new_interface, 15043 .flags = GENL_UNS_ADMIN_PERM, 15044 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15045 NL80211_FLAG_NEED_RTNL, 15046 }, 15047 { 15048 .cmd = NL80211_CMD_DEL_INTERFACE, 15049 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15050 .doit = nl80211_del_interface, 15051 .flags = GENL_UNS_ADMIN_PERM, 15052 .internal_flags = NL80211_FLAG_NEED_WDEV | 15053 NL80211_FLAG_NEED_RTNL, 15054 }, 15055 { 15056 .cmd = NL80211_CMD_GET_KEY, 15057 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15058 .doit = nl80211_get_key, 15059 .flags = GENL_UNS_ADMIN_PERM, 15060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15061 }, 15062 { 15063 .cmd = NL80211_CMD_SET_KEY, 15064 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15065 .doit = nl80211_set_key, 15066 .flags = GENL_UNS_ADMIN_PERM, 15067 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15068 NL80211_FLAG_CLEAR_SKB, 15069 }, 15070 { 15071 .cmd = NL80211_CMD_NEW_KEY, 15072 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15073 .doit = nl80211_new_key, 15074 .flags = GENL_UNS_ADMIN_PERM, 15075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15076 NL80211_FLAG_CLEAR_SKB, 15077 }, 15078 { 15079 .cmd = NL80211_CMD_DEL_KEY, 15080 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15081 .doit = nl80211_del_key, 15082 .flags = GENL_UNS_ADMIN_PERM, 15083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15084 }, 15085 { 15086 .cmd = NL80211_CMD_SET_BEACON, 15087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15088 .flags = GENL_UNS_ADMIN_PERM, 15089 .doit = nl80211_set_beacon, 15090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15091 }, 15092 { 15093 .cmd = NL80211_CMD_START_AP, 15094 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15095 .flags = GENL_UNS_ADMIN_PERM, 15096 .doit = nl80211_start_ap, 15097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15098 }, 15099 { 15100 .cmd = NL80211_CMD_STOP_AP, 15101 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15102 .flags = GENL_UNS_ADMIN_PERM, 15103 .doit = nl80211_stop_ap, 15104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15105 }, 15106 { 15107 .cmd = NL80211_CMD_GET_STATION, 15108 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15109 .doit = nl80211_get_station, 15110 .dumpit = nl80211_dump_station, 15111 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15112 }, 15113 { 15114 .cmd = NL80211_CMD_SET_STATION, 15115 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15116 .doit = nl80211_set_station, 15117 .flags = GENL_UNS_ADMIN_PERM, 15118 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15119 }, 15120 { 15121 .cmd = NL80211_CMD_NEW_STATION, 15122 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15123 .doit = nl80211_new_station, 15124 .flags = GENL_UNS_ADMIN_PERM, 15125 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15126 }, 15127 { 15128 .cmd = NL80211_CMD_DEL_STATION, 15129 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15130 .doit = nl80211_del_station, 15131 .flags = GENL_UNS_ADMIN_PERM, 15132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15133 }, 15134 { 15135 .cmd = NL80211_CMD_GET_MPATH, 15136 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15137 .doit = nl80211_get_mpath, 15138 .dumpit = nl80211_dump_mpath, 15139 .flags = GENL_UNS_ADMIN_PERM, 15140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15141 }, 15142 { 15143 .cmd = NL80211_CMD_GET_MPP, 15144 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15145 .doit = nl80211_get_mpp, 15146 .dumpit = nl80211_dump_mpp, 15147 .flags = GENL_UNS_ADMIN_PERM, 15148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15149 }, 15150 { 15151 .cmd = NL80211_CMD_SET_MPATH, 15152 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15153 .doit = nl80211_set_mpath, 15154 .flags = GENL_UNS_ADMIN_PERM, 15155 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15156 }, 15157 { 15158 .cmd = NL80211_CMD_NEW_MPATH, 15159 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15160 .doit = nl80211_new_mpath, 15161 .flags = GENL_UNS_ADMIN_PERM, 15162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15163 }, 15164 { 15165 .cmd = NL80211_CMD_DEL_MPATH, 15166 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15167 .doit = nl80211_del_mpath, 15168 .flags = GENL_UNS_ADMIN_PERM, 15169 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15170 }, 15171 { 15172 .cmd = NL80211_CMD_SET_BSS, 15173 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15174 .doit = nl80211_set_bss, 15175 .flags = GENL_UNS_ADMIN_PERM, 15176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15177 }, 15178 { 15179 .cmd = NL80211_CMD_GET_REG, 15180 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15181 .doit = nl80211_get_reg_do, 15182 .dumpit = nl80211_get_reg_dump, 15183 .internal_flags = 0, 15184 /* can be retrieved by unprivileged users */ 15185 }, 15186 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 15187 { 15188 .cmd = NL80211_CMD_SET_REG, 15189 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15190 .doit = nl80211_set_reg, 15191 .flags = GENL_ADMIN_PERM, 15192 .internal_flags = 0, 15193 }, 15194 #endif 15195 { 15196 .cmd = NL80211_CMD_REQ_SET_REG, 15197 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15198 .doit = nl80211_req_set_reg, 15199 .flags = GENL_ADMIN_PERM, 15200 }, 15201 { 15202 .cmd = NL80211_CMD_RELOAD_REGDB, 15203 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15204 .doit = nl80211_reload_regdb, 15205 .flags = GENL_ADMIN_PERM, 15206 }, 15207 { 15208 .cmd = NL80211_CMD_GET_MESH_CONFIG, 15209 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15210 .doit = nl80211_get_mesh_config, 15211 /* can be retrieved by unprivileged users */ 15212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15213 }, 15214 { 15215 .cmd = NL80211_CMD_SET_MESH_CONFIG, 15216 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15217 .doit = nl80211_update_mesh_config, 15218 .flags = GENL_UNS_ADMIN_PERM, 15219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15220 }, 15221 { 15222 .cmd = NL80211_CMD_TRIGGER_SCAN, 15223 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15224 .doit = nl80211_trigger_scan, 15225 .flags = GENL_UNS_ADMIN_PERM, 15226 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15227 }, 15228 { 15229 .cmd = NL80211_CMD_ABORT_SCAN, 15230 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15231 .doit = nl80211_abort_scan, 15232 .flags = GENL_UNS_ADMIN_PERM, 15233 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15234 }, 15235 { 15236 .cmd = NL80211_CMD_GET_SCAN, 15237 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15238 .dumpit = nl80211_dump_scan, 15239 }, 15240 { 15241 .cmd = NL80211_CMD_START_SCHED_SCAN, 15242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15243 .doit = nl80211_start_sched_scan, 15244 .flags = GENL_UNS_ADMIN_PERM, 15245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15246 }, 15247 { 15248 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 15249 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15250 .doit = nl80211_stop_sched_scan, 15251 .flags = GENL_UNS_ADMIN_PERM, 15252 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15253 }, 15254 { 15255 .cmd = NL80211_CMD_AUTHENTICATE, 15256 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15257 .doit = nl80211_authenticate, 15258 .flags = GENL_UNS_ADMIN_PERM, 15259 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15260 0 | 15261 NL80211_FLAG_CLEAR_SKB, 15262 }, 15263 { 15264 .cmd = NL80211_CMD_ASSOCIATE, 15265 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15266 .doit = nl80211_associate, 15267 .flags = GENL_UNS_ADMIN_PERM, 15268 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15269 0 | 15270 NL80211_FLAG_CLEAR_SKB, 15271 }, 15272 { 15273 .cmd = NL80211_CMD_DEAUTHENTICATE, 15274 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15275 .doit = nl80211_deauthenticate, 15276 .flags = GENL_UNS_ADMIN_PERM, 15277 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15278 }, 15279 { 15280 .cmd = NL80211_CMD_DISASSOCIATE, 15281 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15282 .doit = nl80211_disassociate, 15283 .flags = GENL_UNS_ADMIN_PERM, 15284 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15285 }, 15286 { 15287 .cmd = NL80211_CMD_JOIN_IBSS, 15288 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15289 .doit = nl80211_join_ibss, 15290 .flags = GENL_UNS_ADMIN_PERM, 15291 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15292 }, 15293 { 15294 .cmd = NL80211_CMD_LEAVE_IBSS, 15295 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15296 .doit = nl80211_leave_ibss, 15297 .flags = GENL_UNS_ADMIN_PERM, 15298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15299 }, 15300 #ifdef CONFIG_NL80211_TESTMODE 15301 { 15302 .cmd = NL80211_CMD_TESTMODE, 15303 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15304 .doit = nl80211_testmode_do, 15305 .dumpit = nl80211_testmode_dump, 15306 .flags = GENL_UNS_ADMIN_PERM, 15307 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15308 }, 15309 #endif 15310 { 15311 .cmd = NL80211_CMD_CONNECT, 15312 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15313 .doit = nl80211_connect, 15314 .flags = GENL_UNS_ADMIN_PERM, 15315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15316 0 | 15317 NL80211_FLAG_CLEAR_SKB, 15318 }, 15319 { 15320 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 15321 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15322 .doit = nl80211_update_connect_params, 15323 .flags = GENL_ADMIN_PERM, 15324 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15325 0 | 15326 NL80211_FLAG_CLEAR_SKB, 15327 }, 15328 { 15329 .cmd = NL80211_CMD_DISCONNECT, 15330 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15331 .doit = nl80211_disconnect, 15332 .flags = GENL_UNS_ADMIN_PERM, 15333 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15334 }, 15335 { 15336 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 15337 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15338 .doit = nl80211_wiphy_netns, 15339 .flags = GENL_UNS_ADMIN_PERM, 15340 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15341 NL80211_FLAG_NEED_RTNL | 15342 NL80211_FLAG_NO_WIPHY_MTX, 15343 }, 15344 { 15345 .cmd = NL80211_CMD_GET_SURVEY, 15346 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15347 .dumpit = nl80211_dump_survey, 15348 }, 15349 { 15350 .cmd = NL80211_CMD_SET_PMKSA, 15351 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15352 .doit = nl80211_setdel_pmksa, 15353 .flags = GENL_UNS_ADMIN_PERM, 15354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15355 0 | 15356 NL80211_FLAG_CLEAR_SKB, 15357 }, 15358 { 15359 .cmd = NL80211_CMD_DEL_PMKSA, 15360 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15361 .doit = nl80211_setdel_pmksa, 15362 .flags = GENL_UNS_ADMIN_PERM, 15363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15364 }, 15365 { 15366 .cmd = NL80211_CMD_FLUSH_PMKSA, 15367 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15368 .doit = nl80211_flush_pmksa, 15369 .flags = GENL_UNS_ADMIN_PERM, 15370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15371 }, 15372 { 15373 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 15374 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15375 .doit = nl80211_remain_on_channel, 15376 .flags = GENL_UNS_ADMIN_PERM, 15377 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15378 }, 15379 { 15380 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 15381 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15382 .doit = nl80211_cancel_remain_on_channel, 15383 .flags = GENL_UNS_ADMIN_PERM, 15384 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15385 }, 15386 { 15387 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 15388 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15389 .doit = nl80211_set_tx_bitrate_mask, 15390 .flags = GENL_UNS_ADMIN_PERM, 15391 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15392 }, 15393 { 15394 .cmd = NL80211_CMD_REGISTER_FRAME, 15395 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15396 .doit = nl80211_register_mgmt, 15397 .flags = GENL_UNS_ADMIN_PERM, 15398 .internal_flags = NL80211_FLAG_NEED_WDEV, 15399 }, 15400 { 15401 .cmd = NL80211_CMD_FRAME, 15402 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15403 .doit = nl80211_tx_mgmt, 15404 .flags = GENL_UNS_ADMIN_PERM, 15405 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15406 }, 15407 { 15408 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 15409 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15410 .doit = nl80211_tx_mgmt_cancel_wait, 15411 .flags = GENL_UNS_ADMIN_PERM, 15412 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15413 }, 15414 { 15415 .cmd = NL80211_CMD_SET_POWER_SAVE, 15416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15417 .doit = nl80211_set_power_save, 15418 .flags = GENL_UNS_ADMIN_PERM, 15419 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15420 }, 15421 { 15422 .cmd = NL80211_CMD_GET_POWER_SAVE, 15423 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15424 .doit = nl80211_get_power_save, 15425 /* can be retrieved by unprivileged users */ 15426 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15427 }, 15428 { 15429 .cmd = NL80211_CMD_SET_CQM, 15430 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15431 .doit = nl80211_set_cqm, 15432 .flags = GENL_UNS_ADMIN_PERM, 15433 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15434 }, 15435 { 15436 .cmd = NL80211_CMD_SET_CHANNEL, 15437 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15438 .doit = nl80211_set_channel, 15439 .flags = GENL_UNS_ADMIN_PERM, 15440 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15441 }, 15442 { 15443 .cmd = NL80211_CMD_JOIN_MESH, 15444 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15445 .doit = nl80211_join_mesh, 15446 .flags = GENL_UNS_ADMIN_PERM, 15447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15448 }, 15449 { 15450 .cmd = NL80211_CMD_LEAVE_MESH, 15451 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15452 .doit = nl80211_leave_mesh, 15453 .flags = GENL_UNS_ADMIN_PERM, 15454 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15455 }, 15456 { 15457 .cmd = NL80211_CMD_JOIN_OCB, 15458 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15459 .doit = nl80211_join_ocb, 15460 .flags = GENL_UNS_ADMIN_PERM, 15461 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15462 }, 15463 { 15464 .cmd = NL80211_CMD_LEAVE_OCB, 15465 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15466 .doit = nl80211_leave_ocb, 15467 .flags = GENL_UNS_ADMIN_PERM, 15468 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15469 }, 15470 #ifdef CONFIG_PM 15471 { 15472 .cmd = NL80211_CMD_GET_WOWLAN, 15473 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15474 .doit = nl80211_get_wowlan, 15475 /* can be retrieved by unprivileged users */ 15476 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15477 }, 15478 { 15479 .cmd = NL80211_CMD_SET_WOWLAN, 15480 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15481 .doit = nl80211_set_wowlan, 15482 .flags = GENL_UNS_ADMIN_PERM, 15483 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15484 }, 15485 #endif 15486 { 15487 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 15488 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15489 .doit = nl80211_set_rekey_data, 15490 .flags = GENL_UNS_ADMIN_PERM, 15491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15492 0 | 15493 NL80211_FLAG_CLEAR_SKB, 15494 }, 15495 { 15496 .cmd = NL80211_CMD_TDLS_MGMT, 15497 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15498 .doit = nl80211_tdls_mgmt, 15499 .flags = GENL_UNS_ADMIN_PERM, 15500 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15501 }, 15502 { 15503 .cmd = NL80211_CMD_TDLS_OPER, 15504 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15505 .doit = nl80211_tdls_oper, 15506 .flags = GENL_UNS_ADMIN_PERM, 15507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15508 }, 15509 { 15510 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 15511 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15512 .doit = nl80211_register_unexpected_frame, 15513 .flags = GENL_UNS_ADMIN_PERM, 15514 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15515 }, 15516 { 15517 .cmd = NL80211_CMD_PROBE_CLIENT, 15518 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15519 .doit = nl80211_probe_client, 15520 .flags = GENL_UNS_ADMIN_PERM, 15521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15522 }, 15523 { 15524 .cmd = NL80211_CMD_REGISTER_BEACONS, 15525 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15526 .doit = nl80211_register_beacons, 15527 .flags = GENL_UNS_ADMIN_PERM, 15528 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15529 }, 15530 { 15531 .cmd = NL80211_CMD_SET_NOACK_MAP, 15532 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15533 .doit = nl80211_set_noack_map, 15534 .flags = GENL_UNS_ADMIN_PERM, 15535 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15536 }, 15537 { 15538 .cmd = NL80211_CMD_START_P2P_DEVICE, 15539 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15540 .doit = nl80211_start_p2p_device, 15541 .flags = GENL_UNS_ADMIN_PERM, 15542 .internal_flags = NL80211_FLAG_NEED_WDEV | 15543 NL80211_FLAG_NEED_RTNL, 15544 }, 15545 { 15546 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 15547 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15548 .doit = nl80211_stop_p2p_device, 15549 .flags = GENL_UNS_ADMIN_PERM, 15550 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15551 NL80211_FLAG_NEED_RTNL, 15552 }, 15553 { 15554 .cmd = NL80211_CMD_START_NAN, 15555 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15556 .doit = nl80211_start_nan, 15557 .flags = GENL_ADMIN_PERM, 15558 .internal_flags = NL80211_FLAG_NEED_WDEV | 15559 NL80211_FLAG_NEED_RTNL, 15560 }, 15561 { 15562 .cmd = NL80211_CMD_STOP_NAN, 15563 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15564 .doit = nl80211_stop_nan, 15565 .flags = GENL_ADMIN_PERM, 15566 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15567 NL80211_FLAG_NEED_RTNL, 15568 }, 15569 { 15570 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 15571 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15572 .doit = nl80211_nan_add_func, 15573 .flags = GENL_ADMIN_PERM, 15574 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15575 }, 15576 { 15577 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 15578 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15579 .doit = nl80211_nan_del_func, 15580 .flags = GENL_ADMIN_PERM, 15581 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15582 }, 15583 { 15584 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 15585 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15586 .doit = nl80211_nan_change_config, 15587 .flags = GENL_ADMIN_PERM, 15588 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15589 }, 15590 { 15591 .cmd = NL80211_CMD_SET_MCAST_RATE, 15592 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15593 .doit = nl80211_set_mcast_rate, 15594 .flags = GENL_UNS_ADMIN_PERM, 15595 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15596 }, 15597 { 15598 .cmd = NL80211_CMD_SET_MAC_ACL, 15599 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15600 .doit = nl80211_set_mac_acl, 15601 .flags = GENL_UNS_ADMIN_PERM, 15602 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15603 }, 15604 { 15605 .cmd = NL80211_CMD_RADAR_DETECT, 15606 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15607 .doit = nl80211_start_radar_detection, 15608 .flags = GENL_UNS_ADMIN_PERM, 15609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15610 }, 15611 { 15612 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 15613 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15614 .doit = nl80211_get_protocol_features, 15615 }, 15616 { 15617 .cmd = NL80211_CMD_UPDATE_FT_IES, 15618 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15619 .doit = nl80211_update_ft_ies, 15620 .flags = GENL_UNS_ADMIN_PERM, 15621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15622 }, 15623 { 15624 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 15625 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15626 .doit = nl80211_crit_protocol_start, 15627 .flags = GENL_UNS_ADMIN_PERM, 15628 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15629 }, 15630 { 15631 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 15632 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15633 .doit = nl80211_crit_protocol_stop, 15634 .flags = GENL_UNS_ADMIN_PERM, 15635 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15636 }, 15637 { 15638 .cmd = NL80211_CMD_GET_COALESCE, 15639 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15640 .doit = nl80211_get_coalesce, 15641 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15642 }, 15643 { 15644 .cmd = NL80211_CMD_SET_COALESCE, 15645 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15646 .doit = nl80211_set_coalesce, 15647 .flags = GENL_UNS_ADMIN_PERM, 15648 .internal_flags = NL80211_FLAG_NEED_WIPHY, 15649 }, 15650 { 15651 .cmd = NL80211_CMD_CHANNEL_SWITCH, 15652 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15653 .doit = nl80211_channel_switch, 15654 .flags = GENL_UNS_ADMIN_PERM, 15655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15656 }, 15657 { 15658 .cmd = NL80211_CMD_VENDOR, 15659 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15660 .doit = nl80211_vendor_cmd, 15661 .dumpit = nl80211_vendor_cmd_dump, 15662 .flags = GENL_UNS_ADMIN_PERM, 15663 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15664 0 | 15665 NL80211_FLAG_CLEAR_SKB, 15666 }, 15667 { 15668 .cmd = NL80211_CMD_SET_QOS_MAP, 15669 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15670 .doit = nl80211_set_qos_map, 15671 .flags = GENL_UNS_ADMIN_PERM, 15672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15673 }, 15674 { 15675 .cmd = NL80211_CMD_ADD_TX_TS, 15676 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15677 .doit = nl80211_add_tx_ts, 15678 .flags = GENL_UNS_ADMIN_PERM, 15679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15680 }, 15681 { 15682 .cmd = NL80211_CMD_DEL_TX_TS, 15683 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15684 .doit = nl80211_del_tx_ts, 15685 .flags = GENL_UNS_ADMIN_PERM, 15686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15687 }, 15688 { 15689 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 15690 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15691 .doit = nl80211_tdls_channel_switch, 15692 .flags = GENL_UNS_ADMIN_PERM, 15693 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15694 }, 15695 { 15696 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 15697 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15698 .doit = nl80211_tdls_cancel_channel_switch, 15699 .flags = GENL_UNS_ADMIN_PERM, 15700 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15701 }, 15702 { 15703 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 15704 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15705 .doit = nl80211_set_multicast_to_unicast, 15706 .flags = GENL_UNS_ADMIN_PERM, 15707 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15708 }, 15709 { 15710 .cmd = NL80211_CMD_SET_PMK, 15711 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15712 .doit = nl80211_set_pmk, 15713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15714 0 | 15715 NL80211_FLAG_CLEAR_SKB, 15716 }, 15717 { 15718 .cmd = NL80211_CMD_DEL_PMK, 15719 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15720 .doit = nl80211_del_pmk, 15721 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15722 }, 15723 { 15724 .cmd = NL80211_CMD_EXTERNAL_AUTH, 15725 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15726 .doit = nl80211_external_auth, 15727 .flags = GENL_ADMIN_PERM, 15728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15729 }, 15730 { 15731 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 15732 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15733 .doit = nl80211_tx_control_port, 15734 .flags = GENL_UNS_ADMIN_PERM, 15735 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15736 }, 15737 { 15738 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 15739 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15740 .doit = nl80211_get_ftm_responder_stats, 15741 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15742 }, 15743 { 15744 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 15745 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15746 .doit = nl80211_pmsr_start, 15747 .flags = GENL_UNS_ADMIN_PERM, 15748 .internal_flags = NL80211_FLAG_NEED_WDEV_UP, 15749 }, 15750 { 15751 .cmd = NL80211_CMD_NOTIFY_RADAR, 15752 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15753 .doit = nl80211_notify_radar_detection, 15754 .flags = GENL_UNS_ADMIN_PERM, 15755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15756 }, 15757 { 15758 .cmd = NL80211_CMD_UPDATE_OWE_INFO, 15759 .doit = nl80211_update_owe_info, 15760 .flags = GENL_ADMIN_PERM, 15761 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15762 }, 15763 { 15764 .cmd = NL80211_CMD_PROBE_MESH_LINK, 15765 .doit = nl80211_probe_mesh_link, 15766 .flags = GENL_UNS_ADMIN_PERM, 15767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, 15768 }, 15769 { 15770 .cmd = NL80211_CMD_SET_TID_CONFIG, 15771 .doit = nl80211_set_tid_config, 15772 .flags = GENL_UNS_ADMIN_PERM, 15773 .internal_flags = NL80211_FLAG_NEED_NETDEV, 15774 }, 15775 { 15776 .cmd = NL80211_CMD_SET_SAR_SPECS, 15777 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15778 .doit = nl80211_set_sar_specs, 15779 .flags = GENL_UNS_ADMIN_PERM, 15780 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15781 NL80211_FLAG_NEED_RTNL, 15782 }, 15783 }; 15784 15785 static struct genl_family nl80211_fam __ro_after_init = { 15786 .name = NL80211_GENL_NAME, /* have users key off the name instead */ 15787 .hdrsize = 0, /* no private header */ 15788 .version = 1, /* no particular meaning now */ 15789 .maxattr = NL80211_ATTR_MAX, 15790 .policy = nl80211_policy, 15791 .netnsok = true, 15792 .pre_doit = nl80211_pre_doit, 15793 .post_doit = nl80211_post_doit, 15794 .module = THIS_MODULE, 15795 .ops = nl80211_ops, 15796 .n_ops = ARRAY_SIZE(nl80211_ops), 15797 .small_ops = nl80211_small_ops, 15798 .n_small_ops = ARRAY_SIZE(nl80211_small_ops), 15799 .mcgrps = nl80211_mcgrps, 15800 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), 15801 .parallel_ops = true, 15802 }; 15803 15804 /* notification functions */ 15805 15806 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, 15807 enum nl80211_commands cmd) 15808 { 15809 struct sk_buff *msg; 15810 struct nl80211_dump_wiphy_state state = {}; 15811 15812 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && 15813 cmd != NL80211_CMD_DEL_WIPHY); 15814 15815 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15816 if (!msg) 15817 return; 15818 15819 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { 15820 nlmsg_free(msg); 15821 return; 15822 } 15823 15824 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15825 NL80211_MCGRP_CONFIG, GFP_KERNEL); 15826 } 15827 15828 void nl80211_notify_iface(struct cfg80211_registered_device *rdev, 15829 struct wireless_dev *wdev, 15830 enum nl80211_commands cmd) 15831 { 15832 struct sk_buff *msg; 15833 15834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15835 if (!msg) 15836 return; 15837 15838 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { 15839 nlmsg_free(msg); 15840 return; 15841 } 15842 15843 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15844 NL80211_MCGRP_CONFIG, GFP_KERNEL); 15845 } 15846 15847 static int nl80211_add_scan_req(struct sk_buff *msg, 15848 struct cfg80211_registered_device *rdev) 15849 { 15850 struct cfg80211_scan_request *req = rdev->scan_req; 15851 struct nlattr *nest; 15852 int i; 15853 struct cfg80211_scan_info *info; 15854 15855 if (WARN_ON(!req)) 15856 return 0; 15857 15858 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); 15859 if (!nest) 15860 goto nla_put_failure; 15861 for (i = 0; i < req->n_ssids; i++) { 15862 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 15863 goto nla_put_failure; 15864 } 15865 nla_nest_end(msg, nest); 15866 15867 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { 15868 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); 15869 if (!nest) 15870 goto nla_put_failure; 15871 for (i = 0; i < req->n_channels; i++) { 15872 if (nla_put_u32(msg, i, 15873 ieee80211_channel_to_khz(req->channels[i]))) 15874 goto nla_put_failure; 15875 } 15876 nla_nest_end(msg, nest); 15877 } else { 15878 nest = nla_nest_start_noflag(msg, 15879 NL80211_ATTR_SCAN_FREQUENCIES); 15880 if (!nest) 15881 goto nla_put_failure; 15882 for (i = 0; i < req->n_channels; i++) { 15883 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 15884 goto nla_put_failure; 15885 } 15886 nla_nest_end(msg, nest); 15887 } 15888 15889 if (req->ie && 15890 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) 15891 goto nla_put_failure; 15892 15893 if (req->flags && 15894 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) 15895 goto nla_put_failure; 15896 15897 info = rdev->int_scan_req ? &rdev->int_scan_req->info : 15898 &rdev->scan_req->info; 15899 if (info->scan_start_tsf && 15900 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, 15901 info->scan_start_tsf, NL80211_BSS_PAD) || 15902 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, 15903 info->tsf_bssid))) 15904 goto nla_put_failure; 15905 15906 return 0; 15907 nla_put_failure: 15908 return -ENOBUFS; 15909 } 15910 15911 static int nl80211_prep_scan_msg(struct sk_buff *msg, 15912 struct cfg80211_registered_device *rdev, 15913 struct wireless_dev *wdev, 15914 u32 portid, u32 seq, int flags, 15915 u32 cmd) 15916 { 15917 void *hdr; 15918 15919 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 15920 if (!hdr) 15921 return -1; 15922 15923 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15924 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 15925 wdev->netdev->ifindex)) || 15926 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 15927 NL80211_ATTR_PAD)) 15928 goto nla_put_failure; 15929 15930 /* ignore errors and send incomplete event anyway */ 15931 nl80211_add_scan_req(msg, rdev); 15932 15933 genlmsg_end(msg, hdr); 15934 return 0; 15935 15936 nla_put_failure: 15937 genlmsg_cancel(msg, hdr); 15938 return -EMSGSIZE; 15939 } 15940 15941 static int 15942 nl80211_prep_sched_scan_msg(struct sk_buff *msg, 15943 struct cfg80211_sched_scan_request *req, u32 cmd) 15944 { 15945 void *hdr; 15946 15947 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 15948 if (!hdr) 15949 return -1; 15950 15951 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, 15952 wiphy_to_rdev(req->wiphy)->wiphy_idx) || 15953 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || 15954 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, 15955 NL80211_ATTR_PAD)) 15956 goto nla_put_failure; 15957 15958 genlmsg_end(msg, hdr); 15959 return 0; 15960 15961 nla_put_failure: 15962 genlmsg_cancel(msg, hdr); 15963 return -EMSGSIZE; 15964 } 15965 15966 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 15967 struct wireless_dev *wdev) 15968 { 15969 struct sk_buff *msg; 15970 15971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15972 if (!msg) 15973 return; 15974 15975 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 15976 NL80211_CMD_TRIGGER_SCAN) < 0) { 15977 nlmsg_free(msg); 15978 return; 15979 } 15980 15981 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15982 NL80211_MCGRP_SCAN, GFP_KERNEL); 15983 } 15984 15985 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 15986 struct wireless_dev *wdev, bool aborted) 15987 { 15988 struct sk_buff *msg; 15989 15990 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15991 if (!msg) 15992 return NULL; 15993 15994 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 15995 aborted ? NL80211_CMD_SCAN_ABORTED : 15996 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 15997 nlmsg_free(msg); 15998 return NULL; 15999 } 16000 16001 return msg; 16002 } 16003 16004 /* send message created by nl80211_build_scan_msg() */ 16005 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, 16006 struct sk_buff *msg) 16007 { 16008 if (!msg) 16009 return; 16010 16011 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16012 NL80211_MCGRP_SCAN, GFP_KERNEL); 16013 } 16014 16015 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) 16016 { 16017 struct sk_buff *msg; 16018 16019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 16020 if (!msg) 16021 return; 16022 16023 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { 16024 nlmsg_free(msg); 16025 return; 16026 } 16027 16028 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, 16029 NL80211_MCGRP_SCAN, GFP_KERNEL); 16030 } 16031 16032 static bool nl80211_reg_change_event_fill(struct sk_buff *msg, 16033 struct regulatory_request *request) 16034 { 16035 /* Userspace can always count this one always being set */ 16036 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) 16037 goto nla_put_failure; 16038 16039 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { 16040 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 16041 NL80211_REGDOM_TYPE_WORLD)) 16042 goto nla_put_failure; 16043 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { 16044 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 16045 NL80211_REGDOM_TYPE_CUSTOM_WORLD)) 16046 goto nla_put_failure; 16047 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || 16048 request->intersect) { 16049 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 16050 NL80211_REGDOM_TYPE_INTERSECTION)) 16051 goto nla_put_failure; 16052 } else { 16053 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 16054 NL80211_REGDOM_TYPE_COUNTRY) || 16055 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, 16056 request->alpha2)) 16057 goto nla_put_failure; 16058 } 16059 16060 if (request->wiphy_idx != WIPHY_IDX_INVALID) { 16061 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); 16062 16063 if (wiphy && 16064 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 16065 goto nla_put_failure; 16066 16067 if (wiphy && 16068 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 16069 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 16070 goto nla_put_failure; 16071 } 16072 16073 return true; 16074 16075 nla_put_failure: 16076 return false; 16077 } 16078 16079 /* 16080 * This can happen on global regulatory changes or device specific settings 16081 * based on custom regulatory domains. 16082 */ 16083 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, 16084 struct regulatory_request *request) 16085 { 16086 struct sk_buff *msg; 16087 void *hdr; 16088 16089 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 16090 if (!msg) 16091 return; 16092 16093 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); 16094 if (!hdr) 16095 goto nla_put_failure; 16096 16097 if (!nl80211_reg_change_event_fill(msg, request)) 16098 goto nla_put_failure; 16099 16100 genlmsg_end(msg, hdr); 16101 16102 rcu_read_lock(); 16103 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 16104 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 16105 rcu_read_unlock(); 16106 16107 return; 16108 16109 nla_put_failure: 16110 nlmsg_free(msg); 16111 } 16112 16113 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 16114 struct net_device *netdev, 16115 const u8 *buf, size_t len, 16116 enum nl80211_commands cmd, gfp_t gfp, 16117 int uapsd_queues, const u8 *req_ies, 16118 size_t req_ies_len, bool reconnect) 16119 { 16120 struct sk_buff *msg; 16121 void *hdr; 16122 16123 msg = nlmsg_new(100 + len + req_ies_len, gfp); 16124 if (!msg) 16125 return; 16126 16127 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 16128 if (!hdr) { 16129 nlmsg_free(msg); 16130 return; 16131 } 16132 16133 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16134 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16135 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 16136 (req_ies && 16137 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) 16138 goto nla_put_failure; 16139 16140 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED)) 16141 goto nla_put_failure; 16142 16143 if (uapsd_queues >= 0) { 16144 struct nlattr *nla_wmm = 16145 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); 16146 if (!nla_wmm) 16147 goto nla_put_failure; 16148 16149 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, 16150 uapsd_queues)) 16151 goto nla_put_failure; 16152 16153 nla_nest_end(msg, nla_wmm); 16154 } 16155 16156 genlmsg_end(msg, hdr); 16157 16158 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16159 NL80211_MCGRP_MLME, gfp); 16160 return; 16161 16162 nla_put_failure: 16163 nlmsg_free(msg); 16164 } 16165 16166 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 16167 struct net_device *netdev, const u8 *buf, 16168 size_t len, gfp_t gfp) 16169 { 16170 nl80211_send_mlme_event(rdev, netdev, buf, len, 16171 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0, 16172 false); 16173 } 16174 16175 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 16176 struct net_device *netdev, const u8 *buf, 16177 size_t len, gfp_t gfp, int uapsd_queues, 16178 const u8 *req_ies, size_t req_ies_len) 16179 { 16180 nl80211_send_mlme_event(rdev, netdev, buf, len, 16181 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, 16182 req_ies, req_ies_len, false); 16183 } 16184 16185 void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 16186 struct net_device *netdev, const u8 *buf, 16187 size_t len, bool reconnect, gfp_t gfp) 16188 { 16189 nl80211_send_mlme_event(rdev, netdev, buf, len, 16190 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0, 16191 reconnect); 16192 } 16193 16194 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 16195 struct net_device *netdev, const u8 *buf, 16196 size_t len, bool reconnect, gfp_t gfp) 16197 { 16198 nl80211_send_mlme_event(rdev, netdev, buf, len, 16199 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0, 16200 reconnect); 16201 } 16202 16203 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, 16204 size_t len) 16205 { 16206 struct wireless_dev *wdev = dev->ieee80211_ptr; 16207 struct wiphy *wiphy = wdev->wiphy; 16208 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16209 const struct ieee80211_mgmt *mgmt = (void *)buf; 16210 u32 cmd; 16211 16212 if (WARN_ON(len < 2)) 16213 return; 16214 16215 if (ieee80211_is_deauth(mgmt->frame_control)) { 16216 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; 16217 } else if (ieee80211_is_disassoc(mgmt->frame_control)) { 16218 cmd = NL80211_CMD_UNPROT_DISASSOCIATE; 16219 } else if (ieee80211_is_beacon(mgmt->frame_control)) { 16220 if (wdev->unprot_beacon_reported && 16221 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) 16222 return; 16223 cmd = NL80211_CMD_UNPROT_BEACON; 16224 wdev->unprot_beacon_reported = jiffies; 16225 } else { 16226 return; 16227 } 16228 16229 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); 16230 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, 16231 NULL, 0, false); 16232 } 16233 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); 16234 16235 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 16236 struct net_device *netdev, int cmd, 16237 const u8 *addr, gfp_t gfp) 16238 { 16239 struct sk_buff *msg; 16240 void *hdr; 16241 16242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16243 if (!msg) 16244 return; 16245 16246 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 16247 if (!hdr) { 16248 nlmsg_free(msg); 16249 return; 16250 } 16251 16252 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16253 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16254 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 16255 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 16256 goto nla_put_failure; 16257 16258 genlmsg_end(msg, hdr); 16259 16260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16261 NL80211_MCGRP_MLME, gfp); 16262 return; 16263 16264 nla_put_failure: 16265 nlmsg_free(msg); 16266 } 16267 16268 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 16269 struct net_device *netdev, const u8 *addr, 16270 gfp_t gfp) 16271 { 16272 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 16273 addr, gfp); 16274 } 16275 16276 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 16277 struct net_device *netdev, const u8 *addr, 16278 gfp_t gfp) 16279 { 16280 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, 16281 addr, gfp); 16282 } 16283 16284 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, 16285 struct net_device *netdev, 16286 struct cfg80211_connect_resp_params *cr, 16287 gfp_t gfp) 16288 { 16289 struct sk_buff *msg; 16290 void *hdr; 16291 16292 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + 16293 cr->fils.kek_len + cr->fils.pmk_len + 16294 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); 16295 if (!msg) 16296 return; 16297 16298 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); 16299 if (!hdr) { 16300 nlmsg_free(msg); 16301 return; 16302 } 16303 16304 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16305 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16306 (cr->bssid && 16307 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || 16308 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 16309 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : 16310 cr->status) || 16311 (cr->status < 0 && 16312 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 16313 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, 16314 cr->timeout_reason))) || 16315 (cr->req_ie && 16316 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || 16317 (cr->resp_ie && 16318 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, 16319 cr->resp_ie)) || 16320 (cr->fils.update_erp_next_seq_num && 16321 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 16322 cr->fils.erp_next_seq_num)) || 16323 (cr->status == WLAN_STATUS_SUCCESS && 16324 ((cr->fils.kek && 16325 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, 16326 cr->fils.kek)) || 16327 (cr->fils.pmk && 16328 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || 16329 (cr->fils.pmkid && 16330 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) 16331 goto nla_put_failure; 16332 16333 genlmsg_end(msg, hdr); 16334 16335 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16336 NL80211_MCGRP_MLME, gfp); 16337 return; 16338 16339 nla_put_failure: 16340 nlmsg_free(msg); 16341 } 16342 16343 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 16344 struct net_device *netdev, 16345 struct cfg80211_roam_info *info, gfp_t gfp) 16346 { 16347 struct sk_buff *msg; 16348 void *hdr; 16349 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; 16350 16351 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + 16352 info->fils.kek_len + info->fils.pmk_len + 16353 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); 16354 if (!msg) 16355 return; 16356 16357 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); 16358 if (!hdr) { 16359 nlmsg_free(msg); 16360 return; 16361 } 16362 16363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16364 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || 16366 (info->req_ie && 16367 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 16368 info->req_ie)) || 16369 (info->resp_ie && 16370 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 16371 info->resp_ie)) || 16372 (info->fils.update_erp_next_seq_num && 16373 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 16374 info->fils.erp_next_seq_num)) || 16375 (info->fils.kek && 16376 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, 16377 info->fils.kek)) || 16378 (info->fils.pmk && 16379 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || 16380 (info->fils.pmkid && 16381 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) 16382 goto nla_put_failure; 16383 16384 genlmsg_end(msg, hdr); 16385 16386 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16387 NL80211_MCGRP_MLME, gfp); 16388 return; 16389 16390 nla_put_failure: 16391 nlmsg_free(msg); 16392 } 16393 16394 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, 16395 struct net_device *netdev, const u8 *bssid) 16396 { 16397 struct sk_buff *msg; 16398 void *hdr; 16399 16400 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 16401 if (!msg) 16402 return; 16403 16404 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); 16405 if (!hdr) { 16406 nlmsg_free(msg); 16407 return; 16408 } 16409 16410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16411 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16412 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 16413 goto nla_put_failure; 16414 16415 genlmsg_end(msg, hdr); 16416 16417 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16418 NL80211_MCGRP_MLME, GFP_KERNEL); 16419 return; 16420 16421 nla_put_failure: 16422 nlmsg_free(msg); 16423 } 16424 16425 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 16426 struct net_device *netdev, u16 reason, 16427 const u8 *ie, size_t ie_len, bool from_ap) 16428 { 16429 struct sk_buff *msg; 16430 void *hdr; 16431 16432 msg = nlmsg_new(100 + ie_len, GFP_KERNEL); 16433 if (!msg) 16434 return; 16435 16436 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); 16437 if (!hdr) { 16438 nlmsg_free(msg); 16439 return; 16440 } 16441 16442 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16443 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16444 (reason && 16445 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || 16446 (from_ap && 16447 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || 16448 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) 16449 goto nla_put_failure; 16450 16451 genlmsg_end(msg, hdr); 16452 16453 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16454 NL80211_MCGRP_MLME, GFP_KERNEL); 16455 return; 16456 16457 nla_put_failure: 16458 nlmsg_free(msg); 16459 } 16460 16461 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 16462 struct net_device *netdev, const u8 *bssid, 16463 gfp_t gfp) 16464 { 16465 struct sk_buff *msg; 16466 void *hdr; 16467 16468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16469 if (!msg) 16470 return; 16471 16472 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); 16473 if (!hdr) { 16474 nlmsg_free(msg); 16475 return; 16476 } 16477 16478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16480 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 16481 goto nla_put_failure; 16482 16483 genlmsg_end(msg, hdr); 16484 16485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16486 NL80211_MCGRP_MLME, gfp); 16487 return; 16488 16489 nla_put_failure: 16490 nlmsg_free(msg); 16491 } 16492 16493 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, 16494 const u8 *ie, u8 ie_len, 16495 int sig_dbm, gfp_t gfp) 16496 { 16497 struct wireless_dev *wdev = dev->ieee80211_ptr; 16498 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16499 struct sk_buff *msg; 16500 void *hdr; 16501 16502 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) 16503 return; 16504 16505 trace_cfg80211_notify_new_peer_candidate(dev, addr); 16506 16507 msg = nlmsg_new(100 + ie_len, gfp); 16508 if (!msg) 16509 return; 16510 16511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); 16512 if (!hdr) { 16513 nlmsg_free(msg); 16514 return; 16515 } 16516 16517 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16518 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16519 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 16520 (ie_len && ie && 16521 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || 16522 (sig_dbm && 16523 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) 16524 goto nla_put_failure; 16525 16526 genlmsg_end(msg, hdr); 16527 16528 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16529 NL80211_MCGRP_MLME, gfp); 16530 return; 16531 16532 nla_put_failure: 16533 nlmsg_free(msg); 16534 } 16535 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); 16536 16537 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 16538 struct net_device *netdev, const u8 *addr, 16539 enum nl80211_key_type key_type, int key_id, 16540 const u8 *tsc, gfp_t gfp) 16541 { 16542 struct sk_buff *msg; 16543 void *hdr; 16544 16545 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16546 if (!msg) 16547 return; 16548 16549 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); 16550 if (!hdr) { 16551 nlmsg_free(msg); 16552 return; 16553 } 16554 16555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16556 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16557 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || 16558 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || 16559 (key_id != -1 && 16560 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || 16561 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) 16562 goto nla_put_failure; 16563 16564 genlmsg_end(msg, hdr); 16565 16566 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16567 NL80211_MCGRP_MLME, gfp); 16568 return; 16569 16570 nla_put_failure: 16571 nlmsg_free(msg); 16572 } 16573 16574 void nl80211_send_beacon_hint_event(struct wiphy *wiphy, 16575 struct ieee80211_channel *channel_before, 16576 struct ieee80211_channel *channel_after) 16577 { 16578 struct sk_buff *msg; 16579 void *hdr; 16580 struct nlattr *nl_freq; 16581 16582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 16583 if (!msg) 16584 return; 16585 16586 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); 16587 if (!hdr) { 16588 nlmsg_free(msg); 16589 return; 16590 } 16591 16592 /* 16593 * Since we are applying the beacon hint to a wiphy we know its 16594 * wiphy_idx is valid 16595 */ 16596 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 16597 goto nla_put_failure; 16598 16599 /* Before */ 16600 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); 16601 if (!nl_freq) 16602 goto nla_put_failure; 16603 16604 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) 16605 goto nla_put_failure; 16606 nla_nest_end(msg, nl_freq); 16607 16608 /* After */ 16609 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); 16610 if (!nl_freq) 16611 goto nla_put_failure; 16612 16613 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) 16614 goto nla_put_failure; 16615 nla_nest_end(msg, nl_freq); 16616 16617 genlmsg_end(msg, hdr); 16618 16619 rcu_read_lock(); 16620 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 16621 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 16622 rcu_read_unlock(); 16623 16624 return; 16625 16626 nla_put_failure: 16627 nlmsg_free(msg); 16628 } 16629 16630 static void nl80211_send_remain_on_chan_event( 16631 int cmd, struct cfg80211_registered_device *rdev, 16632 struct wireless_dev *wdev, u64 cookie, 16633 struct ieee80211_channel *chan, 16634 unsigned int duration, gfp_t gfp) 16635 { 16636 struct sk_buff *msg; 16637 void *hdr; 16638 16639 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16640 if (!msg) 16641 return; 16642 16643 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 16644 if (!hdr) { 16645 nlmsg_free(msg); 16646 return; 16647 } 16648 16649 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16650 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16651 wdev->netdev->ifindex)) || 16652 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16653 NL80211_ATTR_PAD) || 16654 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || 16655 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 16656 NL80211_CHAN_NO_HT) || 16657 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 16658 NL80211_ATTR_PAD)) 16659 goto nla_put_failure; 16660 16661 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && 16662 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) 16663 goto nla_put_failure; 16664 16665 genlmsg_end(msg, hdr); 16666 16667 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16668 NL80211_MCGRP_MLME, gfp); 16669 return; 16670 16671 nla_put_failure: 16672 nlmsg_free(msg); 16673 } 16674 16675 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, 16676 struct ieee80211_channel *chan, 16677 unsigned int duration, gfp_t gfp) 16678 { 16679 struct wiphy *wiphy = wdev->wiphy; 16680 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16681 16682 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); 16683 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, 16684 rdev, wdev, cookie, chan, 16685 duration, gfp); 16686 } 16687 EXPORT_SYMBOL(cfg80211_ready_on_channel); 16688 16689 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, 16690 struct ieee80211_channel *chan, 16691 gfp_t gfp) 16692 { 16693 struct wiphy *wiphy = wdev->wiphy; 16694 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16695 16696 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); 16697 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 16698 rdev, wdev, cookie, chan, 0, gfp); 16699 } 16700 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); 16701 16702 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, 16703 struct ieee80211_channel *chan, 16704 gfp_t gfp) 16705 { 16706 struct wiphy *wiphy = wdev->wiphy; 16707 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16708 16709 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); 16710 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, 16711 rdev, wdev, cookie, chan, 0, gfp); 16712 } 16713 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); 16714 16715 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, 16716 struct station_info *sinfo, gfp_t gfp) 16717 { 16718 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 16719 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16720 struct sk_buff *msg; 16721 16722 trace_cfg80211_new_sta(dev, mac_addr, sinfo); 16723 16724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16725 if (!msg) 16726 return; 16727 16728 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, 16729 rdev, dev, mac_addr, sinfo) < 0) { 16730 nlmsg_free(msg); 16731 return; 16732 } 16733 16734 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16735 NL80211_MCGRP_MLME, gfp); 16736 } 16737 EXPORT_SYMBOL(cfg80211_new_sta); 16738 16739 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, 16740 struct station_info *sinfo, gfp_t gfp) 16741 { 16742 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 16743 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16744 struct sk_buff *msg; 16745 struct station_info empty_sinfo = {}; 16746 16747 if (!sinfo) 16748 sinfo = &empty_sinfo; 16749 16750 trace_cfg80211_del_sta(dev, mac_addr); 16751 16752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16753 if (!msg) { 16754 cfg80211_sinfo_release_content(sinfo); 16755 return; 16756 } 16757 16758 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, 16759 rdev, dev, mac_addr, sinfo) < 0) { 16760 nlmsg_free(msg); 16761 return; 16762 } 16763 16764 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16765 NL80211_MCGRP_MLME, gfp); 16766 } 16767 EXPORT_SYMBOL(cfg80211_del_sta_sinfo); 16768 16769 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, 16770 enum nl80211_connect_failed_reason reason, 16771 gfp_t gfp) 16772 { 16773 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 16774 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16775 struct sk_buff *msg; 16776 void *hdr; 16777 16778 msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 16779 if (!msg) 16780 return; 16781 16782 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); 16783 if (!hdr) { 16784 nlmsg_free(msg); 16785 return; 16786 } 16787 16788 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16789 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 16790 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) 16791 goto nla_put_failure; 16792 16793 genlmsg_end(msg, hdr); 16794 16795 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16796 NL80211_MCGRP_MLME, gfp); 16797 return; 16798 16799 nla_put_failure: 16800 nlmsg_free(msg); 16801 } 16802 EXPORT_SYMBOL(cfg80211_conn_failed); 16803 16804 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, 16805 const u8 *addr, gfp_t gfp) 16806 { 16807 struct wireless_dev *wdev = dev->ieee80211_ptr; 16808 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16809 struct sk_buff *msg; 16810 void *hdr; 16811 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); 16812 16813 if (!nlportid) 16814 return false; 16815 16816 msg = nlmsg_new(100, gfp); 16817 if (!msg) 16818 return true; 16819 16820 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 16821 if (!hdr) { 16822 nlmsg_free(msg); 16823 return true; 16824 } 16825 16826 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16827 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16828 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 16829 goto nla_put_failure; 16830 16831 genlmsg_end(msg, hdr); 16832 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 16833 return true; 16834 16835 nla_put_failure: 16836 nlmsg_free(msg); 16837 return true; 16838 } 16839 16840 bool cfg80211_rx_spurious_frame(struct net_device *dev, 16841 const u8 *addr, gfp_t gfp) 16842 { 16843 struct wireless_dev *wdev = dev->ieee80211_ptr; 16844 bool ret; 16845 16846 trace_cfg80211_rx_spurious_frame(dev, addr); 16847 16848 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 16849 wdev->iftype != NL80211_IFTYPE_P2P_GO)) { 16850 trace_cfg80211_return_bool(false); 16851 return false; 16852 } 16853 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, 16854 addr, gfp); 16855 trace_cfg80211_return_bool(ret); 16856 return ret; 16857 } 16858 EXPORT_SYMBOL(cfg80211_rx_spurious_frame); 16859 16860 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, 16861 const u8 *addr, gfp_t gfp) 16862 { 16863 struct wireless_dev *wdev = dev->ieee80211_ptr; 16864 bool ret; 16865 16866 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); 16867 16868 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 16869 wdev->iftype != NL80211_IFTYPE_P2P_GO && 16870 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { 16871 trace_cfg80211_return_bool(false); 16872 return false; 16873 } 16874 ret = __nl80211_unexpected_frame(dev, 16875 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, 16876 addr, gfp); 16877 trace_cfg80211_return_bool(ret); 16878 return ret; 16879 } 16880 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); 16881 16882 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, 16883 struct wireless_dev *wdev, u32 nlportid, 16884 int freq, int sig_dbm, 16885 const u8 *buf, size_t len, u32 flags, gfp_t gfp) 16886 { 16887 struct net_device *netdev = wdev->netdev; 16888 struct sk_buff *msg; 16889 void *hdr; 16890 16891 msg = nlmsg_new(100 + len, gfp); 16892 if (!msg) 16893 return -ENOMEM; 16894 16895 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 16896 if (!hdr) { 16897 nlmsg_free(msg); 16898 return -ENOMEM; 16899 } 16900 16901 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16902 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16903 netdev->ifindex)) || 16904 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16905 NL80211_ATTR_PAD) || 16906 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || 16907 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || 16908 (sig_dbm && 16909 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 16910 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 16911 (flags && 16912 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) 16913 goto nla_put_failure; 16914 16915 genlmsg_end(msg, hdr); 16916 16917 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 16918 16919 nla_put_failure: 16920 nlmsg_free(msg); 16921 return -ENOBUFS; 16922 } 16923 16924 static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, 16925 const u8 *buf, size_t len, bool ack, 16926 gfp_t gfp, enum nl80211_commands command) 16927 { 16928 struct wiphy *wiphy = wdev->wiphy; 16929 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16930 struct net_device *netdev = wdev->netdev; 16931 struct sk_buff *msg; 16932 void *hdr; 16933 16934 if (command == NL80211_CMD_FRAME_TX_STATUS) 16935 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); 16936 else 16937 trace_cfg80211_control_port_tx_status(wdev, cookie, ack); 16938 16939 msg = nlmsg_new(100 + len, gfp); 16940 if (!msg) 16941 return; 16942 16943 hdr = nl80211hdr_put(msg, 0, 0, 0, command); 16944 if (!hdr) { 16945 nlmsg_free(msg); 16946 return; 16947 } 16948 16949 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16950 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16951 netdev->ifindex)) || 16952 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16953 NL80211_ATTR_PAD) || 16954 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 16955 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 16956 NL80211_ATTR_PAD) || 16957 (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) 16958 goto nla_put_failure; 16959 16960 genlmsg_end(msg, hdr); 16961 16962 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16963 NL80211_MCGRP_MLME, gfp); 16964 return; 16965 16966 nla_put_failure: 16967 nlmsg_free(msg); 16968 } 16969 16970 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, 16971 const u8 *buf, size_t len, bool ack, 16972 gfp_t gfp) 16973 { 16974 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, 16975 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); 16976 } 16977 EXPORT_SYMBOL(cfg80211_control_port_tx_status); 16978 16979 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, 16980 const u8 *buf, size_t len, bool ack, gfp_t gfp) 16981 { 16982 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, 16983 NL80211_CMD_FRAME_TX_STATUS); 16984 } 16985 EXPORT_SYMBOL(cfg80211_mgmt_tx_status); 16986 16987 static int __nl80211_rx_control_port(struct net_device *dev, 16988 struct sk_buff *skb, 16989 bool unencrypted, gfp_t gfp) 16990 { 16991 struct wireless_dev *wdev = dev->ieee80211_ptr; 16992 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16993 struct ethhdr *ehdr = eth_hdr(skb); 16994 const u8 *addr = ehdr->h_source; 16995 u16 proto = be16_to_cpu(skb->protocol); 16996 struct sk_buff *msg; 16997 void *hdr; 16998 struct nlattr *frame; 16999 17000 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); 17001 17002 if (!nlportid) 17003 return -ENOENT; 17004 17005 msg = nlmsg_new(100 + skb->len, gfp); 17006 if (!msg) 17007 return -ENOMEM; 17008 17009 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); 17010 if (!hdr) { 17011 nlmsg_free(msg); 17012 return -ENOBUFS; 17013 } 17014 17015 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17016 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 17017 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17018 NL80211_ATTR_PAD) || 17019 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 17020 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || 17021 (unencrypted && nla_put_flag(msg, 17022 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) 17023 goto nla_put_failure; 17024 17025 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); 17026 if (!frame) 17027 goto nla_put_failure; 17028 17029 skb_copy_bits(skb, 0, nla_data(frame), skb->len); 17030 genlmsg_end(msg, hdr); 17031 17032 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 17033 17034 nla_put_failure: 17035 nlmsg_free(msg); 17036 return -ENOBUFS; 17037 } 17038 17039 bool cfg80211_rx_control_port(struct net_device *dev, 17040 struct sk_buff *skb, bool unencrypted) 17041 { 17042 int ret; 17043 17044 trace_cfg80211_rx_control_port(dev, skb, unencrypted); 17045 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); 17046 trace_cfg80211_return_bool(ret == 0); 17047 return ret == 0; 17048 } 17049 EXPORT_SYMBOL(cfg80211_rx_control_port); 17050 17051 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 17052 const char *mac, gfp_t gfp) 17053 { 17054 struct wireless_dev *wdev = dev->ieee80211_ptr; 17055 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17056 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17057 void **cb; 17058 17059 if (!msg) 17060 return NULL; 17061 17062 cb = (void **)msg->cb; 17063 17064 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 17065 if (!cb[0]) { 17066 nlmsg_free(msg); 17067 return NULL; 17068 } 17069 17070 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17071 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 17072 goto nla_put_failure; 17073 17074 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 17075 goto nla_put_failure; 17076 17077 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); 17078 if (!cb[1]) 17079 goto nla_put_failure; 17080 17081 cb[2] = rdev; 17082 17083 return msg; 17084 nla_put_failure: 17085 nlmsg_free(msg); 17086 return NULL; 17087 } 17088 17089 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) 17090 { 17091 void **cb = (void **)msg->cb; 17092 struct cfg80211_registered_device *rdev = cb[2]; 17093 17094 nla_nest_end(msg, cb[1]); 17095 genlmsg_end(msg, cb[0]); 17096 17097 memset(msg->cb, 0, sizeof(msg->cb)); 17098 17099 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17100 NL80211_MCGRP_MLME, gfp); 17101 } 17102 17103 void cfg80211_cqm_rssi_notify(struct net_device *dev, 17104 enum nl80211_cqm_rssi_threshold_event rssi_event, 17105 s32 rssi_level, gfp_t gfp) 17106 { 17107 struct sk_buff *msg; 17108 struct wireless_dev *wdev = dev->ieee80211_ptr; 17109 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17110 17111 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); 17112 17113 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && 17114 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) 17115 return; 17116 17117 if (wdev->cqm_config) { 17118 wdev->cqm_config->last_rssi_event_value = rssi_level; 17119 17120 cfg80211_cqm_rssi_update(rdev, dev); 17121 17122 if (rssi_level == 0) 17123 rssi_level = wdev->cqm_config->last_rssi_event_value; 17124 } 17125 17126 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 17127 if (!msg) 17128 return; 17129 17130 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 17131 rssi_event)) 17132 goto nla_put_failure; 17133 17134 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, 17135 rssi_level)) 17136 goto nla_put_failure; 17137 17138 cfg80211_send_cqm(msg, gfp); 17139 17140 return; 17141 17142 nla_put_failure: 17143 nlmsg_free(msg); 17144 } 17145 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 17146 17147 void cfg80211_cqm_txe_notify(struct net_device *dev, 17148 const u8 *peer, u32 num_packets, 17149 u32 rate, u32 intvl, gfp_t gfp) 17150 { 17151 struct sk_buff *msg; 17152 17153 msg = cfg80211_prepare_cqm(dev, peer, gfp); 17154 if (!msg) 17155 return; 17156 17157 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 17158 goto nla_put_failure; 17159 17160 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 17161 goto nla_put_failure; 17162 17163 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 17164 goto nla_put_failure; 17165 17166 cfg80211_send_cqm(msg, gfp); 17167 return; 17168 17169 nla_put_failure: 17170 nlmsg_free(msg); 17171 } 17172 EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 17173 17174 void cfg80211_cqm_pktloss_notify(struct net_device *dev, 17175 const u8 *peer, u32 num_packets, gfp_t gfp) 17176 { 17177 struct sk_buff *msg; 17178 17179 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 17180 17181 msg = cfg80211_prepare_cqm(dev, peer, gfp); 17182 if (!msg) 17183 return; 17184 17185 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 17186 goto nla_put_failure; 17187 17188 cfg80211_send_cqm(msg, gfp); 17189 return; 17190 17191 nla_put_failure: 17192 nlmsg_free(msg); 17193 } 17194 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 17195 17196 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) 17197 { 17198 struct sk_buff *msg; 17199 17200 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 17201 if (!msg) 17202 return; 17203 17204 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) 17205 goto nla_put_failure; 17206 17207 cfg80211_send_cqm(msg, gfp); 17208 return; 17209 17210 nla_put_failure: 17211 nlmsg_free(msg); 17212 } 17213 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); 17214 17215 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 17216 struct net_device *netdev, const u8 *bssid, 17217 const u8 *replay_ctr, gfp_t gfp) 17218 { 17219 struct sk_buff *msg; 17220 struct nlattr *rekey_attr; 17221 void *hdr; 17222 17223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17224 if (!msg) 17225 return; 17226 17227 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); 17228 if (!hdr) { 17229 nlmsg_free(msg); 17230 return; 17231 } 17232 17233 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17234 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17235 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 17236 goto nla_put_failure; 17237 17238 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); 17239 if (!rekey_attr) 17240 goto nla_put_failure; 17241 17242 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, 17243 NL80211_REPLAY_CTR_LEN, replay_ctr)) 17244 goto nla_put_failure; 17245 17246 nla_nest_end(msg, rekey_attr); 17247 17248 genlmsg_end(msg, hdr); 17249 17250 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17251 NL80211_MCGRP_MLME, gfp); 17252 return; 17253 17254 nla_put_failure: 17255 nlmsg_free(msg); 17256 } 17257 17258 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, 17259 const u8 *replay_ctr, gfp_t gfp) 17260 { 17261 struct wireless_dev *wdev = dev->ieee80211_ptr; 17262 struct wiphy *wiphy = wdev->wiphy; 17263 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17264 17265 trace_cfg80211_gtk_rekey_notify(dev, bssid); 17266 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); 17267 } 17268 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); 17269 17270 static void 17271 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, 17272 struct net_device *netdev, int index, 17273 const u8 *bssid, bool preauth, gfp_t gfp) 17274 { 17275 struct sk_buff *msg; 17276 struct nlattr *attr; 17277 void *hdr; 17278 17279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17280 if (!msg) 17281 return; 17282 17283 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); 17284 if (!hdr) { 17285 nlmsg_free(msg); 17286 return; 17287 } 17288 17289 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17290 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 17291 goto nla_put_failure; 17292 17293 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); 17294 if (!attr) 17295 goto nla_put_failure; 17296 17297 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || 17298 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || 17299 (preauth && 17300 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) 17301 goto nla_put_failure; 17302 17303 nla_nest_end(msg, attr); 17304 17305 genlmsg_end(msg, hdr); 17306 17307 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17308 NL80211_MCGRP_MLME, gfp); 17309 return; 17310 17311 nla_put_failure: 17312 nlmsg_free(msg); 17313 } 17314 17315 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, 17316 const u8 *bssid, bool preauth, gfp_t gfp) 17317 { 17318 struct wireless_dev *wdev = dev->ieee80211_ptr; 17319 struct wiphy *wiphy = wdev->wiphy; 17320 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17321 17322 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); 17323 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 17324 } 17325 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 17326 17327 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, 17328 struct net_device *netdev, 17329 struct cfg80211_chan_def *chandef, 17330 gfp_t gfp, 17331 enum nl80211_commands notif, 17332 u8 count, bool quiet) 17333 { 17334 struct sk_buff *msg; 17335 void *hdr; 17336 17337 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17338 if (!msg) 17339 return; 17340 17341 hdr = nl80211hdr_put(msg, 0, 0, 0, notif); 17342 if (!hdr) { 17343 nlmsg_free(msg); 17344 return; 17345 } 17346 17347 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 17348 goto nla_put_failure; 17349 17350 if (nl80211_send_chandef(msg, chandef)) 17351 goto nla_put_failure; 17352 17353 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) { 17354 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)) 17355 goto nla_put_failure; 17356 if (quiet && 17357 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) 17358 goto nla_put_failure; 17359 } 17360 17361 genlmsg_end(msg, hdr); 17362 17363 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17364 NL80211_MCGRP_MLME, gfp); 17365 return; 17366 17367 nla_put_failure: 17368 nlmsg_free(msg); 17369 } 17370 17371 void cfg80211_ch_switch_notify(struct net_device *dev, 17372 struct cfg80211_chan_def *chandef) 17373 { 17374 struct wireless_dev *wdev = dev->ieee80211_ptr; 17375 struct wiphy *wiphy = wdev->wiphy; 17376 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17377 17378 ASSERT_WDEV_LOCK(wdev); 17379 17380 trace_cfg80211_ch_switch_notify(dev, chandef); 17381 17382 wdev->chandef = *chandef; 17383 wdev->preset_chandef = *chandef; 17384 17385 if (wdev->iftype == NL80211_IFTYPE_STATION && 17386 !WARN_ON(!wdev->current_bss)) 17387 cfg80211_update_assoc_bss_entry(wdev, chandef->chan); 17388 17389 cfg80211_sched_dfs_chan_update(rdev); 17390 17391 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 17392 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false); 17393 } 17394 EXPORT_SYMBOL(cfg80211_ch_switch_notify); 17395 17396 void cfg80211_ch_switch_started_notify(struct net_device *dev, 17397 struct cfg80211_chan_def *chandef, 17398 u8 count, bool quiet) 17399 { 17400 struct wireless_dev *wdev = dev->ieee80211_ptr; 17401 struct wiphy *wiphy = wdev->wiphy; 17402 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17403 17404 trace_cfg80211_ch_switch_started_notify(dev, chandef); 17405 17406 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 17407 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, 17408 count, quiet); 17409 } 17410 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 17411 17412 void 17413 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 17414 const struct cfg80211_chan_def *chandef, 17415 enum nl80211_radar_event event, 17416 struct net_device *netdev, gfp_t gfp) 17417 { 17418 struct sk_buff *msg; 17419 void *hdr; 17420 17421 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17422 if (!msg) 17423 return; 17424 17425 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); 17426 if (!hdr) { 17427 nlmsg_free(msg); 17428 return; 17429 } 17430 17431 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 17432 goto nla_put_failure; 17433 17434 /* NOP and radar events don't need a netdev parameter */ 17435 if (netdev) { 17436 struct wireless_dev *wdev = netdev->ieee80211_ptr; 17437 17438 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17439 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17440 NL80211_ATTR_PAD)) 17441 goto nla_put_failure; 17442 } 17443 17444 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) 17445 goto nla_put_failure; 17446 17447 if (nl80211_send_chandef(msg, chandef)) 17448 goto nla_put_failure; 17449 17450 genlmsg_end(msg, hdr); 17451 17452 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17453 NL80211_MCGRP_MLME, gfp); 17454 return; 17455 17456 nla_put_failure: 17457 nlmsg_free(msg); 17458 } 17459 17460 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, 17461 struct sta_opmode_info *sta_opmode, 17462 gfp_t gfp) 17463 { 17464 struct sk_buff *msg; 17465 struct wireless_dev *wdev = dev->ieee80211_ptr; 17466 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17467 void *hdr; 17468 17469 if (WARN_ON(!mac)) 17470 return; 17471 17472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17473 if (!msg) 17474 return; 17475 17476 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); 17477 if (!hdr) { 17478 nlmsg_free(msg); 17479 return; 17480 } 17481 17482 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 17483 goto nla_put_failure; 17484 17485 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 17486 goto nla_put_failure; 17487 17488 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 17489 goto nla_put_failure; 17490 17491 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && 17492 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) 17493 goto nla_put_failure; 17494 17495 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && 17496 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) 17497 goto nla_put_failure; 17498 17499 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && 17500 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) 17501 goto nla_put_failure; 17502 17503 genlmsg_end(msg, hdr); 17504 17505 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17506 NL80211_MCGRP_MLME, gfp); 17507 17508 return; 17509 17510 nla_put_failure: 17511 nlmsg_free(msg); 17512 } 17513 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); 17514 17515 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 17516 u64 cookie, bool acked, s32 ack_signal, 17517 bool is_valid_ack_signal, gfp_t gfp) 17518 { 17519 struct wireless_dev *wdev = dev->ieee80211_ptr; 17520 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17521 struct sk_buff *msg; 17522 void *hdr; 17523 17524 trace_cfg80211_probe_status(dev, addr, cookie, acked); 17525 17526 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17527 17528 if (!msg) 17529 return; 17530 17531 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); 17532 if (!hdr) { 17533 nlmsg_free(msg); 17534 return; 17535 } 17536 17537 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17538 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 17539 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 17540 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 17541 NL80211_ATTR_PAD) || 17542 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || 17543 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, 17544 ack_signal))) 17545 goto nla_put_failure; 17546 17547 genlmsg_end(msg, hdr); 17548 17549 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17550 NL80211_MCGRP_MLME, gfp); 17551 return; 17552 17553 nla_put_failure: 17554 nlmsg_free(msg); 17555 } 17556 EXPORT_SYMBOL(cfg80211_probe_status); 17557 17558 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, 17559 size_t len, int freq, int sig_dbm) 17560 { 17561 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17562 struct sk_buff *msg; 17563 void *hdr; 17564 struct cfg80211_beacon_registration *reg; 17565 17566 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); 17567 17568 spin_lock_bh(&rdev->beacon_registrations_lock); 17569 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 17570 msg = nlmsg_new(len + 100, GFP_ATOMIC); 17571 if (!msg) { 17572 spin_unlock_bh(&rdev->beacon_registrations_lock); 17573 return; 17574 } 17575 17576 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 17577 if (!hdr) 17578 goto nla_put_failure; 17579 17580 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17581 (freq && 17582 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 17583 KHZ_TO_MHZ(freq)) || 17584 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 17585 freq % 1000))) || 17586 (sig_dbm && 17587 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 17588 nla_put(msg, NL80211_ATTR_FRAME, len, frame)) 17589 goto nla_put_failure; 17590 17591 genlmsg_end(msg, hdr); 17592 17593 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); 17594 } 17595 spin_unlock_bh(&rdev->beacon_registrations_lock); 17596 return; 17597 17598 nla_put_failure: 17599 spin_unlock_bh(&rdev->beacon_registrations_lock); 17600 nlmsg_free(msg); 17601 } 17602 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); 17603 17604 #ifdef CONFIG_PM 17605 static int cfg80211_net_detect_results(struct sk_buff *msg, 17606 struct cfg80211_wowlan_wakeup *wakeup) 17607 { 17608 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; 17609 struct nlattr *nl_results, *nl_match, *nl_freqs; 17610 int i, j; 17611 17612 nl_results = nla_nest_start_noflag(msg, 17613 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 17614 if (!nl_results) 17615 return -EMSGSIZE; 17616 17617 for (i = 0; i < nd->n_matches; i++) { 17618 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 17619 17620 nl_match = nla_nest_start_noflag(msg, i); 17621 if (!nl_match) 17622 break; 17623 17624 /* The SSID attribute is optional in nl80211, but for 17625 * simplicity reasons it's always present in the 17626 * cfg80211 structure. If a driver can't pass the 17627 * SSID, that needs to be changed. A zero length SSID 17628 * is still a valid SSID (wildcard), so it cannot be 17629 * used for this purpose. 17630 */ 17631 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, 17632 match->ssid.ssid)) { 17633 nla_nest_cancel(msg, nl_match); 17634 goto out; 17635 } 17636 17637 if (match->n_channels) { 17638 nl_freqs = nla_nest_start_noflag(msg, 17639 NL80211_ATTR_SCAN_FREQUENCIES); 17640 if (!nl_freqs) { 17641 nla_nest_cancel(msg, nl_match); 17642 goto out; 17643 } 17644 17645 for (j = 0; j < match->n_channels; j++) { 17646 if (nla_put_u32(msg, j, match->channels[j])) { 17647 nla_nest_cancel(msg, nl_freqs); 17648 nla_nest_cancel(msg, nl_match); 17649 goto out; 17650 } 17651 } 17652 17653 nla_nest_end(msg, nl_freqs); 17654 } 17655 17656 nla_nest_end(msg, nl_match); 17657 } 17658 17659 out: 17660 nla_nest_end(msg, nl_results); 17661 return 0; 17662 } 17663 17664 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, 17665 struct cfg80211_wowlan_wakeup *wakeup, 17666 gfp_t gfp) 17667 { 17668 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17669 struct sk_buff *msg; 17670 void *hdr; 17671 int size = 200; 17672 17673 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); 17674 17675 if (wakeup) 17676 size += wakeup->packet_present_len; 17677 17678 msg = nlmsg_new(size, gfp); 17679 if (!msg) 17680 return; 17681 17682 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); 17683 if (!hdr) 17684 goto free_msg; 17685 17686 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17687 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17688 NL80211_ATTR_PAD)) 17689 goto free_msg; 17690 17691 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 17692 wdev->netdev->ifindex)) 17693 goto free_msg; 17694 17695 if (wakeup) { 17696 struct nlattr *reasons; 17697 17698 reasons = nla_nest_start_noflag(msg, 17699 NL80211_ATTR_WOWLAN_TRIGGERS); 17700 if (!reasons) 17701 goto free_msg; 17702 17703 if (wakeup->disconnect && 17704 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) 17705 goto free_msg; 17706 if (wakeup->magic_pkt && 17707 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) 17708 goto free_msg; 17709 if (wakeup->gtk_rekey_failure && 17710 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) 17711 goto free_msg; 17712 if (wakeup->eap_identity_req && 17713 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) 17714 goto free_msg; 17715 if (wakeup->four_way_handshake && 17716 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) 17717 goto free_msg; 17718 if (wakeup->rfkill_release && 17719 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) 17720 goto free_msg; 17721 17722 if (wakeup->pattern_idx >= 0 && 17723 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 17724 wakeup->pattern_idx)) 17725 goto free_msg; 17726 17727 if (wakeup->tcp_match && 17728 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) 17729 goto free_msg; 17730 17731 if (wakeup->tcp_connlost && 17732 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) 17733 goto free_msg; 17734 17735 if (wakeup->tcp_nomoretokens && 17736 nla_put_flag(msg, 17737 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) 17738 goto free_msg; 17739 17740 if (wakeup->packet) { 17741 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; 17742 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; 17743 17744 if (!wakeup->packet_80211) { 17745 pkt_attr = 17746 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; 17747 len_attr = 17748 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; 17749 } 17750 17751 if (wakeup->packet_len && 17752 nla_put_u32(msg, len_attr, wakeup->packet_len)) 17753 goto free_msg; 17754 17755 if (nla_put(msg, pkt_attr, wakeup->packet_present_len, 17756 wakeup->packet)) 17757 goto free_msg; 17758 } 17759 17760 if (wakeup->net_detect && 17761 cfg80211_net_detect_results(msg, wakeup)) 17762 goto free_msg; 17763 17764 nla_nest_end(msg, reasons); 17765 } 17766 17767 genlmsg_end(msg, hdr); 17768 17769 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17770 NL80211_MCGRP_MLME, gfp); 17771 return; 17772 17773 free_msg: 17774 nlmsg_free(msg); 17775 } 17776 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); 17777 #endif 17778 17779 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, 17780 enum nl80211_tdls_operation oper, 17781 u16 reason_code, gfp_t gfp) 17782 { 17783 struct wireless_dev *wdev = dev->ieee80211_ptr; 17784 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17785 struct sk_buff *msg; 17786 void *hdr; 17787 17788 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, 17789 reason_code); 17790 17791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17792 if (!msg) 17793 return; 17794 17795 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); 17796 if (!hdr) { 17797 nlmsg_free(msg); 17798 return; 17799 } 17800 17801 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17802 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 17803 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || 17804 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || 17805 (reason_code > 0 && 17806 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) 17807 goto nla_put_failure; 17808 17809 genlmsg_end(msg, hdr); 17810 17811 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17812 NL80211_MCGRP_MLME, gfp); 17813 return; 17814 17815 nla_put_failure: 17816 nlmsg_free(msg); 17817 } 17818 EXPORT_SYMBOL(cfg80211_tdls_oper_request); 17819 17820 static int nl80211_netlink_notify(struct notifier_block * nb, 17821 unsigned long state, 17822 void *_notify) 17823 { 17824 struct netlink_notify *notify = _notify; 17825 struct cfg80211_registered_device *rdev; 17826 struct wireless_dev *wdev; 17827 struct cfg80211_beacon_registration *reg, *tmp; 17828 17829 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) 17830 return NOTIFY_DONE; 17831 17832 rcu_read_lock(); 17833 17834 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 17835 struct cfg80211_sched_scan_request *sched_scan_req; 17836 17837 list_for_each_entry_rcu(sched_scan_req, 17838 &rdev->sched_scan_req_list, 17839 list) { 17840 if (sched_scan_req->owner_nlportid == notify->portid) { 17841 sched_scan_req->nl_owner_dead = true; 17842 schedule_work(&rdev->sched_scan_stop_wk); 17843 } 17844 } 17845 17846 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { 17847 cfg80211_mlme_unregister_socket(wdev, notify->portid); 17848 17849 if (wdev->owner_nlportid == notify->portid) { 17850 wdev->nl_owner_dead = true; 17851 schedule_work(&rdev->destroy_work); 17852 } else if (wdev->conn_owner_nlportid == notify->portid) { 17853 schedule_work(&wdev->disconnect_wk); 17854 } 17855 17856 cfg80211_release_pmsr(wdev, notify->portid); 17857 } 17858 17859 spin_lock_bh(&rdev->beacon_registrations_lock); 17860 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, 17861 list) { 17862 if (reg->nlportid == notify->portid) { 17863 list_del(®->list); 17864 kfree(reg); 17865 break; 17866 } 17867 } 17868 spin_unlock_bh(&rdev->beacon_registrations_lock); 17869 } 17870 17871 rcu_read_unlock(); 17872 17873 /* 17874 * It is possible that the user space process that is controlling the 17875 * indoor setting disappeared, so notify the regulatory core. 17876 */ 17877 regulatory_netlink_notify(notify->portid); 17878 return NOTIFY_OK; 17879 } 17880 17881 static struct notifier_block nl80211_netlink_notifier = { 17882 .notifier_call = nl80211_netlink_notify, 17883 }; 17884 17885 void cfg80211_ft_event(struct net_device *netdev, 17886 struct cfg80211_ft_event_params *ft_event) 17887 { 17888 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 17889 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17890 struct sk_buff *msg; 17891 void *hdr; 17892 17893 trace_cfg80211_ft_event(wiphy, netdev, ft_event); 17894 17895 if (!ft_event->target_ap) 17896 return; 17897 17898 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, 17899 GFP_KERNEL); 17900 if (!msg) 17901 return; 17902 17903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); 17904 if (!hdr) 17905 goto out; 17906 17907 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17908 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17909 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) 17910 goto out; 17911 17912 if (ft_event->ies && 17913 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) 17914 goto out; 17915 if (ft_event->ric_ies && 17916 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, 17917 ft_event->ric_ies)) 17918 goto out; 17919 17920 genlmsg_end(msg, hdr); 17921 17922 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17923 NL80211_MCGRP_MLME, GFP_KERNEL); 17924 return; 17925 out: 17926 nlmsg_free(msg); 17927 } 17928 EXPORT_SYMBOL(cfg80211_ft_event); 17929 17930 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) 17931 { 17932 struct cfg80211_registered_device *rdev; 17933 struct sk_buff *msg; 17934 void *hdr; 17935 u32 nlportid; 17936 17937 rdev = wiphy_to_rdev(wdev->wiphy); 17938 if (!rdev->crit_proto_nlportid) 17939 return; 17940 17941 nlportid = rdev->crit_proto_nlportid; 17942 rdev->crit_proto_nlportid = 0; 17943 17944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17945 if (!msg) 17946 return; 17947 17948 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); 17949 if (!hdr) 17950 goto nla_put_failure; 17951 17952 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17953 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17954 NL80211_ATTR_PAD)) 17955 goto nla_put_failure; 17956 17957 genlmsg_end(msg, hdr); 17958 17959 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 17960 return; 17961 17962 nla_put_failure: 17963 nlmsg_free(msg); 17964 } 17965 EXPORT_SYMBOL(cfg80211_crit_proto_stopped); 17966 17967 void nl80211_send_ap_stopped(struct wireless_dev *wdev) 17968 { 17969 struct wiphy *wiphy = wdev->wiphy; 17970 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17971 struct sk_buff *msg; 17972 void *hdr; 17973 17974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17975 if (!msg) 17976 return; 17977 17978 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); 17979 if (!hdr) 17980 goto out; 17981 17982 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17983 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 17984 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17985 NL80211_ATTR_PAD)) 17986 goto out; 17987 17988 genlmsg_end(msg, hdr); 17989 17990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 17991 NL80211_MCGRP_MLME, GFP_KERNEL); 17992 return; 17993 out: 17994 nlmsg_free(msg); 17995 } 17996 17997 int cfg80211_external_auth_request(struct net_device *dev, 17998 struct cfg80211_external_auth_params *params, 17999 gfp_t gfp) 18000 { 18001 struct wireless_dev *wdev = dev->ieee80211_ptr; 18002 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18003 struct sk_buff *msg; 18004 void *hdr; 18005 18006 if (!wdev->conn_owner_nlportid) 18007 return -EINVAL; 18008 18009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18010 if (!msg) 18011 return -ENOMEM; 18012 18013 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); 18014 if (!hdr) 18015 goto nla_put_failure; 18016 18017 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18018 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18019 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || 18020 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, 18021 params->action) || 18022 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || 18023 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, 18024 params->ssid.ssid)) 18025 goto nla_put_failure; 18026 18027 genlmsg_end(msg, hdr); 18028 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 18029 wdev->conn_owner_nlportid); 18030 return 0; 18031 18032 nla_put_failure: 18033 nlmsg_free(msg); 18034 return -ENOBUFS; 18035 } 18036 EXPORT_SYMBOL(cfg80211_external_auth_request); 18037 18038 void cfg80211_update_owe_info_event(struct net_device *netdev, 18039 struct cfg80211_update_owe_info *owe_info, 18040 gfp_t gfp) 18041 { 18042 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 18043 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18044 struct sk_buff *msg; 18045 void *hdr; 18046 18047 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); 18048 18049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18050 if (!msg) 18051 return; 18052 18053 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); 18054 if (!hdr) 18055 goto nla_put_failure; 18056 18057 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18058 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18059 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) 18060 goto nla_put_failure; 18061 18062 if (!owe_info->ie_len || 18063 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) 18064 goto nla_put_failure; 18065 18066 genlmsg_end(msg, hdr); 18067 18068 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18069 NL80211_MCGRP_MLME, gfp); 18070 return; 18071 18072 nla_put_failure: 18073 genlmsg_cancel(msg, hdr); 18074 nlmsg_free(msg); 18075 } 18076 EXPORT_SYMBOL(cfg80211_update_owe_info_event); 18077 18078 /* initialisation/exit functions */ 18079 18080 int __init nl80211_init(void) 18081 { 18082 int err; 18083 18084 err = genl_register_family(&nl80211_fam); 18085 if (err) 18086 return err; 18087 18088 err = netlink_register_notifier(&nl80211_netlink_notifier); 18089 if (err) 18090 goto err_out; 18091 18092 return 0; 18093 err_out: 18094 genl_unregister_family(&nl80211_fam); 18095 return err; 18096 } 18097 18098 void nl80211_exit(void) 18099 { 18100 netlink_unregister_notifier(&nl80211_netlink_notifier); 18101 genl_unregister_family(&nl80211_fam); 18102 } 18103