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-2022 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 static int validate_he_capa(const struct nlattr *attr, 289 struct netlink_ext_ack *extack) 290 { 291 if (!ieee80211_he_capa_size_ok(nla_data(attr), nla_len(attr))) 292 return -EINVAL; 293 294 return 0; 295 } 296 297 /* policy for the attributes */ 298 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; 299 300 static const struct nla_policy 301 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { 302 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, 303 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, 304 .len = U8_MAX }, 305 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, 306 .len = U8_MAX }, 307 }; 308 309 static const struct nla_policy 310 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { 311 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, 312 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, 313 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = 314 NLA_POLICY_MAX(NLA_U8, 15), 315 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, 316 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = 317 NLA_POLICY_MAX(NLA_U8, 15), 318 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = 319 NLA_POLICY_MAX(NLA_U8, 31), 320 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, 321 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, 322 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, 323 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, 324 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, 325 [NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK] = { .type = NLA_FLAG }, 326 }; 327 328 static const struct nla_policy 329 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { 330 [NL80211_PMSR_TYPE_FTM] = 331 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), 332 }; 333 334 static const struct nla_policy 335 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { 336 [NL80211_PMSR_REQ_ATTR_DATA] = 337 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), 338 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, 339 }; 340 341 static const struct nla_policy 342 nl80211_pmsr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { 343 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, 344 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), 345 [NL80211_PMSR_PEER_ATTR_REQ] = 346 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), 347 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, 348 }; 349 350 static const struct nla_policy 351 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { 352 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, 353 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, 354 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, 355 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, 356 [NL80211_PMSR_ATTR_PEERS] = 357 NLA_POLICY_NESTED_ARRAY(nl80211_pmsr_peer_attr_policy), 358 }; 359 360 static const struct nla_policy 361 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { 362 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = 363 NLA_POLICY_RANGE(NLA_U8, 1, 20), 364 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = 365 NLA_POLICY_RANGE(NLA_U8, 1, 20), 366 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = 367 NLA_POLICY_RANGE(NLA_U8, 1, 20), 368 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = 369 NLA_POLICY_EXACT_LEN(8), 370 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = 371 NLA_POLICY_EXACT_LEN(8), 372 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, 373 }; 374 375 static const struct nla_policy 376 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { 377 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), 378 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, 379 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, 380 }; 381 382 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { 383 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, 384 .len = NL80211_MAX_SUPP_RATES }, 385 [NL80211_TXRATE_HT] = { .type = NLA_BINARY, 386 .len = NL80211_MAX_SUPP_HT_RATES }, 387 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), 388 [NL80211_TXRATE_GI] = { .type = NLA_U8 }, 389 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), 390 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, 391 NL80211_RATE_INFO_HE_GI_0_8, 392 NL80211_RATE_INFO_HE_GI_3_2), 393 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, 394 NL80211_RATE_INFO_HE_1XLTF, 395 NL80211_RATE_INFO_HE_4XLTF), 396 }; 397 398 static const struct nla_policy 399 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { 400 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, 401 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, 402 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, 403 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), 404 [NL80211_TID_CONFIG_ATTR_NOACK] = 405 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 406 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 407 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 408 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = 409 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 410 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = 411 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 412 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = 413 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 414 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = 415 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), 416 [NL80211_TID_CONFIG_ATTR_TX_RATE] = 417 NLA_POLICY_NESTED(nl80211_txattr_policy), 418 }; 419 420 static const struct nla_policy 421 nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { 422 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), 423 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), 424 [NL80211_FILS_DISCOVERY_ATTR_TMPL] = 425 NLA_POLICY_RANGE(NLA_BINARY, 426 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, 427 IEEE80211_MAX_DATA_LEN), 428 }; 429 430 static const struct nla_policy 431 nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { 432 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), 433 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, 434 .len = IEEE80211_MAX_DATA_LEN } 435 }; 436 437 static const struct nla_policy 438 sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = { 439 [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 }, 440 [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 }, 441 }; 442 443 static const struct nla_policy 444 sar_policy[NL80211_SAR_ATTR_MAX + 1] = { 445 [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE), 446 [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy), 447 }; 448 449 static const struct nla_policy 450 nl80211_mbssid_config_policy[NL80211_MBSSID_CONFIG_ATTR_MAX + 1] = { 451 [NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES] = NLA_POLICY_MIN(NLA_U8, 2), 452 [NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY] = 453 NLA_POLICY_MIN(NLA_U8, 1), 454 [NL80211_MBSSID_CONFIG_ATTR_INDEX] = { .type = NLA_U8 }, 455 [NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX] = { .type = NLA_U32 }, 456 [NL80211_MBSSID_CONFIG_ATTR_EMA] = { .type = NLA_FLAG }, 457 }; 458 459 static const struct nla_policy 460 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { 461 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, 462 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, 463 }; 464 465 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { 466 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, 467 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 468 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 469 .len = 20-1 }, 470 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, 471 472 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, 473 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, 474 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, 475 NL80211_EDMG_CHANNELS_MIN, 476 NL80211_EDMG_CHANNELS_MAX), 477 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, 478 NL80211_EDMG_BW_CONFIG_MIN, 479 NL80211_EDMG_BW_CONFIG_MAX), 480 481 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, 482 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, 483 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 484 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, 485 486 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 487 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 488 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, 489 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, 490 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, 491 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, 492 493 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), 494 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 495 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, 496 497 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 498 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 499 500 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, 501 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, 502 .len = WLAN_MAX_KEY_LEN }, 503 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), 504 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, 505 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, 506 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 507 [NL80211_ATTR_KEY_TYPE] = 508 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), 509 510 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 511 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 512 [NL80211_ATTR_BEACON_HEAD] = 513 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, 514 IEEE80211_MAX_DATA_LEN), 515 [NL80211_ATTR_BEACON_TAIL] = 516 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 517 IEEE80211_MAX_DATA_LEN), 518 [NL80211_ATTR_STA_AID] = 519 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 520 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, 521 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, 522 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, 523 .len = NL80211_MAX_SUPP_RATES }, 524 [NL80211_ATTR_STA_PLINK_ACTION] = 525 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), 526 [NL80211_ATTR_STA_TX_POWER_SETTING] = 527 NLA_POLICY_RANGE(NLA_U8, 528 NL80211_TX_POWER_AUTOMATIC, 529 NL80211_TX_POWER_FIXED), 530 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, 531 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 532 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 533 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 534 .len = IEEE80211_MAX_MESH_ID_LEN }, 535 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, 536 537 /* allow 3 for NUL-termination, we used to declare this NLA_STRING */ 538 [NL80211_ATTR_REG_ALPHA2] = NLA_POLICY_RANGE(NLA_BINARY, 2, 3), 539 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, 540 541 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 542 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 543 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 544 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 545 .len = NL80211_MAX_SUPP_RATES }, 546 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, 547 548 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, 549 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, 550 551 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), 552 553 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, 554 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, 555 validate_ie_attr, 556 IEEE80211_MAX_DATA_LEN), 557 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, 558 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, 559 560 [NL80211_ATTR_SSID] = { .type = NLA_BINARY, 561 .len = IEEE80211_MAX_SSID_LEN }, 562 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, 563 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, 564 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, 565 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, 566 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, 567 NL80211_MFP_NO, 568 NL80211_MFP_OPTIONAL), 569 [NL80211_ATTR_STA_FLAGS2] = 570 NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_sta_flag_update)), 571 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 572 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, 573 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, 574 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, 575 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, 576 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, 577 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 578 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 579 [NL80211_ATTR_PID] = { .type = NLA_U32 }, 580 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, 581 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), 582 [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, 583 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, 584 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, 585 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, 586 .len = IEEE80211_MAX_DATA_LEN }, 587 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, 588 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, 589 NL80211_PS_DISABLED, 590 NL80211_PS_ENABLED), 591 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, 592 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, 593 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, 594 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, 595 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, 596 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, 597 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, 598 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, 599 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, 600 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, 601 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 602 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, 603 [NL80211_ATTR_STA_PLINK_STATE] = 604 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), 605 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, 606 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, 607 [NL80211_ATTR_MESH_PEER_AID] = 608 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 609 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, 610 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, 611 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, 612 [NL80211_ATTR_HIDDEN_SSID] = 613 NLA_POLICY_RANGE(NLA_U32, 614 NL80211_HIDDEN_SSID_NOT_IN_USE, 615 NL80211_HIDDEN_SSID_ZERO_CONTENTS), 616 [NL80211_ATTR_IE_PROBE_RESP] = 617 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 618 IEEE80211_MAX_DATA_LEN), 619 [NL80211_ATTR_IE_ASSOC_RESP] = 620 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 621 IEEE80211_MAX_DATA_LEN), 622 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, 623 [NL80211_ATTR_STA_WME] = NLA_POLICY_NESTED(nl80211_sta_wme_policy), 624 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, 625 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, 626 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, 627 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, 628 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, 629 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, 630 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, 631 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, 632 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, 633 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, 634 .len = IEEE80211_MAX_DATA_LEN }, 635 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, 636 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, 637 [NL80211_ATTR_HT_CAPABILITY_MASK] = { 638 .len = NL80211_HT_CAPABILITY_LEN 639 }, 640 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, 641 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, 642 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, 643 [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, 644 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, 645 646 /* need to include at least Auth Transaction and Status Code */ 647 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), 648 649 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), 650 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, 651 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), 652 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), 653 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = 654 NLA_POLICY_RANGE(NLA_U32, 655 NL80211_MESH_POWER_UNKNOWN + 1, 656 NL80211_MESH_POWER_MAX), 657 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, 658 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, 659 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, 660 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, 661 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, 662 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, 663 [NL80211_ATTR_VHT_CAPABILITY_MASK] = { 664 .len = NL80211_VHT_CAPABILITY_LEN, 665 }, 666 [NL80211_ATTR_MDID] = { .type = NLA_U16 }, 667 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, 668 .len = IEEE80211_MAX_DATA_LEN }, 669 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, 670 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = 671 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), 672 [NL80211_ATTR_PEER_AID] = 673 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 674 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, 675 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, 676 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, 677 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, 678 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, 679 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), 680 /* 681 * The value of the Length field of the Supported Operating 682 * Classes element is between 2 and 253. 683 */ 684 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = 685 NLA_POLICY_RANGE(NLA_BINARY, 2, 253), 686 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, 687 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, 688 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, 689 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, 690 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, 691 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, 692 IEEE80211_QOS_MAP_LEN_MIN, 693 IEEE80211_QOS_MAP_LEN_MAX), 694 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 695 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, 696 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, 697 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, 698 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, 699 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, 700 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), 701 [NL80211_ATTR_USER_PRIO] = 702 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), 703 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, 704 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, 705 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, 706 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 707 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, 708 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, 709 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, 710 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, 711 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, 712 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, 713 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = 714 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), 715 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { 716 .len = VHT_MUMIMO_GROUPS_DATA_LEN 717 }, 718 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 719 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), 720 [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, 721 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, 722 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, 723 .len = FILS_MAX_KEK_LEN }, 724 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), 725 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, 726 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 727 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, 728 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { 729 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 730 }, 731 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, 732 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, 733 .len = FILS_ERP_MAX_USERNAME_LEN }, 734 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, 735 .len = FILS_ERP_MAX_REALM_LEN }, 736 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, 737 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, 738 .len = FILS_ERP_MAX_RRK_LEN }, 739 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), 740 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, 741 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), 742 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, 743 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, 744 745 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, 746 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, 747 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, 748 [NL80211_ATTR_HE_CAPABILITY] = 749 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_he_capa, 750 NL80211_HE_MAX_CAPABILITY_LEN), 751 [NL80211_ATTR_FTM_RESPONDER] = 752 NLA_POLICY_NESTED(nl80211_ftm_responder_policy), 753 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), 754 [NL80211_ATTR_PEER_MEASUREMENTS] = 755 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), 756 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), 757 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, 758 .len = SAE_PASSWORD_MAX_LEN }, 759 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, 760 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), 761 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), 762 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), 763 [NL80211_ATTR_TID_CONFIG] = 764 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), 765 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, 766 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), 767 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), 768 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, 769 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 770 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, 771 [NL80211_ATTR_HE_6GHZ_CAPABILITY] = 772 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), 773 [NL80211_ATTR_FILS_DISCOVERY] = 774 NLA_POLICY_NESTED(nl80211_fils_discovery_policy), 775 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = 776 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), 777 [NL80211_ATTR_S1G_CAPABILITY] = 778 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), 779 [NL80211_ATTR_S1G_CAPABILITY_MASK] = 780 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), 781 [NL80211_ATTR_SAE_PWE] = 782 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK, 783 NL80211_SAE_PWE_BOTH), 784 [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT }, 785 [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy), 786 [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG }, 787 [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 }, 788 [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 }, 789 [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 }, 790 [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy), 791 [NL80211_ATTR_MBSSID_CONFIG] = 792 NLA_POLICY_NESTED(nl80211_mbssid_config_policy), 793 [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED }, 794 [NL80211_ATTR_RADAR_BACKGROUND] = { .type = NLA_FLAG }, 795 [NL80211_ATTR_AP_SETTINGS_FLAGS] = { .type = NLA_U32 }, 796 [NL80211_ATTR_EHT_CAPABILITY] = 797 NLA_POLICY_RANGE(NLA_BINARY, 798 NL80211_EHT_MIN_CAPABILITY_LEN, 799 NL80211_EHT_MAX_CAPABILITY_LEN), 800 [NL80211_ATTR_DISABLE_EHT] = { .type = NLA_FLAG }, 801 [NL80211_ATTR_MLO_LINKS] = 802 NLA_POLICY_NESTED_ARRAY(nl80211_policy), 803 [NL80211_ATTR_MLO_LINK_ID] = 804 NLA_POLICY_RANGE(NLA_U8, 0, IEEE80211_MLD_MAX_NUM_LINKS), 805 [NL80211_ATTR_MLD_ADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN), 806 [NL80211_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG }, 807 [NL80211_ATTR_MAX_NUM_AKM_SUITES] = { .type = NLA_REJECT }, 808 }; 809 810 /* policy for the key attributes */ 811 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { 812 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 813 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 814 [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, 815 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 816 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, 817 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 818 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), 819 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 820 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), 821 }; 822 823 /* policy for the key default flags */ 824 static const struct nla_policy 825 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { 826 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, 827 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, 828 }; 829 830 #ifdef CONFIG_PM 831 /* policy for WoWLAN attributes */ 832 static const struct nla_policy 833 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { 834 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, 835 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, 836 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, 837 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, 838 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, 839 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, 840 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, 841 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, 842 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, 843 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, 844 }; 845 846 static const struct nla_policy 847 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { 848 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, 849 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, 850 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 851 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, 852 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, 853 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), 854 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { 855 .len = sizeof(struct nl80211_wowlan_tcp_data_seq) 856 }, 857 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { 858 .len = sizeof(struct nl80211_wowlan_tcp_data_token) 859 }, 860 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, 861 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), 862 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), 863 }; 864 #endif /* CONFIG_PM */ 865 866 /* policy for coalesce rule attributes */ 867 static const struct nla_policy 868 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { 869 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, 870 [NL80211_ATTR_COALESCE_RULE_CONDITION] = 871 NLA_POLICY_RANGE(NLA_U32, 872 NL80211_COALESCE_CONDITION_MATCH, 873 NL80211_COALESCE_CONDITION_NO_MATCH), 874 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, 875 }; 876 877 /* policy for GTK rekey offload attributes */ 878 static const struct nla_policy 879 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { 880 [NL80211_REKEY_DATA_KEK] = { 881 .type = NLA_BINARY, 882 .len = NL80211_KEK_EXT_LEN 883 }, 884 [NL80211_REKEY_DATA_KCK] = { 885 .type = NLA_BINARY, 886 .len = NL80211_KCK_EXT_LEN_32 887 }, 888 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), 889 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, 890 }; 891 892 static const struct nla_policy 893 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { 894 [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, 895 [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, 896 [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, 897 [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, 898 [NL80211_BAND_LC] = { .type = NLA_S32 }, 899 }; 900 901 static const struct nla_policy 902 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { 903 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, 904 .len = IEEE80211_MAX_SSID_LEN }, 905 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 906 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, 907 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = 908 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), 909 }; 910 911 static const struct nla_policy 912 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { 913 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, 914 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, 915 }; 916 917 static const struct nla_policy 918 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { 919 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, 920 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, 921 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { 922 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 923 }, 924 }; 925 926 /* policy for NAN function attributes */ 927 static const struct nla_policy 928 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { 929 [NL80211_NAN_FUNC_TYPE] = 930 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), 931 [NL80211_NAN_FUNC_SERVICE_ID] = { 932 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, 933 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, 934 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, 935 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, 936 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, 937 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, 938 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 939 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, 940 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, 941 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, 942 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, 943 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, 944 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, 945 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, 946 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, 947 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, 948 }; 949 950 /* policy for Service Response Filter attributes */ 951 static const struct nla_policy 952 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { 953 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, 954 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, 955 .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, 956 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, 957 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, 958 }; 959 960 /* policy for packet pattern attributes */ 961 static const struct nla_policy 962 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { 963 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, 964 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, 965 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, 966 }; 967 968 static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, 969 struct cfg80211_registered_device **rdev, 970 struct wireless_dev **wdev, 971 struct nlattr **attrbuf) 972 { 973 int err; 974 975 if (!cb->args[0]) { 976 struct nlattr **attrbuf_free = NULL; 977 978 if (!attrbuf) { 979 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 980 GFP_KERNEL); 981 if (!attrbuf) 982 return -ENOMEM; 983 attrbuf_free = attrbuf; 984 } 985 986 err = nlmsg_parse_deprecated(cb->nlh, 987 GENL_HDRLEN + nl80211_fam.hdrsize, 988 attrbuf, nl80211_fam.maxattr, 989 nl80211_policy, NULL); 990 if (err) { 991 kfree(attrbuf_free); 992 return err; 993 } 994 995 rtnl_lock(); 996 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk), 997 attrbuf); 998 kfree(attrbuf_free); 999 if (IS_ERR(*wdev)) { 1000 rtnl_unlock(); 1001 return PTR_ERR(*wdev); 1002 } 1003 *rdev = wiphy_to_rdev((*wdev)->wiphy); 1004 mutex_lock(&(*rdev)->wiphy.mtx); 1005 rtnl_unlock(); 1006 /* 0 is the first index - add 1 to parse only once */ 1007 cb->args[0] = (*rdev)->wiphy_idx + 1; 1008 cb->args[1] = (*wdev)->identifier; 1009 } else { 1010 /* subtract the 1 again here */ 1011 struct wiphy *wiphy; 1012 struct wireless_dev *tmp; 1013 1014 rtnl_lock(); 1015 wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 1016 if (!wiphy) { 1017 rtnl_unlock(); 1018 return -ENODEV; 1019 } 1020 *rdev = wiphy_to_rdev(wiphy); 1021 *wdev = NULL; 1022 1023 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { 1024 if (tmp->identifier == cb->args[1]) { 1025 *wdev = tmp; 1026 break; 1027 } 1028 } 1029 1030 if (!*wdev) { 1031 rtnl_unlock(); 1032 return -ENODEV; 1033 } 1034 mutex_lock(&(*rdev)->wiphy.mtx); 1035 rtnl_unlock(); 1036 } 1037 1038 return 0; 1039 } 1040 1041 /* message building helper */ 1042 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, 1043 int flags, u8 cmd) 1044 { 1045 /* since there is no private header just add the generic one */ 1046 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); 1047 } 1048 1049 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, 1050 const struct ieee80211_reg_rule *rule) 1051 { 1052 int j; 1053 struct nlattr *nl_wmm_rules = 1054 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); 1055 1056 if (!nl_wmm_rules) 1057 goto nla_put_failure; 1058 1059 for (j = 0; j < IEEE80211_NUM_ACS; j++) { 1060 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); 1061 1062 if (!nl_wmm_rule) 1063 goto nla_put_failure; 1064 1065 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, 1066 rule->wmm_rule.client[j].cw_min) || 1067 nla_put_u16(msg, NL80211_WMMR_CW_MAX, 1068 rule->wmm_rule.client[j].cw_max) || 1069 nla_put_u8(msg, NL80211_WMMR_AIFSN, 1070 rule->wmm_rule.client[j].aifsn) || 1071 nla_put_u16(msg, NL80211_WMMR_TXOP, 1072 rule->wmm_rule.client[j].cot)) 1073 goto nla_put_failure; 1074 1075 nla_nest_end(msg, nl_wmm_rule); 1076 } 1077 nla_nest_end(msg, nl_wmm_rules); 1078 1079 return 0; 1080 1081 nla_put_failure: 1082 return -ENOBUFS; 1083 } 1084 1085 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, 1086 struct ieee80211_channel *chan, 1087 bool large) 1088 { 1089 /* Some channels must be completely excluded from the 1090 * list to protect old user-space tools from breaking 1091 */ 1092 if (!large && chan->flags & 1093 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) 1094 return 0; 1095 if (!large && chan->freq_offset) 1096 return 0; 1097 1098 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, 1099 chan->center_freq)) 1100 goto nla_put_failure; 1101 1102 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) 1103 goto nla_put_failure; 1104 1105 if ((chan->flags & IEEE80211_CHAN_DISABLED) && 1106 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) 1107 goto nla_put_failure; 1108 if (chan->flags & IEEE80211_CHAN_NO_IR) { 1109 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) 1110 goto nla_put_failure; 1111 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) 1112 goto nla_put_failure; 1113 } 1114 if (chan->flags & IEEE80211_CHAN_RADAR) { 1115 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) 1116 goto nla_put_failure; 1117 if (large) { 1118 u32 time; 1119 1120 time = elapsed_jiffies_msecs(chan->dfs_state_entered); 1121 1122 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, 1123 chan->dfs_state)) 1124 goto nla_put_failure; 1125 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, 1126 time)) 1127 goto nla_put_failure; 1128 if (nla_put_u32(msg, 1129 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, 1130 chan->dfs_cac_ms)) 1131 goto nla_put_failure; 1132 } 1133 } 1134 1135 if (large) { 1136 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && 1137 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) 1138 goto nla_put_failure; 1139 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && 1140 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) 1141 goto nla_put_failure; 1142 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && 1143 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) 1144 goto nla_put_failure; 1145 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && 1146 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) 1147 goto nla_put_failure; 1148 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && 1149 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) 1150 goto nla_put_failure; 1151 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && 1152 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) 1153 goto nla_put_failure; 1154 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && 1155 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) 1156 goto nla_put_failure; 1157 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && 1158 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) 1159 goto nla_put_failure; 1160 if ((chan->flags & IEEE80211_CHAN_NO_HE) && 1161 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) 1162 goto nla_put_failure; 1163 if ((chan->flags & IEEE80211_CHAN_1MHZ) && 1164 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) 1165 goto nla_put_failure; 1166 if ((chan->flags & IEEE80211_CHAN_2MHZ) && 1167 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) 1168 goto nla_put_failure; 1169 if ((chan->flags & IEEE80211_CHAN_4MHZ) && 1170 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) 1171 goto nla_put_failure; 1172 if ((chan->flags & IEEE80211_CHAN_8MHZ) && 1173 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) 1174 goto nla_put_failure; 1175 if ((chan->flags & IEEE80211_CHAN_16MHZ) && 1176 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) 1177 goto nla_put_failure; 1178 if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) && 1179 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ)) 1180 goto nla_put_failure; 1181 if ((chan->flags & IEEE80211_CHAN_NO_EHT) && 1182 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT)) 1183 goto nla_put_failure; 1184 } 1185 1186 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 1187 DBM_TO_MBM(chan->max_power))) 1188 goto nla_put_failure; 1189 1190 if (large) { 1191 const struct ieee80211_reg_rule *rule = 1192 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); 1193 1194 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { 1195 if (nl80211_msg_put_wmm_rules(msg, rule)) 1196 goto nla_put_failure; 1197 } 1198 } 1199 1200 return 0; 1201 1202 nla_put_failure: 1203 return -ENOBUFS; 1204 } 1205 1206 static bool nl80211_put_txq_stats(struct sk_buff *msg, 1207 struct cfg80211_txq_stats *txqstats, 1208 int attrtype) 1209 { 1210 struct nlattr *txqattr; 1211 1212 #define PUT_TXQVAL_U32(attr, memb) do { \ 1213 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ 1214 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ 1215 return false; \ 1216 } while (0) 1217 1218 txqattr = nla_nest_start_noflag(msg, attrtype); 1219 if (!txqattr) 1220 return false; 1221 1222 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); 1223 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); 1224 PUT_TXQVAL_U32(FLOWS, flows); 1225 PUT_TXQVAL_U32(DROPS, drops); 1226 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); 1227 PUT_TXQVAL_U32(OVERLIMIT, overlimit); 1228 PUT_TXQVAL_U32(OVERMEMORY, overmemory); 1229 PUT_TXQVAL_U32(COLLISIONS, collisions); 1230 PUT_TXQVAL_U32(TX_BYTES, tx_bytes); 1231 PUT_TXQVAL_U32(TX_PACKETS, tx_packets); 1232 PUT_TXQVAL_U32(MAX_FLOWS, max_flows); 1233 nla_nest_end(msg, txqattr); 1234 1235 #undef PUT_TXQVAL_U32 1236 return true; 1237 } 1238 1239 /* netlink command implementations */ 1240 1241 /** 1242 * nl80211_link_id - return link ID 1243 * @attrs: attributes to look at 1244 * 1245 * Returns: the link ID or 0 if not given 1246 * 1247 * Note this function doesn't do any validation of the link 1248 * ID validity wrt. links that were actually added, so it must 1249 * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID 1250 * or if additional validation is done. 1251 */ 1252 static unsigned int nl80211_link_id(struct nlattr **attrs) 1253 { 1254 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1255 1256 if (!linkid) 1257 return 0; 1258 1259 return nla_get_u8(linkid); 1260 } 1261 1262 static int nl80211_link_id_or_invalid(struct nlattr **attrs) 1263 { 1264 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1265 1266 if (!linkid) 1267 return -1; 1268 1269 return nla_get_u8(linkid); 1270 } 1271 1272 struct key_parse { 1273 struct key_params p; 1274 int idx; 1275 int type; 1276 bool def, defmgmt, defbeacon; 1277 bool def_uni, def_multi; 1278 }; 1279 1280 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, 1281 struct key_parse *k) 1282 { 1283 struct nlattr *tb[NL80211_KEY_MAX + 1]; 1284 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, 1285 nl80211_key_policy, 1286 info->extack); 1287 if (err) 1288 return err; 1289 1290 k->def = !!tb[NL80211_KEY_DEFAULT]; 1291 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 1292 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; 1293 1294 if (k->def) { 1295 k->def_uni = true; 1296 k->def_multi = true; 1297 } 1298 if (k->defmgmt || k->defbeacon) 1299 k->def_multi = true; 1300 1301 if (tb[NL80211_KEY_IDX]) 1302 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 1303 1304 if (tb[NL80211_KEY_DATA]) { 1305 k->p.key = nla_data(tb[NL80211_KEY_DATA]); 1306 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); 1307 } 1308 1309 if (tb[NL80211_KEY_SEQ]) { 1310 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); 1311 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); 1312 } 1313 1314 if (tb[NL80211_KEY_CIPHER]) 1315 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 1316 1317 if (tb[NL80211_KEY_TYPE]) 1318 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); 1319 1320 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 1321 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1322 1323 err = nla_parse_nested_deprecated(kdt, 1324 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1325 tb[NL80211_KEY_DEFAULT_TYPES], 1326 nl80211_key_default_policy, 1327 info->extack); 1328 if (err) 1329 return err; 1330 1331 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1332 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1333 } 1334 1335 if (tb[NL80211_KEY_MODE]) 1336 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); 1337 1338 return 0; 1339 } 1340 1341 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) 1342 { 1343 if (info->attrs[NL80211_ATTR_KEY_DATA]) { 1344 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); 1345 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); 1346 } 1347 1348 if (info->attrs[NL80211_ATTR_KEY_SEQ]) { 1349 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); 1350 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); 1351 } 1352 1353 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1354 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1355 1356 if (info->attrs[NL80211_ATTR_KEY_CIPHER]) 1357 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); 1358 1359 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 1360 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 1361 1362 if (k->def) { 1363 k->def_uni = true; 1364 k->def_multi = true; 1365 } 1366 if (k->defmgmt) 1367 k->def_multi = true; 1368 1369 if (info->attrs[NL80211_ATTR_KEY_TYPE]) 1370 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 1371 1372 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1373 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1374 int err = nla_parse_nested_deprecated(kdt, 1375 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1376 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1377 nl80211_key_default_policy, 1378 info->extack); 1379 if (err) 1380 return err; 1381 1382 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1383 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1384 } 1385 1386 return 0; 1387 } 1388 1389 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) 1390 { 1391 int err; 1392 1393 memset(k, 0, sizeof(*k)); 1394 k->idx = -1; 1395 k->type = -1; 1396 1397 if (info->attrs[NL80211_ATTR_KEY]) 1398 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); 1399 else 1400 err = nl80211_parse_key_old(info, k); 1401 1402 if (err) 1403 return err; 1404 1405 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + 1406 (k->defbeacon ? 1 : 0) > 1) { 1407 GENL_SET_ERR_MSG(info, 1408 "key with multiple default flags is invalid"); 1409 return -EINVAL; 1410 } 1411 1412 if (k->defmgmt || k->defbeacon) { 1413 if (k->def_uni || !k->def_multi) { 1414 GENL_SET_ERR_MSG(info, 1415 "defmgmt/defbeacon key must be mcast"); 1416 return -EINVAL; 1417 } 1418 } 1419 1420 if (k->idx != -1) { 1421 if (k->defmgmt) { 1422 if (k->idx < 4 || k->idx > 5) { 1423 GENL_SET_ERR_MSG(info, 1424 "defmgmt key idx not 4 or 5"); 1425 return -EINVAL; 1426 } 1427 } else if (k->defbeacon) { 1428 if (k->idx < 6 || k->idx > 7) { 1429 GENL_SET_ERR_MSG(info, 1430 "defbeacon key idx not 6 or 7"); 1431 return -EINVAL; 1432 } 1433 } else if (k->def) { 1434 if (k->idx < 0 || k->idx > 3) { 1435 GENL_SET_ERR_MSG(info, "def key idx not 0-3"); 1436 return -EINVAL; 1437 } 1438 } else { 1439 if (k->idx < 0 || k->idx > 7) { 1440 GENL_SET_ERR_MSG(info, "key idx not 0-7"); 1441 return -EINVAL; 1442 } 1443 } 1444 } 1445 1446 return 0; 1447 } 1448 1449 static struct cfg80211_cached_keys * 1450 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, 1451 struct genl_info *info, bool *no_ht) 1452 { 1453 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; 1454 struct key_parse parse; 1455 struct nlattr *key; 1456 struct cfg80211_cached_keys *result; 1457 int rem, err, def = 0; 1458 bool have_key = false; 1459 1460 nla_for_each_nested(key, keys, rem) { 1461 have_key = true; 1462 break; 1463 } 1464 1465 if (!have_key) 1466 return NULL; 1467 1468 result = kzalloc(sizeof(*result), GFP_KERNEL); 1469 if (!result) 1470 return ERR_PTR(-ENOMEM); 1471 1472 result->def = -1; 1473 1474 nla_for_each_nested(key, keys, rem) { 1475 memset(&parse, 0, sizeof(parse)); 1476 parse.idx = -1; 1477 1478 err = nl80211_parse_key_new(info, key, &parse); 1479 if (err) 1480 goto error; 1481 err = -EINVAL; 1482 if (!parse.p.key) 1483 goto error; 1484 if (parse.idx < 0 || parse.idx > 3) { 1485 GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); 1486 goto error; 1487 } 1488 if (parse.def) { 1489 if (def) { 1490 GENL_SET_ERR_MSG(info, 1491 "only one key can be default"); 1492 goto error; 1493 } 1494 def = 1; 1495 result->def = parse.idx; 1496 if (!parse.def_uni || !parse.def_multi) 1497 goto error; 1498 } else if (parse.defmgmt) 1499 goto error; 1500 err = cfg80211_validate_key_settings(rdev, &parse.p, 1501 parse.idx, false, NULL); 1502 if (err) 1503 goto error; 1504 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && 1505 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { 1506 GENL_SET_ERR_MSG(info, "connect key must be WEP"); 1507 err = -EINVAL; 1508 goto error; 1509 } 1510 result->params[parse.idx].cipher = parse.p.cipher; 1511 result->params[parse.idx].key_len = parse.p.key_len; 1512 result->params[parse.idx].key = result->data[parse.idx]; 1513 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); 1514 1515 /* must be WEP key if we got here */ 1516 if (no_ht) 1517 *no_ht = true; 1518 } 1519 1520 if (result->def < 0) { 1521 err = -EINVAL; 1522 GENL_SET_ERR_MSG(info, "need a default/TX key"); 1523 goto error; 1524 } 1525 1526 return result; 1527 error: 1528 kfree(result); 1529 return ERR_PTR(err); 1530 } 1531 1532 static int nl80211_key_allowed(struct wireless_dev *wdev) 1533 { 1534 ASSERT_WDEV_LOCK(wdev); 1535 1536 switch (wdev->iftype) { 1537 case NL80211_IFTYPE_AP: 1538 case NL80211_IFTYPE_AP_VLAN: 1539 case NL80211_IFTYPE_P2P_GO: 1540 case NL80211_IFTYPE_MESH_POINT: 1541 break; 1542 case NL80211_IFTYPE_ADHOC: 1543 if (wdev->u.ibss.current_bss) 1544 return 0; 1545 return -ENOLINK; 1546 case NL80211_IFTYPE_STATION: 1547 case NL80211_IFTYPE_P2P_CLIENT: 1548 if (wdev->connected) 1549 return 0; 1550 return -ENOLINK; 1551 case NL80211_IFTYPE_UNSPECIFIED: 1552 case NL80211_IFTYPE_OCB: 1553 case NL80211_IFTYPE_MONITOR: 1554 case NL80211_IFTYPE_NAN: 1555 case NL80211_IFTYPE_P2P_DEVICE: 1556 case NL80211_IFTYPE_WDS: 1557 case NUM_NL80211_IFTYPES: 1558 return -EINVAL; 1559 } 1560 1561 return 0; 1562 } 1563 1564 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, 1565 u32 freq) 1566 { 1567 struct ieee80211_channel *chan; 1568 1569 chan = ieee80211_get_channel_khz(wiphy, freq); 1570 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 1571 return NULL; 1572 return chan; 1573 } 1574 1575 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1576 { 1577 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); 1578 int i; 1579 1580 if (!nl_modes) 1581 goto nla_put_failure; 1582 1583 i = 0; 1584 while (ifmodes) { 1585 if ((ifmodes & 1) && nla_put_flag(msg, i)) 1586 goto nla_put_failure; 1587 ifmodes >>= 1; 1588 i++; 1589 } 1590 1591 nla_nest_end(msg, nl_modes); 1592 return 0; 1593 1594 nla_put_failure: 1595 return -ENOBUFS; 1596 } 1597 1598 static int nl80211_put_iface_combinations(struct wiphy *wiphy, 1599 struct sk_buff *msg, 1600 bool large) 1601 { 1602 struct nlattr *nl_combis; 1603 int i, j; 1604 1605 nl_combis = nla_nest_start_noflag(msg, 1606 NL80211_ATTR_INTERFACE_COMBINATIONS); 1607 if (!nl_combis) 1608 goto nla_put_failure; 1609 1610 for (i = 0; i < wiphy->n_iface_combinations; i++) { 1611 const struct ieee80211_iface_combination *c; 1612 struct nlattr *nl_combi, *nl_limits; 1613 1614 c = &wiphy->iface_combinations[i]; 1615 1616 nl_combi = nla_nest_start_noflag(msg, i + 1); 1617 if (!nl_combi) 1618 goto nla_put_failure; 1619 1620 nl_limits = nla_nest_start_noflag(msg, 1621 NL80211_IFACE_COMB_LIMITS); 1622 if (!nl_limits) 1623 goto nla_put_failure; 1624 1625 for (j = 0; j < c->n_limits; j++) { 1626 struct nlattr *nl_limit; 1627 1628 nl_limit = nla_nest_start_noflag(msg, j + 1); 1629 if (!nl_limit) 1630 goto nla_put_failure; 1631 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1632 c->limits[j].max)) 1633 goto nla_put_failure; 1634 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, 1635 c->limits[j].types)) 1636 goto nla_put_failure; 1637 nla_nest_end(msg, nl_limit); 1638 } 1639 1640 nla_nest_end(msg, nl_limits); 1641 1642 if (c->beacon_int_infra_match && 1643 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) 1644 goto nla_put_failure; 1645 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, 1646 c->num_different_channels) || 1647 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 1648 c->max_interfaces)) 1649 goto nla_put_failure; 1650 if (large && 1651 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, 1652 c->radar_detect_widths) || 1653 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, 1654 c->radar_detect_regions))) 1655 goto nla_put_failure; 1656 if (c->beacon_int_min_gcd && 1657 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, 1658 c->beacon_int_min_gcd)) 1659 goto nla_put_failure; 1660 1661 nla_nest_end(msg, nl_combi); 1662 } 1663 1664 nla_nest_end(msg, nl_combis); 1665 1666 return 0; 1667 nla_put_failure: 1668 return -ENOBUFS; 1669 } 1670 1671 #ifdef CONFIG_PM 1672 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, 1673 struct sk_buff *msg) 1674 { 1675 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; 1676 struct nlattr *nl_tcp; 1677 1678 if (!tcp) 1679 return 0; 1680 1681 nl_tcp = nla_nest_start_noflag(msg, 1682 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1683 if (!nl_tcp) 1684 return -ENOBUFS; 1685 1686 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1687 tcp->data_payload_max)) 1688 return -ENOBUFS; 1689 1690 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1691 tcp->data_payload_max)) 1692 return -ENOBUFS; 1693 1694 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) 1695 return -ENOBUFS; 1696 1697 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 1698 sizeof(*tcp->tok), tcp->tok)) 1699 return -ENOBUFS; 1700 1701 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 1702 tcp->data_interval_max)) 1703 return -ENOBUFS; 1704 1705 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 1706 tcp->wake_payload_max)) 1707 return -ENOBUFS; 1708 1709 nla_nest_end(msg, nl_tcp); 1710 return 0; 1711 } 1712 1713 static int nl80211_send_wowlan(struct sk_buff *msg, 1714 struct cfg80211_registered_device *rdev, 1715 bool large) 1716 { 1717 struct nlattr *nl_wowlan; 1718 1719 if (!rdev->wiphy.wowlan) 1720 return 0; 1721 1722 nl_wowlan = nla_nest_start_noflag(msg, 1723 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1724 if (!nl_wowlan) 1725 return -ENOBUFS; 1726 1727 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && 1728 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 1729 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && 1730 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 1731 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && 1732 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 1733 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && 1734 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || 1735 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 1736 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 1737 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && 1738 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 1739 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && 1740 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 1741 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && 1742 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 1743 return -ENOBUFS; 1744 1745 if (rdev->wiphy.wowlan->n_patterns) { 1746 struct nl80211_pattern_support pat = { 1747 .max_patterns = rdev->wiphy.wowlan->n_patterns, 1748 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, 1749 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, 1750 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, 1751 }; 1752 1753 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 1754 sizeof(pat), &pat)) 1755 return -ENOBUFS; 1756 } 1757 1758 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && 1759 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, 1760 rdev->wiphy.wowlan->max_nd_match_sets)) 1761 return -ENOBUFS; 1762 1763 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) 1764 return -ENOBUFS; 1765 1766 nla_nest_end(msg, nl_wowlan); 1767 1768 return 0; 1769 } 1770 #endif 1771 1772 static int nl80211_send_coalesce(struct sk_buff *msg, 1773 struct cfg80211_registered_device *rdev) 1774 { 1775 struct nl80211_coalesce_rule_support rule; 1776 1777 if (!rdev->wiphy.coalesce) 1778 return 0; 1779 1780 rule.max_rules = rdev->wiphy.coalesce->n_rules; 1781 rule.max_delay = rdev->wiphy.coalesce->max_delay; 1782 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; 1783 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; 1784 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; 1785 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; 1786 1787 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) 1788 return -ENOBUFS; 1789 1790 return 0; 1791 } 1792 1793 static int 1794 nl80211_send_iftype_data(struct sk_buff *msg, 1795 const struct ieee80211_supported_band *sband, 1796 const struct ieee80211_sband_iftype_data *iftdata) 1797 { 1798 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; 1799 const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap; 1800 1801 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, 1802 iftdata->types_mask)) 1803 return -ENOBUFS; 1804 1805 if (he_cap->has_he) { 1806 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, 1807 sizeof(he_cap->he_cap_elem.mac_cap_info), 1808 he_cap->he_cap_elem.mac_cap_info) || 1809 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, 1810 sizeof(he_cap->he_cap_elem.phy_cap_info), 1811 he_cap->he_cap_elem.phy_cap_info) || 1812 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, 1813 sizeof(he_cap->he_mcs_nss_supp), 1814 &he_cap->he_mcs_nss_supp) || 1815 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, 1816 sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) 1817 return -ENOBUFS; 1818 } 1819 1820 if (eht_cap->has_eht && he_cap->has_he) { 1821 u8 mcs_nss_size, ppe_thresh_size; 1822 u16 ppe_thres_hdr; 1823 bool is_ap; 1824 1825 is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) || 1826 iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO); 1827 1828 mcs_nss_size = 1829 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem, 1830 &eht_cap->eht_cap_elem, 1831 is_ap); 1832 1833 ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]); 1834 ppe_thresh_size = 1835 ieee80211_eht_ppe_size(ppe_thres_hdr, 1836 eht_cap->eht_cap_elem.phy_cap_info); 1837 1838 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC, 1839 sizeof(eht_cap->eht_cap_elem.mac_cap_info), 1840 eht_cap->eht_cap_elem.mac_cap_info) || 1841 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY, 1842 sizeof(eht_cap->eht_cap_elem.phy_cap_info), 1843 eht_cap->eht_cap_elem.phy_cap_info) || 1844 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET, 1845 mcs_nss_size, &eht_cap->eht_mcs_nss_supp) || 1846 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE, 1847 ppe_thresh_size, eht_cap->eht_ppe_thres)) 1848 return -ENOBUFS; 1849 } 1850 1851 if (sband->band == NL80211_BAND_6GHZ && 1852 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, 1853 sizeof(iftdata->he_6ghz_capa), 1854 &iftdata->he_6ghz_capa)) 1855 return -ENOBUFS; 1856 1857 if (iftdata->vendor_elems.data && iftdata->vendor_elems.len && 1858 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS, 1859 iftdata->vendor_elems.len, iftdata->vendor_elems.data)) 1860 return -ENOBUFS; 1861 1862 return 0; 1863 } 1864 1865 static int nl80211_send_band_rateinfo(struct sk_buff *msg, 1866 struct ieee80211_supported_band *sband, 1867 bool large) 1868 { 1869 struct nlattr *nl_rates, *nl_rate; 1870 struct ieee80211_rate *rate; 1871 int i; 1872 1873 /* add HT info */ 1874 if (sband->ht_cap.ht_supported && 1875 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, 1876 sizeof(sband->ht_cap.mcs), 1877 &sband->ht_cap.mcs) || 1878 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, 1879 sband->ht_cap.cap) || 1880 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, 1881 sband->ht_cap.ampdu_factor) || 1882 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, 1883 sband->ht_cap.ampdu_density))) 1884 return -ENOBUFS; 1885 1886 /* add VHT info */ 1887 if (sband->vht_cap.vht_supported && 1888 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, 1889 sizeof(sband->vht_cap.vht_mcs), 1890 &sband->vht_cap.vht_mcs) || 1891 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, 1892 sband->vht_cap.cap))) 1893 return -ENOBUFS; 1894 1895 if (large && sband->n_iftype_data) { 1896 struct nlattr *nl_iftype_data = 1897 nla_nest_start_noflag(msg, 1898 NL80211_BAND_ATTR_IFTYPE_DATA); 1899 int err; 1900 1901 if (!nl_iftype_data) 1902 return -ENOBUFS; 1903 1904 for (i = 0; i < sband->n_iftype_data; i++) { 1905 struct nlattr *iftdata; 1906 1907 iftdata = nla_nest_start_noflag(msg, i + 1); 1908 if (!iftdata) 1909 return -ENOBUFS; 1910 1911 err = nl80211_send_iftype_data(msg, sband, 1912 &sband->iftype_data[i]); 1913 if (err) 1914 return err; 1915 1916 nla_nest_end(msg, iftdata); 1917 } 1918 1919 nla_nest_end(msg, nl_iftype_data); 1920 } 1921 1922 /* add EDMG info */ 1923 if (large && sband->edmg_cap.channels && 1924 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, 1925 sband->edmg_cap.channels) || 1926 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, 1927 sband->edmg_cap.bw_config))) 1928 1929 return -ENOBUFS; 1930 1931 /* add bitrates */ 1932 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); 1933 if (!nl_rates) 1934 return -ENOBUFS; 1935 1936 for (i = 0; i < sband->n_bitrates; i++) { 1937 nl_rate = nla_nest_start_noflag(msg, i); 1938 if (!nl_rate) 1939 return -ENOBUFS; 1940 1941 rate = &sband->bitrates[i]; 1942 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, 1943 rate->bitrate)) 1944 return -ENOBUFS; 1945 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && 1946 nla_put_flag(msg, 1947 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) 1948 return -ENOBUFS; 1949 1950 nla_nest_end(msg, nl_rate); 1951 } 1952 1953 nla_nest_end(msg, nl_rates); 1954 1955 return 0; 1956 } 1957 1958 static int 1959 nl80211_send_mgmt_stypes(struct sk_buff *msg, 1960 const struct ieee80211_txrx_stypes *mgmt_stypes) 1961 { 1962 u16 stypes; 1963 struct nlattr *nl_ftypes, *nl_ifs; 1964 enum nl80211_iftype ift; 1965 int i; 1966 1967 if (!mgmt_stypes) 1968 return 0; 1969 1970 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); 1971 if (!nl_ifs) 1972 return -ENOBUFS; 1973 1974 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1975 nl_ftypes = nla_nest_start_noflag(msg, ift); 1976 if (!nl_ftypes) 1977 return -ENOBUFS; 1978 i = 0; 1979 stypes = mgmt_stypes[ift].tx; 1980 while (stypes) { 1981 if ((stypes & 1) && 1982 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1983 (i << 4) | IEEE80211_FTYPE_MGMT)) 1984 return -ENOBUFS; 1985 stypes >>= 1; 1986 i++; 1987 } 1988 nla_nest_end(msg, nl_ftypes); 1989 } 1990 1991 nla_nest_end(msg, nl_ifs); 1992 1993 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); 1994 if (!nl_ifs) 1995 return -ENOBUFS; 1996 1997 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1998 nl_ftypes = nla_nest_start_noflag(msg, ift); 1999 if (!nl_ftypes) 2000 return -ENOBUFS; 2001 i = 0; 2002 stypes = mgmt_stypes[ift].rx; 2003 while (stypes) { 2004 if ((stypes & 1) && 2005 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 2006 (i << 4) | IEEE80211_FTYPE_MGMT)) 2007 return -ENOBUFS; 2008 stypes >>= 1; 2009 i++; 2010 } 2011 nla_nest_end(msg, nl_ftypes); 2012 } 2013 nla_nest_end(msg, nl_ifs); 2014 2015 return 0; 2016 } 2017 2018 #define CMD(op, n) \ 2019 do { \ 2020 if (rdev->ops->op) { \ 2021 i++; \ 2022 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ 2023 goto nla_put_failure; \ 2024 } \ 2025 } while (0) 2026 2027 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, 2028 struct sk_buff *msg) 2029 { 2030 int i = 0; 2031 2032 /* 2033 * do *NOT* add anything into this function, new things need to be 2034 * advertised only to new versions of userspace that can deal with 2035 * the split (and they can't possibly care about new features... 2036 */ 2037 CMD(add_virtual_intf, NEW_INTERFACE); 2038 CMD(change_virtual_intf, SET_INTERFACE); 2039 CMD(add_key, NEW_KEY); 2040 CMD(start_ap, START_AP); 2041 CMD(add_station, NEW_STATION); 2042 CMD(add_mpath, NEW_MPATH); 2043 CMD(update_mesh_config, SET_MESH_CONFIG); 2044 CMD(change_bss, SET_BSS); 2045 CMD(auth, AUTHENTICATE); 2046 CMD(assoc, ASSOCIATE); 2047 CMD(deauth, DEAUTHENTICATE); 2048 CMD(disassoc, DISASSOCIATE); 2049 CMD(join_ibss, JOIN_IBSS); 2050 CMD(join_mesh, JOIN_MESH); 2051 CMD(set_pmksa, SET_PMKSA); 2052 CMD(del_pmksa, DEL_PMKSA); 2053 CMD(flush_pmksa, FLUSH_PMKSA); 2054 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) 2055 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 2056 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 2057 CMD(mgmt_tx, FRAME); 2058 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); 2059 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 2060 i++; 2061 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 2062 goto nla_put_failure; 2063 } 2064 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || 2065 rdev->ops->join_mesh) { 2066 i++; 2067 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) 2068 goto nla_put_failure; 2069 } 2070 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 2071 CMD(tdls_mgmt, TDLS_MGMT); 2072 CMD(tdls_oper, TDLS_OPER); 2073 } 2074 if (rdev->wiphy.max_sched_scan_reqs) 2075 CMD(sched_scan_start, START_SCHED_SCAN); 2076 CMD(probe_client, PROBE_CLIENT); 2077 CMD(set_noack_map, SET_NOACK_MAP); 2078 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { 2079 i++; 2080 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) 2081 goto nla_put_failure; 2082 } 2083 CMD(start_p2p_device, START_P2P_DEVICE); 2084 CMD(set_mcast_rate, SET_MCAST_RATE); 2085 #ifdef CONFIG_NL80211_TESTMODE 2086 CMD(testmode_cmd, TESTMODE); 2087 #endif 2088 2089 if (rdev->ops->connect || rdev->ops->auth) { 2090 i++; 2091 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) 2092 goto nla_put_failure; 2093 } 2094 2095 if (rdev->ops->disconnect || rdev->ops->deauth) { 2096 i++; 2097 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) 2098 goto nla_put_failure; 2099 } 2100 2101 return i; 2102 nla_put_failure: 2103 return -ENOBUFS; 2104 } 2105 2106 static int 2107 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, 2108 struct sk_buff *msg) 2109 { 2110 struct nlattr *ftm; 2111 2112 if (!cap->ftm.supported) 2113 return 0; 2114 2115 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); 2116 if (!ftm) 2117 return -ENOBUFS; 2118 2119 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) 2120 return -ENOBUFS; 2121 if (cap->ftm.non_asap && 2122 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) 2123 return -ENOBUFS; 2124 if (cap->ftm.request_lci && 2125 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) 2126 return -ENOBUFS; 2127 if (cap->ftm.request_civicloc && 2128 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) 2129 return -ENOBUFS; 2130 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, 2131 cap->ftm.preambles)) 2132 return -ENOBUFS; 2133 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, 2134 cap->ftm.bandwidths)) 2135 return -ENOBUFS; 2136 if (cap->ftm.max_bursts_exponent >= 0 && 2137 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, 2138 cap->ftm.max_bursts_exponent)) 2139 return -ENOBUFS; 2140 if (cap->ftm.max_ftms_per_burst && 2141 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, 2142 cap->ftm.max_ftms_per_burst)) 2143 return -ENOBUFS; 2144 if (cap->ftm.trigger_based && 2145 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) 2146 return -ENOBUFS; 2147 if (cap->ftm.non_trigger_based && 2148 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) 2149 return -ENOBUFS; 2150 2151 nla_nest_end(msg, ftm); 2152 return 0; 2153 } 2154 2155 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, 2156 struct sk_buff *msg) 2157 { 2158 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; 2159 struct nlattr *pmsr, *caps; 2160 2161 if (!cap) 2162 return 0; 2163 2164 /* 2165 * we don't need to clean up anything here since the caller 2166 * will genlmsg_cancel() if we fail 2167 */ 2168 2169 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 2170 if (!pmsr) 2171 return -ENOBUFS; 2172 2173 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) 2174 return -ENOBUFS; 2175 2176 if (cap->report_ap_tsf && 2177 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) 2178 return -ENOBUFS; 2179 2180 if (cap->randomize_mac_addr && 2181 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 2182 return -ENOBUFS; 2183 2184 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 2185 if (!caps) 2186 return -ENOBUFS; 2187 2188 if (nl80211_send_pmsr_ftm_capa(cap, msg)) 2189 return -ENOBUFS; 2190 2191 nla_nest_end(msg, caps); 2192 nla_nest_end(msg, pmsr); 2193 2194 return 0; 2195 } 2196 2197 static int 2198 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, 2199 struct sk_buff *msg) 2200 { 2201 int i; 2202 struct nlattr *nested, *nested_akms; 2203 const struct wiphy_iftype_akm_suites *iftype_akms; 2204 2205 if (!rdev->wiphy.num_iftype_akm_suites || 2206 !rdev->wiphy.iftype_akm_suites) 2207 return 0; 2208 2209 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); 2210 if (!nested) 2211 return -ENOBUFS; 2212 2213 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { 2214 nested_akms = nla_nest_start(msg, i + 1); 2215 if (!nested_akms) 2216 return -ENOBUFS; 2217 2218 iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; 2219 2220 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, 2221 iftype_akms->iftypes_mask)) 2222 return -ENOBUFS; 2223 2224 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, 2225 sizeof(u32) * iftype_akms->n_akm_suites, 2226 iftype_akms->akm_suites)) { 2227 return -ENOBUFS; 2228 } 2229 nla_nest_end(msg, nested_akms); 2230 } 2231 2232 nla_nest_end(msg, nested); 2233 2234 return 0; 2235 } 2236 2237 static int 2238 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, 2239 struct sk_buff *msg) 2240 { 2241 struct nlattr *supp; 2242 2243 if (!rdev->wiphy.tid_config_support.vif && 2244 !rdev->wiphy.tid_config_support.peer) 2245 return 0; 2246 2247 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); 2248 if (!supp) 2249 return -ENOSPC; 2250 2251 if (rdev->wiphy.tid_config_support.vif && 2252 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, 2253 rdev->wiphy.tid_config_support.vif, 2254 NL80211_TID_CONFIG_ATTR_PAD)) 2255 goto fail; 2256 2257 if (rdev->wiphy.tid_config_support.peer && 2258 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, 2259 rdev->wiphy.tid_config_support.peer, 2260 NL80211_TID_CONFIG_ATTR_PAD)) 2261 goto fail; 2262 2263 /* for now we just use the same value ... makes more sense */ 2264 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, 2265 rdev->wiphy.tid_config_support.max_retry)) 2266 goto fail; 2267 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, 2268 rdev->wiphy.tid_config_support.max_retry)) 2269 goto fail; 2270 2271 nla_nest_end(msg, supp); 2272 2273 return 0; 2274 fail: 2275 nla_nest_cancel(msg, supp); 2276 return -ENOBUFS; 2277 } 2278 2279 static int 2280 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev, 2281 struct sk_buff *msg) 2282 { 2283 struct nlattr *sar_capa, *specs, *sub_freq_range; 2284 u8 num_freq_ranges; 2285 int i; 2286 2287 if (!rdev->wiphy.sar_capa) 2288 return 0; 2289 2290 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges; 2291 2292 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC); 2293 if (!sar_capa) 2294 return -ENOSPC; 2295 2296 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type)) 2297 goto fail; 2298 2299 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS); 2300 if (!specs) 2301 goto fail; 2302 2303 /* report supported freq_ranges */ 2304 for (i = 0; i < num_freq_ranges; i++) { 2305 sub_freq_range = nla_nest_start(msg, i + 1); 2306 if (!sub_freq_range) 2307 goto fail; 2308 2309 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ, 2310 rdev->wiphy.sar_capa->freq_ranges[i].start_freq)) 2311 goto fail; 2312 2313 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ, 2314 rdev->wiphy.sar_capa->freq_ranges[i].end_freq)) 2315 goto fail; 2316 2317 nla_nest_end(msg, sub_freq_range); 2318 } 2319 2320 nla_nest_end(msg, specs); 2321 nla_nest_end(msg, sar_capa); 2322 2323 return 0; 2324 fail: 2325 nla_nest_cancel(msg, sar_capa); 2326 return -ENOBUFS; 2327 } 2328 2329 static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg) 2330 { 2331 struct nlattr *config; 2332 2333 if (!wiphy->mbssid_max_interfaces) 2334 return 0; 2335 2336 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); 2337 if (!config) 2338 return -ENOBUFS; 2339 2340 if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES, 2341 wiphy->mbssid_max_interfaces)) 2342 goto fail; 2343 2344 if (wiphy->ema_max_profile_periodicity && 2345 nla_put_u8(msg, 2346 NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY, 2347 wiphy->ema_max_profile_periodicity)) 2348 goto fail; 2349 2350 nla_nest_end(msg, config); 2351 return 0; 2352 2353 fail: 2354 nla_nest_cancel(msg, config); 2355 return -ENOBUFS; 2356 } 2357 2358 struct nl80211_dump_wiphy_state { 2359 s64 filter_wiphy; 2360 long start; 2361 long split_start, band_start, chan_start, capa_start; 2362 bool split; 2363 }; 2364 2365 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 2366 enum nl80211_commands cmd, 2367 struct sk_buff *msg, u32 portid, u32 seq, 2368 int flags, struct nl80211_dump_wiphy_state *state) 2369 { 2370 void *hdr; 2371 struct nlattr *nl_bands, *nl_band; 2372 struct nlattr *nl_freqs, *nl_freq; 2373 struct nlattr *nl_cmds; 2374 enum nl80211_band band; 2375 struct ieee80211_channel *chan; 2376 int i; 2377 const struct ieee80211_txrx_stypes *mgmt_stypes = 2378 rdev->wiphy.mgmt_stypes; 2379 u32 features; 2380 2381 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 2382 if (!hdr) 2383 return -ENOBUFS; 2384 2385 if (WARN_ON(!state)) 2386 return -EINVAL; 2387 2388 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 2389 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, 2390 wiphy_name(&rdev->wiphy)) || 2391 nla_put_u32(msg, NL80211_ATTR_GENERATION, 2392 cfg80211_rdev_list_generation)) 2393 goto nla_put_failure; 2394 2395 if (cmd != NL80211_CMD_NEW_WIPHY) 2396 goto finish; 2397 2398 switch (state->split_start) { 2399 case 0: 2400 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 2401 rdev->wiphy.retry_short) || 2402 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, 2403 rdev->wiphy.retry_long) || 2404 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, 2405 rdev->wiphy.frag_threshold) || 2406 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 2407 rdev->wiphy.rts_threshold) || 2408 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 2409 rdev->wiphy.coverage_class) || 2410 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 2411 rdev->wiphy.max_scan_ssids) || 2412 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, 2413 rdev->wiphy.max_sched_scan_ssids) || 2414 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 2415 rdev->wiphy.max_scan_ie_len) || 2416 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, 2417 rdev->wiphy.max_sched_scan_ie_len) || 2418 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, 2419 rdev->wiphy.max_match_sets)) 2420 goto nla_put_failure; 2421 2422 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && 2423 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) 2424 goto nla_put_failure; 2425 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && 2426 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) 2427 goto nla_put_failure; 2428 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && 2429 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) 2430 goto nla_put_failure; 2431 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 2432 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) 2433 goto nla_put_failure; 2434 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && 2435 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) 2436 goto nla_put_failure; 2437 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && 2438 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) 2439 goto nla_put_failure; 2440 state->split_start++; 2441 if (state->split) 2442 break; 2443 fallthrough; 2444 case 1: 2445 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, 2446 sizeof(u32) * rdev->wiphy.n_cipher_suites, 2447 rdev->wiphy.cipher_suites)) 2448 goto nla_put_failure; 2449 2450 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 2451 rdev->wiphy.max_num_pmkids)) 2452 goto nla_put_failure; 2453 2454 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 2455 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) 2456 goto nla_put_failure; 2457 2458 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, 2459 rdev->wiphy.available_antennas_tx) || 2460 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, 2461 rdev->wiphy.available_antennas_rx)) 2462 goto nla_put_failure; 2463 2464 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && 2465 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, 2466 rdev->wiphy.probe_resp_offload)) 2467 goto nla_put_failure; 2468 2469 if ((rdev->wiphy.available_antennas_tx || 2470 rdev->wiphy.available_antennas_rx) && 2471 rdev->ops->get_antenna) { 2472 u32 tx_ant = 0, rx_ant = 0; 2473 int res; 2474 2475 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); 2476 if (!res) { 2477 if (nla_put_u32(msg, 2478 NL80211_ATTR_WIPHY_ANTENNA_TX, 2479 tx_ant) || 2480 nla_put_u32(msg, 2481 NL80211_ATTR_WIPHY_ANTENNA_RX, 2482 rx_ant)) 2483 goto nla_put_failure; 2484 } 2485 } 2486 2487 state->split_start++; 2488 if (state->split) 2489 break; 2490 fallthrough; 2491 case 2: 2492 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, 2493 rdev->wiphy.interface_modes)) 2494 goto nla_put_failure; 2495 state->split_start++; 2496 if (state->split) 2497 break; 2498 fallthrough; 2499 case 3: 2500 nl_bands = nla_nest_start_noflag(msg, 2501 NL80211_ATTR_WIPHY_BANDS); 2502 if (!nl_bands) 2503 goto nla_put_failure; 2504 2505 for (band = state->band_start; 2506 band < (state->split ? 2507 NUM_NL80211_BANDS : 2508 NL80211_BAND_60GHZ + 1); 2509 band++) { 2510 struct ieee80211_supported_band *sband; 2511 2512 /* omit higher bands for ancient software */ 2513 if (band > NL80211_BAND_5GHZ && !state->split) 2514 break; 2515 2516 sband = rdev->wiphy.bands[band]; 2517 2518 if (!sband) 2519 continue; 2520 2521 nl_band = nla_nest_start_noflag(msg, band); 2522 if (!nl_band) 2523 goto nla_put_failure; 2524 2525 switch (state->chan_start) { 2526 case 0: 2527 if (nl80211_send_band_rateinfo(msg, sband, 2528 state->split)) 2529 goto nla_put_failure; 2530 state->chan_start++; 2531 if (state->split) 2532 break; 2533 fallthrough; 2534 default: 2535 /* add frequencies */ 2536 nl_freqs = nla_nest_start_noflag(msg, 2537 NL80211_BAND_ATTR_FREQS); 2538 if (!nl_freqs) 2539 goto nla_put_failure; 2540 2541 for (i = state->chan_start - 1; 2542 i < sband->n_channels; 2543 i++) { 2544 nl_freq = nla_nest_start_noflag(msg, 2545 i); 2546 if (!nl_freq) 2547 goto nla_put_failure; 2548 2549 chan = &sband->channels[i]; 2550 2551 if (nl80211_msg_put_channel( 2552 msg, &rdev->wiphy, chan, 2553 state->split)) 2554 goto nla_put_failure; 2555 2556 nla_nest_end(msg, nl_freq); 2557 if (state->split) 2558 break; 2559 } 2560 if (i < sband->n_channels) 2561 state->chan_start = i + 2; 2562 else 2563 state->chan_start = 0; 2564 nla_nest_end(msg, nl_freqs); 2565 } 2566 2567 nla_nest_end(msg, nl_band); 2568 2569 if (state->split) { 2570 /* start again here */ 2571 if (state->chan_start) 2572 band--; 2573 break; 2574 } 2575 } 2576 nla_nest_end(msg, nl_bands); 2577 2578 if (band < NUM_NL80211_BANDS) 2579 state->band_start = band + 1; 2580 else 2581 state->band_start = 0; 2582 2583 /* if bands & channels are done, continue outside */ 2584 if (state->band_start == 0 && state->chan_start == 0) 2585 state->split_start++; 2586 if (state->split) 2587 break; 2588 fallthrough; 2589 case 4: 2590 nl_cmds = nla_nest_start_noflag(msg, 2591 NL80211_ATTR_SUPPORTED_COMMANDS); 2592 if (!nl_cmds) 2593 goto nla_put_failure; 2594 2595 i = nl80211_add_commands_unsplit(rdev, msg); 2596 if (i < 0) 2597 goto nla_put_failure; 2598 if (state->split) { 2599 CMD(crit_proto_start, CRIT_PROTOCOL_START); 2600 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); 2601 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 2602 CMD(channel_switch, CHANNEL_SWITCH); 2603 CMD(set_qos_map, SET_QOS_MAP); 2604 if (rdev->wiphy.features & 2605 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 2606 CMD(add_tx_ts, ADD_TX_TS); 2607 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); 2608 CMD(update_connect_params, UPDATE_CONNECT_PARAMS); 2609 CMD(update_ft_ies, UPDATE_FT_IES); 2610 if (rdev->wiphy.sar_capa) 2611 CMD(set_sar_specs, SET_SAR_SPECS); 2612 } 2613 #undef CMD 2614 2615 nla_nest_end(msg, nl_cmds); 2616 state->split_start++; 2617 if (state->split) 2618 break; 2619 fallthrough; 2620 case 5: 2621 if (rdev->ops->remain_on_channel && 2622 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && 2623 nla_put_u32(msg, 2624 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, 2625 rdev->wiphy.max_remain_on_channel_duration)) 2626 goto nla_put_failure; 2627 2628 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && 2629 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) 2630 goto nla_put_failure; 2631 2632 state->split_start++; 2633 if (state->split) 2634 break; 2635 fallthrough; 2636 case 6: 2637 #ifdef CONFIG_PM 2638 if (nl80211_send_wowlan(msg, rdev, state->split)) 2639 goto nla_put_failure; 2640 state->split_start++; 2641 if (state->split) 2642 break; 2643 #else 2644 state->split_start++; 2645 #endif 2646 fallthrough; 2647 case 7: 2648 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, 2649 rdev->wiphy.software_iftypes)) 2650 goto nla_put_failure; 2651 2652 if (nl80211_put_iface_combinations(&rdev->wiphy, msg, 2653 state->split)) 2654 goto nla_put_failure; 2655 2656 state->split_start++; 2657 if (state->split) 2658 break; 2659 fallthrough; 2660 case 8: 2661 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && 2662 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, 2663 rdev->wiphy.ap_sme_capa)) 2664 goto nla_put_failure; 2665 2666 features = rdev->wiphy.features; 2667 /* 2668 * We can only add the per-channel limit information if the 2669 * dump is split, otherwise it makes it too big. Therefore 2670 * only advertise it in that case. 2671 */ 2672 if (state->split) 2673 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; 2674 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) 2675 goto nla_put_failure; 2676 2677 if (rdev->wiphy.ht_capa_mod_mask && 2678 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, 2679 sizeof(*rdev->wiphy.ht_capa_mod_mask), 2680 rdev->wiphy.ht_capa_mod_mask)) 2681 goto nla_put_failure; 2682 2683 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && 2684 rdev->wiphy.max_acl_mac_addrs && 2685 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, 2686 rdev->wiphy.max_acl_mac_addrs)) 2687 goto nla_put_failure; 2688 2689 /* 2690 * Any information below this point is only available to 2691 * applications that can deal with it being split. This 2692 * helps ensure that newly added capabilities don't break 2693 * older tools by overrunning their buffers. 2694 * 2695 * We still increment split_start so that in the split 2696 * case we'll continue with more data in the next round, 2697 * but break unconditionally so unsplit data stops here. 2698 */ 2699 if (state->split) 2700 state->split_start++; 2701 else 2702 state->split_start = 0; 2703 break; 2704 case 9: 2705 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) 2706 goto nla_put_failure; 2707 2708 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, 2709 rdev->wiphy.max_sched_scan_plans) || 2710 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, 2711 rdev->wiphy.max_sched_scan_plan_interval) || 2712 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, 2713 rdev->wiphy.max_sched_scan_plan_iterations)) 2714 goto nla_put_failure; 2715 2716 if (rdev->wiphy.extended_capabilities && 2717 (nla_put(msg, NL80211_ATTR_EXT_CAPA, 2718 rdev->wiphy.extended_capabilities_len, 2719 rdev->wiphy.extended_capabilities) || 2720 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2721 rdev->wiphy.extended_capabilities_len, 2722 rdev->wiphy.extended_capabilities_mask))) 2723 goto nla_put_failure; 2724 2725 if (rdev->wiphy.vht_capa_mod_mask && 2726 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, 2727 sizeof(*rdev->wiphy.vht_capa_mod_mask), 2728 rdev->wiphy.vht_capa_mod_mask)) 2729 goto nla_put_failure; 2730 2731 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 2732 rdev->wiphy.perm_addr)) 2733 goto nla_put_failure; 2734 2735 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && 2736 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, 2737 rdev->wiphy.addr_mask)) 2738 goto nla_put_failure; 2739 2740 if (rdev->wiphy.n_addresses > 1) { 2741 void *attr; 2742 2743 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); 2744 if (!attr) 2745 goto nla_put_failure; 2746 2747 for (i = 0; i < rdev->wiphy.n_addresses; i++) 2748 if (nla_put(msg, i + 1, ETH_ALEN, 2749 rdev->wiphy.addresses[i].addr)) 2750 goto nla_put_failure; 2751 2752 nla_nest_end(msg, attr); 2753 } 2754 2755 state->split_start++; 2756 break; 2757 case 10: 2758 if (nl80211_send_coalesce(msg, rdev)) 2759 goto nla_put_failure; 2760 2761 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && 2762 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || 2763 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) 2764 goto nla_put_failure; 2765 2766 if (rdev->wiphy.max_ap_assoc_sta && 2767 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, 2768 rdev->wiphy.max_ap_assoc_sta)) 2769 goto nla_put_failure; 2770 2771 state->split_start++; 2772 break; 2773 case 11: 2774 if (rdev->wiphy.n_vendor_commands) { 2775 const struct nl80211_vendor_cmd_info *info; 2776 struct nlattr *nested; 2777 2778 nested = nla_nest_start_noflag(msg, 2779 NL80211_ATTR_VENDOR_DATA); 2780 if (!nested) 2781 goto nla_put_failure; 2782 2783 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 2784 info = &rdev->wiphy.vendor_commands[i].info; 2785 if (nla_put(msg, i + 1, sizeof(*info), info)) 2786 goto nla_put_failure; 2787 } 2788 nla_nest_end(msg, nested); 2789 } 2790 2791 if (rdev->wiphy.n_vendor_events) { 2792 const struct nl80211_vendor_cmd_info *info; 2793 struct nlattr *nested; 2794 2795 nested = nla_nest_start_noflag(msg, 2796 NL80211_ATTR_VENDOR_EVENTS); 2797 if (!nested) 2798 goto nla_put_failure; 2799 2800 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { 2801 info = &rdev->wiphy.vendor_events[i]; 2802 if (nla_put(msg, i + 1, sizeof(*info), info)) 2803 goto nla_put_failure; 2804 } 2805 nla_nest_end(msg, nested); 2806 } 2807 state->split_start++; 2808 break; 2809 case 12: 2810 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && 2811 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, 2812 rdev->wiphy.max_num_csa_counters)) 2813 goto nla_put_failure; 2814 2815 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 2816 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 2817 goto nla_put_failure; 2818 2819 if (rdev->wiphy.max_sched_scan_reqs && 2820 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, 2821 rdev->wiphy.max_sched_scan_reqs)) 2822 goto nla_put_failure; 2823 2824 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, 2825 sizeof(rdev->wiphy.ext_features), 2826 rdev->wiphy.ext_features)) 2827 goto nla_put_failure; 2828 2829 if (rdev->wiphy.bss_select_support) { 2830 struct nlattr *nested; 2831 u32 bss_select_support = rdev->wiphy.bss_select_support; 2832 2833 nested = nla_nest_start_noflag(msg, 2834 NL80211_ATTR_BSS_SELECT); 2835 if (!nested) 2836 goto nla_put_failure; 2837 2838 i = 0; 2839 while (bss_select_support) { 2840 if ((bss_select_support & 1) && 2841 nla_put_flag(msg, i)) 2842 goto nla_put_failure; 2843 i++; 2844 bss_select_support >>= 1; 2845 } 2846 nla_nest_end(msg, nested); 2847 } 2848 2849 state->split_start++; 2850 break; 2851 case 13: 2852 if (rdev->wiphy.num_iftype_ext_capab && 2853 rdev->wiphy.iftype_ext_capab) { 2854 struct nlattr *nested_ext_capab, *nested; 2855 2856 nested = nla_nest_start_noflag(msg, 2857 NL80211_ATTR_IFTYPE_EXT_CAPA); 2858 if (!nested) 2859 goto nla_put_failure; 2860 2861 for (i = state->capa_start; 2862 i < rdev->wiphy.num_iftype_ext_capab; i++) { 2863 const struct wiphy_iftype_ext_capab *capab; 2864 2865 capab = &rdev->wiphy.iftype_ext_capab[i]; 2866 2867 nested_ext_capab = nla_nest_start_noflag(msg, 2868 i); 2869 if (!nested_ext_capab || 2870 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2871 capab->iftype) || 2872 nla_put(msg, NL80211_ATTR_EXT_CAPA, 2873 capab->extended_capabilities_len, 2874 capab->extended_capabilities) || 2875 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2876 capab->extended_capabilities_len, 2877 capab->extended_capabilities_mask)) 2878 goto nla_put_failure; 2879 2880 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO && 2881 (nla_put_u16(msg, 2882 NL80211_ATTR_EML_CAPABILITY, 2883 capab->eml_capabilities) || 2884 nla_put_u16(msg, 2885 NL80211_ATTR_MLD_CAPA_AND_OPS, 2886 capab->mld_capa_and_ops))) 2887 goto nla_put_failure; 2888 2889 nla_nest_end(msg, nested_ext_capab); 2890 if (state->split) 2891 break; 2892 } 2893 nla_nest_end(msg, nested); 2894 if (i < rdev->wiphy.num_iftype_ext_capab) { 2895 state->capa_start = i + 1; 2896 break; 2897 } 2898 } 2899 2900 if (nla_put_u32(msg, NL80211_ATTR_BANDS, 2901 rdev->wiphy.nan_supported_bands)) 2902 goto nla_put_failure; 2903 2904 if (wiphy_ext_feature_isset(&rdev->wiphy, 2905 NL80211_EXT_FEATURE_TXQS)) { 2906 struct cfg80211_txq_stats txqstats = {}; 2907 int res; 2908 2909 res = rdev_get_txq_stats(rdev, NULL, &txqstats); 2910 if (!res && 2911 !nl80211_put_txq_stats(msg, &txqstats, 2912 NL80211_ATTR_TXQ_STATS)) 2913 goto nla_put_failure; 2914 2915 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, 2916 rdev->wiphy.txq_limit)) 2917 goto nla_put_failure; 2918 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, 2919 rdev->wiphy.txq_memory_limit)) 2920 goto nla_put_failure; 2921 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, 2922 rdev->wiphy.txq_quantum)) 2923 goto nla_put_failure; 2924 } 2925 2926 state->split_start++; 2927 break; 2928 case 14: 2929 if (nl80211_send_pmsr_capa(rdev, msg)) 2930 goto nla_put_failure; 2931 2932 state->split_start++; 2933 break; 2934 case 15: 2935 if (rdev->wiphy.akm_suites && 2936 nla_put(msg, NL80211_ATTR_AKM_SUITES, 2937 sizeof(u32) * rdev->wiphy.n_akm_suites, 2938 rdev->wiphy.akm_suites)) 2939 goto nla_put_failure; 2940 2941 if (nl80211_put_iftype_akm_suites(rdev, msg)) 2942 goto nla_put_failure; 2943 2944 if (nl80211_put_tid_config_support(rdev, msg)) 2945 goto nla_put_failure; 2946 state->split_start++; 2947 break; 2948 case 16: 2949 if (nl80211_put_sar_specs(rdev, msg)) 2950 goto nla_put_failure; 2951 2952 if (nl80211_put_mbssid_support(&rdev->wiphy, msg)) 2953 goto nla_put_failure; 2954 2955 if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES, 2956 rdev->wiphy.max_num_akm_suites)) 2957 goto nla_put_failure; 2958 2959 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO) 2960 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT); 2961 2962 /* done */ 2963 state->split_start = 0; 2964 break; 2965 } 2966 finish: 2967 genlmsg_end(msg, hdr); 2968 return 0; 2969 2970 nla_put_failure: 2971 genlmsg_cancel(msg, hdr); 2972 return -EMSGSIZE; 2973 } 2974 2975 static int nl80211_dump_wiphy_parse(struct sk_buff *skb, 2976 struct netlink_callback *cb, 2977 struct nl80211_dump_wiphy_state *state) 2978 { 2979 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 2980 int ret; 2981 2982 if (!tb) 2983 return -ENOMEM; 2984 2985 ret = nlmsg_parse_deprecated(cb->nlh, 2986 GENL_HDRLEN + nl80211_fam.hdrsize, 2987 tb, nl80211_fam.maxattr, 2988 nl80211_policy, NULL); 2989 /* ignore parse errors for backward compatibility */ 2990 if (ret) { 2991 ret = 0; 2992 goto out; 2993 } 2994 2995 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; 2996 if (tb[NL80211_ATTR_WIPHY]) 2997 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 2998 if (tb[NL80211_ATTR_WDEV]) 2999 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; 3000 if (tb[NL80211_ATTR_IFINDEX]) { 3001 struct net_device *netdev; 3002 struct cfg80211_registered_device *rdev; 3003 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); 3004 3005 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); 3006 if (!netdev) { 3007 ret = -ENODEV; 3008 goto out; 3009 } 3010 if (netdev->ieee80211_ptr) { 3011 rdev = wiphy_to_rdev( 3012 netdev->ieee80211_ptr->wiphy); 3013 state->filter_wiphy = rdev->wiphy_idx; 3014 } 3015 } 3016 3017 ret = 0; 3018 out: 3019 kfree(tb); 3020 return ret; 3021 } 3022 3023 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) 3024 { 3025 int idx = 0, ret; 3026 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; 3027 struct cfg80211_registered_device *rdev; 3028 3029 rtnl_lock(); 3030 if (!state) { 3031 state = kzalloc(sizeof(*state), GFP_KERNEL); 3032 if (!state) { 3033 rtnl_unlock(); 3034 return -ENOMEM; 3035 } 3036 state->filter_wiphy = -1; 3037 ret = nl80211_dump_wiphy_parse(skb, cb, state); 3038 if (ret) { 3039 kfree(state); 3040 rtnl_unlock(); 3041 return ret; 3042 } 3043 cb->args[0] = (long)state; 3044 } 3045 3046 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3047 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3048 continue; 3049 if (++idx <= state->start) 3050 continue; 3051 if (state->filter_wiphy != -1 && 3052 state->filter_wiphy != rdev->wiphy_idx) 3053 continue; 3054 /* attempt to fit multiple wiphy data chunks into the skb */ 3055 do { 3056 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, 3057 skb, 3058 NETLINK_CB(cb->skb).portid, 3059 cb->nlh->nlmsg_seq, 3060 NLM_F_MULTI, state); 3061 if (ret < 0) { 3062 /* 3063 * If sending the wiphy data didn't fit (ENOBUFS 3064 * or EMSGSIZE returned), this SKB is still 3065 * empty (so it's not too big because another 3066 * wiphy dataset is already in the skb) and 3067 * we've not tried to adjust the dump allocation 3068 * yet ... then adjust the alloc size to be 3069 * bigger, and return 1 but with the empty skb. 3070 * This results in an empty message being RX'ed 3071 * in userspace, but that is ignored. 3072 * 3073 * We can then retry with the larger buffer. 3074 */ 3075 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 3076 !skb->len && !state->split && 3077 cb->min_dump_alloc < 4096) { 3078 cb->min_dump_alloc = 4096; 3079 state->split_start = 0; 3080 rtnl_unlock(); 3081 return 1; 3082 } 3083 idx--; 3084 break; 3085 } 3086 } while (state->split_start > 0); 3087 break; 3088 } 3089 rtnl_unlock(); 3090 3091 state->start = idx; 3092 3093 return skb->len; 3094 } 3095 3096 static int nl80211_dump_wiphy_done(struct netlink_callback *cb) 3097 { 3098 kfree((void *)cb->args[0]); 3099 return 0; 3100 } 3101 3102 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 3103 { 3104 struct sk_buff *msg; 3105 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3106 struct nl80211_dump_wiphy_state state = {}; 3107 3108 msg = nlmsg_new(4096, GFP_KERNEL); 3109 if (!msg) 3110 return -ENOMEM; 3111 3112 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, 3113 info->snd_portid, info->snd_seq, 0, 3114 &state) < 0) { 3115 nlmsg_free(msg); 3116 return -ENOBUFS; 3117 } 3118 3119 return genlmsg_reply(msg, info); 3120 } 3121 3122 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 3123 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, 3124 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, 3125 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, 3126 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, 3127 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, 3128 }; 3129 3130 static int parse_txq_params(struct nlattr *tb[], 3131 struct ieee80211_txq_params *txq_params) 3132 { 3133 u8 ac; 3134 3135 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || 3136 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || 3137 !tb[NL80211_TXQ_ATTR_AIFS]) 3138 return -EINVAL; 3139 3140 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); 3141 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); 3142 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); 3143 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); 3144 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); 3145 3146 if (ac >= NL80211_NUM_ACS) 3147 return -EINVAL; 3148 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); 3149 return 0; 3150 } 3151 3152 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 3153 { 3154 /* 3155 * You can only set the channel explicitly for some interfaces, 3156 * most have their channel managed via their respective 3157 * "establish a connection" command (connect, join, ...) 3158 * 3159 * For AP/GO and mesh mode, the channel can be set with the 3160 * channel userspace API, but is only stored and passed to the 3161 * low-level driver when the AP starts or the mesh is joined. 3162 * This is for backward compatibility, userspace can also give 3163 * the channel in the start-ap or join-mesh commands instead. 3164 * 3165 * Monitors are special as they are normally slaved to 3166 * whatever else is going on, so they have their own special 3167 * operation to set the monitor channel if possible. 3168 */ 3169 return !wdev || 3170 wdev->iftype == NL80211_IFTYPE_AP || 3171 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 3172 wdev->iftype == NL80211_IFTYPE_MONITOR || 3173 wdev->iftype == NL80211_IFTYPE_P2P_GO; 3174 } 3175 3176 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, 3177 struct genl_info *info, 3178 struct cfg80211_chan_def *chandef) 3179 { 3180 struct netlink_ext_ack *extack = info->extack; 3181 struct nlattr **attrs = info->attrs; 3182 u32 control_freq; 3183 3184 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) 3185 return -EINVAL; 3186 3187 control_freq = MHZ_TO_KHZ( 3188 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 3189 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 3190 control_freq += 3191 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 3192 3193 memset(chandef, 0, sizeof(*chandef)); 3194 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); 3195 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 3196 chandef->center_freq1 = KHZ_TO_MHZ(control_freq); 3197 chandef->freq1_offset = control_freq % 1000; 3198 chandef->center_freq2 = 0; 3199 3200 /* Primary channel not allowed */ 3201 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { 3202 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 3203 "Channel is disabled"); 3204 return -EINVAL; 3205 } 3206 3207 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 3208 enum nl80211_channel_type chantype; 3209 3210 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); 3211 3212 switch (chantype) { 3213 case NL80211_CHAN_NO_HT: 3214 case NL80211_CHAN_HT20: 3215 case NL80211_CHAN_HT40PLUS: 3216 case NL80211_CHAN_HT40MINUS: 3217 cfg80211_chandef_create(chandef, chandef->chan, 3218 chantype); 3219 /* user input for center_freq is incorrect */ 3220 if (attrs[NL80211_ATTR_CENTER_FREQ1] && 3221 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { 3222 NL_SET_ERR_MSG_ATTR(extack, 3223 attrs[NL80211_ATTR_CENTER_FREQ1], 3224 "bad center frequency 1"); 3225 return -EINVAL; 3226 } 3227 /* center_freq2 must be zero */ 3228 if (attrs[NL80211_ATTR_CENTER_FREQ2] && 3229 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { 3230 NL_SET_ERR_MSG_ATTR(extack, 3231 attrs[NL80211_ATTR_CENTER_FREQ2], 3232 "center frequency 2 can't be used"); 3233 return -EINVAL; 3234 } 3235 break; 3236 default: 3237 NL_SET_ERR_MSG_ATTR(extack, 3238 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], 3239 "invalid channel type"); 3240 return -EINVAL; 3241 } 3242 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { 3243 chandef->width = 3244 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); 3245 if (chandef->chan->band == NL80211_BAND_S1GHZ) { 3246 /* User input error for channel width doesn't match channel */ 3247 if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) { 3248 NL_SET_ERR_MSG_ATTR(extack, 3249 attrs[NL80211_ATTR_CHANNEL_WIDTH], 3250 "bad channel width"); 3251 return -EINVAL; 3252 } 3253 } 3254 if (attrs[NL80211_ATTR_CENTER_FREQ1]) { 3255 chandef->center_freq1 = 3256 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 3257 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) 3258 chandef->freq1_offset = nla_get_u32( 3259 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); 3260 else 3261 chandef->freq1_offset = 0; 3262 } 3263 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 3264 chandef->center_freq2 = 3265 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); 3266 } 3267 3268 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 3269 chandef->edmg.channels = 3270 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 3271 3272 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 3273 chandef->edmg.bw_config = 3274 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 3275 } else { 3276 chandef->edmg.bw_config = 0; 3277 chandef->edmg.channels = 0; 3278 } 3279 3280 if (!cfg80211_chandef_valid(chandef)) { 3281 NL_SET_ERR_MSG(extack, "invalid channel definition"); 3282 return -EINVAL; 3283 } 3284 3285 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, 3286 IEEE80211_CHAN_DISABLED)) { 3287 NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); 3288 return -EINVAL; 3289 } 3290 3291 if ((chandef->width == NL80211_CHAN_WIDTH_5 || 3292 chandef->width == NL80211_CHAN_WIDTH_10) && 3293 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { 3294 NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); 3295 return -EINVAL; 3296 } 3297 3298 return 0; 3299 } 3300 3301 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 3302 struct net_device *dev, 3303 struct genl_info *info, 3304 int _link_id) 3305 { 3306 struct cfg80211_chan_def chandef; 3307 int result; 3308 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; 3309 struct wireless_dev *wdev = NULL; 3310 int link_id = _link_id; 3311 3312 if (dev) 3313 wdev = dev->ieee80211_ptr; 3314 if (!nl80211_can_set_dev_channel(wdev)) 3315 return -EOPNOTSUPP; 3316 if (wdev) 3317 iftype = wdev->iftype; 3318 3319 if (link_id < 0) { 3320 if (wdev && wdev->valid_links) 3321 return -EINVAL; 3322 link_id = 0; 3323 } 3324 3325 result = nl80211_parse_chandef(rdev, info, &chandef); 3326 if (result) 3327 return result; 3328 3329 switch (iftype) { 3330 case NL80211_IFTYPE_AP: 3331 case NL80211_IFTYPE_P2P_GO: 3332 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 3333 iftype)) 3334 return -EINVAL; 3335 if (wdev->links[link_id].ap.beacon_interval) { 3336 struct ieee80211_channel *cur_chan; 3337 3338 if (!dev || !rdev->ops->set_ap_chanwidth || 3339 !(rdev->wiphy.features & 3340 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) 3341 return -EBUSY; 3342 3343 /* Only allow dynamic channel width changes */ 3344 cur_chan = wdev->links[link_id].ap.chandef.chan; 3345 if (chandef.chan != cur_chan) 3346 return -EBUSY; 3347 3348 result = rdev_set_ap_chanwidth(rdev, dev, link_id, 3349 &chandef); 3350 if (result) 3351 return result; 3352 wdev->links[link_id].ap.chandef = chandef; 3353 } else { 3354 wdev->u.ap.preset_chandef = chandef; 3355 } 3356 return 0; 3357 case NL80211_IFTYPE_MESH_POINT: 3358 return cfg80211_set_mesh_channel(rdev, wdev, &chandef); 3359 case NL80211_IFTYPE_MONITOR: 3360 return cfg80211_set_monitor_channel(rdev, &chandef); 3361 default: 3362 break; 3363 } 3364 3365 return -EINVAL; 3366 } 3367 3368 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 3369 { 3370 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3371 int link_id = nl80211_link_id_or_invalid(info->attrs); 3372 struct net_device *netdev = info->user_ptr[1]; 3373 int ret; 3374 3375 wdev_lock(netdev->ieee80211_ptr); 3376 ret = __nl80211_set_channel(rdev, netdev, info, link_id); 3377 wdev_unlock(netdev->ieee80211_ptr); 3378 3379 return ret; 3380 } 3381 3382 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 3383 { 3384 struct cfg80211_registered_device *rdev = NULL; 3385 struct net_device *netdev = NULL; 3386 struct wireless_dev *wdev; 3387 int result = 0, rem_txq_params = 0; 3388 struct nlattr *nl_txq_params; 3389 u32 changed; 3390 u8 retry_short = 0, retry_long = 0; 3391 u32 frag_threshold = 0, rts_threshold = 0; 3392 u8 coverage_class = 0; 3393 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; 3394 3395 rtnl_lock(); 3396 /* 3397 * Try to find the wiphy and netdev. Normally this 3398 * function shouldn't need the netdev, but this is 3399 * done for backward compatibility -- previously 3400 * setting the channel was done per wiphy, but now 3401 * it is per netdev. Previous userland like hostapd 3402 * also passed a netdev to set_wiphy, so that it is 3403 * possible to let that go to the right netdev! 3404 */ 3405 3406 if (info->attrs[NL80211_ATTR_IFINDEX]) { 3407 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 3408 3409 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 3410 if (netdev && netdev->ieee80211_ptr) 3411 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); 3412 else 3413 netdev = NULL; 3414 } 3415 3416 if (!netdev) { 3417 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), 3418 info->attrs); 3419 if (IS_ERR(rdev)) { 3420 rtnl_unlock(); 3421 return PTR_ERR(rdev); 3422 } 3423 wdev = NULL; 3424 netdev = NULL; 3425 result = 0; 3426 } else 3427 wdev = netdev->ieee80211_ptr; 3428 3429 wiphy_lock(&rdev->wiphy); 3430 3431 /* 3432 * end workaround code, by now the rdev is available 3433 * and locked, and wdev may or may not be NULL. 3434 */ 3435 3436 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) 3437 result = cfg80211_dev_rename( 3438 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 3439 rtnl_unlock(); 3440 3441 if (result) 3442 goto out; 3443 3444 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 3445 struct ieee80211_txq_params txq_params; 3446 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 3447 3448 if (!rdev->ops->set_txq_params) { 3449 result = -EOPNOTSUPP; 3450 goto out; 3451 } 3452 3453 if (!netdev) { 3454 result = -EINVAL; 3455 goto out; 3456 } 3457 3458 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3459 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 3460 result = -EINVAL; 3461 goto out; 3462 } 3463 3464 if (!netif_running(netdev)) { 3465 result = -ENETDOWN; 3466 goto out; 3467 } 3468 3469 nla_for_each_nested(nl_txq_params, 3470 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 3471 rem_txq_params) { 3472 result = nla_parse_nested_deprecated(tb, 3473 NL80211_TXQ_ATTR_MAX, 3474 nl_txq_params, 3475 txq_params_policy, 3476 info->extack); 3477 if (result) 3478 goto out; 3479 result = parse_txq_params(tb, &txq_params); 3480 if (result) 3481 goto out; 3482 3483 txq_params.link_id = 3484 nl80211_link_id_or_invalid(info->attrs); 3485 3486 wdev_lock(netdev->ieee80211_ptr); 3487 if (txq_params.link_id >= 0 && 3488 !(netdev->ieee80211_ptr->valid_links & 3489 BIT(txq_params.link_id))) 3490 result = -ENOLINK; 3491 else if (txq_params.link_id >= 0 && 3492 !netdev->ieee80211_ptr->valid_links) 3493 result = -EINVAL; 3494 else 3495 result = rdev_set_txq_params(rdev, netdev, 3496 &txq_params); 3497 wdev_unlock(netdev->ieee80211_ptr); 3498 if (result) 3499 goto out; 3500 } 3501 } 3502 3503 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3504 int link_id = nl80211_link_id_or_invalid(info->attrs); 3505 3506 if (wdev) { 3507 wdev_lock(wdev); 3508 result = __nl80211_set_channel( 3509 rdev, 3510 nl80211_can_set_dev_channel(wdev) ? netdev : NULL, 3511 info, link_id); 3512 wdev_unlock(wdev); 3513 } else { 3514 result = __nl80211_set_channel(rdev, netdev, info, link_id); 3515 } 3516 3517 if (result) 3518 goto out; 3519 } 3520 3521 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { 3522 struct wireless_dev *txp_wdev = wdev; 3523 enum nl80211_tx_power_setting type; 3524 int idx, mbm = 0; 3525 3526 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 3527 txp_wdev = NULL; 3528 3529 if (!rdev->ops->set_tx_power) { 3530 result = -EOPNOTSUPP; 3531 goto out; 3532 } 3533 3534 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 3535 type = nla_get_u32(info->attrs[idx]); 3536 3537 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 3538 (type != NL80211_TX_POWER_AUTOMATIC)) { 3539 result = -EINVAL; 3540 goto out; 3541 } 3542 3543 if (type != NL80211_TX_POWER_AUTOMATIC) { 3544 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; 3545 mbm = nla_get_u32(info->attrs[idx]); 3546 } 3547 3548 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 3549 if (result) 3550 goto out; 3551 } 3552 3553 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && 3554 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { 3555 u32 tx_ant, rx_ant; 3556 3557 if ((!rdev->wiphy.available_antennas_tx && 3558 !rdev->wiphy.available_antennas_rx) || 3559 !rdev->ops->set_antenna) { 3560 result = -EOPNOTSUPP; 3561 goto out; 3562 } 3563 3564 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 3565 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); 3566 3567 /* reject antenna configurations which don't match the 3568 * available antenna masks, except for the "all" mask */ 3569 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 3570 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { 3571 result = -EINVAL; 3572 goto out; 3573 } 3574 3575 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 3576 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 3577 3578 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 3579 if (result) 3580 goto out; 3581 } 3582 3583 changed = 0; 3584 3585 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 3586 retry_short = nla_get_u8( 3587 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); 3588 3589 changed |= WIPHY_PARAM_RETRY_SHORT; 3590 } 3591 3592 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { 3593 retry_long = nla_get_u8( 3594 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); 3595 3596 changed |= WIPHY_PARAM_RETRY_LONG; 3597 } 3598 3599 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 3600 frag_threshold = nla_get_u32( 3601 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 3602 if (frag_threshold < 256) { 3603 result = -EINVAL; 3604 goto out; 3605 } 3606 3607 if (frag_threshold != (u32) -1) { 3608 /* 3609 * Fragments (apart from the last one) are required to 3610 * have even length. Make the fragmentation code 3611 * simpler by stripping LSB should someone try to use 3612 * odd threshold value. 3613 */ 3614 frag_threshold &= ~0x1; 3615 } 3616 changed |= WIPHY_PARAM_FRAG_THRESHOLD; 3617 } 3618 3619 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { 3620 rts_threshold = nla_get_u32( 3621 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); 3622 changed |= WIPHY_PARAM_RTS_THRESHOLD; 3623 } 3624 3625 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 3626 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3627 result = -EINVAL; 3628 goto out; 3629 } 3630 3631 coverage_class = nla_get_u8( 3632 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); 3633 changed |= WIPHY_PARAM_COVERAGE_CLASS; 3634 } 3635 3636 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3637 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { 3638 result = -EOPNOTSUPP; 3639 goto out; 3640 } 3641 3642 changed |= WIPHY_PARAM_DYN_ACK; 3643 } 3644 3645 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 3646 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3647 NL80211_EXT_FEATURE_TXQS)) { 3648 result = -EOPNOTSUPP; 3649 goto out; 3650 } 3651 txq_limit = nla_get_u32( 3652 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 3653 changed |= WIPHY_PARAM_TXQ_LIMIT; 3654 } 3655 3656 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 3657 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3658 NL80211_EXT_FEATURE_TXQS)) { 3659 result = -EOPNOTSUPP; 3660 goto out; 3661 } 3662 txq_memory_limit = nla_get_u32( 3663 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 3664 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; 3665 } 3666 3667 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 3668 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3669 NL80211_EXT_FEATURE_TXQS)) { 3670 result = -EOPNOTSUPP; 3671 goto out; 3672 } 3673 txq_quantum = nla_get_u32( 3674 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 3675 changed |= WIPHY_PARAM_TXQ_QUANTUM; 3676 } 3677 3678 if (changed) { 3679 u8 old_retry_short, old_retry_long; 3680 u32 old_frag_threshold, old_rts_threshold; 3681 u8 old_coverage_class; 3682 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 3683 3684 if (!rdev->ops->set_wiphy_params) { 3685 result = -EOPNOTSUPP; 3686 goto out; 3687 } 3688 3689 old_retry_short = rdev->wiphy.retry_short; 3690 old_retry_long = rdev->wiphy.retry_long; 3691 old_frag_threshold = rdev->wiphy.frag_threshold; 3692 old_rts_threshold = rdev->wiphy.rts_threshold; 3693 old_coverage_class = rdev->wiphy.coverage_class; 3694 old_txq_limit = rdev->wiphy.txq_limit; 3695 old_txq_memory_limit = rdev->wiphy.txq_memory_limit; 3696 old_txq_quantum = rdev->wiphy.txq_quantum; 3697 3698 if (changed & WIPHY_PARAM_RETRY_SHORT) 3699 rdev->wiphy.retry_short = retry_short; 3700 if (changed & WIPHY_PARAM_RETRY_LONG) 3701 rdev->wiphy.retry_long = retry_long; 3702 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 3703 rdev->wiphy.frag_threshold = frag_threshold; 3704 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 3705 rdev->wiphy.rts_threshold = rts_threshold; 3706 if (changed & WIPHY_PARAM_COVERAGE_CLASS) 3707 rdev->wiphy.coverage_class = coverage_class; 3708 if (changed & WIPHY_PARAM_TXQ_LIMIT) 3709 rdev->wiphy.txq_limit = txq_limit; 3710 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) 3711 rdev->wiphy.txq_memory_limit = txq_memory_limit; 3712 if (changed & WIPHY_PARAM_TXQ_QUANTUM) 3713 rdev->wiphy.txq_quantum = txq_quantum; 3714 3715 result = rdev_set_wiphy_params(rdev, changed); 3716 if (result) { 3717 rdev->wiphy.retry_short = old_retry_short; 3718 rdev->wiphy.retry_long = old_retry_long; 3719 rdev->wiphy.frag_threshold = old_frag_threshold; 3720 rdev->wiphy.rts_threshold = old_rts_threshold; 3721 rdev->wiphy.coverage_class = old_coverage_class; 3722 rdev->wiphy.txq_limit = old_txq_limit; 3723 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3724 rdev->wiphy.txq_quantum = old_txq_quantum; 3725 goto out; 3726 } 3727 } 3728 3729 result = 0; 3730 3731 out: 3732 wiphy_unlock(&rdev->wiphy); 3733 return result; 3734 } 3735 3736 static int nl80211_send_chandef(struct sk_buff *msg, 3737 const struct cfg80211_chan_def *chandef) 3738 { 3739 if (WARN_ON(!cfg80211_chandef_valid(chandef))) 3740 return -EINVAL; 3741 3742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 3743 chandef->chan->center_freq)) 3744 return -ENOBUFS; 3745 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 3746 chandef->chan->freq_offset)) 3747 return -ENOBUFS; 3748 switch (chandef->width) { 3749 case NL80211_CHAN_WIDTH_20_NOHT: 3750 case NL80211_CHAN_WIDTH_20: 3751 case NL80211_CHAN_WIDTH_40: 3752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 3753 cfg80211_get_chandef_type(chandef))) 3754 return -ENOBUFS; 3755 break; 3756 default: 3757 break; 3758 } 3759 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) 3760 return -ENOBUFS; 3761 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) 3762 return -ENOBUFS; 3763 if (chandef->center_freq2 && 3764 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) 3765 return -ENOBUFS; 3766 return 0; 3767 } 3768 3769 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, 3770 struct cfg80211_registered_device *rdev, 3771 struct wireless_dev *wdev, 3772 enum nl80211_commands cmd) 3773 { 3774 struct net_device *dev = wdev->netdev; 3775 void *hdr; 3776 3777 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && 3778 cmd != NL80211_CMD_DEL_INTERFACE && 3779 cmd != NL80211_CMD_SET_INTERFACE); 3780 3781 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 3782 if (!hdr) 3783 return -1; 3784 3785 if (dev && 3786 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3787 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) 3788 goto nla_put_failure; 3789 3790 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3791 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || 3792 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3793 NL80211_ATTR_PAD) || 3794 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || 3795 nla_put_u32(msg, NL80211_ATTR_GENERATION, 3796 rdev->devlist_generation ^ 3797 (cfg80211_rdev_list_generation << 2)) || 3798 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) 3799 goto nla_put_failure; 3800 3801 if (rdev->ops->get_channel && !wdev->valid_links) { 3802 struct cfg80211_chan_def chandef = {}; 3803 int ret; 3804 3805 ret = rdev_get_channel(rdev, wdev, 0, &chandef); 3806 if (ret == 0 && nl80211_send_chandef(msg, &chandef)) 3807 goto nla_put_failure; 3808 } 3809 3810 if (rdev->ops->get_tx_power) { 3811 int dbm, ret; 3812 3813 ret = rdev_get_tx_power(rdev, wdev, &dbm); 3814 if (ret == 0 && 3815 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, 3816 DBM_TO_MBM(dbm))) 3817 goto nla_put_failure; 3818 } 3819 3820 wdev_lock(wdev); 3821 switch (wdev->iftype) { 3822 case NL80211_IFTYPE_AP: 3823 case NL80211_IFTYPE_P2P_GO: 3824 if (wdev->u.ap.ssid_len && 3825 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len, 3826 wdev->u.ap.ssid)) 3827 goto nla_put_failure_locked; 3828 break; 3829 case NL80211_IFTYPE_STATION: 3830 case NL80211_IFTYPE_P2P_CLIENT: 3831 if (wdev->u.client.ssid_len && 3832 nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len, 3833 wdev->u.client.ssid)) 3834 goto nla_put_failure_locked; 3835 break; 3836 case NL80211_IFTYPE_ADHOC: 3837 if (wdev->u.ibss.ssid_len && 3838 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len, 3839 wdev->u.ibss.ssid)) 3840 goto nla_put_failure_locked; 3841 break; 3842 default: 3843 /* nothing */ 3844 break; 3845 } 3846 wdev_unlock(wdev); 3847 3848 if (rdev->ops->get_txq_stats) { 3849 struct cfg80211_txq_stats txqstats = {}; 3850 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); 3851 3852 if (ret == 0 && 3853 !nl80211_put_txq_stats(msg, &txqstats, 3854 NL80211_ATTR_TXQ_STATS)) 3855 goto nla_put_failure; 3856 } 3857 3858 if (wdev->valid_links) { 3859 unsigned int link_id; 3860 struct nlattr *links = nla_nest_start(msg, 3861 NL80211_ATTR_MLO_LINKS); 3862 3863 if (!links) 3864 goto nla_put_failure; 3865 3866 for_each_valid_link(wdev, link_id) { 3867 struct nlattr *link = nla_nest_start(msg, link_id + 1); 3868 struct cfg80211_chan_def chandef = {}; 3869 int ret; 3870 3871 if (!link) 3872 goto nla_put_failure; 3873 3874 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 3875 goto nla_put_failure; 3876 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 3877 wdev->links[link_id].addr)) 3878 goto nla_put_failure; 3879 3880 ret = rdev_get_channel(rdev, wdev, link_id, &chandef); 3881 if (ret == 0 && nl80211_send_chandef(msg, &chandef)) 3882 goto nla_put_failure; 3883 3884 nla_nest_end(msg, link); 3885 } 3886 3887 nla_nest_end(msg, links); 3888 } 3889 3890 genlmsg_end(msg, hdr); 3891 return 0; 3892 3893 nla_put_failure_locked: 3894 wdev_unlock(wdev); 3895 nla_put_failure: 3896 genlmsg_cancel(msg, hdr); 3897 return -EMSGSIZE; 3898 } 3899 3900 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) 3901 { 3902 int wp_idx = 0; 3903 int if_idx = 0; 3904 int wp_start = cb->args[0]; 3905 int if_start = cb->args[1]; 3906 int filter_wiphy = -1; 3907 struct cfg80211_registered_device *rdev; 3908 struct wireless_dev *wdev; 3909 int ret; 3910 3911 rtnl_lock(); 3912 if (!cb->args[2]) { 3913 struct nl80211_dump_wiphy_state state = { 3914 .filter_wiphy = -1, 3915 }; 3916 3917 ret = nl80211_dump_wiphy_parse(skb, cb, &state); 3918 if (ret) 3919 goto out_unlock; 3920 3921 filter_wiphy = state.filter_wiphy; 3922 3923 /* 3924 * if filtering, set cb->args[2] to +1 since 0 is the default 3925 * value needed to determine that parsing is necessary. 3926 */ 3927 if (filter_wiphy >= 0) 3928 cb->args[2] = filter_wiphy + 1; 3929 else 3930 cb->args[2] = -1; 3931 } else if (cb->args[2] > 0) { 3932 filter_wiphy = cb->args[2] - 1; 3933 } 3934 3935 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3936 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3937 continue; 3938 if (wp_idx < wp_start) { 3939 wp_idx++; 3940 continue; 3941 } 3942 3943 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) 3944 continue; 3945 3946 if_idx = 0; 3947 3948 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 3949 if (if_idx < if_start) { 3950 if_idx++; 3951 continue; 3952 } 3953 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 3954 cb->nlh->nlmsg_seq, NLM_F_MULTI, 3955 rdev, wdev, 3956 NL80211_CMD_NEW_INTERFACE) < 0) { 3957 goto out; 3958 } 3959 if_idx++; 3960 } 3961 3962 wp_idx++; 3963 } 3964 out: 3965 cb->args[0] = wp_idx; 3966 cb->args[1] = if_idx; 3967 3968 ret = skb->len; 3969 out_unlock: 3970 rtnl_unlock(); 3971 3972 return ret; 3973 } 3974 3975 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 3976 { 3977 struct sk_buff *msg; 3978 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3979 struct wireless_dev *wdev = info->user_ptr[1]; 3980 3981 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3982 if (!msg) 3983 return -ENOMEM; 3984 3985 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 3986 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 3987 nlmsg_free(msg); 3988 return -ENOBUFS; 3989 } 3990 3991 return genlmsg_reply(msg, info); 3992 } 3993 3994 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 3995 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, 3996 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, 3997 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, 3998 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, 3999 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, 4000 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, 4001 }; 4002 4003 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) 4004 { 4005 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; 4006 int flag; 4007 4008 *mntrflags = 0; 4009 4010 if (!nla) 4011 return -EINVAL; 4012 4013 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) 4014 return -EINVAL; 4015 4016 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 4017 if (flags[flag]) 4018 *mntrflags |= (1<<flag); 4019 4020 *mntrflags |= MONITOR_FLAG_CHANGED; 4021 4022 return 0; 4023 } 4024 4025 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, 4026 enum nl80211_iftype type, 4027 struct genl_info *info, 4028 struct vif_params *params) 4029 { 4030 bool change = false; 4031 int err; 4032 4033 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 4034 if (type != NL80211_IFTYPE_MONITOR) 4035 return -EINVAL; 4036 4037 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 4038 ¶ms->flags); 4039 if (err) 4040 return err; 4041 4042 change = true; 4043 } 4044 4045 if (params->flags & MONITOR_FLAG_ACTIVE && 4046 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 4047 return -EOPNOTSUPP; 4048 4049 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { 4050 const u8 *mumimo_groups; 4051 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 4052 4053 if (type != NL80211_IFTYPE_MONITOR) 4054 return -EINVAL; 4055 4056 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 4057 return -EOPNOTSUPP; 4058 4059 mumimo_groups = 4060 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); 4061 4062 /* bits 0 and 63 are reserved and must be zero */ 4063 if ((mumimo_groups[0] & BIT(0)) || 4064 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) 4065 return -EINVAL; 4066 4067 params->vht_mumimo_groups = mumimo_groups; 4068 change = true; 4069 } 4070 4071 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { 4072 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 4073 4074 if (type != NL80211_IFTYPE_MONITOR) 4075 return -EINVAL; 4076 4077 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 4078 return -EOPNOTSUPP; 4079 4080 params->vht_mumimo_follow_addr = 4081 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); 4082 change = true; 4083 } 4084 4085 return change ? 1 : 0; 4086 } 4087 4088 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, 4089 struct net_device *netdev, u8 use_4addr, 4090 enum nl80211_iftype iftype) 4091 { 4092 if (!use_4addr) { 4093 if (netdev && netif_is_bridge_port(netdev)) 4094 return -EBUSY; 4095 return 0; 4096 } 4097 4098 switch (iftype) { 4099 case NL80211_IFTYPE_AP_VLAN: 4100 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) 4101 return 0; 4102 break; 4103 case NL80211_IFTYPE_STATION: 4104 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) 4105 return 0; 4106 break; 4107 default: 4108 break; 4109 } 4110 4111 return -EOPNOTSUPP; 4112 } 4113 4114 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 4115 { 4116 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4117 struct vif_params params; 4118 int err; 4119 enum nl80211_iftype otype, ntype; 4120 struct net_device *dev = info->user_ptr[1]; 4121 bool change = false; 4122 4123 memset(¶ms, 0, sizeof(params)); 4124 4125 otype = ntype = dev->ieee80211_ptr->iftype; 4126 4127 if (info->attrs[NL80211_ATTR_IFTYPE]) { 4128 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 4129 if (otype != ntype) 4130 change = true; 4131 } 4132 4133 if (info->attrs[NL80211_ATTR_MESH_ID]) { 4134 struct wireless_dev *wdev = dev->ieee80211_ptr; 4135 4136 if (ntype != NL80211_IFTYPE_MESH_POINT) 4137 return -EINVAL; 4138 if (netif_running(dev)) 4139 return -EBUSY; 4140 4141 wdev_lock(wdev); 4142 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4143 IEEE80211_MAX_MESH_ID_LEN); 4144 wdev->u.mesh.id_up_len = 4145 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4146 memcpy(wdev->u.mesh.id, 4147 nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4148 wdev->u.mesh.id_up_len); 4149 wdev_unlock(wdev); 4150 } 4151 4152 if (info->attrs[NL80211_ATTR_4ADDR]) { 4153 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 4154 change = true; 4155 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 4156 if (err) 4157 return err; 4158 } else { 4159 params.use_4addr = -1; 4160 } 4161 4162 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); 4163 if (err < 0) 4164 return err; 4165 if (err > 0) 4166 change = true; 4167 4168 if (change) 4169 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); 4170 else 4171 err = 0; 4172 4173 if (!err && params.use_4addr != -1) 4174 dev->ieee80211_ptr->use_4addr = params.use_4addr; 4175 4176 if (change && !err) { 4177 struct wireless_dev *wdev = dev->ieee80211_ptr; 4178 4179 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); 4180 } 4181 4182 return err; 4183 } 4184 4185 static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4186 { 4187 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4188 struct vif_params params; 4189 struct wireless_dev *wdev; 4190 struct sk_buff *msg; 4191 int err; 4192 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 4193 4194 memset(¶ms, 0, sizeof(params)); 4195 4196 if (!info->attrs[NL80211_ATTR_IFNAME]) 4197 return -EINVAL; 4198 4199 if (info->attrs[NL80211_ATTR_IFTYPE]) 4200 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 4201 4202 if (!rdev->ops->add_virtual_intf) 4203 return -EOPNOTSUPP; 4204 4205 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || 4206 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && 4207 info->attrs[NL80211_ATTR_MAC]) { 4208 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 4209 ETH_ALEN); 4210 if (!is_valid_ether_addr(params.macaddr)) 4211 return -EADDRNOTAVAIL; 4212 } 4213 4214 if (info->attrs[NL80211_ATTR_4ADDR]) { 4215 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 4216 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 4217 if (err) 4218 return err; 4219 } 4220 4221 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) 4222 return -EOPNOTSUPP; 4223 4224 err = nl80211_parse_mon_options(rdev, type, info, ¶ms); 4225 if (err < 0) 4226 return err; 4227 4228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4229 if (!msg) 4230 return -ENOMEM; 4231 4232 wdev = rdev_add_virtual_intf(rdev, 4233 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 4234 NET_NAME_USER, type, ¶ms); 4235 if (WARN_ON(!wdev)) { 4236 nlmsg_free(msg); 4237 return -EPROTO; 4238 } else if (IS_ERR(wdev)) { 4239 nlmsg_free(msg); 4240 return PTR_ERR(wdev); 4241 } 4242 4243 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 4244 wdev->owner_nlportid = info->snd_portid; 4245 4246 switch (type) { 4247 case NL80211_IFTYPE_MESH_POINT: 4248 if (!info->attrs[NL80211_ATTR_MESH_ID]) 4249 break; 4250 wdev_lock(wdev); 4251 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4252 IEEE80211_MAX_MESH_ID_LEN); 4253 wdev->u.mesh.id_up_len = 4254 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4255 memcpy(wdev->u.mesh.id, 4256 nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4257 wdev->u.mesh.id_up_len); 4258 wdev_unlock(wdev); 4259 break; 4260 case NL80211_IFTYPE_NAN: 4261 case NL80211_IFTYPE_P2P_DEVICE: 4262 /* 4263 * P2P Device and NAN do not have a netdev, so don't go 4264 * through the netdev notifier and must be added here 4265 */ 4266 cfg80211_init_wdev(wdev); 4267 cfg80211_register_wdev(rdev, wdev); 4268 break; 4269 default: 4270 break; 4271 } 4272 4273 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 4274 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 4275 nlmsg_free(msg); 4276 return -ENOBUFS; 4277 } 4278 4279 return genlmsg_reply(msg, info); 4280 } 4281 4282 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4283 { 4284 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4285 int ret; 4286 4287 /* to avoid failing a new interface creation due to pending removal */ 4288 cfg80211_destroy_ifaces(rdev); 4289 4290 wiphy_lock(&rdev->wiphy); 4291 ret = _nl80211_new_interface(skb, info); 4292 wiphy_unlock(&rdev->wiphy); 4293 4294 return ret; 4295 } 4296 4297 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 4298 { 4299 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4300 struct wireless_dev *wdev = info->user_ptr[1]; 4301 4302 if (!rdev->ops->del_virtual_intf) 4303 return -EOPNOTSUPP; 4304 4305 /* 4306 * We hold RTNL, so this is safe, without RTNL opencount cannot 4307 * reach 0, and thus the rdev cannot be deleted. 4308 * 4309 * We need to do it for the dev_close(), since that will call 4310 * the netdev notifiers, and we need to acquire the mutex there 4311 * but don't know if we get there from here or from some other 4312 * place (e.g. "ip link set ... down"). 4313 */ 4314 mutex_unlock(&rdev->wiphy.mtx); 4315 4316 /* 4317 * If we remove a wireless device without a netdev then clear 4318 * user_ptr[1] so that nl80211_post_doit won't dereference it 4319 * to check if it needs to do dev_put(). Otherwise it crashes 4320 * since the wdev has been freed, unlike with a netdev where 4321 * we need the dev_put() for the netdev to really be freed. 4322 */ 4323 if (!wdev->netdev) 4324 info->user_ptr[1] = NULL; 4325 else 4326 dev_close(wdev->netdev); 4327 4328 mutex_lock(&rdev->wiphy.mtx); 4329 4330 return cfg80211_remove_virtual_intf(rdev, wdev); 4331 } 4332 4333 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) 4334 { 4335 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4336 struct net_device *dev = info->user_ptr[1]; 4337 u16 noack_map; 4338 4339 if (!info->attrs[NL80211_ATTR_NOACK_MAP]) 4340 return -EINVAL; 4341 4342 if (!rdev->ops->set_noack_map) 4343 return -EOPNOTSUPP; 4344 4345 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); 4346 4347 return rdev_set_noack_map(rdev, dev, noack_map); 4348 } 4349 4350 static int nl80211_validate_key_link_id(struct genl_info *info, 4351 struct wireless_dev *wdev, 4352 int link_id, bool pairwise) 4353 { 4354 if (pairwise) { 4355 if (link_id != -1) { 4356 GENL_SET_ERR_MSG(info, 4357 "link ID not allowed for pairwise key"); 4358 return -EINVAL; 4359 } 4360 4361 return 0; 4362 } 4363 4364 if (wdev->valid_links) { 4365 if (link_id == -1) { 4366 GENL_SET_ERR_MSG(info, 4367 "link ID must for MLO group key"); 4368 return -EINVAL; 4369 } 4370 if (!(wdev->valid_links & BIT(link_id))) { 4371 GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key"); 4372 return -EINVAL; 4373 } 4374 } else if (link_id != -1) { 4375 GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key"); 4376 return -EINVAL; 4377 } 4378 4379 return 0; 4380 } 4381 4382 struct get_key_cookie { 4383 struct sk_buff *msg; 4384 int error; 4385 int idx; 4386 }; 4387 4388 static void get_key_callback(void *c, struct key_params *params) 4389 { 4390 struct nlattr *key; 4391 struct get_key_cookie *cookie = c; 4392 4393 if ((params->key && 4394 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, 4395 params->key_len, params->key)) || 4396 (params->seq && 4397 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, 4398 params->seq_len, params->seq)) || 4399 (params->cipher && 4400 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, 4401 params->cipher))) 4402 goto nla_put_failure; 4403 4404 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); 4405 if (!key) 4406 goto nla_put_failure; 4407 4408 if ((params->key && 4409 nla_put(cookie->msg, NL80211_KEY_DATA, 4410 params->key_len, params->key)) || 4411 (params->seq && 4412 nla_put(cookie->msg, NL80211_KEY_SEQ, 4413 params->seq_len, params->seq)) || 4414 (params->cipher && 4415 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, 4416 params->cipher))) 4417 goto nla_put_failure; 4418 4419 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) 4420 goto nla_put_failure; 4421 4422 nla_nest_end(cookie->msg, key); 4423 4424 return; 4425 nla_put_failure: 4426 cookie->error = 1; 4427 } 4428 4429 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 4430 { 4431 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4432 int err; 4433 struct net_device *dev = info->user_ptr[1]; 4434 u8 key_idx = 0; 4435 const u8 *mac_addr = NULL; 4436 bool pairwise; 4437 struct get_key_cookie cookie = { 4438 .error = 0, 4439 }; 4440 void *hdr; 4441 struct sk_buff *msg; 4442 bool bigtk_support = false; 4443 int link_id = nl80211_link_id_or_invalid(info->attrs); 4444 struct wireless_dev *wdev = dev->ieee80211_ptr; 4445 4446 if (wiphy_ext_feature_isset(&rdev->wiphy, 4447 NL80211_EXT_FEATURE_BEACON_PROTECTION)) 4448 bigtk_support = true; 4449 4450 if ((wdev->iftype == NL80211_IFTYPE_STATION || 4451 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) && 4452 wiphy_ext_feature_isset(&rdev->wiphy, 4453 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) 4454 bigtk_support = true; 4455 4456 if (info->attrs[NL80211_ATTR_KEY_IDX]) { 4457 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 4458 4459 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { 4460 GENL_SET_ERR_MSG(info, "BIGTK not supported"); 4461 return -EINVAL; 4462 } 4463 } 4464 4465 if (info->attrs[NL80211_ATTR_MAC]) 4466 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4467 4468 pairwise = !!mac_addr; 4469 if (info->attrs[NL80211_ATTR_KEY_TYPE]) { 4470 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 4471 4472 if (kt != NL80211_KEYTYPE_GROUP && 4473 kt != NL80211_KEYTYPE_PAIRWISE) 4474 return -EINVAL; 4475 pairwise = kt == NL80211_KEYTYPE_PAIRWISE; 4476 } 4477 4478 if (!rdev->ops->get_key) 4479 return -EOPNOTSUPP; 4480 4481 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4482 return -ENOENT; 4483 4484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4485 if (!msg) 4486 return -ENOMEM; 4487 4488 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 4489 NL80211_CMD_NEW_KEY); 4490 if (!hdr) 4491 goto nla_put_failure; 4492 4493 cookie.msg = msg; 4494 cookie.idx = key_idx; 4495 4496 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 4497 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) 4498 goto nla_put_failure; 4499 if (mac_addr && 4500 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) 4501 goto nla_put_failure; 4502 4503 err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise); 4504 if (err) 4505 goto free_msg; 4506 4507 err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr, 4508 &cookie, get_key_callback); 4509 4510 if (err) 4511 goto free_msg; 4512 4513 if (cookie.error) 4514 goto nla_put_failure; 4515 4516 genlmsg_end(msg, hdr); 4517 return genlmsg_reply(msg, info); 4518 4519 nla_put_failure: 4520 err = -ENOBUFS; 4521 free_msg: 4522 nlmsg_free(msg); 4523 return err; 4524 } 4525 4526 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 4527 { 4528 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4529 struct key_parse key; 4530 int err; 4531 struct net_device *dev = info->user_ptr[1]; 4532 int link_id = nl80211_link_id_or_invalid(info->attrs); 4533 struct wireless_dev *wdev = dev->ieee80211_ptr; 4534 4535 err = nl80211_parse_key(info, &key); 4536 if (err) 4537 return err; 4538 4539 if (key.idx < 0) 4540 return -EINVAL; 4541 4542 /* Only support setting default key and 4543 * Extended Key ID action NL80211_KEY_SET_TX. 4544 */ 4545 if (!key.def && !key.defmgmt && !key.defbeacon && 4546 !(key.p.mode == NL80211_KEY_SET_TX)) 4547 return -EINVAL; 4548 4549 wdev_lock(wdev); 4550 4551 if (key.def) { 4552 if (!rdev->ops->set_default_key) { 4553 err = -EOPNOTSUPP; 4554 goto out; 4555 } 4556 4557 err = nl80211_key_allowed(wdev); 4558 if (err) 4559 goto out; 4560 4561 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4562 if (err) 4563 goto out; 4564 4565 err = rdev_set_default_key(rdev, dev, link_id, key.idx, 4566 key.def_uni, key.def_multi); 4567 4568 if (err) 4569 goto out; 4570 4571 #ifdef CONFIG_CFG80211_WEXT 4572 wdev->wext.default_key = key.idx; 4573 #endif 4574 } else if (key.defmgmt) { 4575 if (key.def_uni || !key.def_multi) { 4576 err = -EINVAL; 4577 goto out; 4578 } 4579 4580 if (!rdev->ops->set_default_mgmt_key) { 4581 err = -EOPNOTSUPP; 4582 goto out; 4583 } 4584 4585 err = nl80211_key_allowed(wdev); 4586 if (err) 4587 goto out; 4588 4589 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4590 if (err) 4591 goto out; 4592 4593 err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx); 4594 if (err) 4595 goto out; 4596 4597 #ifdef CONFIG_CFG80211_WEXT 4598 wdev->wext.default_mgmt_key = key.idx; 4599 #endif 4600 } else if (key.defbeacon) { 4601 if (key.def_uni || !key.def_multi) { 4602 err = -EINVAL; 4603 goto out; 4604 } 4605 4606 if (!rdev->ops->set_default_beacon_key) { 4607 err = -EOPNOTSUPP; 4608 goto out; 4609 } 4610 4611 err = nl80211_key_allowed(wdev); 4612 if (err) 4613 goto out; 4614 4615 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4616 if (err) 4617 goto out; 4618 4619 err = rdev_set_default_beacon_key(rdev, dev, link_id, key.idx); 4620 if (err) 4621 goto out; 4622 } else if (key.p.mode == NL80211_KEY_SET_TX && 4623 wiphy_ext_feature_isset(&rdev->wiphy, 4624 NL80211_EXT_FEATURE_EXT_KEY_ID)) { 4625 u8 *mac_addr = NULL; 4626 4627 if (info->attrs[NL80211_ATTR_MAC]) 4628 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4629 4630 if (!mac_addr || key.idx < 0 || key.idx > 1) { 4631 err = -EINVAL; 4632 goto out; 4633 } 4634 4635 err = nl80211_validate_key_link_id(info, wdev, link_id, true); 4636 if (err) 4637 goto out; 4638 4639 err = rdev_add_key(rdev, dev, link_id, key.idx, 4640 NL80211_KEYTYPE_PAIRWISE, 4641 mac_addr, &key.p); 4642 } else { 4643 err = -EINVAL; 4644 } 4645 out: 4646 wdev_unlock(wdev); 4647 4648 return err; 4649 } 4650 4651 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 4652 { 4653 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4654 int err; 4655 struct net_device *dev = info->user_ptr[1]; 4656 struct key_parse key; 4657 const u8 *mac_addr = NULL; 4658 int link_id = nl80211_link_id_or_invalid(info->attrs); 4659 struct wireless_dev *wdev = dev->ieee80211_ptr; 4660 4661 err = nl80211_parse_key(info, &key); 4662 if (err) 4663 return err; 4664 4665 if (!key.p.key) { 4666 GENL_SET_ERR_MSG(info, "no key"); 4667 return -EINVAL; 4668 } 4669 4670 if (info->attrs[NL80211_ATTR_MAC]) 4671 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4672 4673 if (key.type == -1) { 4674 if (mac_addr) 4675 key.type = NL80211_KEYTYPE_PAIRWISE; 4676 else 4677 key.type = NL80211_KEYTYPE_GROUP; 4678 } 4679 4680 /* for now */ 4681 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4682 key.type != NL80211_KEYTYPE_GROUP) { 4683 GENL_SET_ERR_MSG(info, "key type not pairwise or group"); 4684 return -EINVAL; 4685 } 4686 4687 if (key.type == NL80211_KEYTYPE_GROUP && 4688 info->attrs[NL80211_ATTR_VLAN_ID]) 4689 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 4690 4691 if (!rdev->ops->add_key) 4692 return -EOPNOTSUPP; 4693 4694 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, 4695 key.type == NL80211_KEYTYPE_PAIRWISE, 4696 mac_addr)) { 4697 GENL_SET_ERR_MSG(info, "key setting validation failed"); 4698 return -EINVAL; 4699 } 4700 4701 wdev_lock(wdev); 4702 err = nl80211_key_allowed(wdev); 4703 if (err) 4704 GENL_SET_ERR_MSG(info, "key not allowed"); 4705 4706 if (!err) 4707 err = nl80211_validate_key_link_id(info, wdev, link_id, 4708 key.type == NL80211_KEYTYPE_PAIRWISE); 4709 4710 if (!err) { 4711 err = rdev_add_key(rdev, dev, link_id, key.idx, 4712 key.type == NL80211_KEYTYPE_PAIRWISE, 4713 mac_addr, &key.p); 4714 if (err) 4715 GENL_SET_ERR_MSG(info, "key addition failed"); 4716 } 4717 wdev_unlock(wdev); 4718 4719 return err; 4720 } 4721 4722 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 4723 { 4724 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4725 int err; 4726 struct net_device *dev = info->user_ptr[1]; 4727 u8 *mac_addr = NULL; 4728 struct key_parse key; 4729 int link_id = nl80211_link_id_or_invalid(info->attrs); 4730 struct wireless_dev *wdev = dev->ieee80211_ptr; 4731 4732 err = nl80211_parse_key(info, &key); 4733 if (err) 4734 return err; 4735 4736 if (info->attrs[NL80211_ATTR_MAC]) 4737 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4738 4739 if (key.type == -1) { 4740 if (mac_addr) 4741 key.type = NL80211_KEYTYPE_PAIRWISE; 4742 else 4743 key.type = NL80211_KEYTYPE_GROUP; 4744 } 4745 4746 /* for now */ 4747 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4748 key.type != NL80211_KEYTYPE_GROUP) 4749 return -EINVAL; 4750 4751 if (!cfg80211_valid_key_idx(rdev, key.idx, 4752 key.type == NL80211_KEYTYPE_PAIRWISE)) 4753 return -EINVAL; 4754 4755 if (!rdev->ops->del_key) 4756 return -EOPNOTSUPP; 4757 4758 wdev_lock(wdev); 4759 err = nl80211_key_allowed(wdev); 4760 4761 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && 4762 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4763 err = -ENOENT; 4764 4765 if (!err) 4766 err = nl80211_validate_key_link_id(info, wdev, link_id, 4767 key.type == NL80211_KEYTYPE_PAIRWISE); 4768 4769 if (!err) 4770 err = rdev_del_key(rdev, dev, link_id, key.idx, 4771 key.type == NL80211_KEYTYPE_PAIRWISE, 4772 mac_addr); 4773 4774 #ifdef CONFIG_CFG80211_WEXT 4775 if (!err) { 4776 if (key.idx == wdev->wext.default_key) 4777 wdev->wext.default_key = -1; 4778 else if (key.idx == wdev->wext.default_mgmt_key) 4779 wdev->wext.default_mgmt_key = -1; 4780 } 4781 #endif 4782 wdev_unlock(wdev); 4783 4784 return err; 4785 } 4786 4787 /* This function returns an error or the number of nested attributes */ 4788 static int validate_acl_mac_addrs(struct nlattr *nl_attr) 4789 { 4790 struct nlattr *attr; 4791 int n_entries = 0, tmp; 4792 4793 nla_for_each_nested(attr, nl_attr, tmp) { 4794 if (nla_len(attr) != ETH_ALEN) 4795 return -EINVAL; 4796 4797 n_entries++; 4798 } 4799 4800 return n_entries; 4801 } 4802 4803 /* 4804 * This function parses ACL information and allocates memory for ACL data. 4805 * On successful return, the calling function is responsible to free the 4806 * ACL buffer returned by this function. 4807 */ 4808 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, 4809 struct genl_info *info) 4810 { 4811 enum nl80211_acl_policy acl_policy; 4812 struct nlattr *attr; 4813 struct cfg80211_acl_data *acl; 4814 int i = 0, n_entries, tmp; 4815 4816 if (!wiphy->max_acl_mac_addrs) 4817 return ERR_PTR(-EOPNOTSUPP); 4818 4819 if (!info->attrs[NL80211_ATTR_ACL_POLICY]) 4820 return ERR_PTR(-EINVAL); 4821 4822 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); 4823 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && 4824 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) 4825 return ERR_PTR(-EINVAL); 4826 4827 if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) 4828 return ERR_PTR(-EINVAL); 4829 4830 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); 4831 if (n_entries < 0) 4832 return ERR_PTR(n_entries); 4833 4834 if (n_entries > wiphy->max_acl_mac_addrs) 4835 return ERR_PTR(-ENOTSUPP); 4836 4837 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); 4838 if (!acl) 4839 return ERR_PTR(-ENOMEM); 4840 4841 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { 4842 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); 4843 i++; 4844 } 4845 4846 acl->n_acl_entries = n_entries; 4847 acl->acl_policy = acl_policy; 4848 4849 return acl; 4850 } 4851 4852 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) 4853 { 4854 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4855 struct net_device *dev = info->user_ptr[1]; 4856 struct cfg80211_acl_data *acl; 4857 int err; 4858 4859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4860 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4861 return -EOPNOTSUPP; 4862 4863 if (!dev->ieee80211_ptr->links[0].ap.beacon_interval) 4864 return -EINVAL; 4865 4866 acl = parse_acl_data(&rdev->wiphy, info); 4867 if (IS_ERR(acl)) 4868 return PTR_ERR(acl); 4869 4870 err = rdev_set_mac_acl(rdev, dev, acl); 4871 4872 kfree(acl); 4873 4874 return err; 4875 } 4876 4877 static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 4878 u8 *rates, u8 rates_len) 4879 { 4880 u8 i; 4881 u32 mask = 0; 4882 4883 for (i = 0; i < rates_len; i++) { 4884 int rate = (rates[i] & 0x7f) * 5; 4885 int ridx; 4886 4887 for (ridx = 0; ridx < sband->n_bitrates; ridx++) { 4888 struct ieee80211_rate *srate = 4889 &sband->bitrates[ridx]; 4890 if (rate == srate->bitrate) { 4891 mask |= 1 << ridx; 4892 break; 4893 } 4894 } 4895 if (ridx == sband->n_bitrates) 4896 return 0; /* rate not found */ 4897 } 4898 4899 return mask; 4900 } 4901 4902 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, 4903 u8 *rates, u8 rates_len, 4904 u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) 4905 { 4906 u8 i; 4907 4908 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); 4909 4910 for (i = 0; i < rates_len; i++) { 4911 int ridx, rbit; 4912 4913 ridx = rates[i] / 8; 4914 rbit = BIT(rates[i] % 8); 4915 4916 /* check validity */ 4917 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) 4918 return false; 4919 4920 /* check availability */ 4921 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); 4922 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) 4923 mcs[ridx] |= rbit; 4924 else 4925 return false; 4926 } 4927 4928 return true; 4929 } 4930 4931 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) 4932 { 4933 u16 mcs_mask = 0; 4934 4935 switch (vht_mcs_map) { 4936 case IEEE80211_VHT_MCS_NOT_SUPPORTED: 4937 break; 4938 case IEEE80211_VHT_MCS_SUPPORT_0_7: 4939 mcs_mask = 0x00FF; 4940 break; 4941 case IEEE80211_VHT_MCS_SUPPORT_0_8: 4942 mcs_mask = 0x01FF; 4943 break; 4944 case IEEE80211_VHT_MCS_SUPPORT_0_9: 4945 mcs_mask = 0x03FF; 4946 break; 4947 default: 4948 break; 4949 } 4950 4951 return mcs_mask; 4952 } 4953 4954 static void vht_build_mcs_mask(u16 vht_mcs_map, 4955 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) 4956 { 4957 u8 nss; 4958 4959 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 4960 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); 4961 vht_mcs_map >>= 2; 4962 } 4963 } 4964 4965 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, 4966 struct nl80211_txrate_vht *txrate, 4967 u16 mcs[NL80211_VHT_NSS_MAX]) 4968 { 4969 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4970 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; 4971 u8 i; 4972 4973 if (!sband->vht_cap.vht_supported) 4974 return false; 4975 4976 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); 4977 4978 /* Build vht_mcs_mask from VHT capabilities */ 4979 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 4980 4981 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4982 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 4983 mcs[i] = txrate->mcs[i]; 4984 else 4985 return false; 4986 } 4987 4988 return true; 4989 } 4990 4991 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) 4992 { 4993 switch (he_mcs_map) { 4994 case IEEE80211_HE_MCS_NOT_SUPPORTED: 4995 return 0; 4996 case IEEE80211_HE_MCS_SUPPORT_0_7: 4997 return 0x00FF; 4998 case IEEE80211_HE_MCS_SUPPORT_0_9: 4999 return 0x03FF; 5000 case IEEE80211_HE_MCS_SUPPORT_0_11: 5001 return 0xFFF; 5002 default: 5003 break; 5004 } 5005 return 0; 5006 } 5007 5008 static void he_build_mcs_mask(u16 he_mcs_map, 5009 u16 he_mcs_mask[NL80211_HE_NSS_MAX]) 5010 { 5011 u8 nss; 5012 5013 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { 5014 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); 5015 he_mcs_map >>= 2; 5016 } 5017 } 5018 5019 static u16 he_get_txmcsmap(struct genl_info *info, unsigned int link_id, 5020 const struct ieee80211_sta_he_cap *he_cap) 5021 { 5022 struct net_device *dev = info->user_ptr[1]; 5023 struct wireless_dev *wdev = dev->ieee80211_ptr; 5024 struct cfg80211_chan_def *chandef; 5025 __le16 tx_mcs; 5026 5027 chandef = wdev_chandef(wdev, link_id); 5028 if (!chandef) { 5029 /* 5030 * This is probably broken, but we never maintained 5031 * a chandef in these cases, so it always was. 5032 */ 5033 return le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); 5034 } 5035 5036 switch (chandef->width) { 5037 case NL80211_CHAN_WIDTH_80P80: 5038 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; 5039 break; 5040 case NL80211_CHAN_WIDTH_160: 5041 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; 5042 break; 5043 default: 5044 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; 5045 break; 5046 } 5047 5048 return le16_to_cpu(tx_mcs); 5049 } 5050 5051 static bool he_set_mcs_mask(struct genl_info *info, 5052 struct wireless_dev *wdev, 5053 struct ieee80211_supported_band *sband, 5054 struct nl80211_txrate_he *txrate, 5055 u16 mcs[NL80211_HE_NSS_MAX], 5056 unsigned int link_id) 5057 { 5058 const struct ieee80211_sta_he_cap *he_cap; 5059 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; 5060 u16 tx_mcs_map = 0; 5061 u8 i; 5062 5063 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 5064 if (!he_cap) 5065 return false; 5066 5067 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); 5068 5069 tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); 5070 5071 /* Build he_mcs_mask from HE capabilities */ 5072 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 5073 5074 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 5075 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 5076 mcs[i] = txrate->mcs[i]; 5077 else 5078 return false; 5079 } 5080 5081 return true; 5082 } 5083 5084 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, 5085 struct nlattr *attrs[], 5086 enum nl80211_attrs attr, 5087 struct cfg80211_bitrate_mask *mask, 5088 struct net_device *dev, 5089 bool default_all_enabled, 5090 unsigned int link_id) 5091 { 5092 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 5093 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5094 struct wireless_dev *wdev = dev->ieee80211_ptr; 5095 int rem, i; 5096 struct nlattr *tx_rates; 5097 struct ieee80211_supported_band *sband; 5098 u16 vht_tx_mcs_map, he_tx_mcs_map; 5099 5100 memset(mask, 0, sizeof(*mask)); 5101 /* Default to all rates enabled */ 5102 for (i = 0; i < NUM_NL80211_BANDS; i++) { 5103 const struct ieee80211_sta_he_cap *he_cap; 5104 5105 if (!default_all_enabled) 5106 break; 5107 5108 sband = rdev->wiphy.bands[i]; 5109 5110 if (!sband) 5111 continue; 5112 5113 mask->control[i].legacy = (1 << sband->n_bitrates) - 1; 5114 memcpy(mask->control[i].ht_mcs, 5115 sband->ht_cap.mcs.rx_mask, 5116 sizeof(mask->control[i].ht_mcs)); 5117 5118 if (sband->vht_cap.vht_supported) { 5119 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 5120 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); 5121 } 5122 5123 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 5124 if (!he_cap) 5125 continue; 5126 5127 he_tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); 5128 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); 5129 5130 mask->control[i].he_gi = 0xFF; 5131 mask->control[i].he_ltf = 0xFF; 5132 } 5133 5134 /* if no rates are given set it back to the defaults */ 5135 if (!attrs[attr]) 5136 goto out; 5137 5138 /* The nested attribute uses enum nl80211_band as the index. This maps 5139 * directly to the enum nl80211_band values used in cfg80211. 5140 */ 5141 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); 5142 nla_for_each_nested(tx_rates, attrs[attr], rem) { 5143 enum nl80211_band band = nla_type(tx_rates); 5144 int err; 5145 5146 if (band < 0 || band >= NUM_NL80211_BANDS) 5147 return -EINVAL; 5148 sband = rdev->wiphy.bands[band]; 5149 if (sband == NULL) 5150 return -EINVAL; 5151 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, 5152 tx_rates, 5153 nl80211_txattr_policy, 5154 info->extack); 5155 if (err) 5156 return err; 5157 if (tb[NL80211_TXRATE_LEGACY]) { 5158 mask->control[band].legacy = rateset_to_mask( 5159 sband, 5160 nla_data(tb[NL80211_TXRATE_LEGACY]), 5161 nla_len(tb[NL80211_TXRATE_LEGACY])); 5162 if ((mask->control[band].legacy == 0) && 5163 nla_len(tb[NL80211_TXRATE_LEGACY])) 5164 return -EINVAL; 5165 } 5166 if (tb[NL80211_TXRATE_HT]) { 5167 if (!ht_rateset_to_mask( 5168 sband, 5169 nla_data(tb[NL80211_TXRATE_HT]), 5170 nla_len(tb[NL80211_TXRATE_HT]), 5171 mask->control[band].ht_mcs)) 5172 return -EINVAL; 5173 } 5174 5175 if (tb[NL80211_TXRATE_VHT]) { 5176 if (!vht_set_mcs_mask( 5177 sband, 5178 nla_data(tb[NL80211_TXRATE_VHT]), 5179 mask->control[band].vht_mcs)) 5180 return -EINVAL; 5181 } 5182 5183 if (tb[NL80211_TXRATE_GI]) { 5184 mask->control[band].gi = 5185 nla_get_u8(tb[NL80211_TXRATE_GI]); 5186 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) 5187 return -EINVAL; 5188 } 5189 if (tb[NL80211_TXRATE_HE] && 5190 !he_set_mcs_mask(info, wdev, sband, 5191 nla_data(tb[NL80211_TXRATE_HE]), 5192 mask->control[band].he_mcs, 5193 link_id)) 5194 return -EINVAL; 5195 5196 if (tb[NL80211_TXRATE_HE_GI]) 5197 mask->control[band].he_gi = 5198 nla_get_u8(tb[NL80211_TXRATE_HE_GI]); 5199 if (tb[NL80211_TXRATE_HE_LTF]) 5200 mask->control[band].he_ltf = 5201 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); 5202 5203 if (mask->control[band].legacy == 0) { 5204 /* don't allow empty legacy rates if HT, VHT or HE 5205 * are not even supported. 5206 */ 5207 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || 5208 rdev->wiphy.bands[band]->vht_cap.vht_supported || 5209 ieee80211_get_he_iftype_cap(sband, wdev->iftype))) 5210 return -EINVAL; 5211 5212 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) 5213 if (mask->control[band].ht_mcs[i]) 5214 goto out; 5215 5216 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) 5217 if (mask->control[band].vht_mcs[i]) 5218 goto out; 5219 5220 for (i = 0; i < NL80211_HE_NSS_MAX; i++) 5221 if (mask->control[band].he_mcs[i]) 5222 goto out; 5223 5224 /* legacy and mcs rates may not be both empty */ 5225 return -EINVAL; 5226 } 5227 } 5228 5229 out: 5230 return 0; 5231 } 5232 5233 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, 5234 enum nl80211_band band, 5235 struct cfg80211_bitrate_mask *beacon_rate) 5236 { 5237 u32 count_ht, count_vht, count_he, i; 5238 u32 rate = beacon_rate->control[band].legacy; 5239 5240 /* Allow only one rate */ 5241 if (hweight32(rate) > 1) 5242 return -EINVAL; 5243 5244 count_ht = 0; 5245 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 5246 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { 5247 return -EINVAL; 5248 } else if (beacon_rate->control[band].ht_mcs[i]) { 5249 count_ht++; 5250 if (count_ht > 1) 5251 return -EINVAL; 5252 } 5253 if (count_ht && rate) 5254 return -EINVAL; 5255 } 5256 5257 count_vht = 0; 5258 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 5259 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { 5260 return -EINVAL; 5261 } else if (beacon_rate->control[band].vht_mcs[i]) { 5262 count_vht++; 5263 if (count_vht > 1) 5264 return -EINVAL; 5265 } 5266 if (count_vht && rate) 5267 return -EINVAL; 5268 } 5269 5270 count_he = 0; 5271 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 5272 if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) { 5273 return -EINVAL; 5274 } else if (beacon_rate->control[band].he_mcs[i]) { 5275 count_he++; 5276 if (count_he > 1) 5277 return -EINVAL; 5278 } 5279 if (count_he && rate) 5280 return -EINVAL; 5281 } 5282 5283 if ((count_ht && count_vht && count_he) || 5284 (!rate && !count_ht && !count_vht && !count_he)) 5285 return -EINVAL; 5286 5287 if (rate && 5288 !wiphy_ext_feature_isset(&rdev->wiphy, 5289 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 5290 return -EINVAL; 5291 if (count_ht && 5292 !wiphy_ext_feature_isset(&rdev->wiphy, 5293 NL80211_EXT_FEATURE_BEACON_RATE_HT)) 5294 return -EINVAL; 5295 if (count_vht && 5296 !wiphy_ext_feature_isset(&rdev->wiphy, 5297 NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 5298 return -EINVAL; 5299 if (count_he && 5300 !wiphy_ext_feature_isset(&rdev->wiphy, 5301 NL80211_EXT_FEATURE_BEACON_RATE_HE)) 5302 return -EINVAL; 5303 5304 return 0; 5305 } 5306 5307 static int nl80211_parse_mbssid_config(struct wiphy *wiphy, 5308 struct net_device *dev, 5309 struct nlattr *attrs, 5310 struct cfg80211_mbssid_config *config, 5311 u8 num_elems) 5312 { 5313 struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1]; 5314 5315 if (!wiphy->mbssid_max_interfaces) 5316 return -EOPNOTSUPP; 5317 5318 if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL, 5319 NULL) || 5320 !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]) 5321 return -EINVAL; 5322 5323 config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]); 5324 if (config->ema) { 5325 if (!wiphy->ema_max_profile_periodicity) 5326 return -EOPNOTSUPP; 5327 5328 if (num_elems > wiphy->ema_max_profile_periodicity) 5329 return -EINVAL; 5330 } 5331 5332 config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]); 5333 if (config->index >= wiphy->mbssid_max_interfaces || 5334 (!config->index && !num_elems)) 5335 return -EINVAL; 5336 5337 if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) { 5338 u32 tx_ifindex = 5339 nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]); 5340 5341 if ((!config->index && tx_ifindex != dev->ifindex) || 5342 (config->index && tx_ifindex == dev->ifindex)) 5343 return -EINVAL; 5344 5345 if (tx_ifindex != dev->ifindex) { 5346 struct net_device *tx_netdev = 5347 dev_get_by_index(wiphy_net(wiphy), tx_ifindex); 5348 5349 if (!tx_netdev || !tx_netdev->ieee80211_ptr || 5350 tx_netdev->ieee80211_ptr->wiphy != wiphy || 5351 tx_netdev->ieee80211_ptr->iftype != 5352 NL80211_IFTYPE_AP) { 5353 dev_put(tx_netdev); 5354 return -EINVAL; 5355 } 5356 5357 config->tx_wdev = tx_netdev->ieee80211_ptr; 5358 } else { 5359 config->tx_wdev = dev->ieee80211_ptr; 5360 } 5361 } else if (!config->index) { 5362 config->tx_wdev = dev->ieee80211_ptr; 5363 } else { 5364 return -EINVAL; 5365 } 5366 5367 return 0; 5368 } 5369 5370 static struct cfg80211_mbssid_elems * 5371 nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs) 5372 { 5373 struct nlattr *nl_elems; 5374 struct cfg80211_mbssid_elems *elems; 5375 int rem_elems; 5376 u8 i = 0, num_elems = 0; 5377 5378 if (!wiphy->mbssid_max_interfaces) 5379 return ERR_PTR(-EINVAL); 5380 5381 nla_for_each_nested(nl_elems, attrs, rem_elems) 5382 num_elems++; 5383 5384 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); 5385 if (!elems) 5386 return ERR_PTR(-ENOMEM); 5387 5388 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5389 elems->elem[i].data = nla_data(nl_elems); 5390 elems->elem[i].len = nla_len(nl_elems); 5391 i++; 5392 } 5393 elems->cnt = num_elems; 5394 return elems; 5395 } 5396 5397 static int nl80211_parse_he_bss_color(struct nlattr *attrs, 5398 struct cfg80211_he_bss_color *he_bss_color) 5399 { 5400 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; 5401 int err; 5402 5403 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, 5404 he_bss_color_policy, NULL); 5405 if (err) 5406 return err; 5407 5408 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) 5409 return -EINVAL; 5410 5411 he_bss_color->color = 5412 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); 5413 he_bss_color->enabled = 5414 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); 5415 he_bss_color->partial = 5416 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); 5417 5418 return 0; 5419 } 5420 5421 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, 5422 struct nlattr *attrs[], 5423 struct cfg80211_beacon_data *bcn) 5424 { 5425 bool haveinfo = false; 5426 int err; 5427 5428 memset(bcn, 0, sizeof(*bcn)); 5429 5430 bcn->link_id = nl80211_link_id(attrs); 5431 5432 if (attrs[NL80211_ATTR_BEACON_HEAD]) { 5433 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); 5434 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); 5435 if (!bcn->head_len) 5436 return -EINVAL; 5437 haveinfo = true; 5438 } 5439 5440 if (attrs[NL80211_ATTR_BEACON_TAIL]) { 5441 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); 5442 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); 5443 haveinfo = true; 5444 } 5445 5446 if (!haveinfo) 5447 return -EINVAL; 5448 5449 if (attrs[NL80211_ATTR_IE]) { 5450 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); 5451 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); 5452 } 5453 5454 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { 5455 bcn->proberesp_ies = 5456 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); 5457 bcn->proberesp_ies_len = 5458 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); 5459 } 5460 5461 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { 5462 bcn->assocresp_ies = 5463 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5464 bcn->assocresp_ies_len = 5465 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5466 } 5467 5468 if (attrs[NL80211_ATTR_PROBE_RESP]) { 5469 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); 5470 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); 5471 } 5472 5473 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 5474 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 5475 5476 err = nla_parse_nested_deprecated(tb, 5477 NL80211_FTM_RESP_ATTR_MAX, 5478 attrs[NL80211_ATTR_FTM_RESPONDER], 5479 NULL, NULL); 5480 if (err) 5481 return err; 5482 5483 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && 5484 wiphy_ext_feature_isset(&rdev->wiphy, 5485 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 5486 bcn->ftm_responder = 1; 5487 else 5488 return -EOPNOTSUPP; 5489 5490 if (tb[NL80211_FTM_RESP_ATTR_LCI]) { 5491 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); 5492 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); 5493 } 5494 5495 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { 5496 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5497 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5498 } 5499 } else { 5500 bcn->ftm_responder = -1; 5501 } 5502 5503 if (attrs[NL80211_ATTR_HE_BSS_COLOR]) { 5504 err = nl80211_parse_he_bss_color(attrs[NL80211_ATTR_HE_BSS_COLOR], 5505 &bcn->he_bss_color); 5506 if (err) 5507 return err; 5508 bcn->he_bss_color_valid = true; 5509 } 5510 5511 if (attrs[NL80211_ATTR_MBSSID_ELEMS]) { 5512 struct cfg80211_mbssid_elems *mbssid = 5513 nl80211_parse_mbssid_elems(&rdev->wiphy, 5514 attrs[NL80211_ATTR_MBSSID_ELEMS]); 5515 5516 if (IS_ERR(mbssid)) 5517 return PTR_ERR(mbssid); 5518 5519 bcn->mbssid_ies = mbssid; 5520 } 5521 5522 return 0; 5523 } 5524 5525 static int nl80211_parse_he_obss_pd(struct nlattr *attrs, 5526 struct ieee80211_he_obss_pd *he_obss_pd) 5527 { 5528 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; 5529 int err; 5530 5531 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, 5532 he_obss_pd_policy, NULL); 5533 if (err) 5534 return err; 5535 5536 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) 5537 return -EINVAL; 5538 5539 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); 5540 5541 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) 5542 he_obss_pd->min_offset = 5543 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); 5544 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) 5545 he_obss_pd->max_offset = 5546 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); 5547 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) 5548 he_obss_pd->non_srg_max_offset = 5549 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); 5550 5551 if (he_obss_pd->min_offset > he_obss_pd->max_offset) 5552 return -EINVAL; 5553 5554 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) 5555 memcpy(he_obss_pd->bss_color_bitmap, 5556 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), 5557 sizeof(he_obss_pd->bss_color_bitmap)); 5558 5559 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) 5560 memcpy(he_obss_pd->partial_bssid_bitmap, 5561 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), 5562 sizeof(he_obss_pd->partial_bssid_bitmap)); 5563 5564 he_obss_pd->enable = true; 5565 5566 return 0; 5567 } 5568 5569 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, 5570 struct nlattr *attrs, 5571 struct cfg80211_ap_settings *params) 5572 { 5573 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; 5574 int ret; 5575 struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; 5576 5577 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5578 NL80211_EXT_FEATURE_FILS_DISCOVERY)) 5579 return -EINVAL; 5580 5581 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, 5582 NULL, NULL); 5583 if (ret) 5584 return ret; 5585 5586 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || 5587 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || 5588 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) 5589 return -EINVAL; 5590 5591 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5592 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5593 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); 5594 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); 5595 5596 return 0; 5597 } 5598 5599 static int 5600 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, 5601 struct nlattr *attrs, 5602 struct cfg80211_ap_settings *params) 5603 { 5604 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; 5605 int ret; 5606 struct cfg80211_unsol_bcast_probe_resp *presp = 5607 ¶ms->unsol_bcast_probe_resp; 5608 5609 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5610 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) 5611 return -EINVAL; 5612 5613 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, 5614 attrs, NULL, NULL); 5615 if (ret) 5616 return ret; 5617 5618 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || 5619 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) 5620 return -EINVAL; 5621 5622 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5623 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5624 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); 5625 return 0; 5626 } 5627 5628 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, 5629 const struct element *rates) 5630 { 5631 int i; 5632 5633 if (!rates) 5634 return; 5635 5636 for (i = 0; i < rates->datalen; i++) { 5637 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 5638 params->ht_required = true; 5639 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) 5640 params->vht_required = true; 5641 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) 5642 params->he_required = true; 5643 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E) 5644 params->sae_h2e_required = true; 5645 } 5646 } 5647 5648 /* 5649 * Since the nl80211 API didn't include, from the beginning, attributes about 5650 * HT/VHT requirements/capabilities, we parse them out of the IEs for the 5651 * benefit of drivers that rebuild IEs in the firmware. 5652 */ 5653 static int nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) 5654 { 5655 const struct cfg80211_beacon_data *bcn = ¶ms->beacon; 5656 size_t ies_len = bcn->tail_len; 5657 const u8 *ies = bcn->tail; 5658 const struct element *rates; 5659 const struct element *cap; 5660 5661 rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len); 5662 nl80211_check_ap_rate_selectors(params, rates); 5663 5664 rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); 5665 nl80211_check_ap_rate_selectors(params, rates); 5666 5667 cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len); 5668 if (cap && cap->datalen >= sizeof(*params->ht_cap)) 5669 params->ht_cap = (void *)cap->data; 5670 cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len); 5671 if (cap && cap->datalen >= sizeof(*params->vht_cap)) 5672 params->vht_cap = (void *)cap->data; 5673 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); 5674 if (cap && cap->datalen >= sizeof(*params->he_cap) + 1) 5675 params->he_cap = (void *)(cap->data + 1); 5676 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); 5677 if (cap && cap->datalen >= sizeof(*params->he_oper) + 1) 5678 params->he_oper = (void *)(cap->data + 1); 5679 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_CAPABILITY, ies, ies_len); 5680 if (cap) { 5681 if (!cap->datalen) 5682 return -EINVAL; 5683 params->eht_cap = (void *)(cap->data + 1); 5684 if (!ieee80211_eht_capa_size_ok((const u8 *)params->he_cap, 5685 (const u8 *)params->eht_cap, 5686 cap->datalen - 1, true)) 5687 return -EINVAL; 5688 } 5689 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION, ies, ies_len); 5690 if (cap) { 5691 if (!cap->datalen) 5692 return -EINVAL; 5693 params->eht_oper = (void *)(cap->data + 1); 5694 if (!ieee80211_eht_oper_size_ok((const u8 *)params->eht_oper, 5695 cap->datalen - 1)) 5696 return -EINVAL; 5697 } 5698 return 0; 5699 } 5700 5701 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, 5702 struct cfg80211_ap_settings *params) 5703 { 5704 struct wireless_dev *wdev; 5705 5706 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 5707 if (wdev->iftype != NL80211_IFTYPE_AP && 5708 wdev->iftype != NL80211_IFTYPE_P2P_GO) 5709 continue; 5710 5711 if (!wdev->u.ap.preset_chandef.chan) 5712 continue; 5713 5714 params->chandef = wdev->u.ap.preset_chandef; 5715 return true; 5716 } 5717 5718 return false; 5719 } 5720 5721 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, 5722 enum nl80211_auth_type auth_type, 5723 enum nl80211_commands cmd) 5724 { 5725 if (auth_type > NL80211_AUTHTYPE_MAX) 5726 return false; 5727 5728 switch (cmd) { 5729 case NL80211_CMD_AUTHENTICATE: 5730 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5731 auth_type == NL80211_AUTHTYPE_SAE) 5732 return false; 5733 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5734 NL80211_EXT_FEATURE_FILS_STA) && 5735 (auth_type == NL80211_AUTHTYPE_FILS_SK || 5736 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5737 auth_type == NL80211_AUTHTYPE_FILS_PK)) 5738 return false; 5739 return true; 5740 case NL80211_CMD_CONNECT: 5741 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5742 !wiphy_ext_feature_isset(&rdev->wiphy, 5743 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 5744 auth_type == NL80211_AUTHTYPE_SAE) 5745 return false; 5746 5747 /* FILS with SK PFS or PK not supported yet */ 5748 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5749 auth_type == NL80211_AUTHTYPE_FILS_PK) 5750 return false; 5751 if (!wiphy_ext_feature_isset( 5752 &rdev->wiphy, 5753 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 5754 auth_type == NL80211_AUTHTYPE_FILS_SK) 5755 return false; 5756 return true; 5757 case NL80211_CMD_START_AP: 5758 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5759 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && 5760 auth_type == NL80211_AUTHTYPE_SAE) 5761 return false; 5762 /* FILS not supported yet */ 5763 if (auth_type == NL80211_AUTHTYPE_FILS_SK || 5764 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5765 auth_type == NL80211_AUTHTYPE_FILS_PK) 5766 return false; 5767 return true; 5768 default: 5769 return false; 5770 } 5771 } 5772 5773 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) 5774 { 5775 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5776 unsigned int link_id = nl80211_link_id(info->attrs); 5777 struct net_device *dev = info->user_ptr[1]; 5778 struct wireless_dev *wdev = dev->ieee80211_ptr; 5779 struct cfg80211_ap_settings *params; 5780 int err; 5781 5782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5783 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5784 return -EOPNOTSUPP; 5785 5786 if (!rdev->ops->start_ap) 5787 return -EOPNOTSUPP; 5788 5789 if (wdev->links[link_id].ap.beacon_interval) 5790 return -EALREADY; 5791 5792 /* these are required for START_AP */ 5793 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 5794 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 5795 !info->attrs[NL80211_ATTR_BEACON_HEAD]) 5796 return -EINVAL; 5797 5798 params = kzalloc(sizeof(*params), GFP_KERNEL); 5799 if (!params) 5800 return -ENOMEM; 5801 5802 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon); 5803 if (err) 5804 goto out; 5805 5806 params->beacon_interval = 5807 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 5808 params->dtim_period = 5809 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 5810 5811 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, 5812 params->beacon_interval); 5813 if (err) 5814 goto out; 5815 5816 /* 5817 * In theory, some of these attributes should be required here 5818 * but since they were not used when the command was originally 5819 * added, keep them optional for old user space programs to let 5820 * them continue to work with drivers that do not need the 5821 * additional information -- drivers must check! 5822 */ 5823 if (info->attrs[NL80211_ATTR_SSID]) { 5824 params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 5825 params->ssid_len = 5826 nla_len(info->attrs[NL80211_ATTR_SSID]); 5827 if (params->ssid_len == 0) { 5828 err = -EINVAL; 5829 goto out; 5830 } 5831 5832 if (wdev->u.ap.ssid_len && 5833 (wdev->u.ap.ssid_len != params->ssid_len || 5834 memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) { 5835 /* require identical SSID for MLO */ 5836 err = -EINVAL; 5837 goto out; 5838 } 5839 } else if (wdev->valid_links) { 5840 /* require SSID for MLO */ 5841 err = -EINVAL; 5842 goto out; 5843 } 5844 5845 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) 5846 params->hidden_ssid = nla_get_u32( 5847 info->attrs[NL80211_ATTR_HIDDEN_SSID]); 5848 5849 params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 5850 5851 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 5852 params->auth_type = nla_get_u32( 5853 info->attrs[NL80211_ATTR_AUTH_TYPE]); 5854 if (!nl80211_valid_auth_type(rdev, params->auth_type, 5855 NL80211_CMD_START_AP)) { 5856 err = -EINVAL; 5857 goto out; 5858 } 5859 } else 5860 params->auth_type = NL80211_AUTHTYPE_AUTOMATIC; 5861 5862 err = nl80211_crypto_settings(rdev, info, ¶ms->crypto, 5863 NL80211_MAX_NR_CIPHER_SUITES); 5864 if (err) 5865 goto out; 5866 5867 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { 5868 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) { 5869 err = -EOPNOTSUPP; 5870 goto out; 5871 } 5872 params->inactivity_timeout = nla_get_u16( 5873 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 5874 } 5875 5876 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 5877 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 5878 err = -EINVAL; 5879 goto out; 5880 } 5881 params->p2p_ctwindow = 5882 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 5883 if (params->p2p_ctwindow != 0 && 5884 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) { 5885 err = -EINVAL; 5886 goto out; 5887 } 5888 } 5889 5890 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 5891 u8 tmp; 5892 5893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 5894 err = -EINVAL; 5895 goto out; 5896 } 5897 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 5898 params->p2p_opp_ps = tmp; 5899 if (params->p2p_opp_ps != 0 && 5900 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) { 5901 err = -EINVAL; 5902 goto out; 5903 } 5904 } 5905 5906 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 5907 err = nl80211_parse_chandef(rdev, info, ¶ms->chandef); 5908 if (err) 5909 goto out; 5910 } else if (wdev->valid_links) { 5911 /* with MLD need to specify the channel configuration */ 5912 err = -EINVAL; 5913 goto out; 5914 } else if (wdev->u.ap.preset_chandef.chan) { 5915 params->chandef = wdev->u.ap.preset_chandef; 5916 } else if (!nl80211_get_ap_channel(rdev, params)) { 5917 err = -EINVAL; 5918 goto out; 5919 } 5920 5921 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef, 5922 wdev->iftype)) { 5923 err = -EINVAL; 5924 goto out; 5925 } 5926 5927 wdev_lock(wdev); 5928 5929 if (info->attrs[NL80211_ATTR_TX_RATES]) { 5930 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 5931 NL80211_ATTR_TX_RATES, 5932 ¶ms->beacon_rate, 5933 dev, false, link_id); 5934 if (err) 5935 goto out_unlock; 5936 5937 err = validate_beacon_tx_rate(rdev, params->chandef.chan->band, 5938 ¶ms->beacon_rate); 5939 if (err) 5940 goto out_unlock; 5941 } 5942 5943 if (info->attrs[NL80211_ATTR_SMPS_MODE]) { 5944 params->smps_mode = 5945 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); 5946 switch (params->smps_mode) { 5947 case NL80211_SMPS_OFF: 5948 break; 5949 case NL80211_SMPS_STATIC: 5950 if (!(rdev->wiphy.features & 5951 NL80211_FEATURE_STATIC_SMPS)) { 5952 err = -EINVAL; 5953 goto out_unlock; 5954 } 5955 break; 5956 case NL80211_SMPS_DYNAMIC: 5957 if (!(rdev->wiphy.features & 5958 NL80211_FEATURE_DYNAMIC_SMPS)) { 5959 err = -EINVAL; 5960 goto out_unlock; 5961 } 5962 break; 5963 default: 5964 err = -EINVAL; 5965 goto out_unlock; 5966 } 5967 } else { 5968 params->smps_mode = NL80211_SMPS_OFF; 5969 } 5970 5971 params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 5972 if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 5973 err = -EOPNOTSUPP; 5974 goto out_unlock; 5975 } 5976 5977 if (info->attrs[NL80211_ATTR_ACL_POLICY]) { 5978 params->acl = parse_acl_data(&rdev->wiphy, info); 5979 if (IS_ERR(params->acl)) { 5980 err = PTR_ERR(params->acl); 5981 params->acl = NULL; 5982 goto out_unlock; 5983 } 5984 } 5985 5986 params->twt_responder = 5987 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); 5988 5989 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { 5990 err = nl80211_parse_he_obss_pd( 5991 info->attrs[NL80211_ATTR_HE_OBSS_PD], 5992 ¶ms->he_obss_pd); 5993 if (err) 5994 goto out_unlock; 5995 } 5996 5997 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { 5998 err = nl80211_parse_fils_discovery(rdev, 5999 info->attrs[NL80211_ATTR_FILS_DISCOVERY], 6000 params); 6001 if (err) 6002 goto out_unlock; 6003 } 6004 6005 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { 6006 err = nl80211_parse_unsol_bcast_probe_resp( 6007 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], 6008 params); 6009 if (err) 6010 goto out_unlock; 6011 } 6012 6013 if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) { 6014 err = nl80211_parse_mbssid_config(&rdev->wiphy, dev, 6015 info->attrs[NL80211_ATTR_MBSSID_CONFIG], 6016 ¶ms->mbssid_config, 6017 params->beacon.mbssid_ies ? 6018 params->beacon.mbssid_ies->cnt : 6019 0); 6020 if (err) 6021 goto out_unlock; 6022 } 6023 6024 err = nl80211_calculate_ap_params(params); 6025 if (err) 6026 goto out_unlock; 6027 6028 if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]) 6029 params->flags = nla_get_u32( 6030 info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]); 6031 else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) 6032 params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; 6033 6034 if (wdev->conn_owner_nlportid && 6035 info->attrs[NL80211_ATTR_SOCKET_OWNER] && 6036 wdev->conn_owner_nlportid != info->snd_portid) { 6037 err = -EINVAL; 6038 goto out_unlock; 6039 } 6040 6041 /* FIXME: validate MLO/link-id against driver capabilities */ 6042 6043 err = rdev_start_ap(rdev, dev, params); 6044 if (!err) { 6045 wdev->links[link_id].ap.beacon_interval = params->beacon_interval; 6046 wdev->links[link_id].ap.chandef = params->chandef; 6047 wdev->u.ap.ssid_len = params->ssid_len; 6048 memcpy(wdev->u.ap.ssid, params->ssid, 6049 params->ssid_len); 6050 6051 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 6052 wdev->conn_owner_nlportid = info->snd_portid; 6053 } 6054 out_unlock: 6055 wdev_unlock(wdev); 6056 out: 6057 kfree(params->acl); 6058 kfree(params->beacon.mbssid_ies); 6059 if (params->mbssid_config.tx_wdev && 6060 params->mbssid_config.tx_wdev->netdev && 6061 params->mbssid_config.tx_wdev->netdev != dev) 6062 dev_put(params->mbssid_config.tx_wdev->netdev); 6063 kfree(params); 6064 6065 return err; 6066 } 6067 6068 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) 6069 { 6070 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6071 unsigned int link_id = nl80211_link_id(info->attrs); 6072 struct net_device *dev = info->user_ptr[1]; 6073 struct wireless_dev *wdev = dev->ieee80211_ptr; 6074 struct cfg80211_beacon_data params; 6075 int err; 6076 6077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6078 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6079 return -EOPNOTSUPP; 6080 6081 if (!rdev->ops->change_beacon) 6082 return -EOPNOTSUPP; 6083 6084 if (!wdev->links[link_id].ap.beacon_interval) 6085 return -EINVAL; 6086 6087 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); 6088 if (err) 6089 goto out; 6090 6091 wdev_lock(wdev); 6092 err = rdev_change_beacon(rdev, dev, ¶ms); 6093 wdev_unlock(wdev); 6094 6095 out: 6096 kfree(params.mbssid_ies); 6097 return err; 6098 } 6099 6100 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) 6101 { 6102 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6103 unsigned int link_id = nl80211_link_id(info->attrs); 6104 struct net_device *dev = info->user_ptr[1]; 6105 6106 return cfg80211_stop_ap(rdev, dev, link_id, false); 6107 } 6108 6109 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { 6110 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, 6111 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 6112 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 6113 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 6114 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, 6115 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, 6116 }; 6117 6118 static int parse_station_flags(struct genl_info *info, 6119 enum nl80211_iftype iftype, 6120 struct station_parameters *params) 6121 { 6122 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 6123 struct nlattr *nla; 6124 int flag; 6125 6126 /* 6127 * Try parsing the new attribute first so userspace 6128 * can specify both for older kernels. 6129 */ 6130 nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; 6131 if (nla) { 6132 struct nl80211_sta_flag_update *sta_flags; 6133 6134 sta_flags = nla_data(nla); 6135 params->sta_flags_mask = sta_flags->mask; 6136 params->sta_flags_set = sta_flags->set; 6137 params->sta_flags_set &= params->sta_flags_mask; 6138 if ((params->sta_flags_mask | 6139 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) 6140 return -EINVAL; 6141 return 0; 6142 } 6143 6144 /* if present, parse the old attribute */ 6145 6146 nla = info->attrs[NL80211_ATTR_STA_FLAGS]; 6147 if (!nla) 6148 return 0; 6149 6150 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) 6151 return -EINVAL; 6152 6153 /* 6154 * Only allow certain flags for interface types so that 6155 * other attributes are silently ignored. Remember that 6156 * this is backward compatibility code with old userspace 6157 * and shouldn't be hit in other cases anyway. 6158 */ 6159 switch (iftype) { 6160 case NL80211_IFTYPE_AP: 6161 case NL80211_IFTYPE_AP_VLAN: 6162 case NL80211_IFTYPE_P2P_GO: 6163 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 6164 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6165 BIT(NL80211_STA_FLAG_WME) | 6166 BIT(NL80211_STA_FLAG_MFP); 6167 break; 6168 case NL80211_IFTYPE_P2P_CLIENT: 6169 case NL80211_IFTYPE_STATION: 6170 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 6171 BIT(NL80211_STA_FLAG_TDLS_PEER); 6172 break; 6173 case NL80211_IFTYPE_MESH_POINT: 6174 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6175 BIT(NL80211_STA_FLAG_MFP) | 6176 BIT(NL80211_STA_FLAG_AUTHORIZED); 6177 break; 6178 default: 6179 return -EINVAL; 6180 } 6181 6182 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { 6183 if (flags[flag]) { 6184 params->sta_flags_set |= (1<<flag); 6185 6186 /* no longer support new API additions in old API */ 6187 if (flag > NL80211_STA_FLAG_MAX_OLD_API) 6188 return -EINVAL; 6189 } 6190 } 6191 6192 return 0; 6193 } 6194 6195 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) 6196 { 6197 struct nlattr *rate; 6198 u32 bitrate; 6199 u16 bitrate_compat; 6200 enum nl80211_rate_info rate_flg; 6201 6202 rate = nla_nest_start_noflag(msg, attr); 6203 if (!rate) 6204 return false; 6205 6206 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ 6207 bitrate = cfg80211_calculate_bitrate(info); 6208 /* report 16-bit bitrate only if we can */ 6209 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; 6210 if (bitrate > 0 && 6211 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) 6212 return false; 6213 if (bitrate_compat > 0 && 6214 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) 6215 return false; 6216 6217 switch (info->bw) { 6218 case RATE_INFO_BW_5: 6219 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; 6220 break; 6221 case RATE_INFO_BW_10: 6222 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; 6223 break; 6224 default: 6225 WARN_ON(1); 6226 fallthrough; 6227 case RATE_INFO_BW_20: 6228 rate_flg = 0; 6229 break; 6230 case RATE_INFO_BW_40: 6231 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; 6232 break; 6233 case RATE_INFO_BW_80: 6234 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; 6235 break; 6236 case RATE_INFO_BW_160: 6237 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; 6238 break; 6239 case RATE_INFO_BW_HE_RU: 6240 rate_flg = 0; 6241 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); 6242 break; 6243 case RATE_INFO_BW_320: 6244 rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH; 6245 break; 6246 case RATE_INFO_BW_EHT_RU: 6247 rate_flg = 0; 6248 WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS)); 6249 break; 6250 } 6251 6252 if (rate_flg && nla_put_flag(msg, rate_flg)) 6253 return false; 6254 6255 if (info->flags & RATE_INFO_FLAGS_MCS) { 6256 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) 6257 return false; 6258 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6259 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6260 return false; 6261 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { 6262 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) 6263 return false; 6264 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) 6265 return false; 6266 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6267 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6268 return false; 6269 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { 6270 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) 6271 return false; 6272 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) 6273 return false; 6274 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) 6275 return false; 6276 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) 6277 return false; 6278 if (info->bw == RATE_INFO_BW_HE_RU && 6279 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, 6280 info->he_ru_alloc)) 6281 return false; 6282 } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) { 6283 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs)) 6284 return false; 6285 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss)) 6286 return false; 6287 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi)) 6288 return false; 6289 if (info->bw == RATE_INFO_BW_EHT_RU && 6290 nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC, 6291 info->eht_ru_alloc)) 6292 return false; 6293 } 6294 6295 nla_nest_end(msg, rate); 6296 return true; 6297 } 6298 6299 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, 6300 int id) 6301 { 6302 void *attr; 6303 int i = 0; 6304 6305 if (!mask) 6306 return true; 6307 6308 attr = nla_nest_start_noflag(msg, id); 6309 if (!attr) 6310 return false; 6311 6312 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 6313 if (!(mask & BIT(i))) 6314 continue; 6315 6316 if (nla_put_u8(msg, i, signal[i])) 6317 return false; 6318 } 6319 6320 nla_nest_end(msg, attr); 6321 6322 return true; 6323 } 6324 6325 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, 6326 u32 seq, int flags, 6327 struct cfg80211_registered_device *rdev, 6328 struct net_device *dev, 6329 const u8 *mac_addr, struct station_info *sinfo) 6330 { 6331 void *hdr; 6332 struct nlattr *sinfoattr, *bss_param; 6333 6334 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 6335 if (!hdr) { 6336 cfg80211_sinfo_release_content(sinfo); 6337 return -1; 6338 } 6339 6340 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6341 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 6342 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 6343 goto nla_put_failure; 6344 6345 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); 6346 if (!sinfoattr) 6347 goto nla_put_failure; 6348 6349 #define PUT_SINFO(attr, memb, type) do { \ 6350 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ 6351 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 6352 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ 6353 sinfo->memb)) \ 6354 goto nla_put_failure; \ 6355 } while (0) 6356 #define PUT_SINFO_U64(attr, memb) do { \ 6357 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 6358 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ 6359 sinfo->memb, NL80211_STA_INFO_PAD)) \ 6360 goto nla_put_failure; \ 6361 } while (0) 6362 6363 PUT_SINFO(CONNECTED_TIME, connected_time, u32); 6364 PUT_SINFO(INACTIVE_TIME, inactive_time, u32); 6365 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); 6366 6367 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | 6368 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && 6369 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, 6370 (u32)sinfo->rx_bytes)) 6371 goto nla_put_failure; 6372 6373 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 6374 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && 6375 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, 6376 (u32)sinfo->tx_bytes)) 6377 goto nla_put_failure; 6378 6379 PUT_SINFO_U64(RX_BYTES64, rx_bytes); 6380 PUT_SINFO_U64(TX_BYTES64, tx_bytes); 6381 PUT_SINFO(LLID, llid, u16); 6382 PUT_SINFO(PLID, plid, u16); 6383 PUT_SINFO(PLINK_STATE, plink_state, u8); 6384 PUT_SINFO_U64(RX_DURATION, rx_duration); 6385 PUT_SINFO_U64(TX_DURATION, tx_duration); 6386 6387 if (wiphy_ext_feature_isset(&rdev->wiphy, 6388 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6389 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); 6390 6391 switch (rdev->wiphy.signal_type) { 6392 case CFG80211_SIGNAL_TYPE_MBM: 6393 PUT_SINFO(SIGNAL, signal, u8); 6394 PUT_SINFO(SIGNAL_AVG, signal_avg, u8); 6395 break; 6396 default: 6397 break; 6398 } 6399 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { 6400 if (!nl80211_put_signal(msg, sinfo->chains, 6401 sinfo->chain_signal, 6402 NL80211_STA_INFO_CHAIN_SIGNAL)) 6403 goto nla_put_failure; 6404 } 6405 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { 6406 if (!nl80211_put_signal(msg, sinfo->chains, 6407 sinfo->chain_signal_avg, 6408 NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) 6409 goto nla_put_failure; 6410 } 6411 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { 6412 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 6413 NL80211_STA_INFO_TX_BITRATE)) 6414 goto nla_put_failure; 6415 } 6416 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { 6417 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, 6418 NL80211_STA_INFO_RX_BITRATE)) 6419 goto nla_put_failure; 6420 } 6421 6422 PUT_SINFO(RX_PACKETS, rx_packets, u32); 6423 PUT_SINFO(TX_PACKETS, tx_packets, u32); 6424 PUT_SINFO(TX_RETRIES, tx_retries, u32); 6425 PUT_SINFO(TX_FAILED, tx_failed, u32); 6426 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 6427 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); 6428 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 6429 PUT_SINFO(LOCAL_PM, local_pm, u32); 6430 PUT_SINFO(PEER_PM, peer_pm, u32); 6431 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); 6432 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 6433 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); 6434 6435 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 6436 bss_param = nla_nest_start_noflag(msg, 6437 NL80211_STA_INFO_BSS_PARAM); 6438 if (!bss_param) 6439 goto nla_put_failure; 6440 6441 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && 6442 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || 6443 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && 6444 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || 6445 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && 6446 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || 6447 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, 6448 sinfo->bss_param.dtim_period) || 6449 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, 6450 sinfo->bss_param.beacon_interval)) 6451 goto nla_put_failure; 6452 6453 nla_nest_end(msg, bss_param); 6454 } 6455 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && 6456 nla_put(msg, NL80211_STA_INFO_STA_FLAGS, 6457 sizeof(struct nl80211_sta_flag_update), 6458 &sinfo->sta_flags)) 6459 goto nla_put_failure; 6460 6461 PUT_SINFO_U64(T_OFFSET, t_offset); 6462 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); 6463 PUT_SINFO_U64(BEACON_RX, rx_beacon); 6464 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); 6465 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); 6466 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); 6467 if (wiphy_ext_feature_isset(&rdev->wiphy, 6468 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { 6469 PUT_SINFO(ACK_SIGNAL, ack_signal, u8); 6470 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); 6471 } 6472 6473 #undef PUT_SINFO 6474 #undef PUT_SINFO_U64 6475 6476 if (sinfo->pertid) { 6477 struct nlattr *tidsattr; 6478 int tid; 6479 6480 tidsattr = nla_nest_start_noflag(msg, 6481 NL80211_STA_INFO_TID_STATS); 6482 if (!tidsattr) 6483 goto nla_put_failure; 6484 6485 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { 6486 struct cfg80211_tid_stats *tidstats; 6487 struct nlattr *tidattr; 6488 6489 tidstats = &sinfo->pertid[tid]; 6490 6491 if (!tidstats->filled) 6492 continue; 6493 6494 tidattr = nla_nest_start_noflag(msg, tid + 1); 6495 if (!tidattr) 6496 goto nla_put_failure; 6497 6498 #define PUT_TIDVAL_U64(attr, memb) do { \ 6499 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ 6500 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ 6501 tidstats->memb, NL80211_TID_STATS_PAD)) \ 6502 goto nla_put_failure; \ 6503 } while (0) 6504 6505 PUT_TIDVAL_U64(RX_MSDU, rx_msdu); 6506 PUT_TIDVAL_U64(TX_MSDU, tx_msdu); 6507 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); 6508 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); 6509 6510 #undef PUT_TIDVAL_U64 6511 if ((tidstats->filled & 6512 BIT(NL80211_TID_STATS_TXQ_STATS)) && 6513 !nl80211_put_txq_stats(msg, &tidstats->txq_stats, 6514 NL80211_TID_STATS_TXQ_STATS)) 6515 goto nla_put_failure; 6516 6517 nla_nest_end(msg, tidattr); 6518 } 6519 6520 nla_nest_end(msg, tidsattr); 6521 } 6522 6523 nla_nest_end(msg, sinfoattr); 6524 6525 if (sinfo->assoc_req_ies_len && 6526 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, 6527 sinfo->assoc_req_ies)) 6528 goto nla_put_failure; 6529 6530 cfg80211_sinfo_release_content(sinfo); 6531 genlmsg_end(msg, hdr); 6532 return 0; 6533 6534 nla_put_failure: 6535 cfg80211_sinfo_release_content(sinfo); 6536 genlmsg_cancel(msg, hdr); 6537 return -EMSGSIZE; 6538 } 6539 6540 static int nl80211_dump_station(struct sk_buff *skb, 6541 struct netlink_callback *cb) 6542 { 6543 struct station_info sinfo; 6544 struct cfg80211_registered_device *rdev; 6545 struct wireless_dev *wdev; 6546 u8 mac_addr[ETH_ALEN]; 6547 int sta_idx = cb->args[2]; 6548 int err; 6549 6550 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 6551 if (err) 6552 return err; 6553 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 6554 __acquire(&rdev->wiphy.mtx); 6555 6556 if (!wdev->netdev) { 6557 err = -EINVAL; 6558 goto out_err; 6559 } 6560 6561 if (!rdev->ops->dump_station) { 6562 err = -EOPNOTSUPP; 6563 goto out_err; 6564 } 6565 6566 while (1) { 6567 memset(&sinfo, 0, sizeof(sinfo)); 6568 err = rdev_dump_station(rdev, wdev->netdev, sta_idx, 6569 mac_addr, &sinfo); 6570 if (err == -ENOENT) 6571 break; 6572 if (err) 6573 goto out_err; 6574 6575 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, 6576 NETLINK_CB(cb->skb).portid, 6577 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6578 rdev, wdev->netdev, mac_addr, 6579 &sinfo) < 0) 6580 goto out; 6581 6582 sta_idx++; 6583 } 6584 6585 out: 6586 cb->args[2] = sta_idx; 6587 err = skb->len; 6588 out_err: 6589 wiphy_unlock(&rdev->wiphy); 6590 6591 return err; 6592 } 6593 6594 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 6595 { 6596 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6597 struct net_device *dev = info->user_ptr[1]; 6598 struct station_info sinfo; 6599 struct sk_buff *msg; 6600 u8 *mac_addr = NULL; 6601 int err; 6602 6603 memset(&sinfo, 0, sizeof(sinfo)); 6604 6605 if (!info->attrs[NL80211_ATTR_MAC]) 6606 return -EINVAL; 6607 6608 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6609 6610 if (!rdev->ops->get_station) 6611 return -EOPNOTSUPP; 6612 6613 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 6614 if (err) 6615 return err; 6616 6617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6618 if (!msg) { 6619 cfg80211_sinfo_release_content(&sinfo); 6620 return -ENOMEM; 6621 } 6622 6623 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 6624 info->snd_portid, info->snd_seq, 0, 6625 rdev, dev, mac_addr, &sinfo) < 0) { 6626 nlmsg_free(msg); 6627 return -ENOBUFS; 6628 } 6629 6630 return genlmsg_reply(msg, info); 6631 } 6632 6633 int cfg80211_check_station_change(struct wiphy *wiphy, 6634 struct station_parameters *params, 6635 enum cfg80211_station_type statype) 6636 { 6637 if (params->listen_interval != -1 && 6638 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6639 return -EINVAL; 6640 6641 if (params->support_p2p_ps != -1 && 6642 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6643 return -EINVAL; 6644 6645 if (params->aid && 6646 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && 6647 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6648 return -EINVAL; 6649 6650 /* When you run into this, adjust the code below for the new flag */ 6651 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 6652 6653 switch (statype) { 6654 case CFG80211_STA_MESH_PEER_KERNEL: 6655 case CFG80211_STA_MESH_PEER_USER: 6656 /* 6657 * No ignoring the TDLS flag here -- the userspace mesh 6658 * code doesn't have the bug of including TDLS in the 6659 * mask everywhere. 6660 */ 6661 if (params->sta_flags_mask & 6662 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6663 BIT(NL80211_STA_FLAG_MFP) | 6664 BIT(NL80211_STA_FLAG_AUTHORIZED))) 6665 return -EINVAL; 6666 break; 6667 case CFG80211_STA_TDLS_PEER_SETUP: 6668 case CFG80211_STA_TDLS_PEER_ACTIVE: 6669 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 6670 return -EINVAL; 6671 /* ignore since it can't change */ 6672 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6673 break; 6674 default: 6675 /* disallow mesh-specific things */ 6676 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) 6677 return -EINVAL; 6678 if (params->local_pm) 6679 return -EINVAL; 6680 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6681 return -EINVAL; 6682 } 6683 6684 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6685 statype != CFG80211_STA_TDLS_PEER_ACTIVE) { 6686 /* TDLS can't be set, ... */ 6687 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 6688 return -EINVAL; 6689 /* 6690 * ... but don't bother the driver with it. This works around 6691 * a hostapd/wpa_supplicant issue -- it always includes the 6692 * TLDS_PEER flag in the mask even for AP mode. 6693 */ 6694 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6695 } 6696 6697 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6698 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6699 /* reject other things that can't change */ 6700 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) 6701 return -EINVAL; 6702 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) 6703 return -EINVAL; 6704 if (params->link_sta_params.supported_rates) 6705 return -EINVAL; 6706 if (params->ext_capab || params->link_sta_params.ht_capa || 6707 params->link_sta_params.vht_capa || 6708 params->link_sta_params.he_capa || 6709 params->link_sta_params.eht_capa) 6710 return -EINVAL; 6711 } 6712 6713 if (statype != CFG80211_STA_AP_CLIENT && 6714 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6715 if (params->vlan) 6716 return -EINVAL; 6717 } 6718 6719 switch (statype) { 6720 case CFG80211_STA_AP_MLME_CLIENT: 6721 /* Use this only for authorizing/unauthorizing a station */ 6722 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 6723 return -EOPNOTSUPP; 6724 break; 6725 case CFG80211_STA_AP_CLIENT: 6726 case CFG80211_STA_AP_CLIENT_UNASSOC: 6727 /* accept only the listed bits */ 6728 if (params->sta_flags_mask & 6729 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6730 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6731 BIT(NL80211_STA_FLAG_ASSOCIATED) | 6732 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6733 BIT(NL80211_STA_FLAG_WME) | 6734 BIT(NL80211_STA_FLAG_MFP))) 6735 return -EINVAL; 6736 6737 /* but authenticated/associated only if driver handles it */ 6738 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 6739 params->sta_flags_mask & 6740 (BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6741 BIT(NL80211_STA_FLAG_ASSOCIATED))) 6742 return -EINVAL; 6743 break; 6744 case CFG80211_STA_IBSS: 6745 case CFG80211_STA_AP_STA: 6746 /* reject any changes other than AUTHORIZED */ 6747 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 6748 return -EINVAL; 6749 break; 6750 case CFG80211_STA_TDLS_PEER_SETUP: 6751 /* reject any changes other than AUTHORIZED or WME */ 6752 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6753 BIT(NL80211_STA_FLAG_WME))) 6754 return -EINVAL; 6755 /* force (at least) rates when authorizing */ 6756 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && 6757 !params->link_sta_params.supported_rates) 6758 return -EINVAL; 6759 break; 6760 case CFG80211_STA_TDLS_PEER_ACTIVE: 6761 /* reject any changes */ 6762 return -EINVAL; 6763 case CFG80211_STA_MESH_PEER_KERNEL: 6764 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6765 return -EINVAL; 6766 break; 6767 case CFG80211_STA_MESH_PEER_USER: 6768 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && 6769 params->plink_action != NL80211_PLINK_ACTION_BLOCK) 6770 return -EINVAL; 6771 break; 6772 } 6773 6774 /* 6775 * Older kernel versions ignored this attribute entirely, so don't 6776 * reject attempts to update it but mark it as unused instead so the 6777 * driver won't look at the data. 6778 */ 6779 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && 6780 statype != CFG80211_STA_TDLS_PEER_SETUP) 6781 params->link_sta_params.opmode_notif_used = false; 6782 6783 return 0; 6784 } 6785 EXPORT_SYMBOL(cfg80211_check_station_change); 6786 6787 /* 6788 * Get vlan interface making sure it is running and on the right wiphy. 6789 */ 6790 static struct net_device *get_vlan(struct genl_info *info, 6791 struct cfg80211_registered_device *rdev) 6792 { 6793 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; 6794 struct net_device *v; 6795 int ret; 6796 6797 if (!vlanattr) 6798 return NULL; 6799 6800 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); 6801 if (!v) 6802 return ERR_PTR(-ENODEV); 6803 6804 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { 6805 ret = -EINVAL; 6806 goto error; 6807 } 6808 6809 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 6810 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6811 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 6812 ret = -EINVAL; 6813 goto error; 6814 } 6815 6816 if (!netif_running(v)) { 6817 ret = -ENETDOWN; 6818 goto error; 6819 } 6820 6821 return v; 6822 error: 6823 dev_put(v); 6824 return ERR_PTR(ret); 6825 } 6826 6827 static int nl80211_parse_sta_wme(struct genl_info *info, 6828 struct station_parameters *params) 6829 { 6830 struct nlattr *tb[NL80211_STA_WME_MAX + 1]; 6831 struct nlattr *nla; 6832 int err; 6833 6834 /* parse WME attributes if present */ 6835 if (!info->attrs[NL80211_ATTR_STA_WME]) 6836 return 0; 6837 6838 nla = info->attrs[NL80211_ATTR_STA_WME]; 6839 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, 6840 nl80211_sta_wme_policy, 6841 info->extack); 6842 if (err) 6843 return err; 6844 6845 if (tb[NL80211_STA_WME_UAPSD_QUEUES]) 6846 params->uapsd_queues = nla_get_u8( 6847 tb[NL80211_STA_WME_UAPSD_QUEUES]); 6848 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) 6849 return -EINVAL; 6850 6851 if (tb[NL80211_STA_WME_MAX_SP]) 6852 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); 6853 6854 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) 6855 return -EINVAL; 6856 6857 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; 6858 6859 return 0; 6860 } 6861 6862 static int nl80211_parse_sta_channel_info(struct genl_info *info, 6863 struct station_parameters *params) 6864 { 6865 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { 6866 params->supported_channels = 6867 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 6868 params->supported_channels_len = 6869 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 6870 /* 6871 * Need to include at least one (first channel, number of 6872 * channels) tuple for each subband (checked in policy), 6873 * and must have proper tuples for the rest of the data as well. 6874 */ 6875 if (params->supported_channels_len % 2) 6876 return -EINVAL; 6877 } 6878 6879 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { 6880 params->supported_oper_classes = 6881 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 6882 params->supported_oper_classes_len = 6883 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 6884 } 6885 return 0; 6886 } 6887 6888 static int nl80211_set_station_tdls(struct genl_info *info, 6889 struct station_parameters *params) 6890 { 6891 int err; 6892 /* Dummy STA entry gets updated once the peer capabilities are known */ 6893 if (info->attrs[NL80211_ATTR_PEER_AID]) 6894 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 6895 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 6896 params->link_sta_params.ht_capa = 6897 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 6898 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 6899 params->link_sta_params.vht_capa = 6900 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 6901 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 6902 params->link_sta_params.he_capa = 6903 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6904 params->link_sta_params.he_capa_len = 6905 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6906 6907 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 6908 params->link_sta_params.eht_capa = 6909 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 6910 params->link_sta_params.eht_capa_len = 6911 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 6912 6913 if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa, 6914 (const u8 *)params->link_sta_params.eht_capa, 6915 params->link_sta_params.eht_capa_len, 6916 false)) 6917 return -EINVAL; 6918 } 6919 } 6920 6921 err = nl80211_parse_sta_channel_info(info, params); 6922 if (err) 6923 return err; 6924 6925 return nl80211_parse_sta_wme(info, params); 6926 } 6927 6928 static int nl80211_parse_sta_txpower_setting(struct genl_info *info, 6929 struct sta_txpwr *txpwr, 6930 bool *txpwr_set) 6931 { 6932 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6933 int idx; 6934 6935 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { 6936 if (!rdev->ops->set_tx_power || 6937 !wiphy_ext_feature_isset(&rdev->wiphy, 6938 NL80211_EXT_FEATURE_STA_TX_PWR)) 6939 return -EOPNOTSUPP; 6940 6941 idx = NL80211_ATTR_STA_TX_POWER_SETTING; 6942 txpwr->type = nla_get_u8(info->attrs[idx]); 6943 6944 if (txpwr->type == NL80211_TX_POWER_LIMITED) { 6945 idx = NL80211_ATTR_STA_TX_POWER; 6946 6947 if (info->attrs[idx]) 6948 txpwr->power = nla_get_s16(info->attrs[idx]); 6949 else 6950 return -EINVAL; 6951 } 6952 6953 *txpwr_set = true; 6954 } else { 6955 *txpwr_set = false; 6956 } 6957 6958 return 0; 6959 } 6960 6961 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 6962 { 6963 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6964 struct net_device *dev = info->user_ptr[1]; 6965 struct station_parameters params; 6966 u8 *mac_addr; 6967 int err; 6968 6969 memset(¶ms, 0, sizeof(params)); 6970 6971 if (!rdev->ops->change_station) 6972 return -EOPNOTSUPP; 6973 6974 /* 6975 * AID and listen_interval properties can be set only for unassociated 6976 * station. Include these parameters here and will check them in 6977 * cfg80211_check_station_change(). 6978 */ 6979 if (info->attrs[NL80211_ATTR_STA_AID]) 6980 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 6981 6982 if (info->attrs[NL80211_ATTR_VLAN_ID]) 6983 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 6984 6985 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 6986 params.listen_interval = 6987 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 6988 else 6989 params.listen_interval = -1; 6990 6991 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) 6992 params.support_p2p_ps = 6993 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 6994 else 6995 params.support_p2p_ps = -1; 6996 6997 if (!info->attrs[NL80211_ATTR_MAC]) 6998 return -EINVAL; 6999 7000 params.link_sta_params.link_id = 7001 nl80211_link_id_or_invalid(info->attrs); 7002 7003 if (info->attrs[NL80211_ATTR_MLD_ADDR]) { 7004 /* If MLD_ADDR attribute is set then this is an MLD station 7005 * and the MLD_ADDR attribute holds the MLD address and the 7006 * MAC attribute holds for the LINK address. 7007 * In that case, the link_id is also expected to be valid. 7008 */ 7009 if (params.link_sta_params.link_id < 0) 7010 return -EINVAL; 7011 7012 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 7013 params.link_sta_params.mld_mac = mac_addr; 7014 params.link_sta_params.link_mac = 7015 nla_data(info->attrs[NL80211_ATTR_MAC]); 7016 if (!is_valid_ether_addr(params.link_sta_params.link_mac)) 7017 return -EINVAL; 7018 } else { 7019 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 7020 } 7021 7022 7023 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 7024 params.link_sta_params.supported_rates = 7025 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7026 params.link_sta_params.supported_rates_len = 7027 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7028 } 7029 7030 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 7031 params.capability = 7032 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 7033 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 7034 } 7035 7036 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 7037 params.ext_capab = 7038 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7039 params.ext_capab_len = 7040 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7041 } 7042 7043 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 7044 return -EINVAL; 7045 7046 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 7047 params.plink_action = 7048 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 7049 7050 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { 7051 params.plink_state = 7052 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 7053 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) 7054 params.peer_aid = nla_get_u16( 7055 info->attrs[NL80211_ATTR_MESH_PEER_AID]); 7056 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; 7057 } 7058 7059 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) 7060 params.local_pm = nla_get_u32( 7061 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); 7062 7063 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 7064 params.link_sta_params.opmode_notif_used = true; 7065 params.link_sta_params.opmode_notif = 7066 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 7067 } 7068 7069 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 7070 params.link_sta_params.he_6ghz_capa = 7071 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 7072 7073 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 7074 params.airtime_weight = 7075 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 7076 7077 if (params.airtime_weight && 7078 !wiphy_ext_feature_isset(&rdev->wiphy, 7079 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 7080 return -EOPNOTSUPP; 7081 7082 err = nl80211_parse_sta_txpower_setting(info, 7083 ¶ms.link_sta_params.txpwr, 7084 ¶ms.link_sta_params.txpwr_set); 7085 if (err) 7086 return err; 7087 7088 /* Include parameters for TDLS peer (will check later) */ 7089 err = nl80211_set_station_tdls(info, ¶ms); 7090 if (err) 7091 return err; 7092 7093 params.vlan = get_vlan(info, rdev); 7094 if (IS_ERR(params.vlan)) 7095 return PTR_ERR(params.vlan); 7096 7097 switch (dev->ieee80211_ptr->iftype) { 7098 case NL80211_IFTYPE_AP: 7099 case NL80211_IFTYPE_AP_VLAN: 7100 case NL80211_IFTYPE_P2P_GO: 7101 case NL80211_IFTYPE_P2P_CLIENT: 7102 case NL80211_IFTYPE_STATION: 7103 case NL80211_IFTYPE_ADHOC: 7104 case NL80211_IFTYPE_MESH_POINT: 7105 break; 7106 default: 7107 err = -EOPNOTSUPP; 7108 goto out_put_vlan; 7109 } 7110 7111 /* driver will call cfg80211_check_station_change() */ 7112 wdev_lock(dev->ieee80211_ptr); 7113 err = rdev_change_station(rdev, dev, mac_addr, ¶ms); 7114 wdev_unlock(dev->ieee80211_ptr); 7115 7116 out_put_vlan: 7117 dev_put(params.vlan); 7118 7119 return err; 7120 } 7121 7122 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 7123 { 7124 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7125 int err; 7126 struct net_device *dev = info->user_ptr[1]; 7127 struct wireless_dev *wdev = dev->ieee80211_ptr; 7128 struct station_parameters params; 7129 u8 *mac_addr = NULL; 7130 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 7131 BIT(NL80211_STA_FLAG_ASSOCIATED); 7132 7133 memset(¶ms, 0, sizeof(params)); 7134 7135 if (!rdev->ops->add_station) 7136 return -EOPNOTSUPP; 7137 7138 if (!info->attrs[NL80211_ATTR_MAC]) 7139 return -EINVAL; 7140 7141 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 7142 return -EINVAL; 7143 7144 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 7145 return -EINVAL; 7146 7147 if (!info->attrs[NL80211_ATTR_STA_AID] && 7148 !info->attrs[NL80211_ATTR_PEER_AID]) 7149 return -EINVAL; 7150 7151 params.link_sta_params.link_id = 7152 nl80211_link_id_or_invalid(info->attrs); 7153 7154 if (info->attrs[NL80211_ATTR_MLD_ADDR]) { 7155 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 7156 params.link_sta_params.mld_mac = mac_addr; 7157 params.link_sta_params.link_mac = 7158 nla_data(info->attrs[NL80211_ATTR_MAC]); 7159 if (!is_valid_ether_addr(params.link_sta_params.link_mac)) 7160 return -EINVAL; 7161 } else { 7162 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 7163 } 7164 7165 params.link_sta_params.supported_rates = 7166 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7167 params.link_sta_params.supported_rates_len = 7168 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7169 params.listen_interval = 7170 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 7171 7172 if (info->attrs[NL80211_ATTR_VLAN_ID]) 7173 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 7174 7175 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { 7176 params.support_p2p_ps = 7177 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 7178 } else { 7179 /* 7180 * if not specified, assume it's supported for P2P GO interface, 7181 * and is NOT supported for AP interface 7182 */ 7183 params.support_p2p_ps = 7184 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; 7185 } 7186 7187 if (info->attrs[NL80211_ATTR_PEER_AID]) 7188 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 7189 else 7190 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 7191 7192 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 7193 params.capability = 7194 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 7195 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 7196 } 7197 7198 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 7199 params.ext_capab = 7200 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7201 params.ext_capab_len = 7202 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7203 } 7204 7205 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 7206 params.link_sta_params.ht_capa = 7207 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 7208 7209 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 7210 params.link_sta_params.vht_capa = 7211 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 7212 7213 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 7214 params.link_sta_params.he_capa = 7215 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7216 params.link_sta_params.he_capa_len = 7217 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7218 7219 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 7220 params.link_sta_params.eht_capa = 7221 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7222 params.link_sta_params.eht_capa_len = 7223 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7224 7225 if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa, 7226 (const u8 *)params.link_sta_params.eht_capa, 7227 params.link_sta_params.eht_capa_len, 7228 false)) 7229 return -EINVAL; 7230 } 7231 } 7232 7233 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 7234 params.link_sta_params.he_6ghz_capa = 7235 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 7236 7237 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 7238 params.link_sta_params.opmode_notif_used = true; 7239 params.link_sta_params.opmode_notif = 7240 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 7241 } 7242 7243 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 7244 params.plink_action = 7245 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 7246 7247 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 7248 params.airtime_weight = 7249 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 7250 7251 if (params.airtime_weight && 7252 !wiphy_ext_feature_isset(&rdev->wiphy, 7253 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 7254 return -EOPNOTSUPP; 7255 7256 err = nl80211_parse_sta_txpower_setting(info, 7257 ¶ms.link_sta_params.txpwr, 7258 ¶ms.link_sta_params.txpwr_set); 7259 if (err) 7260 return err; 7261 7262 err = nl80211_parse_sta_channel_info(info, ¶ms); 7263 if (err) 7264 return err; 7265 7266 err = nl80211_parse_sta_wme(info, ¶ms); 7267 if (err) 7268 return err; 7269 7270 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 7271 return -EINVAL; 7272 7273 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT 7274 * as userspace might just pass through the capabilities from the IEs 7275 * directly, rather than enforcing this restriction and returning an 7276 * error in this case. 7277 */ 7278 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { 7279 params.link_sta_params.ht_capa = NULL; 7280 params.link_sta_params.vht_capa = NULL; 7281 7282 /* HE and EHT require WME */ 7283 if (params.link_sta_params.he_capa_len || 7284 params.link_sta_params.he_6ghz_capa || 7285 params.link_sta_params.eht_capa_len) 7286 return -EINVAL; 7287 } 7288 7289 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ 7290 if (params.link_sta_params.he_6ghz_capa && 7291 (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa)) 7292 return -EINVAL; 7293 7294 /* When you run into this, adjust the code below for the new flag */ 7295 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 7296 7297 switch (dev->ieee80211_ptr->iftype) { 7298 case NL80211_IFTYPE_AP: 7299 case NL80211_IFTYPE_AP_VLAN: 7300 case NL80211_IFTYPE_P2P_GO: 7301 /* ignore WME attributes if iface/sta is not capable */ 7302 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || 7303 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) 7304 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7305 7306 /* TDLS peers cannot be added */ 7307 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 7308 info->attrs[NL80211_ATTR_PEER_AID]) 7309 return -EINVAL; 7310 /* but don't bother the driver with it */ 7311 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 7312 7313 /* allow authenticated/associated only if driver handles it */ 7314 if (!(rdev->wiphy.features & 7315 NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 7316 params.sta_flags_mask & auth_assoc) 7317 return -EINVAL; 7318 7319 /* Older userspace, or userspace wanting to be compatible with 7320 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth 7321 * and assoc flags in the mask, but assumes the station will be 7322 * added as associated anyway since this was the required driver 7323 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was 7324 * introduced. 7325 * In order to not bother drivers with this quirk in the API 7326 * set the flags in both the mask and set for new stations in 7327 * this case. 7328 */ 7329 if (!(params.sta_flags_mask & auth_assoc)) { 7330 params.sta_flags_mask |= auth_assoc; 7331 params.sta_flags_set |= auth_assoc; 7332 } 7333 7334 /* must be last in here for error handling */ 7335 params.vlan = get_vlan(info, rdev); 7336 if (IS_ERR(params.vlan)) 7337 return PTR_ERR(params.vlan); 7338 break; 7339 case NL80211_IFTYPE_MESH_POINT: 7340 /* ignore uAPSD data */ 7341 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7342 7343 /* associated is disallowed */ 7344 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) 7345 return -EINVAL; 7346 /* TDLS peers cannot be added */ 7347 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 7348 info->attrs[NL80211_ATTR_PEER_AID]) 7349 return -EINVAL; 7350 break; 7351 case NL80211_IFTYPE_STATION: 7352 case NL80211_IFTYPE_P2P_CLIENT: 7353 /* ignore uAPSD data */ 7354 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7355 7356 /* these are disallowed */ 7357 if (params.sta_flags_mask & 7358 (BIT(NL80211_STA_FLAG_ASSOCIATED) | 7359 BIT(NL80211_STA_FLAG_AUTHENTICATED))) 7360 return -EINVAL; 7361 /* Only TDLS peers can be added */ 7362 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 7363 return -EINVAL; 7364 /* Can only add if TDLS ... */ 7365 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) 7366 return -EOPNOTSUPP; 7367 /* ... with external setup is supported */ 7368 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 7369 return -EOPNOTSUPP; 7370 /* 7371 * Older wpa_supplicant versions always mark the TDLS peer 7372 * as authorized, but it shouldn't yet be. 7373 */ 7374 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); 7375 break; 7376 default: 7377 return -EOPNOTSUPP; 7378 } 7379 7380 /* be aware of params.vlan when changing code here */ 7381 7382 wdev_lock(dev->ieee80211_ptr); 7383 if (wdev->valid_links) { 7384 if (params.link_sta_params.link_id < 0) { 7385 err = -EINVAL; 7386 goto out; 7387 } 7388 if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) { 7389 err = -ENOLINK; 7390 goto out; 7391 } 7392 } else { 7393 if (params.link_sta_params.link_id >= 0) { 7394 err = -EINVAL; 7395 goto out; 7396 } 7397 } 7398 err = rdev_add_station(rdev, dev, mac_addr, ¶ms); 7399 out: 7400 wdev_unlock(dev->ieee80211_ptr); 7401 dev_put(params.vlan); 7402 return err; 7403 } 7404 7405 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 7406 { 7407 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7408 struct net_device *dev = info->user_ptr[1]; 7409 struct station_del_parameters params; 7410 int ret; 7411 7412 memset(¶ms, 0, sizeof(params)); 7413 7414 if (info->attrs[NL80211_ATTR_MAC]) 7415 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 7416 7417 switch (dev->ieee80211_ptr->iftype) { 7418 case NL80211_IFTYPE_AP: 7419 case NL80211_IFTYPE_AP_VLAN: 7420 case NL80211_IFTYPE_MESH_POINT: 7421 case NL80211_IFTYPE_P2P_GO: 7422 /* always accept these */ 7423 break; 7424 case NL80211_IFTYPE_ADHOC: 7425 /* conditionally accept */ 7426 if (wiphy_ext_feature_isset(&rdev->wiphy, 7427 NL80211_EXT_FEATURE_DEL_IBSS_STA)) 7428 break; 7429 return -EINVAL; 7430 default: 7431 return -EINVAL; 7432 } 7433 7434 if (!rdev->ops->del_station) 7435 return -EOPNOTSUPP; 7436 7437 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { 7438 params.subtype = 7439 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); 7440 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && 7441 params.subtype != IEEE80211_STYPE_DEAUTH >> 4) 7442 return -EINVAL; 7443 } else { 7444 /* Default to Deauthentication frame */ 7445 params.subtype = IEEE80211_STYPE_DEAUTH >> 4; 7446 } 7447 7448 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 7449 params.reason_code = 7450 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 7451 if (params.reason_code == 0) 7452 return -EINVAL; /* 0 is reserved */ 7453 } else { 7454 /* Default to reason code 2 */ 7455 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; 7456 } 7457 7458 wdev_lock(dev->ieee80211_ptr); 7459 ret = rdev_del_station(rdev, dev, ¶ms); 7460 wdev_unlock(dev->ieee80211_ptr); 7461 7462 return ret; 7463 } 7464 7465 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 7466 int flags, struct net_device *dev, 7467 u8 *dst, u8 *next_hop, 7468 struct mpath_info *pinfo) 7469 { 7470 void *hdr; 7471 struct nlattr *pinfoattr; 7472 7473 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); 7474 if (!hdr) 7475 return -1; 7476 7477 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 7478 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || 7479 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || 7480 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 7481 goto nla_put_failure; 7482 7483 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); 7484 if (!pinfoattr) 7485 goto nla_put_failure; 7486 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 7487 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 7488 pinfo->frame_qlen)) 7489 goto nla_put_failure; 7490 if (((pinfo->filled & MPATH_INFO_SN) && 7491 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || 7492 ((pinfo->filled & MPATH_INFO_METRIC) && 7493 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, 7494 pinfo->metric)) || 7495 ((pinfo->filled & MPATH_INFO_EXPTIME) && 7496 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, 7497 pinfo->exptime)) || 7498 ((pinfo->filled & MPATH_INFO_FLAGS) && 7499 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, 7500 pinfo->flags)) || 7501 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && 7502 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, 7503 pinfo->discovery_timeout)) || 7504 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && 7505 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, 7506 pinfo->discovery_retries)) || 7507 ((pinfo->filled & MPATH_INFO_HOP_COUNT) && 7508 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, 7509 pinfo->hop_count)) || 7510 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && 7511 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, 7512 pinfo->path_change_count))) 7513 goto nla_put_failure; 7514 7515 nla_nest_end(msg, pinfoattr); 7516 7517 genlmsg_end(msg, hdr); 7518 return 0; 7519 7520 nla_put_failure: 7521 genlmsg_cancel(msg, hdr); 7522 return -EMSGSIZE; 7523 } 7524 7525 static int nl80211_dump_mpath(struct sk_buff *skb, 7526 struct netlink_callback *cb) 7527 { 7528 struct mpath_info pinfo; 7529 struct cfg80211_registered_device *rdev; 7530 struct wireless_dev *wdev; 7531 u8 dst[ETH_ALEN]; 7532 u8 next_hop[ETH_ALEN]; 7533 int path_idx = cb->args[2]; 7534 int err; 7535 7536 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 7537 if (err) 7538 return err; 7539 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7540 __acquire(&rdev->wiphy.mtx); 7541 7542 if (!rdev->ops->dump_mpath) { 7543 err = -EOPNOTSUPP; 7544 goto out_err; 7545 } 7546 7547 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7548 err = -EOPNOTSUPP; 7549 goto out_err; 7550 } 7551 7552 while (1) { 7553 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, 7554 next_hop, &pinfo); 7555 if (err == -ENOENT) 7556 break; 7557 if (err) 7558 goto out_err; 7559 7560 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7561 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7562 wdev->netdev, dst, next_hop, 7563 &pinfo) < 0) 7564 goto out; 7565 7566 path_idx++; 7567 } 7568 7569 out: 7570 cb->args[2] = path_idx; 7571 err = skb->len; 7572 out_err: 7573 wiphy_unlock(&rdev->wiphy); 7574 return err; 7575 } 7576 7577 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 7578 { 7579 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7580 int err; 7581 struct net_device *dev = info->user_ptr[1]; 7582 struct mpath_info pinfo; 7583 struct sk_buff *msg; 7584 u8 *dst = NULL; 7585 u8 next_hop[ETH_ALEN]; 7586 7587 memset(&pinfo, 0, sizeof(pinfo)); 7588 7589 if (!info->attrs[NL80211_ATTR_MAC]) 7590 return -EINVAL; 7591 7592 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7593 7594 if (!rdev->ops->get_mpath) 7595 return -EOPNOTSUPP; 7596 7597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7598 return -EOPNOTSUPP; 7599 7600 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); 7601 if (err) 7602 return err; 7603 7604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7605 if (!msg) 7606 return -ENOMEM; 7607 7608 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7609 dev, dst, next_hop, &pinfo) < 0) { 7610 nlmsg_free(msg); 7611 return -ENOBUFS; 7612 } 7613 7614 return genlmsg_reply(msg, info); 7615 } 7616 7617 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 7618 { 7619 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7620 struct net_device *dev = info->user_ptr[1]; 7621 u8 *dst = NULL; 7622 u8 *next_hop = NULL; 7623 7624 if (!info->attrs[NL80211_ATTR_MAC]) 7625 return -EINVAL; 7626 7627 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 7628 return -EINVAL; 7629 7630 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7631 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 7632 7633 if (!rdev->ops->change_mpath) 7634 return -EOPNOTSUPP; 7635 7636 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7637 return -EOPNOTSUPP; 7638 7639 return rdev_change_mpath(rdev, dev, dst, next_hop); 7640 } 7641 7642 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 7643 { 7644 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7645 struct net_device *dev = info->user_ptr[1]; 7646 u8 *dst = NULL; 7647 u8 *next_hop = NULL; 7648 7649 if (!info->attrs[NL80211_ATTR_MAC]) 7650 return -EINVAL; 7651 7652 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 7653 return -EINVAL; 7654 7655 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7656 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 7657 7658 if (!rdev->ops->add_mpath) 7659 return -EOPNOTSUPP; 7660 7661 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7662 return -EOPNOTSUPP; 7663 7664 return rdev_add_mpath(rdev, dev, dst, next_hop); 7665 } 7666 7667 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 7668 { 7669 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7670 struct net_device *dev = info->user_ptr[1]; 7671 u8 *dst = NULL; 7672 7673 if (info->attrs[NL80211_ATTR_MAC]) 7674 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7675 7676 if (!rdev->ops->del_mpath) 7677 return -EOPNOTSUPP; 7678 7679 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7680 return -EOPNOTSUPP; 7681 7682 return rdev_del_mpath(rdev, dev, dst); 7683 } 7684 7685 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) 7686 { 7687 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7688 int err; 7689 struct net_device *dev = info->user_ptr[1]; 7690 struct mpath_info pinfo; 7691 struct sk_buff *msg; 7692 u8 *dst = NULL; 7693 u8 mpp[ETH_ALEN]; 7694 7695 memset(&pinfo, 0, sizeof(pinfo)); 7696 7697 if (!info->attrs[NL80211_ATTR_MAC]) 7698 return -EINVAL; 7699 7700 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7701 7702 if (!rdev->ops->get_mpp) 7703 return -EOPNOTSUPP; 7704 7705 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7706 return -EOPNOTSUPP; 7707 7708 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); 7709 if (err) 7710 return err; 7711 7712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7713 if (!msg) 7714 return -ENOMEM; 7715 7716 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7717 dev, dst, mpp, &pinfo) < 0) { 7718 nlmsg_free(msg); 7719 return -ENOBUFS; 7720 } 7721 7722 return genlmsg_reply(msg, info); 7723 } 7724 7725 static int nl80211_dump_mpp(struct sk_buff *skb, 7726 struct netlink_callback *cb) 7727 { 7728 struct mpath_info pinfo; 7729 struct cfg80211_registered_device *rdev; 7730 struct wireless_dev *wdev; 7731 u8 dst[ETH_ALEN]; 7732 u8 mpp[ETH_ALEN]; 7733 int path_idx = cb->args[2]; 7734 int err; 7735 7736 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 7737 if (err) 7738 return err; 7739 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7740 __acquire(&rdev->wiphy.mtx); 7741 7742 if (!rdev->ops->dump_mpp) { 7743 err = -EOPNOTSUPP; 7744 goto out_err; 7745 } 7746 7747 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7748 err = -EOPNOTSUPP; 7749 goto out_err; 7750 } 7751 7752 while (1) { 7753 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, 7754 mpp, &pinfo); 7755 if (err == -ENOENT) 7756 break; 7757 if (err) 7758 goto out_err; 7759 7760 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7761 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7762 wdev->netdev, dst, mpp, 7763 &pinfo) < 0) 7764 goto out; 7765 7766 path_idx++; 7767 } 7768 7769 out: 7770 cb->args[2] = path_idx; 7771 err = skb->len; 7772 out_err: 7773 wiphy_unlock(&rdev->wiphy); 7774 return err; 7775 } 7776 7777 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 7778 { 7779 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7780 struct net_device *dev = info->user_ptr[1]; 7781 struct wireless_dev *wdev = dev->ieee80211_ptr; 7782 struct bss_parameters params; 7783 int err; 7784 7785 memset(¶ms, 0, sizeof(params)); 7786 params.link_id = nl80211_link_id_or_invalid(info->attrs); 7787 /* default to not changing parameters */ 7788 params.use_cts_prot = -1; 7789 params.use_short_preamble = -1; 7790 params.use_short_slot_time = -1; 7791 params.ap_isolate = -1; 7792 params.ht_opmode = -1; 7793 params.p2p_ctwindow = -1; 7794 params.p2p_opp_ps = -1; 7795 7796 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 7797 params.use_cts_prot = 7798 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); 7799 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) 7800 params.use_short_preamble = 7801 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); 7802 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 7803 params.use_short_slot_time = 7804 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 7805 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 7806 params.basic_rates = 7807 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 7808 params.basic_rates_len = 7809 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 7810 } 7811 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 7812 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 7813 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) 7814 params.ht_opmode = 7815 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); 7816 7817 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 7818 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 7819 return -EINVAL; 7820 params.p2p_ctwindow = 7821 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 7822 if (params.p2p_ctwindow != 0 && 7823 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 7824 return -EINVAL; 7825 } 7826 7827 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 7828 u8 tmp; 7829 7830 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 7831 return -EINVAL; 7832 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 7833 params.p2p_opp_ps = tmp; 7834 if (params.p2p_opp_ps && 7835 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 7836 return -EINVAL; 7837 } 7838 7839 if (!rdev->ops->change_bss) 7840 return -EOPNOTSUPP; 7841 7842 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 7843 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 7844 return -EOPNOTSUPP; 7845 7846 wdev_lock(wdev); 7847 err = rdev_change_bss(rdev, dev, ¶ms); 7848 wdev_unlock(wdev); 7849 7850 return err; 7851 } 7852 7853 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) 7854 { 7855 char *data = NULL; 7856 bool is_indoor; 7857 enum nl80211_user_reg_hint_type user_reg_hint_type; 7858 u32 owner_nlportid; 7859 7860 /* 7861 * You should only get this when cfg80211 hasn't yet initialized 7862 * completely when built-in to the kernel right between the time 7863 * window between nl80211_init() and regulatory_init(), if that is 7864 * even possible. 7865 */ 7866 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 7867 return -EINPROGRESS; 7868 7869 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 7870 user_reg_hint_type = 7871 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 7872 else 7873 user_reg_hint_type = NL80211_USER_REG_HINT_USER; 7874 7875 switch (user_reg_hint_type) { 7876 case NL80211_USER_REG_HINT_USER: 7877 case NL80211_USER_REG_HINT_CELL_BASE: 7878 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 7879 return -EINVAL; 7880 7881 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 7882 return regulatory_hint_user(data, user_reg_hint_type); 7883 case NL80211_USER_REG_HINT_INDOOR: 7884 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 7885 owner_nlportid = info->snd_portid; 7886 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; 7887 } else { 7888 owner_nlportid = 0; 7889 is_indoor = true; 7890 } 7891 7892 return regulatory_hint_indoor(is_indoor, owner_nlportid); 7893 default: 7894 return -EINVAL; 7895 } 7896 } 7897 7898 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) 7899 { 7900 return reg_reload_regdb(); 7901 } 7902 7903 static int nl80211_get_mesh_config(struct sk_buff *skb, 7904 struct genl_info *info) 7905 { 7906 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7907 struct net_device *dev = info->user_ptr[1]; 7908 struct wireless_dev *wdev = dev->ieee80211_ptr; 7909 struct mesh_config cur_params; 7910 int err = 0; 7911 void *hdr; 7912 struct nlattr *pinfoattr; 7913 struct sk_buff *msg; 7914 7915 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 7916 return -EOPNOTSUPP; 7917 7918 if (!rdev->ops->get_mesh_config) 7919 return -EOPNOTSUPP; 7920 7921 wdev_lock(wdev); 7922 /* If not connected, get default parameters */ 7923 if (!wdev->u.mesh.id_len) 7924 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); 7925 else 7926 err = rdev_get_mesh_config(rdev, dev, &cur_params); 7927 wdev_unlock(wdev); 7928 7929 if (err) 7930 return err; 7931 7932 /* Draw up a netlink message to send back */ 7933 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7934 if (!msg) 7935 return -ENOMEM; 7936 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 7937 NL80211_CMD_GET_MESH_CONFIG); 7938 if (!hdr) 7939 goto out; 7940 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); 7941 if (!pinfoattr) 7942 goto nla_put_failure; 7943 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 7944 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, 7945 cur_params.dot11MeshRetryTimeout) || 7946 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, 7947 cur_params.dot11MeshConfirmTimeout) || 7948 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, 7949 cur_params.dot11MeshHoldingTimeout) || 7950 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, 7951 cur_params.dot11MeshMaxPeerLinks) || 7952 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, 7953 cur_params.dot11MeshMaxRetries) || 7954 nla_put_u8(msg, NL80211_MESHCONF_TTL, 7955 cur_params.dot11MeshTTL) || 7956 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, 7957 cur_params.element_ttl) || 7958 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 7959 cur_params.auto_open_plinks) || 7960 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 7961 cur_params.dot11MeshNbrOffsetMaxNeighbor) || 7962 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 7963 cur_params.dot11MeshHWMPmaxPREQretries) || 7964 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, 7965 cur_params.path_refresh_time) || 7966 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 7967 cur_params.min_discovery_timeout) || 7968 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 7969 cur_params.dot11MeshHWMPactivePathTimeout) || 7970 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 7971 cur_params.dot11MeshHWMPpreqMinInterval) || 7972 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 7973 cur_params.dot11MeshHWMPperrMinInterval) || 7974 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 7975 cur_params.dot11MeshHWMPnetDiameterTraversalTime) || 7976 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, 7977 cur_params.dot11MeshHWMPRootMode) || 7978 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, 7979 cur_params.dot11MeshHWMPRannInterval) || 7980 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 7981 cur_params.dot11MeshGateAnnouncementProtocol) || 7982 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, 7983 cur_params.dot11MeshForwarding) || 7984 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, 7985 cur_params.rssi_threshold) || 7986 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, 7987 cur_params.ht_opmode) || 7988 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 7989 cur_params.dot11MeshHWMPactivePathToRootTimeout) || 7990 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 7991 cur_params.dot11MeshHWMProotInterval) || 7992 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 7993 cur_params.dot11MeshHWMPconfirmationInterval) || 7994 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, 7995 cur_params.power_mode) || 7996 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, 7997 cur_params.dot11MeshAwakeWindowDuration) || 7998 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, 7999 cur_params.plink_timeout) || 8000 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, 8001 cur_params.dot11MeshConnectedToMeshGate) || 8002 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, 8003 cur_params.dot11MeshNolearn) || 8004 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, 8005 cur_params.dot11MeshConnectedToAuthServer)) 8006 goto nla_put_failure; 8007 nla_nest_end(msg, pinfoattr); 8008 genlmsg_end(msg, hdr); 8009 return genlmsg_reply(msg, info); 8010 8011 nla_put_failure: 8012 out: 8013 nlmsg_free(msg); 8014 return -ENOBUFS; 8015 } 8016 8017 static const struct nla_policy 8018 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 8019 [NL80211_MESHCONF_RETRY_TIMEOUT] = 8020 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8021 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = 8022 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8023 [NL80211_MESHCONF_HOLDING_TIMEOUT] = 8024 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8025 [NL80211_MESHCONF_MAX_PEER_LINKS] = 8026 NLA_POLICY_RANGE(NLA_U16, 0, 255), 8027 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), 8028 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 8029 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 8030 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), 8031 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = 8032 NLA_POLICY_RANGE(NLA_U32, 1, 255), 8033 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 8034 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, 8035 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), 8036 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, 8037 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = 8038 NLA_POLICY_MIN(NLA_U16, 1), 8039 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = 8040 NLA_POLICY_MIN(NLA_U16, 1), 8041 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = 8042 NLA_POLICY_MIN(NLA_U16, 1), 8043 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), 8044 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = 8045 NLA_POLICY_MIN(NLA_U16, 1), 8046 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), 8047 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), 8048 [NL80211_MESHCONF_RSSI_THRESHOLD] = 8049 NLA_POLICY_RANGE(NLA_S32, -255, 0), 8050 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, 8051 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 8052 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = 8053 NLA_POLICY_MIN(NLA_U16, 1), 8054 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = 8055 NLA_POLICY_MIN(NLA_U16, 1), 8056 [NL80211_MESHCONF_POWER_MODE] = 8057 NLA_POLICY_RANGE(NLA_U32, 8058 NL80211_MESH_POWER_ACTIVE, 8059 NL80211_MESH_POWER_MAX), 8060 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, 8061 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, 8062 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8063 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8064 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8065 }; 8066 8067 static const struct nla_policy 8068 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { 8069 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, 8070 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, 8071 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, 8072 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, 8073 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, 8074 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, 8075 [NL80211_MESH_SETUP_IE] = 8076 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 8077 IEEE80211_MAX_DATA_LEN), 8078 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, 8079 }; 8080 8081 static int nl80211_parse_mesh_config(struct genl_info *info, 8082 struct mesh_config *cfg, 8083 u32 *mask_out) 8084 { 8085 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 8086 u32 mask = 0; 8087 u16 ht_opmode; 8088 8089 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ 8090 do { \ 8091 if (tb[attr]) { \ 8092 cfg->param = fn(tb[attr]); \ 8093 mask |= BIT((attr) - 1); \ 8094 } \ 8095 } while (0) 8096 8097 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 8098 return -EINVAL; 8099 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) 8100 return -EINVAL; 8101 8102 /* This makes sure that there aren't more than 32 mesh config 8103 * parameters (otherwise our bitfield scheme would not work.) */ 8104 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 8105 8106 /* Fill in the params struct */ 8107 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, 8108 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 8109 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, 8110 NL80211_MESHCONF_CONFIRM_TIMEOUT, 8111 nla_get_u16); 8112 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, 8113 NL80211_MESHCONF_HOLDING_TIMEOUT, 8114 nla_get_u16); 8115 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, 8116 NL80211_MESHCONF_MAX_PEER_LINKS, 8117 nla_get_u16); 8118 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, 8119 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 8120 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, 8121 NL80211_MESHCONF_TTL, nla_get_u8); 8122 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, 8123 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); 8124 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, 8125 NL80211_MESHCONF_AUTO_OPEN_PLINKS, 8126 nla_get_u8); 8127 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, 8128 mask, 8129 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 8130 nla_get_u32); 8131 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, 8132 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 8133 nla_get_u8); 8134 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, 8135 NL80211_MESHCONF_PATH_REFRESH_TIME, 8136 nla_get_u32); 8137 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && 8138 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) 8139 return -EINVAL; 8140 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, 8141 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 8142 nla_get_u16); 8143 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, 8144 mask, 8145 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 8146 nla_get_u32); 8147 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && 8148 (cfg->dot11MeshHWMPactivePathTimeout < 1 || 8149 cfg->dot11MeshHWMPactivePathTimeout > 65535)) 8150 return -EINVAL; 8151 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, 8152 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 8153 nla_get_u16); 8154 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, 8155 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 8156 nla_get_u16); 8157 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 8158 dot11MeshHWMPnetDiameterTraversalTime, mask, 8159 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 8160 nla_get_u16); 8161 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 8162 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 8163 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 8164 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 8165 nla_get_u16); 8166 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, 8167 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 8168 nla_get_u8); 8169 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, 8170 NL80211_MESHCONF_FORWARDING, nla_get_u8); 8171 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, 8172 NL80211_MESHCONF_RSSI_THRESHOLD, 8173 nla_get_s32); 8174 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, 8175 NL80211_MESHCONF_CONNECTED_TO_GATE, 8176 nla_get_u8); 8177 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, 8178 NL80211_MESHCONF_CONNECTED_TO_AS, 8179 nla_get_u8); 8180 /* 8181 * Check HT operation mode based on 8182 * IEEE 802.11-2016 9.4.2.57 HT Operation element. 8183 */ 8184 if (tb[NL80211_MESHCONF_HT_OPMODE]) { 8185 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); 8186 8187 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | 8188 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | 8189 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) 8190 return -EINVAL; 8191 8192 /* NON_HT_STA bit is reserved, but some programs set it */ 8193 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; 8194 8195 cfg->ht_opmode = ht_opmode; 8196 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); 8197 } 8198 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 8199 dot11MeshHWMPactivePathToRootTimeout, mask, 8200 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 8201 nla_get_u32); 8202 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && 8203 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || 8204 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) 8205 return -EINVAL; 8206 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, 8207 NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 8208 nla_get_u16); 8209 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, 8210 mask, 8211 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 8212 nla_get_u16); 8213 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, 8214 NL80211_MESHCONF_POWER_MODE, nla_get_u32); 8215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, 8216 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); 8217 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, 8218 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); 8219 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, 8220 NL80211_MESHCONF_NOLEARN, nla_get_u8); 8221 if (mask_out) 8222 *mask_out = mask; 8223 8224 return 0; 8225 8226 #undef FILL_IN_MESH_PARAM_IF_SET 8227 } 8228 8229 static int nl80211_parse_mesh_setup(struct genl_info *info, 8230 struct mesh_setup *setup) 8231 { 8232 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8233 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; 8234 8235 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 8236 return -EINVAL; 8237 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) 8238 return -EINVAL; 8239 8240 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 8241 setup->sync_method = 8242 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? 8243 IEEE80211_SYNC_METHOD_VENDOR : 8244 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; 8245 8246 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) 8247 setup->path_sel_proto = 8248 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? 8249 IEEE80211_PATH_PROTOCOL_VENDOR : 8250 IEEE80211_PATH_PROTOCOL_HWMP; 8251 8252 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) 8253 setup->path_metric = 8254 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? 8255 IEEE80211_PATH_METRIC_VENDOR : 8256 IEEE80211_PATH_METRIC_AIRTIME; 8257 8258 if (tb[NL80211_MESH_SETUP_IE]) { 8259 struct nlattr *ieattr = 8260 tb[NL80211_MESH_SETUP_IE]; 8261 setup->ie = nla_data(ieattr); 8262 setup->ie_len = nla_len(ieattr); 8263 } 8264 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && 8265 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) 8266 return -EINVAL; 8267 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); 8268 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); 8269 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); 8270 if (setup->is_secure) 8271 setup->user_mpm = true; 8272 8273 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { 8274 if (!setup->user_mpm) 8275 return -EINVAL; 8276 setup->auth_id = 8277 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); 8278 } 8279 8280 return 0; 8281 } 8282 8283 static int nl80211_update_mesh_config(struct sk_buff *skb, 8284 struct genl_info *info) 8285 { 8286 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8287 struct net_device *dev = info->user_ptr[1]; 8288 struct wireless_dev *wdev = dev->ieee80211_ptr; 8289 struct mesh_config cfg; 8290 u32 mask; 8291 int err; 8292 8293 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 8294 return -EOPNOTSUPP; 8295 8296 if (!rdev->ops->update_mesh_config) 8297 return -EOPNOTSUPP; 8298 8299 err = nl80211_parse_mesh_config(info, &cfg, &mask); 8300 if (err) 8301 return err; 8302 8303 wdev_lock(wdev); 8304 if (!wdev->u.mesh.id_len) 8305 err = -ENOLINK; 8306 8307 if (!err) 8308 err = rdev_update_mesh_config(rdev, dev, mask, &cfg); 8309 8310 wdev_unlock(wdev); 8311 8312 return err; 8313 } 8314 8315 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, 8316 struct sk_buff *msg) 8317 { 8318 struct nlattr *nl_reg_rules; 8319 unsigned int i; 8320 8321 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || 8322 (regdom->dfs_region && 8323 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 8324 goto nla_put_failure; 8325 8326 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); 8327 if (!nl_reg_rules) 8328 goto nla_put_failure; 8329 8330 for (i = 0; i < regdom->n_reg_rules; i++) { 8331 struct nlattr *nl_reg_rule; 8332 const struct ieee80211_reg_rule *reg_rule; 8333 const struct ieee80211_freq_range *freq_range; 8334 const struct ieee80211_power_rule *power_rule; 8335 unsigned int max_bandwidth_khz; 8336 8337 reg_rule = ®dom->reg_rules[i]; 8338 freq_range = ®_rule->freq_range; 8339 power_rule = ®_rule->power_rule; 8340 8341 nl_reg_rule = nla_nest_start_noflag(msg, i); 8342 if (!nl_reg_rule) 8343 goto nla_put_failure; 8344 8345 max_bandwidth_khz = freq_range->max_bandwidth_khz; 8346 if (!max_bandwidth_khz) 8347 max_bandwidth_khz = reg_get_max_bandwidth(regdom, 8348 reg_rule); 8349 8350 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 8351 reg_rule->flags) || 8352 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, 8353 freq_range->start_freq_khz) || 8354 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, 8355 freq_range->end_freq_khz) || 8356 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, 8357 max_bandwidth_khz) || 8358 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, 8359 power_rule->max_antenna_gain) || 8360 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 8361 power_rule->max_eirp) || 8362 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 8363 reg_rule->dfs_cac_ms)) 8364 goto nla_put_failure; 8365 8366 nla_nest_end(msg, nl_reg_rule); 8367 } 8368 8369 nla_nest_end(msg, nl_reg_rules); 8370 return 0; 8371 8372 nla_put_failure: 8373 return -EMSGSIZE; 8374 } 8375 8376 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) 8377 { 8378 const struct ieee80211_regdomain *regdom = NULL; 8379 struct cfg80211_registered_device *rdev; 8380 struct wiphy *wiphy = NULL; 8381 struct sk_buff *msg; 8382 int err = -EMSGSIZE; 8383 void *hdr; 8384 8385 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 8386 if (!msg) 8387 return -ENOBUFS; 8388 8389 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 8390 NL80211_CMD_GET_REG); 8391 if (!hdr) 8392 goto put_failure; 8393 8394 rtnl_lock(); 8395 8396 if (info->attrs[NL80211_ATTR_WIPHY]) { 8397 bool self_managed; 8398 8399 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 8400 if (IS_ERR(rdev)) { 8401 err = PTR_ERR(rdev); 8402 goto nla_put_failure; 8403 } 8404 8405 wiphy = &rdev->wiphy; 8406 self_managed = wiphy->regulatory_flags & 8407 REGULATORY_WIPHY_SELF_MANAGED; 8408 8409 rcu_read_lock(); 8410 8411 regdom = get_wiphy_regdom(wiphy); 8412 8413 /* a self-managed-reg device must have a private regdom */ 8414 if (WARN_ON(!regdom && self_managed)) { 8415 err = -EINVAL; 8416 goto nla_put_failure_rcu; 8417 } 8418 8419 if (regdom && 8420 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 8421 goto nla_put_failure_rcu; 8422 } else { 8423 rcu_read_lock(); 8424 } 8425 8426 if (!wiphy && reg_last_request_cell_base() && 8427 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 8428 NL80211_USER_REG_HINT_CELL_BASE)) 8429 goto nla_put_failure_rcu; 8430 8431 if (!regdom) 8432 regdom = rcu_dereference(cfg80211_regdomain); 8433 8434 if (nl80211_put_regdom(regdom, msg)) 8435 goto nla_put_failure_rcu; 8436 8437 rcu_read_unlock(); 8438 8439 genlmsg_end(msg, hdr); 8440 rtnl_unlock(); 8441 return genlmsg_reply(msg, info); 8442 8443 nla_put_failure_rcu: 8444 rcu_read_unlock(); 8445 nla_put_failure: 8446 rtnl_unlock(); 8447 put_failure: 8448 nlmsg_free(msg); 8449 return err; 8450 } 8451 8452 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, 8453 u32 seq, int flags, struct wiphy *wiphy, 8454 const struct ieee80211_regdomain *regdom) 8455 { 8456 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 8457 NL80211_CMD_GET_REG); 8458 8459 if (!hdr) 8460 return -1; 8461 8462 genl_dump_check_consistent(cb, hdr); 8463 8464 if (nl80211_put_regdom(regdom, msg)) 8465 goto nla_put_failure; 8466 8467 if (!wiphy && reg_last_request_cell_base() && 8468 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 8469 NL80211_USER_REG_HINT_CELL_BASE)) 8470 goto nla_put_failure; 8471 8472 if (wiphy && 8473 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 8474 goto nla_put_failure; 8475 8476 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 8477 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 8478 goto nla_put_failure; 8479 8480 genlmsg_end(msg, hdr); 8481 return 0; 8482 8483 nla_put_failure: 8484 genlmsg_cancel(msg, hdr); 8485 return -EMSGSIZE; 8486 } 8487 8488 static int nl80211_get_reg_dump(struct sk_buff *skb, 8489 struct netlink_callback *cb) 8490 { 8491 const struct ieee80211_regdomain *regdom = NULL; 8492 struct cfg80211_registered_device *rdev; 8493 int err, reg_idx, start = cb->args[2]; 8494 8495 rcu_read_lock(); 8496 8497 if (cfg80211_regdomain && start == 0) { 8498 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 8499 NLM_F_MULTI, NULL, 8500 rcu_dereference(cfg80211_regdomain)); 8501 if (err < 0) 8502 goto out_err; 8503 } 8504 8505 /* the global regdom is idx 0 */ 8506 reg_idx = 1; 8507 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 8508 regdom = get_wiphy_regdom(&rdev->wiphy); 8509 if (!regdom) 8510 continue; 8511 8512 if (++reg_idx <= start) 8513 continue; 8514 8515 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 8516 NLM_F_MULTI, &rdev->wiphy, regdom); 8517 if (err < 0) { 8518 reg_idx--; 8519 break; 8520 } 8521 } 8522 8523 cb->args[2] = reg_idx; 8524 err = skb->len; 8525 out_err: 8526 rcu_read_unlock(); 8527 return err; 8528 } 8529 8530 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 8531 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 8532 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 8533 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 8534 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 8535 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 8536 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 8537 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 8538 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, 8539 }; 8540 8541 static int parse_reg_rule(struct nlattr *tb[], 8542 struct ieee80211_reg_rule *reg_rule) 8543 { 8544 struct ieee80211_freq_range *freq_range = ®_rule->freq_range; 8545 struct ieee80211_power_rule *power_rule = ®_rule->power_rule; 8546 8547 if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) 8548 return -EINVAL; 8549 if (!tb[NL80211_ATTR_FREQ_RANGE_START]) 8550 return -EINVAL; 8551 if (!tb[NL80211_ATTR_FREQ_RANGE_END]) 8552 return -EINVAL; 8553 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 8554 return -EINVAL; 8555 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 8556 return -EINVAL; 8557 8558 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); 8559 8560 freq_range->start_freq_khz = 8561 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); 8562 freq_range->end_freq_khz = 8563 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); 8564 freq_range->max_bandwidth_khz = 8565 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); 8566 8567 power_rule->max_eirp = 8568 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); 8569 8570 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) 8571 power_rule->max_antenna_gain = 8572 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); 8573 8574 if (tb[NL80211_ATTR_DFS_CAC_TIME]) 8575 reg_rule->dfs_cac_ms = 8576 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); 8577 8578 return 0; 8579 } 8580 8581 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 8582 { 8583 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 8584 struct nlattr *nl_reg_rule; 8585 char *alpha2; 8586 int rem_reg_rules, r; 8587 u32 num_rules = 0, rule_idx = 0; 8588 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 8589 struct ieee80211_regdomain *rd; 8590 8591 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 8592 return -EINVAL; 8593 8594 if (!info->attrs[NL80211_ATTR_REG_RULES]) 8595 return -EINVAL; 8596 8597 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 8598 8599 if (info->attrs[NL80211_ATTR_DFS_REGION]) 8600 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 8601 8602 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 8603 rem_reg_rules) { 8604 num_rules++; 8605 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 8606 return -EINVAL; 8607 } 8608 8609 rtnl_lock(); 8610 if (!reg_is_valid_request(alpha2)) { 8611 r = -EINVAL; 8612 goto out; 8613 } 8614 8615 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); 8616 if (!rd) { 8617 r = -ENOMEM; 8618 goto out; 8619 } 8620 8621 rd->n_reg_rules = num_rules; 8622 rd->alpha2[0] = alpha2[0]; 8623 rd->alpha2[1] = alpha2[1]; 8624 8625 /* 8626 * Disable DFS master mode if the DFS region was 8627 * not supported or known on this kernel. 8628 */ 8629 if (reg_supported_dfs_region(dfs_region)) 8630 rd->dfs_region = dfs_region; 8631 8632 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 8633 rem_reg_rules) { 8634 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, 8635 nl_reg_rule, reg_rule_policy, 8636 info->extack); 8637 if (r) 8638 goto bad_reg; 8639 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 8640 if (r) 8641 goto bad_reg; 8642 8643 rule_idx++; 8644 8645 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { 8646 r = -EINVAL; 8647 goto bad_reg; 8648 } 8649 } 8650 8651 r = set_regdom(rd, REGD_SOURCE_CRDA); 8652 /* set_regdom takes ownership of rd */ 8653 rd = NULL; 8654 bad_reg: 8655 kfree(rd); 8656 out: 8657 rtnl_unlock(); 8658 return r; 8659 } 8660 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ 8661 8662 static int validate_scan_freqs(struct nlattr *freqs) 8663 { 8664 struct nlattr *attr1, *attr2; 8665 int n_channels = 0, tmp1, tmp2; 8666 8667 nla_for_each_nested(attr1, freqs, tmp1) 8668 if (nla_len(attr1) != sizeof(u32)) 8669 return 0; 8670 8671 nla_for_each_nested(attr1, freqs, tmp1) { 8672 n_channels++; 8673 /* 8674 * Some hardware has a limited channel list for 8675 * scanning, and it is pretty much nonsensical 8676 * to scan for a channel twice, so disallow that 8677 * and don't require drivers to check that the 8678 * channel list they get isn't longer than what 8679 * they can scan, as long as they can scan all 8680 * the channels they registered at once. 8681 */ 8682 nla_for_each_nested(attr2, freqs, tmp2) 8683 if (attr1 != attr2 && 8684 nla_get_u32(attr1) == nla_get_u32(attr2)) 8685 return 0; 8686 } 8687 8688 return n_channels; 8689 } 8690 8691 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) 8692 { 8693 return b < NUM_NL80211_BANDS && wiphy->bands[b]; 8694 } 8695 8696 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, 8697 struct cfg80211_bss_selection *bss_select) 8698 { 8699 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; 8700 struct nlattr *nest; 8701 int err; 8702 bool found = false; 8703 int i; 8704 8705 /* only process one nested attribute */ 8706 nest = nla_data(nla); 8707 if (!nla_ok(nest, nla_len(nest))) 8708 return -EINVAL; 8709 8710 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, 8711 nest, nl80211_bss_select_policy, 8712 NULL); 8713 if (err) 8714 return err; 8715 8716 /* only one attribute may be given */ 8717 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { 8718 if (attr[i]) { 8719 if (found) 8720 return -EINVAL; 8721 found = true; 8722 } 8723 } 8724 8725 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; 8726 8727 if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) 8728 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; 8729 8730 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { 8731 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; 8732 bss_select->param.band_pref = 8733 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); 8734 if (!is_band_valid(wiphy, bss_select->param.band_pref)) 8735 return -EINVAL; 8736 } 8737 8738 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { 8739 struct nl80211_bss_select_rssi_adjust *adj_param; 8740 8741 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); 8742 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; 8743 bss_select->param.adjust.band = adj_param->band; 8744 bss_select->param.adjust.delta = adj_param->delta; 8745 if (!is_band_valid(wiphy, bss_select->param.adjust.band)) 8746 return -EINVAL; 8747 } 8748 8749 /* user-space did not provide behaviour attribute */ 8750 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) 8751 return -EINVAL; 8752 8753 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) 8754 return -EINVAL; 8755 8756 return 0; 8757 } 8758 8759 int nl80211_parse_random_mac(struct nlattr **attrs, 8760 u8 *mac_addr, u8 *mac_addr_mask) 8761 { 8762 int i; 8763 8764 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { 8765 eth_zero_addr(mac_addr); 8766 eth_zero_addr(mac_addr_mask); 8767 mac_addr[0] = 0x2; 8768 mac_addr_mask[0] = 0x3; 8769 8770 return 0; 8771 } 8772 8773 /* need both or none */ 8774 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) 8775 return -EINVAL; 8776 8777 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); 8778 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); 8779 8780 /* don't allow or configure an mcast address */ 8781 if (!is_multicast_ether_addr(mac_addr_mask) || 8782 is_multicast_ether_addr(mac_addr)) 8783 return -EINVAL; 8784 8785 /* 8786 * allow users to pass a MAC address that has bits set outside 8787 * of the mask, but don't bother drivers with having to deal 8788 * with such bits 8789 */ 8790 for (i = 0; i < ETH_ALEN; i++) 8791 mac_addr[i] &= mac_addr_mask[i]; 8792 8793 return 0; 8794 } 8795 8796 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev, 8797 struct ieee80211_channel *chan) 8798 { 8799 unsigned int link_id; 8800 bool all_ok = true; 8801 8802 ASSERT_WDEV_LOCK(wdev); 8803 8804 if (!cfg80211_beaconing_iface_active(wdev)) 8805 return true; 8806 8807 /* 8808 * FIXME: check if we have a free HW resource/link for chan 8809 * 8810 * This, as well as the FIXME below, requires knowing the link 8811 * capabilities of the hardware. 8812 */ 8813 8814 /* we cannot leave radar channels */ 8815 for_each_valid_link(wdev, link_id) { 8816 struct cfg80211_chan_def *chandef; 8817 8818 chandef = wdev_chandef(wdev, link_id); 8819 if (!chandef) 8820 continue; 8821 8822 /* 8823 * FIXME: don't require all_ok, but rather check only the 8824 * correct HW resource/link onto which 'chan' falls, 8825 * as only that link leaves the channel for doing 8826 * the off-channel operation. 8827 */ 8828 8829 if (chandef->chan->flags & IEEE80211_CHAN_RADAR) 8830 all_ok = false; 8831 } 8832 8833 if (all_ok) 8834 return true; 8835 8836 return regulatory_pre_cac_allowed(wdev->wiphy); 8837 } 8838 8839 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, 8840 enum nl80211_ext_feature_index feat) 8841 { 8842 if (!(flags & flag)) 8843 return true; 8844 if (wiphy_ext_feature_isset(wiphy, feat)) 8845 return true; 8846 return false; 8847 } 8848 8849 static int 8850 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, 8851 void *request, struct nlattr **attrs, 8852 bool is_sched_scan) 8853 { 8854 u8 *mac_addr, *mac_addr_mask; 8855 u32 *flags; 8856 enum nl80211_feature_flags randomness_flag; 8857 8858 if (!attrs[NL80211_ATTR_SCAN_FLAGS]) 8859 return 0; 8860 8861 if (is_sched_scan) { 8862 struct cfg80211_sched_scan_request *req = request; 8863 8864 randomness_flag = wdev ? 8865 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : 8866 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 8867 flags = &req->flags; 8868 mac_addr = req->mac_addr; 8869 mac_addr_mask = req->mac_addr_mask; 8870 } else { 8871 struct cfg80211_scan_request *req = request; 8872 8873 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 8874 flags = &req->flags; 8875 mac_addr = req->mac_addr; 8876 mac_addr_mask = req->mac_addr_mask; 8877 } 8878 8879 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); 8880 8881 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && 8882 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || 8883 !nl80211_check_scan_feat(wiphy, *flags, 8884 NL80211_SCAN_FLAG_LOW_SPAN, 8885 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || 8886 !nl80211_check_scan_feat(wiphy, *flags, 8887 NL80211_SCAN_FLAG_LOW_POWER, 8888 NL80211_EXT_FEATURE_LOW_POWER_SCAN) || 8889 !nl80211_check_scan_feat(wiphy, *flags, 8890 NL80211_SCAN_FLAG_HIGH_ACCURACY, 8891 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || 8892 !nl80211_check_scan_feat(wiphy, *flags, 8893 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, 8894 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || 8895 !nl80211_check_scan_feat(wiphy, *flags, 8896 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, 8897 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || 8898 !nl80211_check_scan_feat(wiphy, *flags, 8899 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, 8900 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || 8901 !nl80211_check_scan_feat(wiphy, *flags, 8902 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, 8903 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || 8904 !nl80211_check_scan_feat(wiphy, *flags, 8905 NL80211_SCAN_FLAG_RANDOM_SN, 8906 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || 8907 !nl80211_check_scan_feat(wiphy, *flags, 8908 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, 8909 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) 8910 return -EOPNOTSUPP; 8911 8912 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 8913 int err; 8914 8915 if (!(wiphy->features & randomness_flag) || 8916 (wdev && wdev->connected)) 8917 return -EOPNOTSUPP; 8918 8919 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); 8920 if (err) 8921 return err; 8922 } 8923 8924 return 0; 8925 } 8926 8927 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 8928 { 8929 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8930 struct wireless_dev *wdev = info->user_ptr[1]; 8931 struct cfg80211_scan_request *request; 8932 struct nlattr *scan_freqs = NULL; 8933 bool scan_freqs_khz = false; 8934 struct nlattr *attr; 8935 struct wiphy *wiphy; 8936 int err, tmp, n_ssids = 0, n_channels, i; 8937 size_t ie_len; 8938 8939 wiphy = &rdev->wiphy; 8940 8941 if (wdev->iftype == NL80211_IFTYPE_NAN) 8942 return -EOPNOTSUPP; 8943 8944 if (!rdev->ops->scan) 8945 return -EOPNOTSUPP; 8946 8947 if (rdev->scan_req || rdev->scan_msg) 8948 return -EBUSY; 8949 8950 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { 8951 if (!wiphy_ext_feature_isset(wiphy, 8952 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) 8953 return -EOPNOTSUPP; 8954 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; 8955 scan_freqs_khz = true; 8956 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) 8957 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; 8958 8959 if (scan_freqs) { 8960 n_channels = validate_scan_freqs(scan_freqs); 8961 if (!n_channels) 8962 return -EINVAL; 8963 } else { 8964 n_channels = ieee80211_get_num_supported_channels(wiphy); 8965 } 8966 8967 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 8968 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 8969 n_ssids++; 8970 8971 if (n_ssids > wiphy->max_scan_ssids) 8972 return -EINVAL; 8973 8974 if (info->attrs[NL80211_ATTR_IE]) 8975 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 8976 else 8977 ie_len = 0; 8978 8979 if (ie_len > wiphy->max_scan_ie_len) 8980 return -EINVAL; 8981 8982 request = kzalloc(sizeof(*request) 8983 + sizeof(*request->ssids) * n_ssids 8984 + sizeof(*request->channels) * n_channels 8985 + ie_len, GFP_KERNEL); 8986 if (!request) 8987 return -ENOMEM; 8988 8989 if (n_ssids) 8990 request->ssids = (void *)&request->channels[n_channels]; 8991 request->n_ssids = n_ssids; 8992 if (ie_len) { 8993 if (n_ssids) 8994 request->ie = (void *)(request->ssids + n_ssids); 8995 else 8996 request->ie = (void *)(request->channels + n_channels); 8997 } 8998 8999 i = 0; 9000 if (scan_freqs) { 9001 /* user specified, bail out if channel not found */ 9002 nla_for_each_nested(attr, scan_freqs, tmp) { 9003 struct ieee80211_channel *chan; 9004 int freq = nla_get_u32(attr); 9005 9006 if (!scan_freqs_khz) 9007 freq = MHZ_TO_KHZ(freq); 9008 9009 chan = ieee80211_get_channel_khz(wiphy, freq); 9010 if (!chan) { 9011 err = -EINVAL; 9012 goto out_free; 9013 } 9014 9015 /* ignore disabled channels */ 9016 if (chan->flags & IEEE80211_CHAN_DISABLED) 9017 continue; 9018 9019 request->channels[i] = chan; 9020 i++; 9021 } 9022 } else { 9023 enum nl80211_band band; 9024 9025 /* all channels */ 9026 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9027 int j; 9028 9029 if (!wiphy->bands[band]) 9030 continue; 9031 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 9032 struct ieee80211_channel *chan; 9033 9034 chan = &wiphy->bands[band]->channels[j]; 9035 9036 if (chan->flags & IEEE80211_CHAN_DISABLED) 9037 continue; 9038 9039 request->channels[i] = chan; 9040 i++; 9041 } 9042 } 9043 } 9044 9045 if (!i) { 9046 err = -EINVAL; 9047 goto out_free; 9048 } 9049 9050 request->n_channels = i; 9051 9052 wdev_lock(wdev); 9053 for (i = 0; i < request->n_channels; i++) { 9054 struct ieee80211_channel *chan = request->channels[i]; 9055 9056 /* if we can go off-channel to the target channel we're good */ 9057 if (cfg80211_off_channel_oper_allowed(wdev, chan)) 9058 continue; 9059 9060 if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) { 9061 wdev_unlock(wdev); 9062 err = -EBUSY; 9063 goto out_free; 9064 } 9065 } 9066 wdev_unlock(wdev); 9067 9068 i = 0; 9069 if (n_ssids) { 9070 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 9071 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 9072 err = -EINVAL; 9073 goto out_free; 9074 } 9075 request->ssids[i].ssid_len = nla_len(attr); 9076 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); 9077 i++; 9078 } 9079 } 9080 9081 if (info->attrs[NL80211_ATTR_IE]) { 9082 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9083 memcpy((void *)request->ie, 9084 nla_data(info->attrs[NL80211_ATTR_IE]), 9085 request->ie_len); 9086 } 9087 9088 for (i = 0; i < NUM_NL80211_BANDS; i++) 9089 if (wiphy->bands[i]) 9090 request->rates[i] = 9091 (1 << wiphy->bands[i]->n_bitrates) - 1; 9092 9093 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { 9094 nla_for_each_nested(attr, 9095 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], 9096 tmp) { 9097 enum nl80211_band band = nla_type(attr); 9098 9099 if (band < 0 || band >= NUM_NL80211_BANDS) { 9100 err = -EINVAL; 9101 goto out_free; 9102 } 9103 9104 if (!wiphy->bands[band]) 9105 continue; 9106 9107 err = ieee80211_get_ratemask(wiphy->bands[band], 9108 nla_data(attr), 9109 nla_len(attr), 9110 &request->rates[band]); 9111 if (err) 9112 goto out_free; 9113 } 9114 } 9115 9116 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { 9117 request->duration = 9118 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); 9119 request->duration_mandatory = 9120 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); 9121 } 9122 9123 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, 9124 false); 9125 if (err) 9126 goto out_free; 9127 9128 request->no_cck = 9129 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 9130 9131 /* Initial implementation used NL80211_ATTR_MAC to set the specific 9132 * BSSID to scan for. This was problematic because that same attribute 9133 * was already used for another purpose (local random MAC address). The 9134 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards 9135 * compatibility with older userspace components, also use the 9136 * NL80211_ATTR_MAC value here if it can be determined to be used for 9137 * the specific BSSID use case instead of the random MAC address 9138 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). 9139 */ 9140 if (info->attrs[NL80211_ATTR_BSSID]) 9141 memcpy(request->bssid, 9142 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); 9143 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && 9144 info->attrs[NL80211_ATTR_MAC]) 9145 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), 9146 ETH_ALEN); 9147 else 9148 eth_broadcast_addr(request->bssid); 9149 9150 request->wdev = wdev; 9151 request->wiphy = &rdev->wiphy; 9152 request->scan_start = jiffies; 9153 9154 rdev->scan_req = request; 9155 err = cfg80211_scan(rdev); 9156 9157 if (err) 9158 goto out_free; 9159 9160 nl80211_send_scan_start(rdev, wdev); 9161 dev_hold(wdev->netdev); 9162 9163 return 0; 9164 9165 out_free: 9166 rdev->scan_req = NULL; 9167 kfree(request); 9168 9169 return err; 9170 } 9171 9172 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) 9173 { 9174 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9175 struct wireless_dev *wdev = info->user_ptr[1]; 9176 9177 if (!rdev->ops->abort_scan) 9178 return -EOPNOTSUPP; 9179 9180 if (rdev->scan_msg) 9181 return 0; 9182 9183 if (!rdev->scan_req) 9184 return -ENOENT; 9185 9186 rdev_abort_scan(rdev, wdev); 9187 return 0; 9188 } 9189 9190 static int 9191 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, 9192 struct cfg80211_sched_scan_request *request, 9193 struct nlattr **attrs) 9194 { 9195 int tmp, err, i = 0; 9196 struct nlattr *attr; 9197 9198 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 9199 u32 interval; 9200 9201 /* 9202 * If scan plans are not specified, 9203 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this 9204 * case one scan plan will be set with the specified scan 9205 * interval and infinite number of iterations. 9206 */ 9207 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); 9208 if (!interval) 9209 return -EINVAL; 9210 9211 request->scan_plans[0].interval = 9212 DIV_ROUND_UP(interval, MSEC_PER_SEC); 9213 if (!request->scan_plans[0].interval) 9214 return -EINVAL; 9215 9216 if (request->scan_plans[0].interval > 9217 wiphy->max_sched_scan_plan_interval) 9218 request->scan_plans[0].interval = 9219 wiphy->max_sched_scan_plan_interval; 9220 9221 return 0; 9222 } 9223 9224 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { 9225 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; 9226 9227 if (WARN_ON(i >= n_plans)) 9228 return -EINVAL; 9229 9230 err = nla_parse_nested_deprecated(plan, 9231 NL80211_SCHED_SCAN_PLAN_MAX, 9232 attr, nl80211_plan_policy, 9233 NULL); 9234 if (err) 9235 return err; 9236 9237 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) 9238 return -EINVAL; 9239 9240 request->scan_plans[i].interval = 9241 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); 9242 if (!request->scan_plans[i].interval || 9243 request->scan_plans[i].interval > 9244 wiphy->max_sched_scan_plan_interval) 9245 return -EINVAL; 9246 9247 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { 9248 request->scan_plans[i].iterations = 9249 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); 9250 if (!request->scan_plans[i].iterations || 9251 (request->scan_plans[i].iterations > 9252 wiphy->max_sched_scan_plan_iterations)) 9253 return -EINVAL; 9254 } else if (i < n_plans - 1) { 9255 /* 9256 * All scan plans but the last one must specify 9257 * a finite number of iterations 9258 */ 9259 return -EINVAL; 9260 } 9261 9262 i++; 9263 } 9264 9265 /* 9266 * The last scan plan must not specify the number of 9267 * iterations, it is supposed to run infinitely 9268 */ 9269 if (request->scan_plans[n_plans - 1].iterations) 9270 return -EINVAL; 9271 9272 return 0; 9273 } 9274 9275 static int 9276 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, 9277 struct cfg80211_match_set *match_sets, 9278 struct nlattr *tb_band_rssi, 9279 s32 rssi_thold) 9280 { 9281 struct nlattr *attr; 9282 int i, tmp, ret = 0; 9283 9284 if (!wiphy_ext_feature_isset(wiphy, 9285 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { 9286 if (tb_band_rssi) 9287 ret = -EOPNOTSUPP; 9288 else 9289 for (i = 0; i < NUM_NL80211_BANDS; i++) 9290 match_sets->per_band_rssi_thold[i] = 9291 NL80211_SCAN_RSSI_THOLD_OFF; 9292 return ret; 9293 } 9294 9295 for (i = 0; i < NUM_NL80211_BANDS; i++) 9296 match_sets->per_band_rssi_thold[i] = rssi_thold; 9297 9298 nla_for_each_nested(attr, tb_band_rssi, tmp) { 9299 enum nl80211_band band = nla_type(attr); 9300 9301 if (band < 0 || band >= NUM_NL80211_BANDS) 9302 return -EINVAL; 9303 9304 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); 9305 } 9306 9307 return 0; 9308 } 9309 9310 static struct cfg80211_sched_scan_request * 9311 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 9312 struct nlattr **attrs, int max_match_sets) 9313 { 9314 struct cfg80211_sched_scan_request *request; 9315 struct nlattr *attr; 9316 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; 9317 enum nl80211_band band; 9318 size_t ie_len; 9319 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; 9320 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; 9321 9322 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 9323 n_channels = validate_scan_freqs( 9324 attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 9325 if (!n_channels) 9326 return ERR_PTR(-EINVAL); 9327 } else { 9328 n_channels = ieee80211_get_num_supported_channels(wiphy); 9329 } 9330 9331 if (attrs[NL80211_ATTR_SCAN_SSIDS]) 9332 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 9333 tmp) 9334 n_ssids++; 9335 9336 if (n_ssids > wiphy->max_sched_scan_ssids) 9337 return ERR_PTR(-EINVAL); 9338 9339 /* 9340 * First, count the number of 'real' matchsets. Due to an issue with 9341 * the old implementation, matchsets containing only the RSSI attribute 9342 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' 9343 * RSSI for all matchsets, rather than their own matchset for reporting 9344 * all APs with a strong RSSI. This is needed to be compatible with 9345 * older userspace that treated a matchset with only the RSSI as the 9346 * global RSSI for all other matchsets - if there are other matchsets. 9347 */ 9348 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 9349 nla_for_each_nested(attr, 9350 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 9351 tmp) { 9352 struct nlattr *rssi; 9353 9354 err = nla_parse_nested_deprecated(tb, 9355 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 9356 attr, 9357 nl80211_match_policy, 9358 NULL); 9359 if (err) 9360 return ERR_PTR(err); 9361 9362 /* SSID and BSSID are mutually exclusive */ 9363 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && 9364 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) 9365 return ERR_PTR(-EINVAL); 9366 9367 /* add other standalone attributes here */ 9368 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || 9369 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { 9370 n_match_sets++; 9371 continue; 9372 } 9373 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 9374 if (rssi) 9375 default_match_rssi = nla_get_s32(rssi); 9376 } 9377 } 9378 9379 /* However, if there's no other matchset, add the RSSI one */ 9380 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) 9381 n_match_sets = 1; 9382 9383 if (n_match_sets > max_match_sets) 9384 return ERR_PTR(-EINVAL); 9385 9386 if (attrs[NL80211_ATTR_IE]) 9387 ie_len = nla_len(attrs[NL80211_ATTR_IE]); 9388 else 9389 ie_len = 0; 9390 9391 if (ie_len > wiphy->max_sched_scan_ie_len) 9392 return ERR_PTR(-EINVAL); 9393 9394 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 9395 /* 9396 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since 9397 * each scan plan already specifies its own interval 9398 */ 9399 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 9400 return ERR_PTR(-EINVAL); 9401 9402 nla_for_each_nested(attr, 9403 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) 9404 n_plans++; 9405 } else { 9406 /* 9407 * The scan interval attribute is kept for backward 9408 * compatibility. If no scan plans are specified and sched scan 9409 * interval is specified, one scan plan will be set with this 9410 * scan interval and infinite number of iterations. 9411 */ 9412 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 9413 return ERR_PTR(-EINVAL); 9414 9415 n_plans = 1; 9416 } 9417 9418 if (!n_plans || n_plans > wiphy->max_sched_scan_plans) 9419 return ERR_PTR(-EINVAL); 9420 9421 if (!wiphy_ext_feature_isset( 9422 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && 9423 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || 9424 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) 9425 return ERR_PTR(-EINVAL); 9426 9427 request = kzalloc(sizeof(*request) 9428 + sizeof(*request->ssids) * n_ssids 9429 + sizeof(*request->match_sets) * n_match_sets 9430 + sizeof(*request->scan_plans) * n_plans 9431 + sizeof(*request->channels) * n_channels 9432 + ie_len, GFP_KERNEL); 9433 if (!request) 9434 return ERR_PTR(-ENOMEM); 9435 9436 if (n_ssids) 9437 request->ssids = (void *)&request->channels[n_channels]; 9438 request->n_ssids = n_ssids; 9439 if (ie_len) { 9440 if (n_ssids) 9441 request->ie = (void *)(request->ssids + n_ssids); 9442 else 9443 request->ie = (void *)(request->channels + n_channels); 9444 } 9445 9446 if (n_match_sets) { 9447 if (request->ie) 9448 request->match_sets = (void *)(request->ie + ie_len); 9449 else if (n_ssids) 9450 request->match_sets = 9451 (void *)(request->ssids + n_ssids); 9452 else 9453 request->match_sets = 9454 (void *)(request->channels + n_channels); 9455 } 9456 request->n_match_sets = n_match_sets; 9457 9458 if (n_match_sets) 9459 request->scan_plans = (void *)(request->match_sets + 9460 n_match_sets); 9461 else if (request->ie) 9462 request->scan_plans = (void *)(request->ie + ie_len); 9463 else if (n_ssids) 9464 request->scan_plans = (void *)(request->ssids + n_ssids); 9465 else 9466 request->scan_plans = (void *)(request->channels + n_channels); 9467 9468 request->n_scan_plans = n_plans; 9469 9470 i = 0; 9471 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 9472 /* user specified, bail out if channel not found */ 9473 nla_for_each_nested(attr, 9474 attrs[NL80211_ATTR_SCAN_FREQUENCIES], 9475 tmp) { 9476 struct ieee80211_channel *chan; 9477 9478 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 9479 9480 if (!chan) { 9481 err = -EINVAL; 9482 goto out_free; 9483 } 9484 9485 /* ignore disabled channels */ 9486 if (chan->flags & IEEE80211_CHAN_DISABLED) 9487 continue; 9488 9489 request->channels[i] = chan; 9490 i++; 9491 } 9492 } else { 9493 /* all channels */ 9494 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9495 int j; 9496 9497 if (!wiphy->bands[band]) 9498 continue; 9499 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 9500 struct ieee80211_channel *chan; 9501 9502 chan = &wiphy->bands[band]->channels[j]; 9503 9504 if (chan->flags & IEEE80211_CHAN_DISABLED) 9505 continue; 9506 9507 request->channels[i] = chan; 9508 i++; 9509 } 9510 } 9511 } 9512 9513 if (!i) { 9514 err = -EINVAL; 9515 goto out_free; 9516 } 9517 9518 request->n_channels = i; 9519 9520 i = 0; 9521 if (n_ssids) { 9522 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 9523 tmp) { 9524 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 9525 err = -EINVAL; 9526 goto out_free; 9527 } 9528 request->ssids[i].ssid_len = nla_len(attr); 9529 memcpy(request->ssids[i].ssid, nla_data(attr), 9530 nla_len(attr)); 9531 i++; 9532 } 9533 } 9534 9535 i = 0; 9536 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 9537 nla_for_each_nested(attr, 9538 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 9539 tmp) { 9540 struct nlattr *ssid, *bssid, *rssi; 9541 9542 err = nla_parse_nested_deprecated(tb, 9543 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 9544 attr, 9545 nl80211_match_policy, 9546 NULL); 9547 if (err) 9548 goto out_free; 9549 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 9550 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 9551 9552 if (!ssid && !bssid) { 9553 i++; 9554 continue; 9555 } 9556 9557 if (WARN_ON(i >= n_match_sets)) { 9558 /* this indicates a programming error, 9559 * the loop above should have verified 9560 * things properly 9561 */ 9562 err = -EINVAL; 9563 goto out_free; 9564 } 9565 9566 if (ssid) { 9567 memcpy(request->match_sets[i].ssid.ssid, 9568 nla_data(ssid), nla_len(ssid)); 9569 request->match_sets[i].ssid.ssid_len = 9570 nla_len(ssid); 9571 } 9572 if (bssid) 9573 memcpy(request->match_sets[i].bssid, 9574 nla_data(bssid), ETH_ALEN); 9575 9576 /* special attribute - old implementation w/a */ 9577 request->match_sets[i].rssi_thold = default_match_rssi; 9578 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 9579 if (rssi) 9580 request->match_sets[i].rssi_thold = 9581 nla_get_s32(rssi); 9582 9583 /* Parse per band RSSI attribute */ 9584 err = nl80211_parse_sched_scan_per_band_rssi(wiphy, 9585 &request->match_sets[i], 9586 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], 9587 request->match_sets[i].rssi_thold); 9588 if (err) 9589 goto out_free; 9590 9591 i++; 9592 } 9593 9594 /* there was no other matchset, so the RSSI one is alone */ 9595 if (i == 0 && n_match_sets) 9596 request->match_sets[0].rssi_thold = default_match_rssi; 9597 9598 request->min_rssi_thold = INT_MAX; 9599 for (i = 0; i < n_match_sets; i++) 9600 request->min_rssi_thold = 9601 min(request->match_sets[i].rssi_thold, 9602 request->min_rssi_thold); 9603 } else { 9604 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; 9605 } 9606 9607 if (ie_len) { 9608 request->ie_len = ie_len; 9609 memcpy((void *)request->ie, 9610 nla_data(attrs[NL80211_ATTR_IE]), 9611 request->ie_len); 9612 } 9613 9614 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); 9615 if (err) 9616 goto out_free; 9617 9618 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) 9619 request->delay = 9620 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); 9621 9622 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { 9623 request->relative_rssi = nla_get_s8( 9624 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); 9625 request->relative_rssi_set = true; 9626 } 9627 9628 if (request->relative_rssi_set && 9629 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { 9630 struct nl80211_bss_select_rssi_adjust *rssi_adjust; 9631 9632 rssi_adjust = nla_data( 9633 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); 9634 request->rssi_adjust.band = rssi_adjust->band; 9635 request->rssi_adjust.delta = rssi_adjust->delta; 9636 if (!is_band_valid(wiphy, request->rssi_adjust.band)) { 9637 err = -EINVAL; 9638 goto out_free; 9639 } 9640 } 9641 9642 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); 9643 if (err) 9644 goto out_free; 9645 9646 request->scan_start = jiffies; 9647 9648 return request; 9649 9650 out_free: 9651 kfree(request); 9652 return ERR_PTR(err); 9653 } 9654 9655 static int nl80211_start_sched_scan(struct sk_buff *skb, 9656 struct genl_info *info) 9657 { 9658 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9659 struct net_device *dev = info->user_ptr[1]; 9660 struct wireless_dev *wdev = dev->ieee80211_ptr; 9661 struct cfg80211_sched_scan_request *sched_scan_req; 9662 bool want_multi; 9663 int err; 9664 9665 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) 9666 return -EOPNOTSUPP; 9667 9668 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; 9669 err = cfg80211_sched_scan_req_possible(rdev, want_multi); 9670 if (err) 9671 return err; 9672 9673 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, 9674 info->attrs, 9675 rdev->wiphy.max_match_sets); 9676 9677 err = PTR_ERR_OR_ZERO(sched_scan_req); 9678 if (err) 9679 goto out_err; 9680 9681 /* leave request id zero for legacy request 9682 * or if driver does not support multi-scheduled scan 9683 */ 9684 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) 9685 sched_scan_req->reqid = cfg80211_assign_cookie(rdev); 9686 9687 err = rdev_sched_scan_start(rdev, dev, sched_scan_req); 9688 if (err) 9689 goto out_free; 9690 9691 sched_scan_req->dev = dev; 9692 sched_scan_req->wiphy = &rdev->wiphy; 9693 9694 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 9695 sched_scan_req->owner_nlportid = info->snd_portid; 9696 9697 cfg80211_add_sched_scan_req(rdev, sched_scan_req); 9698 9699 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); 9700 return 0; 9701 9702 out_free: 9703 kfree(sched_scan_req); 9704 out_err: 9705 return err; 9706 } 9707 9708 static int nl80211_stop_sched_scan(struct sk_buff *skb, 9709 struct genl_info *info) 9710 { 9711 struct cfg80211_sched_scan_request *req; 9712 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9713 u64 cookie; 9714 9715 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) 9716 return -EOPNOTSUPP; 9717 9718 if (info->attrs[NL80211_ATTR_COOKIE]) { 9719 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 9720 return __cfg80211_stop_sched_scan(rdev, cookie, false); 9721 } 9722 9723 req = list_first_or_null_rcu(&rdev->sched_scan_req_list, 9724 struct cfg80211_sched_scan_request, 9725 list); 9726 if (!req || req->reqid || 9727 (req->owner_nlportid && 9728 req->owner_nlportid != info->snd_portid)) 9729 return -ENOENT; 9730 9731 return cfg80211_stop_sched_scan_req(rdev, req, false); 9732 } 9733 9734 static int nl80211_start_radar_detection(struct sk_buff *skb, 9735 struct genl_info *info) 9736 { 9737 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9738 struct net_device *dev = info->user_ptr[1]; 9739 struct wireless_dev *wdev = dev->ieee80211_ptr; 9740 struct wiphy *wiphy = wdev->wiphy; 9741 struct cfg80211_chan_def chandef; 9742 enum nl80211_dfs_regions dfs_region; 9743 unsigned int cac_time_ms; 9744 int err = -EINVAL; 9745 9746 flush_delayed_work(&rdev->dfs_update_channels_wk); 9747 9748 wiphy_lock(wiphy); 9749 9750 dfs_region = reg_get_dfs_region(wiphy); 9751 if (dfs_region == NL80211_DFS_UNSET) 9752 goto unlock; 9753 9754 err = nl80211_parse_chandef(rdev, info, &chandef); 9755 if (err) 9756 goto unlock; 9757 9758 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 9759 if (err < 0) 9760 goto unlock; 9761 9762 if (err == 0) { 9763 err = -EINVAL; 9764 goto unlock; 9765 } 9766 9767 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) { 9768 err = -EINVAL; 9769 goto unlock; 9770 } 9771 9772 if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) { 9773 err = cfg80211_start_background_radar_detection(rdev, wdev, 9774 &chandef); 9775 goto unlock; 9776 } 9777 9778 if (netif_carrier_ok(dev)) { 9779 err = -EBUSY; 9780 goto unlock; 9781 } 9782 9783 if (wdev->cac_started) { 9784 err = -EBUSY; 9785 goto unlock; 9786 } 9787 9788 /* CAC start is offloaded to HW and can't be started manually */ 9789 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) { 9790 err = -EOPNOTSUPP; 9791 goto unlock; 9792 } 9793 9794 if (!rdev->ops->start_radar_detection) { 9795 err = -EOPNOTSUPP; 9796 goto unlock; 9797 } 9798 9799 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 9800 if (WARN_ON(!cac_time_ms)) 9801 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; 9802 9803 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); 9804 if (!err) { 9805 wdev->links[0].ap.chandef = chandef; 9806 wdev->cac_started = true; 9807 wdev->cac_start_time = jiffies; 9808 wdev->cac_time_ms = cac_time_ms; 9809 } 9810 unlock: 9811 wiphy_unlock(wiphy); 9812 9813 return err; 9814 } 9815 9816 static int nl80211_notify_radar_detection(struct sk_buff *skb, 9817 struct genl_info *info) 9818 { 9819 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9820 struct net_device *dev = info->user_ptr[1]; 9821 struct wireless_dev *wdev = dev->ieee80211_ptr; 9822 struct wiphy *wiphy = wdev->wiphy; 9823 struct cfg80211_chan_def chandef; 9824 enum nl80211_dfs_regions dfs_region; 9825 int err; 9826 9827 dfs_region = reg_get_dfs_region(wiphy); 9828 if (dfs_region == NL80211_DFS_UNSET) { 9829 GENL_SET_ERR_MSG(info, 9830 "DFS Region is not set. Unexpected Radar indication"); 9831 return -EINVAL; 9832 } 9833 9834 err = nl80211_parse_chandef(rdev, info, &chandef); 9835 if (err) { 9836 GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); 9837 return err; 9838 } 9839 9840 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 9841 if (err < 0) { 9842 GENL_SET_ERR_MSG(info, "chandef is invalid"); 9843 return err; 9844 } 9845 9846 if (err == 0) { 9847 GENL_SET_ERR_MSG(info, 9848 "Unexpected Radar indication for chandef/iftype"); 9849 return -EINVAL; 9850 } 9851 9852 /* Do not process this notification if radar is already detected 9853 * by kernel on this channel, and return success. 9854 */ 9855 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) 9856 return 0; 9857 9858 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); 9859 9860 cfg80211_sched_dfs_chan_update(rdev); 9861 9862 rdev->radar_chandef = chandef; 9863 9864 /* Propagate this notification to other radios as well */ 9865 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 9866 9867 return 0; 9868 } 9869 9870 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) 9871 { 9872 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9873 unsigned int link_id = nl80211_link_id(info->attrs); 9874 struct net_device *dev = info->user_ptr[1]; 9875 struct wireless_dev *wdev = dev->ieee80211_ptr; 9876 struct cfg80211_csa_settings params; 9877 struct nlattr **csa_attrs = NULL; 9878 int err; 9879 bool need_new_beacon = false; 9880 bool need_handle_dfs_flag = true; 9881 int len, i; 9882 u32 cs_count; 9883 9884 if (!rdev->ops->channel_switch || 9885 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 9886 return -EOPNOTSUPP; 9887 9888 switch (dev->ieee80211_ptr->iftype) { 9889 case NL80211_IFTYPE_AP: 9890 case NL80211_IFTYPE_P2P_GO: 9891 need_new_beacon = true; 9892 /* For all modes except AP the handle_dfs flag needs to be 9893 * supplied to tell the kernel that userspace will handle radar 9894 * events when they happen. Otherwise a switch to a channel 9895 * requiring DFS will be rejected. 9896 */ 9897 need_handle_dfs_flag = false; 9898 9899 /* useless if AP is not running */ 9900 if (!wdev->links[link_id].ap.beacon_interval) 9901 return -ENOTCONN; 9902 break; 9903 case NL80211_IFTYPE_ADHOC: 9904 if (!wdev->u.ibss.ssid_len) 9905 return -ENOTCONN; 9906 break; 9907 case NL80211_IFTYPE_MESH_POINT: 9908 if (!wdev->u.mesh.id_len) 9909 return -ENOTCONN; 9910 break; 9911 default: 9912 return -EOPNOTSUPP; 9913 } 9914 9915 memset(¶ms, 0, sizeof(params)); 9916 params.beacon_csa.ftm_responder = -1; 9917 9918 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 9919 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) 9920 return -EINVAL; 9921 9922 /* only important for AP, IBSS and mesh create IEs internally */ 9923 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) 9924 return -EINVAL; 9925 9926 /* Even though the attribute is u32, the specification says 9927 * u8, so let's make sure we don't overflow. 9928 */ 9929 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); 9930 if (cs_count > 255) 9931 return -EINVAL; 9932 9933 params.count = cs_count; 9934 9935 if (!need_new_beacon) 9936 goto skip_beacons; 9937 9938 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); 9939 if (err) 9940 goto free; 9941 9942 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs), 9943 GFP_KERNEL); 9944 if (!csa_attrs) { 9945 err = -ENOMEM; 9946 goto free; 9947 } 9948 9949 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, 9950 info->attrs[NL80211_ATTR_CSA_IES], 9951 nl80211_policy, info->extack); 9952 if (err) 9953 goto free; 9954 9955 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); 9956 if (err) 9957 goto free; 9958 9959 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 9960 err = -EINVAL; 9961 goto free; 9962 } 9963 9964 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 9965 if (!len || (len % sizeof(u16))) { 9966 err = -EINVAL; 9967 goto free; 9968 } 9969 9970 params.n_counter_offsets_beacon = len / sizeof(u16); 9971 if (rdev->wiphy.max_num_csa_counters && 9972 (params.n_counter_offsets_beacon > 9973 rdev->wiphy.max_num_csa_counters)) { 9974 err = -EINVAL; 9975 goto free; 9976 } 9977 9978 params.counter_offsets_beacon = 9979 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 9980 9981 /* sanity checks - counters should fit and be the same */ 9982 for (i = 0; i < params.n_counter_offsets_beacon; i++) { 9983 u16 offset = params.counter_offsets_beacon[i]; 9984 9985 if (offset >= params.beacon_csa.tail_len) { 9986 err = -EINVAL; 9987 goto free; 9988 } 9989 9990 if (params.beacon_csa.tail[offset] != params.count) { 9991 err = -EINVAL; 9992 goto free; 9993 } 9994 } 9995 9996 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 9997 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 9998 if (!len || (len % sizeof(u16))) { 9999 err = -EINVAL; 10000 goto free; 10001 } 10002 10003 params.n_counter_offsets_presp = len / sizeof(u16); 10004 if (rdev->wiphy.max_num_csa_counters && 10005 (params.n_counter_offsets_presp > 10006 rdev->wiphy.max_num_csa_counters)) { 10007 err = -EINVAL; 10008 goto free; 10009 } 10010 10011 params.counter_offsets_presp = 10012 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 10013 10014 /* sanity checks - counters should fit and be the same */ 10015 for (i = 0; i < params.n_counter_offsets_presp; i++) { 10016 u16 offset = params.counter_offsets_presp[i]; 10017 10018 if (offset >= params.beacon_csa.probe_resp_len) { 10019 err = -EINVAL; 10020 goto free; 10021 } 10022 10023 if (params.beacon_csa.probe_resp[offset] != 10024 params.count) { 10025 err = -EINVAL; 10026 goto free; 10027 } 10028 } 10029 } 10030 10031 skip_beacons: 10032 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 10033 if (err) 10034 goto free; 10035 10036 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 10037 wdev->iftype)) { 10038 err = -EINVAL; 10039 goto free; 10040 } 10041 10042 err = cfg80211_chandef_dfs_required(wdev->wiphy, 10043 ¶ms.chandef, 10044 wdev->iftype); 10045 if (err < 0) 10046 goto free; 10047 10048 if (err > 0) { 10049 params.radar_required = true; 10050 if (need_handle_dfs_flag && 10051 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { 10052 err = -EINVAL; 10053 goto free; 10054 } 10055 } 10056 10057 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 10058 params.block_tx = true; 10059 10060 wdev_lock(wdev); 10061 err = rdev_channel_switch(rdev, dev, ¶ms); 10062 wdev_unlock(wdev); 10063 10064 free: 10065 kfree(params.beacon_after.mbssid_ies); 10066 kfree(params.beacon_csa.mbssid_ies); 10067 kfree(csa_attrs); 10068 return err; 10069 } 10070 10071 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, 10072 u32 seq, int flags, 10073 struct cfg80211_registered_device *rdev, 10074 struct wireless_dev *wdev, 10075 struct cfg80211_internal_bss *intbss) 10076 { 10077 struct cfg80211_bss *res = &intbss->pub; 10078 const struct cfg80211_bss_ies *ies; 10079 unsigned int link_id; 10080 void *hdr; 10081 struct nlattr *bss; 10082 10083 ASSERT_WDEV_LOCK(wdev); 10084 10085 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 10086 NL80211_CMD_NEW_SCAN_RESULTS); 10087 if (!hdr) 10088 return -1; 10089 10090 genl_dump_check_consistent(cb, hdr); 10091 10092 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) 10093 goto nla_put_failure; 10094 if (wdev->netdev && 10095 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) 10096 goto nla_put_failure; 10097 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 10098 NL80211_ATTR_PAD)) 10099 goto nla_put_failure; 10100 10101 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); 10102 if (!bss) 10103 goto nla_put_failure; 10104 if ((!is_zero_ether_addr(res->bssid) && 10105 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) 10106 goto nla_put_failure; 10107 10108 rcu_read_lock(); 10109 /* indicate whether we have probe response data or not */ 10110 if (rcu_access_pointer(res->proberesp_ies) && 10111 nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) 10112 goto fail_unlock_rcu; 10113 10114 /* this pointer prefers to be pointed to probe response data 10115 * but is always valid 10116 */ 10117 ies = rcu_dereference(res->ies); 10118 if (ies) { 10119 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, 10120 NL80211_BSS_PAD)) 10121 goto fail_unlock_rcu; 10122 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, 10123 ies->len, ies->data)) 10124 goto fail_unlock_rcu; 10125 } 10126 10127 /* and this pointer is always (unless driver didn't know) beacon data */ 10128 ies = rcu_dereference(res->beacon_ies); 10129 if (ies && ies->from_beacon) { 10130 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, 10131 NL80211_BSS_PAD)) 10132 goto fail_unlock_rcu; 10133 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, 10134 ies->len, ies->data)) 10135 goto fail_unlock_rcu; 10136 } 10137 rcu_read_unlock(); 10138 10139 if (res->beacon_interval && 10140 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) 10141 goto nla_put_failure; 10142 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || 10143 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || 10144 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, 10145 res->channel->freq_offset) || 10146 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || 10147 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, 10148 jiffies_to_msecs(jiffies - intbss->ts))) 10149 goto nla_put_failure; 10150 10151 if (intbss->parent_tsf && 10152 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, 10153 intbss->parent_tsf, NL80211_BSS_PAD) || 10154 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, 10155 intbss->parent_bssid))) 10156 goto nla_put_failure; 10157 10158 if (intbss->ts_boottime && 10159 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, 10160 intbss->ts_boottime, NL80211_BSS_PAD)) 10161 goto nla_put_failure; 10162 10163 if (!nl80211_put_signal(msg, intbss->pub.chains, 10164 intbss->pub.chain_signal, 10165 NL80211_BSS_CHAIN_SIGNAL)) 10166 goto nla_put_failure; 10167 10168 switch (rdev->wiphy.signal_type) { 10169 case CFG80211_SIGNAL_TYPE_MBM: 10170 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) 10171 goto nla_put_failure; 10172 break; 10173 case CFG80211_SIGNAL_TYPE_UNSPEC: 10174 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) 10175 goto nla_put_failure; 10176 break; 10177 default: 10178 break; 10179 } 10180 10181 switch (wdev->iftype) { 10182 case NL80211_IFTYPE_P2P_CLIENT: 10183 case NL80211_IFTYPE_STATION: 10184 for_each_valid_link(wdev, link_id) { 10185 if (intbss == wdev->links[link_id].client.current_bss && 10186 (nla_put_u32(msg, NL80211_BSS_STATUS, 10187 NL80211_BSS_STATUS_ASSOCIATED) || 10188 (wdev->valid_links && 10189 (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID, 10190 link_id) || 10191 nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN, 10192 wdev->u.client.connected_addr))))) 10193 goto nla_put_failure; 10194 } 10195 break; 10196 case NL80211_IFTYPE_ADHOC: 10197 if (intbss == wdev->u.ibss.current_bss && 10198 nla_put_u32(msg, NL80211_BSS_STATUS, 10199 NL80211_BSS_STATUS_IBSS_JOINED)) 10200 goto nla_put_failure; 10201 break; 10202 default: 10203 break; 10204 } 10205 10206 nla_nest_end(msg, bss); 10207 10208 genlmsg_end(msg, hdr); 10209 return 0; 10210 10211 fail_unlock_rcu: 10212 rcu_read_unlock(); 10213 nla_put_failure: 10214 genlmsg_cancel(msg, hdr); 10215 return -EMSGSIZE; 10216 } 10217 10218 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) 10219 { 10220 struct cfg80211_registered_device *rdev; 10221 struct cfg80211_internal_bss *scan; 10222 struct wireless_dev *wdev; 10223 int start = cb->args[2], idx = 0; 10224 int err; 10225 10226 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 10227 if (err) 10228 return err; 10229 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 10230 __acquire(&rdev->wiphy.mtx); 10231 10232 wdev_lock(wdev); 10233 spin_lock_bh(&rdev->bss_lock); 10234 10235 /* 10236 * dump_scan will be called multiple times to break up the scan results 10237 * into multiple messages. It is unlikely that any more bss-es will be 10238 * expired after the first call, so only call only call this on the 10239 * first dump_scan invocation. 10240 */ 10241 if (start == 0) 10242 cfg80211_bss_expire(rdev); 10243 10244 cb->seq = rdev->bss_generation; 10245 10246 list_for_each_entry(scan, &rdev->bss_list, list) { 10247 if (++idx <= start) 10248 continue; 10249 if (nl80211_send_bss(skb, cb, 10250 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10251 rdev, wdev, scan) < 0) { 10252 idx--; 10253 break; 10254 } 10255 } 10256 10257 spin_unlock_bh(&rdev->bss_lock); 10258 wdev_unlock(wdev); 10259 10260 cb->args[2] = idx; 10261 wiphy_unlock(&rdev->wiphy); 10262 10263 return skb->len; 10264 } 10265 10266 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, 10267 int flags, struct net_device *dev, 10268 bool allow_radio_stats, 10269 struct survey_info *survey) 10270 { 10271 void *hdr; 10272 struct nlattr *infoattr; 10273 10274 /* skip radio stats if userspace didn't request them */ 10275 if (!survey->channel && !allow_radio_stats) 10276 return 0; 10277 10278 hdr = nl80211hdr_put(msg, portid, seq, flags, 10279 NL80211_CMD_NEW_SURVEY_RESULTS); 10280 if (!hdr) 10281 return -ENOMEM; 10282 10283 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 10284 goto nla_put_failure; 10285 10286 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); 10287 if (!infoattr) 10288 goto nla_put_failure; 10289 10290 if (survey->channel && 10291 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, 10292 survey->channel->center_freq)) 10293 goto nla_put_failure; 10294 10295 if (survey->channel && survey->channel->freq_offset && 10296 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, 10297 survey->channel->freq_offset)) 10298 goto nla_put_failure; 10299 10300 if ((survey->filled & SURVEY_INFO_NOISE_DBM) && 10301 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) 10302 goto nla_put_failure; 10303 if ((survey->filled & SURVEY_INFO_IN_USE) && 10304 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) 10305 goto nla_put_failure; 10306 if ((survey->filled & SURVEY_INFO_TIME) && 10307 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, 10308 survey->time, NL80211_SURVEY_INFO_PAD)) 10309 goto nla_put_failure; 10310 if ((survey->filled & SURVEY_INFO_TIME_BUSY) && 10311 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, 10312 survey->time_busy, NL80211_SURVEY_INFO_PAD)) 10313 goto nla_put_failure; 10314 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && 10315 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, 10316 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) 10317 goto nla_put_failure; 10318 if ((survey->filled & SURVEY_INFO_TIME_RX) && 10319 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, 10320 survey->time_rx, NL80211_SURVEY_INFO_PAD)) 10321 goto nla_put_failure; 10322 if ((survey->filled & SURVEY_INFO_TIME_TX) && 10323 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, 10324 survey->time_tx, NL80211_SURVEY_INFO_PAD)) 10325 goto nla_put_failure; 10326 if ((survey->filled & SURVEY_INFO_TIME_SCAN) && 10327 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, 10328 survey->time_scan, NL80211_SURVEY_INFO_PAD)) 10329 goto nla_put_failure; 10330 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && 10331 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, 10332 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) 10333 goto nla_put_failure; 10334 10335 nla_nest_end(msg, infoattr); 10336 10337 genlmsg_end(msg, hdr); 10338 return 0; 10339 10340 nla_put_failure: 10341 genlmsg_cancel(msg, hdr); 10342 return -EMSGSIZE; 10343 } 10344 10345 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) 10346 { 10347 struct nlattr **attrbuf; 10348 struct survey_info survey; 10349 struct cfg80211_registered_device *rdev; 10350 struct wireless_dev *wdev; 10351 int survey_idx = cb->args[2]; 10352 int res; 10353 bool radio_stats; 10354 10355 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 10356 if (!attrbuf) 10357 return -ENOMEM; 10358 10359 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf); 10360 if (res) { 10361 kfree(attrbuf); 10362 return res; 10363 } 10364 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 10365 __acquire(&rdev->wiphy.mtx); 10366 10367 /* prepare_wdev_dump parsed the attributes */ 10368 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; 10369 10370 if (!wdev->netdev) { 10371 res = -EINVAL; 10372 goto out_err; 10373 } 10374 10375 if (!rdev->ops->dump_survey) { 10376 res = -EOPNOTSUPP; 10377 goto out_err; 10378 } 10379 10380 while (1) { 10381 wdev_lock(wdev); 10382 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); 10383 wdev_unlock(wdev); 10384 if (res == -ENOENT) 10385 break; 10386 if (res) 10387 goto out_err; 10388 10389 /* don't send disabled channels, but do send non-channel data */ 10390 if (survey.channel && 10391 survey.channel->flags & IEEE80211_CHAN_DISABLED) { 10392 survey_idx++; 10393 continue; 10394 } 10395 10396 if (nl80211_send_survey(skb, 10397 NETLINK_CB(cb->skb).portid, 10398 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10399 wdev->netdev, radio_stats, &survey) < 0) 10400 goto out; 10401 survey_idx++; 10402 } 10403 10404 out: 10405 cb->args[2] = survey_idx; 10406 res = skb->len; 10407 out_err: 10408 kfree(attrbuf); 10409 wiphy_unlock(&rdev->wiphy); 10410 return res; 10411 } 10412 10413 static bool nl80211_valid_wpa_versions(u32 wpa_versions) 10414 { 10415 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | 10416 NL80211_WPA_VERSION_2 | 10417 NL80211_WPA_VERSION_3)); 10418 } 10419 10420 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 10421 { 10422 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10423 struct net_device *dev = info->user_ptr[1]; 10424 struct ieee80211_channel *chan; 10425 const u8 *bssid, *ssid; 10426 int err, ssid_len; 10427 enum nl80211_auth_type auth_type; 10428 struct key_parse key; 10429 bool local_state_change; 10430 struct cfg80211_auth_request req = {}; 10431 u32 freq; 10432 10433 if (!info->attrs[NL80211_ATTR_MAC]) 10434 return -EINVAL; 10435 10436 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 10437 return -EINVAL; 10438 10439 if (!info->attrs[NL80211_ATTR_SSID]) 10440 return -EINVAL; 10441 10442 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10443 return -EINVAL; 10444 10445 err = nl80211_parse_key(info, &key); 10446 if (err) 10447 return err; 10448 10449 if (key.idx >= 0) { 10450 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) 10451 return -EINVAL; 10452 if (!key.p.key || !key.p.key_len) 10453 return -EINVAL; 10454 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 10455 key.p.key_len != WLAN_KEY_LEN_WEP40) && 10456 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || 10457 key.p.key_len != WLAN_KEY_LEN_WEP104)) 10458 return -EINVAL; 10459 if (key.idx > 3) 10460 return -EINVAL; 10461 } else { 10462 key.p.key_len = 0; 10463 key.p.key = NULL; 10464 } 10465 10466 if (key.idx >= 0) { 10467 int i; 10468 bool ok = false; 10469 10470 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { 10471 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { 10472 ok = true; 10473 break; 10474 } 10475 } 10476 if (!ok) 10477 return -EINVAL; 10478 } 10479 10480 if (!rdev->ops->auth) 10481 return -EOPNOTSUPP; 10482 10483 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10484 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10485 return -EOPNOTSUPP; 10486 10487 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10488 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 10489 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10490 freq += 10491 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10492 10493 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 10494 if (!chan) 10495 return -EINVAL; 10496 10497 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10498 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10499 10500 if (info->attrs[NL80211_ATTR_IE]) { 10501 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10502 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10503 } 10504 10505 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10506 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) 10507 return -EINVAL; 10508 10509 if ((auth_type == NL80211_AUTHTYPE_SAE || 10510 auth_type == NL80211_AUTHTYPE_FILS_SK || 10511 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 10512 auth_type == NL80211_AUTHTYPE_FILS_PK) && 10513 !info->attrs[NL80211_ATTR_AUTH_DATA]) 10514 return -EINVAL; 10515 10516 if (info->attrs[NL80211_ATTR_AUTH_DATA]) { 10517 if (auth_type != NL80211_AUTHTYPE_SAE && 10518 auth_type != NL80211_AUTHTYPE_FILS_SK && 10519 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && 10520 auth_type != NL80211_AUTHTYPE_FILS_PK) 10521 return -EINVAL; 10522 req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); 10523 req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); 10524 } 10525 10526 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 10527 10528 /* 10529 * Since we no longer track auth state, ignore 10530 * requests to only change local state. 10531 */ 10532 if (local_state_change) 10533 return 0; 10534 10535 req.auth_type = auth_type; 10536 req.key = key.p.key; 10537 req.key_len = key.p.key_len; 10538 req.key_idx = key.idx; 10539 req.link_id = nl80211_link_id_or_invalid(info->attrs); 10540 if (req.link_id >= 0) { 10541 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) 10542 return -EINVAL; 10543 if (!info->attrs[NL80211_ATTR_MLD_ADDR]) 10544 return -EINVAL; 10545 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 10546 } 10547 10548 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, 10549 IEEE80211_BSS_TYPE_ESS, 10550 IEEE80211_PRIVACY_ANY); 10551 if (!req.bss) 10552 return -ENOENT; 10553 10554 wdev_lock(dev->ieee80211_ptr); 10555 err = cfg80211_mlme_auth(rdev, dev, &req); 10556 wdev_unlock(dev->ieee80211_ptr); 10557 10558 cfg80211_put_bss(&rdev->wiphy, req.bss); 10559 10560 return err; 10561 } 10562 10563 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, 10564 struct genl_info *info) 10565 { 10566 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10567 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); 10568 return -EINVAL; 10569 } 10570 10571 if (!rdev->ops->tx_control_port || 10572 !wiphy_ext_feature_isset(&rdev->wiphy, 10573 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 10574 return -EOPNOTSUPP; 10575 10576 return 0; 10577 } 10578 10579 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 10580 struct genl_info *info, 10581 struct cfg80211_crypto_settings *settings, 10582 int cipher_limit) 10583 { 10584 memset(settings, 0, sizeof(*settings)); 10585 10586 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 10587 10588 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 10589 u16 proto; 10590 10591 proto = nla_get_u16( 10592 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 10593 settings->control_port_ethertype = cpu_to_be16(proto); 10594 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 10595 proto != ETH_P_PAE) 10596 return -EINVAL; 10597 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) 10598 settings->control_port_no_encrypt = true; 10599 } else 10600 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); 10601 10602 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 10603 int r = validate_pae_over_nl80211(rdev, info); 10604 10605 if (r < 0) 10606 return r; 10607 10608 settings->control_port_over_nl80211 = true; 10609 10610 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) 10611 settings->control_port_no_preauth = true; 10612 } 10613 10614 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 10615 void *data; 10616 int len, i; 10617 10618 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 10619 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 10620 settings->n_ciphers_pairwise = len / sizeof(u32); 10621 10622 if (len % sizeof(u32)) 10623 return -EINVAL; 10624 10625 if (settings->n_ciphers_pairwise > cipher_limit) 10626 return -EINVAL; 10627 10628 memcpy(settings->ciphers_pairwise, data, len); 10629 10630 for (i = 0; i < settings->n_ciphers_pairwise; i++) 10631 if (!cfg80211_supported_cipher_suite( 10632 &rdev->wiphy, 10633 settings->ciphers_pairwise[i])) 10634 return -EINVAL; 10635 } 10636 10637 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { 10638 settings->cipher_group = 10639 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); 10640 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, 10641 settings->cipher_group)) 10642 return -EINVAL; 10643 } 10644 10645 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { 10646 settings->wpa_versions = 10647 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); 10648 if (!nl80211_valid_wpa_versions(settings->wpa_versions)) 10649 return -EINVAL; 10650 } 10651 10652 if (info->attrs[NL80211_ATTR_AKM_SUITES]) { 10653 void *data; 10654 int len; 10655 10656 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); 10657 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); 10658 settings->n_akm_suites = len / sizeof(u32); 10659 10660 if (len % sizeof(u32)) 10661 return -EINVAL; 10662 10663 if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites) 10664 return -EINVAL; 10665 10666 memcpy(settings->akm_suites, data, len); 10667 } 10668 10669 if (info->attrs[NL80211_ATTR_PMK]) { 10670 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) 10671 return -EINVAL; 10672 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10673 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && 10674 !wiphy_ext_feature_isset(&rdev->wiphy, 10675 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) 10676 return -EINVAL; 10677 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); 10678 } 10679 10680 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { 10681 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10682 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 10683 !wiphy_ext_feature_isset(&rdev->wiphy, 10684 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) 10685 return -EINVAL; 10686 settings->sae_pwd = 10687 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 10688 settings->sae_pwd_len = 10689 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 10690 } 10691 10692 if (info->attrs[NL80211_ATTR_SAE_PWE]) 10693 settings->sae_pwe = 10694 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); 10695 else 10696 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; 10697 10698 return 0; 10699 } 10700 10701 static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev, 10702 const u8 *ssid, int ssid_len, 10703 struct nlattr **attrs, 10704 const u8 **bssid_out) 10705 { 10706 struct ieee80211_channel *chan; 10707 struct cfg80211_bss *bss; 10708 const u8 *bssid; 10709 u32 freq; 10710 10711 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ]) 10712 return ERR_PTR(-EINVAL); 10713 10714 bssid = nla_data(attrs[NL80211_ATTR_MAC]); 10715 10716 freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ])); 10717 if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10718 freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10719 10720 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 10721 if (!chan) 10722 return ERR_PTR(-EINVAL); 10723 10724 bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, 10725 ssid, ssid_len, 10726 IEEE80211_BSS_TYPE_ESS, 10727 IEEE80211_PRIVACY_ANY); 10728 if (!bss) 10729 return ERR_PTR(-ENOENT); 10730 10731 *bssid_out = bssid; 10732 return bss; 10733 } 10734 10735 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 10736 { 10737 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10738 struct net_device *dev = info->user_ptr[1]; 10739 struct cfg80211_assoc_request req = {}; 10740 struct nlattr **attrs = NULL; 10741 const u8 *bssid, *ssid; 10742 unsigned int link_id; 10743 int err, ssid_len; 10744 10745 if (dev->ieee80211_ptr->conn_owner_nlportid && 10746 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10747 return -EPERM; 10748 10749 if (!info->attrs[NL80211_ATTR_SSID]) 10750 return -EINVAL; 10751 10752 if (!rdev->ops->assoc) 10753 return -EOPNOTSUPP; 10754 10755 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10756 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10757 return -EOPNOTSUPP; 10758 10759 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10760 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10761 10762 if (info->attrs[NL80211_ATTR_IE]) { 10763 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10764 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10765 10766 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 10767 req.ie, req.ie_len)) { 10768 GENL_SET_ERR_MSG(info, 10769 "non-inheritance makes no sense"); 10770 return -EINVAL; 10771 } 10772 } 10773 10774 if (info->attrs[NL80211_ATTR_USE_MFP]) { 10775 enum nl80211_mfp mfp = 10776 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 10777 if (mfp == NL80211_MFP_REQUIRED) 10778 req.use_mfp = true; 10779 else if (mfp != NL80211_MFP_NO) 10780 return -EINVAL; 10781 } 10782 10783 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 10784 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 10785 10786 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 10787 req.flags |= ASSOC_REQ_DISABLE_HT; 10788 10789 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10790 memcpy(&req.ht_capa_mask, 10791 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 10792 sizeof(req.ht_capa_mask)); 10793 10794 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 10795 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10796 return -EINVAL; 10797 memcpy(&req.ht_capa, 10798 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 10799 sizeof(req.ht_capa)); 10800 } 10801 10802 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 10803 req.flags |= ASSOC_REQ_DISABLE_VHT; 10804 10805 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 10806 req.flags |= ASSOC_REQ_DISABLE_HE; 10807 10808 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) 10809 req.flags |= ASSOC_REQ_DISABLE_EHT; 10810 10811 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 10812 memcpy(&req.vht_capa_mask, 10813 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 10814 sizeof(req.vht_capa_mask)); 10815 10816 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 10817 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 10818 return -EINVAL; 10819 memcpy(&req.vht_capa, 10820 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 10821 sizeof(req.vht_capa)); 10822 } 10823 10824 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 10825 if (!((rdev->wiphy.features & 10826 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 10827 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 10828 !wiphy_ext_feature_isset(&rdev->wiphy, 10829 NL80211_EXT_FEATURE_RRM)) 10830 return -EINVAL; 10831 req.flags |= ASSOC_REQ_USE_RRM; 10832 } 10833 10834 if (info->attrs[NL80211_ATTR_FILS_KEK]) { 10835 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 10836 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 10837 if (!info->attrs[NL80211_ATTR_FILS_NONCES]) 10838 return -EINVAL; 10839 req.fils_nonces = 10840 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 10841 } 10842 10843 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { 10844 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) 10845 return -EINVAL; 10846 memcpy(&req.s1g_capa_mask, 10847 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), 10848 sizeof(req.s1g_capa_mask)); 10849 } 10850 10851 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { 10852 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) 10853 return -EINVAL; 10854 memcpy(&req.s1g_capa, 10855 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), 10856 sizeof(req.s1g_capa)); 10857 } 10858 10859 req.link_id = nl80211_link_id_or_invalid(info->attrs); 10860 10861 if (info->attrs[NL80211_ATTR_MLO_LINKS]) { 10862 unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs); 10863 struct nlattr *link; 10864 int rem = 0; 10865 10866 if (req.link_id < 0) 10867 return -EINVAL; 10868 10869 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) 10870 return -EINVAL; 10871 10872 if (info->attrs[NL80211_ATTR_MAC] || 10873 info->attrs[NL80211_ATTR_WIPHY_FREQ] || 10874 !info->attrs[NL80211_ATTR_MLD_ADDR]) 10875 return -EINVAL; 10876 10877 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 10878 10879 attrs = kzalloc(attrsize, GFP_KERNEL); 10880 if (!attrs) 10881 return -ENOMEM; 10882 10883 nla_for_each_nested(link, 10884 info->attrs[NL80211_ATTR_MLO_LINKS], 10885 rem) { 10886 memset(attrs, 0, attrsize); 10887 10888 nla_parse_nested(attrs, NL80211_ATTR_MAX, 10889 link, NULL, NULL); 10890 10891 if (!attrs[NL80211_ATTR_MLO_LINK_ID]) { 10892 err = -EINVAL; 10893 goto free; 10894 } 10895 10896 link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]); 10897 /* cannot use the same link ID again */ 10898 if (req.links[link_id].bss) { 10899 err = -EINVAL; 10900 goto free; 10901 } 10902 req.links[link_id].bss = 10903 nl80211_assoc_bss(rdev, ssid, ssid_len, attrs, 10904 &bssid); 10905 if (IS_ERR(req.links[link_id].bss)) { 10906 err = PTR_ERR(req.links[link_id].bss); 10907 req.links[link_id].bss = NULL; 10908 goto free; 10909 } 10910 10911 if (attrs[NL80211_ATTR_IE]) { 10912 req.links[link_id].elems = 10913 nla_data(attrs[NL80211_ATTR_IE]); 10914 req.links[link_id].elems_len = 10915 nla_len(attrs[NL80211_ATTR_IE]); 10916 10917 if (cfg80211_find_elem(WLAN_EID_FRAGMENT, 10918 req.links[link_id].elems, 10919 req.links[link_id].elems_len)) { 10920 GENL_SET_ERR_MSG(info, 10921 "cannot deal with fragmentation"); 10922 err = -EINVAL; 10923 goto free; 10924 } 10925 10926 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 10927 req.links[link_id].elems, 10928 req.links[link_id].elems_len)) { 10929 GENL_SET_ERR_MSG(info, 10930 "cannot deal with non-inheritance"); 10931 err = -EINVAL; 10932 goto free; 10933 } 10934 } 10935 } 10936 10937 if (!req.links[req.link_id].bss) { 10938 err = -EINVAL; 10939 goto free; 10940 } 10941 10942 if (req.links[req.link_id].elems_len) { 10943 GENL_SET_ERR_MSG(info, 10944 "cannot have per-link elems on assoc link"); 10945 err = -EINVAL; 10946 goto free; 10947 } 10948 10949 kfree(attrs); 10950 attrs = NULL; 10951 } else { 10952 if (req.link_id >= 0) 10953 return -EINVAL; 10954 10955 req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs, 10956 &bssid); 10957 if (IS_ERR(req.bss)) 10958 return PTR_ERR(req.bss); 10959 } 10960 10961 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); 10962 if (!err) { 10963 wdev_lock(dev->ieee80211_ptr); 10964 10965 err = cfg80211_mlme_assoc(rdev, dev, &req); 10966 10967 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10968 dev->ieee80211_ptr->conn_owner_nlportid = 10969 info->snd_portid; 10970 memcpy(dev->ieee80211_ptr->disconnect_bssid, 10971 bssid, ETH_ALEN); 10972 } 10973 10974 wdev_unlock(dev->ieee80211_ptr); 10975 } 10976 10977 free: 10978 for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++) 10979 cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss); 10980 cfg80211_put_bss(&rdev->wiphy, req.bss); 10981 kfree(attrs); 10982 10983 return err; 10984 } 10985 10986 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 10987 { 10988 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10989 struct net_device *dev = info->user_ptr[1]; 10990 const u8 *ie = NULL, *bssid; 10991 int ie_len = 0, err; 10992 u16 reason_code; 10993 bool local_state_change; 10994 10995 if (dev->ieee80211_ptr->conn_owner_nlportid && 10996 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10997 return -EPERM; 10998 10999 if (!info->attrs[NL80211_ATTR_MAC]) 11000 return -EINVAL; 11001 11002 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11003 return -EINVAL; 11004 11005 if (!rdev->ops->deauth) 11006 return -EOPNOTSUPP; 11007 11008 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11009 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11010 return -EOPNOTSUPP; 11011 11012 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11013 11014 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11015 if (reason_code == 0) { 11016 /* Reason Code 0 is reserved */ 11017 return -EINVAL; 11018 } 11019 11020 if (info->attrs[NL80211_ATTR_IE]) { 11021 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11022 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11023 } 11024 11025 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 11026 11027 wdev_lock(dev->ieee80211_ptr); 11028 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 11029 local_state_change); 11030 wdev_unlock(dev->ieee80211_ptr); 11031 return err; 11032 } 11033 11034 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 11035 { 11036 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11037 struct net_device *dev = info->user_ptr[1]; 11038 const u8 *ie = NULL, *bssid; 11039 int ie_len = 0, err; 11040 u16 reason_code; 11041 bool local_state_change; 11042 11043 if (dev->ieee80211_ptr->conn_owner_nlportid && 11044 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11045 return -EPERM; 11046 11047 if (!info->attrs[NL80211_ATTR_MAC]) 11048 return -EINVAL; 11049 11050 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11051 return -EINVAL; 11052 11053 if (!rdev->ops->disassoc) 11054 return -EOPNOTSUPP; 11055 11056 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11057 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11058 return -EOPNOTSUPP; 11059 11060 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11061 11062 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11063 if (reason_code == 0) { 11064 /* Reason Code 0 is reserved */ 11065 return -EINVAL; 11066 } 11067 11068 if (info->attrs[NL80211_ATTR_IE]) { 11069 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11070 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11071 } 11072 11073 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 11074 11075 wdev_lock(dev->ieee80211_ptr); 11076 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 11077 local_state_change); 11078 wdev_unlock(dev->ieee80211_ptr); 11079 return err; 11080 } 11081 11082 static bool 11083 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, 11084 int mcast_rate[NUM_NL80211_BANDS], 11085 int rateval) 11086 { 11087 struct wiphy *wiphy = &rdev->wiphy; 11088 bool found = false; 11089 int band, i; 11090 11091 for (band = 0; band < NUM_NL80211_BANDS; band++) { 11092 struct ieee80211_supported_band *sband; 11093 11094 sband = wiphy->bands[band]; 11095 if (!sband) 11096 continue; 11097 11098 for (i = 0; i < sband->n_bitrates; i++) { 11099 if (sband->bitrates[i].bitrate == rateval) { 11100 mcast_rate[band] = i + 1; 11101 found = true; 11102 break; 11103 } 11104 } 11105 } 11106 11107 return found; 11108 } 11109 11110 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 11111 { 11112 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11113 struct net_device *dev = info->user_ptr[1]; 11114 struct cfg80211_ibss_params ibss; 11115 struct wiphy *wiphy; 11116 struct cfg80211_cached_keys *connkeys = NULL; 11117 int err; 11118 11119 memset(&ibss, 0, sizeof(ibss)); 11120 11121 if (!info->attrs[NL80211_ATTR_SSID] || 11122 !nla_len(info->attrs[NL80211_ATTR_SSID])) 11123 return -EINVAL; 11124 11125 ibss.beacon_interval = 100; 11126 11127 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) 11128 ibss.beacon_interval = 11129 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 11130 11131 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, 11132 ibss.beacon_interval); 11133 if (err) 11134 return err; 11135 11136 if (!rdev->ops->join_ibss) 11137 return -EOPNOTSUPP; 11138 11139 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 11140 return -EOPNOTSUPP; 11141 11142 wiphy = &rdev->wiphy; 11143 11144 if (info->attrs[NL80211_ATTR_MAC]) { 11145 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11146 11147 if (!is_valid_ether_addr(ibss.bssid)) 11148 return -EINVAL; 11149 } 11150 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11151 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11152 11153 if (info->attrs[NL80211_ATTR_IE]) { 11154 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11155 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11156 } 11157 11158 err = nl80211_parse_chandef(rdev, info, &ibss.chandef); 11159 if (err) 11160 return err; 11161 11162 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, 11163 NL80211_IFTYPE_ADHOC)) 11164 return -EINVAL; 11165 11166 switch (ibss.chandef.width) { 11167 case NL80211_CHAN_WIDTH_5: 11168 case NL80211_CHAN_WIDTH_10: 11169 case NL80211_CHAN_WIDTH_20_NOHT: 11170 break; 11171 case NL80211_CHAN_WIDTH_20: 11172 case NL80211_CHAN_WIDTH_40: 11173 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 11174 return -EINVAL; 11175 break; 11176 case NL80211_CHAN_WIDTH_80: 11177 case NL80211_CHAN_WIDTH_80P80: 11178 case NL80211_CHAN_WIDTH_160: 11179 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 11180 return -EINVAL; 11181 if (!wiphy_ext_feature_isset(&rdev->wiphy, 11182 NL80211_EXT_FEATURE_VHT_IBSS)) 11183 return -EINVAL; 11184 break; 11185 case NL80211_CHAN_WIDTH_320: 11186 return -EINVAL; 11187 default: 11188 return -EINVAL; 11189 } 11190 11191 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 11192 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 11193 11194 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 11195 u8 *rates = 11196 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11197 int n_rates = 11198 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11199 struct ieee80211_supported_band *sband = 11200 wiphy->bands[ibss.chandef.chan->band]; 11201 11202 err = ieee80211_get_ratemask(sband, rates, n_rates, 11203 &ibss.basic_rates); 11204 if (err) 11205 return err; 11206 } 11207 11208 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11209 memcpy(&ibss.ht_capa_mask, 11210 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 11211 sizeof(ibss.ht_capa_mask)); 11212 11213 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 11214 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11215 return -EINVAL; 11216 memcpy(&ibss.ht_capa, 11217 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11218 sizeof(ibss.ht_capa)); 11219 } 11220 11221 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 11222 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, 11223 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 11224 return -EINVAL; 11225 11226 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { 11227 bool no_ht = false; 11228 11229 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); 11230 if (IS_ERR(connkeys)) 11231 return PTR_ERR(connkeys); 11232 11233 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && 11234 no_ht) { 11235 kfree_sensitive(connkeys); 11236 return -EINVAL; 11237 } 11238 } 11239 11240 ibss.control_port = 11241 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); 11242 11243 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 11244 int r = validate_pae_over_nl80211(rdev, info); 11245 11246 if (r < 0) { 11247 kfree_sensitive(connkeys); 11248 return r; 11249 } 11250 11251 ibss.control_port_over_nl80211 = true; 11252 } 11253 11254 ibss.userspace_handles_dfs = 11255 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 11256 11257 wdev_lock(dev->ieee80211_ptr); 11258 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 11259 if (err) 11260 kfree_sensitive(connkeys); 11261 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 11262 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 11263 wdev_unlock(dev->ieee80211_ptr); 11264 11265 return err; 11266 } 11267 11268 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 11269 { 11270 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11271 struct net_device *dev = info->user_ptr[1]; 11272 11273 if (!rdev->ops->leave_ibss) 11274 return -EOPNOTSUPP; 11275 11276 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 11277 return -EOPNOTSUPP; 11278 11279 return cfg80211_leave_ibss(rdev, dev, false); 11280 } 11281 11282 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) 11283 { 11284 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11285 struct net_device *dev = info->user_ptr[1]; 11286 int mcast_rate[NUM_NL80211_BANDS]; 11287 u32 nla_rate; 11288 11289 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && 11290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 11291 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) 11292 return -EOPNOTSUPP; 11293 11294 if (!rdev->ops->set_mcast_rate) 11295 return -EOPNOTSUPP; 11296 11297 memset(mcast_rate, 0, sizeof(mcast_rate)); 11298 11299 if (!info->attrs[NL80211_ATTR_MCAST_RATE]) 11300 return -EINVAL; 11301 11302 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); 11303 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) 11304 return -EINVAL; 11305 11306 return rdev_set_mcast_rate(rdev, dev, mcast_rate); 11307 } 11308 11309 static struct sk_buff * 11310 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, 11311 struct wireless_dev *wdev, int approxlen, 11312 u32 portid, u32 seq, enum nl80211_commands cmd, 11313 enum nl80211_attrs attr, 11314 const struct nl80211_vendor_cmd_info *info, 11315 gfp_t gfp) 11316 { 11317 struct sk_buff *skb; 11318 void *hdr; 11319 struct nlattr *data; 11320 11321 skb = nlmsg_new(approxlen + 100, gfp); 11322 if (!skb) 11323 return NULL; 11324 11325 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); 11326 if (!hdr) { 11327 kfree_skb(skb); 11328 return NULL; 11329 } 11330 11331 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 11332 goto nla_put_failure; 11333 11334 if (info) { 11335 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, 11336 info->vendor_id)) 11337 goto nla_put_failure; 11338 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, 11339 info->subcmd)) 11340 goto nla_put_failure; 11341 } 11342 11343 if (wdev) { 11344 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 11345 wdev_id(wdev), NL80211_ATTR_PAD)) 11346 goto nla_put_failure; 11347 if (wdev->netdev && 11348 nla_put_u32(skb, NL80211_ATTR_IFINDEX, 11349 wdev->netdev->ifindex)) 11350 goto nla_put_failure; 11351 } 11352 11353 data = nla_nest_start_noflag(skb, attr); 11354 if (!data) 11355 goto nla_put_failure; 11356 11357 ((void **)skb->cb)[0] = rdev; 11358 ((void **)skb->cb)[1] = hdr; 11359 ((void **)skb->cb)[2] = data; 11360 11361 return skb; 11362 11363 nla_put_failure: 11364 kfree_skb(skb); 11365 return NULL; 11366 } 11367 11368 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, 11369 struct wireless_dev *wdev, 11370 enum nl80211_commands cmd, 11371 enum nl80211_attrs attr, 11372 unsigned int portid, 11373 int vendor_event_idx, 11374 int approxlen, gfp_t gfp) 11375 { 11376 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 11377 const struct nl80211_vendor_cmd_info *info; 11378 11379 switch (cmd) { 11380 case NL80211_CMD_TESTMODE: 11381 if (WARN_ON(vendor_event_idx != -1)) 11382 return NULL; 11383 info = NULL; 11384 break; 11385 case NL80211_CMD_VENDOR: 11386 if (WARN_ON(vendor_event_idx < 0 || 11387 vendor_event_idx >= wiphy->n_vendor_events)) 11388 return NULL; 11389 info = &wiphy->vendor_events[vendor_event_idx]; 11390 break; 11391 default: 11392 WARN_ON(1); 11393 return NULL; 11394 } 11395 11396 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, 11397 cmd, attr, info, gfp); 11398 } 11399 EXPORT_SYMBOL(__cfg80211_alloc_event_skb); 11400 11401 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) 11402 { 11403 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 11404 void *hdr = ((void **)skb->cb)[1]; 11405 struct nlmsghdr *nlhdr = nlmsg_hdr(skb); 11406 struct nlattr *data = ((void **)skb->cb)[2]; 11407 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; 11408 11409 /* clear CB data for netlink core to own from now on */ 11410 memset(skb->cb, 0, sizeof(skb->cb)); 11411 11412 nla_nest_end(skb, data); 11413 genlmsg_end(skb, hdr); 11414 11415 if (nlhdr->nlmsg_pid) { 11416 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, 11417 nlhdr->nlmsg_pid); 11418 } else { 11419 if (data->nla_type == NL80211_ATTR_VENDOR_DATA) 11420 mcgrp = NL80211_MCGRP_VENDOR; 11421 11422 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 11423 skb, 0, mcgrp, gfp); 11424 } 11425 } 11426 EXPORT_SYMBOL(__cfg80211_send_event_skb); 11427 11428 #ifdef CONFIG_NL80211_TESTMODE 11429 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 11430 { 11431 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11432 struct wireless_dev *wdev; 11433 int err; 11434 11435 lockdep_assert_held(&rdev->wiphy.mtx); 11436 11437 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 11438 info->attrs); 11439 11440 if (!rdev->ops->testmode_cmd) 11441 return -EOPNOTSUPP; 11442 11443 if (IS_ERR(wdev)) { 11444 err = PTR_ERR(wdev); 11445 if (err != -EINVAL) 11446 return err; 11447 wdev = NULL; 11448 } else if (wdev->wiphy != &rdev->wiphy) { 11449 return -EINVAL; 11450 } 11451 11452 if (!info->attrs[NL80211_ATTR_TESTDATA]) 11453 return -EINVAL; 11454 11455 rdev->cur_cmd_info = info; 11456 err = rdev_testmode_cmd(rdev, wdev, 11457 nla_data(info->attrs[NL80211_ATTR_TESTDATA]), 11458 nla_len(info->attrs[NL80211_ATTR_TESTDATA])); 11459 rdev->cur_cmd_info = NULL; 11460 11461 return err; 11462 } 11463 11464 static int nl80211_testmode_dump(struct sk_buff *skb, 11465 struct netlink_callback *cb) 11466 { 11467 struct cfg80211_registered_device *rdev; 11468 struct nlattr **attrbuf = NULL; 11469 int err; 11470 long phy_idx; 11471 void *data = NULL; 11472 int data_len = 0; 11473 11474 rtnl_lock(); 11475 11476 if (cb->args[0]) { 11477 /* 11478 * 0 is a valid index, but not valid for args[0], 11479 * so we need to offset by 1. 11480 */ 11481 phy_idx = cb->args[0] - 1; 11482 11483 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); 11484 if (!rdev) { 11485 err = -ENOENT; 11486 goto out_err; 11487 } 11488 } else { 11489 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 11490 GFP_KERNEL); 11491 if (!attrbuf) { 11492 err = -ENOMEM; 11493 goto out_err; 11494 } 11495 11496 err = nlmsg_parse_deprecated(cb->nlh, 11497 GENL_HDRLEN + nl80211_fam.hdrsize, 11498 attrbuf, nl80211_fam.maxattr, 11499 nl80211_policy, NULL); 11500 if (err) 11501 goto out_err; 11502 11503 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 11504 if (IS_ERR(rdev)) { 11505 err = PTR_ERR(rdev); 11506 goto out_err; 11507 } 11508 phy_idx = rdev->wiphy_idx; 11509 11510 if (attrbuf[NL80211_ATTR_TESTDATA]) 11511 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; 11512 } 11513 11514 if (cb->args[1]) { 11515 data = nla_data((void *)cb->args[1]); 11516 data_len = nla_len((void *)cb->args[1]); 11517 } 11518 11519 if (!rdev->ops->testmode_dump) { 11520 err = -EOPNOTSUPP; 11521 goto out_err; 11522 } 11523 11524 while (1) { 11525 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 11526 cb->nlh->nlmsg_seq, NLM_F_MULTI, 11527 NL80211_CMD_TESTMODE); 11528 struct nlattr *tmdata; 11529 11530 if (!hdr) 11531 break; 11532 11533 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { 11534 genlmsg_cancel(skb, hdr); 11535 break; 11536 } 11537 11538 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); 11539 if (!tmdata) { 11540 genlmsg_cancel(skb, hdr); 11541 break; 11542 } 11543 err = rdev_testmode_dump(rdev, skb, cb, data, data_len); 11544 nla_nest_end(skb, tmdata); 11545 11546 if (err == -ENOBUFS || err == -ENOENT) { 11547 genlmsg_cancel(skb, hdr); 11548 break; 11549 } else if (err) { 11550 genlmsg_cancel(skb, hdr); 11551 goto out_err; 11552 } 11553 11554 genlmsg_end(skb, hdr); 11555 } 11556 11557 err = skb->len; 11558 /* see above */ 11559 cb->args[0] = phy_idx + 1; 11560 out_err: 11561 kfree(attrbuf); 11562 rtnl_unlock(); 11563 return err; 11564 } 11565 #endif 11566 11567 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 11568 { 11569 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11570 struct net_device *dev = info->user_ptr[1]; 11571 struct cfg80211_connect_params connect; 11572 struct wiphy *wiphy; 11573 struct cfg80211_cached_keys *connkeys = NULL; 11574 u32 freq = 0; 11575 int err; 11576 11577 memset(&connect, 0, sizeof(connect)); 11578 11579 if (!info->attrs[NL80211_ATTR_SSID] || 11580 !nla_len(info->attrs[NL80211_ATTR_SSID])) 11581 return -EINVAL; 11582 11583 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 11584 connect.auth_type = 11585 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 11586 if (!nl80211_valid_auth_type(rdev, connect.auth_type, 11587 NL80211_CMD_CONNECT)) 11588 return -EINVAL; 11589 } else 11590 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 11591 11592 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 11593 11594 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && 11595 !wiphy_ext_feature_isset(&rdev->wiphy, 11596 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 11597 return -EINVAL; 11598 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; 11599 11600 err = nl80211_crypto_settings(rdev, info, &connect.crypto, 11601 NL80211_MAX_NR_CIPHER_SUITES); 11602 if (err) 11603 return err; 11604 11605 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11606 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11607 return -EOPNOTSUPP; 11608 11609 wiphy = &rdev->wiphy; 11610 11611 connect.bg_scan_period = -1; 11612 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && 11613 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { 11614 connect.bg_scan_period = 11615 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); 11616 } 11617 11618 if (info->attrs[NL80211_ATTR_MAC]) 11619 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11620 else if (info->attrs[NL80211_ATTR_MAC_HINT]) 11621 connect.bssid_hint = 11622 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); 11623 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11624 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11625 11626 if (info->attrs[NL80211_ATTR_IE]) { 11627 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11628 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11629 } 11630 11631 if (info->attrs[NL80211_ATTR_USE_MFP]) { 11632 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 11633 if (connect.mfp == NL80211_MFP_OPTIONAL && 11634 !wiphy_ext_feature_isset(&rdev->wiphy, 11635 NL80211_EXT_FEATURE_MFP_OPTIONAL)) 11636 return -EOPNOTSUPP; 11637 } else { 11638 connect.mfp = NL80211_MFP_NO; 11639 } 11640 11641 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 11642 connect.prev_bssid = 11643 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 11644 11645 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) 11646 freq = MHZ_TO_KHZ(nla_get_u32( 11647 info->attrs[NL80211_ATTR_WIPHY_FREQ])); 11648 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 11649 freq += 11650 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 11651 11652 if (freq) { 11653 connect.channel = nl80211_get_valid_chan(wiphy, freq); 11654 if (!connect.channel) 11655 return -EINVAL; 11656 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { 11657 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); 11658 freq = MHZ_TO_KHZ(freq); 11659 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); 11660 if (!connect.channel_hint) 11661 return -EINVAL; 11662 } 11663 11664 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 11665 connect.edmg.channels = 11666 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 11667 11668 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 11669 connect.edmg.bw_config = 11670 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 11671 } 11672 11673 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 11674 connkeys = nl80211_parse_connkeys(rdev, info, NULL); 11675 if (IS_ERR(connkeys)) 11676 return PTR_ERR(connkeys); 11677 } 11678 11679 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 11680 connect.flags |= ASSOC_REQ_DISABLE_HT; 11681 11682 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11683 memcpy(&connect.ht_capa_mask, 11684 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 11685 sizeof(connect.ht_capa_mask)); 11686 11687 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 11688 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { 11689 kfree_sensitive(connkeys); 11690 return -EINVAL; 11691 } 11692 memcpy(&connect.ht_capa, 11693 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11694 sizeof(connect.ht_capa)); 11695 } 11696 11697 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 11698 connect.flags |= ASSOC_REQ_DISABLE_VHT; 11699 11700 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 11701 connect.flags |= ASSOC_REQ_DISABLE_HE; 11702 11703 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) 11704 connect.flags |= ASSOC_REQ_DISABLE_EHT; 11705 11706 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11707 memcpy(&connect.vht_capa_mask, 11708 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 11709 sizeof(connect.vht_capa_mask)); 11710 11711 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 11712 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { 11713 kfree_sensitive(connkeys); 11714 return -EINVAL; 11715 } 11716 memcpy(&connect.vht_capa, 11717 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 11718 sizeof(connect.vht_capa)); 11719 } 11720 11721 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 11722 if (!((rdev->wiphy.features & 11723 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 11724 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 11725 !wiphy_ext_feature_isset(&rdev->wiphy, 11726 NL80211_EXT_FEATURE_RRM)) { 11727 kfree_sensitive(connkeys); 11728 return -EINVAL; 11729 } 11730 connect.flags |= ASSOC_REQ_USE_RRM; 11731 } 11732 11733 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 11734 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 11735 kfree_sensitive(connkeys); 11736 return -EOPNOTSUPP; 11737 } 11738 11739 if (info->attrs[NL80211_ATTR_BSS_SELECT]) { 11740 /* bss selection makes no sense if bssid is set */ 11741 if (connect.bssid) { 11742 kfree_sensitive(connkeys); 11743 return -EINVAL; 11744 } 11745 11746 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], 11747 wiphy, &connect.bss_select); 11748 if (err) { 11749 kfree_sensitive(connkeys); 11750 return err; 11751 } 11752 } 11753 11754 if (wiphy_ext_feature_isset(&rdev->wiphy, 11755 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 11756 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 11757 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 11758 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 11759 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 11760 connect.fils_erp_username = 11761 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 11762 connect.fils_erp_username_len = 11763 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 11764 connect.fils_erp_realm = 11765 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 11766 connect.fils_erp_realm_len = 11767 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 11768 connect.fils_erp_next_seq_num = 11769 nla_get_u16( 11770 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 11771 connect.fils_erp_rrk = 11772 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 11773 connect.fils_erp_rrk_len = 11774 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 11775 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 11776 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 11777 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 11778 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 11779 kfree_sensitive(connkeys); 11780 return -EINVAL; 11781 } 11782 11783 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { 11784 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 11785 kfree_sensitive(connkeys); 11786 GENL_SET_ERR_MSG(info, 11787 "external auth requires connection ownership"); 11788 return -EINVAL; 11789 } 11790 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; 11791 } 11792 11793 if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT])) 11794 connect.flags |= CONNECT_REQ_MLO_SUPPORT; 11795 11796 wdev_lock(dev->ieee80211_ptr); 11797 11798 err = cfg80211_connect(rdev, dev, &connect, connkeys, 11799 connect.prev_bssid); 11800 if (err) 11801 kfree_sensitive(connkeys); 11802 11803 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 11804 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 11805 if (connect.bssid) 11806 memcpy(dev->ieee80211_ptr->disconnect_bssid, 11807 connect.bssid, ETH_ALEN); 11808 else 11809 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); 11810 } 11811 11812 wdev_unlock(dev->ieee80211_ptr); 11813 11814 return err; 11815 } 11816 11817 static int nl80211_update_connect_params(struct sk_buff *skb, 11818 struct genl_info *info) 11819 { 11820 struct cfg80211_connect_params connect = {}; 11821 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11822 struct net_device *dev = info->user_ptr[1]; 11823 struct wireless_dev *wdev = dev->ieee80211_ptr; 11824 bool fils_sk_offload; 11825 u32 auth_type; 11826 u32 changed = 0; 11827 int ret; 11828 11829 if (!rdev->ops->update_connect_params) 11830 return -EOPNOTSUPP; 11831 11832 if (info->attrs[NL80211_ATTR_IE]) { 11833 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11834 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11835 changed |= UPDATE_ASSOC_IES; 11836 } 11837 11838 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, 11839 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); 11840 11841 /* 11842 * when driver supports fils-sk offload all attributes must be 11843 * provided. So the else covers "fils-sk-not-all" and 11844 * "no-fils-sk-any". 11845 */ 11846 if (fils_sk_offload && 11847 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 11848 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 11849 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 11850 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 11851 connect.fils_erp_username = 11852 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 11853 connect.fils_erp_username_len = 11854 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 11855 connect.fils_erp_realm = 11856 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 11857 connect.fils_erp_realm_len = 11858 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 11859 connect.fils_erp_next_seq_num = 11860 nla_get_u16( 11861 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 11862 connect.fils_erp_rrk = 11863 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 11864 connect.fils_erp_rrk_len = 11865 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 11866 changed |= UPDATE_FILS_ERP_INFO; 11867 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 11868 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 11869 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 11870 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 11871 return -EINVAL; 11872 } 11873 11874 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 11875 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 11876 if (!nl80211_valid_auth_type(rdev, auth_type, 11877 NL80211_CMD_CONNECT)) 11878 return -EINVAL; 11879 11880 if (auth_type == NL80211_AUTHTYPE_FILS_SK && 11881 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) 11882 return -EINVAL; 11883 11884 connect.auth_type = auth_type; 11885 changed |= UPDATE_AUTH_TYPE; 11886 } 11887 11888 wdev_lock(dev->ieee80211_ptr); 11889 if (!wdev->connected) 11890 ret = -ENOLINK; 11891 else 11892 ret = rdev_update_connect_params(rdev, dev, &connect, changed); 11893 wdev_unlock(dev->ieee80211_ptr); 11894 11895 return ret; 11896 } 11897 11898 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 11899 { 11900 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11901 struct net_device *dev = info->user_ptr[1]; 11902 u16 reason; 11903 int ret; 11904 11905 if (dev->ieee80211_ptr->conn_owner_nlportid && 11906 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11907 return -EPERM; 11908 11909 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11910 reason = WLAN_REASON_DEAUTH_LEAVING; 11911 else 11912 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11913 11914 if (reason == 0) 11915 return -EINVAL; 11916 11917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11919 return -EOPNOTSUPP; 11920 11921 wdev_lock(dev->ieee80211_ptr); 11922 ret = cfg80211_disconnect(rdev, dev, reason, true); 11923 wdev_unlock(dev->ieee80211_ptr); 11924 return ret; 11925 } 11926 11927 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 11928 { 11929 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11930 struct net *net; 11931 int err; 11932 11933 if (info->attrs[NL80211_ATTR_PID]) { 11934 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 11935 11936 net = get_net_ns_by_pid(pid); 11937 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { 11938 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); 11939 11940 net = get_net_ns_by_fd(fd); 11941 } else { 11942 return -EINVAL; 11943 } 11944 11945 if (IS_ERR(net)) 11946 return PTR_ERR(net); 11947 11948 err = 0; 11949 11950 /* check if anything to do */ 11951 if (!net_eq(wiphy_net(&rdev->wiphy), net)) 11952 err = cfg80211_switch_netns(rdev, net); 11953 11954 put_net(net); 11955 return err; 11956 } 11957 11958 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 11959 { 11960 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11961 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 11962 struct cfg80211_pmksa *pmksa) = NULL; 11963 struct net_device *dev = info->user_ptr[1]; 11964 struct cfg80211_pmksa pmksa; 11965 11966 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 11967 11968 if (!info->attrs[NL80211_ATTR_PMKID]) 11969 return -EINVAL; 11970 11971 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 11972 11973 if (info->attrs[NL80211_ATTR_MAC]) { 11974 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11975 } else if (info->attrs[NL80211_ATTR_SSID] && 11976 info->attrs[NL80211_ATTR_FILS_CACHE_ID] && 11977 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || 11978 info->attrs[NL80211_ATTR_PMK])) { 11979 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11980 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11981 pmksa.cache_id = 11982 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); 11983 } else { 11984 return -EINVAL; 11985 } 11986 if (info->attrs[NL80211_ATTR_PMK]) { 11987 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 11988 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 11989 } 11990 11991 if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) 11992 pmksa.pmk_lifetime = 11993 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); 11994 11995 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) 11996 pmksa.pmk_reauth_threshold = 11997 nla_get_u8( 11998 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); 11999 12000 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12001 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && 12002 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && 12003 wiphy_ext_feature_isset(&rdev->wiphy, 12004 NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) 12005 return -EOPNOTSUPP; 12006 12007 switch (info->genlhdr->cmd) { 12008 case NL80211_CMD_SET_PMKSA: 12009 rdev_ops = rdev->ops->set_pmksa; 12010 break; 12011 case NL80211_CMD_DEL_PMKSA: 12012 rdev_ops = rdev->ops->del_pmksa; 12013 break; 12014 default: 12015 WARN_ON(1); 12016 break; 12017 } 12018 12019 if (!rdev_ops) 12020 return -EOPNOTSUPP; 12021 12022 return rdev_ops(&rdev->wiphy, dev, &pmksa); 12023 } 12024 12025 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 12026 { 12027 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12028 struct net_device *dev = info->user_ptr[1]; 12029 12030 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12031 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 12032 return -EOPNOTSUPP; 12033 12034 if (!rdev->ops->flush_pmksa) 12035 return -EOPNOTSUPP; 12036 12037 return rdev_flush_pmksa(rdev, dev); 12038 } 12039 12040 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) 12041 { 12042 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12043 struct net_device *dev = info->user_ptr[1]; 12044 u8 action_code, dialog_token; 12045 u32 peer_capability = 0; 12046 u16 status_code; 12047 u8 *peer; 12048 bool initiator; 12049 12050 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 12051 !rdev->ops->tdls_mgmt) 12052 return -EOPNOTSUPP; 12053 12054 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || 12055 !info->attrs[NL80211_ATTR_STATUS_CODE] || 12056 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || 12057 !info->attrs[NL80211_ATTR_IE] || 12058 !info->attrs[NL80211_ATTR_MAC]) 12059 return -EINVAL; 12060 12061 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 12062 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); 12063 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 12064 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); 12065 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); 12066 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) 12067 peer_capability = 12068 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); 12069 12070 return rdev_tdls_mgmt(rdev, dev, peer, action_code, 12071 dialog_token, status_code, peer_capability, 12072 initiator, 12073 nla_data(info->attrs[NL80211_ATTR_IE]), 12074 nla_len(info->attrs[NL80211_ATTR_IE])); 12075 } 12076 12077 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) 12078 { 12079 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12080 struct net_device *dev = info->user_ptr[1]; 12081 enum nl80211_tdls_operation operation; 12082 u8 *peer; 12083 12084 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 12085 !rdev->ops->tdls_oper) 12086 return -EOPNOTSUPP; 12087 12088 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || 12089 !info->attrs[NL80211_ATTR_MAC]) 12090 return -EINVAL; 12091 12092 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); 12093 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 12094 12095 return rdev_tdls_oper(rdev, dev, peer, operation); 12096 } 12097 12098 static int nl80211_remain_on_channel(struct sk_buff *skb, 12099 struct genl_info *info) 12100 { 12101 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12102 unsigned int link_id = nl80211_link_id(info->attrs); 12103 struct wireless_dev *wdev = info->user_ptr[1]; 12104 struct cfg80211_chan_def chandef; 12105 struct sk_buff *msg; 12106 void *hdr; 12107 u64 cookie; 12108 u32 duration; 12109 int err; 12110 12111 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 12112 !info->attrs[NL80211_ATTR_DURATION]) 12113 return -EINVAL; 12114 12115 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 12116 12117 if (!rdev->ops->remain_on_channel || 12118 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) 12119 return -EOPNOTSUPP; 12120 12121 /* 12122 * We should be on that channel for at least a minimum amount of 12123 * time (10ms) but no longer than the driver supports. 12124 */ 12125 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 12126 duration > rdev->wiphy.max_remain_on_channel_duration) 12127 return -EINVAL; 12128 12129 err = nl80211_parse_chandef(rdev, info, &chandef); 12130 if (err) 12131 return err; 12132 12133 wdev_lock(wdev); 12134 if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { 12135 const struct cfg80211_chan_def *oper_chandef, *compat_chandef; 12136 12137 oper_chandef = wdev_chandef(wdev, link_id); 12138 12139 if (WARN_ON(!oper_chandef)) { 12140 /* cannot happen since we must beacon to get here */ 12141 WARN_ON(1); 12142 wdev_unlock(wdev); 12143 return -EBUSY; 12144 } 12145 12146 /* note: returns first one if identical chandefs */ 12147 compat_chandef = cfg80211_chandef_compatible(&chandef, 12148 oper_chandef); 12149 12150 if (compat_chandef != &chandef) { 12151 wdev_unlock(wdev); 12152 return -EBUSY; 12153 } 12154 } 12155 wdev_unlock(wdev); 12156 12157 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12158 if (!msg) 12159 return -ENOMEM; 12160 12161 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12162 NL80211_CMD_REMAIN_ON_CHANNEL); 12163 if (!hdr) { 12164 err = -ENOBUFS; 12165 goto free_msg; 12166 } 12167 12168 err = rdev_remain_on_channel(rdev, wdev, chandef.chan, 12169 duration, &cookie); 12170 12171 if (err) 12172 goto free_msg; 12173 12174 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12175 NL80211_ATTR_PAD)) 12176 goto nla_put_failure; 12177 12178 genlmsg_end(msg, hdr); 12179 12180 return genlmsg_reply(msg, info); 12181 12182 nla_put_failure: 12183 err = -ENOBUFS; 12184 free_msg: 12185 nlmsg_free(msg); 12186 return err; 12187 } 12188 12189 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 12190 struct genl_info *info) 12191 { 12192 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12193 struct wireless_dev *wdev = info->user_ptr[1]; 12194 u64 cookie; 12195 12196 if (!info->attrs[NL80211_ATTR_COOKIE]) 12197 return -EINVAL; 12198 12199 if (!rdev->ops->cancel_remain_on_channel) 12200 return -EOPNOTSUPP; 12201 12202 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12203 12204 return rdev_cancel_remain_on_channel(rdev, wdev, cookie); 12205 } 12206 12207 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, 12208 struct genl_info *info) 12209 { 12210 struct cfg80211_bitrate_mask mask; 12211 unsigned int link_id = nl80211_link_id(info->attrs); 12212 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12213 struct net_device *dev = info->user_ptr[1]; 12214 struct wireless_dev *wdev = dev->ieee80211_ptr; 12215 int err; 12216 12217 if (!rdev->ops->set_bitrate_mask) 12218 return -EOPNOTSUPP; 12219 12220 wdev_lock(wdev); 12221 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 12222 NL80211_ATTR_TX_RATES, &mask, 12223 dev, true, link_id); 12224 if (err) 12225 goto out; 12226 12227 err = rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask); 12228 out: 12229 wdev_unlock(wdev); 12230 return err; 12231 } 12232 12233 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) 12234 { 12235 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12236 struct wireless_dev *wdev = info->user_ptr[1]; 12237 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; 12238 12239 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 12240 return -EINVAL; 12241 12242 if (info->attrs[NL80211_ATTR_FRAME_TYPE]) 12243 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); 12244 12245 switch (wdev->iftype) { 12246 case NL80211_IFTYPE_STATION: 12247 case NL80211_IFTYPE_ADHOC: 12248 case NL80211_IFTYPE_P2P_CLIENT: 12249 case NL80211_IFTYPE_AP: 12250 case NL80211_IFTYPE_AP_VLAN: 12251 case NL80211_IFTYPE_MESH_POINT: 12252 case NL80211_IFTYPE_P2P_GO: 12253 case NL80211_IFTYPE_P2P_DEVICE: 12254 break; 12255 case NL80211_IFTYPE_NAN: 12256 default: 12257 return -EOPNOTSUPP; 12258 } 12259 12260 /* not much point in registering if we can't reply */ 12261 if (!rdev->ops->mgmt_tx) 12262 return -EOPNOTSUPP; 12263 12264 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && 12265 !wiphy_ext_feature_isset(&rdev->wiphy, 12266 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { 12267 GENL_SET_ERR_MSG(info, 12268 "multicast RX registrations are not supported"); 12269 return -EOPNOTSUPP; 12270 } 12271 12272 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, 12273 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 12274 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), 12275 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], 12276 info->extack); 12277 } 12278 12279 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) 12280 { 12281 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12282 struct wireless_dev *wdev = info->user_ptr[1]; 12283 struct cfg80211_chan_def chandef; 12284 int err; 12285 void *hdr = NULL; 12286 u64 cookie; 12287 struct sk_buff *msg = NULL; 12288 struct cfg80211_mgmt_tx_params params = { 12289 .dont_wait_for_ack = 12290 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], 12291 }; 12292 12293 if (!info->attrs[NL80211_ATTR_FRAME]) 12294 return -EINVAL; 12295 12296 if (!rdev->ops->mgmt_tx) 12297 return -EOPNOTSUPP; 12298 12299 switch (wdev->iftype) { 12300 case NL80211_IFTYPE_P2P_DEVICE: 12301 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 12302 return -EINVAL; 12303 break; 12304 case NL80211_IFTYPE_STATION: 12305 case NL80211_IFTYPE_ADHOC: 12306 case NL80211_IFTYPE_P2P_CLIENT: 12307 case NL80211_IFTYPE_AP: 12308 case NL80211_IFTYPE_AP_VLAN: 12309 case NL80211_IFTYPE_MESH_POINT: 12310 case NL80211_IFTYPE_P2P_GO: 12311 break; 12312 case NL80211_IFTYPE_NAN: 12313 default: 12314 return -EOPNOTSUPP; 12315 } 12316 12317 if (info->attrs[NL80211_ATTR_DURATION]) { 12318 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 12319 return -EINVAL; 12320 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 12321 12322 /* 12323 * We should wait on the channel for at least a minimum amount 12324 * of time (10ms) but no longer than the driver supports. 12325 */ 12326 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 12327 params.wait > rdev->wiphy.max_remain_on_channel_duration) 12328 return -EINVAL; 12329 } 12330 12331 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; 12332 12333 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 12334 return -EINVAL; 12335 12336 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 12337 12338 /* get the channel if any has been specified, otherwise pass NULL to 12339 * the driver. The latter will use the current one 12340 */ 12341 chandef.chan = NULL; 12342 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 12343 err = nl80211_parse_chandef(rdev, info, &chandef); 12344 if (err) 12345 return err; 12346 } 12347 12348 if (!chandef.chan && params.offchan) 12349 return -EINVAL; 12350 12351 wdev_lock(wdev); 12352 if (params.offchan && 12353 !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { 12354 wdev_unlock(wdev); 12355 return -EBUSY; 12356 } 12357 12358 params.link_id = nl80211_link_id_or_invalid(info->attrs); 12359 /* 12360 * This now races due to the unlock, but we cannot check 12361 * the valid links for the _station_ anyway, so that's up 12362 * to the driver. 12363 */ 12364 if (params.link_id >= 0 && 12365 !(wdev->valid_links & BIT(params.link_id))) { 12366 wdev_unlock(wdev); 12367 return -EINVAL; 12368 } 12369 wdev_unlock(wdev); 12370 12371 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 12372 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 12373 12374 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { 12375 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 12376 int i; 12377 12378 if (len % sizeof(u16)) 12379 return -EINVAL; 12380 12381 params.n_csa_offsets = len / sizeof(u16); 12382 params.csa_offsets = 12383 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 12384 12385 /* check that all the offsets fit the frame */ 12386 for (i = 0; i < params.n_csa_offsets; i++) { 12387 if (params.csa_offsets[i] >= params.len) 12388 return -EINVAL; 12389 } 12390 } 12391 12392 if (!params.dont_wait_for_ack) { 12393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12394 if (!msg) 12395 return -ENOMEM; 12396 12397 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12398 NL80211_CMD_FRAME); 12399 if (!hdr) { 12400 err = -ENOBUFS; 12401 goto free_msg; 12402 } 12403 } 12404 12405 params.chan = chandef.chan; 12406 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); 12407 if (err) 12408 goto free_msg; 12409 12410 if (msg) { 12411 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12412 NL80211_ATTR_PAD)) 12413 goto nla_put_failure; 12414 12415 genlmsg_end(msg, hdr); 12416 return genlmsg_reply(msg, info); 12417 } 12418 12419 return 0; 12420 12421 nla_put_failure: 12422 err = -ENOBUFS; 12423 free_msg: 12424 nlmsg_free(msg); 12425 return err; 12426 } 12427 12428 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) 12429 { 12430 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12431 struct wireless_dev *wdev = info->user_ptr[1]; 12432 u64 cookie; 12433 12434 if (!info->attrs[NL80211_ATTR_COOKIE]) 12435 return -EINVAL; 12436 12437 if (!rdev->ops->mgmt_tx_cancel_wait) 12438 return -EOPNOTSUPP; 12439 12440 switch (wdev->iftype) { 12441 case NL80211_IFTYPE_STATION: 12442 case NL80211_IFTYPE_ADHOC: 12443 case NL80211_IFTYPE_P2P_CLIENT: 12444 case NL80211_IFTYPE_AP: 12445 case NL80211_IFTYPE_AP_VLAN: 12446 case NL80211_IFTYPE_P2P_GO: 12447 case NL80211_IFTYPE_P2P_DEVICE: 12448 break; 12449 case NL80211_IFTYPE_NAN: 12450 default: 12451 return -EOPNOTSUPP; 12452 } 12453 12454 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12455 12456 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); 12457 } 12458 12459 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 12460 { 12461 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12462 struct wireless_dev *wdev; 12463 struct net_device *dev = info->user_ptr[1]; 12464 u8 ps_state; 12465 bool state; 12466 int err; 12467 12468 if (!info->attrs[NL80211_ATTR_PS_STATE]) 12469 return -EINVAL; 12470 12471 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 12472 12473 wdev = dev->ieee80211_ptr; 12474 12475 if (!rdev->ops->set_power_mgmt) 12476 return -EOPNOTSUPP; 12477 12478 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 12479 12480 if (state == wdev->ps) 12481 return 0; 12482 12483 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); 12484 if (!err) 12485 wdev->ps = state; 12486 return err; 12487 } 12488 12489 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 12490 { 12491 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12492 enum nl80211_ps_state ps_state; 12493 struct wireless_dev *wdev; 12494 struct net_device *dev = info->user_ptr[1]; 12495 struct sk_buff *msg; 12496 void *hdr; 12497 int err; 12498 12499 wdev = dev->ieee80211_ptr; 12500 12501 if (!rdev->ops->set_power_mgmt) 12502 return -EOPNOTSUPP; 12503 12504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12505 if (!msg) 12506 return -ENOMEM; 12507 12508 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12509 NL80211_CMD_GET_POWER_SAVE); 12510 if (!hdr) { 12511 err = -ENOBUFS; 12512 goto free_msg; 12513 } 12514 12515 if (wdev->ps) 12516 ps_state = NL80211_PS_ENABLED; 12517 else 12518 ps_state = NL80211_PS_DISABLED; 12519 12520 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) 12521 goto nla_put_failure; 12522 12523 genlmsg_end(msg, hdr); 12524 return genlmsg_reply(msg, info); 12525 12526 nla_put_failure: 12527 err = -ENOBUFS; 12528 free_msg: 12529 nlmsg_free(msg); 12530 return err; 12531 } 12532 12533 static const struct nla_policy 12534 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { 12535 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, 12536 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, 12537 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, 12538 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, 12539 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, 12540 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, 12541 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, 12542 }; 12543 12544 static int nl80211_set_cqm_txe(struct genl_info *info, 12545 u32 rate, u32 pkts, u32 intvl) 12546 { 12547 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12548 struct net_device *dev = info->user_ptr[1]; 12549 struct wireless_dev *wdev = dev->ieee80211_ptr; 12550 12551 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) 12552 return -EINVAL; 12553 12554 if (!rdev->ops->set_cqm_txe_config) 12555 return -EOPNOTSUPP; 12556 12557 if (wdev->iftype != NL80211_IFTYPE_STATION && 12558 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 12559 return -EOPNOTSUPP; 12560 12561 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); 12562 } 12563 12564 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, 12565 struct net_device *dev) 12566 { 12567 struct wireless_dev *wdev = dev->ieee80211_ptr; 12568 s32 last, low, high; 12569 u32 hyst; 12570 int i, n, low_index; 12571 int err; 12572 12573 /* RSSI reporting disabled? */ 12574 if (!wdev->cqm_config) 12575 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); 12576 12577 /* 12578 * Obtain current RSSI value if possible, if not and no RSSI threshold 12579 * event has been received yet, we should receive an event after a 12580 * connection is established and enough beacons received to calculate 12581 * the average. 12582 */ 12583 if (!wdev->cqm_config->last_rssi_event_value && 12584 wdev->links[0].client.current_bss && 12585 rdev->ops->get_station) { 12586 struct station_info sinfo = {}; 12587 u8 *mac_addr; 12588 12589 mac_addr = wdev->links[0].client.current_bss->pub.bssid; 12590 12591 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 12592 if (err) 12593 return err; 12594 12595 cfg80211_sinfo_release_content(&sinfo); 12596 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) 12597 wdev->cqm_config->last_rssi_event_value = 12598 (s8) sinfo.rx_beacon_signal_avg; 12599 } 12600 12601 last = wdev->cqm_config->last_rssi_event_value; 12602 hyst = wdev->cqm_config->rssi_hyst; 12603 n = wdev->cqm_config->n_rssi_thresholds; 12604 12605 for (i = 0; i < n; i++) { 12606 i = array_index_nospec(i, n); 12607 if (last < wdev->cqm_config->rssi_thresholds[i]) 12608 break; 12609 } 12610 12611 low_index = i - 1; 12612 if (low_index >= 0) { 12613 low_index = array_index_nospec(low_index, n); 12614 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; 12615 } else { 12616 low = S32_MIN; 12617 } 12618 if (i < n) { 12619 i = array_index_nospec(i, n); 12620 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; 12621 } else { 12622 high = S32_MAX; 12623 } 12624 12625 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); 12626 } 12627 12628 static int nl80211_set_cqm_rssi(struct genl_info *info, 12629 const s32 *thresholds, int n_thresholds, 12630 u32 hysteresis) 12631 { 12632 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12633 struct net_device *dev = info->user_ptr[1]; 12634 struct wireless_dev *wdev = dev->ieee80211_ptr; 12635 int i, err; 12636 s32 prev = S32_MIN; 12637 12638 /* Check all values negative and sorted */ 12639 for (i = 0; i < n_thresholds; i++) { 12640 if (thresholds[i] > 0 || thresholds[i] <= prev) 12641 return -EINVAL; 12642 12643 prev = thresholds[i]; 12644 } 12645 12646 if (wdev->iftype != NL80211_IFTYPE_STATION && 12647 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 12648 return -EOPNOTSUPP; 12649 12650 wdev_lock(wdev); 12651 cfg80211_cqm_config_free(wdev); 12652 wdev_unlock(wdev); 12653 12654 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { 12655 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ 12656 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); 12657 12658 return rdev_set_cqm_rssi_config(rdev, dev, 12659 thresholds[0], hysteresis); 12660 } 12661 12662 if (!wiphy_ext_feature_isset(&rdev->wiphy, 12663 NL80211_EXT_FEATURE_CQM_RSSI_LIST)) 12664 return -EOPNOTSUPP; 12665 12666 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ 12667 n_thresholds = 0; 12668 12669 wdev_lock(wdev); 12670 if (n_thresholds) { 12671 struct cfg80211_cqm_config *cqm_config; 12672 12673 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, 12674 n_thresholds), 12675 GFP_KERNEL); 12676 if (!cqm_config) { 12677 err = -ENOMEM; 12678 goto unlock; 12679 } 12680 12681 cqm_config->rssi_hyst = hysteresis; 12682 cqm_config->n_rssi_thresholds = n_thresholds; 12683 memcpy(cqm_config->rssi_thresholds, thresholds, 12684 flex_array_size(cqm_config, rssi_thresholds, 12685 n_thresholds)); 12686 12687 wdev->cqm_config = cqm_config; 12688 } 12689 12690 err = cfg80211_cqm_rssi_update(rdev, dev); 12691 12692 unlock: 12693 wdev_unlock(wdev); 12694 12695 return err; 12696 } 12697 12698 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 12699 { 12700 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; 12701 struct nlattr *cqm; 12702 int err; 12703 12704 cqm = info->attrs[NL80211_ATTR_CQM]; 12705 if (!cqm) 12706 return -EINVAL; 12707 12708 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, 12709 nl80211_attr_cqm_policy, 12710 info->extack); 12711 if (err) 12712 return err; 12713 12714 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && 12715 attrs[NL80211_ATTR_CQM_RSSI_HYST]) { 12716 const s32 *thresholds = 12717 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 12718 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 12719 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); 12720 12721 if (len % 4) 12722 return -EINVAL; 12723 12724 return nl80211_set_cqm_rssi(info, thresholds, len / 4, 12725 hysteresis); 12726 } 12727 12728 if (attrs[NL80211_ATTR_CQM_TXE_RATE] && 12729 attrs[NL80211_ATTR_CQM_TXE_PKTS] && 12730 attrs[NL80211_ATTR_CQM_TXE_INTVL]) { 12731 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); 12732 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); 12733 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); 12734 12735 return nl80211_set_cqm_txe(info, rate, pkts, intvl); 12736 } 12737 12738 return -EINVAL; 12739 } 12740 12741 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) 12742 { 12743 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12744 struct net_device *dev = info->user_ptr[1]; 12745 struct ocb_setup setup = {}; 12746 int err; 12747 12748 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 12749 if (err) 12750 return err; 12751 12752 return cfg80211_join_ocb(rdev, dev, &setup); 12753 } 12754 12755 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) 12756 { 12757 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12758 struct net_device *dev = info->user_ptr[1]; 12759 12760 return cfg80211_leave_ocb(rdev, dev); 12761 } 12762 12763 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 12764 { 12765 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12766 struct net_device *dev = info->user_ptr[1]; 12767 struct mesh_config cfg; 12768 struct mesh_setup setup; 12769 int err; 12770 12771 /* start with default */ 12772 memcpy(&cfg, &default_mesh_config, sizeof(cfg)); 12773 memcpy(&setup, &default_mesh_setup, sizeof(setup)); 12774 12775 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { 12776 /* and parse parameters if given */ 12777 err = nl80211_parse_mesh_config(info, &cfg, NULL); 12778 if (err) 12779 return err; 12780 } 12781 12782 if (!info->attrs[NL80211_ATTR_MESH_ID] || 12783 !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) 12784 return -EINVAL; 12785 12786 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 12787 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 12788 12789 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 12790 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, 12791 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 12792 return -EINVAL; 12793 12794 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { 12795 setup.beacon_interval = 12796 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 12797 12798 err = cfg80211_validate_beacon_int(rdev, 12799 NL80211_IFTYPE_MESH_POINT, 12800 setup.beacon_interval); 12801 if (err) 12802 return err; 12803 } 12804 12805 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 12806 setup.dtim_period = 12807 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 12808 if (setup.dtim_period < 1 || setup.dtim_period > 100) 12809 return -EINVAL; 12810 } 12811 12812 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 12813 /* parse additional setup parameters if given */ 12814 err = nl80211_parse_mesh_setup(info, &setup); 12815 if (err) 12816 return err; 12817 } 12818 12819 if (setup.user_mpm) 12820 cfg.auto_open_plinks = false; 12821 12822 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 12823 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 12824 if (err) 12825 return err; 12826 } else { 12827 /* __cfg80211_join_mesh() will sort it out */ 12828 setup.chandef.chan = NULL; 12829 } 12830 12831 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 12832 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 12833 int n_rates = 12834 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 12835 struct ieee80211_supported_band *sband; 12836 12837 if (!setup.chandef.chan) 12838 return -EINVAL; 12839 12840 sband = rdev->wiphy.bands[setup.chandef.chan->band]; 12841 12842 err = ieee80211_get_ratemask(sband, rates, n_rates, 12843 &setup.basic_rates); 12844 if (err) 12845 return err; 12846 } 12847 12848 if (info->attrs[NL80211_ATTR_TX_RATES]) { 12849 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 12850 NL80211_ATTR_TX_RATES, 12851 &setup.beacon_rate, 12852 dev, false, 0); 12853 if (err) 12854 return err; 12855 12856 if (!setup.chandef.chan) 12857 return -EINVAL; 12858 12859 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, 12860 &setup.beacon_rate); 12861 if (err) 12862 return err; 12863 } 12864 12865 setup.userspace_handles_dfs = 12866 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 12867 12868 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 12869 int r = validate_pae_over_nl80211(rdev, info); 12870 12871 if (r < 0) 12872 return r; 12873 12874 setup.control_port_over_nl80211 = true; 12875 } 12876 12877 wdev_lock(dev->ieee80211_ptr); 12878 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); 12879 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) 12880 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 12881 wdev_unlock(dev->ieee80211_ptr); 12882 12883 return err; 12884 } 12885 12886 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) 12887 { 12888 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12889 struct net_device *dev = info->user_ptr[1]; 12890 12891 return cfg80211_leave_mesh(rdev, dev); 12892 } 12893 12894 #ifdef CONFIG_PM 12895 static int nl80211_send_wowlan_patterns(struct sk_buff *msg, 12896 struct cfg80211_registered_device *rdev) 12897 { 12898 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; 12899 struct nlattr *nl_pats, *nl_pat; 12900 int i, pat_len; 12901 12902 if (!wowlan->n_patterns) 12903 return 0; 12904 12905 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 12906 if (!nl_pats) 12907 return -ENOBUFS; 12908 12909 for (i = 0; i < wowlan->n_patterns; i++) { 12910 nl_pat = nla_nest_start_noflag(msg, i + 1); 12911 if (!nl_pat) 12912 return -ENOBUFS; 12913 pat_len = wowlan->patterns[i].pattern_len; 12914 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), 12915 wowlan->patterns[i].mask) || 12916 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 12917 wowlan->patterns[i].pattern) || 12918 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 12919 wowlan->patterns[i].pkt_offset)) 12920 return -ENOBUFS; 12921 nla_nest_end(msg, nl_pat); 12922 } 12923 nla_nest_end(msg, nl_pats); 12924 12925 return 0; 12926 } 12927 12928 static int nl80211_send_wowlan_tcp(struct sk_buff *msg, 12929 struct cfg80211_wowlan_tcp *tcp) 12930 { 12931 struct nlattr *nl_tcp; 12932 12933 if (!tcp) 12934 return 0; 12935 12936 nl_tcp = nla_nest_start_noflag(msg, 12937 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 12938 if (!nl_tcp) 12939 return -ENOBUFS; 12940 12941 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 12942 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 12943 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 12944 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 12945 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || 12946 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 12947 tcp->payload_len, tcp->payload) || 12948 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 12949 tcp->data_interval) || 12950 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 12951 tcp->wake_len, tcp->wake_data) || 12952 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, 12953 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) 12954 return -ENOBUFS; 12955 12956 if (tcp->payload_seq.len && 12957 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, 12958 sizeof(tcp->payload_seq), &tcp->payload_seq)) 12959 return -ENOBUFS; 12960 12961 if (tcp->payload_tok.len && 12962 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 12963 sizeof(tcp->payload_tok) + tcp->tokens_size, 12964 &tcp->payload_tok)) 12965 return -ENOBUFS; 12966 12967 nla_nest_end(msg, nl_tcp); 12968 12969 return 0; 12970 } 12971 12972 static int nl80211_send_wowlan_nd(struct sk_buff *msg, 12973 struct cfg80211_sched_scan_request *req) 12974 { 12975 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; 12976 int i; 12977 12978 if (!req) 12979 return 0; 12980 12981 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 12982 if (!nd) 12983 return -ENOBUFS; 12984 12985 if (req->n_scan_plans == 1 && 12986 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, 12987 req->scan_plans[0].interval * 1000)) 12988 return -ENOBUFS; 12989 12990 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) 12991 return -ENOBUFS; 12992 12993 if (req->relative_rssi_set) { 12994 struct nl80211_bss_select_rssi_adjust rssi_adjust; 12995 12996 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, 12997 req->relative_rssi)) 12998 return -ENOBUFS; 12999 13000 rssi_adjust.band = req->rssi_adjust.band; 13001 rssi_adjust.delta = req->rssi_adjust.delta; 13002 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, 13003 sizeof(rssi_adjust), &rssi_adjust)) 13004 return -ENOBUFS; 13005 } 13006 13007 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 13008 if (!freqs) 13009 return -ENOBUFS; 13010 13011 for (i = 0; i < req->n_channels; i++) { 13012 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 13013 return -ENOBUFS; 13014 } 13015 13016 nla_nest_end(msg, freqs); 13017 13018 if (req->n_match_sets) { 13019 matches = nla_nest_start_noflag(msg, 13020 NL80211_ATTR_SCHED_SCAN_MATCH); 13021 if (!matches) 13022 return -ENOBUFS; 13023 13024 for (i = 0; i < req->n_match_sets; i++) { 13025 match = nla_nest_start_noflag(msg, i); 13026 if (!match) 13027 return -ENOBUFS; 13028 13029 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, 13030 req->match_sets[i].ssid.ssid_len, 13031 req->match_sets[i].ssid.ssid)) 13032 return -ENOBUFS; 13033 nla_nest_end(msg, match); 13034 } 13035 nla_nest_end(msg, matches); 13036 } 13037 13038 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 13039 if (!scan_plans) 13040 return -ENOBUFS; 13041 13042 for (i = 0; i < req->n_scan_plans; i++) { 13043 scan_plan = nla_nest_start_noflag(msg, i + 1); 13044 if (!scan_plan) 13045 return -ENOBUFS; 13046 13047 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, 13048 req->scan_plans[i].interval) || 13049 (req->scan_plans[i].iterations && 13050 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, 13051 req->scan_plans[i].iterations))) 13052 return -ENOBUFS; 13053 nla_nest_end(msg, scan_plan); 13054 } 13055 nla_nest_end(msg, scan_plans); 13056 13057 nla_nest_end(msg, nd); 13058 13059 return 0; 13060 } 13061 13062 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) 13063 { 13064 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13065 struct sk_buff *msg; 13066 void *hdr; 13067 u32 size = NLMSG_DEFAULT_SIZE; 13068 13069 if (!rdev->wiphy.wowlan) 13070 return -EOPNOTSUPP; 13071 13072 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { 13073 /* adjust size to have room for all the data */ 13074 size += rdev->wiphy.wowlan_config->tcp->tokens_size + 13075 rdev->wiphy.wowlan_config->tcp->payload_len + 13076 rdev->wiphy.wowlan_config->tcp->wake_len + 13077 rdev->wiphy.wowlan_config->tcp->wake_len / 8; 13078 } 13079 13080 msg = nlmsg_new(size, GFP_KERNEL); 13081 if (!msg) 13082 return -ENOMEM; 13083 13084 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13085 NL80211_CMD_GET_WOWLAN); 13086 if (!hdr) 13087 goto nla_put_failure; 13088 13089 if (rdev->wiphy.wowlan_config) { 13090 struct nlattr *nl_wowlan; 13091 13092 nl_wowlan = nla_nest_start_noflag(msg, 13093 NL80211_ATTR_WOWLAN_TRIGGERS); 13094 if (!nl_wowlan) 13095 goto nla_put_failure; 13096 13097 if ((rdev->wiphy.wowlan_config->any && 13098 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 13099 (rdev->wiphy.wowlan_config->disconnect && 13100 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 13101 (rdev->wiphy.wowlan_config->magic_pkt && 13102 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 13103 (rdev->wiphy.wowlan_config->gtk_rekey_failure && 13104 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 13105 (rdev->wiphy.wowlan_config->eap_identity_req && 13106 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 13107 (rdev->wiphy.wowlan_config->four_way_handshake && 13108 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 13109 (rdev->wiphy.wowlan_config->rfkill_release && 13110 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 13111 goto nla_put_failure; 13112 13113 if (nl80211_send_wowlan_patterns(msg, rdev)) 13114 goto nla_put_failure; 13115 13116 if (nl80211_send_wowlan_tcp(msg, 13117 rdev->wiphy.wowlan_config->tcp)) 13118 goto nla_put_failure; 13119 13120 if (nl80211_send_wowlan_nd( 13121 msg, 13122 rdev->wiphy.wowlan_config->nd_config)) 13123 goto nla_put_failure; 13124 13125 nla_nest_end(msg, nl_wowlan); 13126 } 13127 13128 genlmsg_end(msg, hdr); 13129 return genlmsg_reply(msg, info); 13130 13131 nla_put_failure: 13132 nlmsg_free(msg); 13133 return -ENOBUFS; 13134 } 13135 13136 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, 13137 struct nlattr *attr, 13138 struct cfg80211_wowlan *trig) 13139 { 13140 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; 13141 struct cfg80211_wowlan_tcp *cfg; 13142 struct nl80211_wowlan_tcp_data_token *tok = NULL; 13143 struct nl80211_wowlan_tcp_data_seq *seq = NULL; 13144 u32 size; 13145 u32 data_size, wake_size, tokens_size = 0, wake_mask_size; 13146 int err, port; 13147 13148 if (!rdev->wiphy.wowlan->tcp) 13149 return -EINVAL; 13150 13151 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, 13152 nl80211_wowlan_tcp_policy, NULL); 13153 if (err) 13154 return err; 13155 13156 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || 13157 !tb[NL80211_WOWLAN_TCP_DST_IPV4] || 13158 !tb[NL80211_WOWLAN_TCP_DST_MAC] || 13159 !tb[NL80211_WOWLAN_TCP_DST_PORT] || 13160 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || 13161 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || 13162 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || 13163 !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) 13164 return -EINVAL; 13165 13166 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); 13167 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) 13168 return -EINVAL; 13169 13170 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > 13171 rdev->wiphy.wowlan->tcp->data_interval_max || 13172 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) 13173 return -EINVAL; 13174 13175 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); 13176 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) 13177 return -EINVAL; 13178 13179 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); 13180 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) 13181 return -EINVAL; 13182 13183 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { 13184 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 13185 13186 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 13187 tokens_size = tokln - sizeof(*tok); 13188 13189 if (!tok->len || tokens_size % tok->len) 13190 return -EINVAL; 13191 if (!rdev->wiphy.wowlan->tcp->tok) 13192 return -EINVAL; 13193 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) 13194 return -EINVAL; 13195 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) 13196 return -EINVAL; 13197 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) 13198 return -EINVAL; 13199 if (tok->offset + tok->len > data_size) 13200 return -EINVAL; 13201 } 13202 13203 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { 13204 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); 13205 if (!rdev->wiphy.wowlan->tcp->seq) 13206 return -EINVAL; 13207 if (seq->len == 0 || seq->len > 4) 13208 return -EINVAL; 13209 if (seq->len + seq->offset > data_size) 13210 return -EINVAL; 13211 } 13212 13213 size = sizeof(*cfg); 13214 size += data_size; 13215 size += wake_size + wake_mask_size; 13216 size += tokens_size; 13217 13218 cfg = kzalloc(size, GFP_KERNEL); 13219 if (!cfg) 13220 return -ENOMEM; 13221 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); 13222 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 13223 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 13224 ETH_ALEN); 13225 if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 13226 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 13227 else 13228 port = 0; 13229 #ifdef CONFIG_INET 13230 /* allocate a socket and port for it and use it */ 13231 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, 13232 IPPROTO_TCP, &cfg->sock, 1); 13233 if (err) { 13234 kfree(cfg); 13235 return err; 13236 } 13237 if (inet_csk_get_port(cfg->sock->sk, port)) { 13238 sock_release(cfg->sock); 13239 kfree(cfg); 13240 return -EADDRINUSE; 13241 } 13242 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; 13243 #else 13244 if (!port) { 13245 kfree(cfg); 13246 return -EINVAL; 13247 } 13248 cfg->src_port = port; 13249 #endif 13250 13251 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); 13252 cfg->payload_len = data_size; 13253 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; 13254 memcpy((void *)cfg->payload, 13255 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), 13256 data_size); 13257 if (seq) 13258 cfg->payload_seq = *seq; 13259 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); 13260 cfg->wake_len = wake_size; 13261 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; 13262 memcpy((void *)cfg->wake_data, 13263 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), 13264 wake_size); 13265 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + 13266 data_size + wake_size; 13267 memcpy((void *)cfg->wake_mask, 13268 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), 13269 wake_mask_size); 13270 if (tok) { 13271 cfg->tokens_size = tokens_size; 13272 cfg->payload_tok = *tok; 13273 memcpy(cfg->payload_tok.token_stream, tok->token_stream, 13274 tokens_size); 13275 } 13276 13277 trig->tcp = cfg; 13278 13279 return 0; 13280 } 13281 13282 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, 13283 const struct wiphy_wowlan_support *wowlan, 13284 struct nlattr *attr, 13285 struct cfg80211_wowlan *trig) 13286 { 13287 struct nlattr **tb; 13288 int err; 13289 13290 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 13291 if (!tb) 13292 return -ENOMEM; 13293 13294 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { 13295 err = -EOPNOTSUPP; 13296 goto out; 13297 } 13298 13299 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, 13300 nl80211_policy, NULL); 13301 if (err) 13302 goto out; 13303 13304 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, 13305 wowlan->max_nd_match_sets); 13306 err = PTR_ERR_OR_ZERO(trig->nd_config); 13307 if (err) 13308 trig->nd_config = NULL; 13309 13310 out: 13311 kfree(tb); 13312 return err; 13313 } 13314 13315 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) 13316 { 13317 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13318 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; 13319 struct cfg80211_wowlan new_triggers = {}; 13320 struct cfg80211_wowlan *ntrig; 13321 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; 13322 int err, i; 13323 bool prev_enabled = rdev->wiphy.wowlan_config; 13324 bool regular = false; 13325 13326 if (!wowlan) 13327 return -EOPNOTSUPP; 13328 13329 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { 13330 cfg80211_rdev_free_wowlan(rdev); 13331 rdev->wiphy.wowlan_config = NULL; 13332 goto set_wakeup; 13333 } 13334 13335 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, 13336 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 13337 nl80211_wowlan_policy, info->extack); 13338 if (err) 13339 return err; 13340 13341 if (tb[NL80211_WOWLAN_TRIG_ANY]) { 13342 if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) 13343 return -EINVAL; 13344 new_triggers.any = true; 13345 } 13346 13347 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { 13348 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) 13349 return -EINVAL; 13350 new_triggers.disconnect = true; 13351 regular = true; 13352 } 13353 13354 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { 13355 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) 13356 return -EINVAL; 13357 new_triggers.magic_pkt = true; 13358 regular = true; 13359 } 13360 13361 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) 13362 return -EINVAL; 13363 13364 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { 13365 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) 13366 return -EINVAL; 13367 new_triggers.gtk_rekey_failure = true; 13368 regular = true; 13369 } 13370 13371 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { 13372 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) 13373 return -EINVAL; 13374 new_triggers.eap_identity_req = true; 13375 regular = true; 13376 } 13377 13378 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { 13379 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) 13380 return -EINVAL; 13381 new_triggers.four_way_handshake = true; 13382 regular = true; 13383 } 13384 13385 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { 13386 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) 13387 return -EINVAL; 13388 new_triggers.rfkill_release = true; 13389 regular = true; 13390 } 13391 13392 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { 13393 struct nlattr *pat; 13394 int n_patterns = 0; 13395 int rem, pat_len, mask_len, pkt_offset; 13396 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 13397 13398 regular = true; 13399 13400 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 13401 rem) 13402 n_patterns++; 13403 if (n_patterns > wowlan->n_patterns) 13404 return -EINVAL; 13405 13406 new_triggers.patterns = kcalloc(n_patterns, 13407 sizeof(new_triggers.patterns[0]), 13408 GFP_KERNEL); 13409 if (!new_triggers.patterns) 13410 return -ENOMEM; 13411 13412 new_triggers.n_patterns = n_patterns; 13413 i = 0; 13414 13415 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 13416 rem) { 13417 u8 *mask_pat; 13418 13419 err = nla_parse_nested_deprecated(pat_tb, 13420 MAX_NL80211_PKTPAT, 13421 pat, 13422 nl80211_packet_pattern_policy, 13423 info->extack); 13424 if (err) 13425 goto error; 13426 13427 err = -EINVAL; 13428 if (!pat_tb[NL80211_PKTPAT_MASK] || 13429 !pat_tb[NL80211_PKTPAT_PATTERN]) 13430 goto error; 13431 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 13432 mask_len = DIV_ROUND_UP(pat_len, 8); 13433 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 13434 goto error; 13435 if (pat_len > wowlan->pattern_max_len || 13436 pat_len < wowlan->pattern_min_len) 13437 goto error; 13438 13439 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13440 pkt_offset = 0; 13441 else 13442 pkt_offset = nla_get_u32( 13443 pat_tb[NL80211_PKTPAT_OFFSET]); 13444 if (pkt_offset > wowlan->max_pkt_offset) 13445 goto error; 13446 new_triggers.patterns[i].pkt_offset = pkt_offset; 13447 13448 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 13449 if (!mask_pat) { 13450 err = -ENOMEM; 13451 goto error; 13452 } 13453 new_triggers.patterns[i].mask = mask_pat; 13454 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 13455 mask_len); 13456 mask_pat += mask_len; 13457 new_triggers.patterns[i].pattern = mask_pat; 13458 new_triggers.patterns[i].pattern_len = pat_len; 13459 memcpy(mask_pat, 13460 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 13461 pat_len); 13462 i++; 13463 } 13464 } 13465 13466 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { 13467 regular = true; 13468 err = nl80211_parse_wowlan_tcp( 13469 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], 13470 &new_triggers); 13471 if (err) 13472 goto error; 13473 } 13474 13475 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { 13476 regular = true; 13477 err = nl80211_parse_wowlan_nd( 13478 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], 13479 &new_triggers); 13480 if (err) 13481 goto error; 13482 } 13483 13484 /* The 'any' trigger means the device continues operating more or less 13485 * as in its normal operation mode and wakes up the host on most of the 13486 * normal interrupts (like packet RX, ...) 13487 * It therefore makes little sense to combine with the more constrained 13488 * wakeup trigger modes. 13489 */ 13490 if (new_triggers.any && regular) { 13491 err = -EINVAL; 13492 goto error; 13493 } 13494 13495 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); 13496 if (!ntrig) { 13497 err = -ENOMEM; 13498 goto error; 13499 } 13500 cfg80211_rdev_free_wowlan(rdev); 13501 rdev->wiphy.wowlan_config = ntrig; 13502 13503 set_wakeup: 13504 if (rdev->ops->set_wakeup && 13505 prev_enabled != !!rdev->wiphy.wowlan_config) 13506 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); 13507 13508 return 0; 13509 error: 13510 for (i = 0; i < new_triggers.n_patterns; i++) 13511 kfree(new_triggers.patterns[i].mask); 13512 kfree(new_triggers.patterns); 13513 if (new_triggers.tcp && new_triggers.tcp->sock) 13514 sock_release(new_triggers.tcp->sock); 13515 kfree(new_triggers.tcp); 13516 kfree(new_triggers.nd_config); 13517 return err; 13518 } 13519 #endif 13520 13521 static int nl80211_send_coalesce_rules(struct sk_buff *msg, 13522 struct cfg80211_registered_device *rdev) 13523 { 13524 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; 13525 int i, j, pat_len; 13526 struct cfg80211_coalesce_rules *rule; 13527 13528 if (!rdev->coalesce->n_rules) 13529 return 0; 13530 13531 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); 13532 if (!nl_rules) 13533 return -ENOBUFS; 13534 13535 for (i = 0; i < rdev->coalesce->n_rules; i++) { 13536 nl_rule = nla_nest_start_noflag(msg, i + 1); 13537 if (!nl_rule) 13538 return -ENOBUFS; 13539 13540 rule = &rdev->coalesce->rules[i]; 13541 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, 13542 rule->delay)) 13543 return -ENOBUFS; 13544 13545 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, 13546 rule->condition)) 13547 return -ENOBUFS; 13548 13549 nl_pats = nla_nest_start_noflag(msg, 13550 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 13551 if (!nl_pats) 13552 return -ENOBUFS; 13553 13554 for (j = 0; j < rule->n_patterns; j++) { 13555 nl_pat = nla_nest_start_noflag(msg, j + 1); 13556 if (!nl_pat) 13557 return -ENOBUFS; 13558 pat_len = rule->patterns[j].pattern_len; 13559 if (nla_put(msg, NL80211_PKTPAT_MASK, 13560 DIV_ROUND_UP(pat_len, 8), 13561 rule->patterns[j].mask) || 13562 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 13563 rule->patterns[j].pattern) || 13564 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 13565 rule->patterns[j].pkt_offset)) 13566 return -ENOBUFS; 13567 nla_nest_end(msg, nl_pat); 13568 } 13569 nla_nest_end(msg, nl_pats); 13570 nla_nest_end(msg, nl_rule); 13571 } 13572 nla_nest_end(msg, nl_rules); 13573 13574 return 0; 13575 } 13576 13577 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) 13578 { 13579 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13580 struct sk_buff *msg; 13581 void *hdr; 13582 13583 if (!rdev->wiphy.coalesce) 13584 return -EOPNOTSUPP; 13585 13586 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13587 if (!msg) 13588 return -ENOMEM; 13589 13590 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13591 NL80211_CMD_GET_COALESCE); 13592 if (!hdr) 13593 goto nla_put_failure; 13594 13595 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) 13596 goto nla_put_failure; 13597 13598 genlmsg_end(msg, hdr); 13599 return genlmsg_reply(msg, info); 13600 13601 nla_put_failure: 13602 nlmsg_free(msg); 13603 return -ENOBUFS; 13604 } 13605 13606 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) 13607 { 13608 struct cfg80211_coalesce *coalesce = rdev->coalesce; 13609 int i, j; 13610 struct cfg80211_coalesce_rules *rule; 13611 13612 if (!coalesce) 13613 return; 13614 13615 for (i = 0; i < coalesce->n_rules; i++) { 13616 rule = &coalesce->rules[i]; 13617 for (j = 0; j < rule->n_patterns; j++) 13618 kfree(rule->patterns[j].mask); 13619 kfree(rule->patterns); 13620 } 13621 kfree(coalesce->rules); 13622 kfree(coalesce); 13623 rdev->coalesce = NULL; 13624 } 13625 13626 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, 13627 struct nlattr *rule, 13628 struct cfg80211_coalesce_rules *new_rule) 13629 { 13630 int err, i; 13631 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 13632 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; 13633 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 13634 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 13635 13636 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, 13637 rule, nl80211_coalesce_policy, NULL); 13638 if (err) 13639 return err; 13640 13641 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) 13642 new_rule->delay = 13643 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); 13644 if (new_rule->delay > coalesce->max_delay) 13645 return -EINVAL; 13646 13647 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) 13648 new_rule->condition = 13649 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); 13650 13651 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) 13652 return -EINVAL; 13653 13654 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 13655 rem) 13656 n_patterns++; 13657 if (n_patterns > coalesce->n_patterns) 13658 return -EINVAL; 13659 13660 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), 13661 GFP_KERNEL); 13662 if (!new_rule->patterns) 13663 return -ENOMEM; 13664 13665 new_rule->n_patterns = n_patterns; 13666 i = 0; 13667 13668 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 13669 rem) { 13670 u8 *mask_pat; 13671 13672 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, 13673 pat, 13674 nl80211_packet_pattern_policy, 13675 NULL); 13676 if (err) 13677 return err; 13678 13679 if (!pat_tb[NL80211_PKTPAT_MASK] || 13680 !pat_tb[NL80211_PKTPAT_PATTERN]) 13681 return -EINVAL; 13682 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 13683 mask_len = DIV_ROUND_UP(pat_len, 8); 13684 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 13685 return -EINVAL; 13686 if (pat_len > coalesce->pattern_max_len || 13687 pat_len < coalesce->pattern_min_len) 13688 return -EINVAL; 13689 13690 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13691 pkt_offset = 0; 13692 else 13693 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 13694 if (pkt_offset > coalesce->max_pkt_offset) 13695 return -EINVAL; 13696 new_rule->patterns[i].pkt_offset = pkt_offset; 13697 13698 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 13699 if (!mask_pat) 13700 return -ENOMEM; 13701 13702 new_rule->patterns[i].mask = mask_pat; 13703 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 13704 mask_len); 13705 13706 mask_pat += mask_len; 13707 new_rule->patterns[i].pattern = mask_pat; 13708 new_rule->patterns[i].pattern_len = pat_len; 13709 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 13710 pat_len); 13711 i++; 13712 } 13713 13714 return 0; 13715 } 13716 13717 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) 13718 { 13719 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13720 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 13721 struct cfg80211_coalesce new_coalesce = {}; 13722 struct cfg80211_coalesce *n_coalesce; 13723 int err, rem_rule, n_rules = 0, i, j; 13724 struct nlattr *rule; 13725 struct cfg80211_coalesce_rules *tmp_rule; 13726 13727 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) 13728 return -EOPNOTSUPP; 13729 13730 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { 13731 cfg80211_rdev_free_coalesce(rdev); 13732 rdev_set_coalesce(rdev, NULL); 13733 return 0; 13734 } 13735 13736 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 13737 rem_rule) 13738 n_rules++; 13739 if (n_rules > coalesce->n_rules) 13740 return -EINVAL; 13741 13742 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), 13743 GFP_KERNEL); 13744 if (!new_coalesce.rules) 13745 return -ENOMEM; 13746 13747 new_coalesce.n_rules = n_rules; 13748 i = 0; 13749 13750 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 13751 rem_rule) { 13752 err = nl80211_parse_coalesce_rule(rdev, rule, 13753 &new_coalesce.rules[i]); 13754 if (err) 13755 goto error; 13756 13757 i++; 13758 } 13759 13760 err = rdev_set_coalesce(rdev, &new_coalesce); 13761 if (err) 13762 goto error; 13763 13764 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); 13765 if (!n_coalesce) { 13766 err = -ENOMEM; 13767 goto error; 13768 } 13769 cfg80211_rdev_free_coalesce(rdev); 13770 rdev->coalesce = n_coalesce; 13771 13772 return 0; 13773 error: 13774 for (i = 0; i < new_coalesce.n_rules; i++) { 13775 tmp_rule = &new_coalesce.rules[i]; 13776 for (j = 0; j < tmp_rule->n_patterns; j++) 13777 kfree(tmp_rule->patterns[j].mask); 13778 kfree(tmp_rule->patterns); 13779 } 13780 kfree(new_coalesce.rules); 13781 13782 return err; 13783 } 13784 13785 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) 13786 { 13787 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13788 struct net_device *dev = info->user_ptr[1]; 13789 struct wireless_dev *wdev = dev->ieee80211_ptr; 13790 struct nlattr *tb[NUM_NL80211_REKEY_DATA]; 13791 struct cfg80211_gtk_rekey_data rekey_data = {}; 13792 int err; 13793 13794 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 13795 return -EINVAL; 13796 13797 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, 13798 info->attrs[NL80211_ATTR_REKEY_DATA], 13799 nl80211_rekey_policy, info->extack); 13800 if (err) 13801 return err; 13802 13803 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || 13804 !tb[NL80211_REKEY_DATA_KCK]) 13805 return -EINVAL; 13806 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && 13807 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 13808 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) 13809 return -ERANGE; 13810 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && 13811 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 13812 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN) && 13813 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KCK_32 && 13814 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN_32)) 13815 return -ERANGE; 13816 13817 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); 13818 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); 13819 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); 13820 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); 13821 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); 13822 if (tb[NL80211_REKEY_DATA_AKM]) 13823 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); 13824 13825 wdev_lock(wdev); 13826 if (!wdev->connected) { 13827 err = -ENOTCONN; 13828 goto out; 13829 } 13830 13831 if (!rdev->ops->set_rekey_data) { 13832 err = -EOPNOTSUPP; 13833 goto out; 13834 } 13835 13836 err = rdev_set_rekey_data(rdev, dev, &rekey_data); 13837 out: 13838 wdev_unlock(wdev); 13839 return err; 13840 } 13841 13842 static int nl80211_register_unexpected_frame(struct sk_buff *skb, 13843 struct genl_info *info) 13844 { 13845 struct net_device *dev = info->user_ptr[1]; 13846 struct wireless_dev *wdev = dev->ieee80211_ptr; 13847 13848 if (wdev->iftype != NL80211_IFTYPE_AP && 13849 wdev->iftype != NL80211_IFTYPE_P2P_GO) 13850 return -EINVAL; 13851 13852 if (wdev->ap_unexpected_nlportid) 13853 return -EBUSY; 13854 13855 wdev->ap_unexpected_nlportid = info->snd_portid; 13856 return 0; 13857 } 13858 13859 static int nl80211_probe_client(struct sk_buff *skb, 13860 struct genl_info *info) 13861 { 13862 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13863 struct net_device *dev = info->user_ptr[1]; 13864 struct wireless_dev *wdev = dev->ieee80211_ptr; 13865 struct sk_buff *msg; 13866 void *hdr; 13867 const u8 *addr; 13868 u64 cookie; 13869 int err; 13870 13871 if (wdev->iftype != NL80211_IFTYPE_AP && 13872 wdev->iftype != NL80211_IFTYPE_P2P_GO) 13873 return -EOPNOTSUPP; 13874 13875 if (!info->attrs[NL80211_ATTR_MAC]) 13876 return -EINVAL; 13877 13878 if (!rdev->ops->probe_client) 13879 return -EOPNOTSUPP; 13880 13881 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13882 if (!msg) 13883 return -ENOMEM; 13884 13885 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13886 NL80211_CMD_PROBE_CLIENT); 13887 if (!hdr) { 13888 err = -ENOBUFS; 13889 goto free_msg; 13890 } 13891 13892 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 13893 13894 err = rdev_probe_client(rdev, dev, addr, &cookie); 13895 if (err) 13896 goto free_msg; 13897 13898 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 13899 NL80211_ATTR_PAD)) 13900 goto nla_put_failure; 13901 13902 genlmsg_end(msg, hdr); 13903 13904 return genlmsg_reply(msg, info); 13905 13906 nla_put_failure: 13907 err = -ENOBUFS; 13908 free_msg: 13909 nlmsg_free(msg); 13910 return err; 13911 } 13912 13913 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) 13914 { 13915 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13916 struct cfg80211_beacon_registration *reg, *nreg; 13917 int rv; 13918 13919 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) 13920 return -EOPNOTSUPP; 13921 13922 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); 13923 if (!nreg) 13924 return -ENOMEM; 13925 13926 /* First, check if already registered. */ 13927 spin_lock_bh(&rdev->beacon_registrations_lock); 13928 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 13929 if (reg->nlportid == info->snd_portid) { 13930 rv = -EALREADY; 13931 goto out_err; 13932 } 13933 } 13934 /* Add it to the list */ 13935 nreg->nlportid = info->snd_portid; 13936 list_add(&nreg->list, &rdev->beacon_registrations); 13937 13938 spin_unlock_bh(&rdev->beacon_registrations_lock); 13939 13940 return 0; 13941 out_err: 13942 spin_unlock_bh(&rdev->beacon_registrations_lock); 13943 kfree(nreg); 13944 return rv; 13945 } 13946 13947 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) 13948 { 13949 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13950 struct wireless_dev *wdev = info->user_ptr[1]; 13951 int err; 13952 13953 if (!rdev->ops->start_p2p_device) 13954 return -EOPNOTSUPP; 13955 13956 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 13957 return -EOPNOTSUPP; 13958 13959 if (wdev_running(wdev)) 13960 return 0; 13961 13962 if (rfkill_blocked(rdev->wiphy.rfkill)) 13963 return -ERFKILL; 13964 13965 err = rdev_start_p2p_device(rdev, wdev); 13966 if (err) 13967 return err; 13968 13969 wdev->is_running = true; 13970 rdev->opencount++; 13971 13972 return 0; 13973 } 13974 13975 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) 13976 { 13977 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13978 struct wireless_dev *wdev = info->user_ptr[1]; 13979 13980 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 13981 return -EOPNOTSUPP; 13982 13983 if (!rdev->ops->stop_p2p_device) 13984 return -EOPNOTSUPP; 13985 13986 cfg80211_stop_p2p_device(rdev, wdev); 13987 13988 return 0; 13989 } 13990 13991 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) 13992 { 13993 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13994 struct wireless_dev *wdev = info->user_ptr[1]; 13995 struct cfg80211_nan_conf conf = {}; 13996 int err; 13997 13998 if (wdev->iftype != NL80211_IFTYPE_NAN) 13999 return -EOPNOTSUPP; 14000 14001 if (wdev_running(wdev)) 14002 return -EEXIST; 14003 14004 if (rfkill_blocked(rdev->wiphy.rfkill)) 14005 return -ERFKILL; 14006 14007 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) 14008 return -EINVAL; 14009 14010 conf.master_pref = 14011 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 14012 14013 if (info->attrs[NL80211_ATTR_BANDS]) { 14014 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 14015 14016 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 14017 return -EOPNOTSUPP; 14018 14019 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 14020 return -EINVAL; 14021 14022 conf.bands = bands; 14023 } 14024 14025 err = rdev_start_nan(rdev, wdev, &conf); 14026 if (err) 14027 return err; 14028 14029 wdev->is_running = true; 14030 rdev->opencount++; 14031 14032 return 0; 14033 } 14034 14035 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) 14036 { 14037 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14038 struct wireless_dev *wdev = info->user_ptr[1]; 14039 14040 if (wdev->iftype != NL80211_IFTYPE_NAN) 14041 return -EOPNOTSUPP; 14042 14043 cfg80211_stop_nan(rdev, wdev); 14044 14045 return 0; 14046 } 14047 14048 static int validate_nan_filter(struct nlattr *filter_attr) 14049 { 14050 struct nlattr *attr; 14051 int len = 0, n_entries = 0, rem; 14052 14053 nla_for_each_nested(attr, filter_attr, rem) { 14054 len += nla_len(attr); 14055 n_entries++; 14056 } 14057 14058 if (len >= U8_MAX) 14059 return -EINVAL; 14060 14061 return n_entries; 14062 } 14063 14064 static int handle_nan_filter(struct nlattr *attr_filter, 14065 struct cfg80211_nan_func *func, 14066 bool tx) 14067 { 14068 struct nlattr *attr; 14069 int n_entries, rem, i; 14070 struct cfg80211_nan_func_filter *filter; 14071 14072 n_entries = validate_nan_filter(attr_filter); 14073 if (n_entries < 0) 14074 return n_entries; 14075 14076 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); 14077 14078 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); 14079 if (!filter) 14080 return -ENOMEM; 14081 14082 i = 0; 14083 nla_for_each_nested(attr, attr_filter, rem) { 14084 filter[i].filter = nla_memdup(attr, GFP_KERNEL); 14085 if (!filter[i].filter) 14086 goto err; 14087 14088 filter[i].len = nla_len(attr); 14089 i++; 14090 } 14091 if (tx) { 14092 func->num_tx_filters = n_entries; 14093 func->tx_filters = filter; 14094 } else { 14095 func->num_rx_filters = n_entries; 14096 func->rx_filters = filter; 14097 } 14098 14099 return 0; 14100 14101 err: 14102 i = 0; 14103 nla_for_each_nested(attr, attr_filter, rem) { 14104 kfree(filter[i].filter); 14105 i++; 14106 } 14107 kfree(filter); 14108 return -ENOMEM; 14109 } 14110 14111 static int nl80211_nan_add_func(struct sk_buff *skb, 14112 struct genl_info *info) 14113 { 14114 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14115 struct wireless_dev *wdev = info->user_ptr[1]; 14116 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; 14117 struct cfg80211_nan_func *func; 14118 struct sk_buff *msg = NULL; 14119 void *hdr = NULL; 14120 int err = 0; 14121 14122 if (wdev->iftype != NL80211_IFTYPE_NAN) 14123 return -EOPNOTSUPP; 14124 14125 if (!wdev_running(wdev)) 14126 return -ENOTCONN; 14127 14128 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 14129 return -EINVAL; 14130 14131 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, 14132 info->attrs[NL80211_ATTR_NAN_FUNC], 14133 nl80211_nan_func_policy, 14134 info->extack); 14135 if (err) 14136 return err; 14137 14138 func = kzalloc(sizeof(*func), GFP_KERNEL); 14139 if (!func) 14140 return -ENOMEM; 14141 14142 func->cookie = cfg80211_assign_cookie(rdev); 14143 14144 if (!tb[NL80211_NAN_FUNC_TYPE]) { 14145 err = -EINVAL; 14146 goto out; 14147 } 14148 14149 14150 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); 14151 14152 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { 14153 err = -EINVAL; 14154 goto out; 14155 } 14156 14157 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), 14158 sizeof(func->service_id)); 14159 14160 func->close_range = 14161 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); 14162 14163 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { 14164 func->serv_spec_info_len = 14165 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); 14166 func->serv_spec_info = 14167 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), 14168 func->serv_spec_info_len, 14169 GFP_KERNEL); 14170 if (!func->serv_spec_info) { 14171 err = -ENOMEM; 14172 goto out; 14173 } 14174 } 14175 14176 if (tb[NL80211_NAN_FUNC_TTL]) 14177 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); 14178 14179 switch (func->type) { 14180 case NL80211_NAN_FUNC_PUBLISH: 14181 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { 14182 err = -EINVAL; 14183 goto out; 14184 } 14185 14186 func->publish_type = 14187 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); 14188 func->publish_bcast = 14189 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); 14190 14191 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && 14192 func->publish_bcast) { 14193 err = -EINVAL; 14194 goto out; 14195 } 14196 break; 14197 case NL80211_NAN_FUNC_SUBSCRIBE: 14198 func->subscribe_active = 14199 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); 14200 break; 14201 case NL80211_NAN_FUNC_FOLLOW_UP: 14202 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || 14203 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || 14204 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { 14205 err = -EINVAL; 14206 goto out; 14207 } 14208 14209 func->followup_id = 14210 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); 14211 func->followup_reqid = 14212 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); 14213 memcpy(func->followup_dest.addr, 14214 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), 14215 sizeof(func->followup_dest.addr)); 14216 if (func->ttl) { 14217 err = -EINVAL; 14218 goto out; 14219 } 14220 break; 14221 default: 14222 err = -EINVAL; 14223 goto out; 14224 } 14225 14226 if (tb[NL80211_NAN_FUNC_SRF]) { 14227 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 14228 14229 err = nla_parse_nested_deprecated(srf_tb, 14230 NL80211_NAN_SRF_ATTR_MAX, 14231 tb[NL80211_NAN_FUNC_SRF], 14232 nl80211_nan_srf_policy, 14233 info->extack); 14234 if (err) 14235 goto out; 14236 14237 func->srf_include = 14238 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); 14239 14240 if (srf_tb[NL80211_NAN_SRF_BF]) { 14241 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || 14242 !srf_tb[NL80211_NAN_SRF_BF_IDX]) { 14243 err = -EINVAL; 14244 goto out; 14245 } 14246 14247 func->srf_bf_len = 14248 nla_len(srf_tb[NL80211_NAN_SRF_BF]); 14249 func->srf_bf = 14250 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), 14251 func->srf_bf_len, GFP_KERNEL); 14252 if (!func->srf_bf) { 14253 err = -ENOMEM; 14254 goto out; 14255 } 14256 14257 func->srf_bf_idx = 14258 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); 14259 } else { 14260 struct nlattr *attr, *mac_attr = 14261 srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; 14262 int n_entries, rem, i = 0; 14263 14264 if (!mac_attr) { 14265 err = -EINVAL; 14266 goto out; 14267 } 14268 14269 n_entries = validate_acl_mac_addrs(mac_attr); 14270 if (n_entries <= 0) { 14271 err = -EINVAL; 14272 goto out; 14273 } 14274 14275 func->srf_num_macs = n_entries; 14276 func->srf_macs = 14277 kcalloc(n_entries, sizeof(*func->srf_macs), 14278 GFP_KERNEL); 14279 if (!func->srf_macs) { 14280 err = -ENOMEM; 14281 goto out; 14282 } 14283 14284 nla_for_each_nested(attr, mac_attr, rem) 14285 memcpy(func->srf_macs[i++].addr, nla_data(attr), 14286 sizeof(*func->srf_macs)); 14287 } 14288 } 14289 14290 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { 14291 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], 14292 func, true); 14293 if (err) 14294 goto out; 14295 } 14296 14297 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { 14298 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], 14299 func, false); 14300 if (err) 14301 goto out; 14302 } 14303 14304 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14305 if (!msg) { 14306 err = -ENOMEM; 14307 goto out; 14308 } 14309 14310 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14311 NL80211_CMD_ADD_NAN_FUNCTION); 14312 /* This can't really happen - we just allocated 4KB */ 14313 if (WARN_ON(!hdr)) { 14314 err = -ENOMEM; 14315 goto out; 14316 } 14317 14318 err = rdev_add_nan_func(rdev, wdev, func); 14319 out: 14320 if (err < 0) { 14321 cfg80211_free_nan_func(func); 14322 nlmsg_free(msg); 14323 return err; 14324 } 14325 14326 /* propagate the instance id and cookie to userspace */ 14327 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, 14328 NL80211_ATTR_PAD)) 14329 goto nla_put_failure; 14330 14331 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 14332 if (!func_attr) 14333 goto nla_put_failure; 14334 14335 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, 14336 func->instance_id)) 14337 goto nla_put_failure; 14338 14339 nla_nest_end(msg, func_attr); 14340 14341 genlmsg_end(msg, hdr); 14342 return genlmsg_reply(msg, info); 14343 14344 nla_put_failure: 14345 nlmsg_free(msg); 14346 return -ENOBUFS; 14347 } 14348 14349 static int nl80211_nan_del_func(struct sk_buff *skb, 14350 struct genl_info *info) 14351 { 14352 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14353 struct wireless_dev *wdev = info->user_ptr[1]; 14354 u64 cookie; 14355 14356 if (wdev->iftype != NL80211_IFTYPE_NAN) 14357 return -EOPNOTSUPP; 14358 14359 if (!wdev_running(wdev)) 14360 return -ENOTCONN; 14361 14362 if (!info->attrs[NL80211_ATTR_COOKIE]) 14363 return -EINVAL; 14364 14365 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 14366 14367 rdev_del_nan_func(rdev, wdev, cookie); 14368 14369 return 0; 14370 } 14371 14372 static int nl80211_nan_change_config(struct sk_buff *skb, 14373 struct genl_info *info) 14374 { 14375 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14376 struct wireless_dev *wdev = info->user_ptr[1]; 14377 struct cfg80211_nan_conf conf = {}; 14378 u32 changed = 0; 14379 14380 if (wdev->iftype != NL80211_IFTYPE_NAN) 14381 return -EOPNOTSUPP; 14382 14383 if (!wdev_running(wdev)) 14384 return -ENOTCONN; 14385 14386 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { 14387 conf.master_pref = 14388 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 14389 if (conf.master_pref <= 1 || conf.master_pref == 255) 14390 return -EINVAL; 14391 14392 changed |= CFG80211_NAN_CONF_CHANGED_PREF; 14393 } 14394 14395 if (info->attrs[NL80211_ATTR_BANDS]) { 14396 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 14397 14398 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 14399 return -EOPNOTSUPP; 14400 14401 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 14402 return -EINVAL; 14403 14404 conf.bands = bands; 14405 changed |= CFG80211_NAN_CONF_CHANGED_BANDS; 14406 } 14407 14408 if (!changed) 14409 return -EINVAL; 14410 14411 return rdev_nan_change_conf(rdev, wdev, &conf, changed); 14412 } 14413 14414 void cfg80211_nan_match(struct wireless_dev *wdev, 14415 struct cfg80211_nan_match_params *match, gfp_t gfp) 14416 { 14417 struct wiphy *wiphy = wdev->wiphy; 14418 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14419 struct nlattr *match_attr, *local_func_attr, *peer_func_attr; 14420 struct sk_buff *msg; 14421 void *hdr; 14422 14423 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) 14424 return; 14425 14426 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14427 if (!msg) 14428 return; 14429 14430 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); 14431 if (!hdr) { 14432 nlmsg_free(msg); 14433 return; 14434 } 14435 14436 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14437 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14438 wdev->netdev->ifindex)) || 14439 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14440 NL80211_ATTR_PAD)) 14441 goto nla_put_failure; 14442 14443 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, 14444 NL80211_ATTR_PAD) || 14445 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 14446 goto nla_put_failure; 14447 14448 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); 14449 if (!match_attr) 14450 goto nla_put_failure; 14451 14452 local_func_attr = nla_nest_start_noflag(msg, 14453 NL80211_NAN_MATCH_FUNC_LOCAL); 14454 if (!local_func_attr) 14455 goto nla_put_failure; 14456 14457 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) 14458 goto nla_put_failure; 14459 14460 nla_nest_end(msg, local_func_attr); 14461 14462 peer_func_attr = nla_nest_start_noflag(msg, 14463 NL80211_NAN_MATCH_FUNC_PEER); 14464 if (!peer_func_attr) 14465 goto nla_put_failure; 14466 14467 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || 14468 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) 14469 goto nla_put_failure; 14470 14471 if (match->info && match->info_len && 14472 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, 14473 match->info)) 14474 goto nla_put_failure; 14475 14476 nla_nest_end(msg, peer_func_attr); 14477 nla_nest_end(msg, match_attr); 14478 genlmsg_end(msg, hdr); 14479 14480 if (!wdev->owner_nlportid) 14481 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 14482 msg, 0, NL80211_MCGRP_NAN, gfp); 14483 else 14484 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 14485 wdev->owner_nlportid); 14486 14487 return; 14488 14489 nla_put_failure: 14490 nlmsg_free(msg); 14491 } 14492 EXPORT_SYMBOL(cfg80211_nan_match); 14493 14494 void cfg80211_nan_func_terminated(struct wireless_dev *wdev, 14495 u8 inst_id, 14496 enum nl80211_nan_func_term_reason reason, 14497 u64 cookie, gfp_t gfp) 14498 { 14499 struct wiphy *wiphy = wdev->wiphy; 14500 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14501 struct sk_buff *msg; 14502 struct nlattr *func_attr; 14503 void *hdr; 14504 14505 if (WARN_ON(!inst_id)) 14506 return; 14507 14508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14509 if (!msg) 14510 return; 14511 14512 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); 14513 if (!hdr) { 14514 nlmsg_free(msg); 14515 return; 14516 } 14517 14518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14519 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14520 wdev->netdev->ifindex)) || 14521 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14522 NL80211_ATTR_PAD)) 14523 goto nla_put_failure; 14524 14525 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 14526 NL80211_ATTR_PAD)) 14527 goto nla_put_failure; 14528 14529 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 14530 if (!func_attr) 14531 goto nla_put_failure; 14532 14533 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || 14534 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) 14535 goto nla_put_failure; 14536 14537 nla_nest_end(msg, func_attr); 14538 genlmsg_end(msg, hdr); 14539 14540 if (!wdev->owner_nlportid) 14541 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 14542 msg, 0, NL80211_MCGRP_NAN, gfp); 14543 else 14544 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 14545 wdev->owner_nlportid); 14546 14547 return; 14548 14549 nla_put_failure: 14550 nlmsg_free(msg); 14551 } 14552 EXPORT_SYMBOL(cfg80211_nan_func_terminated); 14553 14554 static int nl80211_get_protocol_features(struct sk_buff *skb, 14555 struct genl_info *info) 14556 { 14557 void *hdr; 14558 struct sk_buff *msg; 14559 14560 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14561 if (!msg) 14562 return -ENOMEM; 14563 14564 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14565 NL80211_CMD_GET_PROTOCOL_FEATURES); 14566 if (!hdr) 14567 goto nla_put_failure; 14568 14569 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, 14570 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) 14571 goto nla_put_failure; 14572 14573 genlmsg_end(msg, hdr); 14574 return genlmsg_reply(msg, info); 14575 14576 nla_put_failure: 14577 kfree_skb(msg); 14578 return -ENOBUFS; 14579 } 14580 14581 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) 14582 { 14583 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14584 struct cfg80211_update_ft_ies_params ft_params; 14585 struct net_device *dev = info->user_ptr[1]; 14586 14587 if (!rdev->ops->update_ft_ies) 14588 return -EOPNOTSUPP; 14589 14590 if (!info->attrs[NL80211_ATTR_MDID] || 14591 !info->attrs[NL80211_ATTR_IE]) 14592 return -EINVAL; 14593 14594 memset(&ft_params, 0, sizeof(ft_params)); 14595 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); 14596 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 14597 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 14598 14599 return rdev_update_ft_ies(rdev, dev, &ft_params); 14600 } 14601 14602 static int nl80211_crit_protocol_start(struct sk_buff *skb, 14603 struct genl_info *info) 14604 { 14605 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14606 struct wireless_dev *wdev = info->user_ptr[1]; 14607 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; 14608 u16 duration; 14609 int ret; 14610 14611 if (!rdev->ops->crit_proto_start) 14612 return -EOPNOTSUPP; 14613 14614 if (WARN_ON(!rdev->ops->crit_proto_stop)) 14615 return -EINVAL; 14616 14617 if (rdev->crit_proto_nlportid) 14618 return -EBUSY; 14619 14620 /* determine protocol if provided */ 14621 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) 14622 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); 14623 14624 if (proto >= NUM_NL80211_CRIT_PROTO) 14625 return -EINVAL; 14626 14627 /* timeout must be provided */ 14628 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) 14629 return -EINVAL; 14630 14631 duration = 14632 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); 14633 14634 ret = rdev_crit_proto_start(rdev, wdev, proto, duration); 14635 if (!ret) 14636 rdev->crit_proto_nlportid = info->snd_portid; 14637 14638 return ret; 14639 } 14640 14641 static int nl80211_crit_protocol_stop(struct sk_buff *skb, 14642 struct genl_info *info) 14643 { 14644 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14645 struct wireless_dev *wdev = info->user_ptr[1]; 14646 14647 if (!rdev->ops->crit_proto_stop) 14648 return -EOPNOTSUPP; 14649 14650 if (rdev->crit_proto_nlportid) { 14651 rdev->crit_proto_nlportid = 0; 14652 rdev_crit_proto_stop(rdev, wdev); 14653 } 14654 return 0; 14655 } 14656 14657 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, 14658 struct nlattr *attr, 14659 struct netlink_ext_ack *extack) 14660 { 14661 if (vcmd->policy == VENDOR_CMD_RAW_DATA) { 14662 if (attr->nla_type & NLA_F_NESTED) { 14663 NL_SET_ERR_MSG_ATTR(extack, attr, 14664 "unexpected nested data"); 14665 return -EINVAL; 14666 } 14667 14668 return 0; 14669 } 14670 14671 if (!(attr->nla_type & NLA_F_NESTED)) { 14672 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); 14673 return -EINVAL; 14674 } 14675 14676 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); 14677 } 14678 14679 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) 14680 { 14681 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14682 struct wireless_dev *wdev = 14683 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 14684 info->attrs); 14685 int i, err; 14686 u32 vid, subcmd; 14687 14688 if (!rdev->wiphy.vendor_commands) 14689 return -EOPNOTSUPP; 14690 14691 if (IS_ERR(wdev)) { 14692 err = PTR_ERR(wdev); 14693 if (err != -EINVAL) 14694 return err; 14695 wdev = NULL; 14696 } else if (wdev->wiphy != &rdev->wiphy) { 14697 return -EINVAL; 14698 } 14699 14700 if (!info->attrs[NL80211_ATTR_VENDOR_ID] || 14701 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) 14702 return -EINVAL; 14703 14704 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); 14705 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); 14706 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 14707 const struct wiphy_vendor_command *vcmd; 14708 void *data = NULL; 14709 int len = 0; 14710 14711 vcmd = &rdev->wiphy.vendor_commands[i]; 14712 14713 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 14714 continue; 14715 14716 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 14717 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 14718 if (!wdev) 14719 return -EINVAL; 14720 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 14721 !wdev->netdev) 14722 return -EINVAL; 14723 14724 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 14725 if (!wdev_running(wdev)) 14726 return -ENETDOWN; 14727 } 14728 } else { 14729 wdev = NULL; 14730 } 14731 14732 if (!vcmd->doit) 14733 return -EOPNOTSUPP; 14734 14735 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { 14736 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); 14737 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); 14738 14739 err = nl80211_vendor_check_policy(vcmd, 14740 info->attrs[NL80211_ATTR_VENDOR_DATA], 14741 info->extack); 14742 if (err) 14743 return err; 14744 } 14745 14746 rdev->cur_cmd_info = info; 14747 err = vcmd->doit(&rdev->wiphy, wdev, data, len); 14748 rdev->cur_cmd_info = NULL; 14749 return err; 14750 } 14751 14752 return -EOPNOTSUPP; 14753 } 14754 14755 static int nl80211_prepare_vendor_dump(struct sk_buff *skb, 14756 struct netlink_callback *cb, 14757 struct cfg80211_registered_device **rdev, 14758 struct wireless_dev **wdev) 14759 { 14760 struct nlattr **attrbuf; 14761 u32 vid, subcmd; 14762 unsigned int i; 14763 int vcmd_idx = -1; 14764 int err; 14765 void *data = NULL; 14766 unsigned int data_len = 0; 14767 14768 if (cb->args[0]) { 14769 /* subtract the 1 again here */ 14770 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 14771 struct wireless_dev *tmp; 14772 14773 if (!wiphy) 14774 return -ENODEV; 14775 *rdev = wiphy_to_rdev(wiphy); 14776 *wdev = NULL; 14777 14778 if (cb->args[1]) { 14779 list_for_each_entry(tmp, &wiphy->wdev_list, list) { 14780 if (tmp->identifier == cb->args[1] - 1) { 14781 *wdev = tmp; 14782 break; 14783 } 14784 } 14785 } 14786 14787 /* keep rtnl locked in successful case */ 14788 return 0; 14789 } 14790 14791 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 14792 if (!attrbuf) 14793 return -ENOMEM; 14794 14795 err = nlmsg_parse_deprecated(cb->nlh, 14796 GENL_HDRLEN + nl80211_fam.hdrsize, 14797 attrbuf, nl80211_fam.maxattr, 14798 nl80211_policy, NULL); 14799 if (err) 14800 goto out; 14801 14802 if (!attrbuf[NL80211_ATTR_VENDOR_ID] || 14803 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { 14804 err = -EINVAL; 14805 goto out; 14806 } 14807 14808 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf); 14809 if (IS_ERR(*wdev)) 14810 *wdev = NULL; 14811 14812 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 14813 if (IS_ERR(*rdev)) { 14814 err = PTR_ERR(*rdev); 14815 goto out; 14816 } 14817 14818 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); 14819 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); 14820 14821 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { 14822 const struct wiphy_vendor_command *vcmd; 14823 14824 vcmd = &(*rdev)->wiphy.vendor_commands[i]; 14825 14826 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 14827 continue; 14828 14829 if (!vcmd->dumpit) { 14830 err = -EOPNOTSUPP; 14831 goto out; 14832 } 14833 14834 vcmd_idx = i; 14835 break; 14836 } 14837 14838 if (vcmd_idx < 0) { 14839 err = -EOPNOTSUPP; 14840 goto out; 14841 } 14842 14843 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { 14844 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); 14845 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); 14846 14847 err = nl80211_vendor_check_policy( 14848 &(*rdev)->wiphy.vendor_commands[vcmd_idx], 14849 attrbuf[NL80211_ATTR_VENDOR_DATA], 14850 cb->extack); 14851 if (err) 14852 goto out; 14853 } 14854 14855 /* 0 is the first index - add 1 to parse only once */ 14856 cb->args[0] = (*rdev)->wiphy_idx + 1; 14857 /* add 1 to know if it was NULL */ 14858 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; 14859 cb->args[2] = vcmd_idx; 14860 cb->args[3] = (unsigned long)data; 14861 cb->args[4] = data_len; 14862 14863 /* keep rtnl locked in successful case */ 14864 err = 0; 14865 out: 14866 kfree(attrbuf); 14867 return err; 14868 } 14869 14870 static int nl80211_vendor_cmd_dump(struct sk_buff *skb, 14871 struct netlink_callback *cb) 14872 { 14873 struct cfg80211_registered_device *rdev; 14874 struct wireless_dev *wdev; 14875 unsigned int vcmd_idx; 14876 const struct wiphy_vendor_command *vcmd; 14877 void *data; 14878 int data_len; 14879 int err; 14880 struct nlattr *vendor_data; 14881 14882 rtnl_lock(); 14883 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); 14884 if (err) 14885 goto out; 14886 14887 vcmd_idx = cb->args[2]; 14888 data = (void *)cb->args[3]; 14889 data_len = cb->args[4]; 14890 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; 14891 14892 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 14893 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 14894 if (!wdev) { 14895 err = -EINVAL; 14896 goto out; 14897 } 14898 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 14899 !wdev->netdev) { 14900 err = -EINVAL; 14901 goto out; 14902 } 14903 14904 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 14905 if (!wdev_running(wdev)) { 14906 err = -ENETDOWN; 14907 goto out; 14908 } 14909 } 14910 } 14911 14912 while (1) { 14913 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 14914 cb->nlh->nlmsg_seq, NLM_F_MULTI, 14915 NL80211_CMD_VENDOR); 14916 if (!hdr) 14917 break; 14918 14919 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14920 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 14921 wdev_id(wdev), 14922 NL80211_ATTR_PAD))) { 14923 genlmsg_cancel(skb, hdr); 14924 break; 14925 } 14926 14927 vendor_data = nla_nest_start_noflag(skb, 14928 NL80211_ATTR_VENDOR_DATA); 14929 if (!vendor_data) { 14930 genlmsg_cancel(skb, hdr); 14931 break; 14932 } 14933 14934 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, 14935 (unsigned long *)&cb->args[5]); 14936 nla_nest_end(skb, vendor_data); 14937 14938 if (err == -ENOBUFS || err == -ENOENT) { 14939 genlmsg_cancel(skb, hdr); 14940 break; 14941 } else if (err <= 0) { 14942 genlmsg_cancel(skb, hdr); 14943 goto out; 14944 } 14945 14946 genlmsg_end(skb, hdr); 14947 } 14948 14949 err = skb->len; 14950 out: 14951 rtnl_unlock(); 14952 return err; 14953 } 14954 14955 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, 14956 enum nl80211_commands cmd, 14957 enum nl80211_attrs attr, 14958 int approxlen) 14959 { 14960 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14961 14962 if (WARN_ON(!rdev->cur_cmd_info)) 14963 return NULL; 14964 14965 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, 14966 rdev->cur_cmd_info->snd_portid, 14967 rdev->cur_cmd_info->snd_seq, 14968 cmd, attr, NULL, GFP_KERNEL); 14969 } 14970 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); 14971 14972 int cfg80211_vendor_cmd_reply(struct sk_buff *skb) 14973 { 14974 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 14975 void *hdr = ((void **)skb->cb)[1]; 14976 struct nlattr *data = ((void **)skb->cb)[2]; 14977 14978 /* clear CB data for netlink core to own from now on */ 14979 memset(skb->cb, 0, sizeof(skb->cb)); 14980 14981 if (WARN_ON(!rdev->cur_cmd_info)) { 14982 kfree_skb(skb); 14983 return -EINVAL; 14984 } 14985 14986 nla_nest_end(skb, data); 14987 genlmsg_end(skb, hdr); 14988 return genlmsg_reply(skb, rdev->cur_cmd_info); 14989 } 14990 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); 14991 14992 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) 14993 { 14994 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14995 14996 if (WARN_ON(!rdev->cur_cmd_info)) 14997 return 0; 14998 14999 return rdev->cur_cmd_info->snd_portid; 15000 } 15001 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); 15002 15003 static int nl80211_set_qos_map(struct sk_buff *skb, 15004 struct genl_info *info) 15005 { 15006 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15007 struct cfg80211_qos_map *qos_map = NULL; 15008 struct net_device *dev = info->user_ptr[1]; 15009 u8 *pos, len, num_des, des_len, des; 15010 int ret; 15011 15012 if (!rdev->ops->set_qos_map) 15013 return -EOPNOTSUPP; 15014 15015 if (info->attrs[NL80211_ATTR_QOS_MAP]) { 15016 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); 15017 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); 15018 15019 if (len % 2) 15020 return -EINVAL; 15021 15022 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); 15023 if (!qos_map) 15024 return -ENOMEM; 15025 15026 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; 15027 if (num_des) { 15028 des_len = num_des * 15029 sizeof(struct cfg80211_dscp_exception); 15030 memcpy(qos_map->dscp_exception, pos, des_len); 15031 qos_map->num_des = num_des; 15032 for (des = 0; des < num_des; des++) { 15033 if (qos_map->dscp_exception[des].up > 7) { 15034 kfree(qos_map); 15035 return -EINVAL; 15036 } 15037 } 15038 pos += des_len; 15039 } 15040 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); 15041 } 15042 15043 wdev_lock(dev->ieee80211_ptr); 15044 ret = nl80211_key_allowed(dev->ieee80211_ptr); 15045 if (!ret) 15046 ret = rdev_set_qos_map(rdev, dev, qos_map); 15047 wdev_unlock(dev->ieee80211_ptr); 15048 15049 kfree(qos_map); 15050 return ret; 15051 } 15052 15053 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) 15054 { 15055 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15056 struct net_device *dev = info->user_ptr[1]; 15057 struct wireless_dev *wdev = dev->ieee80211_ptr; 15058 const u8 *peer; 15059 u8 tsid, up; 15060 u16 admitted_time = 0; 15061 int err; 15062 15063 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) 15064 return -EOPNOTSUPP; 15065 15066 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 15067 !info->attrs[NL80211_ATTR_USER_PRIO]) 15068 return -EINVAL; 15069 15070 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 15071 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); 15072 15073 /* WMM uses TIDs 0-7 even for TSPEC */ 15074 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { 15075 /* TODO: handle 802.11 TSPEC/admission control 15076 * need more attributes for that (e.g. BA session requirement); 15077 * change the WMM adminssion test above to allow both then 15078 */ 15079 return -EINVAL; 15080 } 15081 15082 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15083 15084 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { 15085 admitted_time = 15086 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); 15087 if (!admitted_time) 15088 return -EINVAL; 15089 } 15090 15091 wdev_lock(wdev); 15092 switch (wdev->iftype) { 15093 case NL80211_IFTYPE_STATION: 15094 case NL80211_IFTYPE_P2P_CLIENT: 15095 if (wdev->connected) 15096 break; 15097 err = -ENOTCONN; 15098 goto out; 15099 default: 15100 err = -EOPNOTSUPP; 15101 goto out; 15102 } 15103 15104 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); 15105 15106 out: 15107 wdev_unlock(wdev); 15108 return err; 15109 } 15110 15111 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) 15112 { 15113 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15114 struct net_device *dev = info->user_ptr[1]; 15115 struct wireless_dev *wdev = dev->ieee80211_ptr; 15116 const u8 *peer; 15117 u8 tsid; 15118 int err; 15119 15120 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) 15121 return -EINVAL; 15122 15123 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 15124 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15125 15126 wdev_lock(wdev); 15127 err = rdev_del_tx_ts(rdev, dev, tsid, peer); 15128 wdev_unlock(wdev); 15129 15130 return err; 15131 } 15132 15133 static int nl80211_tdls_channel_switch(struct sk_buff *skb, 15134 struct genl_info *info) 15135 { 15136 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15137 struct net_device *dev = info->user_ptr[1]; 15138 struct wireless_dev *wdev = dev->ieee80211_ptr; 15139 struct cfg80211_chan_def chandef = {}; 15140 const u8 *addr; 15141 u8 oper_class; 15142 int err; 15143 15144 if (!rdev->ops->tdls_channel_switch || 15145 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 15146 return -EOPNOTSUPP; 15147 15148 switch (dev->ieee80211_ptr->iftype) { 15149 case NL80211_IFTYPE_STATION: 15150 case NL80211_IFTYPE_P2P_CLIENT: 15151 break; 15152 default: 15153 return -EOPNOTSUPP; 15154 } 15155 15156 if (!info->attrs[NL80211_ATTR_MAC] || 15157 !info->attrs[NL80211_ATTR_OPER_CLASS]) 15158 return -EINVAL; 15159 15160 err = nl80211_parse_chandef(rdev, info, &chandef); 15161 if (err) 15162 return err; 15163 15164 /* 15165 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 15166 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the 15167 * specification is not defined for them. 15168 */ 15169 if (chandef.chan->band == NL80211_BAND_2GHZ && 15170 chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 15171 chandef.width != NL80211_CHAN_WIDTH_20) 15172 return -EINVAL; 15173 15174 /* we will be active on the TDLS link */ 15175 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 15176 wdev->iftype)) 15177 return -EINVAL; 15178 15179 /* don't allow switching to DFS channels */ 15180 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) 15181 return -EINVAL; 15182 15183 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15184 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); 15185 15186 wdev_lock(wdev); 15187 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); 15188 wdev_unlock(wdev); 15189 15190 return err; 15191 } 15192 15193 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, 15194 struct genl_info *info) 15195 { 15196 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15197 struct net_device *dev = info->user_ptr[1]; 15198 struct wireless_dev *wdev = dev->ieee80211_ptr; 15199 const u8 *addr; 15200 15201 if (!rdev->ops->tdls_channel_switch || 15202 !rdev->ops->tdls_cancel_channel_switch || 15203 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 15204 return -EOPNOTSUPP; 15205 15206 switch (dev->ieee80211_ptr->iftype) { 15207 case NL80211_IFTYPE_STATION: 15208 case NL80211_IFTYPE_P2P_CLIENT: 15209 break; 15210 default: 15211 return -EOPNOTSUPP; 15212 } 15213 15214 if (!info->attrs[NL80211_ATTR_MAC]) 15215 return -EINVAL; 15216 15217 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15218 15219 wdev_lock(wdev); 15220 rdev_tdls_cancel_channel_switch(rdev, dev, addr); 15221 wdev_unlock(wdev); 15222 15223 return 0; 15224 } 15225 15226 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, 15227 struct genl_info *info) 15228 { 15229 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15230 struct net_device *dev = info->user_ptr[1]; 15231 struct wireless_dev *wdev = dev->ieee80211_ptr; 15232 const struct nlattr *nla; 15233 bool enabled; 15234 15235 if (!rdev->ops->set_multicast_to_unicast) 15236 return -EOPNOTSUPP; 15237 15238 if (wdev->iftype != NL80211_IFTYPE_AP && 15239 wdev->iftype != NL80211_IFTYPE_P2P_GO) 15240 return -EOPNOTSUPP; 15241 15242 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; 15243 enabled = nla_get_flag(nla); 15244 15245 return rdev_set_multicast_to_unicast(rdev, dev, enabled); 15246 } 15247 15248 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) 15249 { 15250 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15251 struct net_device *dev = info->user_ptr[1]; 15252 struct wireless_dev *wdev = dev->ieee80211_ptr; 15253 struct cfg80211_pmk_conf pmk_conf = {}; 15254 int ret; 15255 15256 if (wdev->iftype != NL80211_IFTYPE_STATION && 15257 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 15258 return -EOPNOTSUPP; 15259 15260 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15261 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 15262 return -EOPNOTSUPP; 15263 15264 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) 15265 return -EINVAL; 15266 15267 wdev_lock(wdev); 15268 if (!wdev->connected) { 15269 ret = -ENOTCONN; 15270 goto out; 15271 } 15272 15273 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 15274 if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) { 15275 ret = -EINVAL; 15276 goto out; 15277 } 15278 15279 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 15280 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 15281 if (pmk_conf.pmk_len != WLAN_PMK_LEN && 15282 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { 15283 ret = -EINVAL; 15284 goto out; 15285 } 15286 15287 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) 15288 pmk_conf.pmk_r0_name = 15289 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); 15290 15291 ret = rdev_set_pmk(rdev, dev, &pmk_conf); 15292 out: 15293 wdev_unlock(wdev); 15294 return ret; 15295 } 15296 15297 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) 15298 { 15299 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15300 struct net_device *dev = info->user_ptr[1]; 15301 struct wireless_dev *wdev = dev->ieee80211_ptr; 15302 const u8 *aa; 15303 int ret; 15304 15305 if (wdev->iftype != NL80211_IFTYPE_STATION && 15306 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 15307 return -EOPNOTSUPP; 15308 15309 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15310 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 15311 return -EOPNOTSUPP; 15312 15313 if (!info->attrs[NL80211_ATTR_MAC]) 15314 return -EINVAL; 15315 15316 wdev_lock(wdev); 15317 aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 15318 ret = rdev_del_pmk(rdev, dev, aa); 15319 wdev_unlock(wdev); 15320 15321 return ret; 15322 } 15323 15324 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) 15325 { 15326 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15327 struct net_device *dev = info->user_ptr[1]; 15328 struct cfg80211_external_auth_params params; 15329 15330 if (!rdev->ops->external_auth) 15331 return -EOPNOTSUPP; 15332 15333 if (!info->attrs[NL80211_ATTR_SSID] && 15334 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 15335 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 15336 return -EINVAL; 15337 15338 if (!info->attrs[NL80211_ATTR_BSSID]) 15339 return -EINVAL; 15340 15341 if (!info->attrs[NL80211_ATTR_STATUS_CODE]) 15342 return -EINVAL; 15343 15344 memset(¶ms, 0, sizeof(params)); 15345 15346 if (info->attrs[NL80211_ATTR_SSID]) { 15347 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 15348 if (params.ssid.ssid_len == 0) 15349 return -EINVAL; 15350 memcpy(params.ssid.ssid, 15351 nla_data(info->attrs[NL80211_ATTR_SSID]), 15352 params.ssid.ssid_len); 15353 } 15354 15355 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), 15356 ETH_ALEN); 15357 15358 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 15359 15360 if (info->attrs[NL80211_ATTR_PMKID]) 15361 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 15362 15363 return rdev_external_auth(rdev, dev, ¶ms); 15364 } 15365 15366 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) 15367 { 15368 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; 15369 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15370 struct net_device *dev = info->user_ptr[1]; 15371 struct wireless_dev *wdev = dev->ieee80211_ptr; 15372 const u8 *buf; 15373 size_t len; 15374 u8 *dest; 15375 u16 proto; 15376 bool noencrypt; 15377 u64 cookie = 0; 15378 int link_id; 15379 int err; 15380 15381 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15382 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 15383 return -EOPNOTSUPP; 15384 15385 if (!rdev->ops->tx_control_port) 15386 return -EOPNOTSUPP; 15387 15388 if (!info->attrs[NL80211_ATTR_FRAME] || 15389 !info->attrs[NL80211_ATTR_MAC] || 15390 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 15391 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); 15392 return -EINVAL; 15393 } 15394 15395 wdev_lock(wdev); 15396 15397 switch (wdev->iftype) { 15398 case NL80211_IFTYPE_AP: 15399 case NL80211_IFTYPE_P2P_GO: 15400 case NL80211_IFTYPE_MESH_POINT: 15401 break; 15402 case NL80211_IFTYPE_ADHOC: 15403 if (wdev->u.ibss.current_bss) 15404 break; 15405 err = -ENOTCONN; 15406 goto out; 15407 case NL80211_IFTYPE_STATION: 15408 case NL80211_IFTYPE_P2P_CLIENT: 15409 if (wdev->connected) 15410 break; 15411 err = -ENOTCONN; 15412 goto out; 15413 default: 15414 err = -EOPNOTSUPP; 15415 goto out; 15416 } 15417 15418 wdev_unlock(wdev); 15419 15420 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 15421 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 15422 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 15423 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 15424 noencrypt = 15425 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); 15426 15427 link_id = nl80211_link_id_or_invalid(info->attrs); 15428 15429 err = rdev_tx_control_port(rdev, dev, buf, len, 15430 dest, cpu_to_be16(proto), noencrypt, link_id, 15431 dont_wait_for_ack ? NULL : &cookie); 15432 if (!err && !dont_wait_for_ack) 15433 nl_set_extack_cookie_u64(info->extack, cookie); 15434 return err; 15435 out: 15436 wdev_unlock(wdev); 15437 return err; 15438 } 15439 15440 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, 15441 struct genl_info *info) 15442 { 15443 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15444 struct net_device *dev = info->user_ptr[1]; 15445 struct wireless_dev *wdev = dev->ieee80211_ptr; 15446 struct cfg80211_ftm_responder_stats ftm_stats = {}; 15447 unsigned int link_id = nl80211_link_id(info->attrs); 15448 struct sk_buff *msg; 15449 void *hdr; 15450 struct nlattr *ftm_stats_attr; 15451 int err; 15452 15453 if (wdev->iftype != NL80211_IFTYPE_AP || 15454 !wdev->links[link_id].ap.beacon_interval) 15455 return -EOPNOTSUPP; 15456 15457 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); 15458 if (err) 15459 return err; 15460 15461 if (!ftm_stats.filled) 15462 return -ENODATA; 15463 15464 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15465 if (!msg) 15466 return -ENOMEM; 15467 15468 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 15469 NL80211_CMD_GET_FTM_RESPONDER_STATS); 15470 if (!hdr) 15471 goto nla_put_failure; 15472 15473 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 15474 goto nla_put_failure; 15475 15476 ftm_stats_attr = nla_nest_start_noflag(msg, 15477 NL80211_ATTR_FTM_RESPONDER_STATS); 15478 if (!ftm_stats_attr) 15479 goto nla_put_failure; 15480 15481 #define SET_FTM(field, name, type) \ 15482 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 15483 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ 15484 ftm_stats.field)) \ 15485 goto nla_put_failure; } while (0) 15486 #define SET_FTM_U64(field, name) \ 15487 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 15488 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ 15489 ftm_stats.field, NL80211_FTM_STATS_PAD)) \ 15490 goto nla_put_failure; } while (0) 15491 15492 SET_FTM(success_num, SUCCESS_NUM, u32); 15493 SET_FTM(partial_num, PARTIAL_NUM, u32); 15494 SET_FTM(failed_num, FAILED_NUM, u32); 15495 SET_FTM(asap_num, ASAP_NUM, u32); 15496 SET_FTM(non_asap_num, NON_ASAP_NUM, u32); 15497 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); 15498 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); 15499 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); 15500 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); 15501 #undef SET_FTM 15502 15503 nla_nest_end(msg, ftm_stats_attr); 15504 15505 genlmsg_end(msg, hdr); 15506 return genlmsg_reply(msg, info); 15507 15508 nla_put_failure: 15509 nlmsg_free(msg); 15510 return -ENOBUFS; 15511 } 15512 15513 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) 15514 { 15515 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15516 struct cfg80211_update_owe_info owe_info; 15517 struct net_device *dev = info->user_ptr[1]; 15518 15519 if (!rdev->ops->update_owe_info) 15520 return -EOPNOTSUPP; 15521 15522 if (!info->attrs[NL80211_ATTR_STATUS_CODE] || 15523 !info->attrs[NL80211_ATTR_MAC]) 15524 return -EINVAL; 15525 15526 memset(&owe_info, 0, sizeof(owe_info)); 15527 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 15528 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); 15529 15530 if (info->attrs[NL80211_ATTR_IE]) { 15531 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 15532 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 15533 } 15534 15535 return rdev_update_owe_info(rdev, dev, &owe_info); 15536 } 15537 15538 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) 15539 { 15540 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15541 struct net_device *dev = info->user_ptr[1]; 15542 struct wireless_dev *wdev = dev->ieee80211_ptr; 15543 struct station_info sinfo = {}; 15544 const u8 *buf; 15545 size_t len; 15546 u8 *dest; 15547 int err; 15548 15549 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) 15550 return -EOPNOTSUPP; 15551 15552 if (!info->attrs[NL80211_ATTR_MAC] || 15553 !info->attrs[NL80211_ATTR_FRAME]) { 15554 GENL_SET_ERR_MSG(info, "Frame or MAC missing"); 15555 return -EINVAL; 15556 } 15557 15558 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 15559 return -EOPNOTSUPP; 15560 15561 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 15562 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 15563 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 15564 15565 if (len < sizeof(struct ethhdr)) 15566 return -EINVAL; 15567 15568 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || 15569 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) 15570 return -EINVAL; 15571 15572 err = rdev_get_station(rdev, dev, dest, &sinfo); 15573 if (err) 15574 return err; 15575 15576 cfg80211_sinfo_release_content(&sinfo); 15577 15578 return rdev_probe_mesh_link(rdev, dev, dest, buf, len); 15579 } 15580 15581 static int parse_tid_conf(struct cfg80211_registered_device *rdev, 15582 struct nlattr *attrs[], struct net_device *dev, 15583 struct cfg80211_tid_cfg *tid_conf, 15584 struct genl_info *info, const u8 *peer, 15585 unsigned int link_id) 15586 { 15587 struct netlink_ext_ack *extack = info->extack; 15588 u64 mask; 15589 int err; 15590 15591 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) 15592 return -EINVAL; 15593 15594 tid_conf->config_override = 15595 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); 15596 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); 15597 15598 if (tid_conf->config_override) { 15599 if (rdev->ops->reset_tid_config) { 15600 err = rdev_reset_tid_config(rdev, dev, peer, 15601 tid_conf->tids); 15602 if (err) 15603 return err; 15604 } else { 15605 return -EINVAL; 15606 } 15607 } 15608 15609 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { 15610 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); 15611 tid_conf->noack = 15612 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); 15613 } 15614 15615 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { 15616 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); 15617 tid_conf->retry_short = 15618 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); 15619 15620 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) 15621 return -EINVAL; 15622 } 15623 15624 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { 15625 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); 15626 tid_conf->retry_long = 15627 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); 15628 15629 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) 15630 return -EINVAL; 15631 } 15632 15633 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { 15634 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); 15635 tid_conf->ampdu = 15636 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); 15637 } 15638 15639 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { 15640 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); 15641 tid_conf->rtscts = 15642 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); 15643 } 15644 15645 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { 15646 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); 15647 tid_conf->amsdu = 15648 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); 15649 } 15650 15651 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { 15652 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; 15653 15654 tid_conf->txrate_type = nla_get_u8(attrs[idx]); 15655 15656 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { 15657 attr = NL80211_TID_CONFIG_ATTR_TX_RATE; 15658 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, 15659 &tid_conf->txrate_mask, dev, 15660 true, link_id); 15661 if (err) 15662 return err; 15663 15664 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); 15665 } 15666 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); 15667 } 15668 15669 if (peer) 15670 mask = rdev->wiphy.tid_config_support.peer; 15671 else 15672 mask = rdev->wiphy.tid_config_support.vif; 15673 15674 if (tid_conf->mask & ~mask) { 15675 NL_SET_ERR_MSG(extack, "unsupported TID configuration"); 15676 return -ENOTSUPP; 15677 } 15678 15679 return 0; 15680 } 15681 15682 static int nl80211_set_tid_config(struct sk_buff *skb, 15683 struct genl_info *info) 15684 { 15685 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15686 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; 15687 unsigned int link_id = nl80211_link_id(info->attrs); 15688 struct net_device *dev = info->user_ptr[1]; 15689 struct cfg80211_tid_config *tid_config; 15690 struct nlattr *tid; 15691 int conf_idx = 0, rem_conf; 15692 int ret = -EINVAL; 15693 u32 num_conf = 0; 15694 15695 if (!info->attrs[NL80211_ATTR_TID_CONFIG]) 15696 return -EINVAL; 15697 15698 if (!rdev->ops->set_tid_config) 15699 return -EOPNOTSUPP; 15700 15701 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 15702 rem_conf) 15703 num_conf++; 15704 15705 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), 15706 GFP_KERNEL); 15707 if (!tid_config) 15708 return -ENOMEM; 15709 15710 tid_config->n_tid_conf = num_conf; 15711 15712 if (info->attrs[NL80211_ATTR_MAC]) 15713 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15714 15715 wdev_lock(dev->ieee80211_ptr); 15716 15717 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 15718 rem_conf) { 15719 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, 15720 tid, NULL, NULL); 15721 15722 if (ret) 15723 goto bad_tid_conf; 15724 15725 ret = parse_tid_conf(rdev, attrs, dev, 15726 &tid_config->tid_conf[conf_idx], 15727 info, tid_config->peer, link_id); 15728 if (ret) 15729 goto bad_tid_conf; 15730 15731 conf_idx++; 15732 } 15733 15734 ret = rdev_set_tid_config(rdev, dev, tid_config); 15735 15736 bad_tid_conf: 15737 kfree(tid_config); 15738 wdev_unlock(dev->ieee80211_ptr); 15739 return ret; 15740 } 15741 15742 static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) 15743 { 15744 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15745 struct cfg80211_color_change_settings params = {}; 15746 struct net_device *dev = info->user_ptr[1]; 15747 struct wireless_dev *wdev = dev->ieee80211_ptr; 15748 struct nlattr **tb; 15749 u16 offset; 15750 int err; 15751 15752 if (!rdev->ops->color_change) 15753 return -EOPNOTSUPP; 15754 15755 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15756 NL80211_EXT_FEATURE_BSS_COLOR)) 15757 return -EOPNOTSUPP; 15758 15759 if (wdev->iftype != NL80211_IFTYPE_AP) 15760 return -EOPNOTSUPP; 15761 15762 if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] || 15763 !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] || 15764 !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS]) 15765 return -EINVAL; 15766 15767 params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]); 15768 params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]); 15769 15770 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next); 15771 if (err) 15772 return err; 15773 15774 tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL); 15775 if (!tb) 15776 return -ENOMEM; 15777 15778 err = nla_parse_nested(tb, NL80211_ATTR_MAX, 15779 info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS], 15780 nl80211_policy, info->extack); 15781 if (err) 15782 goto out; 15783 15784 err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change); 15785 if (err) 15786 goto out; 15787 15788 if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 15789 err = -EINVAL; 15790 goto out; 15791 } 15792 15793 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) { 15794 err = -EINVAL; 15795 goto out; 15796 } 15797 15798 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 15799 if (offset >= params.beacon_color_change.tail_len) { 15800 err = -EINVAL; 15801 goto out; 15802 } 15803 15804 if (params.beacon_color_change.tail[offset] != params.count) { 15805 err = -EINVAL; 15806 goto out; 15807 } 15808 15809 params.counter_offset_beacon = offset; 15810 15811 if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 15812 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) != 15813 sizeof(u16)) { 15814 err = -EINVAL; 15815 goto out; 15816 } 15817 15818 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 15819 if (offset >= params.beacon_color_change.probe_resp_len) { 15820 err = -EINVAL; 15821 goto out; 15822 } 15823 15824 if (params.beacon_color_change.probe_resp[offset] != 15825 params.count) { 15826 err = -EINVAL; 15827 goto out; 15828 } 15829 15830 params.counter_offset_presp = offset; 15831 } 15832 15833 wdev_lock(wdev); 15834 err = rdev_color_change(rdev, dev, ¶ms); 15835 wdev_unlock(wdev); 15836 15837 out: 15838 kfree(params.beacon_next.mbssid_ies); 15839 kfree(params.beacon_color_change.mbssid_ies); 15840 kfree(tb); 15841 return err; 15842 } 15843 15844 static int nl80211_set_fils_aad(struct sk_buff *skb, 15845 struct genl_info *info) 15846 { 15847 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15848 struct net_device *dev = info->user_ptr[1]; 15849 struct cfg80211_fils_aad fils_aad = {}; 15850 u8 *nonces; 15851 15852 if (!info->attrs[NL80211_ATTR_MAC] || 15853 !info->attrs[NL80211_ATTR_FILS_KEK] || 15854 !info->attrs[NL80211_ATTR_FILS_NONCES]) 15855 return -EINVAL; 15856 15857 fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15858 fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 15859 fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 15860 nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 15861 fils_aad.snonce = nonces; 15862 fils_aad.anonce = nonces + FILS_NONCE_LEN; 15863 15864 return rdev_set_fils_aad(rdev, dev, &fils_aad); 15865 } 15866 15867 static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info) 15868 { 15869 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15870 unsigned int link_id = nl80211_link_id(info->attrs); 15871 struct net_device *dev = info->user_ptr[1]; 15872 struct wireless_dev *wdev = dev->ieee80211_ptr; 15873 int ret; 15874 15875 if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) 15876 return -EINVAL; 15877 15878 switch (wdev->iftype) { 15879 case NL80211_IFTYPE_AP: 15880 break; 15881 default: 15882 return -EINVAL; 15883 } 15884 15885 if (!info->attrs[NL80211_ATTR_MAC] || 15886 !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC]))) 15887 return -EINVAL; 15888 15889 wdev_lock(wdev); 15890 wdev->valid_links |= BIT(link_id); 15891 ether_addr_copy(wdev->links[link_id].addr, 15892 nla_data(info->attrs[NL80211_ATTR_MAC])); 15893 15894 ret = rdev_add_intf_link(rdev, wdev, link_id); 15895 if (ret) { 15896 wdev->valid_links &= ~BIT(link_id); 15897 eth_zero_addr(wdev->links[link_id].addr); 15898 } 15899 wdev_unlock(wdev); 15900 15901 return ret; 15902 } 15903 15904 static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info) 15905 { 15906 unsigned int link_id = nl80211_link_id(info->attrs); 15907 struct net_device *dev = info->user_ptr[1]; 15908 struct wireless_dev *wdev = dev->ieee80211_ptr; 15909 15910 /* cannot remove if there's no link */ 15911 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) 15912 return -EINVAL; 15913 15914 switch (wdev->iftype) { 15915 case NL80211_IFTYPE_AP: 15916 break; 15917 default: 15918 return -EINVAL; 15919 } 15920 15921 wdev_lock(wdev); 15922 cfg80211_remove_link(wdev, link_id); 15923 wdev_unlock(wdev); 15924 15925 return 0; 15926 } 15927 15928 static int 15929 nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info, 15930 bool add) 15931 { 15932 struct link_station_parameters params = {}; 15933 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15934 struct net_device *dev = info->user_ptr[1]; 15935 int err; 15936 15937 if ((add && !rdev->ops->add_link_station) || 15938 (!add && !rdev->ops->mod_link_station)) 15939 return -EOPNOTSUPP; 15940 15941 if (add && !info->attrs[NL80211_ATTR_MAC]) 15942 return -EINVAL; 15943 15944 if (!info->attrs[NL80211_ATTR_MLD_ADDR]) 15945 return -EINVAL; 15946 15947 if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 15948 return -EINVAL; 15949 15950 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 15951 15952 if (info->attrs[NL80211_ATTR_MAC]) { 15953 params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 15954 if (!is_valid_ether_addr(params.link_mac)) 15955 return -EINVAL; 15956 } 15957 15958 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) 15959 return -EINVAL; 15960 15961 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); 15962 15963 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 15964 params.supported_rates = 15965 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 15966 params.supported_rates_len = 15967 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 15968 } 15969 15970 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 15971 params.ht_capa = 15972 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 15973 15974 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 15975 params.vht_capa = 15976 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 15977 15978 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 15979 params.he_capa = 15980 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 15981 params.he_capa_len = 15982 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 15983 15984 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 15985 params.eht_capa = 15986 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 15987 params.eht_capa_len = 15988 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 15989 15990 if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa, 15991 (const u8 *)params.eht_capa, 15992 params.eht_capa_len, 15993 false)) 15994 return -EINVAL; 15995 } 15996 } 15997 15998 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 15999 params.he_6ghz_capa = 16000 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 16001 16002 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 16003 params.opmode_notif_used = true; 16004 params.opmode_notif = 16005 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 16006 } 16007 16008 err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr, 16009 ¶ms.txpwr_set); 16010 if (err) 16011 return err; 16012 16013 wdev_lock(dev->ieee80211_ptr); 16014 if (add) 16015 err = rdev_add_link_station(rdev, dev, ¶ms); 16016 else 16017 err = rdev_mod_link_station(rdev, dev, ¶ms); 16018 wdev_unlock(dev->ieee80211_ptr); 16019 16020 return err; 16021 } 16022 16023 static int 16024 nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info) 16025 { 16026 return nl80211_add_mod_link_station(skb, info, true); 16027 } 16028 16029 static int 16030 nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info) 16031 { 16032 return nl80211_add_mod_link_station(skb, info, false); 16033 } 16034 16035 static int 16036 nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info) 16037 { 16038 struct link_station_del_parameters params = {}; 16039 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16040 struct net_device *dev = info->user_ptr[1]; 16041 int ret; 16042 16043 if (!rdev->ops->del_link_station) 16044 return -EOPNOTSUPP; 16045 16046 if (!info->attrs[NL80211_ATTR_MLD_ADDR] || 16047 !info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16048 return -EINVAL; 16049 16050 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 16051 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); 16052 16053 wdev_lock(dev->ieee80211_ptr); 16054 ret = rdev_del_link_station(rdev, dev, ¶ms); 16055 wdev_unlock(dev->ieee80211_ptr); 16056 16057 return ret; 16058 } 16059 16060 #define NL80211_FLAG_NEED_WIPHY 0x01 16061 #define NL80211_FLAG_NEED_NETDEV 0x02 16062 #define NL80211_FLAG_NEED_RTNL 0x04 16063 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 16064 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ 16065 NL80211_FLAG_CHECK_NETDEV_UP) 16066 #define NL80211_FLAG_NEED_WDEV 0x10 16067 /* If a netdev is associated, it must be UP, P2P must be started */ 16068 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ 16069 NL80211_FLAG_CHECK_NETDEV_UP) 16070 #define NL80211_FLAG_CLEAR_SKB 0x20 16071 #define NL80211_FLAG_NO_WIPHY_MTX 0x40 16072 #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80 16073 #define NL80211_FLAG_MLO_UNSUPPORTED 0x100 16074 16075 #define INTERNAL_FLAG_SELECTORS(__sel) \ 16076 SELECTOR(__sel, NONE, 0) /* must be first */ \ 16077 SELECTOR(__sel, WIPHY, \ 16078 NL80211_FLAG_NEED_WIPHY) \ 16079 SELECTOR(__sel, WDEV, \ 16080 NL80211_FLAG_NEED_WDEV) \ 16081 SELECTOR(__sel, NETDEV, \ 16082 NL80211_FLAG_NEED_NETDEV) \ 16083 SELECTOR(__sel, NETDEV_LINK, \ 16084 NL80211_FLAG_NEED_NETDEV | \ 16085 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16086 SELECTOR(__sel, NETDEV_NO_MLO, \ 16087 NL80211_FLAG_NEED_NETDEV | \ 16088 NL80211_FLAG_MLO_UNSUPPORTED) \ 16089 SELECTOR(__sel, WIPHY_RTNL, \ 16090 NL80211_FLAG_NEED_WIPHY | \ 16091 NL80211_FLAG_NEED_RTNL) \ 16092 SELECTOR(__sel, WIPHY_RTNL_NOMTX, \ 16093 NL80211_FLAG_NEED_WIPHY | \ 16094 NL80211_FLAG_NEED_RTNL | \ 16095 NL80211_FLAG_NO_WIPHY_MTX) \ 16096 SELECTOR(__sel, WDEV_RTNL, \ 16097 NL80211_FLAG_NEED_WDEV | \ 16098 NL80211_FLAG_NEED_RTNL) \ 16099 SELECTOR(__sel, NETDEV_RTNL, \ 16100 NL80211_FLAG_NEED_NETDEV | \ 16101 NL80211_FLAG_NEED_RTNL) \ 16102 SELECTOR(__sel, NETDEV_UP, \ 16103 NL80211_FLAG_NEED_NETDEV_UP) \ 16104 SELECTOR(__sel, NETDEV_UP_LINK, \ 16105 NL80211_FLAG_NEED_NETDEV_UP | \ 16106 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16107 SELECTOR(__sel, NETDEV_UP_NO_MLO, \ 16108 NL80211_FLAG_NEED_NETDEV_UP | \ 16109 NL80211_FLAG_MLO_UNSUPPORTED) \ 16110 SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \ 16111 NL80211_FLAG_NEED_NETDEV_UP | \ 16112 NL80211_FLAG_CLEAR_SKB | \ 16113 NL80211_FLAG_MLO_UNSUPPORTED) \ 16114 SELECTOR(__sel, NETDEV_UP_NOTMX, \ 16115 NL80211_FLAG_NEED_NETDEV_UP | \ 16116 NL80211_FLAG_NO_WIPHY_MTX) \ 16117 SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \ 16118 NL80211_FLAG_NEED_NETDEV_UP | \ 16119 NL80211_FLAG_NO_WIPHY_MTX | \ 16120 NL80211_FLAG_MLO_UNSUPPORTED) \ 16121 SELECTOR(__sel, NETDEV_UP_CLEAR, \ 16122 NL80211_FLAG_NEED_NETDEV_UP | \ 16123 NL80211_FLAG_CLEAR_SKB) \ 16124 SELECTOR(__sel, WDEV_UP, \ 16125 NL80211_FLAG_NEED_WDEV_UP) \ 16126 SELECTOR(__sel, WDEV_UP_LINK, \ 16127 NL80211_FLAG_NEED_WDEV_UP | \ 16128 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16129 SELECTOR(__sel, WDEV_UP_RTNL, \ 16130 NL80211_FLAG_NEED_WDEV_UP | \ 16131 NL80211_FLAG_NEED_RTNL) \ 16132 SELECTOR(__sel, WIPHY_CLEAR, \ 16133 NL80211_FLAG_NEED_WIPHY | \ 16134 NL80211_FLAG_CLEAR_SKB) 16135 16136 enum nl80211_internal_flags_selector { 16137 #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name, 16138 INTERNAL_FLAG_SELECTORS(_) 16139 #undef SELECTOR 16140 }; 16141 16142 static u32 nl80211_internal_flags[] = { 16143 #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value, 16144 INTERNAL_FLAG_SELECTORS(_) 16145 #undef SELECTOR 16146 }; 16147 16148 static int nl80211_pre_doit(const struct genl_split_ops *ops, 16149 struct sk_buff *skb, 16150 struct genl_info *info) 16151 { 16152 struct cfg80211_registered_device *rdev = NULL; 16153 struct wireless_dev *wdev = NULL; 16154 struct net_device *dev = NULL; 16155 u32 internal_flags; 16156 int err; 16157 16158 if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags))) 16159 return -EINVAL; 16160 16161 internal_flags = nl80211_internal_flags[ops->internal_flags]; 16162 16163 rtnl_lock(); 16164 if (internal_flags & NL80211_FLAG_NEED_WIPHY) { 16165 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 16166 if (IS_ERR(rdev)) { 16167 err = PTR_ERR(rdev); 16168 goto out_unlock; 16169 } 16170 info->user_ptr[0] = rdev; 16171 } else if (internal_flags & NL80211_FLAG_NEED_NETDEV || 16172 internal_flags & NL80211_FLAG_NEED_WDEV) { 16173 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), 16174 info->attrs); 16175 if (IS_ERR(wdev)) { 16176 err = PTR_ERR(wdev); 16177 goto out_unlock; 16178 } 16179 16180 dev = wdev->netdev; 16181 dev_hold(dev); 16182 rdev = wiphy_to_rdev(wdev->wiphy); 16183 16184 if (internal_flags & NL80211_FLAG_NEED_NETDEV) { 16185 if (!dev) { 16186 err = -EINVAL; 16187 goto out_unlock; 16188 } 16189 16190 info->user_ptr[1] = dev; 16191 } else { 16192 info->user_ptr[1] = wdev; 16193 } 16194 16195 if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && 16196 !wdev_running(wdev)) { 16197 err = -ENETDOWN; 16198 goto out_unlock; 16199 } 16200 16201 info->user_ptr[0] = rdev; 16202 } 16203 16204 if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) { 16205 struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID]; 16206 16207 if (!wdev) { 16208 err = -EINVAL; 16209 goto out_unlock; 16210 } 16211 16212 /* MLO -> require valid link ID */ 16213 if (wdev->valid_links && 16214 (!link_id || 16215 !(wdev->valid_links & BIT(nla_get_u8(link_id))))) { 16216 err = -EINVAL; 16217 goto out_unlock; 16218 } 16219 16220 /* non-MLO -> no link ID attribute accepted */ 16221 if (!wdev->valid_links && link_id) { 16222 err = -EINVAL; 16223 goto out_unlock; 16224 } 16225 } 16226 16227 if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) { 16228 if (info->attrs[NL80211_ATTR_MLO_LINK_ID] || 16229 (wdev && wdev->valid_links)) { 16230 err = -EINVAL; 16231 goto out_unlock; 16232 } 16233 } 16234 16235 if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 16236 wiphy_lock(&rdev->wiphy); 16237 /* we keep the mutex locked until post_doit */ 16238 __release(&rdev->wiphy.mtx); 16239 } 16240 if (!(internal_flags & NL80211_FLAG_NEED_RTNL)) 16241 rtnl_unlock(); 16242 16243 return 0; 16244 out_unlock: 16245 rtnl_unlock(); 16246 dev_put(dev); 16247 return err; 16248 } 16249 16250 static void nl80211_post_doit(const struct genl_split_ops *ops, 16251 struct sk_buff *skb, 16252 struct genl_info *info) 16253 { 16254 u32 internal_flags = nl80211_internal_flags[ops->internal_flags]; 16255 16256 if (info->user_ptr[1]) { 16257 if (internal_flags & NL80211_FLAG_NEED_WDEV) { 16258 struct wireless_dev *wdev = info->user_ptr[1]; 16259 16260 dev_put(wdev->netdev); 16261 } else { 16262 dev_put(info->user_ptr[1]); 16263 } 16264 } 16265 16266 if (info->user_ptr[0] && 16267 !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 16268 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16269 16270 /* we kept the mutex locked since pre_doit */ 16271 __acquire(&rdev->wiphy.mtx); 16272 wiphy_unlock(&rdev->wiphy); 16273 } 16274 16275 if (internal_flags & NL80211_FLAG_NEED_RTNL) 16276 rtnl_unlock(); 16277 16278 /* If needed, clear the netlink message payload from the SKB 16279 * as it might contain key data that shouldn't stick around on 16280 * the heap after the SKB is freed. The netlink message header 16281 * is still needed for further processing, so leave it intact. 16282 */ 16283 if (internal_flags & NL80211_FLAG_CLEAR_SKB) { 16284 struct nlmsghdr *nlh = nlmsg_hdr(skb); 16285 16286 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); 16287 } 16288 } 16289 16290 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev, 16291 struct cfg80211_sar_specs *sar_specs, 16292 struct nlattr *spec[], int index) 16293 { 16294 u32 range_index, i; 16295 16296 if (!sar_specs || !spec) 16297 return -EINVAL; 16298 16299 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] || 16300 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]) 16301 return -EINVAL; 16302 16303 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]); 16304 16305 /* check if range_index exceeds num_freq_ranges */ 16306 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges) 16307 return -EINVAL; 16308 16309 /* check if range_index duplicates */ 16310 for (i = 0; i < index; i++) { 16311 if (sar_specs->sub_specs[i].freq_range_index == range_index) 16312 return -EINVAL; 16313 } 16314 16315 sar_specs->sub_specs[index].power = 16316 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]); 16317 16318 sar_specs->sub_specs[index].freq_range_index = range_index; 16319 16320 return 0; 16321 } 16322 16323 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) 16324 { 16325 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16326 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1]; 16327 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1]; 16328 struct cfg80211_sar_specs *sar_spec; 16329 enum nl80211_sar_type type; 16330 struct nlattr *spec_list; 16331 u32 specs; 16332 int rem, err; 16333 16334 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs) 16335 return -EOPNOTSUPP; 16336 16337 if (!info->attrs[NL80211_ATTR_SAR_SPEC]) 16338 return -EINVAL; 16339 16340 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX, 16341 info->attrs[NL80211_ATTR_SAR_SPEC], 16342 NULL, NULL); 16343 16344 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS]) 16345 return -EINVAL; 16346 16347 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]); 16348 if (type != rdev->wiphy.sar_capa->type) 16349 return -EINVAL; 16350 16351 specs = 0; 16352 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) 16353 specs++; 16354 16355 if (specs > rdev->wiphy.sar_capa->num_freq_ranges) 16356 return -EINVAL; 16357 16358 sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL); 16359 if (!sar_spec) 16360 return -ENOMEM; 16361 16362 sar_spec->type = type; 16363 specs = 0; 16364 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) { 16365 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX, 16366 spec_list, NULL, NULL); 16367 16368 switch (type) { 16369 case NL80211_SAR_TYPE_POWER: 16370 if (nl80211_set_sar_sub_specs(rdev, sar_spec, 16371 spec, specs)) { 16372 err = -EINVAL; 16373 goto error; 16374 } 16375 break; 16376 default: 16377 err = -EINVAL; 16378 goto error; 16379 } 16380 specs++; 16381 } 16382 16383 sar_spec->num_sub_specs = specs; 16384 16385 rdev->cur_cmd_info = info; 16386 err = rdev_set_sar_specs(rdev, sar_spec); 16387 rdev->cur_cmd_info = NULL; 16388 error: 16389 kfree(sar_spec); 16390 return err; 16391 } 16392 16393 #define SELECTOR(__sel, name, value) \ 16394 ((__sel) == (value)) ? NL80211_IFL_SEL_##name : 16395 int __missing_selector(void); 16396 #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector() 16397 16398 static const struct genl_ops nl80211_ops[] = { 16399 { 16400 .cmd = NL80211_CMD_GET_WIPHY, 16401 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16402 .doit = nl80211_get_wiphy, 16403 .dumpit = nl80211_dump_wiphy, 16404 .done = nl80211_dump_wiphy_done, 16405 /* can be retrieved by unprivileged users */ 16406 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16407 }, 16408 }; 16409 16410 static const struct genl_small_ops nl80211_small_ops[] = { 16411 { 16412 .cmd = NL80211_CMD_SET_WIPHY, 16413 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16414 .doit = nl80211_set_wiphy, 16415 .flags = GENL_UNS_ADMIN_PERM, 16416 }, 16417 { 16418 .cmd = NL80211_CMD_GET_INTERFACE, 16419 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16420 .doit = nl80211_get_interface, 16421 .dumpit = nl80211_dump_interface, 16422 /* can be retrieved by unprivileged users */ 16423 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), 16424 }, 16425 { 16426 .cmd = NL80211_CMD_SET_INTERFACE, 16427 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16428 .doit = nl80211_set_interface, 16429 .flags = GENL_UNS_ADMIN_PERM, 16430 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 16431 NL80211_FLAG_NEED_RTNL), 16432 }, 16433 { 16434 .cmd = NL80211_CMD_NEW_INTERFACE, 16435 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16436 .doit = nl80211_new_interface, 16437 .flags = GENL_UNS_ADMIN_PERM, 16438 .internal_flags = 16439 IFLAGS(NL80211_FLAG_NEED_WIPHY | 16440 NL80211_FLAG_NEED_RTNL | 16441 /* we take the wiphy mutex later ourselves */ 16442 NL80211_FLAG_NO_WIPHY_MTX), 16443 }, 16444 { 16445 .cmd = NL80211_CMD_DEL_INTERFACE, 16446 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16447 .doit = nl80211_del_interface, 16448 .flags = GENL_UNS_ADMIN_PERM, 16449 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 16450 NL80211_FLAG_NEED_RTNL), 16451 }, 16452 { 16453 .cmd = NL80211_CMD_GET_KEY, 16454 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16455 .doit = nl80211_get_key, 16456 .flags = GENL_UNS_ADMIN_PERM, 16457 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16458 }, 16459 { 16460 .cmd = NL80211_CMD_SET_KEY, 16461 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16462 .doit = nl80211_set_key, 16463 .flags = GENL_UNS_ADMIN_PERM, 16464 /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */ 16465 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16466 NL80211_FLAG_CLEAR_SKB), 16467 }, 16468 { 16469 .cmd = NL80211_CMD_NEW_KEY, 16470 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16471 .doit = nl80211_new_key, 16472 .flags = GENL_UNS_ADMIN_PERM, 16473 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16474 NL80211_FLAG_CLEAR_SKB), 16475 }, 16476 { 16477 .cmd = NL80211_CMD_DEL_KEY, 16478 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16479 .doit = nl80211_del_key, 16480 .flags = GENL_UNS_ADMIN_PERM, 16481 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16482 }, 16483 { 16484 .cmd = NL80211_CMD_SET_BEACON, 16485 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16486 .flags = GENL_UNS_ADMIN_PERM, 16487 .doit = nl80211_set_beacon, 16488 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16489 NL80211_FLAG_MLO_VALID_LINK_ID), 16490 }, 16491 { 16492 .cmd = NL80211_CMD_START_AP, 16493 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16494 .flags = GENL_UNS_ADMIN_PERM, 16495 .doit = nl80211_start_ap, 16496 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16497 NL80211_FLAG_MLO_VALID_LINK_ID), 16498 }, 16499 { 16500 .cmd = NL80211_CMD_STOP_AP, 16501 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16502 .flags = GENL_UNS_ADMIN_PERM, 16503 .doit = nl80211_stop_ap, 16504 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16505 NL80211_FLAG_MLO_VALID_LINK_ID), 16506 }, 16507 { 16508 .cmd = NL80211_CMD_GET_STATION, 16509 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16510 .doit = nl80211_get_station, 16511 .dumpit = nl80211_dump_station, 16512 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16513 }, 16514 { 16515 .cmd = NL80211_CMD_SET_STATION, 16516 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16517 .doit = nl80211_set_station, 16518 .flags = GENL_UNS_ADMIN_PERM, 16519 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16520 }, 16521 { 16522 .cmd = NL80211_CMD_NEW_STATION, 16523 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16524 .doit = nl80211_new_station, 16525 .flags = GENL_UNS_ADMIN_PERM, 16526 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16527 }, 16528 { 16529 .cmd = NL80211_CMD_DEL_STATION, 16530 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16531 .doit = nl80211_del_station, 16532 .flags = GENL_UNS_ADMIN_PERM, 16533 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16534 }, 16535 { 16536 .cmd = NL80211_CMD_GET_MPATH, 16537 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16538 .doit = nl80211_get_mpath, 16539 .dumpit = nl80211_dump_mpath, 16540 .flags = GENL_UNS_ADMIN_PERM, 16541 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16542 }, 16543 { 16544 .cmd = NL80211_CMD_GET_MPP, 16545 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16546 .doit = nl80211_get_mpp, 16547 .dumpit = nl80211_dump_mpp, 16548 .flags = GENL_UNS_ADMIN_PERM, 16549 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16550 }, 16551 { 16552 .cmd = NL80211_CMD_SET_MPATH, 16553 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16554 .doit = nl80211_set_mpath, 16555 .flags = GENL_UNS_ADMIN_PERM, 16556 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16557 }, 16558 { 16559 .cmd = NL80211_CMD_NEW_MPATH, 16560 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16561 .doit = nl80211_new_mpath, 16562 .flags = GENL_UNS_ADMIN_PERM, 16563 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16564 }, 16565 { 16566 .cmd = NL80211_CMD_DEL_MPATH, 16567 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16568 .doit = nl80211_del_mpath, 16569 .flags = GENL_UNS_ADMIN_PERM, 16570 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16571 }, 16572 { 16573 .cmd = NL80211_CMD_SET_BSS, 16574 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16575 .doit = nl80211_set_bss, 16576 .flags = GENL_UNS_ADMIN_PERM, 16577 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16578 NL80211_FLAG_MLO_VALID_LINK_ID), 16579 }, 16580 { 16581 .cmd = NL80211_CMD_GET_REG, 16582 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16583 .doit = nl80211_get_reg_do, 16584 .dumpit = nl80211_get_reg_dump, 16585 /* can be retrieved by unprivileged users */ 16586 }, 16587 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 16588 { 16589 .cmd = NL80211_CMD_SET_REG, 16590 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16591 .doit = nl80211_set_reg, 16592 .flags = GENL_ADMIN_PERM, 16593 }, 16594 #endif 16595 { 16596 .cmd = NL80211_CMD_REQ_SET_REG, 16597 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16598 .doit = nl80211_req_set_reg, 16599 .flags = GENL_ADMIN_PERM, 16600 }, 16601 { 16602 .cmd = NL80211_CMD_RELOAD_REGDB, 16603 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16604 .doit = nl80211_reload_regdb, 16605 .flags = GENL_ADMIN_PERM, 16606 }, 16607 { 16608 .cmd = NL80211_CMD_GET_MESH_CONFIG, 16609 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16610 .doit = nl80211_get_mesh_config, 16611 /* can be retrieved by unprivileged users */ 16612 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16613 }, 16614 { 16615 .cmd = NL80211_CMD_SET_MESH_CONFIG, 16616 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16617 .doit = nl80211_update_mesh_config, 16618 .flags = GENL_UNS_ADMIN_PERM, 16619 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16620 }, 16621 { 16622 .cmd = NL80211_CMD_TRIGGER_SCAN, 16623 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16624 .doit = nl80211_trigger_scan, 16625 .flags = GENL_UNS_ADMIN_PERM, 16626 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16627 }, 16628 { 16629 .cmd = NL80211_CMD_ABORT_SCAN, 16630 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16631 .doit = nl80211_abort_scan, 16632 .flags = GENL_UNS_ADMIN_PERM, 16633 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16634 }, 16635 { 16636 .cmd = NL80211_CMD_GET_SCAN, 16637 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16638 .dumpit = nl80211_dump_scan, 16639 }, 16640 { 16641 .cmd = NL80211_CMD_START_SCHED_SCAN, 16642 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16643 .doit = nl80211_start_sched_scan, 16644 .flags = GENL_UNS_ADMIN_PERM, 16645 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16646 }, 16647 { 16648 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 16649 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16650 .doit = nl80211_stop_sched_scan, 16651 .flags = GENL_UNS_ADMIN_PERM, 16652 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16653 }, 16654 { 16655 .cmd = NL80211_CMD_AUTHENTICATE, 16656 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16657 .doit = nl80211_authenticate, 16658 .flags = GENL_UNS_ADMIN_PERM, 16659 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16660 NL80211_FLAG_CLEAR_SKB), 16661 }, 16662 { 16663 .cmd = NL80211_CMD_ASSOCIATE, 16664 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16665 .doit = nl80211_associate, 16666 .flags = GENL_UNS_ADMIN_PERM, 16667 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16668 NL80211_FLAG_CLEAR_SKB), 16669 }, 16670 { 16671 .cmd = NL80211_CMD_DEAUTHENTICATE, 16672 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16673 .doit = nl80211_deauthenticate, 16674 .flags = GENL_UNS_ADMIN_PERM, 16675 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16676 }, 16677 { 16678 .cmd = NL80211_CMD_DISASSOCIATE, 16679 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16680 .doit = nl80211_disassociate, 16681 .flags = GENL_UNS_ADMIN_PERM, 16682 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16683 }, 16684 { 16685 .cmd = NL80211_CMD_JOIN_IBSS, 16686 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16687 .doit = nl80211_join_ibss, 16688 .flags = GENL_UNS_ADMIN_PERM, 16689 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16690 }, 16691 { 16692 .cmd = NL80211_CMD_LEAVE_IBSS, 16693 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16694 .doit = nl80211_leave_ibss, 16695 .flags = GENL_UNS_ADMIN_PERM, 16696 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16697 }, 16698 #ifdef CONFIG_NL80211_TESTMODE 16699 { 16700 .cmd = NL80211_CMD_TESTMODE, 16701 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16702 .doit = nl80211_testmode_do, 16703 .dumpit = nl80211_testmode_dump, 16704 .flags = GENL_UNS_ADMIN_PERM, 16705 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16706 }, 16707 #endif 16708 { 16709 .cmd = NL80211_CMD_CONNECT, 16710 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16711 .doit = nl80211_connect, 16712 .flags = GENL_UNS_ADMIN_PERM, 16713 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16714 NL80211_FLAG_CLEAR_SKB), 16715 }, 16716 { 16717 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 16718 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16719 .doit = nl80211_update_connect_params, 16720 .flags = GENL_ADMIN_PERM, 16721 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16722 NL80211_FLAG_CLEAR_SKB), 16723 }, 16724 { 16725 .cmd = NL80211_CMD_DISCONNECT, 16726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16727 .doit = nl80211_disconnect, 16728 .flags = GENL_UNS_ADMIN_PERM, 16729 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16730 }, 16731 { 16732 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 16733 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16734 .doit = nl80211_wiphy_netns, 16735 .flags = GENL_UNS_ADMIN_PERM, 16736 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 16737 NL80211_FLAG_NEED_RTNL | 16738 NL80211_FLAG_NO_WIPHY_MTX), 16739 }, 16740 { 16741 .cmd = NL80211_CMD_GET_SURVEY, 16742 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16743 .dumpit = nl80211_dump_survey, 16744 }, 16745 { 16746 .cmd = NL80211_CMD_SET_PMKSA, 16747 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16748 .doit = nl80211_setdel_pmksa, 16749 .flags = GENL_UNS_ADMIN_PERM, 16750 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16751 NL80211_FLAG_CLEAR_SKB), 16752 }, 16753 { 16754 .cmd = NL80211_CMD_DEL_PMKSA, 16755 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16756 .doit = nl80211_setdel_pmksa, 16757 .flags = GENL_UNS_ADMIN_PERM, 16758 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16759 }, 16760 { 16761 .cmd = NL80211_CMD_FLUSH_PMKSA, 16762 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16763 .doit = nl80211_flush_pmksa, 16764 .flags = GENL_UNS_ADMIN_PERM, 16765 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16766 }, 16767 { 16768 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 16769 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16770 .doit = nl80211_remain_on_channel, 16771 .flags = GENL_UNS_ADMIN_PERM, 16772 /* FIXME: requiring a link ID here is probably not good */ 16773 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 16774 NL80211_FLAG_MLO_VALID_LINK_ID), 16775 }, 16776 { 16777 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 16778 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16779 .doit = nl80211_cancel_remain_on_channel, 16780 .flags = GENL_UNS_ADMIN_PERM, 16781 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16782 }, 16783 { 16784 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 16785 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16786 .doit = nl80211_set_tx_bitrate_mask, 16787 .flags = GENL_UNS_ADMIN_PERM, 16788 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 16789 NL80211_FLAG_MLO_VALID_LINK_ID), 16790 }, 16791 { 16792 .cmd = NL80211_CMD_REGISTER_FRAME, 16793 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16794 .doit = nl80211_register_mgmt, 16795 .flags = GENL_UNS_ADMIN_PERM, 16796 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), 16797 }, 16798 { 16799 .cmd = NL80211_CMD_FRAME, 16800 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16801 .doit = nl80211_tx_mgmt, 16802 .flags = GENL_UNS_ADMIN_PERM, 16803 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16804 }, 16805 { 16806 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 16807 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16808 .doit = nl80211_tx_mgmt_cancel_wait, 16809 .flags = GENL_UNS_ADMIN_PERM, 16810 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16811 }, 16812 { 16813 .cmd = NL80211_CMD_SET_POWER_SAVE, 16814 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16815 .doit = nl80211_set_power_save, 16816 .flags = GENL_UNS_ADMIN_PERM, 16817 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16818 }, 16819 { 16820 .cmd = NL80211_CMD_GET_POWER_SAVE, 16821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16822 .doit = nl80211_get_power_save, 16823 /* can be retrieved by unprivileged users */ 16824 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16825 }, 16826 { 16827 .cmd = NL80211_CMD_SET_CQM, 16828 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16829 .doit = nl80211_set_cqm, 16830 .flags = GENL_UNS_ADMIN_PERM, 16831 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16832 }, 16833 { 16834 .cmd = NL80211_CMD_SET_CHANNEL, 16835 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16836 .doit = nl80211_set_channel, 16837 .flags = GENL_UNS_ADMIN_PERM, 16838 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 16839 NL80211_FLAG_MLO_VALID_LINK_ID), 16840 }, 16841 { 16842 .cmd = NL80211_CMD_JOIN_MESH, 16843 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16844 .doit = nl80211_join_mesh, 16845 .flags = GENL_UNS_ADMIN_PERM, 16846 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16847 }, 16848 { 16849 .cmd = NL80211_CMD_LEAVE_MESH, 16850 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16851 .doit = nl80211_leave_mesh, 16852 .flags = GENL_UNS_ADMIN_PERM, 16853 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16854 }, 16855 { 16856 .cmd = NL80211_CMD_JOIN_OCB, 16857 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16858 .doit = nl80211_join_ocb, 16859 .flags = GENL_UNS_ADMIN_PERM, 16860 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16861 }, 16862 { 16863 .cmd = NL80211_CMD_LEAVE_OCB, 16864 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16865 .doit = nl80211_leave_ocb, 16866 .flags = GENL_UNS_ADMIN_PERM, 16867 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16868 }, 16869 #ifdef CONFIG_PM 16870 { 16871 .cmd = NL80211_CMD_GET_WOWLAN, 16872 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16873 .doit = nl80211_get_wowlan, 16874 /* can be retrieved by unprivileged users */ 16875 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16876 }, 16877 { 16878 .cmd = NL80211_CMD_SET_WOWLAN, 16879 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16880 .doit = nl80211_set_wowlan, 16881 .flags = GENL_UNS_ADMIN_PERM, 16882 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16883 }, 16884 #endif 16885 { 16886 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 16887 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16888 .doit = nl80211_set_rekey_data, 16889 .flags = GENL_UNS_ADMIN_PERM, 16890 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16891 NL80211_FLAG_CLEAR_SKB), 16892 }, 16893 { 16894 .cmd = NL80211_CMD_TDLS_MGMT, 16895 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16896 .doit = nl80211_tdls_mgmt, 16897 .flags = GENL_UNS_ADMIN_PERM, 16898 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16899 }, 16900 { 16901 .cmd = NL80211_CMD_TDLS_OPER, 16902 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16903 .doit = nl80211_tdls_oper, 16904 .flags = GENL_UNS_ADMIN_PERM, 16905 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16906 }, 16907 { 16908 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 16909 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16910 .doit = nl80211_register_unexpected_frame, 16911 .flags = GENL_UNS_ADMIN_PERM, 16912 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16913 }, 16914 { 16915 .cmd = NL80211_CMD_PROBE_CLIENT, 16916 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16917 .doit = nl80211_probe_client, 16918 .flags = GENL_UNS_ADMIN_PERM, 16919 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16920 }, 16921 { 16922 .cmd = NL80211_CMD_REGISTER_BEACONS, 16923 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16924 .doit = nl80211_register_beacons, 16925 .flags = GENL_UNS_ADMIN_PERM, 16926 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16927 }, 16928 { 16929 .cmd = NL80211_CMD_SET_NOACK_MAP, 16930 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16931 .doit = nl80211_set_noack_map, 16932 .flags = GENL_UNS_ADMIN_PERM, 16933 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16934 }, 16935 { 16936 .cmd = NL80211_CMD_START_P2P_DEVICE, 16937 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16938 .doit = nl80211_start_p2p_device, 16939 .flags = GENL_UNS_ADMIN_PERM, 16940 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 16941 NL80211_FLAG_NEED_RTNL), 16942 }, 16943 { 16944 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 16945 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16946 .doit = nl80211_stop_p2p_device, 16947 .flags = GENL_UNS_ADMIN_PERM, 16948 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 16949 NL80211_FLAG_NEED_RTNL), 16950 }, 16951 { 16952 .cmd = NL80211_CMD_START_NAN, 16953 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16954 .doit = nl80211_start_nan, 16955 .flags = GENL_ADMIN_PERM, 16956 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 16957 NL80211_FLAG_NEED_RTNL), 16958 }, 16959 { 16960 .cmd = NL80211_CMD_STOP_NAN, 16961 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16962 .doit = nl80211_stop_nan, 16963 .flags = GENL_ADMIN_PERM, 16964 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 16965 NL80211_FLAG_NEED_RTNL), 16966 }, 16967 { 16968 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 16969 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16970 .doit = nl80211_nan_add_func, 16971 .flags = GENL_ADMIN_PERM, 16972 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16973 }, 16974 { 16975 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 16976 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16977 .doit = nl80211_nan_del_func, 16978 .flags = GENL_ADMIN_PERM, 16979 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16980 }, 16981 { 16982 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 16983 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16984 .doit = nl80211_nan_change_config, 16985 .flags = GENL_ADMIN_PERM, 16986 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16987 }, 16988 { 16989 .cmd = NL80211_CMD_SET_MCAST_RATE, 16990 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16991 .doit = nl80211_set_mcast_rate, 16992 .flags = GENL_UNS_ADMIN_PERM, 16993 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16994 }, 16995 { 16996 .cmd = NL80211_CMD_SET_MAC_ACL, 16997 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16998 .doit = nl80211_set_mac_acl, 16999 .flags = GENL_UNS_ADMIN_PERM, 17000 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17001 NL80211_FLAG_MLO_UNSUPPORTED), 17002 }, 17003 { 17004 .cmd = NL80211_CMD_RADAR_DETECT, 17005 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17006 .doit = nl80211_start_radar_detection, 17007 .flags = GENL_UNS_ADMIN_PERM, 17008 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17009 NL80211_FLAG_NO_WIPHY_MTX | 17010 NL80211_FLAG_MLO_UNSUPPORTED), 17011 }, 17012 { 17013 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 17014 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17015 .doit = nl80211_get_protocol_features, 17016 }, 17017 { 17018 .cmd = NL80211_CMD_UPDATE_FT_IES, 17019 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17020 .doit = nl80211_update_ft_ies, 17021 .flags = GENL_UNS_ADMIN_PERM, 17022 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17023 }, 17024 { 17025 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 17026 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17027 .doit = nl80211_crit_protocol_start, 17028 .flags = GENL_UNS_ADMIN_PERM, 17029 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17030 }, 17031 { 17032 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 17033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17034 .doit = nl80211_crit_protocol_stop, 17035 .flags = GENL_UNS_ADMIN_PERM, 17036 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17037 }, 17038 { 17039 .cmd = NL80211_CMD_GET_COALESCE, 17040 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17041 .doit = nl80211_get_coalesce, 17042 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17043 }, 17044 { 17045 .cmd = NL80211_CMD_SET_COALESCE, 17046 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17047 .doit = nl80211_set_coalesce, 17048 .flags = GENL_UNS_ADMIN_PERM, 17049 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17050 }, 17051 { 17052 .cmd = NL80211_CMD_CHANNEL_SWITCH, 17053 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17054 .doit = nl80211_channel_switch, 17055 .flags = GENL_UNS_ADMIN_PERM, 17056 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17057 NL80211_FLAG_MLO_VALID_LINK_ID), 17058 }, 17059 { 17060 .cmd = NL80211_CMD_VENDOR, 17061 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17062 .doit = nl80211_vendor_cmd, 17063 .dumpit = nl80211_vendor_cmd_dump, 17064 .flags = GENL_UNS_ADMIN_PERM, 17065 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17066 NL80211_FLAG_CLEAR_SKB), 17067 }, 17068 { 17069 .cmd = NL80211_CMD_SET_QOS_MAP, 17070 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17071 .doit = nl80211_set_qos_map, 17072 .flags = GENL_UNS_ADMIN_PERM, 17073 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17074 }, 17075 { 17076 .cmd = NL80211_CMD_ADD_TX_TS, 17077 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17078 .doit = nl80211_add_tx_ts, 17079 .flags = GENL_UNS_ADMIN_PERM, 17080 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17081 NL80211_FLAG_MLO_UNSUPPORTED), 17082 }, 17083 { 17084 .cmd = NL80211_CMD_DEL_TX_TS, 17085 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17086 .doit = nl80211_del_tx_ts, 17087 .flags = GENL_UNS_ADMIN_PERM, 17088 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17089 }, 17090 { 17091 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 17092 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17093 .doit = nl80211_tdls_channel_switch, 17094 .flags = GENL_UNS_ADMIN_PERM, 17095 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17096 }, 17097 { 17098 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 17099 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17100 .doit = nl80211_tdls_cancel_channel_switch, 17101 .flags = GENL_UNS_ADMIN_PERM, 17102 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17103 }, 17104 { 17105 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 17106 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17107 .doit = nl80211_set_multicast_to_unicast, 17108 .flags = GENL_UNS_ADMIN_PERM, 17109 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17110 }, 17111 { 17112 .cmd = NL80211_CMD_SET_PMK, 17113 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17114 .doit = nl80211_set_pmk, 17115 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17116 NL80211_FLAG_CLEAR_SKB), 17117 }, 17118 { 17119 .cmd = NL80211_CMD_DEL_PMK, 17120 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17121 .doit = nl80211_del_pmk, 17122 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17123 }, 17124 { 17125 .cmd = NL80211_CMD_EXTERNAL_AUTH, 17126 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17127 .doit = nl80211_external_auth, 17128 .flags = GENL_ADMIN_PERM, 17129 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17130 }, 17131 { 17132 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 17133 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17134 .doit = nl80211_tx_control_port, 17135 .flags = GENL_UNS_ADMIN_PERM, 17136 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17137 }, 17138 { 17139 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 17140 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17141 .doit = nl80211_get_ftm_responder_stats, 17142 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17143 NL80211_FLAG_MLO_VALID_LINK_ID), 17144 }, 17145 { 17146 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 17147 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17148 .doit = nl80211_pmsr_start, 17149 .flags = GENL_UNS_ADMIN_PERM, 17150 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17151 }, 17152 { 17153 .cmd = NL80211_CMD_NOTIFY_RADAR, 17154 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17155 .doit = nl80211_notify_radar_detection, 17156 .flags = GENL_UNS_ADMIN_PERM, 17157 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17158 }, 17159 { 17160 .cmd = NL80211_CMD_UPDATE_OWE_INFO, 17161 .doit = nl80211_update_owe_info, 17162 .flags = GENL_ADMIN_PERM, 17163 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17164 }, 17165 { 17166 .cmd = NL80211_CMD_PROBE_MESH_LINK, 17167 .doit = nl80211_probe_mesh_link, 17168 .flags = GENL_UNS_ADMIN_PERM, 17169 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17170 }, 17171 { 17172 .cmd = NL80211_CMD_SET_TID_CONFIG, 17173 .doit = nl80211_set_tid_config, 17174 .flags = GENL_UNS_ADMIN_PERM, 17175 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17176 NL80211_FLAG_MLO_VALID_LINK_ID), 17177 }, 17178 { 17179 .cmd = NL80211_CMD_SET_SAR_SPECS, 17180 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17181 .doit = nl80211_set_sar_specs, 17182 .flags = GENL_UNS_ADMIN_PERM, 17183 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17184 NL80211_FLAG_NEED_RTNL), 17185 }, 17186 { 17187 .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST, 17188 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17189 .doit = nl80211_color_change, 17190 .flags = GENL_UNS_ADMIN_PERM, 17191 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17192 }, 17193 { 17194 .cmd = NL80211_CMD_SET_FILS_AAD, 17195 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17196 .doit = nl80211_set_fils_aad, 17197 .flags = GENL_UNS_ADMIN_PERM, 17198 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17199 }, 17200 { 17201 .cmd = NL80211_CMD_ADD_LINK, 17202 .doit = nl80211_add_link, 17203 .flags = GENL_UNS_ADMIN_PERM, 17204 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17205 }, 17206 { 17207 .cmd = NL80211_CMD_REMOVE_LINK, 17208 .doit = nl80211_remove_link, 17209 .flags = GENL_UNS_ADMIN_PERM, 17210 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17211 NL80211_FLAG_MLO_VALID_LINK_ID), 17212 }, 17213 { 17214 .cmd = NL80211_CMD_ADD_LINK_STA, 17215 .doit = nl80211_add_link_station, 17216 .flags = GENL_UNS_ADMIN_PERM, 17217 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17218 NL80211_FLAG_MLO_VALID_LINK_ID), 17219 }, 17220 { 17221 .cmd = NL80211_CMD_MODIFY_LINK_STA, 17222 .doit = nl80211_modify_link_station, 17223 .flags = GENL_UNS_ADMIN_PERM, 17224 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17225 NL80211_FLAG_MLO_VALID_LINK_ID), 17226 }, 17227 { 17228 .cmd = NL80211_CMD_REMOVE_LINK_STA, 17229 .doit = nl80211_remove_link_station, 17230 .flags = GENL_UNS_ADMIN_PERM, 17231 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17232 NL80211_FLAG_MLO_VALID_LINK_ID), 17233 }, 17234 }; 17235 17236 static struct genl_family nl80211_fam __ro_after_init = { 17237 .name = NL80211_GENL_NAME, /* have users key off the name instead */ 17238 .hdrsize = 0, /* no private header */ 17239 .version = 1, /* no particular meaning now */ 17240 .maxattr = NL80211_ATTR_MAX, 17241 .policy = nl80211_policy, 17242 .netnsok = true, 17243 .pre_doit = nl80211_pre_doit, 17244 .post_doit = nl80211_post_doit, 17245 .module = THIS_MODULE, 17246 .ops = nl80211_ops, 17247 .n_ops = ARRAY_SIZE(nl80211_ops), 17248 .small_ops = nl80211_small_ops, 17249 .n_small_ops = ARRAY_SIZE(nl80211_small_ops), 17250 .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1, 17251 .mcgrps = nl80211_mcgrps, 17252 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), 17253 .parallel_ops = true, 17254 }; 17255 17256 /* notification functions */ 17257 17258 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, 17259 enum nl80211_commands cmd) 17260 { 17261 struct sk_buff *msg; 17262 struct nl80211_dump_wiphy_state state = {}; 17263 17264 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && 17265 cmd != NL80211_CMD_DEL_WIPHY); 17266 17267 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17268 if (!msg) 17269 return; 17270 17271 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { 17272 nlmsg_free(msg); 17273 return; 17274 } 17275 17276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17277 NL80211_MCGRP_CONFIG, GFP_KERNEL); 17278 } 17279 17280 void nl80211_notify_iface(struct cfg80211_registered_device *rdev, 17281 struct wireless_dev *wdev, 17282 enum nl80211_commands cmd) 17283 { 17284 struct sk_buff *msg; 17285 17286 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17287 if (!msg) 17288 return; 17289 17290 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { 17291 nlmsg_free(msg); 17292 return; 17293 } 17294 17295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17296 NL80211_MCGRP_CONFIG, GFP_KERNEL); 17297 } 17298 17299 static int nl80211_add_scan_req(struct sk_buff *msg, 17300 struct cfg80211_registered_device *rdev) 17301 { 17302 struct cfg80211_scan_request *req = rdev->scan_req; 17303 struct nlattr *nest; 17304 int i; 17305 struct cfg80211_scan_info *info; 17306 17307 if (WARN_ON(!req)) 17308 return 0; 17309 17310 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); 17311 if (!nest) 17312 goto nla_put_failure; 17313 for (i = 0; i < req->n_ssids; i++) { 17314 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 17315 goto nla_put_failure; 17316 } 17317 nla_nest_end(msg, nest); 17318 17319 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { 17320 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); 17321 if (!nest) 17322 goto nla_put_failure; 17323 for (i = 0; i < req->n_channels; i++) { 17324 if (nla_put_u32(msg, i, 17325 ieee80211_channel_to_khz(req->channels[i]))) 17326 goto nla_put_failure; 17327 } 17328 nla_nest_end(msg, nest); 17329 } else { 17330 nest = nla_nest_start_noflag(msg, 17331 NL80211_ATTR_SCAN_FREQUENCIES); 17332 if (!nest) 17333 goto nla_put_failure; 17334 for (i = 0; i < req->n_channels; i++) { 17335 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 17336 goto nla_put_failure; 17337 } 17338 nla_nest_end(msg, nest); 17339 } 17340 17341 if (req->ie && 17342 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) 17343 goto nla_put_failure; 17344 17345 if (req->flags && 17346 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) 17347 goto nla_put_failure; 17348 17349 info = rdev->int_scan_req ? &rdev->int_scan_req->info : 17350 &rdev->scan_req->info; 17351 if (info->scan_start_tsf && 17352 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, 17353 info->scan_start_tsf, NL80211_BSS_PAD) || 17354 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, 17355 info->tsf_bssid))) 17356 goto nla_put_failure; 17357 17358 return 0; 17359 nla_put_failure: 17360 return -ENOBUFS; 17361 } 17362 17363 static int nl80211_prep_scan_msg(struct sk_buff *msg, 17364 struct cfg80211_registered_device *rdev, 17365 struct wireless_dev *wdev, 17366 u32 portid, u32 seq, int flags, 17367 u32 cmd) 17368 { 17369 void *hdr; 17370 17371 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 17372 if (!hdr) 17373 return -1; 17374 17375 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17376 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 17377 wdev->netdev->ifindex)) || 17378 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17379 NL80211_ATTR_PAD)) 17380 goto nla_put_failure; 17381 17382 /* ignore errors and send incomplete event anyway */ 17383 nl80211_add_scan_req(msg, rdev); 17384 17385 genlmsg_end(msg, hdr); 17386 return 0; 17387 17388 nla_put_failure: 17389 genlmsg_cancel(msg, hdr); 17390 return -EMSGSIZE; 17391 } 17392 17393 static int 17394 nl80211_prep_sched_scan_msg(struct sk_buff *msg, 17395 struct cfg80211_sched_scan_request *req, u32 cmd) 17396 { 17397 void *hdr; 17398 17399 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17400 if (!hdr) 17401 return -1; 17402 17403 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, 17404 wiphy_to_rdev(req->wiphy)->wiphy_idx) || 17405 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || 17406 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, 17407 NL80211_ATTR_PAD)) 17408 goto nla_put_failure; 17409 17410 genlmsg_end(msg, hdr); 17411 return 0; 17412 17413 nla_put_failure: 17414 genlmsg_cancel(msg, hdr); 17415 return -EMSGSIZE; 17416 } 17417 17418 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 17419 struct wireless_dev *wdev) 17420 { 17421 struct sk_buff *msg; 17422 17423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17424 if (!msg) 17425 return; 17426 17427 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 17428 NL80211_CMD_TRIGGER_SCAN) < 0) { 17429 nlmsg_free(msg); 17430 return; 17431 } 17432 17433 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17434 NL80211_MCGRP_SCAN, GFP_KERNEL); 17435 } 17436 17437 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 17438 struct wireless_dev *wdev, bool aborted) 17439 { 17440 struct sk_buff *msg; 17441 17442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17443 if (!msg) 17444 return NULL; 17445 17446 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 17447 aborted ? NL80211_CMD_SCAN_ABORTED : 17448 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 17449 nlmsg_free(msg); 17450 return NULL; 17451 } 17452 17453 return msg; 17454 } 17455 17456 /* send message created by nl80211_build_scan_msg() */ 17457 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, 17458 struct sk_buff *msg) 17459 { 17460 if (!msg) 17461 return; 17462 17463 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17464 NL80211_MCGRP_SCAN, GFP_KERNEL); 17465 } 17466 17467 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) 17468 { 17469 struct sk_buff *msg; 17470 17471 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17472 if (!msg) 17473 return; 17474 17475 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { 17476 nlmsg_free(msg); 17477 return; 17478 } 17479 17480 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, 17481 NL80211_MCGRP_SCAN, GFP_KERNEL); 17482 } 17483 17484 static bool nl80211_reg_change_event_fill(struct sk_buff *msg, 17485 struct regulatory_request *request) 17486 { 17487 /* Userspace can always count this one always being set */ 17488 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) 17489 goto nla_put_failure; 17490 17491 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { 17492 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17493 NL80211_REGDOM_TYPE_WORLD)) 17494 goto nla_put_failure; 17495 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { 17496 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17497 NL80211_REGDOM_TYPE_CUSTOM_WORLD)) 17498 goto nla_put_failure; 17499 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || 17500 request->intersect) { 17501 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17502 NL80211_REGDOM_TYPE_INTERSECTION)) 17503 goto nla_put_failure; 17504 } else { 17505 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17506 NL80211_REGDOM_TYPE_COUNTRY) || 17507 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, 17508 request->alpha2)) 17509 goto nla_put_failure; 17510 } 17511 17512 if (request->wiphy_idx != WIPHY_IDX_INVALID) { 17513 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); 17514 17515 if (wiphy && 17516 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 17517 goto nla_put_failure; 17518 17519 if (wiphy && 17520 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 17521 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 17522 goto nla_put_failure; 17523 } 17524 17525 return true; 17526 17527 nla_put_failure: 17528 return false; 17529 } 17530 17531 /* 17532 * This can happen on global regulatory changes or device specific settings 17533 * based on custom regulatory domains. 17534 */ 17535 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, 17536 struct regulatory_request *request) 17537 { 17538 struct sk_buff *msg; 17539 void *hdr; 17540 17541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17542 if (!msg) 17543 return; 17544 17545 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); 17546 if (!hdr) 17547 goto nla_put_failure; 17548 17549 if (!nl80211_reg_change_event_fill(msg, request)) 17550 goto nla_put_failure; 17551 17552 genlmsg_end(msg, hdr); 17553 17554 rcu_read_lock(); 17555 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 17556 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 17557 rcu_read_unlock(); 17558 17559 return; 17560 17561 nla_put_failure: 17562 nlmsg_free(msg); 17563 } 17564 17565 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 17566 struct net_device *netdev, 17567 const u8 *buf, size_t len, 17568 enum nl80211_commands cmd, gfp_t gfp, 17569 int uapsd_queues, const u8 *req_ies, 17570 size_t req_ies_len, bool reconnect) 17571 { 17572 struct sk_buff *msg; 17573 void *hdr; 17574 17575 msg = nlmsg_new(100 + len + req_ies_len, gfp); 17576 if (!msg) 17577 return; 17578 17579 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17580 if (!hdr) { 17581 nlmsg_free(msg); 17582 return; 17583 } 17584 17585 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17586 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17587 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 17588 (req_ies && 17589 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) 17590 goto nla_put_failure; 17591 17592 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED)) 17593 goto nla_put_failure; 17594 17595 if (uapsd_queues >= 0) { 17596 struct nlattr *nla_wmm = 17597 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); 17598 if (!nla_wmm) 17599 goto nla_put_failure; 17600 17601 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, 17602 uapsd_queues)) 17603 goto nla_put_failure; 17604 17605 nla_nest_end(msg, nla_wmm); 17606 } 17607 17608 genlmsg_end(msg, hdr); 17609 17610 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17611 NL80211_MCGRP_MLME, gfp); 17612 return; 17613 17614 nla_put_failure: 17615 nlmsg_free(msg); 17616 } 17617 17618 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 17619 struct net_device *netdev, const u8 *buf, 17620 size_t len, gfp_t gfp) 17621 { 17622 nl80211_send_mlme_event(rdev, netdev, buf, len, 17623 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0, 17624 false); 17625 } 17626 17627 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 17628 struct net_device *netdev, 17629 struct cfg80211_rx_assoc_resp *data) 17630 { 17631 nl80211_send_mlme_event(rdev, netdev, data->buf, data->len, 17632 NL80211_CMD_ASSOCIATE, GFP_KERNEL, 17633 data->uapsd_queues, 17634 data->req_ies, data->req_ies_len, false); 17635 } 17636 17637 void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 17638 struct net_device *netdev, const u8 *buf, 17639 size_t len, bool reconnect, gfp_t gfp) 17640 { 17641 nl80211_send_mlme_event(rdev, netdev, buf, len, 17642 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0, 17643 reconnect); 17644 } 17645 17646 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 17647 struct net_device *netdev, const u8 *buf, 17648 size_t len, bool reconnect, gfp_t gfp) 17649 { 17650 nl80211_send_mlme_event(rdev, netdev, buf, len, 17651 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0, 17652 reconnect); 17653 } 17654 17655 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, 17656 size_t len) 17657 { 17658 struct wireless_dev *wdev = dev->ieee80211_ptr; 17659 struct wiphy *wiphy = wdev->wiphy; 17660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17661 const struct ieee80211_mgmt *mgmt = (void *)buf; 17662 u32 cmd; 17663 17664 if (WARN_ON(len < 2)) 17665 return; 17666 17667 if (ieee80211_is_deauth(mgmt->frame_control)) { 17668 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; 17669 } else if (ieee80211_is_disassoc(mgmt->frame_control)) { 17670 cmd = NL80211_CMD_UNPROT_DISASSOCIATE; 17671 } else if (ieee80211_is_beacon(mgmt->frame_control)) { 17672 if (wdev->unprot_beacon_reported && 17673 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) 17674 return; 17675 cmd = NL80211_CMD_UNPROT_BEACON; 17676 wdev->unprot_beacon_reported = jiffies; 17677 } else { 17678 return; 17679 } 17680 17681 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); 17682 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, 17683 NULL, 0, false); 17684 } 17685 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); 17686 17687 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 17688 struct net_device *netdev, int cmd, 17689 const u8 *addr, gfp_t gfp) 17690 { 17691 struct sk_buff *msg; 17692 void *hdr; 17693 17694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17695 if (!msg) 17696 return; 17697 17698 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17699 if (!hdr) { 17700 nlmsg_free(msg); 17701 return; 17702 } 17703 17704 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17705 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17706 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 17707 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 17708 goto nla_put_failure; 17709 17710 genlmsg_end(msg, hdr); 17711 17712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17713 NL80211_MCGRP_MLME, gfp); 17714 return; 17715 17716 nla_put_failure: 17717 nlmsg_free(msg); 17718 } 17719 17720 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 17721 struct net_device *netdev, const u8 *addr, 17722 gfp_t gfp) 17723 { 17724 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 17725 addr, gfp); 17726 } 17727 17728 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 17729 struct net_device *netdev, const u8 *addr, 17730 gfp_t gfp) 17731 { 17732 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, 17733 addr, gfp); 17734 } 17735 17736 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, 17737 struct net_device *netdev, 17738 struct cfg80211_connect_resp_params *cr, 17739 gfp_t gfp) 17740 { 17741 struct sk_buff *msg; 17742 void *hdr; 17743 unsigned int link; 17744 size_t link_info_size = 0; 17745 const u8 *connected_addr = cr->valid_links ? 17746 cr->ap_mld_addr : cr->links[0].bssid; 17747 17748 if (cr->valid_links) { 17749 for_each_valid_link(cr, link) { 17750 /* Nested attribute header */ 17751 link_info_size += NLA_HDRLEN; 17752 /* Link ID */ 17753 link_info_size += nla_total_size(sizeof(u8)); 17754 link_info_size += cr->links[link].addr ? 17755 nla_total_size(ETH_ALEN) : 0; 17756 link_info_size += (cr->links[link].bssid || 17757 cr->links[link].bss) ? 17758 nla_total_size(ETH_ALEN) : 0; 17759 link_info_size += nla_total_size(sizeof(u16)); 17760 } 17761 } 17762 17763 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + 17764 cr->fils.kek_len + cr->fils.pmk_len + 17765 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size, 17766 gfp); 17767 if (!msg) 17768 return; 17769 17770 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); 17771 if (!hdr) { 17772 nlmsg_free(msg); 17773 return; 17774 } 17775 17776 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17777 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17778 (connected_addr && 17779 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) || 17780 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 17781 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : 17782 cr->status) || 17783 (cr->status < 0 && 17784 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 17785 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, 17786 cr->timeout_reason))) || 17787 (cr->req_ie && 17788 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || 17789 (cr->resp_ie && 17790 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, 17791 cr->resp_ie)) || 17792 (cr->fils.update_erp_next_seq_num && 17793 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 17794 cr->fils.erp_next_seq_num)) || 17795 (cr->status == WLAN_STATUS_SUCCESS && 17796 ((cr->fils.kek && 17797 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, 17798 cr->fils.kek)) || 17799 (cr->fils.pmk && 17800 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || 17801 (cr->fils.pmkid && 17802 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) 17803 goto nla_put_failure; 17804 17805 if (cr->valid_links) { 17806 int i = 1; 17807 struct nlattr *nested; 17808 17809 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 17810 if (!nested) 17811 goto nla_put_failure; 17812 17813 for_each_valid_link(cr, link) { 17814 struct nlattr *nested_mlo_links; 17815 const u8 *bssid = cr->links[link].bss ? 17816 cr->links[link].bss->bssid : 17817 cr->links[link].bssid; 17818 17819 nested_mlo_links = nla_nest_start(msg, i); 17820 if (!nested_mlo_links) 17821 goto nla_put_failure; 17822 17823 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || 17824 (bssid && 17825 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || 17826 (cr->links[link].addr && 17827 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 17828 cr->links[link].addr)) || 17829 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 17830 cr->links[link].status)) 17831 goto nla_put_failure; 17832 17833 nla_nest_end(msg, nested_mlo_links); 17834 i++; 17835 } 17836 nla_nest_end(msg, nested); 17837 } 17838 17839 genlmsg_end(msg, hdr); 17840 17841 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17842 NL80211_MCGRP_MLME, gfp); 17843 return; 17844 17845 nla_put_failure: 17846 nlmsg_free(msg); 17847 } 17848 17849 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 17850 struct net_device *netdev, 17851 struct cfg80211_roam_info *info, gfp_t gfp) 17852 { 17853 struct sk_buff *msg; 17854 void *hdr; 17855 size_t link_info_size = 0; 17856 unsigned int link; 17857 const u8 *connected_addr = info->ap_mld_addr ? 17858 info->ap_mld_addr : 17859 (info->links[0].bss ? 17860 info->links[0].bss->bssid : 17861 info->links[0].bssid); 17862 17863 if (info->valid_links) { 17864 for_each_valid_link(info, link) { 17865 /* Nested attribute header */ 17866 link_info_size += NLA_HDRLEN; 17867 /* Link ID */ 17868 link_info_size += nla_total_size(sizeof(u8)); 17869 link_info_size += info->links[link].addr ? 17870 nla_total_size(ETH_ALEN) : 0; 17871 link_info_size += (info->links[link].bssid || 17872 info->links[link].bss) ? 17873 nla_total_size(ETH_ALEN) : 0; 17874 } 17875 } 17876 17877 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + 17878 info->fils.kek_len + info->fils.pmk_len + 17879 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) + 17880 link_info_size, gfp); 17881 if (!msg) 17882 return; 17883 17884 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); 17885 if (!hdr) { 17886 nlmsg_free(msg); 17887 return; 17888 } 17889 17890 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17891 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17892 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || 17893 (info->req_ie && 17894 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 17895 info->req_ie)) || 17896 (info->resp_ie && 17897 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 17898 info->resp_ie)) || 17899 (info->fils.update_erp_next_seq_num && 17900 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 17901 info->fils.erp_next_seq_num)) || 17902 (info->fils.kek && 17903 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, 17904 info->fils.kek)) || 17905 (info->fils.pmk && 17906 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || 17907 (info->fils.pmkid && 17908 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) 17909 goto nla_put_failure; 17910 17911 if (info->valid_links) { 17912 int i = 1; 17913 struct nlattr *nested; 17914 17915 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 17916 if (!nested) 17917 goto nla_put_failure; 17918 17919 for_each_valid_link(info, link) { 17920 struct nlattr *nested_mlo_links; 17921 const u8 *bssid = info->links[link].bss ? 17922 info->links[link].bss->bssid : 17923 info->links[link].bssid; 17924 17925 nested_mlo_links = nla_nest_start(msg, i); 17926 if (!nested_mlo_links) 17927 goto nla_put_failure; 17928 17929 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || 17930 (bssid && 17931 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || 17932 (info->links[link].addr && 17933 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 17934 info->links[link].addr))) 17935 goto nla_put_failure; 17936 17937 nla_nest_end(msg, nested_mlo_links); 17938 i++; 17939 } 17940 nla_nest_end(msg, nested); 17941 } 17942 17943 genlmsg_end(msg, hdr); 17944 17945 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17946 NL80211_MCGRP_MLME, gfp); 17947 return; 17948 17949 nla_put_failure: 17950 nlmsg_free(msg); 17951 } 17952 17953 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, 17954 struct net_device *netdev, const u8 *bssid, 17955 const u8 *td_bitmap, u8 td_bitmap_len) 17956 { 17957 struct sk_buff *msg; 17958 void *hdr; 17959 17960 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17961 if (!msg) 17962 return; 17963 17964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); 17965 if (!hdr) { 17966 nlmsg_free(msg); 17967 return; 17968 } 17969 17970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17971 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17972 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 17973 goto nla_put_failure; 17974 17975 if ((td_bitmap_len > 0) && td_bitmap) 17976 if (nla_put(msg, NL80211_ATTR_TD_BITMAP, 17977 td_bitmap_len, td_bitmap)) 17978 goto nla_put_failure; 17979 17980 genlmsg_end(msg, hdr); 17981 17982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17983 NL80211_MCGRP_MLME, GFP_KERNEL); 17984 return; 17985 17986 nla_put_failure: 17987 nlmsg_free(msg); 17988 } 17989 17990 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 17991 struct net_device *netdev, u16 reason, 17992 const u8 *ie, size_t ie_len, bool from_ap) 17993 { 17994 struct sk_buff *msg; 17995 void *hdr; 17996 17997 msg = nlmsg_new(100 + ie_len, GFP_KERNEL); 17998 if (!msg) 17999 return; 18000 18001 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); 18002 if (!hdr) { 18003 nlmsg_free(msg); 18004 return; 18005 } 18006 18007 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18008 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18009 (reason && 18010 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || 18011 (from_ap && 18012 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || 18013 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) 18014 goto nla_put_failure; 18015 18016 genlmsg_end(msg, hdr); 18017 18018 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18019 NL80211_MCGRP_MLME, GFP_KERNEL); 18020 return; 18021 18022 nla_put_failure: 18023 nlmsg_free(msg); 18024 } 18025 18026 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 18027 struct net_device *netdev, const u8 *bssid, 18028 gfp_t gfp) 18029 { 18030 struct sk_buff *msg; 18031 void *hdr; 18032 18033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18034 if (!msg) 18035 return; 18036 18037 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); 18038 if (!hdr) { 18039 nlmsg_free(msg); 18040 return; 18041 } 18042 18043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18044 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18045 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 18046 goto nla_put_failure; 18047 18048 genlmsg_end(msg, hdr); 18049 18050 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18051 NL80211_MCGRP_MLME, gfp); 18052 return; 18053 18054 nla_put_failure: 18055 nlmsg_free(msg); 18056 } 18057 18058 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, 18059 const u8 *ie, u8 ie_len, 18060 int sig_dbm, gfp_t gfp) 18061 { 18062 struct wireless_dev *wdev = dev->ieee80211_ptr; 18063 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18064 struct sk_buff *msg; 18065 void *hdr; 18066 18067 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) 18068 return; 18069 18070 trace_cfg80211_notify_new_peer_candidate(dev, addr); 18071 18072 msg = nlmsg_new(100 + ie_len, gfp); 18073 if (!msg) 18074 return; 18075 18076 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); 18077 if (!hdr) { 18078 nlmsg_free(msg); 18079 return; 18080 } 18081 18082 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18083 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18084 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 18085 (ie_len && ie && 18086 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || 18087 (sig_dbm && 18088 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) 18089 goto nla_put_failure; 18090 18091 genlmsg_end(msg, hdr); 18092 18093 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18094 NL80211_MCGRP_MLME, gfp); 18095 return; 18096 18097 nla_put_failure: 18098 nlmsg_free(msg); 18099 } 18100 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); 18101 18102 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 18103 struct net_device *netdev, const u8 *addr, 18104 enum nl80211_key_type key_type, int key_id, 18105 const u8 *tsc, gfp_t gfp) 18106 { 18107 struct sk_buff *msg; 18108 void *hdr; 18109 18110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18111 if (!msg) 18112 return; 18113 18114 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); 18115 if (!hdr) { 18116 nlmsg_free(msg); 18117 return; 18118 } 18119 18120 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18121 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18122 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || 18123 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || 18124 (key_id != -1 && 18125 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || 18126 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) 18127 goto nla_put_failure; 18128 18129 genlmsg_end(msg, hdr); 18130 18131 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18132 NL80211_MCGRP_MLME, gfp); 18133 return; 18134 18135 nla_put_failure: 18136 nlmsg_free(msg); 18137 } 18138 18139 void nl80211_send_beacon_hint_event(struct wiphy *wiphy, 18140 struct ieee80211_channel *channel_before, 18141 struct ieee80211_channel *channel_after) 18142 { 18143 struct sk_buff *msg; 18144 void *hdr; 18145 struct nlattr *nl_freq; 18146 18147 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 18148 if (!msg) 18149 return; 18150 18151 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); 18152 if (!hdr) { 18153 nlmsg_free(msg); 18154 return; 18155 } 18156 18157 /* 18158 * Since we are applying the beacon hint to a wiphy we know its 18159 * wiphy_idx is valid 18160 */ 18161 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 18162 goto nla_put_failure; 18163 18164 /* Before */ 18165 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); 18166 if (!nl_freq) 18167 goto nla_put_failure; 18168 18169 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) 18170 goto nla_put_failure; 18171 nla_nest_end(msg, nl_freq); 18172 18173 /* After */ 18174 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); 18175 if (!nl_freq) 18176 goto nla_put_failure; 18177 18178 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) 18179 goto nla_put_failure; 18180 nla_nest_end(msg, nl_freq); 18181 18182 genlmsg_end(msg, hdr); 18183 18184 rcu_read_lock(); 18185 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 18186 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 18187 rcu_read_unlock(); 18188 18189 return; 18190 18191 nla_put_failure: 18192 nlmsg_free(msg); 18193 } 18194 18195 static void nl80211_send_remain_on_chan_event( 18196 int cmd, struct cfg80211_registered_device *rdev, 18197 struct wireless_dev *wdev, u64 cookie, 18198 struct ieee80211_channel *chan, 18199 unsigned int duration, gfp_t gfp) 18200 { 18201 struct sk_buff *msg; 18202 void *hdr; 18203 18204 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18205 if (!msg) 18206 return; 18207 18208 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 18209 if (!hdr) { 18210 nlmsg_free(msg); 18211 return; 18212 } 18213 18214 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18215 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18216 wdev->netdev->ifindex)) || 18217 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18218 NL80211_ATTR_PAD) || 18219 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || 18220 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 18221 NL80211_CHAN_NO_HT) || 18222 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 18223 NL80211_ATTR_PAD)) 18224 goto nla_put_failure; 18225 18226 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && 18227 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) 18228 goto nla_put_failure; 18229 18230 genlmsg_end(msg, hdr); 18231 18232 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18233 NL80211_MCGRP_MLME, gfp); 18234 return; 18235 18236 nla_put_failure: 18237 nlmsg_free(msg); 18238 } 18239 18240 void cfg80211_assoc_comeback(struct net_device *netdev, 18241 const u8 *ap_addr, u32 timeout) 18242 { 18243 struct wireless_dev *wdev = netdev->ieee80211_ptr; 18244 struct wiphy *wiphy = wdev->wiphy; 18245 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18246 struct sk_buff *msg; 18247 void *hdr; 18248 18249 trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout); 18250 18251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18252 if (!msg) 18253 return; 18254 18255 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK); 18256 if (!hdr) { 18257 nlmsg_free(msg); 18258 return; 18259 } 18260 18261 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18262 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18263 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) || 18264 nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout)) 18265 goto nla_put_failure; 18266 18267 genlmsg_end(msg, hdr); 18268 18269 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18270 NL80211_MCGRP_MLME, GFP_KERNEL); 18271 return; 18272 18273 nla_put_failure: 18274 nlmsg_free(msg); 18275 } 18276 EXPORT_SYMBOL(cfg80211_assoc_comeback); 18277 18278 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, 18279 struct ieee80211_channel *chan, 18280 unsigned int duration, gfp_t gfp) 18281 { 18282 struct wiphy *wiphy = wdev->wiphy; 18283 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18284 18285 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); 18286 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, 18287 rdev, wdev, cookie, chan, 18288 duration, gfp); 18289 } 18290 EXPORT_SYMBOL(cfg80211_ready_on_channel); 18291 18292 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, 18293 struct ieee80211_channel *chan, 18294 gfp_t gfp) 18295 { 18296 struct wiphy *wiphy = wdev->wiphy; 18297 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18298 18299 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); 18300 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 18301 rdev, wdev, cookie, chan, 0, gfp); 18302 } 18303 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); 18304 18305 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, 18306 struct ieee80211_channel *chan, 18307 gfp_t gfp) 18308 { 18309 struct wiphy *wiphy = wdev->wiphy; 18310 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18311 18312 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); 18313 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, 18314 rdev, wdev, cookie, chan, 0, gfp); 18315 } 18316 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); 18317 18318 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, 18319 struct station_info *sinfo, gfp_t gfp) 18320 { 18321 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18322 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18323 struct sk_buff *msg; 18324 18325 trace_cfg80211_new_sta(dev, mac_addr, sinfo); 18326 18327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18328 if (!msg) 18329 return; 18330 18331 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, 18332 rdev, dev, mac_addr, sinfo) < 0) { 18333 nlmsg_free(msg); 18334 return; 18335 } 18336 18337 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18338 NL80211_MCGRP_MLME, gfp); 18339 } 18340 EXPORT_SYMBOL(cfg80211_new_sta); 18341 18342 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, 18343 struct station_info *sinfo, gfp_t gfp) 18344 { 18345 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18346 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18347 struct sk_buff *msg; 18348 struct station_info empty_sinfo = {}; 18349 18350 if (!sinfo) 18351 sinfo = &empty_sinfo; 18352 18353 trace_cfg80211_del_sta(dev, mac_addr); 18354 18355 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18356 if (!msg) { 18357 cfg80211_sinfo_release_content(sinfo); 18358 return; 18359 } 18360 18361 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, 18362 rdev, dev, mac_addr, sinfo) < 0) { 18363 nlmsg_free(msg); 18364 return; 18365 } 18366 18367 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18368 NL80211_MCGRP_MLME, gfp); 18369 } 18370 EXPORT_SYMBOL(cfg80211_del_sta_sinfo); 18371 18372 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, 18373 enum nl80211_connect_failed_reason reason, 18374 gfp_t gfp) 18375 { 18376 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18377 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18378 struct sk_buff *msg; 18379 void *hdr; 18380 18381 msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 18382 if (!msg) 18383 return; 18384 18385 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); 18386 if (!hdr) { 18387 nlmsg_free(msg); 18388 return; 18389 } 18390 18391 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18392 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 18393 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) 18394 goto nla_put_failure; 18395 18396 genlmsg_end(msg, hdr); 18397 18398 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18399 NL80211_MCGRP_MLME, gfp); 18400 return; 18401 18402 nla_put_failure: 18403 nlmsg_free(msg); 18404 } 18405 EXPORT_SYMBOL(cfg80211_conn_failed); 18406 18407 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, 18408 const u8 *addr, gfp_t gfp) 18409 { 18410 struct wireless_dev *wdev = dev->ieee80211_ptr; 18411 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18412 struct sk_buff *msg; 18413 void *hdr; 18414 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); 18415 18416 if (!nlportid) 18417 return false; 18418 18419 msg = nlmsg_new(100, gfp); 18420 if (!msg) 18421 return true; 18422 18423 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 18424 if (!hdr) { 18425 nlmsg_free(msg); 18426 return true; 18427 } 18428 18429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18430 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18431 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 18432 goto nla_put_failure; 18433 18434 genlmsg_end(msg, hdr); 18435 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18436 return true; 18437 18438 nla_put_failure: 18439 nlmsg_free(msg); 18440 return true; 18441 } 18442 18443 bool cfg80211_rx_spurious_frame(struct net_device *dev, 18444 const u8 *addr, gfp_t gfp) 18445 { 18446 struct wireless_dev *wdev = dev->ieee80211_ptr; 18447 bool ret; 18448 18449 trace_cfg80211_rx_spurious_frame(dev, addr); 18450 18451 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 18452 wdev->iftype != NL80211_IFTYPE_P2P_GO)) { 18453 trace_cfg80211_return_bool(false); 18454 return false; 18455 } 18456 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, 18457 addr, gfp); 18458 trace_cfg80211_return_bool(ret); 18459 return ret; 18460 } 18461 EXPORT_SYMBOL(cfg80211_rx_spurious_frame); 18462 18463 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, 18464 const u8 *addr, gfp_t gfp) 18465 { 18466 struct wireless_dev *wdev = dev->ieee80211_ptr; 18467 bool ret; 18468 18469 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); 18470 18471 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 18472 wdev->iftype != NL80211_IFTYPE_P2P_GO && 18473 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { 18474 trace_cfg80211_return_bool(false); 18475 return false; 18476 } 18477 ret = __nl80211_unexpected_frame(dev, 18478 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, 18479 addr, gfp); 18480 trace_cfg80211_return_bool(ret); 18481 return ret; 18482 } 18483 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); 18484 18485 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, 18486 struct wireless_dev *wdev, u32 nlportid, 18487 struct cfg80211_rx_info *info, gfp_t gfp) 18488 { 18489 struct net_device *netdev = wdev->netdev; 18490 struct sk_buff *msg; 18491 void *hdr; 18492 18493 msg = nlmsg_new(100 + info->len, gfp); 18494 if (!msg) 18495 return -ENOMEM; 18496 18497 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 18498 if (!hdr) { 18499 nlmsg_free(msg); 18500 return -ENOMEM; 18501 } 18502 18503 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18504 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18505 netdev->ifindex)) || 18506 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18507 NL80211_ATTR_PAD) || 18508 (info->have_link_id && 18509 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) || 18510 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) || 18511 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) || 18512 (info->sig_dbm && 18513 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) || 18514 nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) || 18515 (info->flags && 18516 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) || 18517 (info->rx_tstamp && nla_put_u64_64bit(msg, 18518 NL80211_ATTR_RX_HW_TIMESTAMP, 18519 info->rx_tstamp, 18520 NL80211_ATTR_PAD)) || 18521 (info->ack_tstamp && nla_put_u64_64bit(msg, 18522 NL80211_ATTR_TX_HW_TIMESTAMP, 18523 info->ack_tstamp, 18524 NL80211_ATTR_PAD))) 18525 goto nla_put_failure; 18526 18527 genlmsg_end(msg, hdr); 18528 18529 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18530 18531 nla_put_failure: 18532 nlmsg_free(msg); 18533 return -ENOBUFS; 18534 } 18535 18536 static void nl80211_frame_tx_status(struct wireless_dev *wdev, 18537 struct cfg80211_tx_status *status, 18538 gfp_t gfp, enum nl80211_commands command) 18539 { 18540 struct wiphy *wiphy = wdev->wiphy; 18541 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18542 struct net_device *netdev = wdev->netdev; 18543 struct sk_buff *msg; 18544 void *hdr; 18545 18546 if (command == NL80211_CMD_FRAME_TX_STATUS) 18547 trace_cfg80211_mgmt_tx_status(wdev, status->cookie, 18548 status->ack); 18549 else 18550 trace_cfg80211_control_port_tx_status(wdev, status->cookie, 18551 status->ack); 18552 18553 msg = nlmsg_new(100 + status->len, gfp); 18554 if (!msg) 18555 return; 18556 18557 hdr = nl80211hdr_put(msg, 0, 0, 0, command); 18558 if (!hdr) { 18559 nlmsg_free(msg); 18560 return; 18561 } 18562 18563 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18564 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18565 netdev->ifindex)) || 18566 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18567 NL80211_ATTR_PAD) || 18568 nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) || 18569 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie, 18570 NL80211_ATTR_PAD) || 18571 (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) || 18572 (status->tx_tstamp && 18573 nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP, 18574 status->tx_tstamp, NL80211_ATTR_PAD)) || 18575 (status->ack_tstamp && 18576 nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP, 18577 status->ack_tstamp, NL80211_ATTR_PAD))) 18578 goto nla_put_failure; 18579 18580 genlmsg_end(msg, hdr); 18581 18582 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18583 NL80211_MCGRP_MLME, gfp); 18584 return; 18585 18586 nla_put_failure: 18587 nlmsg_free(msg); 18588 } 18589 18590 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, 18591 const u8 *buf, size_t len, bool ack, 18592 gfp_t gfp) 18593 { 18594 struct cfg80211_tx_status status = { 18595 .cookie = cookie, 18596 .buf = buf, 18597 .len = len, 18598 .ack = ack 18599 }; 18600 18601 nl80211_frame_tx_status(wdev, &status, gfp, 18602 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); 18603 } 18604 EXPORT_SYMBOL(cfg80211_control_port_tx_status); 18605 18606 void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev, 18607 struct cfg80211_tx_status *status, gfp_t gfp) 18608 { 18609 nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS); 18610 } 18611 EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext); 18612 18613 static int __nl80211_rx_control_port(struct net_device *dev, 18614 struct sk_buff *skb, 18615 bool unencrypted, gfp_t gfp) 18616 { 18617 struct wireless_dev *wdev = dev->ieee80211_ptr; 18618 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18619 struct ethhdr *ehdr = eth_hdr(skb); 18620 const u8 *addr = ehdr->h_source; 18621 u16 proto = be16_to_cpu(skb->protocol); 18622 struct sk_buff *msg; 18623 void *hdr; 18624 struct nlattr *frame; 18625 18626 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); 18627 18628 if (!nlportid) 18629 return -ENOENT; 18630 18631 msg = nlmsg_new(100 + skb->len, gfp); 18632 if (!msg) 18633 return -ENOMEM; 18634 18635 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); 18636 if (!hdr) { 18637 nlmsg_free(msg); 18638 return -ENOBUFS; 18639 } 18640 18641 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18642 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18643 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18644 NL80211_ATTR_PAD) || 18645 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 18646 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || 18647 (unencrypted && nla_put_flag(msg, 18648 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) 18649 goto nla_put_failure; 18650 18651 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); 18652 if (!frame) 18653 goto nla_put_failure; 18654 18655 skb_copy_bits(skb, 0, nla_data(frame), skb->len); 18656 genlmsg_end(msg, hdr); 18657 18658 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18659 18660 nla_put_failure: 18661 nlmsg_free(msg); 18662 return -ENOBUFS; 18663 } 18664 18665 bool cfg80211_rx_control_port(struct net_device *dev, 18666 struct sk_buff *skb, bool unencrypted) 18667 { 18668 int ret; 18669 18670 trace_cfg80211_rx_control_port(dev, skb, unencrypted); 18671 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); 18672 trace_cfg80211_return_bool(ret == 0); 18673 return ret == 0; 18674 } 18675 EXPORT_SYMBOL(cfg80211_rx_control_port); 18676 18677 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 18678 const char *mac, gfp_t gfp) 18679 { 18680 struct wireless_dev *wdev = dev->ieee80211_ptr; 18681 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18682 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18683 void **cb; 18684 18685 if (!msg) 18686 return NULL; 18687 18688 cb = (void **)msg->cb; 18689 18690 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 18691 if (!cb[0]) { 18692 nlmsg_free(msg); 18693 return NULL; 18694 } 18695 18696 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18697 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 18698 goto nla_put_failure; 18699 18700 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 18701 goto nla_put_failure; 18702 18703 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); 18704 if (!cb[1]) 18705 goto nla_put_failure; 18706 18707 cb[2] = rdev; 18708 18709 return msg; 18710 nla_put_failure: 18711 nlmsg_free(msg); 18712 return NULL; 18713 } 18714 18715 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) 18716 { 18717 void **cb = (void **)msg->cb; 18718 struct cfg80211_registered_device *rdev = cb[2]; 18719 18720 nla_nest_end(msg, cb[1]); 18721 genlmsg_end(msg, cb[0]); 18722 18723 memset(msg->cb, 0, sizeof(msg->cb)); 18724 18725 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18726 NL80211_MCGRP_MLME, gfp); 18727 } 18728 18729 void cfg80211_cqm_rssi_notify(struct net_device *dev, 18730 enum nl80211_cqm_rssi_threshold_event rssi_event, 18731 s32 rssi_level, gfp_t gfp) 18732 { 18733 struct sk_buff *msg; 18734 struct wireless_dev *wdev = dev->ieee80211_ptr; 18735 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18736 18737 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); 18738 18739 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && 18740 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) 18741 return; 18742 18743 if (wdev->cqm_config) { 18744 wdev->cqm_config->last_rssi_event_value = rssi_level; 18745 18746 cfg80211_cqm_rssi_update(rdev, dev); 18747 18748 if (rssi_level == 0) 18749 rssi_level = wdev->cqm_config->last_rssi_event_value; 18750 } 18751 18752 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 18753 if (!msg) 18754 return; 18755 18756 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 18757 rssi_event)) 18758 goto nla_put_failure; 18759 18760 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, 18761 rssi_level)) 18762 goto nla_put_failure; 18763 18764 cfg80211_send_cqm(msg, gfp); 18765 18766 return; 18767 18768 nla_put_failure: 18769 nlmsg_free(msg); 18770 } 18771 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 18772 18773 void cfg80211_cqm_txe_notify(struct net_device *dev, 18774 const u8 *peer, u32 num_packets, 18775 u32 rate, u32 intvl, gfp_t gfp) 18776 { 18777 struct sk_buff *msg; 18778 18779 msg = cfg80211_prepare_cqm(dev, peer, gfp); 18780 if (!msg) 18781 return; 18782 18783 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 18784 goto nla_put_failure; 18785 18786 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 18787 goto nla_put_failure; 18788 18789 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 18790 goto nla_put_failure; 18791 18792 cfg80211_send_cqm(msg, gfp); 18793 return; 18794 18795 nla_put_failure: 18796 nlmsg_free(msg); 18797 } 18798 EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 18799 18800 void cfg80211_cqm_pktloss_notify(struct net_device *dev, 18801 const u8 *peer, u32 num_packets, gfp_t gfp) 18802 { 18803 struct sk_buff *msg; 18804 18805 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 18806 18807 msg = cfg80211_prepare_cqm(dev, peer, gfp); 18808 if (!msg) 18809 return; 18810 18811 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 18812 goto nla_put_failure; 18813 18814 cfg80211_send_cqm(msg, gfp); 18815 return; 18816 18817 nla_put_failure: 18818 nlmsg_free(msg); 18819 } 18820 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 18821 18822 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) 18823 { 18824 struct sk_buff *msg; 18825 18826 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 18827 if (!msg) 18828 return; 18829 18830 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) 18831 goto nla_put_failure; 18832 18833 cfg80211_send_cqm(msg, gfp); 18834 return; 18835 18836 nla_put_failure: 18837 nlmsg_free(msg); 18838 } 18839 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); 18840 18841 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 18842 struct net_device *netdev, const u8 *bssid, 18843 const u8 *replay_ctr, gfp_t gfp) 18844 { 18845 struct sk_buff *msg; 18846 struct nlattr *rekey_attr; 18847 void *hdr; 18848 18849 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18850 if (!msg) 18851 return; 18852 18853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); 18854 if (!hdr) { 18855 nlmsg_free(msg); 18856 return; 18857 } 18858 18859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18860 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18861 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 18862 goto nla_put_failure; 18863 18864 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); 18865 if (!rekey_attr) 18866 goto nla_put_failure; 18867 18868 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, 18869 NL80211_REPLAY_CTR_LEN, replay_ctr)) 18870 goto nla_put_failure; 18871 18872 nla_nest_end(msg, rekey_attr); 18873 18874 genlmsg_end(msg, hdr); 18875 18876 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18877 NL80211_MCGRP_MLME, gfp); 18878 return; 18879 18880 nla_put_failure: 18881 nlmsg_free(msg); 18882 } 18883 18884 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, 18885 const u8 *replay_ctr, gfp_t gfp) 18886 { 18887 struct wireless_dev *wdev = dev->ieee80211_ptr; 18888 struct wiphy *wiphy = wdev->wiphy; 18889 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18890 18891 trace_cfg80211_gtk_rekey_notify(dev, bssid); 18892 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); 18893 } 18894 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); 18895 18896 static void 18897 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, 18898 struct net_device *netdev, int index, 18899 const u8 *bssid, bool preauth, gfp_t gfp) 18900 { 18901 struct sk_buff *msg; 18902 struct nlattr *attr; 18903 void *hdr; 18904 18905 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18906 if (!msg) 18907 return; 18908 18909 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); 18910 if (!hdr) { 18911 nlmsg_free(msg); 18912 return; 18913 } 18914 18915 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18916 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 18917 goto nla_put_failure; 18918 18919 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); 18920 if (!attr) 18921 goto nla_put_failure; 18922 18923 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || 18924 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || 18925 (preauth && 18926 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) 18927 goto nla_put_failure; 18928 18929 nla_nest_end(msg, attr); 18930 18931 genlmsg_end(msg, hdr); 18932 18933 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18934 NL80211_MCGRP_MLME, gfp); 18935 return; 18936 18937 nla_put_failure: 18938 nlmsg_free(msg); 18939 } 18940 18941 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, 18942 const u8 *bssid, bool preauth, gfp_t gfp) 18943 { 18944 struct wireless_dev *wdev = dev->ieee80211_ptr; 18945 struct wiphy *wiphy = wdev->wiphy; 18946 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18947 18948 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); 18949 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 18950 } 18951 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 18952 18953 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, 18954 struct net_device *netdev, 18955 unsigned int link_id, 18956 struct cfg80211_chan_def *chandef, 18957 gfp_t gfp, 18958 enum nl80211_commands notif, 18959 u8 count, bool quiet) 18960 { 18961 struct wireless_dev *wdev = netdev->ieee80211_ptr; 18962 struct sk_buff *msg; 18963 void *hdr; 18964 18965 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18966 if (!msg) 18967 return; 18968 18969 hdr = nl80211hdr_put(msg, 0, 0, 0, notif); 18970 if (!hdr) { 18971 nlmsg_free(msg); 18972 return; 18973 } 18974 18975 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 18976 goto nla_put_failure; 18977 18978 if (wdev->valid_links && 18979 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 18980 goto nla_put_failure; 18981 18982 if (nl80211_send_chandef(msg, chandef)) 18983 goto nla_put_failure; 18984 18985 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) { 18986 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)) 18987 goto nla_put_failure; 18988 if (quiet && 18989 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) 18990 goto nla_put_failure; 18991 } 18992 18993 genlmsg_end(msg, hdr); 18994 18995 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18996 NL80211_MCGRP_MLME, gfp); 18997 return; 18998 18999 nla_put_failure: 19000 nlmsg_free(msg); 19001 } 19002 19003 void cfg80211_ch_switch_notify(struct net_device *dev, 19004 struct cfg80211_chan_def *chandef, 19005 unsigned int link_id) 19006 { 19007 struct wireless_dev *wdev = dev->ieee80211_ptr; 19008 struct wiphy *wiphy = wdev->wiphy; 19009 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19010 19011 ASSERT_WDEV_LOCK(wdev); 19012 WARN_INVALID_LINK_ID(wdev, link_id); 19013 19014 trace_cfg80211_ch_switch_notify(dev, chandef, link_id); 19015 19016 switch (wdev->iftype) { 19017 case NL80211_IFTYPE_STATION: 19018 case NL80211_IFTYPE_P2P_CLIENT: 19019 if (!WARN_ON(!wdev->links[link_id].client.current_bss)) 19020 cfg80211_update_assoc_bss_entry(wdev, link_id, 19021 chandef->chan); 19022 break; 19023 case NL80211_IFTYPE_MESH_POINT: 19024 wdev->u.mesh.chandef = *chandef; 19025 wdev->u.mesh.preset_chandef = *chandef; 19026 break; 19027 case NL80211_IFTYPE_AP: 19028 case NL80211_IFTYPE_P2P_GO: 19029 wdev->links[link_id].ap.chandef = *chandef; 19030 break; 19031 case NL80211_IFTYPE_ADHOC: 19032 wdev->u.ibss.chandef = *chandef; 19033 break; 19034 default: 19035 WARN_ON(1); 19036 break; 19037 } 19038 19039 cfg80211_sched_dfs_chan_update(rdev); 19040 19041 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, 19042 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false); 19043 } 19044 EXPORT_SYMBOL(cfg80211_ch_switch_notify); 19045 19046 void cfg80211_ch_switch_started_notify(struct net_device *dev, 19047 struct cfg80211_chan_def *chandef, 19048 unsigned int link_id, u8 count, 19049 bool quiet) 19050 { 19051 struct wireless_dev *wdev = dev->ieee80211_ptr; 19052 struct wiphy *wiphy = wdev->wiphy; 19053 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19054 19055 ASSERT_WDEV_LOCK(wdev); 19056 WARN_INVALID_LINK_ID(wdev, link_id); 19057 19058 trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id); 19059 19060 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, 19061 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, 19062 count, quiet); 19063 } 19064 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 19065 19066 int cfg80211_bss_color_notify(struct net_device *dev, gfp_t gfp, 19067 enum nl80211_commands cmd, u8 count, 19068 u64 color_bitmap) 19069 { 19070 struct wireless_dev *wdev = dev->ieee80211_ptr; 19071 struct wiphy *wiphy = wdev->wiphy; 19072 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19073 struct sk_buff *msg; 19074 void *hdr; 19075 19076 ASSERT_WDEV_LOCK(wdev); 19077 19078 trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap); 19079 19080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19081 if (!msg) 19082 return -ENOMEM; 19083 19084 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 19085 if (!hdr) 19086 goto nla_put_failure; 19087 19088 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19089 goto nla_put_failure; 19090 19091 if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED && 19092 nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count)) 19093 goto nla_put_failure; 19094 19095 if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION && 19096 nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP, 19097 color_bitmap, NL80211_ATTR_PAD)) 19098 goto nla_put_failure; 19099 19100 genlmsg_end(msg, hdr); 19101 19102 return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 19103 msg, 0, NL80211_MCGRP_MLME, gfp); 19104 19105 nla_put_failure: 19106 nlmsg_free(msg); 19107 return -EINVAL; 19108 } 19109 EXPORT_SYMBOL(cfg80211_bss_color_notify); 19110 19111 void 19112 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 19113 const struct cfg80211_chan_def *chandef, 19114 enum nl80211_radar_event event, 19115 struct net_device *netdev, gfp_t gfp) 19116 { 19117 struct sk_buff *msg; 19118 void *hdr; 19119 19120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19121 if (!msg) 19122 return; 19123 19124 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); 19125 if (!hdr) { 19126 nlmsg_free(msg); 19127 return; 19128 } 19129 19130 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 19131 goto nla_put_failure; 19132 19133 /* NOP and radar events don't need a netdev parameter */ 19134 if (netdev) { 19135 struct wireless_dev *wdev = netdev->ieee80211_ptr; 19136 19137 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19138 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19139 NL80211_ATTR_PAD)) 19140 goto nla_put_failure; 19141 } 19142 19143 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) 19144 goto nla_put_failure; 19145 19146 if (nl80211_send_chandef(msg, chandef)) 19147 goto nla_put_failure; 19148 19149 genlmsg_end(msg, hdr); 19150 19151 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19152 NL80211_MCGRP_MLME, gfp); 19153 return; 19154 19155 nla_put_failure: 19156 nlmsg_free(msg); 19157 } 19158 19159 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, 19160 struct sta_opmode_info *sta_opmode, 19161 gfp_t gfp) 19162 { 19163 struct sk_buff *msg; 19164 struct wireless_dev *wdev = dev->ieee80211_ptr; 19165 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19166 void *hdr; 19167 19168 if (WARN_ON(!mac)) 19169 return; 19170 19171 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19172 if (!msg) 19173 return; 19174 19175 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); 19176 if (!hdr) { 19177 nlmsg_free(msg); 19178 return; 19179 } 19180 19181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 19182 goto nla_put_failure; 19183 19184 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19185 goto nla_put_failure; 19186 19187 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 19188 goto nla_put_failure; 19189 19190 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && 19191 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) 19192 goto nla_put_failure; 19193 19194 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && 19195 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) 19196 goto nla_put_failure; 19197 19198 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && 19199 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) 19200 goto nla_put_failure; 19201 19202 genlmsg_end(msg, hdr); 19203 19204 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19205 NL80211_MCGRP_MLME, gfp); 19206 19207 return; 19208 19209 nla_put_failure: 19210 nlmsg_free(msg); 19211 } 19212 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); 19213 19214 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 19215 u64 cookie, bool acked, s32 ack_signal, 19216 bool is_valid_ack_signal, gfp_t gfp) 19217 { 19218 struct wireless_dev *wdev = dev->ieee80211_ptr; 19219 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19220 struct sk_buff *msg; 19221 void *hdr; 19222 19223 trace_cfg80211_probe_status(dev, addr, cookie, acked); 19224 19225 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19226 19227 if (!msg) 19228 return; 19229 19230 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); 19231 if (!hdr) { 19232 nlmsg_free(msg); 19233 return; 19234 } 19235 19236 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19237 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19238 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 19239 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 19240 NL80211_ATTR_PAD) || 19241 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || 19242 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, 19243 ack_signal))) 19244 goto nla_put_failure; 19245 19246 genlmsg_end(msg, hdr); 19247 19248 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19249 NL80211_MCGRP_MLME, gfp); 19250 return; 19251 19252 nla_put_failure: 19253 nlmsg_free(msg); 19254 } 19255 EXPORT_SYMBOL(cfg80211_probe_status); 19256 19257 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, 19258 size_t len, int freq, int sig_dbm) 19259 { 19260 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19261 struct sk_buff *msg; 19262 void *hdr; 19263 struct cfg80211_beacon_registration *reg; 19264 19265 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); 19266 19267 spin_lock_bh(&rdev->beacon_registrations_lock); 19268 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 19269 msg = nlmsg_new(len + 100, GFP_ATOMIC); 19270 if (!msg) { 19271 spin_unlock_bh(&rdev->beacon_registrations_lock); 19272 return; 19273 } 19274 19275 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 19276 if (!hdr) 19277 goto nla_put_failure; 19278 19279 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19280 (freq && 19281 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 19282 KHZ_TO_MHZ(freq)) || 19283 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 19284 freq % 1000))) || 19285 (sig_dbm && 19286 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 19287 nla_put(msg, NL80211_ATTR_FRAME, len, frame)) 19288 goto nla_put_failure; 19289 19290 genlmsg_end(msg, hdr); 19291 19292 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); 19293 } 19294 spin_unlock_bh(&rdev->beacon_registrations_lock); 19295 return; 19296 19297 nla_put_failure: 19298 spin_unlock_bh(&rdev->beacon_registrations_lock); 19299 nlmsg_free(msg); 19300 } 19301 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); 19302 19303 #ifdef CONFIG_PM 19304 static int cfg80211_net_detect_results(struct sk_buff *msg, 19305 struct cfg80211_wowlan_wakeup *wakeup) 19306 { 19307 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; 19308 struct nlattr *nl_results, *nl_match, *nl_freqs; 19309 int i, j; 19310 19311 nl_results = nla_nest_start_noflag(msg, 19312 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 19313 if (!nl_results) 19314 return -EMSGSIZE; 19315 19316 for (i = 0; i < nd->n_matches; i++) { 19317 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 19318 19319 nl_match = nla_nest_start_noflag(msg, i); 19320 if (!nl_match) 19321 break; 19322 19323 /* The SSID attribute is optional in nl80211, but for 19324 * simplicity reasons it's always present in the 19325 * cfg80211 structure. If a driver can't pass the 19326 * SSID, that needs to be changed. A zero length SSID 19327 * is still a valid SSID (wildcard), so it cannot be 19328 * used for this purpose. 19329 */ 19330 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, 19331 match->ssid.ssid)) { 19332 nla_nest_cancel(msg, nl_match); 19333 goto out; 19334 } 19335 19336 if (match->n_channels) { 19337 nl_freqs = nla_nest_start_noflag(msg, 19338 NL80211_ATTR_SCAN_FREQUENCIES); 19339 if (!nl_freqs) { 19340 nla_nest_cancel(msg, nl_match); 19341 goto out; 19342 } 19343 19344 for (j = 0; j < match->n_channels; j++) { 19345 if (nla_put_u32(msg, j, match->channels[j])) { 19346 nla_nest_cancel(msg, nl_freqs); 19347 nla_nest_cancel(msg, nl_match); 19348 goto out; 19349 } 19350 } 19351 19352 nla_nest_end(msg, nl_freqs); 19353 } 19354 19355 nla_nest_end(msg, nl_match); 19356 } 19357 19358 out: 19359 nla_nest_end(msg, nl_results); 19360 return 0; 19361 } 19362 19363 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, 19364 struct cfg80211_wowlan_wakeup *wakeup, 19365 gfp_t gfp) 19366 { 19367 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19368 struct sk_buff *msg; 19369 void *hdr; 19370 int size = 200; 19371 19372 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); 19373 19374 if (wakeup) 19375 size += wakeup->packet_present_len; 19376 19377 msg = nlmsg_new(size, gfp); 19378 if (!msg) 19379 return; 19380 19381 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); 19382 if (!hdr) 19383 goto free_msg; 19384 19385 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19386 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19387 NL80211_ATTR_PAD)) 19388 goto free_msg; 19389 19390 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 19391 wdev->netdev->ifindex)) 19392 goto free_msg; 19393 19394 if (wakeup) { 19395 struct nlattr *reasons; 19396 19397 reasons = nla_nest_start_noflag(msg, 19398 NL80211_ATTR_WOWLAN_TRIGGERS); 19399 if (!reasons) 19400 goto free_msg; 19401 19402 if (wakeup->disconnect && 19403 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) 19404 goto free_msg; 19405 if (wakeup->magic_pkt && 19406 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) 19407 goto free_msg; 19408 if (wakeup->gtk_rekey_failure && 19409 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) 19410 goto free_msg; 19411 if (wakeup->eap_identity_req && 19412 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) 19413 goto free_msg; 19414 if (wakeup->four_way_handshake && 19415 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) 19416 goto free_msg; 19417 if (wakeup->rfkill_release && 19418 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) 19419 goto free_msg; 19420 19421 if (wakeup->pattern_idx >= 0 && 19422 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 19423 wakeup->pattern_idx)) 19424 goto free_msg; 19425 19426 if (wakeup->tcp_match && 19427 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) 19428 goto free_msg; 19429 19430 if (wakeup->tcp_connlost && 19431 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) 19432 goto free_msg; 19433 19434 if (wakeup->tcp_nomoretokens && 19435 nla_put_flag(msg, 19436 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) 19437 goto free_msg; 19438 19439 if (wakeup->packet) { 19440 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; 19441 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; 19442 19443 if (!wakeup->packet_80211) { 19444 pkt_attr = 19445 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; 19446 len_attr = 19447 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; 19448 } 19449 19450 if (wakeup->packet_len && 19451 nla_put_u32(msg, len_attr, wakeup->packet_len)) 19452 goto free_msg; 19453 19454 if (nla_put(msg, pkt_attr, wakeup->packet_present_len, 19455 wakeup->packet)) 19456 goto free_msg; 19457 } 19458 19459 if (wakeup->net_detect && 19460 cfg80211_net_detect_results(msg, wakeup)) 19461 goto free_msg; 19462 19463 nla_nest_end(msg, reasons); 19464 } 19465 19466 genlmsg_end(msg, hdr); 19467 19468 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19469 NL80211_MCGRP_MLME, gfp); 19470 return; 19471 19472 free_msg: 19473 nlmsg_free(msg); 19474 } 19475 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); 19476 #endif 19477 19478 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, 19479 enum nl80211_tdls_operation oper, 19480 u16 reason_code, gfp_t gfp) 19481 { 19482 struct wireless_dev *wdev = dev->ieee80211_ptr; 19483 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19484 struct sk_buff *msg; 19485 void *hdr; 19486 19487 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, 19488 reason_code); 19489 19490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19491 if (!msg) 19492 return; 19493 19494 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); 19495 if (!hdr) { 19496 nlmsg_free(msg); 19497 return; 19498 } 19499 19500 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19501 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19502 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || 19503 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || 19504 (reason_code > 0 && 19505 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) 19506 goto nla_put_failure; 19507 19508 genlmsg_end(msg, hdr); 19509 19510 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19511 NL80211_MCGRP_MLME, gfp); 19512 return; 19513 19514 nla_put_failure: 19515 nlmsg_free(msg); 19516 } 19517 EXPORT_SYMBOL(cfg80211_tdls_oper_request); 19518 19519 static int nl80211_netlink_notify(struct notifier_block * nb, 19520 unsigned long state, 19521 void *_notify) 19522 { 19523 struct netlink_notify *notify = _notify; 19524 struct cfg80211_registered_device *rdev; 19525 struct wireless_dev *wdev; 19526 struct cfg80211_beacon_registration *reg, *tmp; 19527 19528 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) 19529 return NOTIFY_DONE; 19530 19531 rcu_read_lock(); 19532 19533 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 19534 struct cfg80211_sched_scan_request *sched_scan_req; 19535 19536 list_for_each_entry_rcu(sched_scan_req, 19537 &rdev->sched_scan_req_list, 19538 list) { 19539 if (sched_scan_req->owner_nlportid == notify->portid) { 19540 sched_scan_req->nl_owner_dead = true; 19541 schedule_work(&rdev->sched_scan_stop_wk); 19542 } 19543 } 19544 19545 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { 19546 cfg80211_mlme_unregister_socket(wdev, notify->portid); 19547 19548 if (wdev->owner_nlportid == notify->portid) { 19549 wdev->nl_owner_dead = true; 19550 schedule_work(&rdev->destroy_work); 19551 } else if (wdev->conn_owner_nlportid == notify->portid) { 19552 schedule_work(&wdev->disconnect_wk); 19553 } 19554 19555 cfg80211_release_pmsr(wdev, notify->portid); 19556 } 19557 19558 spin_lock_bh(&rdev->beacon_registrations_lock); 19559 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, 19560 list) { 19561 if (reg->nlportid == notify->portid) { 19562 list_del(®->list); 19563 kfree(reg); 19564 break; 19565 } 19566 } 19567 spin_unlock_bh(&rdev->beacon_registrations_lock); 19568 } 19569 19570 rcu_read_unlock(); 19571 19572 /* 19573 * It is possible that the user space process that is controlling the 19574 * indoor setting disappeared, so notify the regulatory core. 19575 */ 19576 regulatory_netlink_notify(notify->portid); 19577 return NOTIFY_OK; 19578 } 19579 19580 static struct notifier_block nl80211_netlink_notifier = { 19581 .notifier_call = nl80211_netlink_notify, 19582 }; 19583 19584 void cfg80211_ft_event(struct net_device *netdev, 19585 struct cfg80211_ft_event_params *ft_event) 19586 { 19587 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 19588 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19589 struct sk_buff *msg; 19590 void *hdr; 19591 19592 trace_cfg80211_ft_event(wiphy, netdev, ft_event); 19593 19594 if (!ft_event->target_ap) 19595 return; 19596 19597 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, 19598 GFP_KERNEL); 19599 if (!msg) 19600 return; 19601 19602 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); 19603 if (!hdr) 19604 goto out; 19605 19606 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19607 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19608 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) 19609 goto out; 19610 19611 if (ft_event->ies && 19612 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) 19613 goto out; 19614 if (ft_event->ric_ies && 19615 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, 19616 ft_event->ric_ies)) 19617 goto out; 19618 19619 genlmsg_end(msg, hdr); 19620 19621 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19622 NL80211_MCGRP_MLME, GFP_KERNEL); 19623 return; 19624 out: 19625 nlmsg_free(msg); 19626 } 19627 EXPORT_SYMBOL(cfg80211_ft_event); 19628 19629 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) 19630 { 19631 struct cfg80211_registered_device *rdev; 19632 struct sk_buff *msg; 19633 void *hdr; 19634 u32 nlportid; 19635 19636 rdev = wiphy_to_rdev(wdev->wiphy); 19637 if (!rdev->crit_proto_nlportid) 19638 return; 19639 19640 nlportid = rdev->crit_proto_nlportid; 19641 rdev->crit_proto_nlportid = 0; 19642 19643 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19644 if (!msg) 19645 return; 19646 19647 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); 19648 if (!hdr) 19649 goto nla_put_failure; 19650 19651 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19652 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19653 NL80211_ATTR_PAD)) 19654 goto nla_put_failure; 19655 19656 genlmsg_end(msg, hdr); 19657 19658 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 19659 return; 19660 19661 nla_put_failure: 19662 nlmsg_free(msg); 19663 } 19664 EXPORT_SYMBOL(cfg80211_crit_proto_stopped); 19665 19666 void nl80211_send_ap_stopped(struct wireless_dev *wdev) 19667 { 19668 struct wiphy *wiphy = wdev->wiphy; 19669 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19670 struct sk_buff *msg; 19671 void *hdr; 19672 19673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 19674 if (!msg) 19675 return; 19676 19677 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); 19678 if (!hdr) 19679 goto out; 19680 19681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19682 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 19683 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19684 NL80211_ATTR_PAD)) 19685 goto out; 19686 19687 genlmsg_end(msg, hdr); 19688 19689 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 19690 NL80211_MCGRP_MLME, GFP_KERNEL); 19691 return; 19692 out: 19693 nlmsg_free(msg); 19694 } 19695 19696 int cfg80211_external_auth_request(struct net_device *dev, 19697 struct cfg80211_external_auth_params *params, 19698 gfp_t gfp) 19699 { 19700 struct wireless_dev *wdev = dev->ieee80211_ptr; 19701 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19702 struct sk_buff *msg; 19703 void *hdr; 19704 19705 if (!wdev->conn_owner_nlportid) 19706 return -EINVAL; 19707 19708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19709 if (!msg) 19710 return -ENOMEM; 19711 19712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); 19713 if (!hdr) 19714 goto nla_put_failure; 19715 19716 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19717 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19718 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || 19719 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, 19720 params->action) || 19721 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || 19722 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, 19723 params->ssid.ssid)) 19724 goto nla_put_failure; 19725 19726 genlmsg_end(msg, hdr); 19727 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 19728 wdev->conn_owner_nlportid); 19729 return 0; 19730 19731 nla_put_failure: 19732 nlmsg_free(msg); 19733 return -ENOBUFS; 19734 } 19735 EXPORT_SYMBOL(cfg80211_external_auth_request); 19736 19737 void cfg80211_update_owe_info_event(struct net_device *netdev, 19738 struct cfg80211_update_owe_info *owe_info, 19739 gfp_t gfp) 19740 { 19741 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 19742 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19743 struct sk_buff *msg; 19744 void *hdr; 19745 19746 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); 19747 19748 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19749 if (!msg) 19750 return; 19751 19752 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); 19753 if (!hdr) 19754 goto nla_put_failure; 19755 19756 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19757 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19758 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) 19759 goto nla_put_failure; 19760 19761 if (!owe_info->ie_len || 19762 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) 19763 goto nla_put_failure; 19764 19765 genlmsg_end(msg, hdr); 19766 19767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19768 NL80211_MCGRP_MLME, gfp); 19769 return; 19770 19771 nla_put_failure: 19772 genlmsg_cancel(msg, hdr); 19773 nlmsg_free(msg); 19774 } 19775 EXPORT_SYMBOL(cfg80211_update_owe_info_event); 19776 19777 /* initialisation/exit functions */ 19778 19779 int __init nl80211_init(void) 19780 { 19781 int err; 19782 19783 err = genl_register_family(&nl80211_fam); 19784 if (err) 19785 return err; 19786 19787 err = netlink_register_notifier(&nl80211_netlink_notifier); 19788 if (err) 19789 goto err_out; 19790 19791 return 0; 19792 err_out: 19793 genl_unregister_family(&nl80211_fam); 19794 return err; 19795 } 19796 19797 void nl80211_exit(void) 19798 { 19799 netlink_unregister_notifier(&nl80211_netlink_notifier); 19800 genl_unregister_family(&nl80211_fam); 19801 } 19802