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-2020 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 net *netns, struct nlattr **attrs) 68 { 69 struct cfg80211_registered_device *rdev; 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; 74 int wiphy_idx = -1; 75 int ifidx = -1; 76 77 ASSERT_RTNL(); 78 79 if (!have_ifidx && !have_wdev_id) 80 return ERR_PTR(-EINVAL); 81 82 if (have_ifidx) 83 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 84 if (have_wdev_id) { 85 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 86 wiphy_idx = wdev_id >> 32; 87 } 88 89 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 90 struct wireless_dev *wdev; 91 92 if (wiphy_net(&rdev->wiphy) != netns) 93 continue; 94 95 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) 96 continue; 97 98 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 99 if (have_ifidx && wdev->netdev && 100 wdev->netdev->ifindex == ifidx) { 101 result = wdev; 102 break; 103 } 104 if (have_wdev_id && wdev->identifier == (u32)wdev_id) { 105 result = wdev; 106 break; 107 } 108 } 109 110 if (result) 111 break; 112 } 113 114 if (result) 115 return result; 116 return ERR_PTR(-ENODEV); 117 } 118 119 static struct cfg80211_registered_device * 120 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) 121 { 122 struct cfg80211_registered_device *rdev = NULL, *tmp; 123 struct net_device *netdev; 124 125 ASSERT_RTNL(); 126 127 if (!attrs[NL80211_ATTR_WIPHY] && 128 !attrs[NL80211_ATTR_IFINDEX] && 129 !attrs[NL80211_ATTR_WDEV]) 130 return ERR_PTR(-EINVAL); 131 132 if (attrs[NL80211_ATTR_WIPHY]) 133 rdev = cfg80211_rdev_by_wiphy_idx( 134 nla_get_u32(attrs[NL80211_ATTR_WIPHY])); 135 136 if (attrs[NL80211_ATTR_WDEV]) { 137 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 138 struct wireless_dev *wdev; 139 bool found = false; 140 141 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); 142 if (tmp) { 143 /* make sure wdev exists */ 144 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { 145 if (wdev->identifier != (u32)wdev_id) 146 continue; 147 found = true; 148 break; 149 } 150 151 if (!found) 152 tmp = NULL; 153 154 if (rdev && tmp != rdev) 155 return ERR_PTR(-EINVAL); 156 rdev = tmp; 157 } 158 } 159 160 if (attrs[NL80211_ATTR_IFINDEX]) { 161 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 162 163 netdev = __dev_get_by_index(netns, ifindex); 164 if (netdev) { 165 if (netdev->ieee80211_ptr) 166 tmp = wiphy_to_rdev( 167 netdev->ieee80211_ptr->wiphy); 168 else 169 tmp = NULL; 170 171 /* not wireless device -- return error */ 172 if (!tmp) 173 return ERR_PTR(-EINVAL); 174 175 /* mismatch -- return error */ 176 if (rdev && tmp != rdev) 177 return ERR_PTR(-EINVAL); 178 179 rdev = tmp; 180 } 181 } 182 183 if (!rdev) 184 return ERR_PTR(-ENODEV); 185 186 if (netns != wiphy_net(&rdev->wiphy)) 187 return ERR_PTR(-ENODEV); 188 189 return rdev; 190 } 191 192 /* 193 * This function returns a pointer to the driver 194 * that the genl_info item that is passed refers to. 195 * 196 * The result of this can be a PTR_ERR and hence must 197 * be checked with IS_ERR() for errors. 198 */ 199 static struct cfg80211_registered_device * 200 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) 201 { 202 return __cfg80211_rdev_from_attrs(netns, info->attrs); 203 } 204 205 static int validate_beacon_head(const struct nlattr *attr, 206 struct netlink_ext_ack *extack) 207 { 208 const u8 *data = nla_data(attr); 209 unsigned int len = nla_len(attr); 210 const struct element *elem; 211 const struct ieee80211_mgmt *mgmt = (void *)data; 212 unsigned int fixedlen = offsetof(struct ieee80211_mgmt, 213 u.beacon.variable); 214 215 if (len < fixedlen) 216 goto err; 217 218 if (ieee80211_hdrlen(mgmt->frame_control) != 219 offsetof(struct ieee80211_mgmt, u.beacon)) 220 goto err; 221 222 data += fixedlen; 223 len -= fixedlen; 224 225 for_each_element(elem, data, len) { 226 /* nothing */ 227 } 228 229 if (for_each_element_completed(elem, data, len)) 230 return 0; 231 232 err: 233 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); 234 return -EINVAL; 235 } 236 237 static int validate_ie_attr(const struct nlattr *attr, 238 struct netlink_ext_ack *extack) 239 { 240 const u8 *data = nla_data(attr); 241 unsigned int len = nla_len(attr); 242 const struct element *elem; 243 244 for_each_element(elem, data, len) { 245 /* nothing */ 246 } 247 248 if (for_each_element_completed(elem, data, len)) 249 return 0; 250 251 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); 252 return -EINVAL; 253 } 254 255 /* policy for the attributes */ 256 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; 257 258 static const struct nla_policy 259 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { 260 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, 261 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, 262 .len = U8_MAX }, 263 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, 264 .len = U8_MAX }, 265 }; 266 267 static const struct nla_policy 268 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { 269 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, 270 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, 271 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = 272 NLA_POLICY_MAX(NLA_U8, 15), 273 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, 274 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = 275 NLA_POLICY_MAX(NLA_U8, 15), 276 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = 277 NLA_POLICY_MAX(NLA_U8, 31), 278 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, 279 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, 280 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, 281 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, 282 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, 283 }; 284 285 static const struct nla_policy 286 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { 287 [NL80211_PMSR_TYPE_FTM] = 288 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), 289 }; 290 291 static const struct nla_policy 292 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { 293 [NL80211_PMSR_REQ_ATTR_DATA] = 294 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), 295 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, 296 }; 297 298 static const struct nla_policy 299 nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { 300 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, 301 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), 302 [NL80211_PMSR_PEER_ATTR_REQ] = 303 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), 304 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, 305 }; 306 307 static const struct nla_policy 308 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { 309 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, 310 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, 311 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, 312 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, 313 [NL80211_PMSR_ATTR_PEERS] = 314 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), 315 }; 316 317 static const struct nla_policy 318 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { 319 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = 320 NLA_POLICY_RANGE(NLA_U8, 1, 20), 321 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = 322 NLA_POLICY_RANGE(NLA_U8, 1, 20), 323 }; 324 325 static const struct nla_policy 326 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { 327 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), 328 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, 329 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, 330 }; 331 332 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { 333 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, 334 .len = NL80211_MAX_SUPP_RATES }, 335 [NL80211_TXRATE_HT] = { .type = NLA_BINARY, 336 .len = NL80211_MAX_SUPP_HT_RATES }, 337 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), 338 [NL80211_TXRATE_GI] = { .type = NLA_U8 }, 339 }; 340 341 static const struct nla_policy 342 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { 343 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, 344 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, 345 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, 346 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), 347 [NL80211_TID_CONFIG_ATTR_NOACK] = 348 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 349 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 350 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 351 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = 352 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 353 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = 354 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 355 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = 356 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 357 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = 358 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), 359 [NL80211_TID_CONFIG_ATTR_TX_RATE] = 360 NLA_POLICY_NESTED(nl80211_txattr_policy), 361 }; 362 363 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { 364 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, 365 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 366 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 367 .len = 20-1 }, 368 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, 369 370 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, 371 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, 372 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, 373 NL80211_EDMG_CHANNELS_MIN, 374 NL80211_EDMG_CHANNELS_MAX), 375 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, 376 NL80211_EDMG_BW_CONFIG_MIN, 377 NL80211_EDMG_BW_CONFIG_MAX), 378 379 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, 380 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, 381 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 382 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, 383 384 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 385 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 386 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, 387 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, 388 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, 389 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, 390 391 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), 392 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 393 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, 394 395 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 396 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 397 398 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, 399 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, 400 .len = WLAN_MAX_KEY_LEN }, 401 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), 402 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, 403 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, 404 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 405 [NL80211_ATTR_KEY_TYPE] = 406 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), 407 408 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 409 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 410 [NL80211_ATTR_BEACON_HEAD] = 411 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, 412 IEEE80211_MAX_DATA_LEN), 413 [NL80211_ATTR_BEACON_TAIL] = 414 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 415 IEEE80211_MAX_DATA_LEN), 416 [NL80211_ATTR_STA_AID] = 417 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 418 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, 419 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, 420 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, 421 .len = NL80211_MAX_SUPP_RATES }, 422 [NL80211_ATTR_STA_PLINK_ACTION] = 423 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), 424 [NL80211_ATTR_STA_TX_POWER_SETTING] = 425 NLA_POLICY_RANGE(NLA_U8, 426 NL80211_TX_POWER_AUTOMATIC, 427 NL80211_TX_POWER_FIXED), 428 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, 429 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 430 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 431 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 432 .len = IEEE80211_MAX_MESH_ID_LEN }, 433 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, 434 435 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, 436 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, 437 438 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 439 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 440 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 441 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 442 .len = NL80211_MAX_SUPP_RATES }, 443 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, 444 445 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, 446 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, 447 448 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), 449 450 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, 451 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, 452 validate_ie_attr, 453 IEEE80211_MAX_DATA_LEN), 454 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, 455 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, 456 457 [NL80211_ATTR_SSID] = { .type = NLA_BINARY, 458 .len = IEEE80211_MAX_SSID_LEN }, 459 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, 460 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, 461 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, 462 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, 463 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, 464 NL80211_MFP_NO, 465 NL80211_MFP_OPTIONAL), 466 [NL80211_ATTR_STA_FLAGS2] = { 467 .len = sizeof(struct nl80211_sta_flag_update), 468 }, 469 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 470 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, 471 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, 472 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, 473 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, 474 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, 475 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 476 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 477 [NL80211_ATTR_PID] = { .type = NLA_U32 }, 478 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, 479 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), 480 [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, 481 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, 482 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, 483 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, 484 .len = IEEE80211_MAX_DATA_LEN }, 485 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, 486 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, 487 NL80211_PS_DISABLED, 488 NL80211_PS_ENABLED), 489 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, 490 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, 491 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, 492 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, 493 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, 494 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, 495 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, 496 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, 497 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, 498 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, 499 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 500 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, 501 [NL80211_ATTR_STA_PLINK_STATE] = 502 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), 503 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, 504 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, 505 [NL80211_ATTR_MESH_PEER_AID] = 506 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 507 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, 508 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, 509 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, 510 [NL80211_ATTR_HIDDEN_SSID] = 511 NLA_POLICY_RANGE(NLA_U32, 512 NL80211_HIDDEN_SSID_NOT_IN_USE, 513 NL80211_HIDDEN_SSID_ZERO_CONTENTS), 514 [NL80211_ATTR_IE_PROBE_RESP] = 515 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 516 IEEE80211_MAX_DATA_LEN), 517 [NL80211_ATTR_IE_ASSOC_RESP] = 518 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 519 IEEE80211_MAX_DATA_LEN), 520 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, 521 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, 522 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, 523 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, 524 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, 525 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, 526 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, 527 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, 528 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, 529 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, 530 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, 531 .len = IEEE80211_MAX_DATA_LEN }, 532 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, 533 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, 534 [NL80211_ATTR_HT_CAPABILITY_MASK] = { 535 .len = NL80211_HT_CAPABILITY_LEN 536 }, 537 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, 538 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, 539 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, 540 [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, 541 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, 542 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, 543 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), 544 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, 545 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), 546 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), 547 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = 548 NLA_POLICY_RANGE(NLA_U32, 549 NL80211_MESH_POWER_UNKNOWN + 1, 550 NL80211_MESH_POWER_MAX), 551 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, 552 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, 553 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, 554 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, 555 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, 556 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, 557 [NL80211_ATTR_VHT_CAPABILITY_MASK] = { 558 .len = NL80211_VHT_CAPABILITY_LEN, 559 }, 560 [NL80211_ATTR_MDID] = { .type = NLA_U16 }, 561 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, 562 .len = IEEE80211_MAX_DATA_LEN }, 563 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, 564 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = { .type = NLA_U16 }, 565 [NL80211_ATTR_PEER_AID] = 566 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 567 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, 568 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, 569 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, 570 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, 571 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, 572 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, 573 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, 574 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, 575 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, 576 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, 577 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, 578 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, 579 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, 580 .len = IEEE80211_QOS_MAP_LEN_MAX }, 581 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 582 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, 583 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, 584 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, 585 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, 586 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, 587 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), 588 [NL80211_ATTR_USER_PRIO] = 589 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), 590 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, 591 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, 592 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, 593 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 594 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, 595 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, 596 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, 597 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, 598 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, 599 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, 600 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = 601 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), 602 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { 603 .len = VHT_MUMIMO_GROUPS_DATA_LEN 604 }, 605 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 606 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), 607 [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, 608 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, 609 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, 610 .len = FILS_MAX_KEK_LEN }, 611 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), 612 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, 613 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 614 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, 615 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { 616 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 617 }, 618 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, 619 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, 620 .len = FILS_ERP_MAX_USERNAME_LEN }, 621 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, 622 .len = FILS_ERP_MAX_REALM_LEN }, 623 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, 624 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, 625 .len = FILS_ERP_MAX_RRK_LEN }, 626 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), 627 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, 628 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, 629 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, 630 631 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, 632 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, 633 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, 634 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, 635 .len = NL80211_HE_MAX_CAPABILITY_LEN }, 636 637 [NL80211_ATTR_FTM_RESPONDER] = 638 NLA_POLICY_NESTED(nl80211_ftm_responder_policy), 639 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), 640 [NL80211_ATTR_PEER_MEASUREMENTS] = 641 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), 642 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), 643 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, 644 .len = SAE_PASSWORD_MAX_LEN }, 645 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, 646 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), 647 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), 648 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), 649 [NL80211_ATTR_TID_CONFIG] = 650 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), 651 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, 652 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), 653 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), 654 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, 655 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 656 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, 657 [NL80211_ATTR_HE_6GHZ_CAPABILITY] = { 658 .type = NLA_EXACT_LEN, 659 .len = sizeof(struct ieee80211_he_6ghz_capa), 660 }, 661 }; 662 663 /* policy for the key attributes */ 664 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { 665 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 666 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 667 [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, 668 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 669 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, 670 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 671 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), 672 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 673 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), 674 }; 675 676 /* policy for the key default flags */ 677 static const struct nla_policy 678 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { 679 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, 680 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, 681 }; 682 683 #ifdef CONFIG_PM 684 /* policy for WoWLAN attributes */ 685 static const struct nla_policy 686 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { 687 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, 688 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, 689 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, 690 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, 691 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, 692 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, 693 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, 694 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, 695 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, 696 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, 697 }; 698 699 static const struct nla_policy 700 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { 701 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, 702 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, 703 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 704 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, 705 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, 706 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, 707 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { 708 .len = sizeof(struct nl80211_wowlan_tcp_data_seq) 709 }, 710 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { 711 .len = sizeof(struct nl80211_wowlan_tcp_data_token) 712 }, 713 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, 714 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, 715 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 }, 716 }; 717 #endif /* CONFIG_PM */ 718 719 /* policy for coalesce rule attributes */ 720 static const struct nla_policy 721 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { 722 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, 723 [NL80211_ATTR_COALESCE_RULE_CONDITION] = 724 NLA_POLICY_RANGE(NLA_U32, 725 NL80211_COALESCE_CONDITION_MATCH, 726 NL80211_COALESCE_CONDITION_NO_MATCH), 727 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, 728 }; 729 730 /* policy for GTK rekey offload attributes */ 731 static const struct nla_policy 732 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { 733 [NL80211_REKEY_DATA_KEK] = { 734 .type = NLA_BINARY, 735 .len = NL80211_KEK_EXT_LEN 736 }, 737 [NL80211_REKEY_DATA_KCK] = { 738 .type = NLA_BINARY, 739 .len = NL80211_KCK_EXT_LEN 740 }, 741 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN_WARN(NL80211_REPLAY_CTR_LEN), 742 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, 743 }; 744 745 static const struct nla_policy 746 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { 747 [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, 748 [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, 749 [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, 750 [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, 751 }; 752 753 static const struct nla_policy 754 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { 755 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, 756 .len = IEEE80211_MAX_SSID_LEN }, 757 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 758 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, 759 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = 760 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), 761 }; 762 763 static const struct nla_policy 764 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { 765 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, 766 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, 767 }; 768 769 static const struct nla_policy 770 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { 771 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, 772 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, 773 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { 774 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 775 }, 776 }; 777 778 /* policy for NAN function attributes */ 779 static const struct nla_policy 780 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { 781 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, 782 [NL80211_NAN_FUNC_SERVICE_ID] = { 783 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, 784 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, 785 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, 786 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, 787 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, 788 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, 789 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 790 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, 791 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, 792 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, 793 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, 794 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, 795 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, 796 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, 797 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, 798 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, 799 }; 800 801 /* policy for Service Response Filter attributes */ 802 static const struct nla_policy 803 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { 804 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, 805 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, 806 .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, 807 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, 808 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, 809 }; 810 811 /* policy for packet pattern attributes */ 812 static const struct nla_policy 813 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { 814 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, 815 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, 816 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, 817 }; 818 819 int nl80211_prepare_wdev_dump(struct netlink_callback *cb, 820 struct cfg80211_registered_device **rdev, 821 struct wireless_dev **wdev) 822 { 823 int err; 824 825 if (!cb->args[0]) { 826 struct nlattr **attrbuf; 827 828 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 829 GFP_KERNEL); 830 if (!attrbuf) 831 return -ENOMEM; 832 833 err = nlmsg_parse_deprecated(cb->nlh, 834 GENL_HDRLEN + nl80211_fam.hdrsize, 835 attrbuf, nl80211_fam.maxattr, 836 nl80211_policy, NULL); 837 if (err) { 838 kfree(attrbuf); 839 return err; 840 } 841 842 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk), 843 attrbuf); 844 kfree(attrbuf); 845 if (IS_ERR(*wdev)) 846 return PTR_ERR(*wdev); 847 *rdev = wiphy_to_rdev((*wdev)->wiphy); 848 /* 0 is the first index - add 1 to parse only once */ 849 cb->args[0] = (*rdev)->wiphy_idx + 1; 850 cb->args[1] = (*wdev)->identifier; 851 } else { 852 /* subtract the 1 again here */ 853 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 854 struct wireless_dev *tmp; 855 856 if (!wiphy) 857 return -ENODEV; 858 *rdev = wiphy_to_rdev(wiphy); 859 *wdev = NULL; 860 861 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { 862 if (tmp->identifier == cb->args[1]) { 863 *wdev = tmp; 864 break; 865 } 866 } 867 868 if (!*wdev) 869 return -ENODEV; 870 } 871 872 return 0; 873 } 874 875 /* message building helper */ 876 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, 877 int flags, u8 cmd) 878 { 879 /* since there is no private header just add the generic one */ 880 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); 881 } 882 883 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, 884 const struct ieee80211_reg_rule *rule) 885 { 886 int j; 887 struct nlattr *nl_wmm_rules = 888 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); 889 890 if (!nl_wmm_rules) 891 goto nla_put_failure; 892 893 for (j = 0; j < IEEE80211_NUM_ACS; j++) { 894 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); 895 896 if (!nl_wmm_rule) 897 goto nla_put_failure; 898 899 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, 900 rule->wmm_rule.client[j].cw_min) || 901 nla_put_u16(msg, NL80211_WMMR_CW_MAX, 902 rule->wmm_rule.client[j].cw_max) || 903 nla_put_u8(msg, NL80211_WMMR_AIFSN, 904 rule->wmm_rule.client[j].aifsn) || 905 nla_put_u16(msg, NL80211_WMMR_TXOP, 906 rule->wmm_rule.client[j].cot)) 907 goto nla_put_failure; 908 909 nla_nest_end(msg, nl_wmm_rule); 910 } 911 nla_nest_end(msg, nl_wmm_rules); 912 913 return 0; 914 915 nla_put_failure: 916 return -ENOBUFS; 917 } 918 919 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, 920 struct ieee80211_channel *chan, 921 bool large) 922 { 923 /* Some channels must be completely excluded from the 924 * list to protect old user-space tools from breaking 925 */ 926 if (!large && chan->flags & 927 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) 928 return 0; 929 930 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, 931 chan->center_freq)) 932 goto nla_put_failure; 933 934 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) 935 goto nla_put_failure; 936 937 if ((chan->flags & IEEE80211_CHAN_DISABLED) && 938 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) 939 goto nla_put_failure; 940 if (chan->flags & IEEE80211_CHAN_NO_IR) { 941 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) 942 goto nla_put_failure; 943 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) 944 goto nla_put_failure; 945 } 946 if (chan->flags & IEEE80211_CHAN_RADAR) { 947 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) 948 goto nla_put_failure; 949 if (large) { 950 u32 time; 951 952 time = elapsed_jiffies_msecs(chan->dfs_state_entered); 953 954 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, 955 chan->dfs_state)) 956 goto nla_put_failure; 957 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, 958 time)) 959 goto nla_put_failure; 960 if (nla_put_u32(msg, 961 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, 962 chan->dfs_cac_ms)) 963 goto nla_put_failure; 964 } 965 } 966 967 if (large) { 968 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && 969 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) 970 goto nla_put_failure; 971 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && 972 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) 973 goto nla_put_failure; 974 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && 975 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) 976 goto nla_put_failure; 977 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && 978 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) 979 goto nla_put_failure; 980 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && 981 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) 982 goto nla_put_failure; 983 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && 984 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) 985 goto nla_put_failure; 986 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && 987 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) 988 goto nla_put_failure; 989 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && 990 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) 991 goto nla_put_failure; 992 if ((chan->flags & IEEE80211_CHAN_NO_HE) && 993 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) 994 goto nla_put_failure; 995 } 996 997 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 998 DBM_TO_MBM(chan->max_power))) 999 goto nla_put_failure; 1000 1001 if (large) { 1002 const struct ieee80211_reg_rule *rule = 1003 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); 1004 1005 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { 1006 if (nl80211_msg_put_wmm_rules(msg, rule)) 1007 goto nla_put_failure; 1008 } 1009 } 1010 1011 return 0; 1012 1013 nla_put_failure: 1014 return -ENOBUFS; 1015 } 1016 1017 static bool nl80211_put_txq_stats(struct sk_buff *msg, 1018 struct cfg80211_txq_stats *txqstats, 1019 int attrtype) 1020 { 1021 struct nlattr *txqattr; 1022 1023 #define PUT_TXQVAL_U32(attr, memb) do { \ 1024 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ 1025 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ 1026 return false; \ 1027 } while (0) 1028 1029 txqattr = nla_nest_start_noflag(msg, attrtype); 1030 if (!txqattr) 1031 return false; 1032 1033 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); 1034 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); 1035 PUT_TXQVAL_U32(FLOWS, flows); 1036 PUT_TXQVAL_U32(DROPS, drops); 1037 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); 1038 PUT_TXQVAL_U32(OVERLIMIT, overlimit); 1039 PUT_TXQVAL_U32(OVERMEMORY, overmemory); 1040 PUT_TXQVAL_U32(COLLISIONS, collisions); 1041 PUT_TXQVAL_U32(TX_BYTES, tx_bytes); 1042 PUT_TXQVAL_U32(TX_PACKETS, tx_packets); 1043 PUT_TXQVAL_U32(MAX_FLOWS, max_flows); 1044 nla_nest_end(msg, txqattr); 1045 1046 #undef PUT_TXQVAL_U32 1047 return true; 1048 } 1049 1050 /* netlink command implementations */ 1051 1052 struct key_parse { 1053 struct key_params p; 1054 int idx; 1055 int type; 1056 bool def, defmgmt, defbeacon; 1057 bool def_uni, def_multi; 1058 }; 1059 1060 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, 1061 struct key_parse *k) 1062 { 1063 struct nlattr *tb[NL80211_KEY_MAX + 1]; 1064 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, 1065 nl80211_key_policy, 1066 info->extack); 1067 if (err) 1068 return err; 1069 1070 k->def = !!tb[NL80211_KEY_DEFAULT]; 1071 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 1072 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; 1073 1074 if (k->def) { 1075 k->def_uni = true; 1076 k->def_multi = true; 1077 } 1078 if (k->defmgmt || k->defbeacon) 1079 k->def_multi = true; 1080 1081 if (tb[NL80211_KEY_IDX]) 1082 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 1083 1084 if (tb[NL80211_KEY_DATA]) { 1085 k->p.key = nla_data(tb[NL80211_KEY_DATA]); 1086 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); 1087 } 1088 1089 if (tb[NL80211_KEY_SEQ]) { 1090 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); 1091 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); 1092 } 1093 1094 if (tb[NL80211_KEY_CIPHER]) 1095 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 1096 1097 if (tb[NL80211_KEY_TYPE]) 1098 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); 1099 1100 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 1101 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1102 1103 err = nla_parse_nested_deprecated(kdt, 1104 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1105 tb[NL80211_KEY_DEFAULT_TYPES], 1106 nl80211_key_default_policy, 1107 info->extack); 1108 if (err) 1109 return err; 1110 1111 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1112 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1113 } 1114 1115 if (tb[NL80211_KEY_MODE]) 1116 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); 1117 1118 return 0; 1119 } 1120 1121 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) 1122 { 1123 if (info->attrs[NL80211_ATTR_KEY_DATA]) { 1124 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); 1125 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); 1126 } 1127 1128 if (info->attrs[NL80211_ATTR_KEY_SEQ]) { 1129 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); 1130 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); 1131 } 1132 1133 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1134 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1135 1136 if (info->attrs[NL80211_ATTR_KEY_CIPHER]) 1137 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); 1138 1139 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 1140 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 1141 1142 if (k->def) { 1143 k->def_uni = true; 1144 k->def_multi = true; 1145 } 1146 if (k->defmgmt) 1147 k->def_multi = true; 1148 1149 if (info->attrs[NL80211_ATTR_KEY_TYPE]) 1150 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 1151 1152 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1153 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1154 int err = nla_parse_nested_deprecated(kdt, 1155 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1156 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1157 nl80211_key_default_policy, 1158 info->extack); 1159 if (err) 1160 return err; 1161 1162 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1163 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1164 } 1165 1166 return 0; 1167 } 1168 1169 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) 1170 { 1171 int err; 1172 1173 memset(k, 0, sizeof(*k)); 1174 k->idx = -1; 1175 k->type = -1; 1176 1177 if (info->attrs[NL80211_ATTR_KEY]) 1178 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); 1179 else 1180 err = nl80211_parse_key_old(info, k); 1181 1182 if (err) 1183 return err; 1184 1185 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + 1186 (k->defbeacon ? 1 : 0) > 1) { 1187 GENL_SET_ERR_MSG(info, 1188 "key with multiple default flags is invalid"); 1189 return -EINVAL; 1190 } 1191 1192 if (k->defmgmt || k->defbeacon) { 1193 if (k->def_uni || !k->def_multi) { 1194 GENL_SET_ERR_MSG(info, 1195 "defmgmt/defbeacon key must be mcast"); 1196 return -EINVAL; 1197 } 1198 } 1199 1200 if (k->idx != -1) { 1201 if (k->defmgmt) { 1202 if (k->idx < 4 || k->idx > 5) { 1203 GENL_SET_ERR_MSG(info, 1204 "defmgmt key idx not 4 or 5"); 1205 return -EINVAL; 1206 } 1207 } else if (k->defbeacon) { 1208 if (k->idx < 6 || k->idx > 7) { 1209 GENL_SET_ERR_MSG(info, 1210 "defbeacon key idx not 6 or 7"); 1211 return -EINVAL; 1212 } 1213 } else if (k->def) { 1214 if (k->idx < 0 || k->idx > 3) { 1215 GENL_SET_ERR_MSG(info, "def key idx not 0-3"); 1216 return -EINVAL; 1217 } 1218 } else { 1219 if (k->idx < 0 || k->idx > 7) { 1220 GENL_SET_ERR_MSG(info, "key idx not 0-7"); 1221 return -EINVAL; 1222 } 1223 } 1224 } 1225 1226 return 0; 1227 } 1228 1229 static struct cfg80211_cached_keys * 1230 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, 1231 struct genl_info *info, bool *no_ht) 1232 { 1233 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; 1234 struct key_parse parse; 1235 struct nlattr *key; 1236 struct cfg80211_cached_keys *result; 1237 int rem, err, def = 0; 1238 bool have_key = false; 1239 1240 nla_for_each_nested(key, keys, rem) { 1241 have_key = true; 1242 break; 1243 } 1244 1245 if (!have_key) 1246 return NULL; 1247 1248 result = kzalloc(sizeof(*result), GFP_KERNEL); 1249 if (!result) 1250 return ERR_PTR(-ENOMEM); 1251 1252 result->def = -1; 1253 1254 nla_for_each_nested(key, keys, rem) { 1255 memset(&parse, 0, sizeof(parse)); 1256 parse.idx = -1; 1257 1258 err = nl80211_parse_key_new(info, key, &parse); 1259 if (err) 1260 goto error; 1261 err = -EINVAL; 1262 if (!parse.p.key) 1263 goto error; 1264 if (parse.idx < 0 || parse.idx > 3) { 1265 GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); 1266 goto error; 1267 } 1268 if (parse.def) { 1269 if (def) { 1270 GENL_SET_ERR_MSG(info, 1271 "only one key can be default"); 1272 goto error; 1273 } 1274 def = 1; 1275 result->def = parse.idx; 1276 if (!parse.def_uni || !parse.def_multi) 1277 goto error; 1278 } else if (parse.defmgmt) 1279 goto error; 1280 err = cfg80211_validate_key_settings(rdev, &parse.p, 1281 parse.idx, false, NULL); 1282 if (err) 1283 goto error; 1284 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && 1285 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { 1286 GENL_SET_ERR_MSG(info, "connect key must be WEP"); 1287 err = -EINVAL; 1288 goto error; 1289 } 1290 result->params[parse.idx].cipher = parse.p.cipher; 1291 result->params[parse.idx].key_len = parse.p.key_len; 1292 result->params[parse.idx].key = result->data[parse.idx]; 1293 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); 1294 1295 /* must be WEP key if we got here */ 1296 if (no_ht) 1297 *no_ht = true; 1298 } 1299 1300 if (result->def < 0) { 1301 err = -EINVAL; 1302 GENL_SET_ERR_MSG(info, "need a default/TX key"); 1303 goto error; 1304 } 1305 1306 return result; 1307 error: 1308 kfree(result); 1309 return ERR_PTR(err); 1310 } 1311 1312 static int nl80211_key_allowed(struct wireless_dev *wdev) 1313 { 1314 ASSERT_WDEV_LOCK(wdev); 1315 1316 switch (wdev->iftype) { 1317 case NL80211_IFTYPE_AP: 1318 case NL80211_IFTYPE_AP_VLAN: 1319 case NL80211_IFTYPE_P2P_GO: 1320 case NL80211_IFTYPE_MESH_POINT: 1321 break; 1322 case NL80211_IFTYPE_ADHOC: 1323 case NL80211_IFTYPE_STATION: 1324 case NL80211_IFTYPE_P2P_CLIENT: 1325 if (!wdev->current_bss) 1326 return -ENOLINK; 1327 break; 1328 case NL80211_IFTYPE_UNSPECIFIED: 1329 case NL80211_IFTYPE_OCB: 1330 case NL80211_IFTYPE_MONITOR: 1331 case NL80211_IFTYPE_NAN: 1332 case NL80211_IFTYPE_P2P_DEVICE: 1333 case NL80211_IFTYPE_WDS: 1334 case NUM_NL80211_IFTYPES: 1335 return -EINVAL; 1336 } 1337 1338 return 0; 1339 } 1340 1341 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, 1342 u32 freq) 1343 { 1344 struct ieee80211_channel *chan; 1345 1346 chan = ieee80211_get_channel_khz(wiphy, freq); 1347 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 1348 return NULL; 1349 return chan; 1350 } 1351 1352 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1353 { 1354 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); 1355 int i; 1356 1357 if (!nl_modes) 1358 goto nla_put_failure; 1359 1360 i = 0; 1361 while (ifmodes) { 1362 if ((ifmodes & 1) && nla_put_flag(msg, i)) 1363 goto nla_put_failure; 1364 ifmodes >>= 1; 1365 i++; 1366 } 1367 1368 nla_nest_end(msg, nl_modes); 1369 return 0; 1370 1371 nla_put_failure: 1372 return -ENOBUFS; 1373 } 1374 1375 static int nl80211_put_iface_combinations(struct wiphy *wiphy, 1376 struct sk_buff *msg, 1377 bool large) 1378 { 1379 struct nlattr *nl_combis; 1380 int i, j; 1381 1382 nl_combis = nla_nest_start_noflag(msg, 1383 NL80211_ATTR_INTERFACE_COMBINATIONS); 1384 if (!nl_combis) 1385 goto nla_put_failure; 1386 1387 for (i = 0; i < wiphy->n_iface_combinations; i++) { 1388 const struct ieee80211_iface_combination *c; 1389 struct nlattr *nl_combi, *nl_limits; 1390 1391 c = &wiphy->iface_combinations[i]; 1392 1393 nl_combi = nla_nest_start_noflag(msg, i + 1); 1394 if (!nl_combi) 1395 goto nla_put_failure; 1396 1397 nl_limits = nla_nest_start_noflag(msg, 1398 NL80211_IFACE_COMB_LIMITS); 1399 if (!nl_limits) 1400 goto nla_put_failure; 1401 1402 for (j = 0; j < c->n_limits; j++) { 1403 struct nlattr *nl_limit; 1404 1405 nl_limit = nla_nest_start_noflag(msg, j + 1); 1406 if (!nl_limit) 1407 goto nla_put_failure; 1408 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1409 c->limits[j].max)) 1410 goto nla_put_failure; 1411 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, 1412 c->limits[j].types)) 1413 goto nla_put_failure; 1414 nla_nest_end(msg, nl_limit); 1415 } 1416 1417 nla_nest_end(msg, nl_limits); 1418 1419 if (c->beacon_int_infra_match && 1420 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) 1421 goto nla_put_failure; 1422 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, 1423 c->num_different_channels) || 1424 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 1425 c->max_interfaces)) 1426 goto nla_put_failure; 1427 if (large && 1428 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, 1429 c->radar_detect_widths) || 1430 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, 1431 c->radar_detect_regions))) 1432 goto nla_put_failure; 1433 if (c->beacon_int_min_gcd && 1434 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, 1435 c->beacon_int_min_gcd)) 1436 goto nla_put_failure; 1437 1438 nla_nest_end(msg, nl_combi); 1439 } 1440 1441 nla_nest_end(msg, nl_combis); 1442 1443 return 0; 1444 nla_put_failure: 1445 return -ENOBUFS; 1446 } 1447 1448 #ifdef CONFIG_PM 1449 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, 1450 struct sk_buff *msg) 1451 { 1452 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; 1453 struct nlattr *nl_tcp; 1454 1455 if (!tcp) 1456 return 0; 1457 1458 nl_tcp = nla_nest_start_noflag(msg, 1459 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1460 if (!nl_tcp) 1461 return -ENOBUFS; 1462 1463 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1464 tcp->data_payload_max)) 1465 return -ENOBUFS; 1466 1467 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1468 tcp->data_payload_max)) 1469 return -ENOBUFS; 1470 1471 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) 1472 return -ENOBUFS; 1473 1474 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 1475 sizeof(*tcp->tok), tcp->tok)) 1476 return -ENOBUFS; 1477 1478 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 1479 tcp->data_interval_max)) 1480 return -ENOBUFS; 1481 1482 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 1483 tcp->wake_payload_max)) 1484 return -ENOBUFS; 1485 1486 nla_nest_end(msg, nl_tcp); 1487 return 0; 1488 } 1489 1490 static int nl80211_send_wowlan(struct sk_buff *msg, 1491 struct cfg80211_registered_device *rdev, 1492 bool large) 1493 { 1494 struct nlattr *nl_wowlan; 1495 1496 if (!rdev->wiphy.wowlan) 1497 return 0; 1498 1499 nl_wowlan = nla_nest_start_noflag(msg, 1500 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1501 if (!nl_wowlan) 1502 return -ENOBUFS; 1503 1504 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && 1505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 1506 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && 1507 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 1508 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && 1509 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 1510 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && 1511 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || 1512 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 1513 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 1514 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && 1515 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 1516 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && 1517 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 1518 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && 1519 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 1520 return -ENOBUFS; 1521 1522 if (rdev->wiphy.wowlan->n_patterns) { 1523 struct nl80211_pattern_support pat = { 1524 .max_patterns = rdev->wiphy.wowlan->n_patterns, 1525 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, 1526 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, 1527 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, 1528 }; 1529 1530 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 1531 sizeof(pat), &pat)) 1532 return -ENOBUFS; 1533 } 1534 1535 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && 1536 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, 1537 rdev->wiphy.wowlan->max_nd_match_sets)) 1538 return -ENOBUFS; 1539 1540 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) 1541 return -ENOBUFS; 1542 1543 nla_nest_end(msg, nl_wowlan); 1544 1545 return 0; 1546 } 1547 #endif 1548 1549 static int nl80211_send_coalesce(struct sk_buff *msg, 1550 struct cfg80211_registered_device *rdev) 1551 { 1552 struct nl80211_coalesce_rule_support rule; 1553 1554 if (!rdev->wiphy.coalesce) 1555 return 0; 1556 1557 rule.max_rules = rdev->wiphy.coalesce->n_rules; 1558 rule.max_delay = rdev->wiphy.coalesce->max_delay; 1559 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; 1560 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; 1561 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; 1562 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; 1563 1564 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) 1565 return -ENOBUFS; 1566 1567 return 0; 1568 } 1569 1570 static int 1571 nl80211_send_iftype_data(struct sk_buff *msg, 1572 const struct ieee80211_supported_band *sband, 1573 const struct ieee80211_sband_iftype_data *iftdata) 1574 { 1575 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; 1576 1577 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, 1578 iftdata->types_mask)) 1579 return -ENOBUFS; 1580 1581 if (he_cap->has_he) { 1582 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, 1583 sizeof(he_cap->he_cap_elem.mac_cap_info), 1584 he_cap->he_cap_elem.mac_cap_info) || 1585 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, 1586 sizeof(he_cap->he_cap_elem.phy_cap_info), 1587 he_cap->he_cap_elem.phy_cap_info) || 1588 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, 1589 sizeof(he_cap->he_mcs_nss_supp), 1590 &he_cap->he_mcs_nss_supp) || 1591 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, 1592 sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) 1593 return -ENOBUFS; 1594 } 1595 1596 if (sband->band == NL80211_BAND_6GHZ && 1597 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, 1598 sizeof(iftdata->he_6ghz_capa), 1599 &iftdata->he_6ghz_capa)) 1600 return -ENOBUFS; 1601 1602 return 0; 1603 } 1604 1605 static int nl80211_send_band_rateinfo(struct sk_buff *msg, 1606 struct ieee80211_supported_band *sband) 1607 { 1608 struct nlattr *nl_rates, *nl_rate; 1609 struct ieee80211_rate *rate; 1610 int i; 1611 1612 /* add HT info */ 1613 if (sband->ht_cap.ht_supported && 1614 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, 1615 sizeof(sband->ht_cap.mcs), 1616 &sband->ht_cap.mcs) || 1617 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, 1618 sband->ht_cap.cap) || 1619 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, 1620 sband->ht_cap.ampdu_factor) || 1621 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, 1622 sband->ht_cap.ampdu_density))) 1623 return -ENOBUFS; 1624 1625 /* add VHT info */ 1626 if (sband->vht_cap.vht_supported && 1627 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, 1628 sizeof(sband->vht_cap.vht_mcs), 1629 &sband->vht_cap.vht_mcs) || 1630 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, 1631 sband->vht_cap.cap))) 1632 return -ENOBUFS; 1633 1634 if (sband->n_iftype_data) { 1635 struct nlattr *nl_iftype_data = 1636 nla_nest_start_noflag(msg, 1637 NL80211_BAND_ATTR_IFTYPE_DATA); 1638 int err; 1639 1640 if (!nl_iftype_data) 1641 return -ENOBUFS; 1642 1643 for (i = 0; i < sband->n_iftype_data; i++) { 1644 struct nlattr *iftdata; 1645 1646 iftdata = nla_nest_start_noflag(msg, i + 1); 1647 if (!iftdata) 1648 return -ENOBUFS; 1649 1650 err = nl80211_send_iftype_data(msg, sband, 1651 &sband->iftype_data[i]); 1652 if (err) 1653 return err; 1654 1655 nla_nest_end(msg, iftdata); 1656 } 1657 1658 nla_nest_end(msg, nl_iftype_data); 1659 } 1660 1661 /* add EDMG info */ 1662 if (sband->edmg_cap.channels && 1663 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, 1664 sband->edmg_cap.channels) || 1665 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, 1666 sband->edmg_cap.bw_config))) 1667 1668 return -ENOBUFS; 1669 1670 /* add bitrates */ 1671 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); 1672 if (!nl_rates) 1673 return -ENOBUFS; 1674 1675 for (i = 0; i < sband->n_bitrates; i++) { 1676 nl_rate = nla_nest_start_noflag(msg, i); 1677 if (!nl_rate) 1678 return -ENOBUFS; 1679 1680 rate = &sband->bitrates[i]; 1681 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, 1682 rate->bitrate)) 1683 return -ENOBUFS; 1684 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && 1685 nla_put_flag(msg, 1686 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) 1687 return -ENOBUFS; 1688 1689 nla_nest_end(msg, nl_rate); 1690 } 1691 1692 nla_nest_end(msg, nl_rates); 1693 1694 return 0; 1695 } 1696 1697 static int 1698 nl80211_send_mgmt_stypes(struct sk_buff *msg, 1699 const struct ieee80211_txrx_stypes *mgmt_stypes) 1700 { 1701 u16 stypes; 1702 struct nlattr *nl_ftypes, *nl_ifs; 1703 enum nl80211_iftype ift; 1704 int i; 1705 1706 if (!mgmt_stypes) 1707 return 0; 1708 1709 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); 1710 if (!nl_ifs) 1711 return -ENOBUFS; 1712 1713 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1714 nl_ftypes = nla_nest_start_noflag(msg, ift); 1715 if (!nl_ftypes) 1716 return -ENOBUFS; 1717 i = 0; 1718 stypes = mgmt_stypes[ift].tx; 1719 while (stypes) { 1720 if ((stypes & 1) && 1721 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1722 (i << 4) | IEEE80211_FTYPE_MGMT)) 1723 return -ENOBUFS; 1724 stypes >>= 1; 1725 i++; 1726 } 1727 nla_nest_end(msg, nl_ftypes); 1728 } 1729 1730 nla_nest_end(msg, nl_ifs); 1731 1732 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); 1733 if (!nl_ifs) 1734 return -ENOBUFS; 1735 1736 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1737 nl_ftypes = nla_nest_start_noflag(msg, ift); 1738 if (!nl_ftypes) 1739 return -ENOBUFS; 1740 i = 0; 1741 stypes = mgmt_stypes[ift].rx; 1742 while (stypes) { 1743 if ((stypes & 1) && 1744 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1745 (i << 4) | IEEE80211_FTYPE_MGMT)) 1746 return -ENOBUFS; 1747 stypes >>= 1; 1748 i++; 1749 } 1750 nla_nest_end(msg, nl_ftypes); 1751 } 1752 nla_nest_end(msg, nl_ifs); 1753 1754 return 0; 1755 } 1756 1757 #define CMD(op, n) \ 1758 do { \ 1759 if (rdev->ops->op) { \ 1760 i++; \ 1761 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ 1762 goto nla_put_failure; \ 1763 } \ 1764 } while (0) 1765 1766 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, 1767 struct sk_buff *msg) 1768 { 1769 int i = 0; 1770 1771 /* 1772 * do *NOT* add anything into this function, new things need to be 1773 * advertised only to new versions of userspace that can deal with 1774 * the split (and they can't possibly care about new features... 1775 */ 1776 CMD(add_virtual_intf, NEW_INTERFACE); 1777 CMD(change_virtual_intf, SET_INTERFACE); 1778 CMD(add_key, NEW_KEY); 1779 CMD(start_ap, START_AP); 1780 CMD(add_station, NEW_STATION); 1781 CMD(add_mpath, NEW_MPATH); 1782 CMD(update_mesh_config, SET_MESH_CONFIG); 1783 CMD(change_bss, SET_BSS); 1784 CMD(auth, AUTHENTICATE); 1785 CMD(assoc, ASSOCIATE); 1786 CMD(deauth, DEAUTHENTICATE); 1787 CMD(disassoc, DISASSOCIATE); 1788 CMD(join_ibss, JOIN_IBSS); 1789 CMD(join_mesh, JOIN_MESH); 1790 CMD(set_pmksa, SET_PMKSA); 1791 CMD(del_pmksa, DEL_PMKSA); 1792 CMD(flush_pmksa, FLUSH_PMKSA); 1793 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) 1794 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 1795 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 1796 CMD(mgmt_tx, FRAME); 1797 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); 1798 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 1799 i++; 1800 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 1801 goto nla_put_failure; 1802 } 1803 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || 1804 rdev->ops->join_mesh) { 1805 i++; 1806 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) 1807 goto nla_put_failure; 1808 } 1809 CMD(set_wds_peer, SET_WDS_PEER); 1810 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 1811 CMD(tdls_mgmt, TDLS_MGMT); 1812 CMD(tdls_oper, TDLS_OPER); 1813 } 1814 if (rdev->wiphy.max_sched_scan_reqs) 1815 CMD(sched_scan_start, START_SCHED_SCAN); 1816 CMD(probe_client, PROBE_CLIENT); 1817 CMD(set_noack_map, SET_NOACK_MAP); 1818 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { 1819 i++; 1820 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) 1821 goto nla_put_failure; 1822 } 1823 CMD(start_p2p_device, START_P2P_DEVICE); 1824 CMD(set_mcast_rate, SET_MCAST_RATE); 1825 #ifdef CONFIG_NL80211_TESTMODE 1826 CMD(testmode_cmd, TESTMODE); 1827 #endif 1828 1829 if (rdev->ops->connect || rdev->ops->auth) { 1830 i++; 1831 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) 1832 goto nla_put_failure; 1833 } 1834 1835 if (rdev->ops->disconnect || rdev->ops->deauth) { 1836 i++; 1837 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) 1838 goto nla_put_failure; 1839 } 1840 1841 return i; 1842 nla_put_failure: 1843 return -ENOBUFS; 1844 } 1845 1846 static int 1847 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, 1848 struct sk_buff *msg) 1849 { 1850 struct nlattr *ftm; 1851 1852 if (!cap->ftm.supported) 1853 return 0; 1854 1855 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); 1856 if (!ftm) 1857 return -ENOBUFS; 1858 1859 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) 1860 return -ENOBUFS; 1861 if (cap->ftm.non_asap && 1862 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) 1863 return -ENOBUFS; 1864 if (cap->ftm.request_lci && 1865 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) 1866 return -ENOBUFS; 1867 if (cap->ftm.request_civicloc && 1868 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) 1869 return -ENOBUFS; 1870 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, 1871 cap->ftm.preambles)) 1872 return -ENOBUFS; 1873 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, 1874 cap->ftm.bandwidths)) 1875 return -ENOBUFS; 1876 if (cap->ftm.max_bursts_exponent >= 0 && 1877 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, 1878 cap->ftm.max_bursts_exponent)) 1879 return -ENOBUFS; 1880 if (cap->ftm.max_ftms_per_burst && 1881 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, 1882 cap->ftm.max_ftms_per_burst)) 1883 return -ENOBUFS; 1884 if (cap->ftm.trigger_based && 1885 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) 1886 return -ENOBUFS; 1887 if (cap->ftm.non_trigger_based && 1888 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) 1889 return -ENOBUFS; 1890 1891 nla_nest_end(msg, ftm); 1892 return 0; 1893 } 1894 1895 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, 1896 struct sk_buff *msg) 1897 { 1898 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; 1899 struct nlattr *pmsr, *caps; 1900 1901 if (!cap) 1902 return 0; 1903 1904 /* 1905 * we don't need to clean up anything here since the caller 1906 * will genlmsg_cancel() if we fail 1907 */ 1908 1909 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 1910 if (!pmsr) 1911 return -ENOBUFS; 1912 1913 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) 1914 return -ENOBUFS; 1915 1916 if (cap->report_ap_tsf && 1917 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) 1918 return -ENOBUFS; 1919 1920 if (cap->randomize_mac_addr && 1921 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 1922 return -ENOBUFS; 1923 1924 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 1925 if (!caps) 1926 return -ENOBUFS; 1927 1928 if (nl80211_send_pmsr_ftm_capa(cap, msg)) 1929 return -ENOBUFS; 1930 1931 nla_nest_end(msg, caps); 1932 nla_nest_end(msg, pmsr); 1933 1934 return 0; 1935 } 1936 1937 static int 1938 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, 1939 struct sk_buff *msg) 1940 { 1941 int i; 1942 struct nlattr *nested, *nested_akms; 1943 const struct wiphy_iftype_akm_suites *iftype_akms; 1944 1945 if (!rdev->wiphy.num_iftype_akm_suites || 1946 !rdev->wiphy.iftype_akm_suites) 1947 return 0; 1948 1949 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); 1950 if (!nested) 1951 return -ENOBUFS; 1952 1953 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { 1954 nested_akms = nla_nest_start(msg, i + 1); 1955 if (!nested_akms) 1956 return -ENOBUFS; 1957 1958 iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; 1959 1960 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, 1961 iftype_akms->iftypes_mask)) 1962 return -ENOBUFS; 1963 1964 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, 1965 sizeof(u32) * iftype_akms->n_akm_suites, 1966 iftype_akms->akm_suites)) { 1967 return -ENOBUFS; 1968 } 1969 nla_nest_end(msg, nested_akms); 1970 } 1971 1972 nla_nest_end(msg, nested); 1973 1974 return 0; 1975 } 1976 1977 static int 1978 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, 1979 struct sk_buff *msg) 1980 { 1981 struct nlattr *supp; 1982 1983 if (!rdev->wiphy.tid_config_support.vif && 1984 !rdev->wiphy.tid_config_support.peer) 1985 return 0; 1986 1987 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); 1988 if (!supp) 1989 return -ENOSPC; 1990 1991 if (rdev->wiphy.tid_config_support.vif && 1992 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, 1993 rdev->wiphy.tid_config_support.vif, 1994 NL80211_TID_CONFIG_ATTR_PAD)) 1995 goto fail; 1996 1997 if (rdev->wiphy.tid_config_support.peer && 1998 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, 1999 rdev->wiphy.tid_config_support.peer, 2000 NL80211_TID_CONFIG_ATTR_PAD)) 2001 goto fail; 2002 2003 /* for now we just use the same value ... makes more sense */ 2004 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, 2005 rdev->wiphy.tid_config_support.max_retry)) 2006 goto fail; 2007 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, 2008 rdev->wiphy.tid_config_support.max_retry)) 2009 goto fail; 2010 2011 nla_nest_end(msg, supp); 2012 2013 return 0; 2014 fail: 2015 nla_nest_cancel(msg, supp); 2016 return -ENOBUFS; 2017 } 2018 2019 struct nl80211_dump_wiphy_state { 2020 s64 filter_wiphy; 2021 long start; 2022 long split_start, band_start, chan_start, capa_start; 2023 bool split; 2024 }; 2025 2026 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 2027 enum nl80211_commands cmd, 2028 struct sk_buff *msg, u32 portid, u32 seq, 2029 int flags, struct nl80211_dump_wiphy_state *state) 2030 { 2031 void *hdr; 2032 struct nlattr *nl_bands, *nl_band; 2033 struct nlattr *nl_freqs, *nl_freq; 2034 struct nlattr *nl_cmds; 2035 enum nl80211_band band; 2036 struct ieee80211_channel *chan; 2037 int i; 2038 const struct ieee80211_txrx_stypes *mgmt_stypes = 2039 rdev->wiphy.mgmt_stypes; 2040 u32 features; 2041 2042 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 2043 if (!hdr) 2044 return -ENOBUFS; 2045 2046 if (WARN_ON(!state)) 2047 return -EINVAL; 2048 2049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 2050 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, 2051 wiphy_name(&rdev->wiphy)) || 2052 nla_put_u32(msg, NL80211_ATTR_GENERATION, 2053 cfg80211_rdev_list_generation)) 2054 goto nla_put_failure; 2055 2056 if (cmd != NL80211_CMD_NEW_WIPHY) 2057 goto finish; 2058 2059 switch (state->split_start) { 2060 case 0: 2061 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 2062 rdev->wiphy.retry_short) || 2063 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, 2064 rdev->wiphy.retry_long) || 2065 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, 2066 rdev->wiphy.frag_threshold) || 2067 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 2068 rdev->wiphy.rts_threshold) || 2069 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 2070 rdev->wiphy.coverage_class) || 2071 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 2072 rdev->wiphy.max_scan_ssids) || 2073 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, 2074 rdev->wiphy.max_sched_scan_ssids) || 2075 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 2076 rdev->wiphy.max_scan_ie_len) || 2077 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, 2078 rdev->wiphy.max_sched_scan_ie_len) || 2079 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, 2080 rdev->wiphy.max_match_sets) || 2081 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, 2082 rdev->wiphy.max_sched_scan_plans) || 2083 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, 2084 rdev->wiphy.max_sched_scan_plan_interval) || 2085 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, 2086 rdev->wiphy.max_sched_scan_plan_iterations)) 2087 goto nla_put_failure; 2088 2089 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && 2090 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) 2091 goto nla_put_failure; 2092 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && 2093 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) 2094 goto nla_put_failure; 2095 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && 2096 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) 2097 goto nla_put_failure; 2098 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 2099 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) 2100 goto nla_put_failure; 2101 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && 2102 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) 2103 goto nla_put_failure; 2104 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && 2105 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) 2106 goto nla_put_failure; 2107 state->split_start++; 2108 if (state->split) 2109 break; 2110 fallthrough; 2111 case 1: 2112 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, 2113 sizeof(u32) * rdev->wiphy.n_cipher_suites, 2114 rdev->wiphy.cipher_suites)) 2115 goto nla_put_failure; 2116 2117 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 2118 rdev->wiphy.max_num_pmkids)) 2119 goto nla_put_failure; 2120 2121 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 2122 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) 2123 goto nla_put_failure; 2124 2125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, 2126 rdev->wiphy.available_antennas_tx) || 2127 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, 2128 rdev->wiphy.available_antennas_rx)) 2129 goto nla_put_failure; 2130 2131 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && 2132 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, 2133 rdev->wiphy.probe_resp_offload)) 2134 goto nla_put_failure; 2135 2136 if ((rdev->wiphy.available_antennas_tx || 2137 rdev->wiphy.available_antennas_rx) && 2138 rdev->ops->get_antenna) { 2139 u32 tx_ant = 0, rx_ant = 0; 2140 int res; 2141 2142 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); 2143 if (!res) { 2144 if (nla_put_u32(msg, 2145 NL80211_ATTR_WIPHY_ANTENNA_TX, 2146 tx_ant) || 2147 nla_put_u32(msg, 2148 NL80211_ATTR_WIPHY_ANTENNA_RX, 2149 rx_ant)) 2150 goto nla_put_failure; 2151 } 2152 } 2153 2154 state->split_start++; 2155 if (state->split) 2156 break; 2157 fallthrough; 2158 case 2: 2159 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, 2160 rdev->wiphy.interface_modes)) 2161 goto nla_put_failure; 2162 state->split_start++; 2163 if (state->split) 2164 break; 2165 fallthrough; 2166 case 3: 2167 nl_bands = nla_nest_start_noflag(msg, 2168 NL80211_ATTR_WIPHY_BANDS); 2169 if (!nl_bands) 2170 goto nla_put_failure; 2171 2172 for (band = state->band_start; 2173 band < NUM_NL80211_BANDS; band++) { 2174 struct ieee80211_supported_band *sband; 2175 2176 sband = rdev->wiphy.bands[band]; 2177 2178 if (!sband) 2179 continue; 2180 2181 nl_band = nla_nest_start_noflag(msg, band); 2182 if (!nl_band) 2183 goto nla_put_failure; 2184 2185 switch (state->chan_start) { 2186 case 0: 2187 if (nl80211_send_band_rateinfo(msg, sband)) 2188 goto nla_put_failure; 2189 state->chan_start++; 2190 if (state->split) 2191 break; 2192 fallthrough; 2193 default: 2194 /* add frequencies */ 2195 nl_freqs = nla_nest_start_noflag(msg, 2196 NL80211_BAND_ATTR_FREQS); 2197 if (!nl_freqs) 2198 goto nla_put_failure; 2199 2200 for (i = state->chan_start - 1; 2201 i < sband->n_channels; 2202 i++) { 2203 nl_freq = nla_nest_start_noflag(msg, 2204 i); 2205 if (!nl_freq) 2206 goto nla_put_failure; 2207 2208 chan = &sband->channels[i]; 2209 2210 if (nl80211_msg_put_channel( 2211 msg, &rdev->wiphy, chan, 2212 state->split)) 2213 goto nla_put_failure; 2214 2215 nla_nest_end(msg, nl_freq); 2216 if (state->split) 2217 break; 2218 } 2219 if (i < sband->n_channels) 2220 state->chan_start = i + 2; 2221 else 2222 state->chan_start = 0; 2223 nla_nest_end(msg, nl_freqs); 2224 } 2225 2226 nla_nest_end(msg, nl_band); 2227 2228 if (state->split) { 2229 /* start again here */ 2230 if (state->chan_start) 2231 band--; 2232 break; 2233 } 2234 } 2235 nla_nest_end(msg, nl_bands); 2236 2237 if (band < NUM_NL80211_BANDS) 2238 state->band_start = band + 1; 2239 else 2240 state->band_start = 0; 2241 2242 /* if bands & channels are done, continue outside */ 2243 if (state->band_start == 0 && state->chan_start == 0) 2244 state->split_start++; 2245 if (state->split) 2246 break; 2247 fallthrough; 2248 case 4: 2249 nl_cmds = nla_nest_start_noflag(msg, 2250 NL80211_ATTR_SUPPORTED_COMMANDS); 2251 if (!nl_cmds) 2252 goto nla_put_failure; 2253 2254 i = nl80211_add_commands_unsplit(rdev, msg); 2255 if (i < 0) 2256 goto nla_put_failure; 2257 if (state->split) { 2258 CMD(crit_proto_start, CRIT_PROTOCOL_START); 2259 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); 2260 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 2261 CMD(channel_switch, CHANNEL_SWITCH); 2262 CMD(set_qos_map, SET_QOS_MAP); 2263 if (rdev->wiphy.features & 2264 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 2265 CMD(add_tx_ts, ADD_TX_TS); 2266 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); 2267 CMD(update_connect_params, UPDATE_CONNECT_PARAMS); 2268 CMD(update_ft_ies, UPDATE_FT_IES); 2269 } 2270 #undef CMD 2271 2272 nla_nest_end(msg, nl_cmds); 2273 state->split_start++; 2274 if (state->split) 2275 break; 2276 fallthrough; 2277 case 5: 2278 if (rdev->ops->remain_on_channel && 2279 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && 2280 nla_put_u32(msg, 2281 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, 2282 rdev->wiphy.max_remain_on_channel_duration)) 2283 goto nla_put_failure; 2284 2285 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && 2286 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) 2287 goto nla_put_failure; 2288 2289 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) 2290 goto nla_put_failure; 2291 state->split_start++; 2292 if (state->split) 2293 break; 2294 fallthrough; 2295 case 6: 2296 #ifdef CONFIG_PM 2297 if (nl80211_send_wowlan(msg, rdev, state->split)) 2298 goto nla_put_failure; 2299 state->split_start++; 2300 if (state->split) 2301 break; 2302 #else 2303 state->split_start++; 2304 #endif 2305 fallthrough; 2306 case 7: 2307 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, 2308 rdev->wiphy.software_iftypes)) 2309 goto nla_put_failure; 2310 2311 if (nl80211_put_iface_combinations(&rdev->wiphy, msg, 2312 state->split)) 2313 goto nla_put_failure; 2314 2315 state->split_start++; 2316 if (state->split) 2317 break; 2318 fallthrough; 2319 case 8: 2320 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && 2321 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, 2322 rdev->wiphy.ap_sme_capa)) 2323 goto nla_put_failure; 2324 2325 features = rdev->wiphy.features; 2326 /* 2327 * We can only add the per-channel limit information if the 2328 * dump is split, otherwise it makes it too big. Therefore 2329 * only advertise it in that case. 2330 */ 2331 if (state->split) 2332 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; 2333 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) 2334 goto nla_put_failure; 2335 2336 if (rdev->wiphy.ht_capa_mod_mask && 2337 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, 2338 sizeof(*rdev->wiphy.ht_capa_mod_mask), 2339 rdev->wiphy.ht_capa_mod_mask)) 2340 goto nla_put_failure; 2341 2342 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && 2343 rdev->wiphy.max_acl_mac_addrs && 2344 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, 2345 rdev->wiphy.max_acl_mac_addrs)) 2346 goto nla_put_failure; 2347 2348 /* 2349 * Any information below this point is only available to 2350 * applications that can deal with it being split. This 2351 * helps ensure that newly added capabilities don't break 2352 * older tools by overrunning their buffers. 2353 * 2354 * We still increment split_start so that in the split 2355 * case we'll continue with more data in the next round, 2356 * but break unconditionally so unsplit data stops here. 2357 */ 2358 state->split_start++; 2359 break; 2360 case 9: 2361 if (rdev->wiphy.extended_capabilities && 2362 (nla_put(msg, NL80211_ATTR_EXT_CAPA, 2363 rdev->wiphy.extended_capabilities_len, 2364 rdev->wiphy.extended_capabilities) || 2365 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2366 rdev->wiphy.extended_capabilities_len, 2367 rdev->wiphy.extended_capabilities_mask))) 2368 goto nla_put_failure; 2369 2370 if (rdev->wiphy.vht_capa_mod_mask && 2371 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, 2372 sizeof(*rdev->wiphy.vht_capa_mod_mask), 2373 rdev->wiphy.vht_capa_mod_mask)) 2374 goto nla_put_failure; 2375 2376 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 2377 rdev->wiphy.perm_addr)) 2378 goto nla_put_failure; 2379 2380 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && 2381 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, 2382 rdev->wiphy.addr_mask)) 2383 goto nla_put_failure; 2384 2385 if (rdev->wiphy.n_addresses > 1) { 2386 void *attr; 2387 2388 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); 2389 if (!attr) 2390 goto nla_put_failure; 2391 2392 for (i = 0; i < rdev->wiphy.n_addresses; i++) 2393 if (nla_put(msg, i + 1, ETH_ALEN, 2394 rdev->wiphy.addresses[i].addr)) 2395 goto nla_put_failure; 2396 2397 nla_nest_end(msg, attr); 2398 } 2399 2400 state->split_start++; 2401 break; 2402 case 10: 2403 if (nl80211_send_coalesce(msg, rdev)) 2404 goto nla_put_failure; 2405 2406 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && 2407 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || 2408 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) 2409 goto nla_put_failure; 2410 2411 if (rdev->wiphy.max_ap_assoc_sta && 2412 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, 2413 rdev->wiphy.max_ap_assoc_sta)) 2414 goto nla_put_failure; 2415 2416 state->split_start++; 2417 break; 2418 case 11: 2419 if (rdev->wiphy.n_vendor_commands) { 2420 const struct nl80211_vendor_cmd_info *info; 2421 struct nlattr *nested; 2422 2423 nested = nla_nest_start_noflag(msg, 2424 NL80211_ATTR_VENDOR_DATA); 2425 if (!nested) 2426 goto nla_put_failure; 2427 2428 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 2429 info = &rdev->wiphy.vendor_commands[i].info; 2430 if (nla_put(msg, i + 1, sizeof(*info), info)) 2431 goto nla_put_failure; 2432 } 2433 nla_nest_end(msg, nested); 2434 } 2435 2436 if (rdev->wiphy.n_vendor_events) { 2437 const struct nl80211_vendor_cmd_info *info; 2438 struct nlattr *nested; 2439 2440 nested = nla_nest_start_noflag(msg, 2441 NL80211_ATTR_VENDOR_EVENTS); 2442 if (!nested) 2443 goto nla_put_failure; 2444 2445 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { 2446 info = &rdev->wiphy.vendor_events[i]; 2447 if (nla_put(msg, i + 1, sizeof(*info), info)) 2448 goto nla_put_failure; 2449 } 2450 nla_nest_end(msg, nested); 2451 } 2452 state->split_start++; 2453 break; 2454 case 12: 2455 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && 2456 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, 2457 rdev->wiphy.max_num_csa_counters)) 2458 goto nla_put_failure; 2459 2460 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 2461 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 2462 goto nla_put_failure; 2463 2464 if (rdev->wiphy.max_sched_scan_reqs && 2465 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, 2466 rdev->wiphy.max_sched_scan_reqs)) 2467 goto nla_put_failure; 2468 2469 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, 2470 sizeof(rdev->wiphy.ext_features), 2471 rdev->wiphy.ext_features)) 2472 goto nla_put_failure; 2473 2474 if (rdev->wiphy.bss_select_support) { 2475 struct nlattr *nested; 2476 u32 bss_select_support = rdev->wiphy.bss_select_support; 2477 2478 nested = nla_nest_start_noflag(msg, 2479 NL80211_ATTR_BSS_SELECT); 2480 if (!nested) 2481 goto nla_put_failure; 2482 2483 i = 0; 2484 while (bss_select_support) { 2485 if ((bss_select_support & 1) && 2486 nla_put_flag(msg, i)) 2487 goto nla_put_failure; 2488 i++; 2489 bss_select_support >>= 1; 2490 } 2491 nla_nest_end(msg, nested); 2492 } 2493 2494 state->split_start++; 2495 break; 2496 case 13: 2497 if (rdev->wiphy.num_iftype_ext_capab && 2498 rdev->wiphy.iftype_ext_capab) { 2499 struct nlattr *nested_ext_capab, *nested; 2500 2501 nested = nla_nest_start_noflag(msg, 2502 NL80211_ATTR_IFTYPE_EXT_CAPA); 2503 if (!nested) 2504 goto nla_put_failure; 2505 2506 for (i = state->capa_start; 2507 i < rdev->wiphy.num_iftype_ext_capab; i++) { 2508 const struct wiphy_iftype_ext_capab *capab; 2509 2510 capab = &rdev->wiphy.iftype_ext_capab[i]; 2511 2512 nested_ext_capab = nla_nest_start_noflag(msg, 2513 i); 2514 if (!nested_ext_capab || 2515 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2516 capab->iftype) || 2517 nla_put(msg, NL80211_ATTR_EXT_CAPA, 2518 capab->extended_capabilities_len, 2519 capab->extended_capabilities) || 2520 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2521 capab->extended_capabilities_len, 2522 capab->extended_capabilities_mask)) 2523 goto nla_put_failure; 2524 2525 nla_nest_end(msg, nested_ext_capab); 2526 if (state->split) 2527 break; 2528 } 2529 nla_nest_end(msg, nested); 2530 if (i < rdev->wiphy.num_iftype_ext_capab) { 2531 state->capa_start = i + 1; 2532 break; 2533 } 2534 } 2535 2536 if (nla_put_u32(msg, NL80211_ATTR_BANDS, 2537 rdev->wiphy.nan_supported_bands)) 2538 goto nla_put_failure; 2539 2540 if (wiphy_ext_feature_isset(&rdev->wiphy, 2541 NL80211_EXT_FEATURE_TXQS)) { 2542 struct cfg80211_txq_stats txqstats = {}; 2543 int res; 2544 2545 res = rdev_get_txq_stats(rdev, NULL, &txqstats); 2546 if (!res && 2547 !nl80211_put_txq_stats(msg, &txqstats, 2548 NL80211_ATTR_TXQ_STATS)) 2549 goto nla_put_failure; 2550 2551 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, 2552 rdev->wiphy.txq_limit)) 2553 goto nla_put_failure; 2554 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, 2555 rdev->wiphy.txq_memory_limit)) 2556 goto nla_put_failure; 2557 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, 2558 rdev->wiphy.txq_quantum)) 2559 goto nla_put_failure; 2560 } 2561 2562 state->split_start++; 2563 break; 2564 case 14: 2565 if (nl80211_send_pmsr_capa(rdev, msg)) 2566 goto nla_put_failure; 2567 2568 state->split_start++; 2569 break; 2570 case 15: 2571 if (rdev->wiphy.akm_suites && 2572 nla_put(msg, NL80211_ATTR_AKM_SUITES, 2573 sizeof(u32) * rdev->wiphy.n_akm_suites, 2574 rdev->wiphy.akm_suites)) 2575 goto nla_put_failure; 2576 2577 if (nl80211_put_iftype_akm_suites(rdev, msg)) 2578 goto nla_put_failure; 2579 2580 if (nl80211_put_tid_config_support(rdev, msg)) 2581 goto nla_put_failure; 2582 2583 /* done */ 2584 state->split_start = 0; 2585 break; 2586 } 2587 finish: 2588 genlmsg_end(msg, hdr); 2589 return 0; 2590 2591 nla_put_failure: 2592 genlmsg_cancel(msg, hdr); 2593 return -EMSGSIZE; 2594 } 2595 2596 static int nl80211_dump_wiphy_parse(struct sk_buff *skb, 2597 struct netlink_callback *cb, 2598 struct nl80211_dump_wiphy_state *state) 2599 { 2600 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 2601 int ret; 2602 2603 if (!tb) 2604 return -ENOMEM; 2605 2606 ret = nlmsg_parse_deprecated(cb->nlh, 2607 GENL_HDRLEN + nl80211_fam.hdrsize, 2608 tb, nl80211_fam.maxattr, 2609 nl80211_policy, NULL); 2610 /* ignore parse errors for backward compatibility */ 2611 if (ret) { 2612 ret = 0; 2613 goto out; 2614 } 2615 2616 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; 2617 if (tb[NL80211_ATTR_WIPHY]) 2618 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 2619 if (tb[NL80211_ATTR_WDEV]) 2620 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; 2621 if (tb[NL80211_ATTR_IFINDEX]) { 2622 struct net_device *netdev; 2623 struct cfg80211_registered_device *rdev; 2624 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); 2625 2626 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); 2627 if (!netdev) { 2628 ret = -ENODEV; 2629 goto out; 2630 } 2631 if (netdev->ieee80211_ptr) { 2632 rdev = wiphy_to_rdev( 2633 netdev->ieee80211_ptr->wiphy); 2634 state->filter_wiphy = rdev->wiphy_idx; 2635 } 2636 } 2637 2638 ret = 0; 2639 out: 2640 kfree(tb); 2641 return ret; 2642 } 2643 2644 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) 2645 { 2646 int idx = 0, ret; 2647 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; 2648 struct cfg80211_registered_device *rdev; 2649 2650 rtnl_lock(); 2651 if (!state) { 2652 state = kzalloc(sizeof(*state), GFP_KERNEL); 2653 if (!state) { 2654 rtnl_unlock(); 2655 return -ENOMEM; 2656 } 2657 state->filter_wiphy = -1; 2658 ret = nl80211_dump_wiphy_parse(skb, cb, state); 2659 if (ret) { 2660 kfree(state); 2661 rtnl_unlock(); 2662 return ret; 2663 } 2664 cb->args[0] = (long)state; 2665 } 2666 2667 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 2668 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 2669 continue; 2670 if (++idx <= state->start) 2671 continue; 2672 if (state->filter_wiphy != -1 && 2673 state->filter_wiphy != rdev->wiphy_idx) 2674 continue; 2675 /* attempt to fit multiple wiphy data chunks into the skb */ 2676 do { 2677 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, 2678 skb, 2679 NETLINK_CB(cb->skb).portid, 2680 cb->nlh->nlmsg_seq, 2681 NLM_F_MULTI, state); 2682 if (ret < 0) { 2683 /* 2684 * If sending the wiphy data didn't fit (ENOBUFS 2685 * or EMSGSIZE returned), this SKB is still 2686 * empty (so it's not too big because another 2687 * wiphy dataset is already in the skb) and 2688 * we've not tried to adjust the dump allocation 2689 * yet ... then adjust the alloc size to be 2690 * bigger, and return 1 but with the empty skb. 2691 * This results in an empty message being RX'ed 2692 * in userspace, but that is ignored. 2693 * 2694 * We can then retry with the larger buffer. 2695 */ 2696 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 2697 !skb->len && !state->split && 2698 cb->min_dump_alloc < 4096) { 2699 cb->min_dump_alloc = 4096; 2700 state->split_start = 0; 2701 rtnl_unlock(); 2702 return 1; 2703 } 2704 idx--; 2705 break; 2706 } 2707 } while (state->split_start > 0); 2708 break; 2709 } 2710 rtnl_unlock(); 2711 2712 state->start = idx; 2713 2714 return skb->len; 2715 } 2716 2717 static int nl80211_dump_wiphy_done(struct netlink_callback *cb) 2718 { 2719 kfree((void *)cb->args[0]); 2720 return 0; 2721 } 2722 2723 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 2724 { 2725 struct sk_buff *msg; 2726 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2727 struct nl80211_dump_wiphy_state state = {}; 2728 2729 msg = nlmsg_new(4096, GFP_KERNEL); 2730 if (!msg) 2731 return -ENOMEM; 2732 2733 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, 2734 info->snd_portid, info->snd_seq, 0, 2735 &state) < 0) { 2736 nlmsg_free(msg); 2737 return -ENOBUFS; 2738 } 2739 2740 return genlmsg_reply(msg, info); 2741 } 2742 2743 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 2744 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, 2745 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, 2746 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, 2747 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, 2748 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, 2749 }; 2750 2751 static int parse_txq_params(struct nlattr *tb[], 2752 struct ieee80211_txq_params *txq_params) 2753 { 2754 u8 ac; 2755 2756 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || 2757 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || 2758 !tb[NL80211_TXQ_ATTR_AIFS]) 2759 return -EINVAL; 2760 2761 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); 2762 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); 2763 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); 2764 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); 2765 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); 2766 2767 if (ac >= NL80211_NUM_ACS) 2768 return -EINVAL; 2769 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); 2770 return 0; 2771 } 2772 2773 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 2774 { 2775 /* 2776 * You can only set the channel explicitly for WDS interfaces, 2777 * all others have their channel managed via their respective 2778 * "establish a connection" command (connect, join, ...) 2779 * 2780 * For AP/GO and mesh mode, the channel can be set with the 2781 * channel userspace API, but is only stored and passed to the 2782 * low-level driver when the AP starts or the mesh is joined. 2783 * This is for backward compatibility, userspace can also give 2784 * the channel in the start-ap or join-mesh commands instead. 2785 * 2786 * Monitors are special as they are normally slaved to 2787 * whatever else is going on, so they have their own special 2788 * operation to set the monitor channel if possible. 2789 */ 2790 return !wdev || 2791 wdev->iftype == NL80211_IFTYPE_AP || 2792 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 2793 wdev->iftype == NL80211_IFTYPE_MONITOR || 2794 wdev->iftype == NL80211_IFTYPE_P2P_GO; 2795 } 2796 2797 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, 2798 struct genl_info *info, 2799 struct cfg80211_chan_def *chandef) 2800 { 2801 struct netlink_ext_ack *extack = info->extack; 2802 struct nlattr **attrs = info->attrs; 2803 u32 control_freq; 2804 2805 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) 2806 return -EINVAL; 2807 2808 control_freq = MHZ_TO_KHZ( 2809 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 2810 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 2811 control_freq += 2812 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 2813 2814 memset(chandef, 0, sizeof(*chandef)); 2815 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); 2816 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 2817 chandef->center_freq1 = KHZ_TO_MHZ(control_freq); 2818 chandef->freq1_offset = control_freq % 1000; 2819 chandef->center_freq2 = 0; 2820 2821 /* Primary channel not allowed */ 2822 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { 2823 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 2824 "Channel is disabled"); 2825 return -EINVAL; 2826 } 2827 2828 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 2829 enum nl80211_channel_type chantype; 2830 2831 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); 2832 2833 switch (chantype) { 2834 case NL80211_CHAN_NO_HT: 2835 case NL80211_CHAN_HT20: 2836 case NL80211_CHAN_HT40PLUS: 2837 case NL80211_CHAN_HT40MINUS: 2838 cfg80211_chandef_create(chandef, chandef->chan, 2839 chantype); 2840 /* user input for center_freq is incorrect */ 2841 if (attrs[NL80211_ATTR_CENTER_FREQ1] && 2842 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { 2843 NL_SET_ERR_MSG_ATTR(extack, 2844 attrs[NL80211_ATTR_CENTER_FREQ1], 2845 "bad center frequency 1"); 2846 return -EINVAL; 2847 } 2848 /* center_freq2 must be zero */ 2849 if (attrs[NL80211_ATTR_CENTER_FREQ2] && 2850 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { 2851 NL_SET_ERR_MSG_ATTR(extack, 2852 attrs[NL80211_ATTR_CENTER_FREQ2], 2853 "center frequency 2 can't be used"); 2854 return -EINVAL; 2855 } 2856 break; 2857 default: 2858 NL_SET_ERR_MSG_ATTR(extack, 2859 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], 2860 "invalid channel type"); 2861 return -EINVAL; 2862 } 2863 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { 2864 chandef->width = 2865 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); 2866 if (attrs[NL80211_ATTR_CENTER_FREQ1]) { 2867 chandef->center_freq1 = 2868 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 2869 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) 2870 chandef->freq1_offset = nla_get_u32( 2871 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); 2872 else 2873 chandef->freq1_offset = 0; 2874 } 2875 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 2876 chandef->center_freq2 = 2877 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); 2878 } 2879 2880 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 2881 chandef->edmg.channels = 2882 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 2883 2884 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 2885 chandef->edmg.bw_config = 2886 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 2887 } else { 2888 chandef->edmg.bw_config = 0; 2889 chandef->edmg.channels = 0; 2890 } 2891 2892 if (!cfg80211_chandef_valid(chandef)) { 2893 NL_SET_ERR_MSG(extack, "invalid channel definition"); 2894 return -EINVAL; 2895 } 2896 2897 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, 2898 IEEE80211_CHAN_DISABLED)) { 2899 NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); 2900 return -EINVAL; 2901 } 2902 2903 if ((chandef->width == NL80211_CHAN_WIDTH_5 || 2904 chandef->width == NL80211_CHAN_WIDTH_10) && 2905 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { 2906 NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); 2907 return -EINVAL; 2908 } 2909 2910 return 0; 2911 } 2912 2913 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 2914 struct net_device *dev, 2915 struct genl_info *info) 2916 { 2917 struct cfg80211_chan_def chandef; 2918 int result; 2919 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; 2920 struct wireless_dev *wdev = NULL; 2921 2922 if (dev) 2923 wdev = dev->ieee80211_ptr; 2924 if (!nl80211_can_set_dev_channel(wdev)) 2925 return -EOPNOTSUPP; 2926 if (wdev) 2927 iftype = wdev->iftype; 2928 2929 result = nl80211_parse_chandef(rdev, info, &chandef); 2930 if (result) 2931 return result; 2932 2933 switch (iftype) { 2934 case NL80211_IFTYPE_AP: 2935 case NL80211_IFTYPE_P2P_GO: 2936 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 2937 iftype)) { 2938 result = -EINVAL; 2939 break; 2940 } 2941 if (wdev->beacon_interval) { 2942 if (!dev || !rdev->ops->set_ap_chanwidth || 2943 !(rdev->wiphy.features & 2944 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { 2945 result = -EBUSY; 2946 break; 2947 } 2948 2949 /* Only allow dynamic channel width changes */ 2950 if (chandef.chan != wdev->preset_chandef.chan) { 2951 result = -EBUSY; 2952 break; 2953 } 2954 result = rdev_set_ap_chanwidth(rdev, dev, &chandef); 2955 if (result) 2956 break; 2957 } 2958 wdev->preset_chandef = chandef; 2959 result = 0; 2960 break; 2961 case NL80211_IFTYPE_MESH_POINT: 2962 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); 2963 break; 2964 case NL80211_IFTYPE_MONITOR: 2965 result = cfg80211_set_monitor_channel(rdev, &chandef); 2966 break; 2967 default: 2968 result = -EINVAL; 2969 } 2970 2971 return result; 2972 } 2973 2974 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 2975 { 2976 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2977 struct net_device *netdev = info->user_ptr[1]; 2978 2979 return __nl80211_set_channel(rdev, netdev, info); 2980 } 2981 2982 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) 2983 { 2984 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2985 struct net_device *dev = info->user_ptr[1]; 2986 struct wireless_dev *wdev = dev->ieee80211_ptr; 2987 const u8 *bssid; 2988 2989 if (!info->attrs[NL80211_ATTR_MAC]) 2990 return -EINVAL; 2991 2992 if (netif_running(dev)) 2993 return -EBUSY; 2994 2995 if (!rdev->ops->set_wds_peer) 2996 return -EOPNOTSUPP; 2997 2998 if (wdev->iftype != NL80211_IFTYPE_WDS) 2999 return -EOPNOTSUPP; 3000 3001 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 3002 return rdev_set_wds_peer(rdev, dev, bssid); 3003 } 3004 3005 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 3006 { 3007 struct cfg80211_registered_device *rdev; 3008 struct net_device *netdev = NULL; 3009 struct wireless_dev *wdev; 3010 int result = 0, rem_txq_params = 0; 3011 struct nlattr *nl_txq_params; 3012 u32 changed; 3013 u8 retry_short = 0, retry_long = 0; 3014 u32 frag_threshold = 0, rts_threshold = 0; 3015 u8 coverage_class = 0; 3016 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; 3017 3018 ASSERT_RTNL(); 3019 3020 /* 3021 * Try to find the wiphy and netdev. Normally this 3022 * function shouldn't need the netdev, but this is 3023 * done for backward compatibility -- previously 3024 * setting the channel was done per wiphy, but now 3025 * it is per netdev. Previous userland like hostapd 3026 * also passed a netdev to set_wiphy, so that it is 3027 * possible to let that go to the right netdev! 3028 */ 3029 3030 if (info->attrs[NL80211_ATTR_IFINDEX]) { 3031 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 3032 3033 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 3034 if (netdev && netdev->ieee80211_ptr) 3035 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); 3036 else 3037 netdev = NULL; 3038 } 3039 3040 if (!netdev) { 3041 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), 3042 info->attrs); 3043 if (IS_ERR(rdev)) 3044 return PTR_ERR(rdev); 3045 wdev = NULL; 3046 netdev = NULL; 3047 result = 0; 3048 } else 3049 wdev = netdev->ieee80211_ptr; 3050 3051 /* 3052 * end workaround code, by now the rdev is available 3053 * and locked, and wdev may or may not be NULL. 3054 */ 3055 3056 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) 3057 result = cfg80211_dev_rename( 3058 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 3059 3060 if (result) 3061 return result; 3062 3063 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 3064 struct ieee80211_txq_params txq_params; 3065 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 3066 3067 if (!rdev->ops->set_txq_params) 3068 return -EOPNOTSUPP; 3069 3070 if (!netdev) 3071 return -EINVAL; 3072 3073 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3074 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 3075 return -EINVAL; 3076 3077 if (!netif_running(netdev)) 3078 return -ENETDOWN; 3079 3080 nla_for_each_nested(nl_txq_params, 3081 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 3082 rem_txq_params) { 3083 result = nla_parse_nested_deprecated(tb, 3084 NL80211_TXQ_ATTR_MAX, 3085 nl_txq_params, 3086 txq_params_policy, 3087 info->extack); 3088 if (result) 3089 return result; 3090 result = parse_txq_params(tb, &txq_params); 3091 if (result) 3092 return result; 3093 3094 result = rdev_set_txq_params(rdev, netdev, 3095 &txq_params); 3096 if (result) 3097 return result; 3098 } 3099 } 3100 3101 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3102 result = __nl80211_set_channel( 3103 rdev, 3104 nl80211_can_set_dev_channel(wdev) ? netdev : NULL, 3105 info); 3106 if (result) 3107 return result; 3108 } 3109 3110 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { 3111 struct wireless_dev *txp_wdev = wdev; 3112 enum nl80211_tx_power_setting type; 3113 int idx, mbm = 0; 3114 3115 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 3116 txp_wdev = NULL; 3117 3118 if (!rdev->ops->set_tx_power) 3119 return -EOPNOTSUPP; 3120 3121 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 3122 type = nla_get_u32(info->attrs[idx]); 3123 3124 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 3125 (type != NL80211_TX_POWER_AUTOMATIC)) 3126 return -EINVAL; 3127 3128 if (type != NL80211_TX_POWER_AUTOMATIC) { 3129 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; 3130 mbm = nla_get_u32(info->attrs[idx]); 3131 } 3132 3133 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 3134 if (result) 3135 return result; 3136 } 3137 3138 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && 3139 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { 3140 u32 tx_ant, rx_ant; 3141 3142 if ((!rdev->wiphy.available_antennas_tx && 3143 !rdev->wiphy.available_antennas_rx) || 3144 !rdev->ops->set_antenna) 3145 return -EOPNOTSUPP; 3146 3147 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 3148 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); 3149 3150 /* reject antenna configurations which don't match the 3151 * available antenna masks, except for the "all" mask */ 3152 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 3153 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) 3154 return -EINVAL; 3155 3156 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 3157 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 3158 3159 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 3160 if (result) 3161 return result; 3162 } 3163 3164 changed = 0; 3165 3166 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 3167 retry_short = nla_get_u8( 3168 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); 3169 3170 changed |= WIPHY_PARAM_RETRY_SHORT; 3171 } 3172 3173 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { 3174 retry_long = nla_get_u8( 3175 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); 3176 3177 changed |= WIPHY_PARAM_RETRY_LONG; 3178 } 3179 3180 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 3181 frag_threshold = nla_get_u32( 3182 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 3183 if (frag_threshold < 256) 3184 return -EINVAL; 3185 3186 if (frag_threshold != (u32) -1) { 3187 /* 3188 * Fragments (apart from the last one) are required to 3189 * have even length. Make the fragmentation code 3190 * simpler by stripping LSB should someone try to use 3191 * odd threshold value. 3192 */ 3193 frag_threshold &= ~0x1; 3194 } 3195 changed |= WIPHY_PARAM_FRAG_THRESHOLD; 3196 } 3197 3198 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { 3199 rts_threshold = nla_get_u32( 3200 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); 3201 changed |= WIPHY_PARAM_RTS_THRESHOLD; 3202 } 3203 3204 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 3205 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) 3206 return -EINVAL; 3207 3208 coverage_class = nla_get_u8( 3209 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); 3210 changed |= WIPHY_PARAM_COVERAGE_CLASS; 3211 } 3212 3213 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3214 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) 3215 return -EOPNOTSUPP; 3216 3217 changed |= WIPHY_PARAM_DYN_ACK; 3218 } 3219 3220 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 3221 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3222 NL80211_EXT_FEATURE_TXQS)) 3223 return -EOPNOTSUPP; 3224 txq_limit = nla_get_u32( 3225 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 3226 changed |= WIPHY_PARAM_TXQ_LIMIT; 3227 } 3228 3229 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 3230 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3231 NL80211_EXT_FEATURE_TXQS)) 3232 return -EOPNOTSUPP; 3233 txq_memory_limit = nla_get_u32( 3234 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 3235 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; 3236 } 3237 3238 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 3239 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3240 NL80211_EXT_FEATURE_TXQS)) 3241 return -EOPNOTSUPP; 3242 txq_quantum = nla_get_u32( 3243 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 3244 changed |= WIPHY_PARAM_TXQ_QUANTUM; 3245 } 3246 3247 if (changed) { 3248 u8 old_retry_short, old_retry_long; 3249 u32 old_frag_threshold, old_rts_threshold; 3250 u8 old_coverage_class; 3251 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 3252 3253 if (!rdev->ops->set_wiphy_params) 3254 return -EOPNOTSUPP; 3255 3256 old_retry_short = rdev->wiphy.retry_short; 3257 old_retry_long = rdev->wiphy.retry_long; 3258 old_frag_threshold = rdev->wiphy.frag_threshold; 3259 old_rts_threshold = rdev->wiphy.rts_threshold; 3260 old_coverage_class = rdev->wiphy.coverage_class; 3261 old_txq_limit = rdev->wiphy.txq_limit; 3262 old_txq_memory_limit = rdev->wiphy.txq_memory_limit; 3263 old_txq_quantum = rdev->wiphy.txq_quantum; 3264 3265 if (changed & WIPHY_PARAM_RETRY_SHORT) 3266 rdev->wiphy.retry_short = retry_short; 3267 if (changed & WIPHY_PARAM_RETRY_LONG) 3268 rdev->wiphy.retry_long = retry_long; 3269 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 3270 rdev->wiphy.frag_threshold = frag_threshold; 3271 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 3272 rdev->wiphy.rts_threshold = rts_threshold; 3273 if (changed & WIPHY_PARAM_COVERAGE_CLASS) 3274 rdev->wiphy.coverage_class = coverage_class; 3275 if (changed & WIPHY_PARAM_TXQ_LIMIT) 3276 rdev->wiphy.txq_limit = txq_limit; 3277 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) 3278 rdev->wiphy.txq_memory_limit = txq_memory_limit; 3279 if (changed & WIPHY_PARAM_TXQ_QUANTUM) 3280 rdev->wiphy.txq_quantum = txq_quantum; 3281 3282 result = rdev_set_wiphy_params(rdev, changed); 3283 if (result) { 3284 rdev->wiphy.retry_short = old_retry_short; 3285 rdev->wiphy.retry_long = old_retry_long; 3286 rdev->wiphy.frag_threshold = old_frag_threshold; 3287 rdev->wiphy.rts_threshold = old_rts_threshold; 3288 rdev->wiphy.coverage_class = old_coverage_class; 3289 rdev->wiphy.txq_limit = old_txq_limit; 3290 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3291 rdev->wiphy.txq_quantum = old_txq_quantum; 3292 return result; 3293 } 3294 } 3295 return 0; 3296 } 3297 3298 static int nl80211_send_chandef(struct sk_buff *msg, 3299 const struct cfg80211_chan_def *chandef) 3300 { 3301 if (WARN_ON(!cfg80211_chandef_valid(chandef))) 3302 return -EINVAL; 3303 3304 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 3305 chandef->chan->center_freq)) 3306 return -ENOBUFS; 3307 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 3308 chandef->chan->freq_offset)) 3309 return -ENOBUFS; 3310 switch (chandef->width) { 3311 case NL80211_CHAN_WIDTH_20_NOHT: 3312 case NL80211_CHAN_WIDTH_20: 3313 case NL80211_CHAN_WIDTH_40: 3314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 3315 cfg80211_get_chandef_type(chandef))) 3316 return -ENOBUFS; 3317 break; 3318 default: 3319 break; 3320 } 3321 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) 3322 return -ENOBUFS; 3323 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) 3324 return -ENOBUFS; 3325 if (chandef->center_freq2 && 3326 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) 3327 return -ENOBUFS; 3328 return 0; 3329 } 3330 3331 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, 3332 struct cfg80211_registered_device *rdev, 3333 struct wireless_dev *wdev, 3334 enum nl80211_commands cmd) 3335 { 3336 struct net_device *dev = wdev->netdev; 3337 void *hdr; 3338 3339 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && 3340 cmd != NL80211_CMD_DEL_INTERFACE && 3341 cmd != NL80211_CMD_SET_INTERFACE); 3342 3343 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 3344 if (!hdr) 3345 return -1; 3346 3347 if (dev && 3348 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3349 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) 3350 goto nla_put_failure; 3351 3352 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3353 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || 3354 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3355 NL80211_ATTR_PAD) || 3356 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || 3357 nla_put_u32(msg, NL80211_ATTR_GENERATION, 3358 rdev->devlist_generation ^ 3359 (cfg80211_rdev_list_generation << 2)) || 3360 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) 3361 goto nla_put_failure; 3362 3363 if (rdev->ops->get_channel) { 3364 int ret; 3365 struct cfg80211_chan_def chandef = {}; 3366 3367 ret = rdev_get_channel(rdev, wdev, &chandef); 3368 if (ret == 0) { 3369 if (nl80211_send_chandef(msg, &chandef)) 3370 goto nla_put_failure; 3371 } 3372 } 3373 3374 if (rdev->ops->get_tx_power) { 3375 int dbm, ret; 3376 3377 ret = rdev_get_tx_power(rdev, wdev, &dbm); 3378 if (ret == 0 && 3379 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, 3380 DBM_TO_MBM(dbm))) 3381 goto nla_put_failure; 3382 } 3383 3384 wdev_lock(wdev); 3385 switch (wdev->iftype) { 3386 case NL80211_IFTYPE_AP: 3387 if (wdev->ssid_len && 3388 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) 3389 goto nla_put_failure_locked; 3390 break; 3391 case NL80211_IFTYPE_STATION: 3392 case NL80211_IFTYPE_P2P_CLIENT: 3393 case NL80211_IFTYPE_ADHOC: { 3394 const u8 *ssid_ie; 3395 if (!wdev->current_bss) 3396 break; 3397 rcu_read_lock(); 3398 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, 3399 WLAN_EID_SSID); 3400 if (ssid_ie && 3401 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) 3402 goto nla_put_failure_rcu_locked; 3403 rcu_read_unlock(); 3404 break; 3405 } 3406 default: 3407 /* nothing */ 3408 break; 3409 } 3410 wdev_unlock(wdev); 3411 3412 if (rdev->ops->get_txq_stats) { 3413 struct cfg80211_txq_stats txqstats = {}; 3414 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); 3415 3416 if (ret == 0 && 3417 !nl80211_put_txq_stats(msg, &txqstats, 3418 NL80211_ATTR_TXQ_STATS)) 3419 goto nla_put_failure; 3420 } 3421 3422 genlmsg_end(msg, hdr); 3423 return 0; 3424 3425 nla_put_failure_rcu_locked: 3426 rcu_read_unlock(); 3427 nla_put_failure_locked: 3428 wdev_unlock(wdev); 3429 nla_put_failure: 3430 genlmsg_cancel(msg, hdr); 3431 return -EMSGSIZE; 3432 } 3433 3434 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) 3435 { 3436 int wp_idx = 0; 3437 int if_idx = 0; 3438 int wp_start = cb->args[0]; 3439 int if_start = cb->args[1]; 3440 int filter_wiphy = -1; 3441 struct cfg80211_registered_device *rdev; 3442 struct wireless_dev *wdev; 3443 int ret; 3444 3445 rtnl_lock(); 3446 if (!cb->args[2]) { 3447 struct nl80211_dump_wiphy_state state = { 3448 .filter_wiphy = -1, 3449 }; 3450 3451 ret = nl80211_dump_wiphy_parse(skb, cb, &state); 3452 if (ret) 3453 goto out_unlock; 3454 3455 filter_wiphy = state.filter_wiphy; 3456 3457 /* 3458 * if filtering, set cb->args[2] to +1 since 0 is the default 3459 * value needed to determine that parsing is necessary. 3460 */ 3461 if (filter_wiphy >= 0) 3462 cb->args[2] = filter_wiphy + 1; 3463 else 3464 cb->args[2] = -1; 3465 } else if (cb->args[2] > 0) { 3466 filter_wiphy = cb->args[2] - 1; 3467 } 3468 3469 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3470 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3471 continue; 3472 if (wp_idx < wp_start) { 3473 wp_idx++; 3474 continue; 3475 } 3476 3477 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) 3478 continue; 3479 3480 if_idx = 0; 3481 3482 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 3483 if (if_idx < if_start) { 3484 if_idx++; 3485 continue; 3486 } 3487 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 3488 cb->nlh->nlmsg_seq, NLM_F_MULTI, 3489 rdev, wdev, 3490 NL80211_CMD_NEW_INTERFACE) < 0) { 3491 goto out; 3492 } 3493 if_idx++; 3494 } 3495 3496 wp_idx++; 3497 } 3498 out: 3499 cb->args[0] = wp_idx; 3500 cb->args[1] = if_idx; 3501 3502 ret = skb->len; 3503 out_unlock: 3504 rtnl_unlock(); 3505 3506 return ret; 3507 } 3508 3509 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 3510 { 3511 struct sk_buff *msg; 3512 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3513 struct wireless_dev *wdev = info->user_ptr[1]; 3514 3515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3516 if (!msg) 3517 return -ENOMEM; 3518 3519 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 3520 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 3521 nlmsg_free(msg); 3522 return -ENOBUFS; 3523 } 3524 3525 return genlmsg_reply(msg, info); 3526 } 3527 3528 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 3529 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, 3530 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, 3531 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, 3532 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, 3533 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, 3534 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, 3535 }; 3536 3537 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) 3538 { 3539 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; 3540 int flag; 3541 3542 *mntrflags = 0; 3543 3544 if (!nla) 3545 return -EINVAL; 3546 3547 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) 3548 return -EINVAL; 3549 3550 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 3551 if (flags[flag]) 3552 *mntrflags |= (1<<flag); 3553 3554 *mntrflags |= MONITOR_FLAG_CHANGED; 3555 3556 return 0; 3557 } 3558 3559 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, 3560 enum nl80211_iftype type, 3561 struct genl_info *info, 3562 struct vif_params *params) 3563 { 3564 bool change = false; 3565 int err; 3566 3567 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 3568 if (type != NL80211_IFTYPE_MONITOR) 3569 return -EINVAL; 3570 3571 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 3572 ¶ms->flags); 3573 if (err) 3574 return err; 3575 3576 change = true; 3577 } 3578 3579 if (params->flags & MONITOR_FLAG_ACTIVE && 3580 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 3581 return -EOPNOTSUPP; 3582 3583 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { 3584 const u8 *mumimo_groups; 3585 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 3586 3587 if (type != NL80211_IFTYPE_MONITOR) 3588 return -EINVAL; 3589 3590 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 3591 return -EOPNOTSUPP; 3592 3593 mumimo_groups = 3594 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); 3595 3596 /* bits 0 and 63 are reserved and must be zero */ 3597 if ((mumimo_groups[0] & BIT(0)) || 3598 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) 3599 return -EINVAL; 3600 3601 params->vht_mumimo_groups = mumimo_groups; 3602 change = true; 3603 } 3604 3605 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { 3606 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 3607 3608 if (type != NL80211_IFTYPE_MONITOR) 3609 return -EINVAL; 3610 3611 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 3612 return -EOPNOTSUPP; 3613 3614 params->vht_mumimo_follow_addr = 3615 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); 3616 change = true; 3617 } 3618 3619 return change ? 1 : 0; 3620 } 3621 3622 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, 3623 struct net_device *netdev, u8 use_4addr, 3624 enum nl80211_iftype iftype) 3625 { 3626 if (!use_4addr) { 3627 if (netdev && netif_is_bridge_port(netdev)) 3628 return -EBUSY; 3629 return 0; 3630 } 3631 3632 switch (iftype) { 3633 case NL80211_IFTYPE_AP_VLAN: 3634 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) 3635 return 0; 3636 break; 3637 case NL80211_IFTYPE_STATION: 3638 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) 3639 return 0; 3640 break; 3641 default: 3642 break; 3643 } 3644 3645 return -EOPNOTSUPP; 3646 } 3647 3648 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 3649 { 3650 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3651 struct vif_params params; 3652 int err; 3653 enum nl80211_iftype otype, ntype; 3654 struct net_device *dev = info->user_ptr[1]; 3655 bool change = false; 3656 3657 memset(¶ms, 0, sizeof(params)); 3658 3659 otype = ntype = dev->ieee80211_ptr->iftype; 3660 3661 if (info->attrs[NL80211_ATTR_IFTYPE]) { 3662 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 3663 if (otype != ntype) 3664 change = true; 3665 } 3666 3667 if (info->attrs[NL80211_ATTR_MESH_ID]) { 3668 struct wireless_dev *wdev = dev->ieee80211_ptr; 3669 3670 if (ntype != NL80211_IFTYPE_MESH_POINT) 3671 return -EINVAL; 3672 if (netif_running(dev)) 3673 return -EBUSY; 3674 3675 wdev_lock(wdev); 3676 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 3677 IEEE80211_MAX_MESH_ID_LEN); 3678 wdev->mesh_id_up_len = 3679 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 3680 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 3681 wdev->mesh_id_up_len); 3682 wdev_unlock(wdev); 3683 } 3684 3685 if (info->attrs[NL80211_ATTR_4ADDR]) { 3686 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 3687 change = true; 3688 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 3689 if (err) 3690 return err; 3691 } else { 3692 params.use_4addr = -1; 3693 } 3694 3695 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); 3696 if (err < 0) 3697 return err; 3698 if (err > 0) 3699 change = true; 3700 3701 if (change) 3702 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); 3703 else 3704 err = 0; 3705 3706 if (!err && params.use_4addr != -1) 3707 dev->ieee80211_ptr->use_4addr = params.use_4addr; 3708 3709 if (change && !err) { 3710 struct wireless_dev *wdev = dev->ieee80211_ptr; 3711 3712 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); 3713 } 3714 3715 return err; 3716 } 3717 3718 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 3719 { 3720 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3721 struct vif_params params; 3722 struct wireless_dev *wdev; 3723 struct sk_buff *msg; 3724 int err; 3725 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 3726 3727 /* to avoid failing a new interface creation due to pending removal */ 3728 cfg80211_destroy_ifaces(rdev); 3729 3730 memset(¶ms, 0, sizeof(params)); 3731 3732 if (!info->attrs[NL80211_ATTR_IFNAME]) 3733 return -EINVAL; 3734 3735 if (info->attrs[NL80211_ATTR_IFTYPE]) 3736 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 3737 3738 if (!rdev->ops->add_virtual_intf) 3739 return -EOPNOTSUPP; 3740 3741 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || 3742 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && 3743 info->attrs[NL80211_ATTR_MAC]) { 3744 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 3745 ETH_ALEN); 3746 if (!is_valid_ether_addr(params.macaddr)) 3747 return -EADDRNOTAVAIL; 3748 } 3749 3750 if (info->attrs[NL80211_ATTR_4ADDR]) { 3751 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 3752 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 3753 if (err) 3754 return err; 3755 } 3756 3757 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) 3758 return -EOPNOTSUPP; 3759 3760 err = nl80211_parse_mon_options(rdev, type, info, ¶ms); 3761 if (err < 0) 3762 return err; 3763 3764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3765 if (!msg) 3766 return -ENOMEM; 3767 3768 wdev = rdev_add_virtual_intf(rdev, 3769 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 3770 NET_NAME_USER, type, ¶ms); 3771 if (WARN_ON(!wdev)) { 3772 nlmsg_free(msg); 3773 return -EPROTO; 3774 } else if (IS_ERR(wdev)) { 3775 nlmsg_free(msg); 3776 return PTR_ERR(wdev); 3777 } 3778 3779 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 3780 wdev->owner_nlportid = info->snd_portid; 3781 3782 switch (type) { 3783 case NL80211_IFTYPE_MESH_POINT: 3784 if (!info->attrs[NL80211_ATTR_MESH_ID]) 3785 break; 3786 wdev_lock(wdev); 3787 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 3788 IEEE80211_MAX_MESH_ID_LEN); 3789 wdev->mesh_id_up_len = 3790 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 3791 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 3792 wdev->mesh_id_up_len); 3793 wdev_unlock(wdev); 3794 break; 3795 case NL80211_IFTYPE_NAN: 3796 case NL80211_IFTYPE_P2P_DEVICE: 3797 /* 3798 * P2P Device and NAN do not have a netdev, so don't go 3799 * through the netdev notifier and must be added here 3800 */ 3801 cfg80211_init_wdev(rdev, wdev); 3802 break; 3803 default: 3804 break; 3805 } 3806 3807 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 3808 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 3809 nlmsg_free(msg); 3810 return -ENOBUFS; 3811 } 3812 3813 return genlmsg_reply(msg, info); 3814 } 3815 3816 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 3817 { 3818 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3819 struct wireless_dev *wdev = info->user_ptr[1]; 3820 3821 if (!rdev->ops->del_virtual_intf) 3822 return -EOPNOTSUPP; 3823 3824 /* 3825 * If we remove a wireless device without a netdev then clear 3826 * user_ptr[1] so that nl80211_post_doit won't dereference it 3827 * to check if it needs to do dev_put(). Otherwise it crashes 3828 * since the wdev has been freed, unlike with a netdev where 3829 * we need the dev_put() for the netdev to really be freed. 3830 */ 3831 if (!wdev->netdev) 3832 info->user_ptr[1] = NULL; 3833 3834 return rdev_del_virtual_intf(rdev, wdev); 3835 } 3836 3837 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) 3838 { 3839 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3840 struct net_device *dev = info->user_ptr[1]; 3841 u16 noack_map; 3842 3843 if (!info->attrs[NL80211_ATTR_NOACK_MAP]) 3844 return -EINVAL; 3845 3846 if (!rdev->ops->set_noack_map) 3847 return -EOPNOTSUPP; 3848 3849 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); 3850 3851 return rdev_set_noack_map(rdev, dev, noack_map); 3852 } 3853 3854 struct get_key_cookie { 3855 struct sk_buff *msg; 3856 int error; 3857 int idx; 3858 }; 3859 3860 static void get_key_callback(void *c, struct key_params *params) 3861 { 3862 struct nlattr *key; 3863 struct get_key_cookie *cookie = c; 3864 3865 if ((params->key && 3866 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, 3867 params->key_len, params->key)) || 3868 (params->seq && 3869 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, 3870 params->seq_len, params->seq)) || 3871 (params->cipher && 3872 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, 3873 params->cipher))) 3874 goto nla_put_failure; 3875 3876 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); 3877 if (!key) 3878 goto nla_put_failure; 3879 3880 if ((params->key && 3881 nla_put(cookie->msg, NL80211_KEY_DATA, 3882 params->key_len, params->key)) || 3883 (params->seq && 3884 nla_put(cookie->msg, NL80211_KEY_SEQ, 3885 params->seq_len, params->seq)) || 3886 (params->cipher && 3887 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, 3888 params->cipher))) 3889 goto nla_put_failure; 3890 3891 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) 3892 goto nla_put_failure; 3893 3894 nla_nest_end(cookie->msg, key); 3895 3896 return; 3897 nla_put_failure: 3898 cookie->error = 1; 3899 } 3900 3901 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 3902 { 3903 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3904 int err; 3905 struct net_device *dev = info->user_ptr[1]; 3906 u8 key_idx = 0; 3907 const u8 *mac_addr = NULL; 3908 bool pairwise; 3909 struct get_key_cookie cookie = { 3910 .error = 0, 3911 }; 3912 void *hdr; 3913 struct sk_buff *msg; 3914 bool bigtk_support = false; 3915 3916 if (wiphy_ext_feature_isset(&rdev->wiphy, 3917 NL80211_EXT_FEATURE_BEACON_PROTECTION)) 3918 bigtk_support = true; 3919 3920 if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || 3921 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && 3922 wiphy_ext_feature_isset(&rdev->wiphy, 3923 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) 3924 bigtk_support = true; 3925 3926 if (info->attrs[NL80211_ATTR_KEY_IDX]) { 3927 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 3928 3929 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { 3930 GENL_SET_ERR_MSG(info, "BIGTK not supported"); 3931 return -EINVAL; 3932 } 3933 } 3934 3935 if (info->attrs[NL80211_ATTR_MAC]) 3936 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3937 3938 pairwise = !!mac_addr; 3939 if (info->attrs[NL80211_ATTR_KEY_TYPE]) { 3940 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 3941 3942 if (kt != NL80211_KEYTYPE_GROUP && 3943 kt != NL80211_KEYTYPE_PAIRWISE) 3944 return -EINVAL; 3945 pairwise = kt == NL80211_KEYTYPE_PAIRWISE; 3946 } 3947 3948 if (!rdev->ops->get_key) 3949 return -EOPNOTSUPP; 3950 3951 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 3952 return -ENOENT; 3953 3954 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3955 if (!msg) 3956 return -ENOMEM; 3957 3958 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 3959 NL80211_CMD_NEW_KEY); 3960 if (!hdr) 3961 goto nla_put_failure; 3962 3963 cookie.msg = msg; 3964 cookie.idx = key_idx; 3965 3966 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3967 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) 3968 goto nla_put_failure; 3969 if (mac_addr && 3970 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) 3971 goto nla_put_failure; 3972 3973 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, 3974 get_key_callback); 3975 3976 if (err) 3977 goto free_msg; 3978 3979 if (cookie.error) 3980 goto nla_put_failure; 3981 3982 genlmsg_end(msg, hdr); 3983 return genlmsg_reply(msg, info); 3984 3985 nla_put_failure: 3986 err = -ENOBUFS; 3987 free_msg: 3988 nlmsg_free(msg); 3989 return err; 3990 } 3991 3992 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 3993 { 3994 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3995 struct key_parse key; 3996 int err; 3997 struct net_device *dev = info->user_ptr[1]; 3998 3999 err = nl80211_parse_key(info, &key); 4000 if (err) 4001 return err; 4002 4003 if (key.idx < 0) 4004 return -EINVAL; 4005 4006 /* Only support setting default key and 4007 * Extended Key ID action NL80211_KEY_SET_TX. 4008 */ 4009 if (!key.def && !key.defmgmt && !key.defbeacon && 4010 !(key.p.mode == NL80211_KEY_SET_TX)) 4011 return -EINVAL; 4012 4013 wdev_lock(dev->ieee80211_ptr); 4014 4015 if (key.def) { 4016 if (!rdev->ops->set_default_key) { 4017 err = -EOPNOTSUPP; 4018 goto out; 4019 } 4020 4021 err = nl80211_key_allowed(dev->ieee80211_ptr); 4022 if (err) 4023 goto out; 4024 4025 err = rdev_set_default_key(rdev, dev, key.idx, 4026 key.def_uni, key.def_multi); 4027 4028 if (err) 4029 goto out; 4030 4031 #ifdef CONFIG_CFG80211_WEXT 4032 dev->ieee80211_ptr->wext.default_key = key.idx; 4033 #endif 4034 } else if (key.defmgmt) { 4035 if (key.def_uni || !key.def_multi) { 4036 err = -EINVAL; 4037 goto out; 4038 } 4039 4040 if (!rdev->ops->set_default_mgmt_key) { 4041 err = -EOPNOTSUPP; 4042 goto out; 4043 } 4044 4045 err = nl80211_key_allowed(dev->ieee80211_ptr); 4046 if (err) 4047 goto out; 4048 4049 err = rdev_set_default_mgmt_key(rdev, dev, key.idx); 4050 if (err) 4051 goto out; 4052 4053 #ifdef CONFIG_CFG80211_WEXT 4054 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; 4055 #endif 4056 } else if (key.defbeacon) { 4057 if (key.def_uni || !key.def_multi) { 4058 err = -EINVAL; 4059 goto out; 4060 } 4061 4062 if (!rdev->ops->set_default_beacon_key) { 4063 err = -EOPNOTSUPP; 4064 goto out; 4065 } 4066 4067 err = nl80211_key_allowed(dev->ieee80211_ptr); 4068 if (err) 4069 goto out; 4070 4071 err = rdev_set_default_beacon_key(rdev, dev, key.idx); 4072 if (err) 4073 goto out; 4074 } else if (key.p.mode == NL80211_KEY_SET_TX && 4075 wiphy_ext_feature_isset(&rdev->wiphy, 4076 NL80211_EXT_FEATURE_EXT_KEY_ID)) { 4077 u8 *mac_addr = NULL; 4078 4079 if (info->attrs[NL80211_ATTR_MAC]) 4080 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4081 4082 if (!mac_addr || key.idx < 0 || key.idx > 1) { 4083 err = -EINVAL; 4084 goto out; 4085 } 4086 4087 err = rdev_add_key(rdev, dev, key.idx, 4088 NL80211_KEYTYPE_PAIRWISE, 4089 mac_addr, &key.p); 4090 } else { 4091 err = -EINVAL; 4092 } 4093 out: 4094 wdev_unlock(dev->ieee80211_ptr); 4095 4096 return err; 4097 } 4098 4099 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 4100 { 4101 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4102 int err; 4103 struct net_device *dev = info->user_ptr[1]; 4104 struct key_parse key; 4105 const u8 *mac_addr = NULL; 4106 4107 err = nl80211_parse_key(info, &key); 4108 if (err) 4109 return err; 4110 4111 if (!key.p.key) { 4112 GENL_SET_ERR_MSG(info, "no key"); 4113 return -EINVAL; 4114 } 4115 4116 if (info->attrs[NL80211_ATTR_MAC]) 4117 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4118 4119 if (key.type == -1) { 4120 if (mac_addr) 4121 key.type = NL80211_KEYTYPE_PAIRWISE; 4122 else 4123 key.type = NL80211_KEYTYPE_GROUP; 4124 } 4125 4126 /* for now */ 4127 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4128 key.type != NL80211_KEYTYPE_GROUP) { 4129 GENL_SET_ERR_MSG(info, "key type not pairwise or group"); 4130 return -EINVAL; 4131 } 4132 4133 if (key.type == NL80211_KEYTYPE_GROUP && 4134 info->attrs[NL80211_ATTR_VLAN_ID]) 4135 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 4136 4137 if (!rdev->ops->add_key) 4138 return -EOPNOTSUPP; 4139 4140 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, 4141 key.type == NL80211_KEYTYPE_PAIRWISE, 4142 mac_addr)) { 4143 GENL_SET_ERR_MSG(info, "key setting validation failed"); 4144 return -EINVAL; 4145 } 4146 4147 wdev_lock(dev->ieee80211_ptr); 4148 err = nl80211_key_allowed(dev->ieee80211_ptr); 4149 if (err) 4150 GENL_SET_ERR_MSG(info, "key not allowed"); 4151 if (!err) { 4152 err = rdev_add_key(rdev, dev, key.idx, 4153 key.type == NL80211_KEYTYPE_PAIRWISE, 4154 mac_addr, &key.p); 4155 if (err) 4156 GENL_SET_ERR_MSG(info, "key addition failed"); 4157 } 4158 wdev_unlock(dev->ieee80211_ptr); 4159 4160 return err; 4161 } 4162 4163 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 4164 { 4165 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4166 int err; 4167 struct net_device *dev = info->user_ptr[1]; 4168 u8 *mac_addr = NULL; 4169 struct key_parse key; 4170 4171 err = nl80211_parse_key(info, &key); 4172 if (err) 4173 return err; 4174 4175 if (key.idx < 0) 4176 return -EINVAL; 4177 4178 if (info->attrs[NL80211_ATTR_MAC]) 4179 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4180 4181 if (key.type == -1) { 4182 if (mac_addr) 4183 key.type = NL80211_KEYTYPE_PAIRWISE; 4184 else 4185 key.type = NL80211_KEYTYPE_GROUP; 4186 } 4187 4188 /* for now */ 4189 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4190 key.type != NL80211_KEYTYPE_GROUP) 4191 return -EINVAL; 4192 4193 if (!rdev->ops->del_key) 4194 return -EOPNOTSUPP; 4195 4196 wdev_lock(dev->ieee80211_ptr); 4197 err = nl80211_key_allowed(dev->ieee80211_ptr); 4198 4199 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && 4200 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4201 err = -ENOENT; 4202 4203 if (!err) 4204 err = rdev_del_key(rdev, dev, key.idx, 4205 key.type == NL80211_KEYTYPE_PAIRWISE, 4206 mac_addr); 4207 4208 #ifdef CONFIG_CFG80211_WEXT 4209 if (!err) { 4210 if (key.idx == dev->ieee80211_ptr->wext.default_key) 4211 dev->ieee80211_ptr->wext.default_key = -1; 4212 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) 4213 dev->ieee80211_ptr->wext.default_mgmt_key = -1; 4214 } 4215 #endif 4216 wdev_unlock(dev->ieee80211_ptr); 4217 4218 return err; 4219 } 4220 4221 /* This function returns an error or the number of nested attributes */ 4222 static int validate_acl_mac_addrs(struct nlattr *nl_attr) 4223 { 4224 struct nlattr *attr; 4225 int n_entries = 0, tmp; 4226 4227 nla_for_each_nested(attr, nl_attr, tmp) { 4228 if (nla_len(attr) != ETH_ALEN) 4229 return -EINVAL; 4230 4231 n_entries++; 4232 } 4233 4234 return n_entries; 4235 } 4236 4237 /* 4238 * This function parses ACL information and allocates memory for ACL data. 4239 * On successful return, the calling function is responsible to free the 4240 * ACL buffer returned by this function. 4241 */ 4242 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, 4243 struct genl_info *info) 4244 { 4245 enum nl80211_acl_policy acl_policy; 4246 struct nlattr *attr; 4247 struct cfg80211_acl_data *acl; 4248 int i = 0, n_entries, tmp; 4249 4250 if (!wiphy->max_acl_mac_addrs) 4251 return ERR_PTR(-EOPNOTSUPP); 4252 4253 if (!info->attrs[NL80211_ATTR_ACL_POLICY]) 4254 return ERR_PTR(-EINVAL); 4255 4256 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); 4257 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && 4258 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) 4259 return ERR_PTR(-EINVAL); 4260 4261 if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) 4262 return ERR_PTR(-EINVAL); 4263 4264 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); 4265 if (n_entries < 0) 4266 return ERR_PTR(n_entries); 4267 4268 if (n_entries > wiphy->max_acl_mac_addrs) 4269 return ERR_PTR(-ENOTSUPP); 4270 4271 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); 4272 if (!acl) 4273 return ERR_PTR(-ENOMEM); 4274 4275 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { 4276 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); 4277 i++; 4278 } 4279 4280 acl->n_acl_entries = n_entries; 4281 acl->acl_policy = acl_policy; 4282 4283 return acl; 4284 } 4285 4286 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) 4287 { 4288 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4289 struct net_device *dev = info->user_ptr[1]; 4290 struct cfg80211_acl_data *acl; 4291 int err; 4292 4293 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4295 return -EOPNOTSUPP; 4296 4297 if (!dev->ieee80211_ptr->beacon_interval) 4298 return -EINVAL; 4299 4300 acl = parse_acl_data(&rdev->wiphy, info); 4301 if (IS_ERR(acl)) 4302 return PTR_ERR(acl); 4303 4304 err = rdev_set_mac_acl(rdev, dev, acl); 4305 4306 kfree(acl); 4307 4308 return err; 4309 } 4310 4311 static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 4312 u8 *rates, u8 rates_len) 4313 { 4314 u8 i; 4315 u32 mask = 0; 4316 4317 for (i = 0; i < rates_len; i++) { 4318 int rate = (rates[i] & 0x7f) * 5; 4319 int ridx; 4320 4321 for (ridx = 0; ridx < sband->n_bitrates; ridx++) { 4322 struct ieee80211_rate *srate = 4323 &sband->bitrates[ridx]; 4324 if (rate == srate->bitrate) { 4325 mask |= 1 << ridx; 4326 break; 4327 } 4328 } 4329 if (ridx == sband->n_bitrates) 4330 return 0; /* rate not found */ 4331 } 4332 4333 return mask; 4334 } 4335 4336 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, 4337 u8 *rates, u8 rates_len, 4338 u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) 4339 { 4340 u8 i; 4341 4342 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); 4343 4344 for (i = 0; i < rates_len; i++) { 4345 int ridx, rbit; 4346 4347 ridx = rates[i] / 8; 4348 rbit = BIT(rates[i] % 8); 4349 4350 /* check validity */ 4351 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) 4352 return false; 4353 4354 /* check availability */ 4355 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); 4356 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) 4357 mcs[ridx] |= rbit; 4358 else 4359 return false; 4360 } 4361 4362 return true; 4363 } 4364 4365 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) 4366 { 4367 u16 mcs_mask = 0; 4368 4369 switch (vht_mcs_map) { 4370 case IEEE80211_VHT_MCS_NOT_SUPPORTED: 4371 break; 4372 case IEEE80211_VHT_MCS_SUPPORT_0_7: 4373 mcs_mask = 0x00FF; 4374 break; 4375 case IEEE80211_VHT_MCS_SUPPORT_0_8: 4376 mcs_mask = 0x01FF; 4377 break; 4378 case IEEE80211_VHT_MCS_SUPPORT_0_9: 4379 mcs_mask = 0x03FF; 4380 break; 4381 default: 4382 break; 4383 } 4384 4385 return mcs_mask; 4386 } 4387 4388 static void vht_build_mcs_mask(u16 vht_mcs_map, 4389 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) 4390 { 4391 u8 nss; 4392 4393 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 4394 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); 4395 vht_mcs_map >>= 2; 4396 } 4397 } 4398 4399 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, 4400 struct nl80211_txrate_vht *txrate, 4401 u16 mcs[NL80211_VHT_NSS_MAX]) 4402 { 4403 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4404 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; 4405 u8 i; 4406 4407 if (!sband->vht_cap.vht_supported) 4408 return false; 4409 4410 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); 4411 4412 /* Build vht_mcs_mask from VHT capabilities */ 4413 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 4414 4415 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4416 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 4417 mcs[i] = txrate->mcs[i]; 4418 else 4419 return false; 4420 } 4421 4422 return true; 4423 } 4424 4425 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, 4426 struct nlattr *attrs[], 4427 enum nl80211_attrs attr, 4428 struct cfg80211_bitrate_mask *mask) 4429 { 4430 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 4431 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4432 int rem, i; 4433 struct nlattr *tx_rates; 4434 struct ieee80211_supported_band *sband; 4435 u16 vht_tx_mcs_map; 4436 4437 memset(mask, 0, sizeof(*mask)); 4438 /* Default to all rates enabled */ 4439 for (i = 0; i < NUM_NL80211_BANDS; i++) { 4440 sband = rdev->wiphy.bands[i]; 4441 4442 if (!sband) 4443 continue; 4444 4445 mask->control[i].legacy = (1 << sband->n_bitrates) - 1; 4446 memcpy(mask->control[i].ht_mcs, 4447 sband->ht_cap.mcs.rx_mask, 4448 sizeof(mask->control[i].ht_mcs)); 4449 4450 if (!sband->vht_cap.vht_supported) 4451 continue; 4452 4453 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4454 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); 4455 } 4456 4457 /* if no rates are given set it back to the defaults */ 4458 if (!attrs[attr]) 4459 goto out; 4460 4461 /* The nested attribute uses enum nl80211_band as the index. This maps 4462 * directly to the enum nl80211_band values used in cfg80211. 4463 */ 4464 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); 4465 nla_for_each_nested(tx_rates, attrs[attr], rem) { 4466 enum nl80211_band band = nla_type(tx_rates); 4467 int err; 4468 4469 if (band < 0 || band >= NUM_NL80211_BANDS) 4470 return -EINVAL; 4471 sband = rdev->wiphy.bands[band]; 4472 if (sband == NULL) 4473 return -EINVAL; 4474 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, 4475 tx_rates, 4476 nl80211_txattr_policy, 4477 info->extack); 4478 if (err) 4479 return err; 4480 if (tb[NL80211_TXRATE_LEGACY]) { 4481 mask->control[band].legacy = rateset_to_mask( 4482 sband, 4483 nla_data(tb[NL80211_TXRATE_LEGACY]), 4484 nla_len(tb[NL80211_TXRATE_LEGACY])); 4485 if ((mask->control[band].legacy == 0) && 4486 nla_len(tb[NL80211_TXRATE_LEGACY])) 4487 return -EINVAL; 4488 } 4489 if (tb[NL80211_TXRATE_HT]) { 4490 if (!ht_rateset_to_mask( 4491 sband, 4492 nla_data(tb[NL80211_TXRATE_HT]), 4493 nla_len(tb[NL80211_TXRATE_HT]), 4494 mask->control[band].ht_mcs)) 4495 return -EINVAL; 4496 } 4497 if (tb[NL80211_TXRATE_VHT]) { 4498 if (!vht_set_mcs_mask( 4499 sband, 4500 nla_data(tb[NL80211_TXRATE_VHT]), 4501 mask->control[band].vht_mcs)) 4502 return -EINVAL; 4503 } 4504 if (tb[NL80211_TXRATE_GI]) { 4505 mask->control[band].gi = 4506 nla_get_u8(tb[NL80211_TXRATE_GI]); 4507 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) 4508 return -EINVAL; 4509 } 4510 4511 if (mask->control[band].legacy == 0) { 4512 /* don't allow empty legacy rates if HT or VHT 4513 * are not even supported. 4514 */ 4515 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || 4516 rdev->wiphy.bands[band]->vht_cap.vht_supported)) 4517 return -EINVAL; 4518 4519 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) 4520 if (mask->control[band].ht_mcs[i]) 4521 goto out; 4522 4523 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) 4524 if (mask->control[band].vht_mcs[i]) 4525 goto out; 4526 4527 /* legacy and mcs rates may not be both empty */ 4528 return -EINVAL; 4529 } 4530 } 4531 4532 out: 4533 return 0; 4534 } 4535 4536 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, 4537 enum nl80211_band band, 4538 struct cfg80211_bitrate_mask *beacon_rate) 4539 { 4540 u32 count_ht, count_vht, i; 4541 u32 rate = beacon_rate->control[band].legacy; 4542 4543 /* Allow only one rate */ 4544 if (hweight32(rate) > 1) 4545 return -EINVAL; 4546 4547 count_ht = 0; 4548 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 4549 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { 4550 return -EINVAL; 4551 } else if (beacon_rate->control[band].ht_mcs[i]) { 4552 count_ht++; 4553 if (count_ht > 1) 4554 return -EINVAL; 4555 } 4556 if (count_ht && rate) 4557 return -EINVAL; 4558 } 4559 4560 count_vht = 0; 4561 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4562 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { 4563 return -EINVAL; 4564 } else if (beacon_rate->control[band].vht_mcs[i]) { 4565 count_vht++; 4566 if (count_vht > 1) 4567 return -EINVAL; 4568 } 4569 if (count_vht && rate) 4570 return -EINVAL; 4571 } 4572 4573 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) 4574 return -EINVAL; 4575 4576 if (rate && 4577 !wiphy_ext_feature_isset(&rdev->wiphy, 4578 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 4579 return -EINVAL; 4580 if (count_ht && 4581 !wiphy_ext_feature_isset(&rdev->wiphy, 4582 NL80211_EXT_FEATURE_BEACON_RATE_HT)) 4583 return -EINVAL; 4584 if (count_vht && 4585 !wiphy_ext_feature_isset(&rdev->wiphy, 4586 NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 4587 return -EINVAL; 4588 4589 return 0; 4590 } 4591 4592 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, 4593 struct nlattr *attrs[], 4594 struct cfg80211_beacon_data *bcn) 4595 { 4596 bool haveinfo = false; 4597 int err; 4598 4599 memset(bcn, 0, sizeof(*bcn)); 4600 4601 if (attrs[NL80211_ATTR_BEACON_HEAD]) { 4602 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); 4603 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); 4604 if (!bcn->head_len) 4605 return -EINVAL; 4606 haveinfo = true; 4607 } 4608 4609 if (attrs[NL80211_ATTR_BEACON_TAIL]) { 4610 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); 4611 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); 4612 haveinfo = true; 4613 } 4614 4615 if (!haveinfo) 4616 return -EINVAL; 4617 4618 if (attrs[NL80211_ATTR_IE]) { 4619 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); 4620 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); 4621 } 4622 4623 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { 4624 bcn->proberesp_ies = 4625 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); 4626 bcn->proberesp_ies_len = 4627 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); 4628 } 4629 4630 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { 4631 bcn->assocresp_ies = 4632 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 4633 bcn->assocresp_ies_len = 4634 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 4635 } 4636 4637 if (attrs[NL80211_ATTR_PROBE_RESP]) { 4638 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); 4639 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); 4640 } 4641 4642 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 4643 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 4644 4645 err = nla_parse_nested_deprecated(tb, 4646 NL80211_FTM_RESP_ATTR_MAX, 4647 attrs[NL80211_ATTR_FTM_RESPONDER], 4648 NULL, NULL); 4649 if (err) 4650 return err; 4651 4652 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && 4653 wiphy_ext_feature_isset(&rdev->wiphy, 4654 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 4655 bcn->ftm_responder = 1; 4656 else 4657 return -EOPNOTSUPP; 4658 4659 if (tb[NL80211_FTM_RESP_ATTR_LCI]) { 4660 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); 4661 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); 4662 } 4663 4664 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { 4665 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 4666 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 4667 } 4668 } else { 4669 bcn->ftm_responder = -1; 4670 } 4671 4672 return 0; 4673 } 4674 4675 static int nl80211_parse_he_obss_pd(struct nlattr *attrs, 4676 struct ieee80211_he_obss_pd *he_obss_pd) 4677 { 4678 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; 4679 int err; 4680 4681 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, 4682 he_obss_pd_policy, NULL); 4683 if (err) 4684 return err; 4685 4686 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] || 4687 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) 4688 return -EINVAL; 4689 4690 he_obss_pd->min_offset = 4691 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); 4692 he_obss_pd->max_offset = 4693 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); 4694 4695 if (he_obss_pd->min_offset >= he_obss_pd->max_offset) 4696 return -EINVAL; 4697 4698 he_obss_pd->enable = true; 4699 4700 return 0; 4701 } 4702 4703 static int nl80211_parse_he_bss_color(struct nlattr *attrs, 4704 struct cfg80211_he_bss_color *he_bss_color) 4705 { 4706 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; 4707 int err; 4708 4709 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, 4710 he_bss_color_policy, NULL); 4711 if (err) 4712 return err; 4713 4714 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) 4715 return -EINVAL; 4716 4717 he_bss_color->color = 4718 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); 4719 he_bss_color->enabled = 4720 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); 4721 he_bss_color->partial = 4722 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); 4723 4724 return 0; 4725 } 4726 4727 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, 4728 const u8 *rates) 4729 { 4730 int i; 4731 4732 if (!rates) 4733 return; 4734 4735 for (i = 0; i < rates[1]; i++) { 4736 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 4737 params->ht_required = true; 4738 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) 4739 params->vht_required = true; 4740 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) 4741 params->he_required = true; 4742 } 4743 } 4744 4745 /* 4746 * Since the nl80211 API didn't include, from the beginning, attributes about 4747 * HT/VHT requirements/capabilities, we parse them out of the IEs for the 4748 * benefit of drivers that rebuild IEs in the firmware. 4749 */ 4750 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) 4751 { 4752 const struct cfg80211_beacon_data *bcn = ¶ms->beacon; 4753 size_t ies_len = bcn->tail_len; 4754 const u8 *ies = bcn->tail; 4755 const u8 *rates; 4756 const u8 *cap; 4757 4758 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); 4759 nl80211_check_ap_rate_selectors(params, rates); 4760 4761 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); 4762 nl80211_check_ap_rate_selectors(params, rates); 4763 4764 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); 4765 if (cap && cap[1] >= sizeof(*params->ht_cap)) 4766 params->ht_cap = (void *)(cap + 2); 4767 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); 4768 if (cap && cap[1] >= sizeof(*params->vht_cap)) 4769 params->vht_cap = (void *)(cap + 2); 4770 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); 4771 if (cap && cap[1] >= sizeof(*params->he_cap) + 1) 4772 params->he_cap = (void *)(cap + 3); 4773 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); 4774 if (cap && cap[1] >= sizeof(*params->he_oper) + 1) 4775 params->he_oper = (void *)(cap + 3); 4776 } 4777 4778 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, 4779 struct cfg80211_ap_settings *params) 4780 { 4781 struct wireless_dev *wdev; 4782 bool ret = false; 4783 4784 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 4785 if (wdev->iftype != NL80211_IFTYPE_AP && 4786 wdev->iftype != NL80211_IFTYPE_P2P_GO) 4787 continue; 4788 4789 if (!wdev->preset_chandef.chan) 4790 continue; 4791 4792 params->chandef = wdev->preset_chandef; 4793 ret = true; 4794 break; 4795 } 4796 4797 return ret; 4798 } 4799 4800 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, 4801 enum nl80211_auth_type auth_type, 4802 enum nl80211_commands cmd) 4803 { 4804 if (auth_type > NL80211_AUTHTYPE_MAX) 4805 return false; 4806 4807 switch (cmd) { 4808 case NL80211_CMD_AUTHENTICATE: 4809 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 4810 auth_type == NL80211_AUTHTYPE_SAE) 4811 return false; 4812 if (!wiphy_ext_feature_isset(&rdev->wiphy, 4813 NL80211_EXT_FEATURE_FILS_STA) && 4814 (auth_type == NL80211_AUTHTYPE_FILS_SK || 4815 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 4816 auth_type == NL80211_AUTHTYPE_FILS_PK)) 4817 return false; 4818 return true; 4819 case NL80211_CMD_CONNECT: 4820 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 4821 !wiphy_ext_feature_isset(&rdev->wiphy, 4822 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 4823 auth_type == NL80211_AUTHTYPE_SAE) 4824 return false; 4825 4826 /* FILS with SK PFS or PK not supported yet */ 4827 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 4828 auth_type == NL80211_AUTHTYPE_FILS_PK) 4829 return false; 4830 if (!wiphy_ext_feature_isset( 4831 &rdev->wiphy, 4832 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 4833 auth_type == NL80211_AUTHTYPE_FILS_SK) 4834 return false; 4835 return true; 4836 case NL80211_CMD_START_AP: 4837 /* SAE not supported yet */ 4838 if (auth_type == NL80211_AUTHTYPE_SAE) 4839 return false; 4840 /* FILS not supported yet */ 4841 if (auth_type == NL80211_AUTHTYPE_FILS_SK || 4842 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 4843 auth_type == NL80211_AUTHTYPE_FILS_PK) 4844 return false; 4845 return true; 4846 default: 4847 return false; 4848 } 4849 } 4850 4851 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) 4852 { 4853 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4854 struct net_device *dev = info->user_ptr[1]; 4855 struct wireless_dev *wdev = dev->ieee80211_ptr; 4856 struct cfg80211_ap_settings params; 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 (!rdev->ops->start_ap) 4864 return -EOPNOTSUPP; 4865 4866 if (wdev->beacon_interval) 4867 return -EALREADY; 4868 4869 memset(¶ms, 0, sizeof(params)); 4870 4871 /* these are required for START_AP */ 4872 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 4873 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 4874 !info->attrs[NL80211_ATTR_BEACON_HEAD]) 4875 return -EINVAL; 4876 4877 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); 4878 if (err) 4879 return err; 4880 4881 params.beacon_interval = 4882 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 4883 params.dtim_period = 4884 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 4885 4886 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, 4887 params.beacon_interval); 4888 if (err) 4889 return err; 4890 4891 /* 4892 * In theory, some of these attributes should be required here 4893 * but since they were not used when the command was originally 4894 * added, keep them optional for old user space programs to let 4895 * them continue to work with drivers that do not need the 4896 * additional information -- drivers must check! 4897 */ 4898 if (info->attrs[NL80211_ATTR_SSID]) { 4899 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 4900 params.ssid_len = 4901 nla_len(info->attrs[NL80211_ATTR_SSID]); 4902 if (params.ssid_len == 0 || 4903 params.ssid_len > IEEE80211_MAX_SSID_LEN) 4904 return -EINVAL; 4905 } 4906 4907 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) 4908 params.hidden_ssid = nla_get_u32( 4909 info->attrs[NL80211_ATTR_HIDDEN_SSID]); 4910 4911 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 4912 4913 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 4914 params.auth_type = nla_get_u32( 4915 info->attrs[NL80211_ATTR_AUTH_TYPE]); 4916 if (!nl80211_valid_auth_type(rdev, params.auth_type, 4917 NL80211_CMD_START_AP)) 4918 return -EINVAL; 4919 } else 4920 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 4921 4922 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, 4923 NL80211_MAX_NR_CIPHER_SUITES); 4924 if (err) 4925 return err; 4926 4927 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { 4928 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) 4929 return -EOPNOTSUPP; 4930 params.inactivity_timeout = nla_get_u16( 4931 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 4932 } 4933 4934 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 4935 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4936 return -EINVAL; 4937 params.p2p_ctwindow = 4938 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 4939 if (params.p2p_ctwindow != 0 && 4940 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 4941 return -EINVAL; 4942 } 4943 4944 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 4945 u8 tmp; 4946 4947 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4948 return -EINVAL; 4949 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 4950 params.p2p_opp_ps = tmp; 4951 if (params.p2p_opp_ps != 0 && 4952 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 4953 return -EINVAL; 4954 } 4955 4956 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 4957 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 4958 if (err) 4959 return err; 4960 } else if (wdev->preset_chandef.chan) { 4961 params.chandef = wdev->preset_chandef; 4962 } else if (!nl80211_get_ap_channel(rdev, ¶ms)) 4963 return -EINVAL; 4964 4965 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 4966 wdev->iftype)) 4967 return -EINVAL; 4968 4969 if (info->attrs[NL80211_ATTR_TX_RATES]) { 4970 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 4971 NL80211_ATTR_TX_RATES, 4972 ¶ms.beacon_rate); 4973 if (err) 4974 return err; 4975 4976 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, 4977 ¶ms.beacon_rate); 4978 if (err) 4979 return err; 4980 } 4981 4982 if (info->attrs[NL80211_ATTR_SMPS_MODE]) { 4983 params.smps_mode = 4984 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); 4985 switch (params.smps_mode) { 4986 case NL80211_SMPS_OFF: 4987 break; 4988 case NL80211_SMPS_STATIC: 4989 if (!(rdev->wiphy.features & 4990 NL80211_FEATURE_STATIC_SMPS)) 4991 return -EINVAL; 4992 break; 4993 case NL80211_SMPS_DYNAMIC: 4994 if (!(rdev->wiphy.features & 4995 NL80211_FEATURE_DYNAMIC_SMPS)) 4996 return -EINVAL; 4997 break; 4998 default: 4999 return -EINVAL; 5000 } 5001 } else { 5002 params.smps_mode = NL80211_SMPS_OFF; 5003 } 5004 5005 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 5006 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) 5007 return -EOPNOTSUPP; 5008 5009 if (info->attrs[NL80211_ATTR_ACL_POLICY]) { 5010 params.acl = parse_acl_data(&rdev->wiphy, info); 5011 if (IS_ERR(params.acl)) 5012 return PTR_ERR(params.acl); 5013 } 5014 5015 params.twt_responder = 5016 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); 5017 5018 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { 5019 err = nl80211_parse_he_obss_pd( 5020 info->attrs[NL80211_ATTR_HE_OBSS_PD], 5021 ¶ms.he_obss_pd); 5022 if (err) 5023 goto out; 5024 } 5025 5026 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { 5027 err = nl80211_parse_he_bss_color( 5028 info->attrs[NL80211_ATTR_HE_BSS_COLOR], 5029 ¶ms.he_bss_color); 5030 if (err) 5031 goto out; 5032 } 5033 5034 nl80211_calculate_ap_params(¶ms); 5035 5036 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) 5037 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; 5038 5039 wdev_lock(wdev); 5040 err = rdev_start_ap(rdev, dev, ¶ms); 5041 if (!err) { 5042 wdev->preset_chandef = params.chandef; 5043 wdev->beacon_interval = params.beacon_interval; 5044 wdev->chandef = params.chandef; 5045 wdev->ssid_len = params.ssid_len; 5046 memcpy(wdev->ssid, params.ssid, wdev->ssid_len); 5047 5048 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 5049 wdev->conn_owner_nlportid = info->snd_portid; 5050 } 5051 wdev_unlock(wdev); 5052 5053 out: 5054 kfree(params.acl); 5055 5056 return err; 5057 } 5058 5059 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) 5060 { 5061 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5062 struct net_device *dev = info->user_ptr[1]; 5063 struct wireless_dev *wdev = dev->ieee80211_ptr; 5064 struct cfg80211_beacon_data params; 5065 int err; 5066 5067 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5068 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5069 return -EOPNOTSUPP; 5070 5071 if (!rdev->ops->change_beacon) 5072 return -EOPNOTSUPP; 5073 5074 if (!wdev->beacon_interval) 5075 return -EINVAL; 5076 5077 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); 5078 if (err) 5079 return err; 5080 5081 wdev_lock(wdev); 5082 err = rdev_change_beacon(rdev, dev, ¶ms); 5083 wdev_unlock(wdev); 5084 5085 return err; 5086 } 5087 5088 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) 5089 { 5090 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5091 struct net_device *dev = info->user_ptr[1]; 5092 5093 return cfg80211_stop_ap(rdev, dev, false); 5094 } 5095 5096 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { 5097 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, 5098 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 5099 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 5100 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 5101 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, 5102 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, 5103 }; 5104 5105 static int parse_station_flags(struct genl_info *info, 5106 enum nl80211_iftype iftype, 5107 struct station_parameters *params) 5108 { 5109 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 5110 struct nlattr *nla; 5111 int flag; 5112 5113 /* 5114 * Try parsing the new attribute first so userspace 5115 * can specify both for older kernels. 5116 */ 5117 nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; 5118 if (nla) { 5119 struct nl80211_sta_flag_update *sta_flags; 5120 5121 sta_flags = nla_data(nla); 5122 params->sta_flags_mask = sta_flags->mask; 5123 params->sta_flags_set = sta_flags->set; 5124 params->sta_flags_set &= params->sta_flags_mask; 5125 if ((params->sta_flags_mask | 5126 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) 5127 return -EINVAL; 5128 return 0; 5129 } 5130 5131 /* if present, parse the old attribute */ 5132 5133 nla = info->attrs[NL80211_ATTR_STA_FLAGS]; 5134 if (!nla) 5135 return 0; 5136 5137 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) 5138 return -EINVAL; 5139 5140 /* 5141 * Only allow certain flags for interface types so that 5142 * other attributes are silently ignored. Remember that 5143 * this is backward compatibility code with old userspace 5144 * and shouldn't be hit in other cases anyway. 5145 */ 5146 switch (iftype) { 5147 case NL80211_IFTYPE_AP: 5148 case NL80211_IFTYPE_AP_VLAN: 5149 case NL80211_IFTYPE_P2P_GO: 5150 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 5151 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 5152 BIT(NL80211_STA_FLAG_WME) | 5153 BIT(NL80211_STA_FLAG_MFP); 5154 break; 5155 case NL80211_IFTYPE_P2P_CLIENT: 5156 case NL80211_IFTYPE_STATION: 5157 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 5158 BIT(NL80211_STA_FLAG_TDLS_PEER); 5159 break; 5160 case NL80211_IFTYPE_MESH_POINT: 5161 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5162 BIT(NL80211_STA_FLAG_MFP) | 5163 BIT(NL80211_STA_FLAG_AUTHORIZED); 5164 break; 5165 default: 5166 return -EINVAL; 5167 } 5168 5169 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { 5170 if (flags[flag]) { 5171 params->sta_flags_set |= (1<<flag); 5172 5173 /* no longer support new API additions in old API */ 5174 if (flag > NL80211_STA_FLAG_MAX_OLD_API) 5175 return -EINVAL; 5176 } 5177 } 5178 5179 return 0; 5180 } 5181 5182 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) 5183 { 5184 struct nlattr *rate; 5185 u32 bitrate; 5186 u16 bitrate_compat; 5187 enum nl80211_rate_info rate_flg; 5188 5189 rate = nla_nest_start_noflag(msg, attr); 5190 if (!rate) 5191 return false; 5192 5193 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ 5194 bitrate = cfg80211_calculate_bitrate(info); 5195 /* report 16-bit bitrate only if we can */ 5196 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; 5197 if (bitrate > 0 && 5198 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) 5199 return false; 5200 if (bitrate_compat > 0 && 5201 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) 5202 return false; 5203 5204 switch (info->bw) { 5205 case RATE_INFO_BW_5: 5206 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; 5207 break; 5208 case RATE_INFO_BW_10: 5209 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; 5210 break; 5211 default: 5212 WARN_ON(1); 5213 fallthrough; 5214 case RATE_INFO_BW_20: 5215 rate_flg = 0; 5216 break; 5217 case RATE_INFO_BW_40: 5218 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; 5219 break; 5220 case RATE_INFO_BW_80: 5221 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; 5222 break; 5223 case RATE_INFO_BW_160: 5224 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; 5225 break; 5226 case RATE_INFO_BW_HE_RU: 5227 rate_flg = 0; 5228 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); 5229 } 5230 5231 if (rate_flg && nla_put_flag(msg, rate_flg)) 5232 return false; 5233 5234 if (info->flags & RATE_INFO_FLAGS_MCS) { 5235 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) 5236 return false; 5237 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 5238 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 5239 return false; 5240 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { 5241 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) 5242 return false; 5243 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) 5244 return false; 5245 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 5246 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 5247 return false; 5248 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { 5249 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) 5250 return false; 5251 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) 5252 return false; 5253 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) 5254 return false; 5255 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) 5256 return false; 5257 if (info->bw == RATE_INFO_BW_HE_RU && 5258 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, 5259 info->he_ru_alloc)) 5260 return false; 5261 } 5262 5263 nla_nest_end(msg, rate); 5264 return true; 5265 } 5266 5267 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, 5268 int id) 5269 { 5270 void *attr; 5271 int i = 0; 5272 5273 if (!mask) 5274 return true; 5275 5276 attr = nla_nest_start_noflag(msg, id); 5277 if (!attr) 5278 return false; 5279 5280 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 5281 if (!(mask & BIT(i))) 5282 continue; 5283 5284 if (nla_put_u8(msg, i, signal[i])) 5285 return false; 5286 } 5287 5288 nla_nest_end(msg, attr); 5289 5290 return true; 5291 } 5292 5293 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, 5294 u32 seq, int flags, 5295 struct cfg80211_registered_device *rdev, 5296 struct net_device *dev, 5297 const u8 *mac_addr, struct station_info *sinfo) 5298 { 5299 void *hdr; 5300 struct nlattr *sinfoattr, *bss_param; 5301 5302 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 5303 if (!hdr) { 5304 cfg80211_sinfo_release_content(sinfo); 5305 return -1; 5306 } 5307 5308 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 5309 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 5310 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 5311 goto nla_put_failure; 5312 5313 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); 5314 if (!sinfoattr) 5315 goto nla_put_failure; 5316 5317 #define PUT_SINFO(attr, memb, type) do { \ 5318 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ 5319 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 5320 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ 5321 sinfo->memb)) \ 5322 goto nla_put_failure; \ 5323 } while (0) 5324 #define PUT_SINFO_U64(attr, memb) do { \ 5325 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 5326 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ 5327 sinfo->memb, NL80211_STA_INFO_PAD)) \ 5328 goto nla_put_failure; \ 5329 } while (0) 5330 5331 PUT_SINFO(CONNECTED_TIME, connected_time, u32); 5332 PUT_SINFO(INACTIVE_TIME, inactive_time, u32); 5333 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); 5334 5335 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | 5336 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && 5337 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, 5338 (u32)sinfo->rx_bytes)) 5339 goto nla_put_failure; 5340 5341 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 5342 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && 5343 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, 5344 (u32)sinfo->tx_bytes)) 5345 goto nla_put_failure; 5346 5347 PUT_SINFO_U64(RX_BYTES64, rx_bytes); 5348 PUT_SINFO_U64(TX_BYTES64, tx_bytes); 5349 PUT_SINFO(LLID, llid, u16); 5350 PUT_SINFO(PLID, plid, u16); 5351 PUT_SINFO(PLINK_STATE, plink_state, u8); 5352 PUT_SINFO_U64(RX_DURATION, rx_duration); 5353 PUT_SINFO_U64(TX_DURATION, tx_duration); 5354 5355 if (wiphy_ext_feature_isset(&rdev->wiphy, 5356 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 5357 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); 5358 5359 switch (rdev->wiphy.signal_type) { 5360 case CFG80211_SIGNAL_TYPE_MBM: 5361 PUT_SINFO(SIGNAL, signal, u8); 5362 PUT_SINFO(SIGNAL_AVG, signal_avg, u8); 5363 break; 5364 default: 5365 break; 5366 } 5367 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { 5368 if (!nl80211_put_signal(msg, sinfo->chains, 5369 sinfo->chain_signal, 5370 NL80211_STA_INFO_CHAIN_SIGNAL)) 5371 goto nla_put_failure; 5372 } 5373 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { 5374 if (!nl80211_put_signal(msg, sinfo->chains, 5375 sinfo->chain_signal_avg, 5376 NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) 5377 goto nla_put_failure; 5378 } 5379 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { 5380 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 5381 NL80211_STA_INFO_TX_BITRATE)) 5382 goto nla_put_failure; 5383 } 5384 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { 5385 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, 5386 NL80211_STA_INFO_RX_BITRATE)) 5387 goto nla_put_failure; 5388 } 5389 5390 PUT_SINFO(RX_PACKETS, rx_packets, u32); 5391 PUT_SINFO(TX_PACKETS, tx_packets, u32); 5392 PUT_SINFO(TX_RETRIES, tx_retries, u32); 5393 PUT_SINFO(TX_FAILED, tx_failed, u32); 5394 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 5395 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); 5396 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 5397 PUT_SINFO(LOCAL_PM, local_pm, u32); 5398 PUT_SINFO(PEER_PM, peer_pm, u32); 5399 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); 5400 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 5401 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); 5402 5403 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 5404 bss_param = nla_nest_start_noflag(msg, 5405 NL80211_STA_INFO_BSS_PARAM); 5406 if (!bss_param) 5407 goto nla_put_failure; 5408 5409 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && 5410 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || 5411 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && 5412 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || 5413 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && 5414 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || 5415 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, 5416 sinfo->bss_param.dtim_period) || 5417 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, 5418 sinfo->bss_param.beacon_interval)) 5419 goto nla_put_failure; 5420 5421 nla_nest_end(msg, bss_param); 5422 } 5423 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && 5424 nla_put(msg, NL80211_STA_INFO_STA_FLAGS, 5425 sizeof(struct nl80211_sta_flag_update), 5426 &sinfo->sta_flags)) 5427 goto nla_put_failure; 5428 5429 PUT_SINFO_U64(T_OFFSET, t_offset); 5430 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); 5431 PUT_SINFO_U64(BEACON_RX, rx_beacon); 5432 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); 5433 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); 5434 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); 5435 if (wiphy_ext_feature_isset(&rdev->wiphy, 5436 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { 5437 PUT_SINFO(ACK_SIGNAL, ack_signal, u8); 5438 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); 5439 } 5440 5441 #undef PUT_SINFO 5442 #undef PUT_SINFO_U64 5443 5444 if (sinfo->pertid) { 5445 struct nlattr *tidsattr; 5446 int tid; 5447 5448 tidsattr = nla_nest_start_noflag(msg, 5449 NL80211_STA_INFO_TID_STATS); 5450 if (!tidsattr) 5451 goto nla_put_failure; 5452 5453 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { 5454 struct cfg80211_tid_stats *tidstats; 5455 struct nlattr *tidattr; 5456 5457 tidstats = &sinfo->pertid[tid]; 5458 5459 if (!tidstats->filled) 5460 continue; 5461 5462 tidattr = nla_nest_start_noflag(msg, tid + 1); 5463 if (!tidattr) 5464 goto nla_put_failure; 5465 5466 #define PUT_TIDVAL_U64(attr, memb) do { \ 5467 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ 5468 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ 5469 tidstats->memb, NL80211_TID_STATS_PAD)) \ 5470 goto nla_put_failure; \ 5471 } while (0) 5472 5473 PUT_TIDVAL_U64(RX_MSDU, rx_msdu); 5474 PUT_TIDVAL_U64(TX_MSDU, tx_msdu); 5475 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); 5476 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); 5477 5478 #undef PUT_TIDVAL_U64 5479 if ((tidstats->filled & 5480 BIT(NL80211_TID_STATS_TXQ_STATS)) && 5481 !nl80211_put_txq_stats(msg, &tidstats->txq_stats, 5482 NL80211_TID_STATS_TXQ_STATS)) 5483 goto nla_put_failure; 5484 5485 nla_nest_end(msg, tidattr); 5486 } 5487 5488 nla_nest_end(msg, tidsattr); 5489 } 5490 5491 nla_nest_end(msg, sinfoattr); 5492 5493 if (sinfo->assoc_req_ies_len && 5494 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, 5495 sinfo->assoc_req_ies)) 5496 goto nla_put_failure; 5497 5498 cfg80211_sinfo_release_content(sinfo); 5499 genlmsg_end(msg, hdr); 5500 return 0; 5501 5502 nla_put_failure: 5503 cfg80211_sinfo_release_content(sinfo); 5504 genlmsg_cancel(msg, hdr); 5505 return -EMSGSIZE; 5506 } 5507 5508 static int nl80211_dump_station(struct sk_buff *skb, 5509 struct netlink_callback *cb) 5510 { 5511 struct station_info sinfo; 5512 struct cfg80211_registered_device *rdev; 5513 struct wireless_dev *wdev; 5514 u8 mac_addr[ETH_ALEN]; 5515 int sta_idx = cb->args[2]; 5516 int err; 5517 5518 rtnl_lock(); 5519 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 5520 if (err) 5521 goto out_err; 5522 5523 if (!wdev->netdev) { 5524 err = -EINVAL; 5525 goto out_err; 5526 } 5527 5528 if (!rdev->ops->dump_station) { 5529 err = -EOPNOTSUPP; 5530 goto out_err; 5531 } 5532 5533 while (1) { 5534 memset(&sinfo, 0, sizeof(sinfo)); 5535 err = rdev_dump_station(rdev, wdev->netdev, sta_idx, 5536 mac_addr, &sinfo); 5537 if (err == -ENOENT) 5538 break; 5539 if (err) 5540 goto out_err; 5541 5542 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, 5543 NETLINK_CB(cb->skb).portid, 5544 cb->nlh->nlmsg_seq, NLM_F_MULTI, 5545 rdev, wdev->netdev, mac_addr, 5546 &sinfo) < 0) 5547 goto out; 5548 5549 sta_idx++; 5550 } 5551 5552 out: 5553 cb->args[2] = sta_idx; 5554 err = skb->len; 5555 out_err: 5556 rtnl_unlock(); 5557 5558 return err; 5559 } 5560 5561 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 5562 { 5563 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5564 struct net_device *dev = info->user_ptr[1]; 5565 struct station_info sinfo; 5566 struct sk_buff *msg; 5567 u8 *mac_addr = NULL; 5568 int err; 5569 5570 memset(&sinfo, 0, sizeof(sinfo)); 5571 5572 if (!info->attrs[NL80211_ATTR_MAC]) 5573 return -EINVAL; 5574 5575 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 5576 5577 if (!rdev->ops->get_station) 5578 return -EOPNOTSUPP; 5579 5580 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 5581 if (err) 5582 return err; 5583 5584 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 5585 if (!msg) { 5586 cfg80211_sinfo_release_content(&sinfo); 5587 return -ENOMEM; 5588 } 5589 5590 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 5591 info->snd_portid, info->snd_seq, 0, 5592 rdev, dev, mac_addr, &sinfo) < 0) { 5593 nlmsg_free(msg); 5594 return -ENOBUFS; 5595 } 5596 5597 return genlmsg_reply(msg, info); 5598 } 5599 5600 int cfg80211_check_station_change(struct wiphy *wiphy, 5601 struct station_parameters *params, 5602 enum cfg80211_station_type statype) 5603 { 5604 if (params->listen_interval != -1 && 5605 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 5606 return -EINVAL; 5607 5608 if (params->support_p2p_ps != -1 && 5609 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 5610 return -EINVAL; 5611 5612 if (params->aid && 5613 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && 5614 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 5615 return -EINVAL; 5616 5617 /* When you run into this, adjust the code below for the new flag */ 5618 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 5619 5620 switch (statype) { 5621 case CFG80211_STA_MESH_PEER_KERNEL: 5622 case CFG80211_STA_MESH_PEER_USER: 5623 /* 5624 * No ignoring the TDLS flag here -- the userspace mesh 5625 * code doesn't have the bug of including TDLS in the 5626 * mask everywhere. 5627 */ 5628 if (params->sta_flags_mask & 5629 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5630 BIT(NL80211_STA_FLAG_MFP) | 5631 BIT(NL80211_STA_FLAG_AUTHORIZED))) 5632 return -EINVAL; 5633 break; 5634 case CFG80211_STA_TDLS_PEER_SETUP: 5635 case CFG80211_STA_TDLS_PEER_ACTIVE: 5636 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 5637 return -EINVAL; 5638 /* ignore since it can't change */ 5639 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 5640 break; 5641 default: 5642 /* disallow mesh-specific things */ 5643 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) 5644 return -EINVAL; 5645 if (params->local_pm) 5646 return -EINVAL; 5647 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 5648 return -EINVAL; 5649 } 5650 5651 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 5652 statype != CFG80211_STA_TDLS_PEER_ACTIVE) { 5653 /* TDLS can't be set, ... */ 5654 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 5655 return -EINVAL; 5656 /* 5657 * ... but don't bother the driver with it. This works around 5658 * a hostapd/wpa_supplicant issue -- it always includes the 5659 * TLDS_PEER flag in the mask even for AP mode. 5660 */ 5661 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 5662 } 5663 5664 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 5665 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 5666 /* reject other things that can't change */ 5667 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) 5668 return -EINVAL; 5669 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) 5670 return -EINVAL; 5671 if (params->supported_rates) 5672 return -EINVAL; 5673 if (params->ext_capab || params->ht_capa || params->vht_capa || 5674 params->he_capa) 5675 return -EINVAL; 5676 } 5677 5678 if (statype != CFG80211_STA_AP_CLIENT && 5679 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 5680 if (params->vlan) 5681 return -EINVAL; 5682 } 5683 5684 switch (statype) { 5685 case CFG80211_STA_AP_MLME_CLIENT: 5686 /* Use this only for authorizing/unauthorizing a station */ 5687 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 5688 return -EOPNOTSUPP; 5689 break; 5690 case CFG80211_STA_AP_CLIENT: 5691 case CFG80211_STA_AP_CLIENT_UNASSOC: 5692 /* accept only the listed bits */ 5693 if (params->sta_flags_mask & 5694 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 5695 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5696 BIT(NL80211_STA_FLAG_ASSOCIATED) | 5697 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 5698 BIT(NL80211_STA_FLAG_WME) | 5699 BIT(NL80211_STA_FLAG_MFP))) 5700 return -EINVAL; 5701 5702 /* but authenticated/associated only if driver handles it */ 5703 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 5704 params->sta_flags_mask & 5705 (BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5706 BIT(NL80211_STA_FLAG_ASSOCIATED))) 5707 return -EINVAL; 5708 break; 5709 case CFG80211_STA_IBSS: 5710 case CFG80211_STA_AP_STA: 5711 /* reject any changes other than AUTHORIZED */ 5712 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 5713 return -EINVAL; 5714 break; 5715 case CFG80211_STA_TDLS_PEER_SETUP: 5716 /* reject any changes other than AUTHORIZED or WME */ 5717 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 5718 BIT(NL80211_STA_FLAG_WME))) 5719 return -EINVAL; 5720 /* force (at least) rates when authorizing */ 5721 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && 5722 !params->supported_rates) 5723 return -EINVAL; 5724 break; 5725 case CFG80211_STA_TDLS_PEER_ACTIVE: 5726 /* reject any changes */ 5727 return -EINVAL; 5728 case CFG80211_STA_MESH_PEER_KERNEL: 5729 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 5730 return -EINVAL; 5731 break; 5732 case CFG80211_STA_MESH_PEER_USER: 5733 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && 5734 params->plink_action != NL80211_PLINK_ACTION_BLOCK) 5735 return -EINVAL; 5736 break; 5737 } 5738 5739 /* 5740 * Older kernel versions ignored this attribute entirely, so don't 5741 * reject attempts to update it but mark it as unused instead so the 5742 * driver won't look at the data. 5743 */ 5744 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && 5745 statype != CFG80211_STA_TDLS_PEER_SETUP) 5746 params->opmode_notif_used = false; 5747 5748 return 0; 5749 } 5750 EXPORT_SYMBOL(cfg80211_check_station_change); 5751 5752 /* 5753 * Get vlan interface making sure it is running and on the right wiphy. 5754 */ 5755 static struct net_device *get_vlan(struct genl_info *info, 5756 struct cfg80211_registered_device *rdev) 5757 { 5758 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; 5759 struct net_device *v; 5760 int ret; 5761 5762 if (!vlanattr) 5763 return NULL; 5764 5765 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); 5766 if (!v) 5767 return ERR_PTR(-ENODEV); 5768 5769 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { 5770 ret = -EINVAL; 5771 goto error; 5772 } 5773 5774 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 5775 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5776 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 5777 ret = -EINVAL; 5778 goto error; 5779 } 5780 5781 if (!netif_running(v)) { 5782 ret = -ENETDOWN; 5783 goto error; 5784 } 5785 5786 return v; 5787 error: 5788 dev_put(v); 5789 return ERR_PTR(ret); 5790 } 5791 5792 static const struct nla_policy 5793 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { 5794 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, 5795 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, 5796 }; 5797 5798 static int nl80211_parse_sta_wme(struct genl_info *info, 5799 struct station_parameters *params) 5800 { 5801 struct nlattr *tb[NL80211_STA_WME_MAX + 1]; 5802 struct nlattr *nla; 5803 int err; 5804 5805 /* parse WME attributes if present */ 5806 if (!info->attrs[NL80211_ATTR_STA_WME]) 5807 return 0; 5808 5809 nla = info->attrs[NL80211_ATTR_STA_WME]; 5810 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, 5811 nl80211_sta_wme_policy, 5812 info->extack); 5813 if (err) 5814 return err; 5815 5816 if (tb[NL80211_STA_WME_UAPSD_QUEUES]) 5817 params->uapsd_queues = nla_get_u8( 5818 tb[NL80211_STA_WME_UAPSD_QUEUES]); 5819 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) 5820 return -EINVAL; 5821 5822 if (tb[NL80211_STA_WME_MAX_SP]) 5823 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); 5824 5825 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) 5826 return -EINVAL; 5827 5828 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; 5829 5830 return 0; 5831 } 5832 5833 static int nl80211_parse_sta_channel_info(struct genl_info *info, 5834 struct station_parameters *params) 5835 { 5836 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { 5837 params->supported_channels = 5838 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 5839 params->supported_channels_len = 5840 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 5841 /* 5842 * Need to include at least one (first channel, number of 5843 * channels) tuple for each subband, and must have proper 5844 * tuples for the rest of the data as well. 5845 */ 5846 if (params->supported_channels_len < 2) 5847 return -EINVAL; 5848 if (params->supported_channels_len % 2) 5849 return -EINVAL; 5850 } 5851 5852 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { 5853 params->supported_oper_classes = 5854 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 5855 params->supported_oper_classes_len = 5856 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 5857 /* 5858 * The value of the Length field of the Supported Operating 5859 * Classes element is between 2 and 253. 5860 */ 5861 if (params->supported_oper_classes_len < 2 || 5862 params->supported_oper_classes_len > 253) 5863 return -EINVAL; 5864 } 5865 return 0; 5866 } 5867 5868 static int nl80211_set_station_tdls(struct genl_info *info, 5869 struct station_parameters *params) 5870 { 5871 int err; 5872 /* Dummy STA entry gets updated once the peer capabilities are known */ 5873 if (info->attrs[NL80211_ATTR_PEER_AID]) 5874 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 5875 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 5876 params->ht_capa = 5877 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 5878 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 5879 params->vht_capa = 5880 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 5881 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 5882 params->he_capa = 5883 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 5884 params->he_capa_len = 5885 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 5886 5887 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) 5888 return -EINVAL; 5889 } 5890 5891 err = nl80211_parse_sta_channel_info(info, params); 5892 if (err) 5893 return err; 5894 5895 return nl80211_parse_sta_wme(info, params); 5896 } 5897 5898 static int nl80211_parse_sta_txpower_setting(struct genl_info *info, 5899 struct station_parameters *params) 5900 { 5901 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5902 int idx; 5903 5904 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { 5905 if (!rdev->ops->set_tx_power || 5906 !wiphy_ext_feature_isset(&rdev->wiphy, 5907 NL80211_EXT_FEATURE_STA_TX_PWR)) 5908 return -EOPNOTSUPP; 5909 5910 idx = NL80211_ATTR_STA_TX_POWER_SETTING; 5911 params->txpwr.type = nla_get_u8(info->attrs[idx]); 5912 5913 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { 5914 idx = NL80211_ATTR_STA_TX_POWER; 5915 5916 if (info->attrs[idx]) 5917 params->txpwr.power = 5918 nla_get_s16(info->attrs[idx]); 5919 else 5920 return -EINVAL; 5921 } 5922 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; 5923 } 5924 5925 return 0; 5926 } 5927 5928 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 5929 { 5930 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5931 struct net_device *dev = info->user_ptr[1]; 5932 struct station_parameters params; 5933 u8 *mac_addr; 5934 int err; 5935 5936 memset(¶ms, 0, sizeof(params)); 5937 5938 if (!rdev->ops->change_station) 5939 return -EOPNOTSUPP; 5940 5941 /* 5942 * AID and listen_interval properties can be set only for unassociated 5943 * station. Include these parameters here and will check them in 5944 * cfg80211_check_station_change(). 5945 */ 5946 if (info->attrs[NL80211_ATTR_STA_AID]) 5947 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 5948 5949 if (info->attrs[NL80211_ATTR_VLAN_ID]) 5950 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 5951 5952 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 5953 params.listen_interval = 5954 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 5955 else 5956 params.listen_interval = -1; 5957 5958 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) 5959 params.support_p2p_ps = 5960 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 5961 else 5962 params.support_p2p_ps = -1; 5963 5964 if (!info->attrs[NL80211_ATTR_MAC]) 5965 return -EINVAL; 5966 5967 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 5968 5969 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 5970 params.supported_rates = 5971 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 5972 params.supported_rates_len = 5973 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 5974 } 5975 5976 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 5977 params.capability = 5978 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 5979 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 5980 } 5981 5982 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 5983 params.ext_capab = 5984 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 5985 params.ext_capab_len = 5986 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 5987 } 5988 5989 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 5990 return -EINVAL; 5991 5992 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 5993 params.plink_action = 5994 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 5995 5996 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { 5997 params.plink_state = 5998 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 5999 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) 6000 params.peer_aid = nla_get_u16( 6001 info->attrs[NL80211_ATTR_MESH_PEER_AID]); 6002 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; 6003 } 6004 6005 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) 6006 params.local_pm = nla_get_u32( 6007 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); 6008 6009 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 6010 params.opmode_notif_used = true; 6011 params.opmode_notif = 6012 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 6013 } 6014 6015 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 6016 params.he_6ghz_capa = 6017 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 6018 6019 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 6020 params.airtime_weight = 6021 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 6022 6023 if (params.airtime_weight && 6024 !wiphy_ext_feature_isset(&rdev->wiphy, 6025 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6026 return -EOPNOTSUPP; 6027 6028 err = nl80211_parse_sta_txpower_setting(info, ¶ms); 6029 if (err) 6030 return err; 6031 6032 /* Include parameters for TDLS peer (will check later) */ 6033 err = nl80211_set_station_tdls(info, ¶ms); 6034 if (err) 6035 return err; 6036 6037 params.vlan = get_vlan(info, rdev); 6038 if (IS_ERR(params.vlan)) 6039 return PTR_ERR(params.vlan); 6040 6041 switch (dev->ieee80211_ptr->iftype) { 6042 case NL80211_IFTYPE_AP: 6043 case NL80211_IFTYPE_AP_VLAN: 6044 case NL80211_IFTYPE_P2P_GO: 6045 case NL80211_IFTYPE_P2P_CLIENT: 6046 case NL80211_IFTYPE_STATION: 6047 case NL80211_IFTYPE_ADHOC: 6048 case NL80211_IFTYPE_MESH_POINT: 6049 break; 6050 default: 6051 err = -EOPNOTSUPP; 6052 goto out_put_vlan; 6053 } 6054 6055 /* driver will call cfg80211_check_station_change() */ 6056 err = rdev_change_station(rdev, dev, mac_addr, ¶ms); 6057 6058 out_put_vlan: 6059 if (params.vlan) 6060 dev_put(params.vlan); 6061 6062 return err; 6063 } 6064 6065 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 6066 { 6067 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6068 int err; 6069 struct net_device *dev = info->user_ptr[1]; 6070 struct station_parameters params; 6071 u8 *mac_addr = NULL; 6072 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6073 BIT(NL80211_STA_FLAG_ASSOCIATED); 6074 6075 memset(¶ms, 0, sizeof(params)); 6076 6077 if (!rdev->ops->add_station) 6078 return -EOPNOTSUPP; 6079 6080 if (!info->attrs[NL80211_ATTR_MAC]) 6081 return -EINVAL; 6082 6083 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 6084 return -EINVAL; 6085 6086 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 6087 return -EINVAL; 6088 6089 if (!info->attrs[NL80211_ATTR_STA_AID] && 6090 !info->attrs[NL80211_ATTR_PEER_AID]) 6091 return -EINVAL; 6092 6093 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6094 params.supported_rates = 6095 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 6096 params.supported_rates_len = 6097 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 6098 params.listen_interval = 6099 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 6100 6101 if (info->attrs[NL80211_ATTR_VLAN_ID]) 6102 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 6103 6104 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { 6105 params.support_p2p_ps = 6106 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 6107 } else { 6108 /* 6109 * if not specified, assume it's supported for P2P GO interface, 6110 * and is NOT supported for AP interface 6111 */ 6112 params.support_p2p_ps = 6113 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; 6114 } 6115 6116 if (info->attrs[NL80211_ATTR_PEER_AID]) 6117 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 6118 else 6119 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 6120 6121 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 6122 params.capability = 6123 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 6124 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 6125 } 6126 6127 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 6128 params.ext_capab = 6129 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 6130 params.ext_capab_len = 6131 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 6132 } 6133 6134 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 6135 params.ht_capa = 6136 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 6137 6138 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 6139 params.vht_capa = 6140 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 6141 6142 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 6143 params.he_capa = 6144 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6145 params.he_capa_len = 6146 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 6147 6148 /* max len is validated in nla policy */ 6149 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) 6150 return -EINVAL; 6151 } 6152 6153 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 6154 params.he_6ghz_capa = 6155 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 6156 6157 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 6158 params.opmode_notif_used = true; 6159 params.opmode_notif = 6160 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 6161 } 6162 6163 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 6164 params.plink_action = 6165 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 6166 6167 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 6168 params.airtime_weight = 6169 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 6170 6171 if (params.airtime_weight && 6172 !wiphy_ext_feature_isset(&rdev->wiphy, 6173 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6174 return -EOPNOTSUPP; 6175 6176 err = nl80211_parse_sta_txpower_setting(info, ¶ms); 6177 if (err) 6178 return err; 6179 6180 err = nl80211_parse_sta_channel_info(info, ¶ms); 6181 if (err) 6182 return err; 6183 6184 err = nl80211_parse_sta_wme(info, ¶ms); 6185 if (err) 6186 return err; 6187 6188 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 6189 return -EINVAL; 6190 6191 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT 6192 * as userspace might just pass through the capabilities from the IEs 6193 * directly, rather than enforcing this restriction and returning an 6194 * error in this case. 6195 */ 6196 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { 6197 params.ht_capa = NULL; 6198 params.vht_capa = NULL; 6199 6200 /* HE requires WME */ 6201 if (params.he_capa_len || params.he_6ghz_capa) 6202 return -EINVAL; 6203 } 6204 6205 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ 6206 if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) 6207 return -EINVAL; 6208 6209 /* When you run into this, adjust the code below for the new flag */ 6210 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 6211 6212 switch (dev->ieee80211_ptr->iftype) { 6213 case NL80211_IFTYPE_AP: 6214 case NL80211_IFTYPE_AP_VLAN: 6215 case NL80211_IFTYPE_P2P_GO: 6216 /* ignore WME attributes if iface/sta is not capable */ 6217 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || 6218 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) 6219 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 6220 6221 /* TDLS peers cannot be added */ 6222 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 6223 info->attrs[NL80211_ATTR_PEER_AID]) 6224 return -EINVAL; 6225 /* but don't bother the driver with it */ 6226 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6227 6228 /* allow authenticated/associated only if driver handles it */ 6229 if (!(rdev->wiphy.features & 6230 NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 6231 params.sta_flags_mask & auth_assoc) 6232 return -EINVAL; 6233 6234 /* Older userspace, or userspace wanting to be compatible with 6235 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth 6236 * and assoc flags in the mask, but assumes the station will be 6237 * added as associated anyway since this was the required driver 6238 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was 6239 * introduced. 6240 * In order to not bother drivers with this quirk in the API 6241 * set the flags in both the mask and set for new stations in 6242 * this case. 6243 */ 6244 if (!(params.sta_flags_mask & auth_assoc)) { 6245 params.sta_flags_mask |= auth_assoc; 6246 params.sta_flags_set |= auth_assoc; 6247 } 6248 6249 /* must be last in here for error handling */ 6250 params.vlan = get_vlan(info, rdev); 6251 if (IS_ERR(params.vlan)) 6252 return PTR_ERR(params.vlan); 6253 break; 6254 case NL80211_IFTYPE_MESH_POINT: 6255 /* ignore uAPSD data */ 6256 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 6257 6258 /* associated is disallowed */ 6259 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) 6260 return -EINVAL; 6261 /* TDLS peers cannot be added */ 6262 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 6263 info->attrs[NL80211_ATTR_PEER_AID]) 6264 return -EINVAL; 6265 break; 6266 case NL80211_IFTYPE_STATION: 6267 case NL80211_IFTYPE_P2P_CLIENT: 6268 /* ignore uAPSD data */ 6269 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 6270 6271 /* these are disallowed */ 6272 if (params.sta_flags_mask & 6273 (BIT(NL80211_STA_FLAG_ASSOCIATED) | 6274 BIT(NL80211_STA_FLAG_AUTHENTICATED))) 6275 return -EINVAL; 6276 /* Only TDLS peers can be added */ 6277 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 6278 return -EINVAL; 6279 /* Can only add if TDLS ... */ 6280 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) 6281 return -EOPNOTSUPP; 6282 /* ... with external setup is supported */ 6283 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 6284 return -EOPNOTSUPP; 6285 /* 6286 * Older wpa_supplicant versions always mark the TDLS peer 6287 * as authorized, but it shouldn't yet be. 6288 */ 6289 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); 6290 break; 6291 default: 6292 return -EOPNOTSUPP; 6293 } 6294 6295 /* be aware of params.vlan when changing code here */ 6296 6297 err = rdev_add_station(rdev, dev, mac_addr, ¶ms); 6298 6299 if (params.vlan) 6300 dev_put(params.vlan); 6301 return err; 6302 } 6303 6304 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 6305 { 6306 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6307 struct net_device *dev = info->user_ptr[1]; 6308 struct station_del_parameters params; 6309 6310 memset(¶ms, 0, sizeof(params)); 6311 6312 if (info->attrs[NL80211_ATTR_MAC]) 6313 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 6314 6315 switch (dev->ieee80211_ptr->iftype) { 6316 case NL80211_IFTYPE_AP: 6317 case NL80211_IFTYPE_AP_VLAN: 6318 case NL80211_IFTYPE_MESH_POINT: 6319 case NL80211_IFTYPE_P2P_GO: 6320 /* always accept these */ 6321 break; 6322 case NL80211_IFTYPE_ADHOC: 6323 /* conditionally accept */ 6324 if (wiphy_ext_feature_isset(&rdev->wiphy, 6325 NL80211_EXT_FEATURE_DEL_IBSS_STA)) 6326 break; 6327 return -EINVAL; 6328 default: 6329 return -EINVAL; 6330 } 6331 6332 if (!rdev->ops->del_station) 6333 return -EOPNOTSUPP; 6334 6335 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { 6336 params.subtype = 6337 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); 6338 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && 6339 params.subtype != IEEE80211_STYPE_DEAUTH >> 4) 6340 return -EINVAL; 6341 } else { 6342 /* Default to Deauthentication frame */ 6343 params.subtype = IEEE80211_STYPE_DEAUTH >> 4; 6344 } 6345 6346 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 6347 params.reason_code = 6348 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 6349 if (params.reason_code == 0) 6350 return -EINVAL; /* 0 is reserved */ 6351 } else { 6352 /* Default to reason code 2 */ 6353 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; 6354 } 6355 6356 return rdev_del_station(rdev, dev, ¶ms); 6357 } 6358 6359 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 6360 int flags, struct net_device *dev, 6361 u8 *dst, u8 *next_hop, 6362 struct mpath_info *pinfo) 6363 { 6364 void *hdr; 6365 struct nlattr *pinfoattr; 6366 6367 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); 6368 if (!hdr) 6369 return -1; 6370 6371 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6372 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || 6373 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || 6374 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 6375 goto nla_put_failure; 6376 6377 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); 6378 if (!pinfoattr) 6379 goto nla_put_failure; 6380 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 6381 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 6382 pinfo->frame_qlen)) 6383 goto nla_put_failure; 6384 if (((pinfo->filled & MPATH_INFO_SN) && 6385 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || 6386 ((pinfo->filled & MPATH_INFO_METRIC) && 6387 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, 6388 pinfo->metric)) || 6389 ((pinfo->filled & MPATH_INFO_EXPTIME) && 6390 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, 6391 pinfo->exptime)) || 6392 ((pinfo->filled & MPATH_INFO_FLAGS) && 6393 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, 6394 pinfo->flags)) || 6395 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && 6396 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, 6397 pinfo->discovery_timeout)) || 6398 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && 6399 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, 6400 pinfo->discovery_retries)) || 6401 ((pinfo->filled & MPATH_INFO_HOP_COUNT) && 6402 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, 6403 pinfo->hop_count)) || 6404 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && 6405 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, 6406 pinfo->path_change_count))) 6407 goto nla_put_failure; 6408 6409 nla_nest_end(msg, pinfoattr); 6410 6411 genlmsg_end(msg, hdr); 6412 return 0; 6413 6414 nla_put_failure: 6415 genlmsg_cancel(msg, hdr); 6416 return -EMSGSIZE; 6417 } 6418 6419 static int nl80211_dump_mpath(struct sk_buff *skb, 6420 struct netlink_callback *cb) 6421 { 6422 struct mpath_info pinfo; 6423 struct cfg80211_registered_device *rdev; 6424 struct wireless_dev *wdev; 6425 u8 dst[ETH_ALEN]; 6426 u8 next_hop[ETH_ALEN]; 6427 int path_idx = cb->args[2]; 6428 int err; 6429 6430 rtnl_lock(); 6431 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 6432 if (err) 6433 goto out_err; 6434 6435 if (!rdev->ops->dump_mpath) { 6436 err = -EOPNOTSUPP; 6437 goto out_err; 6438 } 6439 6440 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 6441 err = -EOPNOTSUPP; 6442 goto out_err; 6443 } 6444 6445 while (1) { 6446 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, 6447 next_hop, &pinfo); 6448 if (err == -ENOENT) 6449 break; 6450 if (err) 6451 goto out_err; 6452 6453 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 6454 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6455 wdev->netdev, dst, next_hop, 6456 &pinfo) < 0) 6457 goto out; 6458 6459 path_idx++; 6460 } 6461 6462 out: 6463 cb->args[2] = path_idx; 6464 err = skb->len; 6465 out_err: 6466 rtnl_unlock(); 6467 return err; 6468 } 6469 6470 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 6471 { 6472 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6473 int err; 6474 struct net_device *dev = info->user_ptr[1]; 6475 struct mpath_info pinfo; 6476 struct sk_buff *msg; 6477 u8 *dst = NULL; 6478 u8 next_hop[ETH_ALEN]; 6479 6480 memset(&pinfo, 0, sizeof(pinfo)); 6481 6482 if (!info->attrs[NL80211_ATTR_MAC]) 6483 return -EINVAL; 6484 6485 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6486 6487 if (!rdev->ops->get_mpath) 6488 return -EOPNOTSUPP; 6489 6490 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6491 return -EOPNOTSUPP; 6492 6493 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); 6494 if (err) 6495 return err; 6496 6497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6498 if (!msg) 6499 return -ENOMEM; 6500 6501 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 6502 dev, dst, next_hop, &pinfo) < 0) { 6503 nlmsg_free(msg); 6504 return -ENOBUFS; 6505 } 6506 6507 return genlmsg_reply(msg, info); 6508 } 6509 6510 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 6511 { 6512 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6513 struct net_device *dev = info->user_ptr[1]; 6514 u8 *dst = NULL; 6515 u8 *next_hop = NULL; 6516 6517 if (!info->attrs[NL80211_ATTR_MAC]) 6518 return -EINVAL; 6519 6520 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 6521 return -EINVAL; 6522 6523 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6524 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 6525 6526 if (!rdev->ops->change_mpath) 6527 return -EOPNOTSUPP; 6528 6529 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6530 return -EOPNOTSUPP; 6531 6532 return rdev_change_mpath(rdev, dev, dst, next_hop); 6533 } 6534 6535 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 6536 { 6537 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6538 struct net_device *dev = info->user_ptr[1]; 6539 u8 *dst = NULL; 6540 u8 *next_hop = NULL; 6541 6542 if (!info->attrs[NL80211_ATTR_MAC]) 6543 return -EINVAL; 6544 6545 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 6546 return -EINVAL; 6547 6548 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6549 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 6550 6551 if (!rdev->ops->add_mpath) 6552 return -EOPNOTSUPP; 6553 6554 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6555 return -EOPNOTSUPP; 6556 6557 return rdev_add_mpath(rdev, dev, dst, next_hop); 6558 } 6559 6560 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 6561 { 6562 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6563 struct net_device *dev = info->user_ptr[1]; 6564 u8 *dst = NULL; 6565 6566 if (info->attrs[NL80211_ATTR_MAC]) 6567 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6568 6569 if (!rdev->ops->del_mpath) 6570 return -EOPNOTSUPP; 6571 6572 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6573 return -EOPNOTSUPP; 6574 6575 return rdev_del_mpath(rdev, dev, dst); 6576 } 6577 6578 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) 6579 { 6580 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6581 int err; 6582 struct net_device *dev = info->user_ptr[1]; 6583 struct mpath_info pinfo; 6584 struct sk_buff *msg; 6585 u8 *dst = NULL; 6586 u8 mpp[ETH_ALEN]; 6587 6588 memset(&pinfo, 0, sizeof(pinfo)); 6589 6590 if (!info->attrs[NL80211_ATTR_MAC]) 6591 return -EINVAL; 6592 6593 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6594 6595 if (!rdev->ops->get_mpp) 6596 return -EOPNOTSUPP; 6597 6598 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6599 return -EOPNOTSUPP; 6600 6601 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); 6602 if (err) 6603 return err; 6604 6605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6606 if (!msg) 6607 return -ENOMEM; 6608 6609 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 6610 dev, dst, mpp, &pinfo) < 0) { 6611 nlmsg_free(msg); 6612 return -ENOBUFS; 6613 } 6614 6615 return genlmsg_reply(msg, info); 6616 } 6617 6618 static int nl80211_dump_mpp(struct sk_buff *skb, 6619 struct netlink_callback *cb) 6620 { 6621 struct mpath_info pinfo; 6622 struct cfg80211_registered_device *rdev; 6623 struct wireless_dev *wdev; 6624 u8 dst[ETH_ALEN]; 6625 u8 mpp[ETH_ALEN]; 6626 int path_idx = cb->args[2]; 6627 int err; 6628 6629 rtnl_lock(); 6630 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 6631 if (err) 6632 goto out_err; 6633 6634 if (!rdev->ops->dump_mpp) { 6635 err = -EOPNOTSUPP; 6636 goto out_err; 6637 } 6638 6639 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 6640 err = -EOPNOTSUPP; 6641 goto out_err; 6642 } 6643 6644 while (1) { 6645 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, 6646 mpp, &pinfo); 6647 if (err == -ENOENT) 6648 break; 6649 if (err) 6650 goto out_err; 6651 6652 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 6653 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6654 wdev->netdev, dst, mpp, 6655 &pinfo) < 0) 6656 goto out; 6657 6658 path_idx++; 6659 } 6660 6661 out: 6662 cb->args[2] = path_idx; 6663 err = skb->len; 6664 out_err: 6665 rtnl_unlock(); 6666 return err; 6667 } 6668 6669 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 6670 { 6671 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6672 struct net_device *dev = info->user_ptr[1]; 6673 struct wireless_dev *wdev = dev->ieee80211_ptr; 6674 struct bss_parameters params; 6675 int err; 6676 6677 memset(¶ms, 0, sizeof(params)); 6678 /* default to not changing parameters */ 6679 params.use_cts_prot = -1; 6680 params.use_short_preamble = -1; 6681 params.use_short_slot_time = -1; 6682 params.ap_isolate = -1; 6683 params.ht_opmode = -1; 6684 params.p2p_ctwindow = -1; 6685 params.p2p_opp_ps = -1; 6686 6687 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 6688 params.use_cts_prot = 6689 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); 6690 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) 6691 params.use_short_preamble = 6692 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); 6693 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 6694 params.use_short_slot_time = 6695 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 6696 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 6697 params.basic_rates = 6698 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 6699 params.basic_rates_len = 6700 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 6701 } 6702 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 6703 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 6704 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) 6705 params.ht_opmode = 6706 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); 6707 6708 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 6709 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6710 return -EINVAL; 6711 params.p2p_ctwindow = 6712 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 6713 if (params.p2p_ctwindow != 0 && 6714 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 6715 return -EINVAL; 6716 } 6717 6718 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 6719 u8 tmp; 6720 6721 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6722 return -EINVAL; 6723 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 6724 params.p2p_opp_ps = tmp; 6725 if (params.p2p_opp_ps && 6726 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 6727 return -EINVAL; 6728 } 6729 6730 if (!rdev->ops->change_bss) 6731 return -EOPNOTSUPP; 6732 6733 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6734 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6735 return -EOPNOTSUPP; 6736 6737 wdev_lock(wdev); 6738 err = rdev_change_bss(rdev, dev, ¶ms); 6739 wdev_unlock(wdev); 6740 6741 return err; 6742 } 6743 6744 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) 6745 { 6746 char *data = NULL; 6747 bool is_indoor; 6748 enum nl80211_user_reg_hint_type user_reg_hint_type; 6749 u32 owner_nlportid; 6750 6751 /* 6752 * You should only get this when cfg80211 hasn't yet initialized 6753 * completely when built-in to the kernel right between the time 6754 * window between nl80211_init() and regulatory_init(), if that is 6755 * even possible. 6756 */ 6757 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 6758 return -EINPROGRESS; 6759 6760 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 6761 user_reg_hint_type = 6762 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 6763 else 6764 user_reg_hint_type = NL80211_USER_REG_HINT_USER; 6765 6766 switch (user_reg_hint_type) { 6767 case NL80211_USER_REG_HINT_USER: 6768 case NL80211_USER_REG_HINT_CELL_BASE: 6769 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 6770 return -EINVAL; 6771 6772 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 6773 return regulatory_hint_user(data, user_reg_hint_type); 6774 case NL80211_USER_REG_HINT_INDOOR: 6775 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 6776 owner_nlportid = info->snd_portid; 6777 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; 6778 } else { 6779 owner_nlportid = 0; 6780 is_indoor = true; 6781 } 6782 6783 return regulatory_hint_indoor(is_indoor, owner_nlportid); 6784 default: 6785 return -EINVAL; 6786 } 6787 } 6788 6789 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) 6790 { 6791 return reg_reload_regdb(); 6792 } 6793 6794 static int nl80211_get_mesh_config(struct sk_buff *skb, 6795 struct genl_info *info) 6796 { 6797 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6798 struct net_device *dev = info->user_ptr[1]; 6799 struct wireless_dev *wdev = dev->ieee80211_ptr; 6800 struct mesh_config cur_params; 6801 int err = 0; 6802 void *hdr; 6803 struct nlattr *pinfoattr; 6804 struct sk_buff *msg; 6805 6806 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 6807 return -EOPNOTSUPP; 6808 6809 if (!rdev->ops->get_mesh_config) 6810 return -EOPNOTSUPP; 6811 6812 wdev_lock(wdev); 6813 /* If not connected, get default parameters */ 6814 if (!wdev->mesh_id_len) 6815 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); 6816 else 6817 err = rdev_get_mesh_config(rdev, dev, &cur_params); 6818 wdev_unlock(wdev); 6819 6820 if (err) 6821 return err; 6822 6823 /* Draw up a netlink message to send back */ 6824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6825 if (!msg) 6826 return -ENOMEM; 6827 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 6828 NL80211_CMD_GET_MESH_CONFIG); 6829 if (!hdr) 6830 goto out; 6831 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); 6832 if (!pinfoattr) 6833 goto nla_put_failure; 6834 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6835 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, 6836 cur_params.dot11MeshRetryTimeout) || 6837 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, 6838 cur_params.dot11MeshConfirmTimeout) || 6839 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, 6840 cur_params.dot11MeshHoldingTimeout) || 6841 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, 6842 cur_params.dot11MeshMaxPeerLinks) || 6843 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, 6844 cur_params.dot11MeshMaxRetries) || 6845 nla_put_u8(msg, NL80211_MESHCONF_TTL, 6846 cur_params.dot11MeshTTL) || 6847 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, 6848 cur_params.element_ttl) || 6849 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 6850 cur_params.auto_open_plinks) || 6851 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 6852 cur_params.dot11MeshNbrOffsetMaxNeighbor) || 6853 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 6854 cur_params.dot11MeshHWMPmaxPREQretries) || 6855 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, 6856 cur_params.path_refresh_time) || 6857 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 6858 cur_params.min_discovery_timeout) || 6859 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 6860 cur_params.dot11MeshHWMPactivePathTimeout) || 6861 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 6862 cur_params.dot11MeshHWMPpreqMinInterval) || 6863 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 6864 cur_params.dot11MeshHWMPperrMinInterval) || 6865 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 6866 cur_params.dot11MeshHWMPnetDiameterTraversalTime) || 6867 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, 6868 cur_params.dot11MeshHWMPRootMode) || 6869 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, 6870 cur_params.dot11MeshHWMPRannInterval) || 6871 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 6872 cur_params.dot11MeshGateAnnouncementProtocol) || 6873 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, 6874 cur_params.dot11MeshForwarding) || 6875 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, 6876 cur_params.rssi_threshold) || 6877 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, 6878 cur_params.ht_opmode) || 6879 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 6880 cur_params.dot11MeshHWMPactivePathToRootTimeout) || 6881 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 6882 cur_params.dot11MeshHWMProotInterval) || 6883 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 6884 cur_params.dot11MeshHWMPconfirmationInterval) || 6885 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, 6886 cur_params.power_mode) || 6887 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, 6888 cur_params.dot11MeshAwakeWindowDuration) || 6889 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, 6890 cur_params.plink_timeout) || 6891 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, 6892 cur_params.dot11MeshConnectedToMeshGate) || 6893 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, 6894 cur_params.dot11MeshNolearn) || 6895 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, 6896 cur_params.dot11MeshConnectedToAuthServer)) 6897 goto nla_put_failure; 6898 nla_nest_end(msg, pinfoattr); 6899 genlmsg_end(msg, hdr); 6900 return genlmsg_reply(msg, info); 6901 6902 nla_put_failure: 6903 out: 6904 nlmsg_free(msg); 6905 return -ENOBUFS; 6906 } 6907 6908 static const struct nla_policy 6909 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 6910 [NL80211_MESHCONF_RETRY_TIMEOUT] = 6911 NLA_POLICY_RANGE(NLA_U16, 1, 255), 6912 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = 6913 NLA_POLICY_RANGE(NLA_U16, 1, 255), 6914 [NL80211_MESHCONF_HOLDING_TIMEOUT] = 6915 NLA_POLICY_RANGE(NLA_U16, 1, 255), 6916 [NL80211_MESHCONF_MAX_PEER_LINKS] = 6917 NLA_POLICY_RANGE(NLA_U16, 0, 255), 6918 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), 6919 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 6920 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 6921 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), 6922 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = 6923 NLA_POLICY_RANGE(NLA_U32, 1, 255), 6924 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 6925 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, 6926 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), 6927 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, 6928 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = 6929 NLA_POLICY_MIN(NLA_U16, 1), 6930 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = 6931 NLA_POLICY_MIN(NLA_U16, 1), 6932 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = 6933 NLA_POLICY_MIN(NLA_U16, 1), 6934 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), 6935 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = 6936 NLA_POLICY_MIN(NLA_U16, 1), 6937 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), 6938 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), 6939 [NL80211_MESHCONF_RSSI_THRESHOLD] = 6940 NLA_POLICY_RANGE(NLA_S32, -255, 0), 6941 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, 6942 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 6943 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = 6944 NLA_POLICY_MIN(NLA_U16, 1), 6945 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = 6946 NLA_POLICY_MIN(NLA_U16, 1), 6947 [NL80211_MESHCONF_POWER_MODE] = 6948 NLA_POLICY_RANGE(NLA_U32, 6949 NL80211_MESH_POWER_ACTIVE, 6950 NL80211_MESH_POWER_MAX), 6951 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, 6952 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, 6953 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 6954 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 6955 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 6956 }; 6957 6958 static const struct nla_policy 6959 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { 6960 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, 6961 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, 6962 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, 6963 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, 6964 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, 6965 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, 6966 [NL80211_MESH_SETUP_IE] = 6967 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 6968 IEEE80211_MAX_DATA_LEN), 6969 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, 6970 }; 6971 6972 static int nl80211_parse_mesh_config(struct genl_info *info, 6973 struct mesh_config *cfg, 6974 u32 *mask_out) 6975 { 6976 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 6977 u32 mask = 0; 6978 u16 ht_opmode; 6979 6980 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ 6981 do { \ 6982 if (tb[attr]) { \ 6983 cfg->param = fn(tb[attr]); \ 6984 mask |= BIT((attr) - 1); \ 6985 } \ 6986 } while (0) 6987 6988 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 6989 return -EINVAL; 6990 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) 6991 return -EINVAL; 6992 6993 /* This makes sure that there aren't more than 32 mesh config 6994 * parameters (otherwise our bitfield scheme would not work.) */ 6995 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 6996 6997 /* Fill in the params struct */ 6998 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, 6999 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 7000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, 7001 NL80211_MESHCONF_CONFIRM_TIMEOUT, 7002 nla_get_u16); 7003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, 7004 NL80211_MESHCONF_HOLDING_TIMEOUT, 7005 nla_get_u16); 7006 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, 7007 NL80211_MESHCONF_MAX_PEER_LINKS, 7008 nla_get_u16); 7009 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, 7010 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 7011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, 7012 NL80211_MESHCONF_TTL, nla_get_u8); 7013 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, 7014 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); 7015 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, 7016 NL80211_MESHCONF_AUTO_OPEN_PLINKS, 7017 nla_get_u8); 7018 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, 7019 mask, 7020 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 7021 nla_get_u32); 7022 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, 7023 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 7024 nla_get_u8); 7025 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, 7026 NL80211_MESHCONF_PATH_REFRESH_TIME, 7027 nla_get_u32); 7028 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && 7029 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) 7030 return -EINVAL; 7031 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, 7032 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 7033 nla_get_u16); 7034 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, 7035 mask, 7036 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 7037 nla_get_u32); 7038 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && 7039 (cfg->dot11MeshHWMPactivePathTimeout < 1 || 7040 cfg->dot11MeshHWMPactivePathTimeout > 65535)) 7041 return -EINVAL; 7042 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, 7043 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 7044 nla_get_u16); 7045 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, 7046 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 7047 nla_get_u16); 7048 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 7049 dot11MeshHWMPnetDiameterTraversalTime, mask, 7050 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 7051 nla_get_u16); 7052 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 7053 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 7054 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 7055 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 7056 nla_get_u16); 7057 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, 7058 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 7059 nla_get_u8); 7060 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, 7061 NL80211_MESHCONF_FORWARDING, nla_get_u8); 7062 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, 7063 NL80211_MESHCONF_RSSI_THRESHOLD, 7064 nla_get_s32); 7065 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, 7066 NL80211_MESHCONF_CONNECTED_TO_GATE, 7067 nla_get_u8); 7068 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, 7069 NL80211_MESHCONF_CONNECTED_TO_AS, 7070 nla_get_u8); 7071 /* 7072 * Check HT operation mode based on 7073 * IEEE 802.11-2016 9.4.2.57 HT Operation element. 7074 */ 7075 if (tb[NL80211_MESHCONF_HT_OPMODE]) { 7076 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); 7077 7078 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | 7079 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | 7080 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) 7081 return -EINVAL; 7082 7083 /* NON_HT_STA bit is reserved, but some programs set it */ 7084 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; 7085 7086 cfg->ht_opmode = ht_opmode; 7087 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); 7088 } 7089 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 7090 dot11MeshHWMPactivePathToRootTimeout, mask, 7091 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 7092 nla_get_u32); 7093 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && 7094 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || 7095 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) 7096 return -EINVAL; 7097 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, 7098 NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 7099 nla_get_u16); 7100 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, 7101 mask, 7102 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 7103 nla_get_u16); 7104 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, 7105 NL80211_MESHCONF_POWER_MODE, nla_get_u32); 7106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, 7107 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); 7108 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, 7109 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); 7110 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, 7111 NL80211_MESHCONF_NOLEARN, nla_get_u8); 7112 if (mask_out) 7113 *mask_out = mask; 7114 7115 return 0; 7116 7117 #undef FILL_IN_MESH_PARAM_IF_SET 7118 } 7119 7120 static int nl80211_parse_mesh_setup(struct genl_info *info, 7121 struct mesh_setup *setup) 7122 { 7123 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7124 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; 7125 7126 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 7127 return -EINVAL; 7128 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) 7129 return -EINVAL; 7130 7131 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 7132 setup->sync_method = 7133 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? 7134 IEEE80211_SYNC_METHOD_VENDOR : 7135 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; 7136 7137 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) 7138 setup->path_sel_proto = 7139 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? 7140 IEEE80211_PATH_PROTOCOL_VENDOR : 7141 IEEE80211_PATH_PROTOCOL_HWMP; 7142 7143 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) 7144 setup->path_metric = 7145 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? 7146 IEEE80211_PATH_METRIC_VENDOR : 7147 IEEE80211_PATH_METRIC_AIRTIME; 7148 7149 if (tb[NL80211_MESH_SETUP_IE]) { 7150 struct nlattr *ieattr = 7151 tb[NL80211_MESH_SETUP_IE]; 7152 setup->ie = nla_data(ieattr); 7153 setup->ie_len = nla_len(ieattr); 7154 } 7155 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && 7156 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) 7157 return -EINVAL; 7158 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); 7159 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); 7160 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); 7161 if (setup->is_secure) 7162 setup->user_mpm = true; 7163 7164 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { 7165 if (!setup->user_mpm) 7166 return -EINVAL; 7167 setup->auth_id = 7168 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); 7169 } 7170 7171 return 0; 7172 } 7173 7174 static int nl80211_update_mesh_config(struct sk_buff *skb, 7175 struct genl_info *info) 7176 { 7177 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7178 struct net_device *dev = info->user_ptr[1]; 7179 struct wireless_dev *wdev = dev->ieee80211_ptr; 7180 struct mesh_config cfg; 7181 u32 mask; 7182 int err; 7183 7184 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 7185 return -EOPNOTSUPP; 7186 7187 if (!rdev->ops->update_mesh_config) 7188 return -EOPNOTSUPP; 7189 7190 err = nl80211_parse_mesh_config(info, &cfg, &mask); 7191 if (err) 7192 return err; 7193 7194 wdev_lock(wdev); 7195 if (!wdev->mesh_id_len) 7196 err = -ENOLINK; 7197 7198 if (!err) 7199 err = rdev_update_mesh_config(rdev, dev, mask, &cfg); 7200 7201 wdev_unlock(wdev); 7202 7203 return err; 7204 } 7205 7206 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, 7207 struct sk_buff *msg) 7208 { 7209 struct nlattr *nl_reg_rules; 7210 unsigned int i; 7211 7212 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || 7213 (regdom->dfs_region && 7214 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 7215 goto nla_put_failure; 7216 7217 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); 7218 if (!nl_reg_rules) 7219 goto nla_put_failure; 7220 7221 for (i = 0; i < regdom->n_reg_rules; i++) { 7222 struct nlattr *nl_reg_rule; 7223 const struct ieee80211_reg_rule *reg_rule; 7224 const struct ieee80211_freq_range *freq_range; 7225 const struct ieee80211_power_rule *power_rule; 7226 unsigned int max_bandwidth_khz; 7227 7228 reg_rule = ®dom->reg_rules[i]; 7229 freq_range = ®_rule->freq_range; 7230 power_rule = ®_rule->power_rule; 7231 7232 nl_reg_rule = nla_nest_start_noflag(msg, i); 7233 if (!nl_reg_rule) 7234 goto nla_put_failure; 7235 7236 max_bandwidth_khz = freq_range->max_bandwidth_khz; 7237 if (!max_bandwidth_khz) 7238 max_bandwidth_khz = reg_get_max_bandwidth(regdom, 7239 reg_rule); 7240 7241 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 7242 reg_rule->flags) || 7243 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, 7244 freq_range->start_freq_khz) || 7245 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, 7246 freq_range->end_freq_khz) || 7247 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, 7248 max_bandwidth_khz) || 7249 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, 7250 power_rule->max_antenna_gain) || 7251 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 7252 power_rule->max_eirp) || 7253 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 7254 reg_rule->dfs_cac_ms)) 7255 goto nla_put_failure; 7256 7257 nla_nest_end(msg, nl_reg_rule); 7258 } 7259 7260 nla_nest_end(msg, nl_reg_rules); 7261 return 0; 7262 7263 nla_put_failure: 7264 return -EMSGSIZE; 7265 } 7266 7267 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) 7268 { 7269 const struct ieee80211_regdomain *regdom = NULL; 7270 struct cfg80211_registered_device *rdev; 7271 struct wiphy *wiphy = NULL; 7272 struct sk_buff *msg; 7273 void *hdr; 7274 7275 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7276 if (!msg) 7277 return -ENOBUFS; 7278 7279 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 7280 NL80211_CMD_GET_REG); 7281 if (!hdr) 7282 goto put_failure; 7283 7284 if (info->attrs[NL80211_ATTR_WIPHY]) { 7285 bool self_managed; 7286 7287 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 7288 if (IS_ERR(rdev)) { 7289 nlmsg_free(msg); 7290 return PTR_ERR(rdev); 7291 } 7292 7293 wiphy = &rdev->wiphy; 7294 self_managed = wiphy->regulatory_flags & 7295 REGULATORY_WIPHY_SELF_MANAGED; 7296 regdom = get_wiphy_regdom(wiphy); 7297 7298 /* a self-managed-reg device must have a private regdom */ 7299 if (WARN_ON(!regdom && self_managed)) { 7300 nlmsg_free(msg); 7301 return -EINVAL; 7302 } 7303 7304 if (regdom && 7305 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 7306 goto nla_put_failure; 7307 } 7308 7309 if (!wiphy && reg_last_request_cell_base() && 7310 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 7311 NL80211_USER_REG_HINT_CELL_BASE)) 7312 goto nla_put_failure; 7313 7314 rcu_read_lock(); 7315 7316 if (!regdom) 7317 regdom = rcu_dereference(cfg80211_regdomain); 7318 7319 if (nl80211_put_regdom(regdom, msg)) 7320 goto nla_put_failure_rcu; 7321 7322 rcu_read_unlock(); 7323 7324 genlmsg_end(msg, hdr); 7325 return genlmsg_reply(msg, info); 7326 7327 nla_put_failure_rcu: 7328 rcu_read_unlock(); 7329 nla_put_failure: 7330 put_failure: 7331 nlmsg_free(msg); 7332 return -EMSGSIZE; 7333 } 7334 7335 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, 7336 u32 seq, int flags, struct wiphy *wiphy, 7337 const struct ieee80211_regdomain *regdom) 7338 { 7339 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 7340 NL80211_CMD_GET_REG); 7341 7342 if (!hdr) 7343 return -1; 7344 7345 genl_dump_check_consistent(cb, hdr); 7346 7347 if (nl80211_put_regdom(regdom, msg)) 7348 goto nla_put_failure; 7349 7350 if (!wiphy && reg_last_request_cell_base() && 7351 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 7352 NL80211_USER_REG_HINT_CELL_BASE)) 7353 goto nla_put_failure; 7354 7355 if (wiphy && 7356 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 7357 goto nla_put_failure; 7358 7359 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 7360 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 7361 goto nla_put_failure; 7362 7363 genlmsg_end(msg, hdr); 7364 return 0; 7365 7366 nla_put_failure: 7367 genlmsg_cancel(msg, hdr); 7368 return -EMSGSIZE; 7369 } 7370 7371 static int nl80211_get_reg_dump(struct sk_buff *skb, 7372 struct netlink_callback *cb) 7373 { 7374 const struct ieee80211_regdomain *regdom = NULL; 7375 struct cfg80211_registered_device *rdev; 7376 int err, reg_idx, start = cb->args[2]; 7377 7378 rtnl_lock(); 7379 7380 if (cfg80211_regdomain && start == 0) { 7381 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 7382 NLM_F_MULTI, NULL, 7383 rtnl_dereference(cfg80211_regdomain)); 7384 if (err < 0) 7385 goto out_err; 7386 } 7387 7388 /* the global regdom is idx 0 */ 7389 reg_idx = 1; 7390 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 7391 regdom = get_wiphy_regdom(&rdev->wiphy); 7392 if (!regdom) 7393 continue; 7394 7395 if (++reg_idx <= start) 7396 continue; 7397 7398 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 7399 NLM_F_MULTI, &rdev->wiphy, regdom); 7400 if (err < 0) { 7401 reg_idx--; 7402 break; 7403 } 7404 } 7405 7406 cb->args[2] = reg_idx; 7407 err = skb->len; 7408 out_err: 7409 rtnl_unlock(); 7410 return err; 7411 } 7412 7413 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 7414 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 7415 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 7416 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 7417 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 7418 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 7419 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 7420 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 7421 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, 7422 }; 7423 7424 static int parse_reg_rule(struct nlattr *tb[], 7425 struct ieee80211_reg_rule *reg_rule) 7426 { 7427 struct ieee80211_freq_range *freq_range = ®_rule->freq_range; 7428 struct ieee80211_power_rule *power_rule = ®_rule->power_rule; 7429 7430 if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) 7431 return -EINVAL; 7432 if (!tb[NL80211_ATTR_FREQ_RANGE_START]) 7433 return -EINVAL; 7434 if (!tb[NL80211_ATTR_FREQ_RANGE_END]) 7435 return -EINVAL; 7436 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 7437 return -EINVAL; 7438 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 7439 return -EINVAL; 7440 7441 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); 7442 7443 freq_range->start_freq_khz = 7444 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); 7445 freq_range->end_freq_khz = 7446 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); 7447 freq_range->max_bandwidth_khz = 7448 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); 7449 7450 power_rule->max_eirp = 7451 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); 7452 7453 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) 7454 power_rule->max_antenna_gain = 7455 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); 7456 7457 if (tb[NL80211_ATTR_DFS_CAC_TIME]) 7458 reg_rule->dfs_cac_ms = 7459 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); 7460 7461 return 0; 7462 } 7463 7464 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 7465 { 7466 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 7467 struct nlattr *nl_reg_rule; 7468 char *alpha2; 7469 int rem_reg_rules, r; 7470 u32 num_rules = 0, rule_idx = 0; 7471 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 7472 struct ieee80211_regdomain *rd; 7473 7474 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 7475 return -EINVAL; 7476 7477 if (!info->attrs[NL80211_ATTR_REG_RULES]) 7478 return -EINVAL; 7479 7480 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 7481 7482 if (info->attrs[NL80211_ATTR_DFS_REGION]) 7483 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 7484 7485 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7486 rem_reg_rules) { 7487 num_rules++; 7488 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 7489 return -EINVAL; 7490 } 7491 7492 if (!reg_is_valid_request(alpha2)) 7493 return -EINVAL; 7494 7495 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); 7496 if (!rd) 7497 return -ENOMEM; 7498 7499 rd->n_reg_rules = num_rules; 7500 rd->alpha2[0] = alpha2[0]; 7501 rd->alpha2[1] = alpha2[1]; 7502 7503 /* 7504 * Disable DFS master mode if the DFS region was 7505 * not supported or known on this kernel. 7506 */ 7507 if (reg_supported_dfs_region(dfs_region)) 7508 rd->dfs_region = dfs_region; 7509 7510 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7511 rem_reg_rules) { 7512 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, 7513 nl_reg_rule, reg_rule_policy, 7514 info->extack); 7515 if (r) 7516 goto bad_reg; 7517 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 7518 if (r) 7519 goto bad_reg; 7520 7521 rule_idx++; 7522 7523 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { 7524 r = -EINVAL; 7525 goto bad_reg; 7526 } 7527 } 7528 7529 /* set_regdom takes ownership of rd */ 7530 return set_regdom(rd, REGD_SOURCE_CRDA); 7531 bad_reg: 7532 kfree(rd); 7533 return r; 7534 } 7535 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ 7536 7537 static int validate_scan_freqs(struct nlattr *freqs) 7538 { 7539 struct nlattr *attr1, *attr2; 7540 int n_channels = 0, tmp1, tmp2; 7541 7542 nla_for_each_nested(attr1, freqs, tmp1) 7543 if (nla_len(attr1) != sizeof(u32)) 7544 return 0; 7545 7546 nla_for_each_nested(attr1, freqs, tmp1) { 7547 n_channels++; 7548 /* 7549 * Some hardware has a limited channel list for 7550 * scanning, and it is pretty much nonsensical 7551 * to scan for a channel twice, so disallow that 7552 * and don't require drivers to check that the 7553 * channel list they get isn't longer than what 7554 * they can scan, as long as they can scan all 7555 * the channels they registered at once. 7556 */ 7557 nla_for_each_nested(attr2, freqs, tmp2) 7558 if (attr1 != attr2 && 7559 nla_get_u32(attr1) == nla_get_u32(attr2)) 7560 return 0; 7561 } 7562 7563 return n_channels; 7564 } 7565 7566 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) 7567 { 7568 return b < NUM_NL80211_BANDS && wiphy->bands[b]; 7569 } 7570 7571 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, 7572 struct cfg80211_bss_selection *bss_select) 7573 { 7574 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; 7575 struct nlattr *nest; 7576 int err; 7577 bool found = false; 7578 int i; 7579 7580 /* only process one nested attribute */ 7581 nest = nla_data(nla); 7582 if (!nla_ok(nest, nla_len(nest))) 7583 return -EINVAL; 7584 7585 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, 7586 nest, nl80211_bss_select_policy, 7587 NULL); 7588 if (err) 7589 return err; 7590 7591 /* only one attribute may be given */ 7592 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { 7593 if (attr[i]) { 7594 if (found) 7595 return -EINVAL; 7596 found = true; 7597 } 7598 } 7599 7600 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; 7601 7602 if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) 7603 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; 7604 7605 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { 7606 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; 7607 bss_select->param.band_pref = 7608 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); 7609 if (!is_band_valid(wiphy, bss_select->param.band_pref)) 7610 return -EINVAL; 7611 } 7612 7613 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { 7614 struct nl80211_bss_select_rssi_adjust *adj_param; 7615 7616 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); 7617 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; 7618 bss_select->param.adjust.band = adj_param->band; 7619 bss_select->param.adjust.delta = adj_param->delta; 7620 if (!is_band_valid(wiphy, bss_select->param.adjust.band)) 7621 return -EINVAL; 7622 } 7623 7624 /* user-space did not provide behaviour attribute */ 7625 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) 7626 return -EINVAL; 7627 7628 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) 7629 return -EINVAL; 7630 7631 return 0; 7632 } 7633 7634 int nl80211_parse_random_mac(struct nlattr **attrs, 7635 u8 *mac_addr, u8 *mac_addr_mask) 7636 { 7637 int i; 7638 7639 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { 7640 eth_zero_addr(mac_addr); 7641 eth_zero_addr(mac_addr_mask); 7642 mac_addr[0] = 0x2; 7643 mac_addr_mask[0] = 0x3; 7644 7645 return 0; 7646 } 7647 7648 /* need both or none */ 7649 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) 7650 return -EINVAL; 7651 7652 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); 7653 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); 7654 7655 /* don't allow or configure an mcast address */ 7656 if (!is_multicast_ether_addr(mac_addr_mask) || 7657 is_multicast_ether_addr(mac_addr)) 7658 return -EINVAL; 7659 7660 /* 7661 * allow users to pass a MAC address that has bits set outside 7662 * of the mask, but don't bother drivers with having to deal 7663 * with such bits 7664 */ 7665 for (i = 0; i < ETH_ALEN; i++) 7666 mac_addr[i] &= mac_addr_mask[i]; 7667 7668 return 0; 7669 } 7670 7671 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) 7672 { 7673 ASSERT_WDEV_LOCK(wdev); 7674 7675 if (!cfg80211_beaconing_iface_active(wdev)) 7676 return true; 7677 7678 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) 7679 return true; 7680 7681 return regulatory_pre_cac_allowed(wdev->wiphy); 7682 } 7683 7684 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, 7685 enum nl80211_ext_feature_index feat) 7686 { 7687 if (!(flags & flag)) 7688 return true; 7689 if (wiphy_ext_feature_isset(wiphy, feat)) 7690 return true; 7691 return false; 7692 } 7693 7694 static int 7695 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, 7696 void *request, struct nlattr **attrs, 7697 bool is_sched_scan) 7698 { 7699 u8 *mac_addr, *mac_addr_mask; 7700 u32 *flags; 7701 enum nl80211_feature_flags randomness_flag; 7702 7703 if (!attrs[NL80211_ATTR_SCAN_FLAGS]) 7704 return 0; 7705 7706 if (is_sched_scan) { 7707 struct cfg80211_sched_scan_request *req = request; 7708 7709 randomness_flag = wdev ? 7710 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : 7711 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 7712 flags = &req->flags; 7713 mac_addr = req->mac_addr; 7714 mac_addr_mask = req->mac_addr_mask; 7715 } else { 7716 struct cfg80211_scan_request *req = request; 7717 7718 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 7719 flags = &req->flags; 7720 mac_addr = req->mac_addr; 7721 mac_addr_mask = req->mac_addr_mask; 7722 } 7723 7724 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); 7725 7726 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && 7727 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || 7728 !nl80211_check_scan_feat(wiphy, *flags, 7729 NL80211_SCAN_FLAG_LOW_SPAN, 7730 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || 7731 !nl80211_check_scan_feat(wiphy, *flags, 7732 NL80211_SCAN_FLAG_LOW_POWER, 7733 NL80211_EXT_FEATURE_LOW_POWER_SCAN) || 7734 !nl80211_check_scan_feat(wiphy, *flags, 7735 NL80211_SCAN_FLAG_HIGH_ACCURACY, 7736 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || 7737 !nl80211_check_scan_feat(wiphy, *flags, 7738 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, 7739 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || 7740 !nl80211_check_scan_feat(wiphy, *flags, 7741 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, 7742 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || 7743 !nl80211_check_scan_feat(wiphy, *flags, 7744 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, 7745 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || 7746 !nl80211_check_scan_feat(wiphy, *flags, 7747 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, 7748 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || 7749 !nl80211_check_scan_feat(wiphy, *flags, 7750 NL80211_SCAN_FLAG_RANDOM_SN, 7751 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || 7752 !nl80211_check_scan_feat(wiphy, *flags, 7753 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, 7754 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) 7755 return -EOPNOTSUPP; 7756 7757 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 7758 int err; 7759 7760 if (!(wiphy->features & randomness_flag) || 7761 (wdev && wdev->current_bss)) 7762 return -EOPNOTSUPP; 7763 7764 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); 7765 if (err) 7766 return err; 7767 } 7768 7769 return 0; 7770 } 7771 7772 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 7773 { 7774 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7775 struct wireless_dev *wdev = info->user_ptr[1]; 7776 struct cfg80211_scan_request *request; 7777 struct nlattr *scan_freqs = NULL; 7778 bool scan_freqs_khz = false; 7779 struct nlattr *attr; 7780 struct wiphy *wiphy; 7781 int err, tmp, n_ssids = 0, n_channels, i; 7782 size_t ie_len; 7783 7784 wiphy = &rdev->wiphy; 7785 7786 if (wdev->iftype == NL80211_IFTYPE_NAN) 7787 return -EOPNOTSUPP; 7788 7789 if (!rdev->ops->scan) 7790 return -EOPNOTSUPP; 7791 7792 if (rdev->scan_req || rdev->scan_msg) 7793 return -EBUSY; 7794 7795 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { 7796 if (!wiphy_ext_feature_isset(wiphy, 7797 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) 7798 return -EOPNOTSUPP; 7799 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; 7800 scan_freqs_khz = true; 7801 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) 7802 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; 7803 7804 if (scan_freqs) { 7805 n_channels = validate_scan_freqs(scan_freqs); 7806 if (!n_channels) 7807 return -EINVAL; 7808 } else { 7809 n_channels = ieee80211_get_num_supported_channels(wiphy); 7810 } 7811 7812 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 7813 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 7814 n_ssids++; 7815 7816 if (n_ssids > wiphy->max_scan_ssids) 7817 return -EINVAL; 7818 7819 if (info->attrs[NL80211_ATTR_IE]) 7820 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 7821 else 7822 ie_len = 0; 7823 7824 if (ie_len > wiphy->max_scan_ie_len) 7825 return -EINVAL; 7826 7827 request = kzalloc(sizeof(*request) 7828 + sizeof(*request->ssids) * n_ssids 7829 + sizeof(*request->channels) * n_channels 7830 + ie_len, GFP_KERNEL); 7831 if (!request) 7832 return -ENOMEM; 7833 7834 if (n_ssids) 7835 request->ssids = (void *)&request->channels[n_channels]; 7836 request->n_ssids = n_ssids; 7837 if (ie_len) { 7838 if (n_ssids) 7839 request->ie = (void *)(request->ssids + n_ssids); 7840 else 7841 request->ie = (void *)(request->channels + n_channels); 7842 } 7843 7844 i = 0; 7845 if (scan_freqs) { 7846 /* user specified, bail out if channel not found */ 7847 nla_for_each_nested(attr, scan_freqs, tmp) { 7848 struct ieee80211_channel *chan; 7849 int freq = nla_get_u32(attr); 7850 7851 if (!scan_freqs_khz) 7852 freq = MHZ_TO_KHZ(freq); 7853 7854 chan = ieee80211_get_channel_khz(wiphy, freq); 7855 if (!chan) { 7856 err = -EINVAL; 7857 goto out_free; 7858 } 7859 7860 /* ignore disabled channels */ 7861 if (chan->flags & IEEE80211_CHAN_DISABLED) 7862 continue; 7863 7864 request->channels[i] = chan; 7865 i++; 7866 } 7867 } else { 7868 enum nl80211_band band; 7869 7870 /* all channels */ 7871 for (band = 0; band < NUM_NL80211_BANDS; band++) { 7872 int j; 7873 7874 if (!wiphy->bands[band]) 7875 continue; 7876 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 7877 struct ieee80211_channel *chan; 7878 7879 chan = &wiphy->bands[band]->channels[j]; 7880 7881 if (chan->flags & IEEE80211_CHAN_DISABLED) 7882 continue; 7883 7884 request->channels[i] = chan; 7885 i++; 7886 } 7887 } 7888 } 7889 7890 if (!i) { 7891 err = -EINVAL; 7892 goto out_free; 7893 } 7894 7895 request->n_channels = i; 7896 7897 wdev_lock(wdev); 7898 if (!cfg80211_off_channel_oper_allowed(wdev)) { 7899 struct ieee80211_channel *chan; 7900 7901 if (request->n_channels != 1) { 7902 wdev_unlock(wdev); 7903 err = -EBUSY; 7904 goto out_free; 7905 } 7906 7907 chan = request->channels[0]; 7908 if (chan->center_freq != wdev->chandef.chan->center_freq) { 7909 wdev_unlock(wdev); 7910 err = -EBUSY; 7911 goto out_free; 7912 } 7913 } 7914 wdev_unlock(wdev); 7915 7916 i = 0; 7917 if (n_ssids) { 7918 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 7919 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 7920 err = -EINVAL; 7921 goto out_free; 7922 } 7923 request->ssids[i].ssid_len = nla_len(attr); 7924 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); 7925 i++; 7926 } 7927 } 7928 7929 if (info->attrs[NL80211_ATTR_IE]) { 7930 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 7931 memcpy((void *)request->ie, 7932 nla_data(info->attrs[NL80211_ATTR_IE]), 7933 request->ie_len); 7934 } 7935 7936 for (i = 0; i < NUM_NL80211_BANDS; i++) 7937 if (wiphy->bands[i]) 7938 request->rates[i] = 7939 (1 << wiphy->bands[i]->n_bitrates) - 1; 7940 7941 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { 7942 nla_for_each_nested(attr, 7943 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], 7944 tmp) { 7945 enum nl80211_band band = nla_type(attr); 7946 7947 if (band < 0 || band >= NUM_NL80211_BANDS) { 7948 err = -EINVAL; 7949 goto out_free; 7950 } 7951 7952 if (!wiphy->bands[band]) 7953 continue; 7954 7955 err = ieee80211_get_ratemask(wiphy->bands[band], 7956 nla_data(attr), 7957 nla_len(attr), 7958 &request->rates[band]); 7959 if (err) 7960 goto out_free; 7961 } 7962 } 7963 7964 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { 7965 if (!wiphy_ext_feature_isset(wiphy, 7966 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { 7967 err = -EOPNOTSUPP; 7968 goto out_free; 7969 } 7970 7971 request->duration = 7972 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); 7973 request->duration_mandatory = 7974 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); 7975 } 7976 7977 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, 7978 false); 7979 if (err) 7980 goto out_free; 7981 7982 request->no_cck = 7983 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 7984 7985 /* Initial implementation used NL80211_ATTR_MAC to set the specific 7986 * BSSID to scan for. This was problematic because that same attribute 7987 * was already used for another purpose (local random MAC address). The 7988 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards 7989 * compatibility with older userspace components, also use the 7990 * NL80211_ATTR_MAC value here if it can be determined to be used for 7991 * the specific BSSID use case instead of the random MAC address 7992 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). 7993 */ 7994 if (info->attrs[NL80211_ATTR_BSSID]) 7995 memcpy(request->bssid, 7996 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); 7997 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && 7998 info->attrs[NL80211_ATTR_MAC]) 7999 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), 8000 ETH_ALEN); 8001 else 8002 eth_broadcast_addr(request->bssid); 8003 8004 request->wdev = wdev; 8005 request->wiphy = &rdev->wiphy; 8006 request->scan_start = jiffies; 8007 8008 rdev->scan_req = request; 8009 err = rdev_scan(rdev, request); 8010 8011 if (err) 8012 goto out_free; 8013 8014 nl80211_send_scan_start(rdev, wdev); 8015 if (wdev->netdev) 8016 dev_hold(wdev->netdev); 8017 8018 return 0; 8019 8020 out_free: 8021 rdev->scan_req = NULL; 8022 kfree(request); 8023 8024 return err; 8025 } 8026 8027 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) 8028 { 8029 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8030 struct wireless_dev *wdev = info->user_ptr[1]; 8031 8032 if (!rdev->ops->abort_scan) 8033 return -EOPNOTSUPP; 8034 8035 if (rdev->scan_msg) 8036 return 0; 8037 8038 if (!rdev->scan_req) 8039 return -ENOENT; 8040 8041 rdev_abort_scan(rdev, wdev); 8042 return 0; 8043 } 8044 8045 static int 8046 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, 8047 struct cfg80211_sched_scan_request *request, 8048 struct nlattr **attrs) 8049 { 8050 int tmp, err, i = 0; 8051 struct nlattr *attr; 8052 8053 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 8054 u32 interval; 8055 8056 /* 8057 * If scan plans are not specified, 8058 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this 8059 * case one scan plan will be set with the specified scan 8060 * interval and infinite number of iterations. 8061 */ 8062 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); 8063 if (!interval) 8064 return -EINVAL; 8065 8066 request->scan_plans[0].interval = 8067 DIV_ROUND_UP(interval, MSEC_PER_SEC); 8068 if (!request->scan_plans[0].interval) 8069 return -EINVAL; 8070 8071 if (request->scan_plans[0].interval > 8072 wiphy->max_sched_scan_plan_interval) 8073 request->scan_plans[0].interval = 8074 wiphy->max_sched_scan_plan_interval; 8075 8076 return 0; 8077 } 8078 8079 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { 8080 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; 8081 8082 if (WARN_ON(i >= n_plans)) 8083 return -EINVAL; 8084 8085 err = nla_parse_nested_deprecated(plan, 8086 NL80211_SCHED_SCAN_PLAN_MAX, 8087 attr, nl80211_plan_policy, 8088 NULL); 8089 if (err) 8090 return err; 8091 8092 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) 8093 return -EINVAL; 8094 8095 request->scan_plans[i].interval = 8096 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); 8097 if (!request->scan_plans[i].interval || 8098 request->scan_plans[i].interval > 8099 wiphy->max_sched_scan_plan_interval) 8100 return -EINVAL; 8101 8102 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { 8103 request->scan_plans[i].iterations = 8104 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); 8105 if (!request->scan_plans[i].iterations || 8106 (request->scan_plans[i].iterations > 8107 wiphy->max_sched_scan_plan_iterations)) 8108 return -EINVAL; 8109 } else if (i < n_plans - 1) { 8110 /* 8111 * All scan plans but the last one must specify 8112 * a finite number of iterations 8113 */ 8114 return -EINVAL; 8115 } 8116 8117 i++; 8118 } 8119 8120 /* 8121 * The last scan plan must not specify the number of 8122 * iterations, it is supposed to run infinitely 8123 */ 8124 if (request->scan_plans[n_plans - 1].iterations) 8125 return -EINVAL; 8126 8127 return 0; 8128 } 8129 8130 static int 8131 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, 8132 struct cfg80211_match_set *match_sets, 8133 struct nlattr *tb_band_rssi, 8134 s32 rssi_thold) 8135 { 8136 struct nlattr *attr; 8137 int i, tmp, ret = 0; 8138 8139 if (!wiphy_ext_feature_isset(wiphy, 8140 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { 8141 if (tb_band_rssi) 8142 ret = -EOPNOTSUPP; 8143 else 8144 for (i = 0; i < NUM_NL80211_BANDS; i++) 8145 match_sets->per_band_rssi_thold[i] = 8146 NL80211_SCAN_RSSI_THOLD_OFF; 8147 return ret; 8148 } 8149 8150 for (i = 0; i < NUM_NL80211_BANDS; i++) 8151 match_sets->per_band_rssi_thold[i] = rssi_thold; 8152 8153 nla_for_each_nested(attr, tb_band_rssi, tmp) { 8154 enum nl80211_band band = nla_type(attr); 8155 8156 if (band < 0 || band >= NUM_NL80211_BANDS) 8157 return -EINVAL; 8158 8159 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); 8160 } 8161 8162 return 0; 8163 } 8164 8165 static struct cfg80211_sched_scan_request * 8166 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 8167 struct nlattr **attrs, int max_match_sets) 8168 { 8169 struct cfg80211_sched_scan_request *request; 8170 struct nlattr *attr; 8171 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; 8172 enum nl80211_band band; 8173 size_t ie_len; 8174 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; 8175 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; 8176 8177 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 8178 n_channels = validate_scan_freqs( 8179 attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 8180 if (!n_channels) 8181 return ERR_PTR(-EINVAL); 8182 } else { 8183 n_channels = ieee80211_get_num_supported_channels(wiphy); 8184 } 8185 8186 if (attrs[NL80211_ATTR_SCAN_SSIDS]) 8187 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 8188 tmp) 8189 n_ssids++; 8190 8191 if (n_ssids > wiphy->max_sched_scan_ssids) 8192 return ERR_PTR(-EINVAL); 8193 8194 /* 8195 * First, count the number of 'real' matchsets. Due to an issue with 8196 * the old implementation, matchsets containing only the RSSI attribute 8197 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' 8198 * RSSI for all matchsets, rather than their own matchset for reporting 8199 * all APs with a strong RSSI. This is needed to be compatible with 8200 * older userspace that treated a matchset with only the RSSI as the 8201 * global RSSI for all other matchsets - if there are other matchsets. 8202 */ 8203 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 8204 nla_for_each_nested(attr, 8205 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 8206 tmp) { 8207 struct nlattr *rssi; 8208 8209 err = nla_parse_nested_deprecated(tb, 8210 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 8211 attr, 8212 nl80211_match_policy, 8213 NULL); 8214 if (err) 8215 return ERR_PTR(err); 8216 8217 /* SSID and BSSID are mutually exclusive */ 8218 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && 8219 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) 8220 return ERR_PTR(-EINVAL); 8221 8222 /* add other standalone attributes here */ 8223 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || 8224 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { 8225 n_match_sets++; 8226 continue; 8227 } 8228 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 8229 if (rssi) 8230 default_match_rssi = nla_get_s32(rssi); 8231 } 8232 } 8233 8234 /* However, if there's no other matchset, add the RSSI one */ 8235 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) 8236 n_match_sets = 1; 8237 8238 if (n_match_sets > max_match_sets) 8239 return ERR_PTR(-EINVAL); 8240 8241 if (attrs[NL80211_ATTR_IE]) 8242 ie_len = nla_len(attrs[NL80211_ATTR_IE]); 8243 else 8244 ie_len = 0; 8245 8246 if (ie_len > wiphy->max_sched_scan_ie_len) 8247 return ERR_PTR(-EINVAL); 8248 8249 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 8250 /* 8251 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since 8252 * each scan plan already specifies its own interval 8253 */ 8254 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 8255 return ERR_PTR(-EINVAL); 8256 8257 nla_for_each_nested(attr, 8258 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) 8259 n_plans++; 8260 } else { 8261 /* 8262 * The scan interval attribute is kept for backward 8263 * compatibility. If no scan plans are specified and sched scan 8264 * interval is specified, one scan plan will be set with this 8265 * scan interval and infinite number of iterations. 8266 */ 8267 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 8268 return ERR_PTR(-EINVAL); 8269 8270 n_plans = 1; 8271 } 8272 8273 if (!n_plans || n_plans > wiphy->max_sched_scan_plans) 8274 return ERR_PTR(-EINVAL); 8275 8276 if (!wiphy_ext_feature_isset( 8277 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && 8278 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || 8279 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) 8280 return ERR_PTR(-EINVAL); 8281 8282 request = kzalloc(sizeof(*request) 8283 + sizeof(*request->ssids) * n_ssids 8284 + sizeof(*request->match_sets) * n_match_sets 8285 + sizeof(*request->scan_plans) * n_plans 8286 + sizeof(*request->channels) * n_channels 8287 + ie_len, GFP_KERNEL); 8288 if (!request) 8289 return ERR_PTR(-ENOMEM); 8290 8291 if (n_ssids) 8292 request->ssids = (void *)&request->channels[n_channels]; 8293 request->n_ssids = n_ssids; 8294 if (ie_len) { 8295 if (n_ssids) 8296 request->ie = (void *)(request->ssids + n_ssids); 8297 else 8298 request->ie = (void *)(request->channels + n_channels); 8299 } 8300 8301 if (n_match_sets) { 8302 if (request->ie) 8303 request->match_sets = (void *)(request->ie + ie_len); 8304 else if (n_ssids) 8305 request->match_sets = 8306 (void *)(request->ssids + n_ssids); 8307 else 8308 request->match_sets = 8309 (void *)(request->channels + n_channels); 8310 } 8311 request->n_match_sets = n_match_sets; 8312 8313 if (n_match_sets) 8314 request->scan_plans = (void *)(request->match_sets + 8315 n_match_sets); 8316 else if (request->ie) 8317 request->scan_plans = (void *)(request->ie + ie_len); 8318 else if (n_ssids) 8319 request->scan_plans = (void *)(request->ssids + n_ssids); 8320 else 8321 request->scan_plans = (void *)(request->channels + n_channels); 8322 8323 request->n_scan_plans = n_plans; 8324 8325 i = 0; 8326 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 8327 /* user specified, bail out if channel not found */ 8328 nla_for_each_nested(attr, 8329 attrs[NL80211_ATTR_SCAN_FREQUENCIES], 8330 tmp) { 8331 struct ieee80211_channel *chan; 8332 8333 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 8334 8335 if (!chan) { 8336 err = -EINVAL; 8337 goto out_free; 8338 } 8339 8340 /* ignore disabled channels */ 8341 if (chan->flags & IEEE80211_CHAN_DISABLED) 8342 continue; 8343 8344 request->channels[i] = chan; 8345 i++; 8346 } 8347 } else { 8348 /* all channels */ 8349 for (band = 0; band < NUM_NL80211_BANDS; band++) { 8350 int j; 8351 8352 if (!wiphy->bands[band]) 8353 continue; 8354 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 8355 struct ieee80211_channel *chan; 8356 8357 chan = &wiphy->bands[band]->channels[j]; 8358 8359 if (chan->flags & IEEE80211_CHAN_DISABLED) 8360 continue; 8361 8362 request->channels[i] = chan; 8363 i++; 8364 } 8365 } 8366 } 8367 8368 if (!i) { 8369 err = -EINVAL; 8370 goto out_free; 8371 } 8372 8373 request->n_channels = i; 8374 8375 i = 0; 8376 if (n_ssids) { 8377 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 8378 tmp) { 8379 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 8380 err = -EINVAL; 8381 goto out_free; 8382 } 8383 request->ssids[i].ssid_len = nla_len(attr); 8384 memcpy(request->ssids[i].ssid, nla_data(attr), 8385 nla_len(attr)); 8386 i++; 8387 } 8388 } 8389 8390 i = 0; 8391 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 8392 nla_for_each_nested(attr, 8393 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 8394 tmp) { 8395 struct nlattr *ssid, *bssid, *rssi; 8396 8397 err = nla_parse_nested_deprecated(tb, 8398 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 8399 attr, 8400 nl80211_match_policy, 8401 NULL); 8402 if (err) 8403 goto out_free; 8404 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 8405 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 8406 8407 if (!ssid && !bssid) { 8408 i++; 8409 continue; 8410 } 8411 8412 if (WARN_ON(i >= n_match_sets)) { 8413 /* this indicates a programming error, 8414 * the loop above should have verified 8415 * things properly 8416 */ 8417 err = -EINVAL; 8418 goto out_free; 8419 } 8420 8421 if (ssid) { 8422 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { 8423 err = -EINVAL; 8424 goto out_free; 8425 } 8426 memcpy(request->match_sets[i].ssid.ssid, 8427 nla_data(ssid), nla_len(ssid)); 8428 request->match_sets[i].ssid.ssid_len = 8429 nla_len(ssid); 8430 } 8431 if (bssid) { 8432 if (nla_len(bssid) != ETH_ALEN) { 8433 err = -EINVAL; 8434 goto out_free; 8435 } 8436 memcpy(request->match_sets[i].bssid, 8437 nla_data(bssid), ETH_ALEN); 8438 } 8439 8440 /* special attribute - old implementation w/a */ 8441 request->match_sets[i].rssi_thold = default_match_rssi; 8442 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 8443 if (rssi) 8444 request->match_sets[i].rssi_thold = 8445 nla_get_s32(rssi); 8446 8447 /* Parse per band RSSI attribute */ 8448 err = nl80211_parse_sched_scan_per_band_rssi(wiphy, 8449 &request->match_sets[i], 8450 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], 8451 request->match_sets[i].rssi_thold); 8452 if (err) 8453 goto out_free; 8454 8455 i++; 8456 } 8457 8458 /* there was no other matchset, so the RSSI one is alone */ 8459 if (i == 0 && n_match_sets) 8460 request->match_sets[0].rssi_thold = default_match_rssi; 8461 8462 request->min_rssi_thold = INT_MAX; 8463 for (i = 0; i < n_match_sets; i++) 8464 request->min_rssi_thold = 8465 min(request->match_sets[i].rssi_thold, 8466 request->min_rssi_thold); 8467 } else { 8468 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; 8469 } 8470 8471 if (ie_len) { 8472 request->ie_len = ie_len; 8473 memcpy((void *)request->ie, 8474 nla_data(attrs[NL80211_ATTR_IE]), 8475 request->ie_len); 8476 } 8477 8478 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); 8479 if (err) 8480 goto out_free; 8481 8482 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) 8483 request->delay = 8484 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); 8485 8486 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { 8487 request->relative_rssi = nla_get_s8( 8488 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); 8489 request->relative_rssi_set = true; 8490 } 8491 8492 if (request->relative_rssi_set && 8493 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { 8494 struct nl80211_bss_select_rssi_adjust *rssi_adjust; 8495 8496 rssi_adjust = nla_data( 8497 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); 8498 request->rssi_adjust.band = rssi_adjust->band; 8499 request->rssi_adjust.delta = rssi_adjust->delta; 8500 if (!is_band_valid(wiphy, request->rssi_adjust.band)) { 8501 err = -EINVAL; 8502 goto out_free; 8503 } 8504 } 8505 8506 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); 8507 if (err) 8508 goto out_free; 8509 8510 request->scan_start = jiffies; 8511 8512 return request; 8513 8514 out_free: 8515 kfree(request); 8516 return ERR_PTR(err); 8517 } 8518 8519 static int nl80211_start_sched_scan(struct sk_buff *skb, 8520 struct genl_info *info) 8521 { 8522 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8523 struct net_device *dev = info->user_ptr[1]; 8524 struct wireless_dev *wdev = dev->ieee80211_ptr; 8525 struct cfg80211_sched_scan_request *sched_scan_req; 8526 bool want_multi; 8527 int err; 8528 8529 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) 8530 return -EOPNOTSUPP; 8531 8532 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; 8533 err = cfg80211_sched_scan_req_possible(rdev, want_multi); 8534 if (err) 8535 return err; 8536 8537 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, 8538 info->attrs, 8539 rdev->wiphy.max_match_sets); 8540 8541 err = PTR_ERR_OR_ZERO(sched_scan_req); 8542 if (err) 8543 goto out_err; 8544 8545 /* leave request id zero for legacy request 8546 * or if driver does not support multi-scheduled scan 8547 */ 8548 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) 8549 sched_scan_req->reqid = cfg80211_assign_cookie(rdev); 8550 8551 err = rdev_sched_scan_start(rdev, dev, sched_scan_req); 8552 if (err) 8553 goto out_free; 8554 8555 sched_scan_req->dev = dev; 8556 sched_scan_req->wiphy = &rdev->wiphy; 8557 8558 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 8559 sched_scan_req->owner_nlportid = info->snd_portid; 8560 8561 cfg80211_add_sched_scan_req(rdev, sched_scan_req); 8562 8563 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); 8564 return 0; 8565 8566 out_free: 8567 kfree(sched_scan_req); 8568 out_err: 8569 return err; 8570 } 8571 8572 static int nl80211_stop_sched_scan(struct sk_buff *skb, 8573 struct genl_info *info) 8574 { 8575 struct cfg80211_sched_scan_request *req; 8576 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8577 u64 cookie; 8578 8579 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) 8580 return -EOPNOTSUPP; 8581 8582 if (info->attrs[NL80211_ATTR_COOKIE]) { 8583 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 8584 return __cfg80211_stop_sched_scan(rdev, cookie, false); 8585 } 8586 8587 req = list_first_or_null_rcu(&rdev->sched_scan_req_list, 8588 struct cfg80211_sched_scan_request, 8589 list); 8590 if (!req || req->reqid || 8591 (req->owner_nlportid && 8592 req->owner_nlportid != info->snd_portid)) 8593 return -ENOENT; 8594 8595 return cfg80211_stop_sched_scan_req(rdev, req, false); 8596 } 8597 8598 static int nl80211_start_radar_detection(struct sk_buff *skb, 8599 struct genl_info *info) 8600 { 8601 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8602 struct net_device *dev = info->user_ptr[1]; 8603 struct wireless_dev *wdev = dev->ieee80211_ptr; 8604 struct wiphy *wiphy = wdev->wiphy; 8605 struct cfg80211_chan_def chandef; 8606 enum nl80211_dfs_regions dfs_region; 8607 unsigned int cac_time_ms; 8608 int err; 8609 8610 dfs_region = reg_get_dfs_region(wiphy); 8611 if (dfs_region == NL80211_DFS_UNSET) 8612 return -EINVAL; 8613 8614 err = nl80211_parse_chandef(rdev, info, &chandef); 8615 if (err) 8616 return err; 8617 8618 if (netif_carrier_ok(dev)) 8619 return -EBUSY; 8620 8621 if (wdev->cac_started) 8622 return -EBUSY; 8623 8624 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 8625 if (err < 0) 8626 return err; 8627 8628 if (err == 0) 8629 return -EINVAL; 8630 8631 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) 8632 return -EINVAL; 8633 8634 /* CAC start is offloaded to HW and can't be started manually */ 8635 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) 8636 return -EOPNOTSUPP; 8637 8638 if (!rdev->ops->start_radar_detection) 8639 return -EOPNOTSUPP; 8640 8641 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 8642 if (WARN_ON(!cac_time_ms)) 8643 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; 8644 8645 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); 8646 if (!err) { 8647 wdev->chandef = chandef; 8648 wdev->cac_started = true; 8649 wdev->cac_start_time = jiffies; 8650 wdev->cac_time_ms = cac_time_ms; 8651 } 8652 return err; 8653 } 8654 8655 static int nl80211_notify_radar_detection(struct sk_buff *skb, 8656 struct genl_info *info) 8657 { 8658 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8659 struct net_device *dev = info->user_ptr[1]; 8660 struct wireless_dev *wdev = dev->ieee80211_ptr; 8661 struct wiphy *wiphy = wdev->wiphy; 8662 struct cfg80211_chan_def chandef; 8663 enum nl80211_dfs_regions dfs_region; 8664 int err; 8665 8666 dfs_region = reg_get_dfs_region(wiphy); 8667 if (dfs_region == NL80211_DFS_UNSET) { 8668 GENL_SET_ERR_MSG(info, 8669 "DFS Region is not set. Unexpected Radar indication"); 8670 return -EINVAL; 8671 } 8672 8673 err = nl80211_parse_chandef(rdev, info, &chandef); 8674 if (err) { 8675 GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); 8676 return err; 8677 } 8678 8679 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 8680 if (err < 0) { 8681 GENL_SET_ERR_MSG(info, "chandef is invalid"); 8682 return err; 8683 } 8684 8685 if (err == 0) { 8686 GENL_SET_ERR_MSG(info, 8687 "Unexpected Radar indication for chandef/iftype"); 8688 return -EINVAL; 8689 } 8690 8691 /* Do not process this notification if radar is already detected 8692 * by kernel on this channel, and return success. 8693 */ 8694 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) 8695 return 0; 8696 8697 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); 8698 8699 cfg80211_sched_dfs_chan_update(rdev); 8700 8701 rdev->radar_chandef = chandef; 8702 8703 /* Propagate this notification to other radios as well */ 8704 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 8705 8706 return 0; 8707 } 8708 8709 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) 8710 { 8711 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8712 struct net_device *dev = info->user_ptr[1]; 8713 struct wireless_dev *wdev = dev->ieee80211_ptr; 8714 struct cfg80211_csa_settings params; 8715 /* csa_attrs is defined static to avoid waste of stack size - this 8716 * function is called under RTNL lock, so this should not be a problem. 8717 */ 8718 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; 8719 int err; 8720 bool need_new_beacon = false; 8721 bool need_handle_dfs_flag = true; 8722 int len, i; 8723 u32 cs_count; 8724 8725 if (!rdev->ops->channel_switch || 8726 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 8727 return -EOPNOTSUPP; 8728 8729 switch (dev->ieee80211_ptr->iftype) { 8730 case NL80211_IFTYPE_AP: 8731 case NL80211_IFTYPE_P2P_GO: 8732 need_new_beacon = true; 8733 /* For all modes except AP the handle_dfs flag needs to be 8734 * supplied to tell the kernel that userspace will handle radar 8735 * events when they happen. Otherwise a switch to a channel 8736 * requiring DFS will be rejected. 8737 */ 8738 need_handle_dfs_flag = false; 8739 8740 /* useless if AP is not running */ 8741 if (!wdev->beacon_interval) 8742 return -ENOTCONN; 8743 break; 8744 case NL80211_IFTYPE_ADHOC: 8745 if (!wdev->ssid_len) 8746 return -ENOTCONN; 8747 break; 8748 case NL80211_IFTYPE_MESH_POINT: 8749 if (!wdev->mesh_id_len) 8750 return -ENOTCONN; 8751 break; 8752 default: 8753 return -EOPNOTSUPP; 8754 } 8755 8756 memset(¶ms, 0, sizeof(params)); 8757 params.beacon_csa.ftm_responder = -1; 8758 8759 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 8760 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) 8761 return -EINVAL; 8762 8763 /* only important for AP, IBSS and mesh create IEs internally */ 8764 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) 8765 return -EINVAL; 8766 8767 /* Even though the attribute is u32, the specification says 8768 * u8, so let's make sure we don't overflow. 8769 */ 8770 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); 8771 if (cs_count > 255) 8772 return -EINVAL; 8773 8774 params.count = cs_count; 8775 8776 if (!need_new_beacon) 8777 goto skip_beacons; 8778 8779 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); 8780 if (err) 8781 return err; 8782 8783 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, 8784 info->attrs[NL80211_ATTR_CSA_IES], 8785 nl80211_policy, info->extack); 8786 if (err) 8787 return err; 8788 8789 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); 8790 if (err) 8791 return err; 8792 8793 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) 8794 return -EINVAL; 8795 8796 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); 8797 if (!len || (len % sizeof(u16))) 8798 return -EINVAL; 8799 8800 params.n_counter_offsets_beacon = len / sizeof(u16); 8801 if (rdev->wiphy.max_num_csa_counters && 8802 (params.n_counter_offsets_beacon > 8803 rdev->wiphy.max_num_csa_counters)) 8804 return -EINVAL; 8805 8806 params.counter_offsets_beacon = 8807 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); 8808 8809 /* sanity checks - counters should fit and be the same */ 8810 for (i = 0; i < params.n_counter_offsets_beacon; i++) { 8811 u16 offset = params.counter_offsets_beacon[i]; 8812 8813 if (offset >= params.beacon_csa.tail_len) 8814 return -EINVAL; 8815 8816 if (params.beacon_csa.tail[offset] != params.count) 8817 return -EINVAL; 8818 } 8819 8820 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { 8821 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); 8822 if (!len || (len % sizeof(u16))) 8823 return -EINVAL; 8824 8825 params.n_counter_offsets_presp = len / sizeof(u16); 8826 if (rdev->wiphy.max_num_csa_counters && 8827 (params.n_counter_offsets_presp > 8828 rdev->wiphy.max_num_csa_counters)) 8829 return -EINVAL; 8830 8831 params.counter_offsets_presp = 8832 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); 8833 8834 /* sanity checks - counters should fit and be the same */ 8835 for (i = 0; i < params.n_counter_offsets_presp; i++) { 8836 u16 offset = params.counter_offsets_presp[i]; 8837 8838 if (offset >= params.beacon_csa.probe_resp_len) 8839 return -EINVAL; 8840 8841 if (params.beacon_csa.probe_resp[offset] != 8842 params.count) 8843 return -EINVAL; 8844 } 8845 } 8846 8847 skip_beacons: 8848 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 8849 if (err) 8850 return err; 8851 8852 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 8853 wdev->iftype)) 8854 return -EINVAL; 8855 8856 err = cfg80211_chandef_dfs_required(wdev->wiphy, 8857 ¶ms.chandef, 8858 wdev->iftype); 8859 if (err < 0) 8860 return err; 8861 8862 if (err > 0) { 8863 params.radar_required = true; 8864 if (need_handle_dfs_flag && 8865 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { 8866 return -EINVAL; 8867 } 8868 } 8869 8870 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 8871 params.block_tx = true; 8872 8873 wdev_lock(wdev); 8874 err = rdev_channel_switch(rdev, dev, ¶ms); 8875 wdev_unlock(wdev); 8876 8877 return err; 8878 } 8879 8880 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, 8881 u32 seq, int flags, 8882 struct cfg80211_registered_device *rdev, 8883 struct wireless_dev *wdev, 8884 struct cfg80211_internal_bss *intbss) 8885 { 8886 struct cfg80211_bss *res = &intbss->pub; 8887 const struct cfg80211_bss_ies *ies; 8888 void *hdr; 8889 struct nlattr *bss; 8890 8891 ASSERT_WDEV_LOCK(wdev); 8892 8893 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 8894 NL80211_CMD_NEW_SCAN_RESULTS); 8895 if (!hdr) 8896 return -1; 8897 8898 genl_dump_check_consistent(cb, hdr); 8899 8900 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) 8901 goto nla_put_failure; 8902 if (wdev->netdev && 8903 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) 8904 goto nla_put_failure; 8905 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 8906 NL80211_ATTR_PAD)) 8907 goto nla_put_failure; 8908 8909 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); 8910 if (!bss) 8911 goto nla_put_failure; 8912 if ((!is_zero_ether_addr(res->bssid) && 8913 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) 8914 goto nla_put_failure; 8915 8916 rcu_read_lock(); 8917 /* indicate whether we have probe response data or not */ 8918 if (rcu_access_pointer(res->proberesp_ies) && 8919 nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) 8920 goto fail_unlock_rcu; 8921 8922 /* this pointer prefers to be pointed to probe response data 8923 * but is always valid 8924 */ 8925 ies = rcu_dereference(res->ies); 8926 if (ies) { 8927 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, 8928 NL80211_BSS_PAD)) 8929 goto fail_unlock_rcu; 8930 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, 8931 ies->len, ies->data)) 8932 goto fail_unlock_rcu; 8933 } 8934 8935 /* and this pointer is always (unless driver didn't know) beacon data */ 8936 ies = rcu_dereference(res->beacon_ies); 8937 if (ies && ies->from_beacon) { 8938 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, 8939 NL80211_BSS_PAD)) 8940 goto fail_unlock_rcu; 8941 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, 8942 ies->len, ies->data)) 8943 goto fail_unlock_rcu; 8944 } 8945 rcu_read_unlock(); 8946 8947 if (res->beacon_interval && 8948 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) 8949 goto nla_put_failure; 8950 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || 8951 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || 8952 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, 8953 res->channel->freq_offset) || 8954 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || 8955 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, 8956 jiffies_to_msecs(jiffies - intbss->ts))) 8957 goto nla_put_failure; 8958 8959 if (intbss->parent_tsf && 8960 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, 8961 intbss->parent_tsf, NL80211_BSS_PAD) || 8962 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, 8963 intbss->parent_bssid))) 8964 goto nla_put_failure; 8965 8966 if (intbss->ts_boottime && 8967 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, 8968 intbss->ts_boottime, NL80211_BSS_PAD)) 8969 goto nla_put_failure; 8970 8971 if (!nl80211_put_signal(msg, intbss->pub.chains, 8972 intbss->pub.chain_signal, 8973 NL80211_BSS_CHAIN_SIGNAL)) 8974 goto nla_put_failure; 8975 8976 switch (rdev->wiphy.signal_type) { 8977 case CFG80211_SIGNAL_TYPE_MBM: 8978 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) 8979 goto nla_put_failure; 8980 break; 8981 case CFG80211_SIGNAL_TYPE_UNSPEC: 8982 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) 8983 goto nla_put_failure; 8984 break; 8985 default: 8986 break; 8987 } 8988 8989 switch (wdev->iftype) { 8990 case NL80211_IFTYPE_P2P_CLIENT: 8991 case NL80211_IFTYPE_STATION: 8992 if (intbss == wdev->current_bss && 8993 nla_put_u32(msg, NL80211_BSS_STATUS, 8994 NL80211_BSS_STATUS_ASSOCIATED)) 8995 goto nla_put_failure; 8996 break; 8997 case NL80211_IFTYPE_ADHOC: 8998 if (intbss == wdev->current_bss && 8999 nla_put_u32(msg, NL80211_BSS_STATUS, 9000 NL80211_BSS_STATUS_IBSS_JOINED)) 9001 goto nla_put_failure; 9002 break; 9003 default: 9004 break; 9005 } 9006 9007 nla_nest_end(msg, bss); 9008 9009 genlmsg_end(msg, hdr); 9010 return 0; 9011 9012 fail_unlock_rcu: 9013 rcu_read_unlock(); 9014 nla_put_failure: 9015 genlmsg_cancel(msg, hdr); 9016 return -EMSGSIZE; 9017 } 9018 9019 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) 9020 { 9021 struct cfg80211_registered_device *rdev; 9022 struct cfg80211_internal_bss *scan; 9023 struct wireless_dev *wdev; 9024 int start = cb->args[2], idx = 0; 9025 int err; 9026 9027 rtnl_lock(); 9028 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 9029 if (err) { 9030 rtnl_unlock(); 9031 return err; 9032 } 9033 9034 wdev_lock(wdev); 9035 spin_lock_bh(&rdev->bss_lock); 9036 9037 /* 9038 * dump_scan will be called multiple times to break up the scan results 9039 * into multiple messages. It is unlikely that any more bss-es will be 9040 * expired after the first call, so only call only call this on the 9041 * first dump_scan invocation. 9042 */ 9043 if (start == 0) 9044 cfg80211_bss_expire(rdev); 9045 9046 cb->seq = rdev->bss_generation; 9047 9048 list_for_each_entry(scan, &rdev->bss_list, list) { 9049 if (++idx <= start) 9050 continue; 9051 if (nl80211_send_bss(skb, cb, 9052 cb->nlh->nlmsg_seq, NLM_F_MULTI, 9053 rdev, wdev, scan) < 0) { 9054 idx--; 9055 break; 9056 } 9057 } 9058 9059 spin_unlock_bh(&rdev->bss_lock); 9060 wdev_unlock(wdev); 9061 9062 cb->args[2] = idx; 9063 rtnl_unlock(); 9064 9065 return skb->len; 9066 } 9067 9068 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, 9069 int flags, struct net_device *dev, 9070 bool allow_radio_stats, 9071 struct survey_info *survey) 9072 { 9073 void *hdr; 9074 struct nlattr *infoattr; 9075 9076 /* skip radio stats if userspace didn't request them */ 9077 if (!survey->channel && !allow_radio_stats) 9078 return 0; 9079 9080 hdr = nl80211hdr_put(msg, portid, seq, flags, 9081 NL80211_CMD_NEW_SURVEY_RESULTS); 9082 if (!hdr) 9083 return -ENOMEM; 9084 9085 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 9086 goto nla_put_failure; 9087 9088 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); 9089 if (!infoattr) 9090 goto nla_put_failure; 9091 9092 if (survey->channel && 9093 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, 9094 survey->channel->center_freq)) 9095 goto nla_put_failure; 9096 9097 if ((survey->filled & SURVEY_INFO_NOISE_DBM) && 9098 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) 9099 goto nla_put_failure; 9100 if ((survey->filled & SURVEY_INFO_IN_USE) && 9101 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) 9102 goto nla_put_failure; 9103 if ((survey->filled & SURVEY_INFO_TIME) && 9104 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, 9105 survey->time, NL80211_SURVEY_INFO_PAD)) 9106 goto nla_put_failure; 9107 if ((survey->filled & SURVEY_INFO_TIME_BUSY) && 9108 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, 9109 survey->time_busy, NL80211_SURVEY_INFO_PAD)) 9110 goto nla_put_failure; 9111 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && 9112 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, 9113 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) 9114 goto nla_put_failure; 9115 if ((survey->filled & SURVEY_INFO_TIME_RX) && 9116 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, 9117 survey->time_rx, NL80211_SURVEY_INFO_PAD)) 9118 goto nla_put_failure; 9119 if ((survey->filled & SURVEY_INFO_TIME_TX) && 9120 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, 9121 survey->time_tx, NL80211_SURVEY_INFO_PAD)) 9122 goto nla_put_failure; 9123 if ((survey->filled & SURVEY_INFO_TIME_SCAN) && 9124 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, 9125 survey->time_scan, NL80211_SURVEY_INFO_PAD)) 9126 goto nla_put_failure; 9127 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && 9128 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, 9129 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) 9130 goto nla_put_failure; 9131 9132 nla_nest_end(msg, infoattr); 9133 9134 genlmsg_end(msg, hdr); 9135 return 0; 9136 9137 nla_put_failure: 9138 genlmsg_cancel(msg, hdr); 9139 return -EMSGSIZE; 9140 } 9141 9142 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) 9143 { 9144 struct nlattr **attrbuf; 9145 struct survey_info survey; 9146 struct cfg80211_registered_device *rdev; 9147 struct wireless_dev *wdev; 9148 int survey_idx = cb->args[2]; 9149 int res; 9150 bool radio_stats; 9151 9152 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 9153 if (!attrbuf) 9154 return -ENOMEM; 9155 9156 rtnl_lock(); 9157 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 9158 if (res) 9159 goto out_err; 9160 9161 /* prepare_wdev_dump parsed the attributes */ 9162 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; 9163 9164 if (!wdev->netdev) { 9165 res = -EINVAL; 9166 goto out_err; 9167 } 9168 9169 if (!rdev->ops->dump_survey) { 9170 res = -EOPNOTSUPP; 9171 goto out_err; 9172 } 9173 9174 while (1) { 9175 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); 9176 if (res == -ENOENT) 9177 break; 9178 if (res) 9179 goto out_err; 9180 9181 /* don't send disabled channels, but do send non-channel data */ 9182 if (survey.channel && 9183 survey.channel->flags & IEEE80211_CHAN_DISABLED) { 9184 survey_idx++; 9185 continue; 9186 } 9187 9188 if (nl80211_send_survey(skb, 9189 NETLINK_CB(cb->skb).portid, 9190 cb->nlh->nlmsg_seq, NLM_F_MULTI, 9191 wdev->netdev, radio_stats, &survey) < 0) 9192 goto out; 9193 survey_idx++; 9194 } 9195 9196 out: 9197 cb->args[2] = survey_idx; 9198 res = skb->len; 9199 out_err: 9200 kfree(attrbuf); 9201 rtnl_unlock(); 9202 return res; 9203 } 9204 9205 static bool nl80211_valid_wpa_versions(u32 wpa_versions) 9206 { 9207 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | 9208 NL80211_WPA_VERSION_2 | 9209 NL80211_WPA_VERSION_3)); 9210 } 9211 9212 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 9213 { 9214 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9215 struct net_device *dev = info->user_ptr[1]; 9216 struct ieee80211_channel *chan; 9217 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; 9218 int err, ssid_len, ie_len = 0, auth_data_len = 0; 9219 enum nl80211_auth_type auth_type; 9220 struct key_parse key; 9221 bool local_state_change; 9222 u32 freq; 9223 9224 if (!info->attrs[NL80211_ATTR_MAC]) 9225 return -EINVAL; 9226 9227 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 9228 return -EINVAL; 9229 9230 if (!info->attrs[NL80211_ATTR_SSID]) 9231 return -EINVAL; 9232 9233 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 9234 return -EINVAL; 9235 9236 err = nl80211_parse_key(info, &key); 9237 if (err) 9238 return err; 9239 9240 if (key.idx >= 0) { 9241 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) 9242 return -EINVAL; 9243 if (!key.p.key || !key.p.key_len) 9244 return -EINVAL; 9245 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 9246 key.p.key_len != WLAN_KEY_LEN_WEP40) && 9247 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || 9248 key.p.key_len != WLAN_KEY_LEN_WEP104)) 9249 return -EINVAL; 9250 if (key.idx > 3) 9251 return -EINVAL; 9252 } else { 9253 key.p.key_len = 0; 9254 key.p.key = NULL; 9255 } 9256 9257 if (key.idx >= 0) { 9258 int i; 9259 bool ok = false; 9260 9261 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { 9262 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { 9263 ok = true; 9264 break; 9265 } 9266 } 9267 if (!ok) 9268 return -EINVAL; 9269 } 9270 9271 if (!rdev->ops->auth) 9272 return -EOPNOTSUPP; 9273 9274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9275 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9276 return -EOPNOTSUPP; 9277 9278 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9279 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 9280 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 9281 freq += 9282 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 9283 9284 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 9285 if (!chan) 9286 return -EINVAL; 9287 9288 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9289 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9290 9291 if (info->attrs[NL80211_ATTR_IE]) { 9292 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9293 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9294 } 9295 9296 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 9297 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) 9298 return -EINVAL; 9299 9300 if ((auth_type == NL80211_AUTHTYPE_SAE || 9301 auth_type == NL80211_AUTHTYPE_FILS_SK || 9302 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 9303 auth_type == NL80211_AUTHTYPE_FILS_PK) && 9304 !info->attrs[NL80211_ATTR_AUTH_DATA]) 9305 return -EINVAL; 9306 9307 if (info->attrs[NL80211_ATTR_AUTH_DATA]) { 9308 if (auth_type != NL80211_AUTHTYPE_SAE && 9309 auth_type != NL80211_AUTHTYPE_FILS_SK && 9310 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && 9311 auth_type != NL80211_AUTHTYPE_FILS_PK) 9312 return -EINVAL; 9313 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); 9314 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); 9315 /* need to include at least Auth Transaction and Status Code */ 9316 if (auth_data_len < 4) 9317 return -EINVAL; 9318 } 9319 9320 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 9321 9322 /* 9323 * Since we no longer track auth state, ignore 9324 * requests to only change local state. 9325 */ 9326 if (local_state_change) 9327 return 0; 9328 9329 wdev_lock(dev->ieee80211_ptr); 9330 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, 9331 ssid, ssid_len, ie, ie_len, 9332 key.p.key, key.p.key_len, key.idx, 9333 auth_data, auth_data_len); 9334 wdev_unlock(dev->ieee80211_ptr); 9335 return err; 9336 } 9337 9338 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, 9339 struct genl_info *info) 9340 { 9341 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 9342 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); 9343 return -EINVAL; 9344 } 9345 9346 if (!rdev->ops->tx_control_port || 9347 !wiphy_ext_feature_isset(&rdev->wiphy, 9348 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 9349 return -EOPNOTSUPP; 9350 9351 return 0; 9352 } 9353 9354 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 9355 struct genl_info *info, 9356 struct cfg80211_crypto_settings *settings, 9357 int cipher_limit) 9358 { 9359 memset(settings, 0, sizeof(*settings)); 9360 9361 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 9362 9363 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 9364 u16 proto; 9365 9366 proto = nla_get_u16( 9367 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 9368 settings->control_port_ethertype = cpu_to_be16(proto); 9369 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 9370 proto != ETH_P_PAE) 9371 return -EINVAL; 9372 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) 9373 settings->control_port_no_encrypt = true; 9374 } else 9375 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); 9376 9377 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 9378 int r = validate_pae_over_nl80211(rdev, info); 9379 9380 if (r < 0) 9381 return r; 9382 9383 settings->control_port_over_nl80211 = true; 9384 9385 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) 9386 settings->control_port_no_preauth = true; 9387 } 9388 9389 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 9390 void *data; 9391 int len, i; 9392 9393 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 9394 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 9395 settings->n_ciphers_pairwise = len / sizeof(u32); 9396 9397 if (len % sizeof(u32)) 9398 return -EINVAL; 9399 9400 if (settings->n_ciphers_pairwise > cipher_limit) 9401 return -EINVAL; 9402 9403 memcpy(settings->ciphers_pairwise, data, len); 9404 9405 for (i = 0; i < settings->n_ciphers_pairwise; i++) 9406 if (!cfg80211_supported_cipher_suite( 9407 &rdev->wiphy, 9408 settings->ciphers_pairwise[i])) 9409 return -EINVAL; 9410 } 9411 9412 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { 9413 settings->cipher_group = 9414 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); 9415 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, 9416 settings->cipher_group)) 9417 return -EINVAL; 9418 } 9419 9420 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { 9421 settings->wpa_versions = 9422 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); 9423 if (!nl80211_valid_wpa_versions(settings->wpa_versions)) 9424 return -EINVAL; 9425 } 9426 9427 if (info->attrs[NL80211_ATTR_AKM_SUITES]) { 9428 void *data; 9429 int len; 9430 9431 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); 9432 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); 9433 settings->n_akm_suites = len / sizeof(u32); 9434 9435 if (len % sizeof(u32)) 9436 return -EINVAL; 9437 9438 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) 9439 return -EINVAL; 9440 9441 memcpy(settings->akm_suites, data, len); 9442 } 9443 9444 if (info->attrs[NL80211_ATTR_PMK]) { 9445 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) 9446 return -EINVAL; 9447 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9448 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && 9449 !wiphy_ext_feature_isset(&rdev->wiphy, 9450 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) 9451 return -EINVAL; 9452 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); 9453 } 9454 9455 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { 9456 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9457 NL80211_EXT_FEATURE_SAE_OFFLOAD)) 9458 return -EINVAL; 9459 settings->sae_pwd = 9460 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 9461 settings->sae_pwd_len = 9462 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 9463 } 9464 9465 return 0; 9466 } 9467 9468 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 9469 { 9470 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9471 struct net_device *dev = info->user_ptr[1]; 9472 struct ieee80211_channel *chan; 9473 struct cfg80211_assoc_request req = {}; 9474 const u8 *bssid, *ssid; 9475 int err, ssid_len = 0; 9476 u32 freq; 9477 9478 if (dev->ieee80211_ptr->conn_owner_nlportid && 9479 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9480 return -EPERM; 9481 9482 if (!info->attrs[NL80211_ATTR_MAC] || 9483 !info->attrs[NL80211_ATTR_SSID] || 9484 !info->attrs[NL80211_ATTR_WIPHY_FREQ]) 9485 return -EINVAL; 9486 9487 if (!rdev->ops->assoc) 9488 return -EOPNOTSUPP; 9489 9490 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9491 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9492 return -EOPNOTSUPP; 9493 9494 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9495 9496 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 9497 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 9498 freq += 9499 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 9500 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 9501 if (!chan) 9502 return -EINVAL; 9503 9504 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9505 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9506 9507 if (info->attrs[NL80211_ATTR_IE]) { 9508 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9509 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9510 } 9511 9512 if (info->attrs[NL80211_ATTR_USE_MFP]) { 9513 enum nl80211_mfp mfp = 9514 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 9515 if (mfp == NL80211_MFP_REQUIRED) 9516 req.use_mfp = true; 9517 else if (mfp != NL80211_MFP_NO) 9518 return -EINVAL; 9519 } 9520 9521 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 9522 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 9523 9524 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 9525 req.flags |= ASSOC_REQ_DISABLE_HT; 9526 9527 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9528 memcpy(&req.ht_capa_mask, 9529 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 9530 sizeof(req.ht_capa_mask)); 9531 9532 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 9533 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9534 return -EINVAL; 9535 memcpy(&req.ht_capa, 9536 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 9537 sizeof(req.ht_capa)); 9538 } 9539 9540 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 9541 req.flags |= ASSOC_REQ_DISABLE_VHT; 9542 9543 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 9544 memcpy(&req.vht_capa_mask, 9545 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 9546 sizeof(req.vht_capa_mask)); 9547 9548 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 9549 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 9550 return -EINVAL; 9551 memcpy(&req.vht_capa, 9552 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 9553 sizeof(req.vht_capa)); 9554 } 9555 9556 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 9557 if (!((rdev->wiphy.features & 9558 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 9559 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 9560 !wiphy_ext_feature_isset(&rdev->wiphy, 9561 NL80211_EXT_FEATURE_RRM)) 9562 return -EINVAL; 9563 req.flags |= ASSOC_REQ_USE_RRM; 9564 } 9565 9566 if (info->attrs[NL80211_ATTR_FILS_KEK]) { 9567 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 9568 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 9569 if (!info->attrs[NL80211_ATTR_FILS_NONCES]) 9570 return -EINVAL; 9571 req.fils_nonces = 9572 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 9573 } 9574 9575 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); 9576 if (!err) { 9577 wdev_lock(dev->ieee80211_ptr); 9578 9579 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, 9580 ssid, ssid_len, &req); 9581 9582 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 9583 dev->ieee80211_ptr->conn_owner_nlportid = 9584 info->snd_portid; 9585 memcpy(dev->ieee80211_ptr->disconnect_bssid, 9586 bssid, ETH_ALEN); 9587 } 9588 9589 wdev_unlock(dev->ieee80211_ptr); 9590 } 9591 9592 return err; 9593 } 9594 9595 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 9596 { 9597 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9598 struct net_device *dev = info->user_ptr[1]; 9599 const u8 *ie = NULL, *bssid; 9600 int ie_len = 0, err; 9601 u16 reason_code; 9602 bool local_state_change; 9603 9604 if (dev->ieee80211_ptr->conn_owner_nlportid && 9605 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9606 return -EPERM; 9607 9608 if (!info->attrs[NL80211_ATTR_MAC]) 9609 return -EINVAL; 9610 9611 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 9612 return -EINVAL; 9613 9614 if (!rdev->ops->deauth) 9615 return -EOPNOTSUPP; 9616 9617 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9618 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9619 return -EOPNOTSUPP; 9620 9621 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9622 9623 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 9624 if (reason_code == 0) { 9625 /* Reason Code 0 is reserved */ 9626 return -EINVAL; 9627 } 9628 9629 if (info->attrs[NL80211_ATTR_IE]) { 9630 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9631 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9632 } 9633 9634 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 9635 9636 wdev_lock(dev->ieee80211_ptr); 9637 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 9638 local_state_change); 9639 wdev_unlock(dev->ieee80211_ptr); 9640 return err; 9641 } 9642 9643 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 9644 { 9645 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9646 struct net_device *dev = info->user_ptr[1]; 9647 const u8 *ie = NULL, *bssid; 9648 int ie_len = 0, err; 9649 u16 reason_code; 9650 bool local_state_change; 9651 9652 if (dev->ieee80211_ptr->conn_owner_nlportid && 9653 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9654 return -EPERM; 9655 9656 if (!info->attrs[NL80211_ATTR_MAC]) 9657 return -EINVAL; 9658 9659 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 9660 return -EINVAL; 9661 9662 if (!rdev->ops->disassoc) 9663 return -EOPNOTSUPP; 9664 9665 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9666 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9667 return -EOPNOTSUPP; 9668 9669 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9670 9671 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 9672 if (reason_code == 0) { 9673 /* Reason Code 0 is reserved */ 9674 return -EINVAL; 9675 } 9676 9677 if (info->attrs[NL80211_ATTR_IE]) { 9678 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9679 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9680 } 9681 9682 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 9683 9684 wdev_lock(dev->ieee80211_ptr); 9685 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 9686 local_state_change); 9687 wdev_unlock(dev->ieee80211_ptr); 9688 return err; 9689 } 9690 9691 static bool 9692 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, 9693 int mcast_rate[NUM_NL80211_BANDS], 9694 int rateval) 9695 { 9696 struct wiphy *wiphy = &rdev->wiphy; 9697 bool found = false; 9698 int band, i; 9699 9700 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9701 struct ieee80211_supported_band *sband; 9702 9703 sband = wiphy->bands[band]; 9704 if (!sband) 9705 continue; 9706 9707 for (i = 0; i < sband->n_bitrates; i++) { 9708 if (sband->bitrates[i].bitrate == rateval) { 9709 mcast_rate[band] = i + 1; 9710 found = true; 9711 break; 9712 } 9713 } 9714 } 9715 9716 return found; 9717 } 9718 9719 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 9720 { 9721 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9722 struct net_device *dev = info->user_ptr[1]; 9723 struct cfg80211_ibss_params ibss; 9724 struct wiphy *wiphy; 9725 struct cfg80211_cached_keys *connkeys = NULL; 9726 int err; 9727 9728 memset(&ibss, 0, sizeof(ibss)); 9729 9730 if (!info->attrs[NL80211_ATTR_SSID] || 9731 !nla_len(info->attrs[NL80211_ATTR_SSID])) 9732 return -EINVAL; 9733 9734 ibss.beacon_interval = 100; 9735 9736 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) 9737 ibss.beacon_interval = 9738 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 9739 9740 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, 9741 ibss.beacon_interval); 9742 if (err) 9743 return err; 9744 9745 if (!rdev->ops->join_ibss) 9746 return -EOPNOTSUPP; 9747 9748 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 9749 return -EOPNOTSUPP; 9750 9751 wiphy = &rdev->wiphy; 9752 9753 if (info->attrs[NL80211_ATTR_MAC]) { 9754 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9755 9756 if (!is_valid_ether_addr(ibss.bssid)) 9757 return -EINVAL; 9758 } 9759 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9760 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9761 9762 if (info->attrs[NL80211_ATTR_IE]) { 9763 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9764 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9765 } 9766 9767 err = nl80211_parse_chandef(rdev, info, &ibss.chandef); 9768 if (err) 9769 return err; 9770 9771 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, 9772 NL80211_IFTYPE_ADHOC)) 9773 return -EINVAL; 9774 9775 switch (ibss.chandef.width) { 9776 case NL80211_CHAN_WIDTH_5: 9777 case NL80211_CHAN_WIDTH_10: 9778 case NL80211_CHAN_WIDTH_20_NOHT: 9779 break; 9780 case NL80211_CHAN_WIDTH_20: 9781 case NL80211_CHAN_WIDTH_40: 9782 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 9783 return -EINVAL; 9784 break; 9785 case NL80211_CHAN_WIDTH_80: 9786 case NL80211_CHAN_WIDTH_80P80: 9787 case NL80211_CHAN_WIDTH_160: 9788 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 9789 return -EINVAL; 9790 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9791 NL80211_EXT_FEATURE_VHT_IBSS)) 9792 return -EINVAL; 9793 break; 9794 default: 9795 return -EINVAL; 9796 } 9797 9798 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 9799 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 9800 9801 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 9802 u8 *rates = 9803 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 9804 int n_rates = 9805 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 9806 struct ieee80211_supported_band *sband = 9807 wiphy->bands[ibss.chandef.chan->band]; 9808 9809 err = ieee80211_get_ratemask(sband, rates, n_rates, 9810 &ibss.basic_rates); 9811 if (err) 9812 return err; 9813 } 9814 9815 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9816 memcpy(&ibss.ht_capa_mask, 9817 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 9818 sizeof(ibss.ht_capa_mask)); 9819 9820 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 9821 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9822 return -EINVAL; 9823 memcpy(&ibss.ht_capa, 9824 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 9825 sizeof(ibss.ht_capa)); 9826 } 9827 9828 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 9829 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, 9830 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 9831 return -EINVAL; 9832 9833 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { 9834 bool no_ht = false; 9835 9836 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); 9837 if (IS_ERR(connkeys)) 9838 return PTR_ERR(connkeys); 9839 9840 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && 9841 no_ht) { 9842 kfree_sensitive(connkeys); 9843 return -EINVAL; 9844 } 9845 } 9846 9847 ibss.control_port = 9848 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); 9849 9850 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 9851 int r = validate_pae_over_nl80211(rdev, info); 9852 9853 if (r < 0) { 9854 kfree_sensitive(connkeys); 9855 return r; 9856 } 9857 9858 ibss.control_port_over_nl80211 = true; 9859 } 9860 9861 ibss.userspace_handles_dfs = 9862 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 9863 9864 wdev_lock(dev->ieee80211_ptr); 9865 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 9866 if (err) 9867 kfree_sensitive(connkeys); 9868 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 9869 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 9870 wdev_unlock(dev->ieee80211_ptr); 9871 9872 return err; 9873 } 9874 9875 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 9876 { 9877 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9878 struct net_device *dev = info->user_ptr[1]; 9879 9880 if (!rdev->ops->leave_ibss) 9881 return -EOPNOTSUPP; 9882 9883 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 9884 return -EOPNOTSUPP; 9885 9886 return cfg80211_leave_ibss(rdev, dev, false); 9887 } 9888 9889 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) 9890 { 9891 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9892 struct net_device *dev = info->user_ptr[1]; 9893 int mcast_rate[NUM_NL80211_BANDS]; 9894 u32 nla_rate; 9895 int err; 9896 9897 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && 9898 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 9899 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) 9900 return -EOPNOTSUPP; 9901 9902 if (!rdev->ops->set_mcast_rate) 9903 return -EOPNOTSUPP; 9904 9905 memset(mcast_rate, 0, sizeof(mcast_rate)); 9906 9907 if (!info->attrs[NL80211_ATTR_MCAST_RATE]) 9908 return -EINVAL; 9909 9910 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); 9911 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) 9912 return -EINVAL; 9913 9914 err = rdev_set_mcast_rate(rdev, dev, mcast_rate); 9915 9916 return err; 9917 } 9918 9919 static struct sk_buff * 9920 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, 9921 struct wireless_dev *wdev, int approxlen, 9922 u32 portid, u32 seq, enum nl80211_commands cmd, 9923 enum nl80211_attrs attr, 9924 const struct nl80211_vendor_cmd_info *info, 9925 gfp_t gfp) 9926 { 9927 struct sk_buff *skb; 9928 void *hdr; 9929 struct nlattr *data; 9930 9931 skb = nlmsg_new(approxlen + 100, gfp); 9932 if (!skb) 9933 return NULL; 9934 9935 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); 9936 if (!hdr) { 9937 kfree_skb(skb); 9938 return NULL; 9939 } 9940 9941 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 9942 goto nla_put_failure; 9943 9944 if (info) { 9945 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, 9946 info->vendor_id)) 9947 goto nla_put_failure; 9948 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, 9949 info->subcmd)) 9950 goto nla_put_failure; 9951 } 9952 9953 if (wdev) { 9954 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 9955 wdev_id(wdev), NL80211_ATTR_PAD)) 9956 goto nla_put_failure; 9957 if (wdev->netdev && 9958 nla_put_u32(skb, NL80211_ATTR_IFINDEX, 9959 wdev->netdev->ifindex)) 9960 goto nla_put_failure; 9961 } 9962 9963 data = nla_nest_start_noflag(skb, attr); 9964 if (!data) 9965 goto nla_put_failure; 9966 9967 ((void **)skb->cb)[0] = rdev; 9968 ((void **)skb->cb)[1] = hdr; 9969 ((void **)skb->cb)[2] = data; 9970 9971 return skb; 9972 9973 nla_put_failure: 9974 kfree_skb(skb); 9975 return NULL; 9976 } 9977 9978 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, 9979 struct wireless_dev *wdev, 9980 enum nl80211_commands cmd, 9981 enum nl80211_attrs attr, 9982 unsigned int portid, 9983 int vendor_event_idx, 9984 int approxlen, gfp_t gfp) 9985 { 9986 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 9987 const struct nl80211_vendor_cmd_info *info; 9988 9989 switch (cmd) { 9990 case NL80211_CMD_TESTMODE: 9991 if (WARN_ON(vendor_event_idx != -1)) 9992 return NULL; 9993 info = NULL; 9994 break; 9995 case NL80211_CMD_VENDOR: 9996 if (WARN_ON(vendor_event_idx < 0 || 9997 vendor_event_idx >= wiphy->n_vendor_events)) 9998 return NULL; 9999 info = &wiphy->vendor_events[vendor_event_idx]; 10000 break; 10001 default: 10002 WARN_ON(1); 10003 return NULL; 10004 } 10005 10006 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, 10007 cmd, attr, info, gfp); 10008 } 10009 EXPORT_SYMBOL(__cfg80211_alloc_event_skb); 10010 10011 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) 10012 { 10013 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 10014 void *hdr = ((void **)skb->cb)[1]; 10015 struct nlmsghdr *nlhdr = nlmsg_hdr(skb); 10016 struct nlattr *data = ((void **)skb->cb)[2]; 10017 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; 10018 10019 /* clear CB data for netlink core to own from now on */ 10020 memset(skb->cb, 0, sizeof(skb->cb)); 10021 10022 nla_nest_end(skb, data); 10023 genlmsg_end(skb, hdr); 10024 10025 if (nlhdr->nlmsg_pid) { 10026 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, 10027 nlhdr->nlmsg_pid); 10028 } else { 10029 if (data->nla_type == NL80211_ATTR_VENDOR_DATA) 10030 mcgrp = NL80211_MCGRP_VENDOR; 10031 10032 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 10033 skb, 0, mcgrp, gfp); 10034 } 10035 } 10036 EXPORT_SYMBOL(__cfg80211_send_event_skb); 10037 10038 #ifdef CONFIG_NL80211_TESTMODE 10039 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 10040 { 10041 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10042 struct wireless_dev *wdev = 10043 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); 10044 int err; 10045 10046 if (!rdev->ops->testmode_cmd) 10047 return -EOPNOTSUPP; 10048 10049 if (IS_ERR(wdev)) { 10050 err = PTR_ERR(wdev); 10051 if (err != -EINVAL) 10052 return err; 10053 wdev = NULL; 10054 } else if (wdev->wiphy != &rdev->wiphy) { 10055 return -EINVAL; 10056 } 10057 10058 if (!info->attrs[NL80211_ATTR_TESTDATA]) 10059 return -EINVAL; 10060 10061 rdev->cur_cmd_info = info; 10062 err = rdev_testmode_cmd(rdev, wdev, 10063 nla_data(info->attrs[NL80211_ATTR_TESTDATA]), 10064 nla_len(info->attrs[NL80211_ATTR_TESTDATA])); 10065 rdev->cur_cmd_info = NULL; 10066 10067 return err; 10068 } 10069 10070 static int nl80211_testmode_dump(struct sk_buff *skb, 10071 struct netlink_callback *cb) 10072 { 10073 struct cfg80211_registered_device *rdev; 10074 struct nlattr **attrbuf = NULL; 10075 int err; 10076 long phy_idx; 10077 void *data = NULL; 10078 int data_len = 0; 10079 10080 rtnl_lock(); 10081 10082 if (cb->args[0]) { 10083 /* 10084 * 0 is a valid index, but not valid for args[0], 10085 * so we need to offset by 1. 10086 */ 10087 phy_idx = cb->args[0] - 1; 10088 10089 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); 10090 if (!rdev) { 10091 err = -ENOENT; 10092 goto out_err; 10093 } 10094 } else { 10095 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 10096 GFP_KERNEL); 10097 if (!attrbuf) { 10098 err = -ENOMEM; 10099 goto out_err; 10100 } 10101 10102 err = nlmsg_parse_deprecated(cb->nlh, 10103 GENL_HDRLEN + nl80211_fam.hdrsize, 10104 attrbuf, nl80211_fam.maxattr, 10105 nl80211_policy, NULL); 10106 if (err) 10107 goto out_err; 10108 10109 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 10110 if (IS_ERR(rdev)) { 10111 err = PTR_ERR(rdev); 10112 goto out_err; 10113 } 10114 phy_idx = rdev->wiphy_idx; 10115 10116 if (attrbuf[NL80211_ATTR_TESTDATA]) 10117 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; 10118 } 10119 10120 if (cb->args[1]) { 10121 data = nla_data((void *)cb->args[1]); 10122 data_len = nla_len((void *)cb->args[1]); 10123 } 10124 10125 if (!rdev->ops->testmode_dump) { 10126 err = -EOPNOTSUPP; 10127 goto out_err; 10128 } 10129 10130 while (1) { 10131 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 10132 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10133 NL80211_CMD_TESTMODE); 10134 struct nlattr *tmdata; 10135 10136 if (!hdr) 10137 break; 10138 10139 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { 10140 genlmsg_cancel(skb, hdr); 10141 break; 10142 } 10143 10144 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); 10145 if (!tmdata) { 10146 genlmsg_cancel(skb, hdr); 10147 break; 10148 } 10149 err = rdev_testmode_dump(rdev, skb, cb, data, data_len); 10150 nla_nest_end(skb, tmdata); 10151 10152 if (err == -ENOBUFS || err == -ENOENT) { 10153 genlmsg_cancel(skb, hdr); 10154 break; 10155 } else if (err) { 10156 genlmsg_cancel(skb, hdr); 10157 goto out_err; 10158 } 10159 10160 genlmsg_end(skb, hdr); 10161 } 10162 10163 err = skb->len; 10164 /* see above */ 10165 cb->args[0] = phy_idx + 1; 10166 out_err: 10167 kfree(attrbuf); 10168 rtnl_unlock(); 10169 return err; 10170 } 10171 #endif 10172 10173 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 10174 { 10175 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10176 struct net_device *dev = info->user_ptr[1]; 10177 struct cfg80211_connect_params connect; 10178 struct wiphy *wiphy; 10179 struct cfg80211_cached_keys *connkeys = NULL; 10180 u32 freq = 0; 10181 int err; 10182 10183 memset(&connect, 0, sizeof(connect)); 10184 10185 if (!info->attrs[NL80211_ATTR_SSID] || 10186 !nla_len(info->attrs[NL80211_ATTR_SSID])) 10187 return -EINVAL; 10188 10189 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 10190 connect.auth_type = 10191 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10192 if (!nl80211_valid_auth_type(rdev, connect.auth_type, 10193 NL80211_CMD_CONNECT)) 10194 return -EINVAL; 10195 } else 10196 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 10197 10198 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 10199 10200 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && 10201 !wiphy_ext_feature_isset(&rdev->wiphy, 10202 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 10203 return -EINVAL; 10204 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; 10205 10206 err = nl80211_crypto_settings(rdev, info, &connect.crypto, 10207 NL80211_MAX_NR_CIPHER_SUITES); 10208 if (err) 10209 return err; 10210 10211 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10212 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10213 return -EOPNOTSUPP; 10214 10215 wiphy = &rdev->wiphy; 10216 10217 connect.bg_scan_period = -1; 10218 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && 10219 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { 10220 connect.bg_scan_period = 10221 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); 10222 } 10223 10224 if (info->attrs[NL80211_ATTR_MAC]) 10225 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10226 else if (info->attrs[NL80211_ATTR_MAC_HINT]) 10227 connect.bssid_hint = 10228 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); 10229 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10230 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10231 10232 if (info->attrs[NL80211_ATTR_IE]) { 10233 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10234 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10235 } 10236 10237 if (info->attrs[NL80211_ATTR_USE_MFP]) { 10238 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 10239 if (connect.mfp == NL80211_MFP_OPTIONAL && 10240 !wiphy_ext_feature_isset(&rdev->wiphy, 10241 NL80211_EXT_FEATURE_MFP_OPTIONAL)) 10242 return -EOPNOTSUPP; 10243 } else { 10244 connect.mfp = NL80211_MFP_NO; 10245 } 10246 10247 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 10248 connect.prev_bssid = 10249 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 10250 10251 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10252 freq = MHZ_TO_KHZ(nla_get_u32( 10253 info->attrs[NL80211_ATTR_WIPHY_FREQ])); 10254 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10255 freq += 10256 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10257 10258 if (freq) { 10259 connect.channel = nl80211_get_valid_chan(wiphy, freq); 10260 if (!connect.channel) 10261 return -EINVAL; 10262 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { 10263 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); 10264 freq = MHZ_TO_KHZ(freq); 10265 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); 10266 if (!connect.channel_hint) 10267 return -EINVAL; 10268 } 10269 10270 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 10271 connect.edmg.channels = 10272 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 10273 10274 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 10275 connect.edmg.bw_config = 10276 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 10277 } 10278 10279 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 10280 connkeys = nl80211_parse_connkeys(rdev, info, NULL); 10281 if (IS_ERR(connkeys)) 10282 return PTR_ERR(connkeys); 10283 } 10284 10285 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 10286 connect.flags |= ASSOC_REQ_DISABLE_HT; 10287 10288 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10289 memcpy(&connect.ht_capa_mask, 10290 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 10291 sizeof(connect.ht_capa_mask)); 10292 10293 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 10294 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { 10295 kfree_sensitive(connkeys); 10296 return -EINVAL; 10297 } 10298 memcpy(&connect.ht_capa, 10299 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 10300 sizeof(connect.ht_capa)); 10301 } 10302 10303 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 10304 connect.flags |= ASSOC_REQ_DISABLE_VHT; 10305 10306 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 10307 memcpy(&connect.vht_capa_mask, 10308 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 10309 sizeof(connect.vht_capa_mask)); 10310 10311 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 10312 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { 10313 kfree_sensitive(connkeys); 10314 return -EINVAL; 10315 } 10316 memcpy(&connect.vht_capa, 10317 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 10318 sizeof(connect.vht_capa)); 10319 } 10320 10321 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 10322 if (!((rdev->wiphy.features & 10323 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 10324 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 10325 !wiphy_ext_feature_isset(&rdev->wiphy, 10326 NL80211_EXT_FEATURE_RRM)) { 10327 kfree_sensitive(connkeys); 10328 return -EINVAL; 10329 } 10330 connect.flags |= ASSOC_REQ_USE_RRM; 10331 } 10332 10333 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 10334 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 10335 kfree_sensitive(connkeys); 10336 return -EOPNOTSUPP; 10337 } 10338 10339 if (info->attrs[NL80211_ATTR_BSS_SELECT]) { 10340 /* bss selection makes no sense if bssid is set */ 10341 if (connect.bssid) { 10342 kfree_sensitive(connkeys); 10343 return -EINVAL; 10344 } 10345 10346 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], 10347 wiphy, &connect.bss_select); 10348 if (err) { 10349 kfree_sensitive(connkeys); 10350 return err; 10351 } 10352 } 10353 10354 if (wiphy_ext_feature_isset(&rdev->wiphy, 10355 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 10356 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 10357 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 10358 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 10359 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10360 connect.fils_erp_username = 10361 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10362 connect.fils_erp_username_len = 10363 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10364 connect.fils_erp_realm = 10365 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10366 connect.fils_erp_realm_len = 10367 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10368 connect.fils_erp_next_seq_num = 10369 nla_get_u16( 10370 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 10371 connect.fils_erp_rrk = 10372 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10373 connect.fils_erp_rrk_len = 10374 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10375 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 10376 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 10377 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 10378 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10379 kfree_sensitive(connkeys); 10380 return -EINVAL; 10381 } 10382 10383 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { 10384 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10385 kfree_sensitive(connkeys); 10386 GENL_SET_ERR_MSG(info, 10387 "external auth requires connection ownership"); 10388 return -EINVAL; 10389 } 10390 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; 10391 } 10392 10393 wdev_lock(dev->ieee80211_ptr); 10394 10395 err = cfg80211_connect(rdev, dev, &connect, connkeys, 10396 connect.prev_bssid); 10397 if (err) 10398 kfree_sensitive(connkeys); 10399 10400 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10401 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 10402 if (connect.bssid) 10403 memcpy(dev->ieee80211_ptr->disconnect_bssid, 10404 connect.bssid, ETH_ALEN); 10405 else 10406 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); 10407 } 10408 10409 wdev_unlock(dev->ieee80211_ptr); 10410 10411 return err; 10412 } 10413 10414 static int nl80211_update_connect_params(struct sk_buff *skb, 10415 struct genl_info *info) 10416 { 10417 struct cfg80211_connect_params connect = {}; 10418 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10419 struct net_device *dev = info->user_ptr[1]; 10420 struct wireless_dev *wdev = dev->ieee80211_ptr; 10421 bool fils_sk_offload; 10422 u32 auth_type; 10423 u32 changed = 0; 10424 int ret; 10425 10426 if (!rdev->ops->update_connect_params) 10427 return -EOPNOTSUPP; 10428 10429 if (info->attrs[NL80211_ATTR_IE]) { 10430 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10431 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10432 changed |= UPDATE_ASSOC_IES; 10433 } 10434 10435 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, 10436 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); 10437 10438 /* 10439 * when driver supports fils-sk offload all attributes must be 10440 * provided. So the else covers "fils-sk-not-all" and 10441 * "no-fils-sk-any". 10442 */ 10443 if (fils_sk_offload && 10444 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 10445 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 10446 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 10447 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10448 connect.fils_erp_username = 10449 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10450 connect.fils_erp_username_len = 10451 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 10452 connect.fils_erp_realm = 10453 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10454 connect.fils_erp_realm_len = 10455 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 10456 connect.fils_erp_next_seq_num = 10457 nla_get_u16( 10458 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 10459 connect.fils_erp_rrk = 10460 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10461 connect.fils_erp_rrk_len = 10462 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 10463 changed |= UPDATE_FILS_ERP_INFO; 10464 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 10465 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 10466 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 10467 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 10468 return -EINVAL; 10469 } 10470 10471 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 10472 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10473 if (!nl80211_valid_auth_type(rdev, auth_type, 10474 NL80211_CMD_CONNECT)) 10475 return -EINVAL; 10476 10477 if (auth_type == NL80211_AUTHTYPE_FILS_SK && 10478 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) 10479 return -EINVAL; 10480 10481 connect.auth_type = auth_type; 10482 changed |= UPDATE_AUTH_TYPE; 10483 } 10484 10485 wdev_lock(dev->ieee80211_ptr); 10486 if (!wdev->current_bss) 10487 ret = -ENOLINK; 10488 else 10489 ret = rdev_update_connect_params(rdev, dev, &connect, changed); 10490 wdev_unlock(dev->ieee80211_ptr); 10491 10492 return ret; 10493 } 10494 10495 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 10496 { 10497 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10498 struct net_device *dev = info->user_ptr[1]; 10499 u16 reason; 10500 int ret; 10501 10502 if (dev->ieee80211_ptr->conn_owner_nlportid && 10503 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10504 return -EPERM; 10505 10506 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 10507 reason = WLAN_REASON_DEAUTH_LEAVING; 10508 else 10509 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 10510 10511 if (reason == 0) 10512 return -EINVAL; 10513 10514 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10515 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10516 return -EOPNOTSUPP; 10517 10518 wdev_lock(dev->ieee80211_ptr); 10519 ret = cfg80211_disconnect(rdev, dev, reason, true); 10520 wdev_unlock(dev->ieee80211_ptr); 10521 return ret; 10522 } 10523 10524 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 10525 { 10526 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10527 struct net *net; 10528 int err; 10529 10530 if (info->attrs[NL80211_ATTR_PID]) { 10531 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 10532 10533 net = get_net_ns_by_pid(pid); 10534 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { 10535 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); 10536 10537 net = get_net_ns_by_fd(fd); 10538 } else { 10539 return -EINVAL; 10540 } 10541 10542 if (IS_ERR(net)) 10543 return PTR_ERR(net); 10544 10545 err = 0; 10546 10547 /* check if anything to do */ 10548 if (!net_eq(wiphy_net(&rdev->wiphy), net)) 10549 err = cfg80211_switch_netns(rdev, net); 10550 10551 put_net(net); 10552 return err; 10553 } 10554 10555 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 10556 { 10557 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10558 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 10559 struct cfg80211_pmksa *pmksa) = NULL; 10560 struct net_device *dev = info->user_ptr[1]; 10561 struct cfg80211_pmksa pmksa; 10562 10563 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 10564 10565 if (!info->attrs[NL80211_ATTR_PMKID]) 10566 return -EINVAL; 10567 10568 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 10569 10570 if (info->attrs[NL80211_ATTR_MAC]) { 10571 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10572 } else if (info->attrs[NL80211_ATTR_SSID] && 10573 info->attrs[NL80211_ATTR_FILS_CACHE_ID] && 10574 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || 10575 info->attrs[NL80211_ATTR_PMK])) { 10576 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10577 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10578 pmksa.cache_id = 10579 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); 10580 } else { 10581 return -EINVAL; 10582 } 10583 if (info->attrs[NL80211_ATTR_PMK]) { 10584 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 10585 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 10586 } 10587 10588 if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) 10589 pmksa.pmk_lifetime = 10590 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); 10591 10592 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) 10593 pmksa.pmk_reauth_threshold = 10594 nla_get_u8( 10595 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); 10596 10597 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10598 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && 10599 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && 10600 wiphy_ext_feature_isset(&rdev->wiphy, 10601 NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) 10602 return -EOPNOTSUPP; 10603 10604 switch (info->genlhdr->cmd) { 10605 case NL80211_CMD_SET_PMKSA: 10606 rdev_ops = rdev->ops->set_pmksa; 10607 break; 10608 case NL80211_CMD_DEL_PMKSA: 10609 rdev_ops = rdev->ops->del_pmksa; 10610 break; 10611 default: 10612 WARN_ON(1); 10613 break; 10614 } 10615 10616 if (!rdev_ops) 10617 return -EOPNOTSUPP; 10618 10619 return rdev_ops(&rdev->wiphy, dev, &pmksa); 10620 } 10621 10622 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 10623 { 10624 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10625 struct net_device *dev = info->user_ptr[1]; 10626 10627 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10628 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10629 return -EOPNOTSUPP; 10630 10631 if (!rdev->ops->flush_pmksa) 10632 return -EOPNOTSUPP; 10633 10634 return rdev_flush_pmksa(rdev, dev); 10635 } 10636 10637 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) 10638 { 10639 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10640 struct net_device *dev = info->user_ptr[1]; 10641 u8 action_code, dialog_token; 10642 u32 peer_capability = 0; 10643 u16 status_code; 10644 u8 *peer; 10645 bool initiator; 10646 10647 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 10648 !rdev->ops->tdls_mgmt) 10649 return -EOPNOTSUPP; 10650 10651 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || 10652 !info->attrs[NL80211_ATTR_STATUS_CODE] || 10653 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || 10654 !info->attrs[NL80211_ATTR_IE] || 10655 !info->attrs[NL80211_ATTR_MAC]) 10656 return -EINVAL; 10657 10658 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 10659 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); 10660 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 10661 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); 10662 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); 10663 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) 10664 peer_capability = 10665 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); 10666 10667 return rdev_tdls_mgmt(rdev, dev, peer, action_code, 10668 dialog_token, status_code, peer_capability, 10669 initiator, 10670 nla_data(info->attrs[NL80211_ATTR_IE]), 10671 nla_len(info->attrs[NL80211_ATTR_IE])); 10672 } 10673 10674 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) 10675 { 10676 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10677 struct net_device *dev = info->user_ptr[1]; 10678 enum nl80211_tdls_operation operation; 10679 u8 *peer; 10680 10681 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 10682 !rdev->ops->tdls_oper) 10683 return -EOPNOTSUPP; 10684 10685 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || 10686 !info->attrs[NL80211_ATTR_MAC]) 10687 return -EINVAL; 10688 10689 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); 10690 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 10691 10692 return rdev_tdls_oper(rdev, dev, peer, operation); 10693 } 10694 10695 static int nl80211_remain_on_channel(struct sk_buff *skb, 10696 struct genl_info *info) 10697 { 10698 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10699 struct wireless_dev *wdev = info->user_ptr[1]; 10700 struct cfg80211_chan_def chandef; 10701 const struct cfg80211_chan_def *compat_chandef; 10702 struct sk_buff *msg; 10703 void *hdr; 10704 u64 cookie; 10705 u32 duration; 10706 int err; 10707 10708 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 10709 !info->attrs[NL80211_ATTR_DURATION]) 10710 return -EINVAL; 10711 10712 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 10713 10714 if (!rdev->ops->remain_on_channel || 10715 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) 10716 return -EOPNOTSUPP; 10717 10718 /* 10719 * We should be on that channel for at least a minimum amount of 10720 * time (10ms) but no longer than the driver supports. 10721 */ 10722 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 10723 duration > rdev->wiphy.max_remain_on_channel_duration) 10724 return -EINVAL; 10725 10726 err = nl80211_parse_chandef(rdev, info, &chandef); 10727 if (err) 10728 return err; 10729 10730 wdev_lock(wdev); 10731 if (!cfg80211_off_channel_oper_allowed(wdev) && 10732 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { 10733 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, 10734 &chandef); 10735 if (compat_chandef != &chandef) { 10736 wdev_unlock(wdev); 10737 return -EBUSY; 10738 } 10739 } 10740 wdev_unlock(wdev); 10741 10742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10743 if (!msg) 10744 return -ENOMEM; 10745 10746 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 10747 NL80211_CMD_REMAIN_ON_CHANNEL); 10748 if (!hdr) { 10749 err = -ENOBUFS; 10750 goto free_msg; 10751 } 10752 10753 err = rdev_remain_on_channel(rdev, wdev, chandef.chan, 10754 duration, &cookie); 10755 10756 if (err) 10757 goto free_msg; 10758 10759 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 10760 NL80211_ATTR_PAD)) 10761 goto nla_put_failure; 10762 10763 genlmsg_end(msg, hdr); 10764 10765 return genlmsg_reply(msg, info); 10766 10767 nla_put_failure: 10768 err = -ENOBUFS; 10769 free_msg: 10770 nlmsg_free(msg); 10771 return err; 10772 } 10773 10774 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 10775 struct genl_info *info) 10776 { 10777 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10778 struct wireless_dev *wdev = info->user_ptr[1]; 10779 u64 cookie; 10780 10781 if (!info->attrs[NL80211_ATTR_COOKIE]) 10782 return -EINVAL; 10783 10784 if (!rdev->ops->cancel_remain_on_channel) 10785 return -EOPNOTSUPP; 10786 10787 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 10788 10789 return rdev_cancel_remain_on_channel(rdev, wdev, cookie); 10790 } 10791 10792 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, 10793 struct genl_info *info) 10794 { 10795 struct cfg80211_bitrate_mask mask; 10796 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10797 struct net_device *dev = info->user_ptr[1]; 10798 int err; 10799 10800 if (!rdev->ops->set_bitrate_mask) 10801 return -EOPNOTSUPP; 10802 10803 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 10804 NL80211_ATTR_TX_RATES, &mask); 10805 if (err) 10806 return err; 10807 10808 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); 10809 } 10810 10811 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) 10812 { 10813 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10814 struct wireless_dev *wdev = info->user_ptr[1]; 10815 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; 10816 10817 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 10818 return -EINVAL; 10819 10820 if (info->attrs[NL80211_ATTR_FRAME_TYPE]) 10821 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); 10822 10823 switch (wdev->iftype) { 10824 case NL80211_IFTYPE_STATION: 10825 case NL80211_IFTYPE_ADHOC: 10826 case NL80211_IFTYPE_P2P_CLIENT: 10827 case NL80211_IFTYPE_AP: 10828 case NL80211_IFTYPE_AP_VLAN: 10829 case NL80211_IFTYPE_MESH_POINT: 10830 case NL80211_IFTYPE_P2P_GO: 10831 case NL80211_IFTYPE_P2P_DEVICE: 10832 break; 10833 case NL80211_IFTYPE_NAN: 10834 default: 10835 return -EOPNOTSUPP; 10836 } 10837 10838 /* not much point in registering if we can't reply */ 10839 if (!rdev->ops->mgmt_tx) 10840 return -EOPNOTSUPP; 10841 10842 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && 10843 !wiphy_ext_feature_isset(&rdev->wiphy, 10844 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { 10845 GENL_SET_ERR_MSG(info, 10846 "multicast RX registrations are not supported"); 10847 return -EOPNOTSUPP; 10848 } 10849 10850 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, 10851 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 10852 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), 10853 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], 10854 info->extack); 10855 } 10856 10857 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) 10858 { 10859 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10860 struct wireless_dev *wdev = info->user_ptr[1]; 10861 struct cfg80211_chan_def chandef; 10862 int err; 10863 void *hdr = NULL; 10864 u64 cookie; 10865 struct sk_buff *msg = NULL; 10866 struct cfg80211_mgmt_tx_params params = { 10867 .dont_wait_for_ack = 10868 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], 10869 }; 10870 10871 if (!info->attrs[NL80211_ATTR_FRAME]) 10872 return -EINVAL; 10873 10874 if (!rdev->ops->mgmt_tx) 10875 return -EOPNOTSUPP; 10876 10877 switch (wdev->iftype) { 10878 case NL80211_IFTYPE_P2P_DEVICE: 10879 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10880 return -EINVAL; 10881 case NL80211_IFTYPE_STATION: 10882 case NL80211_IFTYPE_ADHOC: 10883 case NL80211_IFTYPE_P2P_CLIENT: 10884 case NL80211_IFTYPE_AP: 10885 case NL80211_IFTYPE_AP_VLAN: 10886 case NL80211_IFTYPE_MESH_POINT: 10887 case NL80211_IFTYPE_P2P_GO: 10888 break; 10889 case NL80211_IFTYPE_NAN: 10890 default: 10891 return -EOPNOTSUPP; 10892 } 10893 10894 if (info->attrs[NL80211_ATTR_DURATION]) { 10895 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 10896 return -EINVAL; 10897 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 10898 10899 /* 10900 * We should wait on the channel for at least a minimum amount 10901 * of time (10ms) but no longer than the driver supports. 10902 */ 10903 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 10904 params.wait > rdev->wiphy.max_remain_on_channel_duration) 10905 return -EINVAL; 10906 } 10907 10908 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; 10909 10910 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 10911 return -EINVAL; 10912 10913 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 10914 10915 /* get the channel if any has been specified, otherwise pass NULL to 10916 * the driver. The latter will use the current one 10917 */ 10918 chandef.chan = NULL; 10919 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 10920 err = nl80211_parse_chandef(rdev, info, &chandef); 10921 if (err) 10922 return err; 10923 } 10924 10925 if (!chandef.chan && params.offchan) 10926 return -EINVAL; 10927 10928 wdev_lock(wdev); 10929 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { 10930 wdev_unlock(wdev); 10931 return -EBUSY; 10932 } 10933 wdev_unlock(wdev); 10934 10935 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 10936 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 10937 10938 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { 10939 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 10940 int i; 10941 10942 if (len % sizeof(u16)) 10943 return -EINVAL; 10944 10945 params.n_csa_offsets = len / sizeof(u16); 10946 params.csa_offsets = 10947 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 10948 10949 /* check that all the offsets fit the frame */ 10950 for (i = 0; i < params.n_csa_offsets; i++) { 10951 if (params.csa_offsets[i] >= params.len) 10952 return -EINVAL; 10953 } 10954 } 10955 10956 if (!params.dont_wait_for_ack) { 10957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10958 if (!msg) 10959 return -ENOMEM; 10960 10961 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 10962 NL80211_CMD_FRAME); 10963 if (!hdr) { 10964 err = -ENOBUFS; 10965 goto free_msg; 10966 } 10967 } 10968 10969 params.chan = chandef.chan; 10970 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); 10971 if (err) 10972 goto free_msg; 10973 10974 if (msg) { 10975 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 10976 NL80211_ATTR_PAD)) 10977 goto nla_put_failure; 10978 10979 genlmsg_end(msg, hdr); 10980 return genlmsg_reply(msg, info); 10981 } 10982 10983 return 0; 10984 10985 nla_put_failure: 10986 err = -ENOBUFS; 10987 free_msg: 10988 nlmsg_free(msg); 10989 return err; 10990 } 10991 10992 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) 10993 { 10994 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10995 struct wireless_dev *wdev = info->user_ptr[1]; 10996 u64 cookie; 10997 10998 if (!info->attrs[NL80211_ATTR_COOKIE]) 10999 return -EINVAL; 11000 11001 if (!rdev->ops->mgmt_tx_cancel_wait) 11002 return -EOPNOTSUPP; 11003 11004 switch (wdev->iftype) { 11005 case NL80211_IFTYPE_STATION: 11006 case NL80211_IFTYPE_ADHOC: 11007 case NL80211_IFTYPE_P2P_CLIENT: 11008 case NL80211_IFTYPE_AP: 11009 case NL80211_IFTYPE_AP_VLAN: 11010 case NL80211_IFTYPE_P2P_GO: 11011 case NL80211_IFTYPE_P2P_DEVICE: 11012 break; 11013 case NL80211_IFTYPE_NAN: 11014 default: 11015 return -EOPNOTSUPP; 11016 } 11017 11018 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 11019 11020 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); 11021 } 11022 11023 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 11024 { 11025 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11026 struct wireless_dev *wdev; 11027 struct net_device *dev = info->user_ptr[1]; 11028 u8 ps_state; 11029 bool state; 11030 int err; 11031 11032 if (!info->attrs[NL80211_ATTR_PS_STATE]) 11033 return -EINVAL; 11034 11035 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 11036 11037 wdev = dev->ieee80211_ptr; 11038 11039 if (!rdev->ops->set_power_mgmt) 11040 return -EOPNOTSUPP; 11041 11042 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 11043 11044 if (state == wdev->ps) 11045 return 0; 11046 11047 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); 11048 if (!err) 11049 wdev->ps = state; 11050 return err; 11051 } 11052 11053 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 11054 { 11055 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11056 enum nl80211_ps_state ps_state; 11057 struct wireless_dev *wdev; 11058 struct net_device *dev = info->user_ptr[1]; 11059 struct sk_buff *msg; 11060 void *hdr; 11061 int err; 11062 11063 wdev = dev->ieee80211_ptr; 11064 11065 if (!rdev->ops->set_power_mgmt) 11066 return -EOPNOTSUPP; 11067 11068 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 11069 if (!msg) 11070 return -ENOMEM; 11071 11072 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11073 NL80211_CMD_GET_POWER_SAVE); 11074 if (!hdr) { 11075 err = -ENOBUFS; 11076 goto free_msg; 11077 } 11078 11079 if (wdev->ps) 11080 ps_state = NL80211_PS_ENABLED; 11081 else 11082 ps_state = NL80211_PS_DISABLED; 11083 11084 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) 11085 goto nla_put_failure; 11086 11087 genlmsg_end(msg, hdr); 11088 return genlmsg_reply(msg, info); 11089 11090 nla_put_failure: 11091 err = -ENOBUFS; 11092 free_msg: 11093 nlmsg_free(msg); 11094 return err; 11095 } 11096 11097 static const struct nla_policy 11098 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { 11099 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, 11100 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, 11101 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, 11102 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, 11103 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, 11104 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, 11105 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, 11106 }; 11107 11108 static int nl80211_set_cqm_txe(struct genl_info *info, 11109 u32 rate, u32 pkts, u32 intvl) 11110 { 11111 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11112 struct net_device *dev = info->user_ptr[1]; 11113 struct wireless_dev *wdev = dev->ieee80211_ptr; 11114 11115 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) 11116 return -EINVAL; 11117 11118 if (!rdev->ops->set_cqm_txe_config) 11119 return -EOPNOTSUPP; 11120 11121 if (wdev->iftype != NL80211_IFTYPE_STATION && 11122 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 11123 return -EOPNOTSUPP; 11124 11125 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); 11126 } 11127 11128 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, 11129 struct net_device *dev) 11130 { 11131 struct wireless_dev *wdev = dev->ieee80211_ptr; 11132 s32 last, low, high; 11133 u32 hyst; 11134 int i, n, low_index; 11135 int err; 11136 11137 /* RSSI reporting disabled? */ 11138 if (!wdev->cqm_config) 11139 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); 11140 11141 /* 11142 * Obtain current RSSI value if possible, if not and no RSSI threshold 11143 * event has been received yet, we should receive an event after a 11144 * connection is established and enough beacons received to calculate 11145 * the average. 11146 */ 11147 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && 11148 rdev->ops->get_station) { 11149 struct station_info sinfo = {}; 11150 u8 *mac_addr; 11151 11152 mac_addr = wdev->current_bss->pub.bssid; 11153 11154 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 11155 if (err) 11156 return err; 11157 11158 cfg80211_sinfo_release_content(&sinfo); 11159 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) 11160 wdev->cqm_config->last_rssi_event_value = 11161 (s8) sinfo.rx_beacon_signal_avg; 11162 } 11163 11164 last = wdev->cqm_config->last_rssi_event_value; 11165 hyst = wdev->cqm_config->rssi_hyst; 11166 n = wdev->cqm_config->n_rssi_thresholds; 11167 11168 for (i = 0; i < n; i++) { 11169 i = array_index_nospec(i, n); 11170 if (last < wdev->cqm_config->rssi_thresholds[i]) 11171 break; 11172 } 11173 11174 low_index = i - 1; 11175 if (low_index >= 0) { 11176 low_index = array_index_nospec(low_index, n); 11177 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; 11178 } else { 11179 low = S32_MIN; 11180 } 11181 if (i < n) { 11182 i = array_index_nospec(i, n); 11183 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; 11184 } else { 11185 high = S32_MAX; 11186 } 11187 11188 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); 11189 } 11190 11191 static int nl80211_set_cqm_rssi(struct genl_info *info, 11192 const s32 *thresholds, int n_thresholds, 11193 u32 hysteresis) 11194 { 11195 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11196 struct net_device *dev = info->user_ptr[1]; 11197 struct wireless_dev *wdev = dev->ieee80211_ptr; 11198 int i, err; 11199 s32 prev = S32_MIN; 11200 11201 /* Check all values negative and sorted */ 11202 for (i = 0; i < n_thresholds; i++) { 11203 if (thresholds[i] > 0 || thresholds[i] <= prev) 11204 return -EINVAL; 11205 11206 prev = thresholds[i]; 11207 } 11208 11209 if (wdev->iftype != NL80211_IFTYPE_STATION && 11210 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 11211 return -EOPNOTSUPP; 11212 11213 wdev_lock(wdev); 11214 cfg80211_cqm_config_free(wdev); 11215 wdev_unlock(wdev); 11216 11217 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { 11218 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ 11219 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); 11220 11221 return rdev_set_cqm_rssi_config(rdev, dev, 11222 thresholds[0], hysteresis); 11223 } 11224 11225 if (!wiphy_ext_feature_isset(&rdev->wiphy, 11226 NL80211_EXT_FEATURE_CQM_RSSI_LIST)) 11227 return -EOPNOTSUPP; 11228 11229 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ 11230 n_thresholds = 0; 11231 11232 wdev_lock(wdev); 11233 if (n_thresholds) { 11234 struct cfg80211_cqm_config *cqm_config; 11235 11236 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + 11237 n_thresholds * sizeof(s32), GFP_KERNEL); 11238 if (!cqm_config) { 11239 err = -ENOMEM; 11240 goto unlock; 11241 } 11242 11243 cqm_config->rssi_hyst = hysteresis; 11244 cqm_config->n_rssi_thresholds = n_thresholds; 11245 memcpy(cqm_config->rssi_thresholds, thresholds, 11246 n_thresholds * sizeof(s32)); 11247 11248 wdev->cqm_config = cqm_config; 11249 } 11250 11251 err = cfg80211_cqm_rssi_update(rdev, dev); 11252 11253 unlock: 11254 wdev_unlock(wdev); 11255 11256 return err; 11257 } 11258 11259 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 11260 { 11261 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; 11262 struct nlattr *cqm; 11263 int err; 11264 11265 cqm = info->attrs[NL80211_ATTR_CQM]; 11266 if (!cqm) 11267 return -EINVAL; 11268 11269 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, 11270 nl80211_attr_cqm_policy, 11271 info->extack); 11272 if (err) 11273 return err; 11274 11275 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && 11276 attrs[NL80211_ATTR_CQM_RSSI_HYST]) { 11277 const s32 *thresholds = 11278 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 11279 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 11280 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); 11281 11282 if (len % 4) 11283 return -EINVAL; 11284 11285 return nl80211_set_cqm_rssi(info, thresholds, len / 4, 11286 hysteresis); 11287 } 11288 11289 if (attrs[NL80211_ATTR_CQM_TXE_RATE] && 11290 attrs[NL80211_ATTR_CQM_TXE_PKTS] && 11291 attrs[NL80211_ATTR_CQM_TXE_INTVL]) { 11292 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); 11293 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); 11294 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); 11295 11296 return nl80211_set_cqm_txe(info, rate, pkts, intvl); 11297 } 11298 11299 return -EINVAL; 11300 } 11301 11302 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) 11303 { 11304 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11305 struct net_device *dev = info->user_ptr[1]; 11306 struct ocb_setup setup = {}; 11307 int err; 11308 11309 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 11310 if (err) 11311 return err; 11312 11313 return cfg80211_join_ocb(rdev, dev, &setup); 11314 } 11315 11316 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) 11317 { 11318 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11319 struct net_device *dev = info->user_ptr[1]; 11320 11321 return cfg80211_leave_ocb(rdev, dev); 11322 } 11323 11324 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 11325 { 11326 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11327 struct net_device *dev = info->user_ptr[1]; 11328 struct mesh_config cfg; 11329 struct mesh_setup setup; 11330 int err; 11331 11332 /* start with default */ 11333 memcpy(&cfg, &default_mesh_config, sizeof(cfg)); 11334 memcpy(&setup, &default_mesh_setup, sizeof(setup)); 11335 11336 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { 11337 /* and parse parameters if given */ 11338 err = nl80211_parse_mesh_config(info, &cfg, NULL); 11339 if (err) 11340 return err; 11341 } 11342 11343 if (!info->attrs[NL80211_ATTR_MESH_ID] || 11344 !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) 11345 return -EINVAL; 11346 11347 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 11348 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 11349 11350 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 11351 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, 11352 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 11353 return -EINVAL; 11354 11355 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { 11356 setup.beacon_interval = 11357 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 11358 11359 err = cfg80211_validate_beacon_int(rdev, 11360 NL80211_IFTYPE_MESH_POINT, 11361 setup.beacon_interval); 11362 if (err) 11363 return err; 11364 } 11365 11366 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 11367 setup.dtim_period = 11368 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 11369 if (setup.dtim_period < 1 || setup.dtim_period > 100) 11370 return -EINVAL; 11371 } 11372 11373 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 11374 /* parse additional setup parameters if given */ 11375 err = nl80211_parse_mesh_setup(info, &setup); 11376 if (err) 11377 return err; 11378 } 11379 11380 if (setup.user_mpm) 11381 cfg.auto_open_plinks = false; 11382 11383 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 11384 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 11385 if (err) 11386 return err; 11387 } else { 11388 /* __cfg80211_join_mesh() will sort it out */ 11389 setup.chandef.chan = NULL; 11390 } 11391 11392 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 11393 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11394 int n_rates = 11395 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11396 struct ieee80211_supported_band *sband; 11397 11398 if (!setup.chandef.chan) 11399 return -EINVAL; 11400 11401 sband = rdev->wiphy.bands[setup.chandef.chan->band]; 11402 11403 err = ieee80211_get_ratemask(sband, rates, n_rates, 11404 &setup.basic_rates); 11405 if (err) 11406 return err; 11407 } 11408 11409 if (info->attrs[NL80211_ATTR_TX_RATES]) { 11410 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 11411 NL80211_ATTR_TX_RATES, 11412 &setup.beacon_rate); 11413 if (err) 11414 return err; 11415 11416 if (!setup.chandef.chan) 11417 return -EINVAL; 11418 11419 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, 11420 &setup.beacon_rate); 11421 if (err) 11422 return err; 11423 } 11424 11425 setup.userspace_handles_dfs = 11426 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 11427 11428 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 11429 int r = validate_pae_over_nl80211(rdev, info); 11430 11431 if (r < 0) 11432 return r; 11433 11434 setup.control_port_over_nl80211 = true; 11435 } 11436 11437 wdev_lock(dev->ieee80211_ptr); 11438 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); 11439 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) 11440 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 11441 wdev_unlock(dev->ieee80211_ptr); 11442 11443 return err; 11444 } 11445 11446 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) 11447 { 11448 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11449 struct net_device *dev = info->user_ptr[1]; 11450 11451 return cfg80211_leave_mesh(rdev, dev); 11452 } 11453 11454 #ifdef CONFIG_PM 11455 static int nl80211_send_wowlan_patterns(struct sk_buff *msg, 11456 struct cfg80211_registered_device *rdev) 11457 { 11458 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; 11459 struct nlattr *nl_pats, *nl_pat; 11460 int i, pat_len; 11461 11462 if (!wowlan->n_patterns) 11463 return 0; 11464 11465 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 11466 if (!nl_pats) 11467 return -ENOBUFS; 11468 11469 for (i = 0; i < wowlan->n_patterns; i++) { 11470 nl_pat = nla_nest_start_noflag(msg, i + 1); 11471 if (!nl_pat) 11472 return -ENOBUFS; 11473 pat_len = wowlan->patterns[i].pattern_len; 11474 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), 11475 wowlan->patterns[i].mask) || 11476 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 11477 wowlan->patterns[i].pattern) || 11478 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 11479 wowlan->patterns[i].pkt_offset)) 11480 return -ENOBUFS; 11481 nla_nest_end(msg, nl_pat); 11482 } 11483 nla_nest_end(msg, nl_pats); 11484 11485 return 0; 11486 } 11487 11488 static int nl80211_send_wowlan_tcp(struct sk_buff *msg, 11489 struct cfg80211_wowlan_tcp *tcp) 11490 { 11491 struct nlattr *nl_tcp; 11492 11493 if (!tcp) 11494 return 0; 11495 11496 nl_tcp = nla_nest_start_noflag(msg, 11497 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 11498 if (!nl_tcp) 11499 return -ENOBUFS; 11500 11501 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 11502 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 11503 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 11504 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 11505 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || 11506 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 11507 tcp->payload_len, tcp->payload) || 11508 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 11509 tcp->data_interval) || 11510 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 11511 tcp->wake_len, tcp->wake_data) || 11512 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, 11513 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) 11514 return -ENOBUFS; 11515 11516 if (tcp->payload_seq.len && 11517 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, 11518 sizeof(tcp->payload_seq), &tcp->payload_seq)) 11519 return -ENOBUFS; 11520 11521 if (tcp->payload_tok.len && 11522 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 11523 sizeof(tcp->payload_tok) + tcp->tokens_size, 11524 &tcp->payload_tok)) 11525 return -ENOBUFS; 11526 11527 nla_nest_end(msg, nl_tcp); 11528 11529 return 0; 11530 } 11531 11532 static int nl80211_send_wowlan_nd(struct sk_buff *msg, 11533 struct cfg80211_sched_scan_request *req) 11534 { 11535 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; 11536 int i; 11537 11538 if (!req) 11539 return 0; 11540 11541 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 11542 if (!nd) 11543 return -ENOBUFS; 11544 11545 if (req->n_scan_plans == 1 && 11546 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, 11547 req->scan_plans[0].interval * 1000)) 11548 return -ENOBUFS; 11549 11550 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) 11551 return -ENOBUFS; 11552 11553 if (req->relative_rssi_set) { 11554 struct nl80211_bss_select_rssi_adjust rssi_adjust; 11555 11556 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, 11557 req->relative_rssi)) 11558 return -ENOBUFS; 11559 11560 rssi_adjust.band = req->rssi_adjust.band; 11561 rssi_adjust.delta = req->rssi_adjust.delta; 11562 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, 11563 sizeof(rssi_adjust), &rssi_adjust)) 11564 return -ENOBUFS; 11565 } 11566 11567 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 11568 if (!freqs) 11569 return -ENOBUFS; 11570 11571 for (i = 0; i < req->n_channels; i++) { 11572 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 11573 return -ENOBUFS; 11574 } 11575 11576 nla_nest_end(msg, freqs); 11577 11578 if (req->n_match_sets) { 11579 matches = nla_nest_start_noflag(msg, 11580 NL80211_ATTR_SCHED_SCAN_MATCH); 11581 if (!matches) 11582 return -ENOBUFS; 11583 11584 for (i = 0; i < req->n_match_sets; i++) { 11585 match = nla_nest_start_noflag(msg, i); 11586 if (!match) 11587 return -ENOBUFS; 11588 11589 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, 11590 req->match_sets[i].ssid.ssid_len, 11591 req->match_sets[i].ssid.ssid)) 11592 return -ENOBUFS; 11593 nla_nest_end(msg, match); 11594 } 11595 nla_nest_end(msg, matches); 11596 } 11597 11598 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 11599 if (!scan_plans) 11600 return -ENOBUFS; 11601 11602 for (i = 0; i < req->n_scan_plans; i++) { 11603 scan_plan = nla_nest_start_noflag(msg, i + 1); 11604 if (!scan_plan) 11605 return -ENOBUFS; 11606 11607 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, 11608 req->scan_plans[i].interval) || 11609 (req->scan_plans[i].iterations && 11610 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, 11611 req->scan_plans[i].iterations))) 11612 return -ENOBUFS; 11613 nla_nest_end(msg, scan_plan); 11614 } 11615 nla_nest_end(msg, scan_plans); 11616 11617 nla_nest_end(msg, nd); 11618 11619 return 0; 11620 } 11621 11622 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) 11623 { 11624 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11625 struct sk_buff *msg; 11626 void *hdr; 11627 u32 size = NLMSG_DEFAULT_SIZE; 11628 11629 if (!rdev->wiphy.wowlan) 11630 return -EOPNOTSUPP; 11631 11632 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { 11633 /* adjust size to have room for all the data */ 11634 size += rdev->wiphy.wowlan_config->tcp->tokens_size + 11635 rdev->wiphy.wowlan_config->tcp->payload_len + 11636 rdev->wiphy.wowlan_config->tcp->wake_len + 11637 rdev->wiphy.wowlan_config->tcp->wake_len / 8; 11638 } 11639 11640 msg = nlmsg_new(size, GFP_KERNEL); 11641 if (!msg) 11642 return -ENOMEM; 11643 11644 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11645 NL80211_CMD_GET_WOWLAN); 11646 if (!hdr) 11647 goto nla_put_failure; 11648 11649 if (rdev->wiphy.wowlan_config) { 11650 struct nlattr *nl_wowlan; 11651 11652 nl_wowlan = nla_nest_start_noflag(msg, 11653 NL80211_ATTR_WOWLAN_TRIGGERS); 11654 if (!nl_wowlan) 11655 goto nla_put_failure; 11656 11657 if ((rdev->wiphy.wowlan_config->any && 11658 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 11659 (rdev->wiphy.wowlan_config->disconnect && 11660 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 11661 (rdev->wiphy.wowlan_config->magic_pkt && 11662 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 11663 (rdev->wiphy.wowlan_config->gtk_rekey_failure && 11664 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 11665 (rdev->wiphy.wowlan_config->eap_identity_req && 11666 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 11667 (rdev->wiphy.wowlan_config->four_way_handshake && 11668 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 11669 (rdev->wiphy.wowlan_config->rfkill_release && 11670 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 11671 goto nla_put_failure; 11672 11673 if (nl80211_send_wowlan_patterns(msg, rdev)) 11674 goto nla_put_failure; 11675 11676 if (nl80211_send_wowlan_tcp(msg, 11677 rdev->wiphy.wowlan_config->tcp)) 11678 goto nla_put_failure; 11679 11680 if (nl80211_send_wowlan_nd( 11681 msg, 11682 rdev->wiphy.wowlan_config->nd_config)) 11683 goto nla_put_failure; 11684 11685 nla_nest_end(msg, nl_wowlan); 11686 } 11687 11688 genlmsg_end(msg, hdr); 11689 return genlmsg_reply(msg, info); 11690 11691 nla_put_failure: 11692 nlmsg_free(msg); 11693 return -ENOBUFS; 11694 } 11695 11696 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, 11697 struct nlattr *attr, 11698 struct cfg80211_wowlan *trig) 11699 { 11700 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; 11701 struct cfg80211_wowlan_tcp *cfg; 11702 struct nl80211_wowlan_tcp_data_token *tok = NULL; 11703 struct nl80211_wowlan_tcp_data_seq *seq = NULL; 11704 u32 size; 11705 u32 data_size, wake_size, tokens_size = 0, wake_mask_size; 11706 int err, port; 11707 11708 if (!rdev->wiphy.wowlan->tcp) 11709 return -EINVAL; 11710 11711 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, 11712 nl80211_wowlan_tcp_policy, NULL); 11713 if (err) 11714 return err; 11715 11716 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || 11717 !tb[NL80211_WOWLAN_TCP_DST_IPV4] || 11718 !tb[NL80211_WOWLAN_TCP_DST_MAC] || 11719 !tb[NL80211_WOWLAN_TCP_DST_PORT] || 11720 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || 11721 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || 11722 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || 11723 !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) 11724 return -EINVAL; 11725 11726 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); 11727 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) 11728 return -EINVAL; 11729 11730 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > 11731 rdev->wiphy.wowlan->tcp->data_interval_max || 11732 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) 11733 return -EINVAL; 11734 11735 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); 11736 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) 11737 return -EINVAL; 11738 11739 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); 11740 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) 11741 return -EINVAL; 11742 11743 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { 11744 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 11745 11746 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 11747 tokens_size = tokln - sizeof(*tok); 11748 11749 if (!tok->len || tokens_size % tok->len) 11750 return -EINVAL; 11751 if (!rdev->wiphy.wowlan->tcp->tok) 11752 return -EINVAL; 11753 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) 11754 return -EINVAL; 11755 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) 11756 return -EINVAL; 11757 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) 11758 return -EINVAL; 11759 if (tok->offset + tok->len > data_size) 11760 return -EINVAL; 11761 } 11762 11763 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { 11764 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); 11765 if (!rdev->wiphy.wowlan->tcp->seq) 11766 return -EINVAL; 11767 if (seq->len == 0 || seq->len > 4) 11768 return -EINVAL; 11769 if (seq->len + seq->offset > data_size) 11770 return -EINVAL; 11771 } 11772 11773 size = sizeof(*cfg); 11774 size += data_size; 11775 size += wake_size + wake_mask_size; 11776 size += tokens_size; 11777 11778 cfg = kzalloc(size, GFP_KERNEL); 11779 if (!cfg) 11780 return -ENOMEM; 11781 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); 11782 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 11783 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 11784 ETH_ALEN); 11785 if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 11786 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 11787 else 11788 port = 0; 11789 #ifdef CONFIG_INET 11790 /* allocate a socket and port for it and use it */ 11791 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, 11792 IPPROTO_TCP, &cfg->sock, 1); 11793 if (err) { 11794 kfree(cfg); 11795 return err; 11796 } 11797 if (inet_csk_get_port(cfg->sock->sk, port)) { 11798 sock_release(cfg->sock); 11799 kfree(cfg); 11800 return -EADDRINUSE; 11801 } 11802 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; 11803 #else 11804 if (!port) { 11805 kfree(cfg); 11806 return -EINVAL; 11807 } 11808 cfg->src_port = port; 11809 #endif 11810 11811 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); 11812 cfg->payload_len = data_size; 11813 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; 11814 memcpy((void *)cfg->payload, 11815 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), 11816 data_size); 11817 if (seq) 11818 cfg->payload_seq = *seq; 11819 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); 11820 cfg->wake_len = wake_size; 11821 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; 11822 memcpy((void *)cfg->wake_data, 11823 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), 11824 wake_size); 11825 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + 11826 data_size + wake_size; 11827 memcpy((void *)cfg->wake_mask, 11828 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), 11829 wake_mask_size); 11830 if (tok) { 11831 cfg->tokens_size = tokens_size; 11832 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); 11833 } 11834 11835 trig->tcp = cfg; 11836 11837 return 0; 11838 } 11839 11840 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, 11841 const struct wiphy_wowlan_support *wowlan, 11842 struct nlattr *attr, 11843 struct cfg80211_wowlan *trig) 11844 { 11845 struct nlattr **tb; 11846 int err; 11847 11848 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 11849 if (!tb) 11850 return -ENOMEM; 11851 11852 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { 11853 err = -EOPNOTSUPP; 11854 goto out; 11855 } 11856 11857 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, 11858 nl80211_policy, NULL); 11859 if (err) 11860 goto out; 11861 11862 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, 11863 wowlan->max_nd_match_sets); 11864 err = PTR_ERR_OR_ZERO(trig->nd_config); 11865 if (err) 11866 trig->nd_config = NULL; 11867 11868 out: 11869 kfree(tb); 11870 return err; 11871 } 11872 11873 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) 11874 { 11875 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11876 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; 11877 struct cfg80211_wowlan new_triggers = {}; 11878 struct cfg80211_wowlan *ntrig; 11879 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; 11880 int err, i; 11881 bool prev_enabled = rdev->wiphy.wowlan_config; 11882 bool regular = false; 11883 11884 if (!wowlan) 11885 return -EOPNOTSUPP; 11886 11887 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { 11888 cfg80211_rdev_free_wowlan(rdev); 11889 rdev->wiphy.wowlan_config = NULL; 11890 goto set_wakeup; 11891 } 11892 11893 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, 11894 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 11895 nl80211_wowlan_policy, info->extack); 11896 if (err) 11897 return err; 11898 11899 if (tb[NL80211_WOWLAN_TRIG_ANY]) { 11900 if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) 11901 return -EINVAL; 11902 new_triggers.any = true; 11903 } 11904 11905 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { 11906 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) 11907 return -EINVAL; 11908 new_triggers.disconnect = true; 11909 regular = true; 11910 } 11911 11912 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { 11913 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) 11914 return -EINVAL; 11915 new_triggers.magic_pkt = true; 11916 regular = true; 11917 } 11918 11919 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) 11920 return -EINVAL; 11921 11922 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { 11923 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) 11924 return -EINVAL; 11925 new_triggers.gtk_rekey_failure = true; 11926 regular = true; 11927 } 11928 11929 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { 11930 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) 11931 return -EINVAL; 11932 new_triggers.eap_identity_req = true; 11933 regular = true; 11934 } 11935 11936 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { 11937 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) 11938 return -EINVAL; 11939 new_triggers.four_way_handshake = true; 11940 regular = true; 11941 } 11942 11943 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { 11944 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) 11945 return -EINVAL; 11946 new_triggers.rfkill_release = true; 11947 regular = true; 11948 } 11949 11950 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { 11951 struct nlattr *pat; 11952 int n_patterns = 0; 11953 int rem, pat_len, mask_len, pkt_offset; 11954 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 11955 11956 regular = true; 11957 11958 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 11959 rem) 11960 n_patterns++; 11961 if (n_patterns > wowlan->n_patterns) 11962 return -EINVAL; 11963 11964 new_triggers.patterns = kcalloc(n_patterns, 11965 sizeof(new_triggers.patterns[0]), 11966 GFP_KERNEL); 11967 if (!new_triggers.patterns) 11968 return -ENOMEM; 11969 11970 new_triggers.n_patterns = n_patterns; 11971 i = 0; 11972 11973 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 11974 rem) { 11975 u8 *mask_pat; 11976 11977 err = nla_parse_nested_deprecated(pat_tb, 11978 MAX_NL80211_PKTPAT, 11979 pat, 11980 nl80211_packet_pattern_policy, 11981 info->extack); 11982 if (err) 11983 goto error; 11984 11985 err = -EINVAL; 11986 if (!pat_tb[NL80211_PKTPAT_MASK] || 11987 !pat_tb[NL80211_PKTPAT_PATTERN]) 11988 goto error; 11989 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 11990 mask_len = DIV_ROUND_UP(pat_len, 8); 11991 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 11992 goto error; 11993 if (pat_len > wowlan->pattern_max_len || 11994 pat_len < wowlan->pattern_min_len) 11995 goto error; 11996 11997 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 11998 pkt_offset = 0; 11999 else 12000 pkt_offset = nla_get_u32( 12001 pat_tb[NL80211_PKTPAT_OFFSET]); 12002 if (pkt_offset > wowlan->max_pkt_offset) 12003 goto error; 12004 new_triggers.patterns[i].pkt_offset = pkt_offset; 12005 12006 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 12007 if (!mask_pat) { 12008 err = -ENOMEM; 12009 goto error; 12010 } 12011 new_triggers.patterns[i].mask = mask_pat; 12012 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 12013 mask_len); 12014 mask_pat += mask_len; 12015 new_triggers.patterns[i].pattern = mask_pat; 12016 new_triggers.patterns[i].pattern_len = pat_len; 12017 memcpy(mask_pat, 12018 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 12019 pat_len); 12020 i++; 12021 } 12022 } 12023 12024 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { 12025 regular = true; 12026 err = nl80211_parse_wowlan_tcp( 12027 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], 12028 &new_triggers); 12029 if (err) 12030 goto error; 12031 } 12032 12033 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { 12034 regular = true; 12035 err = nl80211_parse_wowlan_nd( 12036 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], 12037 &new_triggers); 12038 if (err) 12039 goto error; 12040 } 12041 12042 /* The 'any' trigger means the device continues operating more or less 12043 * as in its normal operation mode and wakes up the host on most of the 12044 * normal interrupts (like packet RX, ...) 12045 * It therefore makes little sense to combine with the more constrained 12046 * wakeup trigger modes. 12047 */ 12048 if (new_triggers.any && regular) { 12049 err = -EINVAL; 12050 goto error; 12051 } 12052 12053 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); 12054 if (!ntrig) { 12055 err = -ENOMEM; 12056 goto error; 12057 } 12058 cfg80211_rdev_free_wowlan(rdev); 12059 rdev->wiphy.wowlan_config = ntrig; 12060 12061 set_wakeup: 12062 if (rdev->ops->set_wakeup && 12063 prev_enabled != !!rdev->wiphy.wowlan_config) 12064 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); 12065 12066 return 0; 12067 error: 12068 for (i = 0; i < new_triggers.n_patterns; i++) 12069 kfree(new_triggers.patterns[i].mask); 12070 kfree(new_triggers.patterns); 12071 if (new_triggers.tcp && new_triggers.tcp->sock) 12072 sock_release(new_triggers.tcp->sock); 12073 kfree(new_triggers.tcp); 12074 kfree(new_triggers.nd_config); 12075 return err; 12076 } 12077 #endif 12078 12079 static int nl80211_send_coalesce_rules(struct sk_buff *msg, 12080 struct cfg80211_registered_device *rdev) 12081 { 12082 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; 12083 int i, j, pat_len; 12084 struct cfg80211_coalesce_rules *rule; 12085 12086 if (!rdev->coalesce->n_rules) 12087 return 0; 12088 12089 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); 12090 if (!nl_rules) 12091 return -ENOBUFS; 12092 12093 for (i = 0; i < rdev->coalesce->n_rules; i++) { 12094 nl_rule = nla_nest_start_noflag(msg, i + 1); 12095 if (!nl_rule) 12096 return -ENOBUFS; 12097 12098 rule = &rdev->coalesce->rules[i]; 12099 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, 12100 rule->delay)) 12101 return -ENOBUFS; 12102 12103 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, 12104 rule->condition)) 12105 return -ENOBUFS; 12106 12107 nl_pats = nla_nest_start_noflag(msg, 12108 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 12109 if (!nl_pats) 12110 return -ENOBUFS; 12111 12112 for (j = 0; j < rule->n_patterns; j++) { 12113 nl_pat = nla_nest_start_noflag(msg, j + 1); 12114 if (!nl_pat) 12115 return -ENOBUFS; 12116 pat_len = rule->patterns[j].pattern_len; 12117 if (nla_put(msg, NL80211_PKTPAT_MASK, 12118 DIV_ROUND_UP(pat_len, 8), 12119 rule->patterns[j].mask) || 12120 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 12121 rule->patterns[j].pattern) || 12122 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 12123 rule->patterns[j].pkt_offset)) 12124 return -ENOBUFS; 12125 nla_nest_end(msg, nl_pat); 12126 } 12127 nla_nest_end(msg, nl_pats); 12128 nla_nest_end(msg, nl_rule); 12129 } 12130 nla_nest_end(msg, nl_rules); 12131 12132 return 0; 12133 } 12134 12135 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) 12136 { 12137 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12138 struct sk_buff *msg; 12139 void *hdr; 12140 12141 if (!rdev->wiphy.coalesce) 12142 return -EOPNOTSUPP; 12143 12144 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12145 if (!msg) 12146 return -ENOMEM; 12147 12148 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12149 NL80211_CMD_GET_COALESCE); 12150 if (!hdr) 12151 goto nla_put_failure; 12152 12153 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) 12154 goto nla_put_failure; 12155 12156 genlmsg_end(msg, hdr); 12157 return genlmsg_reply(msg, info); 12158 12159 nla_put_failure: 12160 nlmsg_free(msg); 12161 return -ENOBUFS; 12162 } 12163 12164 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) 12165 { 12166 struct cfg80211_coalesce *coalesce = rdev->coalesce; 12167 int i, j; 12168 struct cfg80211_coalesce_rules *rule; 12169 12170 if (!coalesce) 12171 return; 12172 12173 for (i = 0; i < coalesce->n_rules; i++) { 12174 rule = &coalesce->rules[i]; 12175 for (j = 0; j < rule->n_patterns; j++) 12176 kfree(rule->patterns[j].mask); 12177 kfree(rule->patterns); 12178 } 12179 kfree(coalesce->rules); 12180 kfree(coalesce); 12181 rdev->coalesce = NULL; 12182 } 12183 12184 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, 12185 struct nlattr *rule, 12186 struct cfg80211_coalesce_rules *new_rule) 12187 { 12188 int err, i; 12189 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 12190 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; 12191 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 12192 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 12193 12194 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, 12195 rule, nl80211_coalesce_policy, NULL); 12196 if (err) 12197 return err; 12198 12199 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) 12200 new_rule->delay = 12201 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); 12202 if (new_rule->delay > coalesce->max_delay) 12203 return -EINVAL; 12204 12205 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) 12206 new_rule->condition = 12207 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); 12208 12209 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) 12210 return -EINVAL; 12211 12212 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 12213 rem) 12214 n_patterns++; 12215 if (n_patterns > coalesce->n_patterns) 12216 return -EINVAL; 12217 12218 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), 12219 GFP_KERNEL); 12220 if (!new_rule->patterns) 12221 return -ENOMEM; 12222 12223 new_rule->n_patterns = n_patterns; 12224 i = 0; 12225 12226 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 12227 rem) { 12228 u8 *mask_pat; 12229 12230 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, 12231 pat, 12232 nl80211_packet_pattern_policy, 12233 NULL); 12234 if (err) 12235 return err; 12236 12237 if (!pat_tb[NL80211_PKTPAT_MASK] || 12238 !pat_tb[NL80211_PKTPAT_PATTERN]) 12239 return -EINVAL; 12240 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 12241 mask_len = DIV_ROUND_UP(pat_len, 8); 12242 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 12243 return -EINVAL; 12244 if (pat_len > coalesce->pattern_max_len || 12245 pat_len < coalesce->pattern_min_len) 12246 return -EINVAL; 12247 12248 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 12249 pkt_offset = 0; 12250 else 12251 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 12252 if (pkt_offset > coalesce->max_pkt_offset) 12253 return -EINVAL; 12254 new_rule->patterns[i].pkt_offset = pkt_offset; 12255 12256 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 12257 if (!mask_pat) 12258 return -ENOMEM; 12259 12260 new_rule->patterns[i].mask = mask_pat; 12261 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 12262 mask_len); 12263 12264 mask_pat += mask_len; 12265 new_rule->patterns[i].pattern = mask_pat; 12266 new_rule->patterns[i].pattern_len = pat_len; 12267 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 12268 pat_len); 12269 i++; 12270 } 12271 12272 return 0; 12273 } 12274 12275 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) 12276 { 12277 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12278 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 12279 struct cfg80211_coalesce new_coalesce = {}; 12280 struct cfg80211_coalesce *n_coalesce; 12281 int err, rem_rule, n_rules = 0, i, j; 12282 struct nlattr *rule; 12283 struct cfg80211_coalesce_rules *tmp_rule; 12284 12285 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) 12286 return -EOPNOTSUPP; 12287 12288 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { 12289 cfg80211_rdev_free_coalesce(rdev); 12290 rdev_set_coalesce(rdev, NULL); 12291 return 0; 12292 } 12293 12294 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 12295 rem_rule) 12296 n_rules++; 12297 if (n_rules > coalesce->n_rules) 12298 return -EINVAL; 12299 12300 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), 12301 GFP_KERNEL); 12302 if (!new_coalesce.rules) 12303 return -ENOMEM; 12304 12305 new_coalesce.n_rules = n_rules; 12306 i = 0; 12307 12308 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 12309 rem_rule) { 12310 err = nl80211_parse_coalesce_rule(rdev, rule, 12311 &new_coalesce.rules[i]); 12312 if (err) 12313 goto error; 12314 12315 i++; 12316 } 12317 12318 err = rdev_set_coalesce(rdev, &new_coalesce); 12319 if (err) 12320 goto error; 12321 12322 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); 12323 if (!n_coalesce) { 12324 err = -ENOMEM; 12325 goto error; 12326 } 12327 cfg80211_rdev_free_coalesce(rdev); 12328 rdev->coalesce = n_coalesce; 12329 12330 return 0; 12331 error: 12332 for (i = 0; i < new_coalesce.n_rules; i++) { 12333 tmp_rule = &new_coalesce.rules[i]; 12334 for (j = 0; j < tmp_rule->n_patterns; j++) 12335 kfree(tmp_rule->patterns[j].mask); 12336 kfree(tmp_rule->patterns); 12337 } 12338 kfree(new_coalesce.rules); 12339 12340 return err; 12341 } 12342 12343 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) 12344 { 12345 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12346 struct net_device *dev = info->user_ptr[1]; 12347 struct wireless_dev *wdev = dev->ieee80211_ptr; 12348 struct nlattr *tb[NUM_NL80211_REKEY_DATA]; 12349 struct cfg80211_gtk_rekey_data rekey_data; 12350 int err; 12351 12352 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 12353 return -EINVAL; 12354 12355 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, 12356 info->attrs[NL80211_ATTR_REKEY_DATA], 12357 nl80211_rekey_policy, info->extack); 12358 if (err) 12359 return err; 12360 12361 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || 12362 !tb[NL80211_REKEY_DATA_KCK]) 12363 return -EINVAL; 12364 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) 12365 return -ERANGE; 12366 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && 12367 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 12368 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) 12369 return -ERANGE; 12370 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && 12371 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 12372 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) 12373 return -ERANGE; 12374 12375 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); 12376 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); 12377 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); 12378 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); 12379 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); 12380 if (tb[NL80211_REKEY_DATA_AKM]) 12381 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); 12382 12383 wdev_lock(wdev); 12384 if (!wdev->current_bss) { 12385 err = -ENOTCONN; 12386 goto out; 12387 } 12388 12389 if (!rdev->ops->set_rekey_data) { 12390 err = -EOPNOTSUPP; 12391 goto out; 12392 } 12393 12394 err = rdev_set_rekey_data(rdev, dev, &rekey_data); 12395 out: 12396 wdev_unlock(wdev); 12397 return err; 12398 } 12399 12400 static int nl80211_register_unexpected_frame(struct sk_buff *skb, 12401 struct genl_info *info) 12402 { 12403 struct net_device *dev = info->user_ptr[1]; 12404 struct wireless_dev *wdev = dev->ieee80211_ptr; 12405 12406 if (wdev->iftype != NL80211_IFTYPE_AP && 12407 wdev->iftype != NL80211_IFTYPE_P2P_GO) 12408 return -EINVAL; 12409 12410 if (wdev->ap_unexpected_nlportid) 12411 return -EBUSY; 12412 12413 wdev->ap_unexpected_nlportid = info->snd_portid; 12414 return 0; 12415 } 12416 12417 static int nl80211_probe_client(struct sk_buff *skb, 12418 struct genl_info *info) 12419 { 12420 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12421 struct net_device *dev = info->user_ptr[1]; 12422 struct wireless_dev *wdev = dev->ieee80211_ptr; 12423 struct sk_buff *msg; 12424 void *hdr; 12425 const u8 *addr; 12426 u64 cookie; 12427 int err; 12428 12429 if (wdev->iftype != NL80211_IFTYPE_AP && 12430 wdev->iftype != NL80211_IFTYPE_P2P_GO) 12431 return -EOPNOTSUPP; 12432 12433 if (!info->attrs[NL80211_ATTR_MAC]) 12434 return -EINVAL; 12435 12436 if (!rdev->ops->probe_client) 12437 return -EOPNOTSUPP; 12438 12439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12440 if (!msg) 12441 return -ENOMEM; 12442 12443 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12444 NL80211_CMD_PROBE_CLIENT); 12445 if (!hdr) { 12446 err = -ENOBUFS; 12447 goto free_msg; 12448 } 12449 12450 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 12451 12452 err = rdev_probe_client(rdev, dev, addr, &cookie); 12453 if (err) 12454 goto free_msg; 12455 12456 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12457 NL80211_ATTR_PAD)) 12458 goto nla_put_failure; 12459 12460 genlmsg_end(msg, hdr); 12461 12462 return genlmsg_reply(msg, info); 12463 12464 nla_put_failure: 12465 err = -ENOBUFS; 12466 free_msg: 12467 nlmsg_free(msg); 12468 return err; 12469 } 12470 12471 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) 12472 { 12473 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12474 struct cfg80211_beacon_registration *reg, *nreg; 12475 int rv; 12476 12477 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) 12478 return -EOPNOTSUPP; 12479 12480 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); 12481 if (!nreg) 12482 return -ENOMEM; 12483 12484 /* First, check if already registered. */ 12485 spin_lock_bh(&rdev->beacon_registrations_lock); 12486 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 12487 if (reg->nlportid == info->snd_portid) { 12488 rv = -EALREADY; 12489 goto out_err; 12490 } 12491 } 12492 /* Add it to the list */ 12493 nreg->nlportid = info->snd_portid; 12494 list_add(&nreg->list, &rdev->beacon_registrations); 12495 12496 spin_unlock_bh(&rdev->beacon_registrations_lock); 12497 12498 return 0; 12499 out_err: 12500 spin_unlock_bh(&rdev->beacon_registrations_lock); 12501 kfree(nreg); 12502 return rv; 12503 } 12504 12505 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) 12506 { 12507 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12508 struct wireless_dev *wdev = info->user_ptr[1]; 12509 int err; 12510 12511 if (!rdev->ops->start_p2p_device) 12512 return -EOPNOTSUPP; 12513 12514 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 12515 return -EOPNOTSUPP; 12516 12517 if (wdev_running(wdev)) 12518 return 0; 12519 12520 if (rfkill_blocked(rdev->rfkill)) 12521 return -ERFKILL; 12522 12523 err = rdev_start_p2p_device(rdev, wdev); 12524 if (err) 12525 return err; 12526 12527 wdev->is_running = true; 12528 rdev->opencount++; 12529 12530 return 0; 12531 } 12532 12533 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) 12534 { 12535 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12536 struct wireless_dev *wdev = info->user_ptr[1]; 12537 12538 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 12539 return -EOPNOTSUPP; 12540 12541 if (!rdev->ops->stop_p2p_device) 12542 return -EOPNOTSUPP; 12543 12544 cfg80211_stop_p2p_device(rdev, wdev); 12545 12546 return 0; 12547 } 12548 12549 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) 12550 { 12551 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12552 struct wireless_dev *wdev = info->user_ptr[1]; 12553 struct cfg80211_nan_conf conf = {}; 12554 int err; 12555 12556 if (wdev->iftype != NL80211_IFTYPE_NAN) 12557 return -EOPNOTSUPP; 12558 12559 if (wdev_running(wdev)) 12560 return -EEXIST; 12561 12562 if (rfkill_blocked(rdev->rfkill)) 12563 return -ERFKILL; 12564 12565 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) 12566 return -EINVAL; 12567 12568 conf.master_pref = 12569 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 12570 12571 if (info->attrs[NL80211_ATTR_BANDS]) { 12572 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 12573 12574 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 12575 return -EOPNOTSUPP; 12576 12577 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 12578 return -EINVAL; 12579 12580 conf.bands = bands; 12581 } 12582 12583 err = rdev_start_nan(rdev, wdev, &conf); 12584 if (err) 12585 return err; 12586 12587 wdev->is_running = true; 12588 rdev->opencount++; 12589 12590 return 0; 12591 } 12592 12593 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) 12594 { 12595 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12596 struct wireless_dev *wdev = info->user_ptr[1]; 12597 12598 if (wdev->iftype != NL80211_IFTYPE_NAN) 12599 return -EOPNOTSUPP; 12600 12601 cfg80211_stop_nan(rdev, wdev); 12602 12603 return 0; 12604 } 12605 12606 static int validate_nan_filter(struct nlattr *filter_attr) 12607 { 12608 struct nlattr *attr; 12609 int len = 0, n_entries = 0, rem; 12610 12611 nla_for_each_nested(attr, filter_attr, rem) { 12612 len += nla_len(attr); 12613 n_entries++; 12614 } 12615 12616 if (len >= U8_MAX) 12617 return -EINVAL; 12618 12619 return n_entries; 12620 } 12621 12622 static int handle_nan_filter(struct nlattr *attr_filter, 12623 struct cfg80211_nan_func *func, 12624 bool tx) 12625 { 12626 struct nlattr *attr; 12627 int n_entries, rem, i; 12628 struct cfg80211_nan_func_filter *filter; 12629 12630 n_entries = validate_nan_filter(attr_filter); 12631 if (n_entries < 0) 12632 return n_entries; 12633 12634 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); 12635 12636 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); 12637 if (!filter) 12638 return -ENOMEM; 12639 12640 i = 0; 12641 nla_for_each_nested(attr, attr_filter, rem) { 12642 filter[i].filter = nla_memdup(attr, GFP_KERNEL); 12643 filter[i].len = nla_len(attr); 12644 i++; 12645 } 12646 if (tx) { 12647 func->num_tx_filters = n_entries; 12648 func->tx_filters = filter; 12649 } else { 12650 func->num_rx_filters = n_entries; 12651 func->rx_filters = filter; 12652 } 12653 12654 return 0; 12655 } 12656 12657 static int nl80211_nan_add_func(struct sk_buff *skb, 12658 struct genl_info *info) 12659 { 12660 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12661 struct wireless_dev *wdev = info->user_ptr[1]; 12662 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; 12663 struct cfg80211_nan_func *func; 12664 struct sk_buff *msg = NULL; 12665 void *hdr = NULL; 12666 int err = 0; 12667 12668 if (wdev->iftype != NL80211_IFTYPE_NAN) 12669 return -EOPNOTSUPP; 12670 12671 if (!wdev_running(wdev)) 12672 return -ENOTCONN; 12673 12674 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 12675 return -EINVAL; 12676 12677 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, 12678 info->attrs[NL80211_ATTR_NAN_FUNC], 12679 nl80211_nan_func_policy, 12680 info->extack); 12681 if (err) 12682 return err; 12683 12684 func = kzalloc(sizeof(*func), GFP_KERNEL); 12685 if (!func) 12686 return -ENOMEM; 12687 12688 func->cookie = cfg80211_assign_cookie(rdev); 12689 12690 if (!tb[NL80211_NAN_FUNC_TYPE] || 12691 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { 12692 err = -EINVAL; 12693 goto out; 12694 } 12695 12696 12697 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); 12698 12699 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { 12700 err = -EINVAL; 12701 goto out; 12702 } 12703 12704 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), 12705 sizeof(func->service_id)); 12706 12707 func->close_range = 12708 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); 12709 12710 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { 12711 func->serv_spec_info_len = 12712 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); 12713 func->serv_spec_info = 12714 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), 12715 func->serv_spec_info_len, 12716 GFP_KERNEL); 12717 if (!func->serv_spec_info) { 12718 err = -ENOMEM; 12719 goto out; 12720 } 12721 } 12722 12723 if (tb[NL80211_NAN_FUNC_TTL]) 12724 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); 12725 12726 switch (func->type) { 12727 case NL80211_NAN_FUNC_PUBLISH: 12728 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { 12729 err = -EINVAL; 12730 goto out; 12731 } 12732 12733 func->publish_type = 12734 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); 12735 func->publish_bcast = 12736 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); 12737 12738 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && 12739 func->publish_bcast) { 12740 err = -EINVAL; 12741 goto out; 12742 } 12743 break; 12744 case NL80211_NAN_FUNC_SUBSCRIBE: 12745 func->subscribe_active = 12746 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); 12747 break; 12748 case NL80211_NAN_FUNC_FOLLOW_UP: 12749 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || 12750 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || 12751 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { 12752 err = -EINVAL; 12753 goto out; 12754 } 12755 12756 func->followup_id = 12757 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); 12758 func->followup_reqid = 12759 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); 12760 memcpy(func->followup_dest.addr, 12761 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), 12762 sizeof(func->followup_dest.addr)); 12763 if (func->ttl) { 12764 err = -EINVAL; 12765 goto out; 12766 } 12767 break; 12768 default: 12769 err = -EINVAL; 12770 goto out; 12771 } 12772 12773 if (tb[NL80211_NAN_FUNC_SRF]) { 12774 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 12775 12776 err = nla_parse_nested_deprecated(srf_tb, 12777 NL80211_NAN_SRF_ATTR_MAX, 12778 tb[NL80211_NAN_FUNC_SRF], 12779 nl80211_nan_srf_policy, 12780 info->extack); 12781 if (err) 12782 goto out; 12783 12784 func->srf_include = 12785 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); 12786 12787 if (srf_tb[NL80211_NAN_SRF_BF]) { 12788 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || 12789 !srf_tb[NL80211_NAN_SRF_BF_IDX]) { 12790 err = -EINVAL; 12791 goto out; 12792 } 12793 12794 func->srf_bf_len = 12795 nla_len(srf_tb[NL80211_NAN_SRF_BF]); 12796 func->srf_bf = 12797 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), 12798 func->srf_bf_len, GFP_KERNEL); 12799 if (!func->srf_bf) { 12800 err = -ENOMEM; 12801 goto out; 12802 } 12803 12804 func->srf_bf_idx = 12805 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); 12806 } else { 12807 struct nlattr *attr, *mac_attr = 12808 srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; 12809 int n_entries, rem, i = 0; 12810 12811 if (!mac_attr) { 12812 err = -EINVAL; 12813 goto out; 12814 } 12815 12816 n_entries = validate_acl_mac_addrs(mac_attr); 12817 if (n_entries <= 0) { 12818 err = -EINVAL; 12819 goto out; 12820 } 12821 12822 func->srf_num_macs = n_entries; 12823 func->srf_macs = 12824 kcalloc(n_entries, sizeof(*func->srf_macs), 12825 GFP_KERNEL); 12826 if (!func->srf_macs) { 12827 err = -ENOMEM; 12828 goto out; 12829 } 12830 12831 nla_for_each_nested(attr, mac_attr, rem) 12832 memcpy(func->srf_macs[i++].addr, nla_data(attr), 12833 sizeof(*func->srf_macs)); 12834 } 12835 } 12836 12837 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { 12838 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], 12839 func, true); 12840 if (err) 12841 goto out; 12842 } 12843 12844 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { 12845 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], 12846 func, false); 12847 if (err) 12848 goto out; 12849 } 12850 12851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12852 if (!msg) { 12853 err = -ENOMEM; 12854 goto out; 12855 } 12856 12857 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12858 NL80211_CMD_ADD_NAN_FUNCTION); 12859 /* This can't really happen - we just allocated 4KB */ 12860 if (WARN_ON(!hdr)) { 12861 err = -ENOMEM; 12862 goto out; 12863 } 12864 12865 err = rdev_add_nan_func(rdev, wdev, func); 12866 out: 12867 if (err < 0) { 12868 cfg80211_free_nan_func(func); 12869 nlmsg_free(msg); 12870 return err; 12871 } 12872 12873 /* propagate the instance id and cookie to userspace */ 12874 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, 12875 NL80211_ATTR_PAD)) 12876 goto nla_put_failure; 12877 12878 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 12879 if (!func_attr) 12880 goto nla_put_failure; 12881 12882 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, 12883 func->instance_id)) 12884 goto nla_put_failure; 12885 12886 nla_nest_end(msg, func_attr); 12887 12888 genlmsg_end(msg, hdr); 12889 return genlmsg_reply(msg, info); 12890 12891 nla_put_failure: 12892 nlmsg_free(msg); 12893 return -ENOBUFS; 12894 } 12895 12896 static int nl80211_nan_del_func(struct sk_buff *skb, 12897 struct genl_info *info) 12898 { 12899 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12900 struct wireless_dev *wdev = info->user_ptr[1]; 12901 u64 cookie; 12902 12903 if (wdev->iftype != NL80211_IFTYPE_NAN) 12904 return -EOPNOTSUPP; 12905 12906 if (!wdev_running(wdev)) 12907 return -ENOTCONN; 12908 12909 if (!info->attrs[NL80211_ATTR_COOKIE]) 12910 return -EINVAL; 12911 12912 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12913 12914 rdev_del_nan_func(rdev, wdev, cookie); 12915 12916 return 0; 12917 } 12918 12919 static int nl80211_nan_change_config(struct sk_buff *skb, 12920 struct genl_info *info) 12921 { 12922 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12923 struct wireless_dev *wdev = info->user_ptr[1]; 12924 struct cfg80211_nan_conf conf = {}; 12925 u32 changed = 0; 12926 12927 if (wdev->iftype != NL80211_IFTYPE_NAN) 12928 return -EOPNOTSUPP; 12929 12930 if (!wdev_running(wdev)) 12931 return -ENOTCONN; 12932 12933 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { 12934 conf.master_pref = 12935 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 12936 if (conf.master_pref <= 1 || conf.master_pref == 255) 12937 return -EINVAL; 12938 12939 changed |= CFG80211_NAN_CONF_CHANGED_PREF; 12940 } 12941 12942 if (info->attrs[NL80211_ATTR_BANDS]) { 12943 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 12944 12945 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 12946 return -EOPNOTSUPP; 12947 12948 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 12949 return -EINVAL; 12950 12951 conf.bands = bands; 12952 changed |= CFG80211_NAN_CONF_CHANGED_BANDS; 12953 } 12954 12955 if (!changed) 12956 return -EINVAL; 12957 12958 return rdev_nan_change_conf(rdev, wdev, &conf, changed); 12959 } 12960 12961 void cfg80211_nan_match(struct wireless_dev *wdev, 12962 struct cfg80211_nan_match_params *match, gfp_t gfp) 12963 { 12964 struct wiphy *wiphy = wdev->wiphy; 12965 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 12966 struct nlattr *match_attr, *local_func_attr, *peer_func_attr; 12967 struct sk_buff *msg; 12968 void *hdr; 12969 12970 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) 12971 return; 12972 12973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 12974 if (!msg) 12975 return; 12976 12977 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); 12978 if (!hdr) { 12979 nlmsg_free(msg); 12980 return; 12981 } 12982 12983 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 12984 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 12985 wdev->netdev->ifindex)) || 12986 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 12987 NL80211_ATTR_PAD)) 12988 goto nla_put_failure; 12989 12990 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, 12991 NL80211_ATTR_PAD) || 12992 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 12993 goto nla_put_failure; 12994 12995 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); 12996 if (!match_attr) 12997 goto nla_put_failure; 12998 12999 local_func_attr = nla_nest_start_noflag(msg, 13000 NL80211_NAN_MATCH_FUNC_LOCAL); 13001 if (!local_func_attr) 13002 goto nla_put_failure; 13003 13004 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) 13005 goto nla_put_failure; 13006 13007 nla_nest_end(msg, local_func_attr); 13008 13009 peer_func_attr = nla_nest_start_noflag(msg, 13010 NL80211_NAN_MATCH_FUNC_PEER); 13011 if (!peer_func_attr) 13012 goto nla_put_failure; 13013 13014 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || 13015 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) 13016 goto nla_put_failure; 13017 13018 if (match->info && match->info_len && 13019 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, 13020 match->info)) 13021 goto nla_put_failure; 13022 13023 nla_nest_end(msg, peer_func_attr); 13024 nla_nest_end(msg, match_attr); 13025 genlmsg_end(msg, hdr); 13026 13027 if (!wdev->owner_nlportid) 13028 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 13029 msg, 0, NL80211_MCGRP_NAN, gfp); 13030 else 13031 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 13032 wdev->owner_nlportid); 13033 13034 return; 13035 13036 nla_put_failure: 13037 nlmsg_free(msg); 13038 } 13039 EXPORT_SYMBOL(cfg80211_nan_match); 13040 13041 void cfg80211_nan_func_terminated(struct wireless_dev *wdev, 13042 u8 inst_id, 13043 enum nl80211_nan_func_term_reason reason, 13044 u64 cookie, gfp_t gfp) 13045 { 13046 struct wiphy *wiphy = wdev->wiphy; 13047 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 13048 struct sk_buff *msg; 13049 struct nlattr *func_attr; 13050 void *hdr; 13051 13052 if (WARN_ON(!inst_id)) 13053 return; 13054 13055 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 13056 if (!msg) 13057 return; 13058 13059 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); 13060 if (!hdr) { 13061 nlmsg_free(msg); 13062 return; 13063 } 13064 13065 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 13066 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 13067 wdev->netdev->ifindex)) || 13068 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 13069 NL80211_ATTR_PAD)) 13070 goto nla_put_failure; 13071 13072 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 13073 NL80211_ATTR_PAD)) 13074 goto nla_put_failure; 13075 13076 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 13077 if (!func_attr) 13078 goto nla_put_failure; 13079 13080 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || 13081 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) 13082 goto nla_put_failure; 13083 13084 nla_nest_end(msg, func_attr); 13085 genlmsg_end(msg, hdr); 13086 13087 if (!wdev->owner_nlportid) 13088 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 13089 msg, 0, NL80211_MCGRP_NAN, gfp); 13090 else 13091 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 13092 wdev->owner_nlportid); 13093 13094 return; 13095 13096 nla_put_failure: 13097 nlmsg_free(msg); 13098 } 13099 EXPORT_SYMBOL(cfg80211_nan_func_terminated); 13100 13101 static int nl80211_get_protocol_features(struct sk_buff *skb, 13102 struct genl_info *info) 13103 { 13104 void *hdr; 13105 struct sk_buff *msg; 13106 13107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13108 if (!msg) 13109 return -ENOMEM; 13110 13111 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13112 NL80211_CMD_GET_PROTOCOL_FEATURES); 13113 if (!hdr) 13114 goto nla_put_failure; 13115 13116 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, 13117 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) 13118 goto nla_put_failure; 13119 13120 genlmsg_end(msg, hdr); 13121 return genlmsg_reply(msg, info); 13122 13123 nla_put_failure: 13124 kfree_skb(msg); 13125 return -ENOBUFS; 13126 } 13127 13128 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) 13129 { 13130 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13131 struct cfg80211_update_ft_ies_params ft_params; 13132 struct net_device *dev = info->user_ptr[1]; 13133 13134 if (!rdev->ops->update_ft_ies) 13135 return -EOPNOTSUPP; 13136 13137 if (!info->attrs[NL80211_ATTR_MDID] || 13138 !info->attrs[NL80211_ATTR_IE]) 13139 return -EINVAL; 13140 13141 memset(&ft_params, 0, sizeof(ft_params)); 13142 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); 13143 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 13144 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 13145 13146 return rdev_update_ft_ies(rdev, dev, &ft_params); 13147 } 13148 13149 static int nl80211_crit_protocol_start(struct sk_buff *skb, 13150 struct genl_info *info) 13151 { 13152 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13153 struct wireless_dev *wdev = info->user_ptr[1]; 13154 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; 13155 u16 duration; 13156 int ret; 13157 13158 if (!rdev->ops->crit_proto_start) 13159 return -EOPNOTSUPP; 13160 13161 if (WARN_ON(!rdev->ops->crit_proto_stop)) 13162 return -EINVAL; 13163 13164 if (rdev->crit_proto_nlportid) 13165 return -EBUSY; 13166 13167 /* determine protocol if provided */ 13168 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) 13169 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); 13170 13171 if (proto >= NUM_NL80211_CRIT_PROTO) 13172 return -EINVAL; 13173 13174 /* timeout must be provided */ 13175 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) 13176 return -EINVAL; 13177 13178 duration = 13179 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); 13180 13181 if (duration > NL80211_CRIT_PROTO_MAX_DURATION) 13182 return -ERANGE; 13183 13184 ret = rdev_crit_proto_start(rdev, wdev, proto, duration); 13185 if (!ret) 13186 rdev->crit_proto_nlportid = info->snd_portid; 13187 13188 return ret; 13189 } 13190 13191 static int nl80211_crit_protocol_stop(struct sk_buff *skb, 13192 struct genl_info *info) 13193 { 13194 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13195 struct wireless_dev *wdev = info->user_ptr[1]; 13196 13197 if (!rdev->ops->crit_proto_stop) 13198 return -EOPNOTSUPP; 13199 13200 if (rdev->crit_proto_nlportid) { 13201 rdev->crit_proto_nlportid = 0; 13202 rdev_crit_proto_stop(rdev, wdev); 13203 } 13204 return 0; 13205 } 13206 13207 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, 13208 struct nlattr *attr, 13209 struct netlink_ext_ack *extack) 13210 { 13211 if (vcmd->policy == VENDOR_CMD_RAW_DATA) { 13212 if (attr->nla_type & NLA_F_NESTED) { 13213 NL_SET_ERR_MSG_ATTR(extack, attr, 13214 "unexpected nested data"); 13215 return -EINVAL; 13216 } 13217 13218 return 0; 13219 } 13220 13221 if (!(attr->nla_type & NLA_F_NESTED)) { 13222 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); 13223 return -EINVAL; 13224 } 13225 13226 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); 13227 } 13228 13229 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) 13230 { 13231 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13232 struct wireless_dev *wdev = 13233 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); 13234 int i, err; 13235 u32 vid, subcmd; 13236 13237 if (!rdev->wiphy.vendor_commands) 13238 return -EOPNOTSUPP; 13239 13240 if (IS_ERR(wdev)) { 13241 err = PTR_ERR(wdev); 13242 if (err != -EINVAL) 13243 return err; 13244 wdev = NULL; 13245 } else if (wdev->wiphy != &rdev->wiphy) { 13246 return -EINVAL; 13247 } 13248 13249 if (!info->attrs[NL80211_ATTR_VENDOR_ID] || 13250 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) 13251 return -EINVAL; 13252 13253 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); 13254 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); 13255 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 13256 const struct wiphy_vendor_command *vcmd; 13257 void *data = NULL; 13258 int len = 0; 13259 13260 vcmd = &rdev->wiphy.vendor_commands[i]; 13261 13262 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 13263 continue; 13264 13265 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 13266 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 13267 if (!wdev) 13268 return -EINVAL; 13269 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 13270 !wdev->netdev) 13271 return -EINVAL; 13272 13273 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 13274 if (!wdev_running(wdev)) 13275 return -ENETDOWN; 13276 } 13277 } else { 13278 wdev = NULL; 13279 } 13280 13281 if (!vcmd->doit) 13282 return -EOPNOTSUPP; 13283 13284 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { 13285 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); 13286 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); 13287 13288 err = nl80211_vendor_check_policy(vcmd, 13289 info->attrs[NL80211_ATTR_VENDOR_DATA], 13290 info->extack); 13291 if (err) 13292 return err; 13293 } 13294 13295 rdev->cur_cmd_info = info; 13296 err = vcmd->doit(&rdev->wiphy, wdev, data, len); 13297 rdev->cur_cmd_info = NULL; 13298 return err; 13299 } 13300 13301 return -EOPNOTSUPP; 13302 } 13303 13304 static int nl80211_prepare_vendor_dump(struct sk_buff *skb, 13305 struct netlink_callback *cb, 13306 struct cfg80211_registered_device **rdev, 13307 struct wireless_dev **wdev) 13308 { 13309 struct nlattr **attrbuf; 13310 u32 vid, subcmd; 13311 unsigned int i; 13312 int vcmd_idx = -1; 13313 int err; 13314 void *data = NULL; 13315 unsigned int data_len = 0; 13316 13317 if (cb->args[0]) { 13318 /* subtract the 1 again here */ 13319 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 13320 struct wireless_dev *tmp; 13321 13322 if (!wiphy) 13323 return -ENODEV; 13324 *rdev = wiphy_to_rdev(wiphy); 13325 *wdev = NULL; 13326 13327 if (cb->args[1]) { 13328 list_for_each_entry(tmp, &wiphy->wdev_list, list) { 13329 if (tmp->identifier == cb->args[1] - 1) { 13330 *wdev = tmp; 13331 break; 13332 } 13333 } 13334 } 13335 13336 /* keep rtnl locked in successful case */ 13337 return 0; 13338 } 13339 13340 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 13341 if (!attrbuf) 13342 return -ENOMEM; 13343 13344 err = nlmsg_parse_deprecated(cb->nlh, 13345 GENL_HDRLEN + nl80211_fam.hdrsize, 13346 attrbuf, nl80211_fam.maxattr, 13347 nl80211_policy, NULL); 13348 if (err) 13349 goto out; 13350 13351 if (!attrbuf[NL80211_ATTR_VENDOR_ID] || 13352 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { 13353 err = -EINVAL; 13354 goto out; 13355 } 13356 13357 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); 13358 if (IS_ERR(*wdev)) 13359 *wdev = NULL; 13360 13361 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 13362 if (IS_ERR(*rdev)) { 13363 err = PTR_ERR(*rdev); 13364 goto out; 13365 } 13366 13367 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); 13368 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); 13369 13370 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { 13371 const struct wiphy_vendor_command *vcmd; 13372 13373 vcmd = &(*rdev)->wiphy.vendor_commands[i]; 13374 13375 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 13376 continue; 13377 13378 if (!vcmd->dumpit) { 13379 err = -EOPNOTSUPP; 13380 goto out; 13381 } 13382 13383 vcmd_idx = i; 13384 break; 13385 } 13386 13387 if (vcmd_idx < 0) { 13388 err = -EOPNOTSUPP; 13389 goto out; 13390 } 13391 13392 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { 13393 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); 13394 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); 13395 13396 err = nl80211_vendor_check_policy( 13397 &(*rdev)->wiphy.vendor_commands[vcmd_idx], 13398 attrbuf[NL80211_ATTR_VENDOR_DATA], 13399 cb->extack); 13400 if (err) 13401 goto out; 13402 } 13403 13404 /* 0 is the first index - add 1 to parse only once */ 13405 cb->args[0] = (*rdev)->wiphy_idx + 1; 13406 /* add 1 to know if it was NULL */ 13407 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; 13408 cb->args[2] = vcmd_idx; 13409 cb->args[3] = (unsigned long)data; 13410 cb->args[4] = data_len; 13411 13412 /* keep rtnl locked in successful case */ 13413 err = 0; 13414 out: 13415 kfree(attrbuf); 13416 return err; 13417 } 13418 13419 static int nl80211_vendor_cmd_dump(struct sk_buff *skb, 13420 struct netlink_callback *cb) 13421 { 13422 struct cfg80211_registered_device *rdev; 13423 struct wireless_dev *wdev; 13424 unsigned int vcmd_idx; 13425 const struct wiphy_vendor_command *vcmd; 13426 void *data; 13427 int data_len; 13428 int err; 13429 struct nlattr *vendor_data; 13430 13431 rtnl_lock(); 13432 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); 13433 if (err) 13434 goto out; 13435 13436 vcmd_idx = cb->args[2]; 13437 data = (void *)cb->args[3]; 13438 data_len = cb->args[4]; 13439 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; 13440 13441 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 13442 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 13443 if (!wdev) { 13444 err = -EINVAL; 13445 goto out; 13446 } 13447 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 13448 !wdev->netdev) { 13449 err = -EINVAL; 13450 goto out; 13451 } 13452 13453 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 13454 if (!wdev_running(wdev)) { 13455 err = -ENETDOWN; 13456 goto out; 13457 } 13458 } 13459 } 13460 13461 while (1) { 13462 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 13463 cb->nlh->nlmsg_seq, NLM_F_MULTI, 13464 NL80211_CMD_VENDOR); 13465 if (!hdr) 13466 break; 13467 13468 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 13469 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 13470 wdev_id(wdev), 13471 NL80211_ATTR_PAD))) { 13472 genlmsg_cancel(skb, hdr); 13473 break; 13474 } 13475 13476 vendor_data = nla_nest_start_noflag(skb, 13477 NL80211_ATTR_VENDOR_DATA); 13478 if (!vendor_data) { 13479 genlmsg_cancel(skb, hdr); 13480 break; 13481 } 13482 13483 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, 13484 (unsigned long *)&cb->args[5]); 13485 nla_nest_end(skb, vendor_data); 13486 13487 if (err == -ENOBUFS || err == -ENOENT) { 13488 genlmsg_cancel(skb, hdr); 13489 break; 13490 } else if (err <= 0) { 13491 genlmsg_cancel(skb, hdr); 13492 goto out; 13493 } 13494 13495 genlmsg_end(skb, hdr); 13496 } 13497 13498 err = skb->len; 13499 out: 13500 rtnl_unlock(); 13501 return err; 13502 } 13503 13504 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, 13505 enum nl80211_commands cmd, 13506 enum nl80211_attrs attr, 13507 int approxlen) 13508 { 13509 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 13510 13511 if (WARN_ON(!rdev->cur_cmd_info)) 13512 return NULL; 13513 13514 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, 13515 rdev->cur_cmd_info->snd_portid, 13516 rdev->cur_cmd_info->snd_seq, 13517 cmd, attr, NULL, GFP_KERNEL); 13518 } 13519 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); 13520 13521 int cfg80211_vendor_cmd_reply(struct sk_buff *skb) 13522 { 13523 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 13524 void *hdr = ((void **)skb->cb)[1]; 13525 struct nlattr *data = ((void **)skb->cb)[2]; 13526 13527 /* clear CB data for netlink core to own from now on */ 13528 memset(skb->cb, 0, sizeof(skb->cb)); 13529 13530 if (WARN_ON(!rdev->cur_cmd_info)) { 13531 kfree_skb(skb); 13532 return -EINVAL; 13533 } 13534 13535 nla_nest_end(skb, data); 13536 genlmsg_end(skb, hdr); 13537 return genlmsg_reply(skb, rdev->cur_cmd_info); 13538 } 13539 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); 13540 13541 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) 13542 { 13543 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 13544 13545 if (WARN_ON(!rdev->cur_cmd_info)) 13546 return 0; 13547 13548 return rdev->cur_cmd_info->snd_portid; 13549 } 13550 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); 13551 13552 static int nl80211_set_qos_map(struct sk_buff *skb, 13553 struct genl_info *info) 13554 { 13555 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13556 struct cfg80211_qos_map *qos_map = NULL; 13557 struct net_device *dev = info->user_ptr[1]; 13558 u8 *pos, len, num_des, des_len, des; 13559 int ret; 13560 13561 if (!rdev->ops->set_qos_map) 13562 return -EOPNOTSUPP; 13563 13564 if (info->attrs[NL80211_ATTR_QOS_MAP]) { 13565 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); 13566 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); 13567 13568 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || 13569 len > IEEE80211_QOS_MAP_LEN_MAX) 13570 return -EINVAL; 13571 13572 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); 13573 if (!qos_map) 13574 return -ENOMEM; 13575 13576 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; 13577 if (num_des) { 13578 des_len = num_des * 13579 sizeof(struct cfg80211_dscp_exception); 13580 memcpy(qos_map->dscp_exception, pos, des_len); 13581 qos_map->num_des = num_des; 13582 for (des = 0; des < num_des; des++) { 13583 if (qos_map->dscp_exception[des].up > 7) { 13584 kfree(qos_map); 13585 return -EINVAL; 13586 } 13587 } 13588 pos += des_len; 13589 } 13590 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); 13591 } 13592 13593 wdev_lock(dev->ieee80211_ptr); 13594 ret = nl80211_key_allowed(dev->ieee80211_ptr); 13595 if (!ret) 13596 ret = rdev_set_qos_map(rdev, dev, qos_map); 13597 wdev_unlock(dev->ieee80211_ptr); 13598 13599 kfree(qos_map); 13600 return ret; 13601 } 13602 13603 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) 13604 { 13605 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13606 struct net_device *dev = info->user_ptr[1]; 13607 struct wireless_dev *wdev = dev->ieee80211_ptr; 13608 const u8 *peer; 13609 u8 tsid, up; 13610 u16 admitted_time = 0; 13611 int err; 13612 13613 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) 13614 return -EOPNOTSUPP; 13615 13616 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 13617 !info->attrs[NL80211_ATTR_USER_PRIO]) 13618 return -EINVAL; 13619 13620 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 13621 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); 13622 13623 /* WMM uses TIDs 0-7 even for TSPEC */ 13624 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { 13625 /* TODO: handle 802.11 TSPEC/admission control 13626 * need more attributes for that (e.g. BA session requirement); 13627 * change the WMM adminssion test above to allow both then 13628 */ 13629 return -EINVAL; 13630 } 13631 13632 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 13633 13634 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { 13635 admitted_time = 13636 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); 13637 if (!admitted_time) 13638 return -EINVAL; 13639 } 13640 13641 wdev_lock(wdev); 13642 switch (wdev->iftype) { 13643 case NL80211_IFTYPE_STATION: 13644 case NL80211_IFTYPE_P2P_CLIENT: 13645 if (wdev->current_bss) 13646 break; 13647 err = -ENOTCONN; 13648 goto out; 13649 default: 13650 err = -EOPNOTSUPP; 13651 goto out; 13652 } 13653 13654 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); 13655 13656 out: 13657 wdev_unlock(wdev); 13658 return err; 13659 } 13660 13661 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) 13662 { 13663 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13664 struct net_device *dev = info->user_ptr[1]; 13665 struct wireless_dev *wdev = dev->ieee80211_ptr; 13666 const u8 *peer; 13667 u8 tsid; 13668 int err; 13669 13670 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) 13671 return -EINVAL; 13672 13673 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 13674 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 13675 13676 wdev_lock(wdev); 13677 err = rdev_del_tx_ts(rdev, dev, tsid, peer); 13678 wdev_unlock(wdev); 13679 13680 return err; 13681 } 13682 13683 static int nl80211_tdls_channel_switch(struct sk_buff *skb, 13684 struct genl_info *info) 13685 { 13686 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13687 struct net_device *dev = info->user_ptr[1]; 13688 struct wireless_dev *wdev = dev->ieee80211_ptr; 13689 struct cfg80211_chan_def chandef = {}; 13690 const u8 *addr; 13691 u8 oper_class; 13692 int err; 13693 13694 if (!rdev->ops->tdls_channel_switch || 13695 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 13696 return -EOPNOTSUPP; 13697 13698 switch (dev->ieee80211_ptr->iftype) { 13699 case NL80211_IFTYPE_STATION: 13700 case NL80211_IFTYPE_P2P_CLIENT: 13701 break; 13702 default: 13703 return -EOPNOTSUPP; 13704 } 13705 13706 if (!info->attrs[NL80211_ATTR_MAC] || 13707 !info->attrs[NL80211_ATTR_OPER_CLASS]) 13708 return -EINVAL; 13709 13710 err = nl80211_parse_chandef(rdev, info, &chandef); 13711 if (err) 13712 return err; 13713 13714 /* 13715 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 13716 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the 13717 * specification is not defined for them. 13718 */ 13719 if (chandef.chan->band == NL80211_BAND_2GHZ && 13720 chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 13721 chandef.width != NL80211_CHAN_WIDTH_20) 13722 return -EINVAL; 13723 13724 /* we will be active on the TDLS link */ 13725 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 13726 wdev->iftype)) 13727 return -EINVAL; 13728 13729 /* don't allow switching to DFS channels */ 13730 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) 13731 return -EINVAL; 13732 13733 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 13734 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); 13735 13736 wdev_lock(wdev); 13737 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); 13738 wdev_unlock(wdev); 13739 13740 return err; 13741 } 13742 13743 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, 13744 struct genl_info *info) 13745 { 13746 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13747 struct net_device *dev = info->user_ptr[1]; 13748 struct wireless_dev *wdev = dev->ieee80211_ptr; 13749 const u8 *addr; 13750 13751 if (!rdev->ops->tdls_channel_switch || 13752 !rdev->ops->tdls_cancel_channel_switch || 13753 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 13754 return -EOPNOTSUPP; 13755 13756 switch (dev->ieee80211_ptr->iftype) { 13757 case NL80211_IFTYPE_STATION: 13758 case NL80211_IFTYPE_P2P_CLIENT: 13759 break; 13760 default: 13761 return -EOPNOTSUPP; 13762 } 13763 13764 if (!info->attrs[NL80211_ATTR_MAC]) 13765 return -EINVAL; 13766 13767 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 13768 13769 wdev_lock(wdev); 13770 rdev_tdls_cancel_channel_switch(rdev, dev, addr); 13771 wdev_unlock(wdev); 13772 13773 return 0; 13774 } 13775 13776 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, 13777 struct genl_info *info) 13778 { 13779 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13780 struct net_device *dev = info->user_ptr[1]; 13781 struct wireless_dev *wdev = dev->ieee80211_ptr; 13782 const struct nlattr *nla; 13783 bool enabled; 13784 13785 if (!rdev->ops->set_multicast_to_unicast) 13786 return -EOPNOTSUPP; 13787 13788 if (wdev->iftype != NL80211_IFTYPE_AP && 13789 wdev->iftype != NL80211_IFTYPE_P2P_GO) 13790 return -EOPNOTSUPP; 13791 13792 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; 13793 enabled = nla_get_flag(nla); 13794 13795 return rdev_set_multicast_to_unicast(rdev, dev, enabled); 13796 } 13797 13798 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) 13799 { 13800 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13801 struct net_device *dev = info->user_ptr[1]; 13802 struct wireless_dev *wdev = dev->ieee80211_ptr; 13803 struct cfg80211_pmk_conf pmk_conf = {}; 13804 int ret; 13805 13806 if (wdev->iftype != NL80211_IFTYPE_STATION && 13807 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 13808 return -EOPNOTSUPP; 13809 13810 if (!wiphy_ext_feature_isset(&rdev->wiphy, 13811 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 13812 return -EOPNOTSUPP; 13813 13814 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) 13815 return -EINVAL; 13816 13817 wdev_lock(wdev); 13818 if (!wdev->current_bss) { 13819 ret = -ENOTCONN; 13820 goto out; 13821 } 13822 13823 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 13824 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { 13825 ret = -EINVAL; 13826 goto out; 13827 } 13828 13829 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 13830 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 13831 if (pmk_conf.pmk_len != WLAN_PMK_LEN && 13832 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { 13833 ret = -EINVAL; 13834 goto out; 13835 } 13836 13837 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { 13838 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); 13839 13840 if (r0_name_len != WLAN_PMK_NAME_LEN) { 13841 ret = -EINVAL; 13842 goto out; 13843 } 13844 13845 pmk_conf.pmk_r0_name = 13846 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); 13847 } 13848 13849 ret = rdev_set_pmk(rdev, dev, &pmk_conf); 13850 out: 13851 wdev_unlock(wdev); 13852 return ret; 13853 } 13854 13855 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) 13856 { 13857 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13858 struct net_device *dev = info->user_ptr[1]; 13859 struct wireless_dev *wdev = dev->ieee80211_ptr; 13860 const u8 *aa; 13861 int ret; 13862 13863 if (wdev->iftype != NL80211_IFTYPE_STATION && 13864 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 13865 return -EOPNOTSUPP; 13866 13867 if (!wiphy_ext_feature_isset(&rdev->wiphy, 13868 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 13869 return -EOPNOTSUPP; 13870 13871 if (!info->attrs[NL80211_ATTR_MAC]) 13872 return -EINVAL; 13873 13874 wdev_lock(wdev); 13875 aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 13876 ret = rdev_del_pmk(rdev, dev, aa); 13877 wdev_unlock(wdev); 13878 13879 return ret; 13880 } 13881 13882 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) 13883 { 13884 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13885 struct net_device *dev = info->user_ptr[1]; 13886 struct cfg80211_external_auth_params params; 13887 13888 if (!rdev->ops->external_auth) 13889 return -EOPNOTSUPP; 13890 13891 if (!info->attrs[NL80211_ATTR_SSID] && 13892 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 13893 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 13894 return -EINVAL; 13895 13896 if (!info->attrs[NL80211_ATTR_BSSID]) 13897 return -EINVAL; 13898 13899 if (!info->attrs[NL80211_ATTR_STATUS_CODE]) 13900 return -EINVAL; 13901 13902 memset(¶ms, 0, sizeof(params)); 13903 13904 if (info->attrs[NL80211_ATTR_SSID]) { 13905 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 13906 if (params.ssid.ssid_len == 0 || 13907 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) 13908 return -EINVAL; 13909 memcpy(params.ssid.ssid, 13910 nla_data(info->attrs[NL80211_ATTR_SSID]), 13911 params.ssid.ssid_len); 13912 } 13913 13914 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), 13915 ETH_ALEN); 13916 13917 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 13918 13919 if (info->attrs[NL80211_ATTR_PMKID]) 13920 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 13921 13922 return rdev_external_auth(rdev, dev, ¶ms); 13923 } 13924 13925 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) 13926 { 13927 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; 13928 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13929 struct net_device *dev = info->user_ptr[1]; 13930 struct wireless_dev *wdev = dev->ieee80211_ptr; 13931 const u8 *buf; 13932 size_t len; 13933 u8 *dest; 13934 u16 proto; 13935 bool noencrypt; 13936 u64 cookie = 0; 13937 int err; 13938 13939 if (!wiphy_ext_feature_isset(&rdev->wiphy, 13940 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 13941 return -EOPNOTSUPP; 13942 13943 if (!rdev->ops->tx_control_port) 13944 return -EOPNOTSUPP; 13945 13946 if (!info->attrs[NL80211_ATTR_FRAME] || 13947 !info->attrs[NL80211_ATTR_MAC] || 13948 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 13949 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); 13950 return -EINVAL; 13951 } 13952 13953 wdev_lock(wdev); 13954 13955 switch (wdev->iftype) { 13956 case NL80211_IFTYPE_AP: 13957 case NL80211_IFTYPE_P2P_GO: 13958 case NL80211_IFTYPE_MESH_POINT: 13959 break; 13960 case NL80211_IFTYPE_ADHOC: 13961 case NL80211_IFTYPE_STATION: 13962 case NL80211_IFTYPE_P2P_CLIENT: 13963 if (wdev->current_bss) 13964 break; 13965 err = -ENOTCONN; 13966 goto out; 13967 default: 13968 err = -EOPNOTSUPP; 13969 goto out; 13970 } 13971 13972 wdev_unlock(wdev); 13973 13974 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 13975 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 13976 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 13977 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 13978 noencrypt = 13979 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); 13980 13981 err = rdev_tx_control_port(rdev, dev, buf, len, 13982 dest, cpu_to_be16(proto), noencrypt, 13983 dont_wait_for_ack ? NULL : &cookie); 13984 if (!err && !dont_wait_for_ack) 13985 nl_set_extack_cookie_u64(info->extack, cookie); 13986 return err; 13987 out: 13988 wdev_unlock(wdev); 13989 return err; 13990 } 13991 13992 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, 13993 struct genl_info *info) 13994 { 13995 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13996 struct net_device *dev = info->user_ptr[1]; 13997 struct wireless_dev *wdev = dev->ieee80211_ptr; 13998 struct cfg80211_ftm_responder_stats ftm_stats = {}; 13999 struct sk_buff *msg; 14000 void *hdr; 14001 struct nlattr *ftm_stats_attr; 14002 int err; 14003 14004 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) 14005 return -EOPNOTSUPP; 14006 14007 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); 14008 if (err) 14009 return err; 14010 14011 if (!ftm_stats.filled) 14012 return -ENODATA; 14013 14014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14015 if (!msg) 14016 return -ENOMEM; 14017 14018 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14019 NL80211_CMD_GET_FTM_RESPONDER_STATS); 14020 if (!hdr) 14021 goto nla_put_failure; 14022 14023 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 14024 goto nla_put_failure; 14025 14026 ftm_stats_attr = nla_nest_start_noflag(msg, 14027 NL80211_ATTR_FTM_RESPONDER_STATS); 14028 if (!ftm_stats_attr) 14029 goto nla_put_failure; 14030 14031 #define SET_FTM(field, name, type) \ 14032 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 14033 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ 14034 ftm_stats.field)) \ 14035 goto nla_put_failure; } while (0) 14036 #define SET_FTM_U64(field, name) \ 14037 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 14038 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ 14039 ftm_stats.field, NL80211_FTM_STATS_PAD)) \ 14040 goto nla_put_failure; } while (0) 14041 14042 SET_FTM(success_num, SUCCESS_NUM, u32); 14043 SET_FTM(partial_num, PARTIAL_NUM, u32); 14044 SET_FTM(failed_num, FAILED_NUM, u32); 14045 SET_FTM(asap_num, ASAP_NUM, u32); 14046 SET_FTM(non_asap_num, NON_ASAP_NUM, u32); 14047 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); 14048 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); 14049 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); 14050 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); 14051 #undef SET_FTM 14052 14053 nla_nest_end(msg, ftm_stats_attr); 14054 14055 genlmsg_end(msg, hdr); 14056 return genlmsg_reply(msg, info); 14057 14058 nla_put_failure: 14059 nlmsg_free(msg); 14060 return -ENOBUFS; 14061 } 14062 14063 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) 14064 { 14065 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14066 struct cfg80211_update_owe_info owe_info; 14067 struct net_device *dev = info->user_ptr[1]; 14068 14069 if (!rdev->ops->update_owe_info) 14070 return -EOPNOTSUPP; 14071 14072 if (!info->attrs[NL80211_ATTR_STATUS_CODE] || 14073 !info->attrs[NL80211_ATTR_MAC]) 14074 return -EINVAL; 14075 14076 memset(&owe_info, 0, sizeof(owe_info)); 14077 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 14078 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); 14079 14080 if (info->attrs[NL80211_ATTR_IE]) { 14081 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 14082 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 14083 } 14084 14085 return rdev_update_owe_info(rdev, dev, &owe_info); 14086 } 14087 14088 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) 14089 { 14090 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14091 struct net_device *dev = info->user_ptr[1]; 14092 struct wireless_dev *wdev = dev->ieee80211_ptr; 14093 struct station_info sinfo = {}; 14094 const u8 *buf; 14095 size_t len; 14096 u8 *dest; 14097 int err; 14098 14099 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) 14100 return -EOPNOTSUPP; 14101 14102 if (!info->attrs[NL80211_ATTR_MAC] || 14103 !info->attrs[NL80211_ATTR_FRAME]) { 14104 GENL_SET_ERR_MSG(info, "Frame or MAC missing"); 14105 return -EINVAL; 14106 } 14107 14108 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 14109 return -EOPNOTSUPP; 14110 14111 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 14112 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 14113 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 14114 14115 if (len < sizeof(struct ethhdr)) 14116 return -EINVAL; 14117 14118 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || 14119 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) 14120 return -EINVAL; 14121 14122 err = rdev_get_station(rdev, dev, dest, &sinfo); 14123 if (err) 14124 return err; 14125 14126 cfg80211_sinfo_release_content(&sinfo); 14127 14128 return rdev_probe_mesh_link(rdev, dev, dest, buf, len); 14129 } 14130 14131 static int parse_tid_conf(struct cfg80211_registered_device *rdev, 14132 struct nlattr *attrs[], struct net_device *dev, 14133 struct cfg80211_tid_cfg *tid_conf, 14134 struct genl_info *info, const u8 *peer) 14135 { 14136 struct netlink_ext_ack *extack = info->extack; 14137 u64 mask; 14138 int err; 14139 14140 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) 14141 return -EINVAL; 14142 14143 tid_conf->config_override = 14144 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); 14145 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); 14146 14147 if (tid_conf->config_override) { 14148 if (rdev->ops->reset_tid_config) { 14149 err = rdev_reset_tid_config(rdev, dev, peer, 14150 tid_conf->tids); 14151 if (err) 14152 return err; 14153 } else { 14154 return -EINVAL; 14155 } 14156 } 14157 14158 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { 14159 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); 14160 tid_conf->noack = 14161 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); 14162 } 14163 14164 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { 14165 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); 14166 tid_conf->retry_short = 14167 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); 14168 14169 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) 14170 return -EINVAL; 14171 } 14172 14173 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { 14174 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); 14175 tid_conf->retry_long = 14176 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); 14177 14178 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) 14179 return -EINVAL; 14180 } 14181 14182 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { 14183 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); 14184 tid_conf->ampdu = 14185 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); 14186 } 14187 14188 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { 14189 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); 14190 tid_conf->rtscts = 14191 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); 14192 } 14193 14194 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { 14195 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); 14196 tid_conf->amsdu = 14197 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); 14198 } 14199 14200 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { 14201 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; 14202 14203 tid_conf->txrate_type = nla_get_u8(attrs[idx]); 14204 14205 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { 14206 attr = NL80211_TID_CONFIG_ATTR_TX_RATE; 14207 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, 14208 &tid_conf->txrate_mask); 14209 if (err) 14210 return err; 14211 14212 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); 14213 } 14214 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); 14215 } 14216 14217 if (peer) 14218 mask = rdev->wiphy.tid_config_support.peer; 14219 else 14220 mask = rdev->wiphy.tid_config_support.vif; 14221 14222 if (tid_conf->mask & ~mask) { 14223 NL_SET_ERR_MSG(extack, "unsupported TID configuration"); 14224 return -ENOTSUPP; 14225 } 14226 14227 return 0; 14228 } 14229 14230 static int nl80211_set_tid_config(struct sk_buff *skb, 14231 struct genl_info *info) 14232 { 14233 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14234 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; 14235 struct net_device *dev = info->user_ptr[1]; 14236 struct cfg80211_tid_config *tid_config; 14237 struct nlattr *tid; 14238 int conf_idx = 0, rem_conf; 14239 int ret = -EINVAL; 14240 u32 num_conf = 0; 14241 14242 if (!info->attrs[NL80211_ATTR_TID_CONFIG]) 14243 return -EINVAL; 14244 14245 if (!rdev->ops->set_tid_config) 14246 return -EOPNOTSUPP; 14247 14248 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 14249 rem_conf) 14250 num_conf++; 14251 14252 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), 14253 GFP_KERNEL); 14254 if (!tid_config) 14255 return -ENOMEM; 14256 14257 tid_config->n_tid_conf = num_conf; 14258 14259 if (info->attrs[NL80211_ATTR_MAC]) 14260 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 14261 14262 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 14263 rem_conf) { 14264 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, 14265 tid, NULL, NULL); 14266 14267 if (ret) 14268 goto bad_tid_conf; 14269 14270 ret = parse_tid_conf(rdev, attrs, dev, 14271 &tid_config->tid_conf[conf_idx], 14272 info, tid_config->peer); 14273 if (ret) 14274 goto bad_tid_conf; 14275 14276 conf_idx++; 14277 } 14278 14279 ret = rdev_set_tid_config(rdev, dev, tid_config); 14280 14281 bad_tid_conf: 14282 kfree(tid_config); 14283 return ret; 14284 } 14285 14286 #define NL80211_FLAG_NEED_WIPHY 0x01 14287 #define NL80211_FLAG_NEED_NETDEV 0x02 14288 #define NL80211_FLAG_NEED_RTNL 0x04 14289 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 14290 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ 14291 NL80211_FLAG_CHECK_NETDEV_UP) 14292 #define NL80211_FLAG_NEED_WDEV 0x10 14293 /* If a netdev is associated, it must be UP, P2P must be started */ 14294 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ 14295 NL80211_FLAG_CHECK_NETDEV_UP) 14296 #define NL80211_FLAG_CLEAR_SKB 0x20 14297 14298 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, 14299 struct genl_info *info) 14300 { 14301 struct cfg80211_registered_device *rdev; 14302 struct wireless_dev *wdev; 14303 struct net_device *dev; 14304 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; 14305 14306 if (rtnl) 14307 rtnl_lock(); 14308 14309 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { 14310 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 14311 if (IS_ERR(rdev)) { 14312 if (rtnl) 14313 rtnl_unlock(); 14314 return PTR_ERR(rdev); 14315 } 14316 info->user_ptr[0] = rdev; 14317 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || 14318 ops->internal_flags & NL80211_FLAG_NEED_WDEV) { 14319 ASSERT_RTNL(); 14320 14321 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), 14322 info->attrs); 14323 if (IS_ERR(wdev)) { 14324 if (rtnl) 14325 rtnl_unlock(); 14326 return PTR_ERR(wdev); 14327 } 14328 14329 dev = wdev->netdev; 14330 rdev = wiphy_to_rdev(wdev->wiphy); 14331 14332 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { 14333 if (!dev) { 14334 if (rtnl) 14335 rtnl_unlock(); 14336 return -EINVAL; 14337 } 14338 14339 info->user_ptr[1] = dev; 14340 } else { 14341 info->user_ptr[1] = wdev; 14342 } 14343 14344 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && 14345 !wdev_running(wdev)) { 14346 if (rtnl) 14347 rtnl_unlock(); 14348 return -ENETDOWN; 14349 } 14350 14351 if (dev) 14352 dev_hold(dev); 14353 14354 info->user_ptr[0] = rdev; 14355 } 14356 14357 return 0; 14358 } 14359 14360 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, 14361 struct genl_info *info) 14362 { 14363 if (info->user_ptr[1]) { 14364 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { 14365 struct wireless_dev *wdev = info->user_ptr[1]; 14366 14367 if (wdev->netdev) 14368 dev_put(wdev->netdev); 14369 } else { 14370 dev_put(info->user_ptr[1]); 14371 } 14372 } 14373 14374 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) 14375 rtnl_unlock(); 14376 14377 /* If needed, clear the netlink message payload from the SKB 14378 * as it might contain key data that shouldn't stick around on 14379 * the heap after the SKB is freed. The netlink message header 14380 * is still needed for further processing, so leave it intact. 14381 */ 14382 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { 14383 struct nlmsghdr *nlh = nlmsg_hdr(skb); 14384 14385 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); 14386 } 14387 } 14388 14389 static const struct genl_ops nl80211_ops[] = { 14390 { 14391 .cmd = NL80211_CMD_GET_WIPHY, 14392 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14393 .doit = nl80211_get_wiphy, 14394 .dumpit = nl80211_dump_wiphy, 14395 .done = nl80211_dump_wiphy_done, 14396 /* can be retrieved by unprivileged users */ 14397 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14398 NL80211_FLAG_NEED_RTNL, 14399 }, 14400 { 14401 .cmd = NL80211_CMD_SET_WIPHY, 14402 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14403 .doit = nl80211_set_wiphy, 14404 .flags = GENL_UNS_ADMIN_PERM, 14405 .internal_flags = NL80211_FLAG_NEED_RTNL, 14406 }, 14407 { 14408 .cmd = NL80211_CMD_GET_INTERFACE, 14409 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14410 .doit = nl80211_get_interface, 14411 .dumpit = nl80211_dump_interface, 14412 /* can be retrieved by unprivileged users */ 14413 .internal_flags = NL80211_FLAG_NEED_WDEV | 14414 NL80211_FLAG_NEED_RTNL, 14415 }, 14416 { 14417 .cmd = NL80211_CMD_SET_INTERFACE, 14418 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14419 .doit = nl80211_set_interface, 14420 .flags = GENL_UNS_ADMIN_PERM, 14421 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14422 NL80211_FLAG_NEED_RTNL, 14423 }, 14424 { 14425 .cmd = NL80211_CMD_NEW_INTERFACE, 14426 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14427 .doit = nl80211_new_interface, 14428 .flags = GENL_UNS_ADMIN_PERM, 14429 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14430 NL80211_FLAG_NEED_RTNL, 14431 }, 14432 { 14433 .cmd = NL80211_CMD_DEL_INTERFACE, 14434 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14435 .doit = nl80211_del_interface, 14436 .flags = GENL_UNS_ADMIN_PERM, 14437 .internal_flags = NL80211_FLAG_NEED_WDEV | 14438 NL80211_FLAG_NEED_RTNL, 14439 }, 14440 { 14441 .cmd = NL80211_CMD_GET_KEY, 14442 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14443 .doit = nl80211_get_key, 14444 .flags = GENL_UNS_ADMIN_PERM, 14445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14446 NL80211_FLAG_NEED_RTNL, 14447 }, 14448 { 14449 .cmd = NL80211_CMD_SET_KEY, 14450 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14451 .doit = nl80211_set_key, 14452 .flags = GENL_UNS_ADMIN_PERM, 14453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14454 NL80211_FLAG_NEED_RTNL | 14455 NL80211_FLAG_CLEAR_SKB, 14456 }, 14457 { 14458 .cmd = NL80211_CMD_NEW_KEY, 14459 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14460 .doit = nl80211_new_key, 14461 .flags = GENL_UNS_ADMIN_PERM, 14462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14463 NL80211_FLAG_NEED_RTNL | 14464 NL80211_FLAG_CLEAR_SKB, 14465 }, 14466 { 14467 .cmd = NL80211_CMD_DEL_KEY, 14468 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14469 .doit = nl80211_del_key, 14470 .flags = GENL_UNS_ADMIN_PERM, 14471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14472 NL80211_FLAG_NEED_RTNL, 14473 }, 14474 { 14475 .cmd = NL80211_CMD_SET_BEACON, 14476 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14477 .flags = GENL_UNS_ADMIN_PERM, 14478 .doit = nl80211_set_beacon, 14479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14480 NL80211_FLAG_NEED_RTNL, 14481 }, 14482 { 14483 .cmd = NL80211_CMD_START_AP, 14484 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14485 .flags = GENL_UNS_ADMIN_PERM, 14486 .doit = nl80211_start_ap, 14487 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14488 NL80211_FLAG_NEED_RTNL, 14489 }, 14490 { 14491 .cmd = NL80211_CMD_STOP_AP, 14492 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14493 .flags = GENL_UNS_ADMIN_PERM, 14494 .doit = nl80211_stop_ap, 14495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14496 NL80211_FLAG_NEED_RTNL, 14497 }, 14498 { 14499 .cmd = NL80211_CMD_GET_STATION, 14500 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14501 .doit = nl80211_get_station, 14502 .dumpit = nl80211_dump_station, 14503 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14504 NL80211_FLAG_NEED_RTNL, 14505 }, 14506 { 14507 .cmd = NL80211_CMD_SET_STATION, 14508 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14509 .doit = nl80211_set_station, 14510 .flags = GENL_UNS_ADMIN_PERM, 14511 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14512 NL80211_FLAG_NEED_RTNL, 14513 }, 14514 { 14515 .cmd = NL80211_CMD_NEW_STATION, 14516 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14517 .doit = nl80211_new_station, 14518 .flags = GENL_UNS_ADMIN_PERM, 14519 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14520 NL80211_FLAG_NEED_RTNL, 14521 }, 14522 { 14523 .cmd = NL80211_CMD_DEL_STATION, 14524 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14525 .doit = nl80211_del_station, 14526 .flags = GENL_UNS_ADMIN_PERM, 14527 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14528 NL80211_FLAG_NEED_RTNL, 14529 }, 14530 { 14531 .cmd = NL80211_CMD_GET_MPATH, 14532 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14533 .doit = nl80211_get_mpath, 14534 .dumpit = nl80211_dump_mpath, 14535 .flags = GENL_UNS_ADMIN_PERM, 14536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14537 NL80211_FLAG_NEED_RTNL, 14538 }, 14539 { 14540 .cmd = NL80211_CMD_GET_MPP, 14541 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14542 .doit = nl80211_get_mpp, 14543 .dumpit = nl80211_dump_mpp, 14544 .flags = GENL_UNS_ADMIN_PERM, 14545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14546 NL80211_FLAG_NEED_RTNL, 14547 }, 14548 { 14549 .cmd = NL80211_CMD_SET_MPATH, 14550 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14551 .doit = nl80211_set_mpath, 14552 .flags = GENL_UNS_ADMIN_PERM, 14553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14554 NL80211_FLAG_NEED_RTNL, 14555 }, 14556 { 14557 .cmd = NL80211_CMD_NEW_MPATH, 14558 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14559 .doit = nl80211_new_mpath, 14560 .flags = GENL_UNS_ADMIN_PERM, 14561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14562 NL80211_FLAG_NEED_RTNL, 14563 }, 14564 { 14565 .cmd = NL80211_CMD_DEL_MPATH, 14566 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14567 .doit = nl80211_del_mpath, 14568 .flags = GENL_UNS_ADMIN_PERM, 14569 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14570 NL80211_FLAG_NEED_RTNL, 14571 }, 14572 { 14573 .cmd = NL80211_CMD_SET_BSS, 14574 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14575 .doit = nl80211_set_bss, 14576 .flags = GENL_UNS_ADMIN_PERM, 14577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14578 NL80211_FLAG_NEED_RTNL, 14579 }, 14580 { 14581 .cmd = NL80211_CMD_GET_REG, 14582 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14583 .doit = nl80211_get_reg_do, 14584 .dumpit = nl80211_get_reg_dump, 14585 .internal_flags = NL80211_FLAG_NEED_RTNL, 14586 /* can be retrieved by unprivileged users */ 14587 }, 14588 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 14589 { 14590 .cmd = NL80211_CMD_SET_REG, 14591 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14592 .doit = nl80211_set_reg, 14593 .flags = GENL_ADMIN_PERM, 14594 .internal_flags = NL80211_FLAG_NEED_RTNL, 14595 }, 14596 #endif 14597 { 14598 .cmd = NL80211_CMD_REQ_SET_REG, 14599 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14600 .doit = nl80211_req_set_reg, 14601 .flags = GENL_ADMIN_PERM, 14602 }, 14603 { 14604 .cmd = NL80211_CMD_RELOAD_REGDB, 14605 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14606 .doit = nl80211_reload_regdb, 14607 .flags = GENL_ADMIN_PERM, 14608 }, 14609 { 14610 .cmd = NL80211_CMD_GET_MESH_CONFIG, 14611 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14612 .doit = nl80211_get_mesh_config, 14613 /* can be retrieved by unprivileged users */ 14614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14615 NL80211_FLAG_NEED_RTNL, 14616 }, 14617 { 14618 .cmd = NL80211_CMD_SET_MESH_CONFIG, 14619 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14620 .doit = nl80211_update_mesh_config, 14621 .flags = GENL_UNS_ADMIN_PERM, 14622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14623 NL80211_FLAG_NEED_RTNL, 14624 }, 14625 { 14626 .cmd = NL80211_CMD_TRIGGER_SCAN, 14627 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14628 .doit = nl80211_trigger_scan, 14629 .flags = GENL_UNS_ADMIN_PERM, 14630 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14631 NL80211_FLAG_NEED_RTNL, 14632 }, 14633 { 14634 .cmd = NL80211_CMD_ABORT_SCAN, 14635 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14636 .doit = nl80211_abort_scan, 14637 .flags = GENL_UNS_ADMIN_PERM, 14638 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14639 NL80211_FLAG_NEED_RTNL, 14640 }, 14641 { 14642 .cmd = NL80211_CMD_GET_SCAN, 14643 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14644 .dumpit = nl80211_dump_scan, 14645 }, 14646 { 14647 .cmd = NL80211_CMD_START_SCHED_SCAN, 14648 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14649 .doit = nl80211_start_sched_scan, 14650 .flags = GENL_UNS_ADMIN_PERM, 14651 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14652 NL80211_FLAG_NEED_RTNL, 14653 }, 14654 { 14655 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 14656 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14657 .doit = nl80211_stop_sched_scan, 14658 .flags = GENL_UNS_ADMIN_PERM, 14659 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14660 NL80211_FLAG_NEED_RTNL, 14661 }, 14662 { 14663 .cmd = NL80211_CMD_AUTHENTICATE, 14664 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14665 .doit = nl80211_authenticate, 14666 .flags = GENL_UNS_ADMIN_PERM, 14667 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14668 NL80211_FLAG_NEED_RTNL | 14669 NL80211_FLAG_CLEAR_SKB, 14670 }, 14671 { 14672 .cmd = NL80211_CMD_ASSOCIATE, 14673 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14674 .doit = nl80211_associate, 14675 .flags = GENL_UNS_ADMIN_PERM, 14676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14677 NL80211_FLAG_NEED_RTNL | 14678 NL80211_FLAG_CLEAR_SKB, 14679 }, 14680 { 14681 .cmd = NL80211_CMD_DEAUTHENTICATE, 14682 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14683 .doit = nl80211_deauthenticate, 14684 .flags = GENL_UNS_ADMIN_PERM, 14685 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14686 NL80211_FLAG_NEED_RTNL, 14687 }, 14688 { 14689 .cmd = NL80211_CMD_DISASSOCIATE, 14690 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14691 .doit = nl80211_disassociate, 14692 .flags = GENL_UNS_ADMIN_PERM, 14693 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14694 NL80211_FLAG_NEED_RTNL, 14695 }, 14696 { 14697 .cmd = NL80211_CMD_JOIN_IBSS, 14698 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14699 .doit = nl80211_join_ibss, 14700 .flags = GENL_UNS_ADMIN_PERM, 14701 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14702 NL80211_FLAG_NEED_RTNL, 14703 }, 14704 { 14705 .cmd = NL80211_CMD_LEAVE_IBSS, 14706 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14707 .doit = nl80211_leave_ibss, 14708 .flags = GENL_UNS_ADMIN_PERM, 14709 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14710 NL80211_FLAG_NEED_RTNL, 14711 }, 14712 #ifdef CONFIG_NL80211_TESTMODE 14713 { 14714 .cmd = NL80211_CMD_TESTMODE, 14715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14716 .doit = nl80211_testmode_do, 14717 .dumpit = nl80211_testmode_dump, 14718 .flags = GENL_UNS_ADMIN_PERM, 14719 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14720 NL80211_FLAG_NEED_RTNL, 14721 }, 14722 #endif 14723 { 14724 .cmd = NL80211_CMD_CONNECT, 14725 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14726 .doit = nl80211_connect, 14727 .flags = GENL_UNS_ADMIN_PERM, 14728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14729 NL80211_FLAG_NEED_RTNL | 14730 NL80211_FLAG_CLEAR_SKB, 14731 }, 14732 { 14733 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 14734 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14735 .doit = nl80211_update_connect_params, 14736 .flags = GENL_ADMIN_PERM, 14737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14738 NL80211_FLAG_NEED_RTNL | 14739 NL80211_FLAG_CLEAR_SKB, 14740 }, 14741 { 14742 .cmd = NL80211_CMD_DISCONNECT, 14743 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14744 .doit = nl80211_disconnect, 14745 .flags = GENL_UNS_ADMIN_PERM, 14746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14747 NL80211_FLAG_NEED_RTNL, 14748 }, 14749 { 14750 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 14751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14752 .doit = nl80211_wiphy_netns, 14753 .flags = GENL_UNS_ADMIN_PERM, 14754 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14755 NL80211_FLAG_NEED_RTNL, 14756 }, 14757 { 14758 .cmd = NL80211_CMD_GET_SURVEY, 14759 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14760 .dumpit = nl80211_dump_survey, 14761 }, 14762 { 14763 .cmd = NL80211_CMD_SET_PMKSA, 14764 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14765 .doit = nl80211_setdel_pmksa, 14766 .flags = GENL_UNS_ADMIN_PERM, 14767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14768 NL80211_FLAG_NEED_RTNL | 14769 NL80211_FLAG_CLEAR_SKB, 14770 }, 14771 { 14772 .cmd = NL80211_CMD_DEL_PMKSA, 14773 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14774 .doit = nl80211_setdel_pmksa, 14775 .flags = GENL_UNS_ADMIN_PERM, 14776 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14777 NL80211_FLAG_NEED_RTNL, 14778 }, 14779 { 14780 .cmd = NL80211_CMD_FLUSH_PMKSA, 14781 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14782 .doit = nl80211_flush_pmksa, 14783 .flags = GENL_UNS_ADMIN_PERM, 14784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14785 NL80211_FLAG_NEED_RTNL, 14786 }, 14787 { 14788 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 14789 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14790 .doit = nl80211_remain_on_channel, 14791 .flags = GENL_UNS_ADMIN_PERM, 14792 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14793 NL80211_FLAG_NEED_RTNL, 14794 }, 14795 { 14796 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 14797 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14798 .doit = nl80211_cancel_remain_on_channel, 14799 .flags = GENL_UNS_ADMIN_PERM, 14800 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14801 NL80211_FLAG_NEED_RTNL, 14802 }, 14803 { 14804 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 14805 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14806 .doit = nl80211_set_tx_bitrate_mask, 14807 .flags = GENL_UNS_ADMIN_PERM, 14808 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14809 NL80211_FLAG_NEED_RTNL, 14810 }, 14811 { 14812 .cmd = NL80211_CMD_REGISTER_FRAME, 14813 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14814 .doit = nl80211_register_mgmt, 14815 .flags = GENL_UNS_ADMIN_PERM, 14816 .internal_flags = NL80211_FLAG_NEED_WDEV | 14817 NL80211_FLAG_NEED_RTNL, 14818 }, 14819 { 14820 .cmd = NL80211_CMD_FRAME, 14821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14822 .doit = nl80211_tx_mgmt, 14823 .flags = GENL_UNS_ADMIN_PERM, 14824 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14825 NL80211_FLAG_NEED_RTNL, 14826 }, 14827 { 14828 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 14829 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14830 .doit = nl80211_tx_mgmt_cancel_wait, 14831 .flags = GENL_UNS_ADMIN_PERM, 14832 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14833 NL80211_FLAG_NEED_RTNL, 14834 }, 14835 { 14836 .cmd = NL80211_CMD_SET_POWER_SAVE, 14837 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14838 .doit = nl80211_set_power_save, 14839 .flags = GENL_UNS_ADMIN_PERM, 14840 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14841 NL80211_FLAG_NEED_RTNL, 14842 }, 14843 { 14844 .cmd = NL80211_CMD_GET_POWER_SAVE, 14845 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14846 .doit = nl80211_get_power_save, 14847 /* can be retrieved by unprivileged users */ 14848 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14849 NL80211_FLAG_NEED_RTNL, 14850 }, 14851 { 14852 .cmd = NL80211_CMD_SET_CQM, 14853 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14854 .doit = nl80211_set_cqm, 14855 .flags = GENL_UNS_ADMIN_PERM, 14856 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14857 NL80211_FLAG_NEED_RTNL, 14858 }, 14859 { 14860 .cmd = NL80211_CMD_SET_CHANNEL, 14861 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14862 .doit = nl80211_set_channel, 14863 .flags = GENL_UNS_ADMIN_PERM, 14864 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14865 NL80211_FLAG_NEED_RTNL, 14866 }, 14867 { 14868 .cmd = NL80211_CMD_SET_WDS_PEER, 14869 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14870 .doit = nl80211_set_wds_peer, 14871 .flags = GENL_UNS_ADMIN_PERM, 14872 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14873 NL80211_FLAG_NEED_RTNL, 14874 }, 14875 { 14876 .cmd = NL80211_CMD_JOIN_MESH, 14877 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14878 .doit = nl80211_join_mesh, 14879 .flags = GENL_UNS_ADMIN_PERM, 14880 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14881 NL80211_FLAG_NEED_RTNL, 14882 }, 14883 { 14884 .cmd = NL80211_CMD_LEAVE_MESH, 14885 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14886 .doit = nl80211_leave_mesh, 14887 .flags = GENL_UNS_ADMIN_PERM, 14888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14889 NL80211_FLAG_NEED_RTNL, 14890 }, 14891 { 14892 .cmd = NL80211_CMD_JOIN_OCB, 14893 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14894 .doit = nl80211_join_ocb, 14895 .flags = GENL_UNS_ADMIN_PERM, 14896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14897 NL80211_FLAG_NEED_RTNL, 14898 }, 14899 { 14900 .cmd = NL80211_CMD_LEAVE_OCB, 14901 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14902 .doit = nl80211_leave_ocb, 14903 .flags = GENL_UNS_ADMIN_PERM, 14904 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14905 NL80211_FLAG_NEED_RTNL, 14906 }, 14907 #ifdef CONFIG_PM 14908 { 14909 .cmd = NL80211_CMD_GET_WOWLAN, 14910 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14911 .doit = nl80211_get_wowlan, 14912 /* can be retrieved by unprivileged users */ 14913 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14914 NL80211_FLAG_NEED_RTNL, 14915 }, 14916 { 14917 .cmd = NL80211_CMD_SET_WOWLAN, 14918 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14919 .doit = nl80211_set_wowlan, 14920 .flags = GENL_UNS_ADMIN_PERM, 14921 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14922 NL80211_FLAG_NEED_RTNL, 14923 }, 14924 #endif 14925 { 14926 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 14927 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14928 .doit = nl80211_set_rekey_data, 14929 .flags = GENL_UNS_ADMIN_PERM, 14930 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14931 NL80211_FLAG_NEED_RTNL | 14932 NL80211_FLAG_CLEAR_SKB, 14933 }, 14934 { 14935 .cmd = NL80211_CMD_TDLS_MGMT, 14936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14937 .doit = nl80211_tdls_mgmt, 14938 .flags = GENL_UNS_ADMIN_PERM, 14939 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14940 NL80211_FLAG_NEED_RTNL, 14941 }, 14942 { 14943 .cmd = NL80211_CMD_TDLS_OPER, 14944 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14945 .doit = nl80211_tdls_oper, 14946 .flags = GENL_UNS_ADMIN_PERM, 14947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14948 NL80211_FLAG_NEED_RTNL, 14949 }, 14950 { 14951 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 14952 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14953 .doit = nl80211_register_unexpected_frame, 14954 .flags = GENL_UNS_ADMIN_PERM, 14955 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14956 NL80211_FLAG_NEED_RTNL, 14957 }, 14958 { 14959 .cmd = NL80211_CMD_PROBE_CLIENT, 14960 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14961 .doit = nl80211_probe_client, 14962 .flags = GENL_UNS_ADMIN_PERM, 14963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14964 NL80211_FLAG_NEED_RTNL, 14965 }, 14966 { 14967 .cmd = NL80211_CMD_REGISTER_BEACONS, 14968 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14969 .doit = nl80211_register_beacons, 14970 .flags = GENL_UNS_ADMIN_PERM, 14971 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14972 NL80211_FLAG_NEED_RTNL, 14973 }, 14974 { 14975 .cmd = NL80211_CMD_SET_NOACK_MAP, 14976 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14977 .doit = nl80211_set_noack_map, 14978 .flags = GENL_UNS_ADMIN_PERM, 14979 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14980 NL80211_FLAG_NEED_RTNL, 14981 }, 14982 { 14983 .cmd = NL80211_CMD_START_P2P_DEVICE, 14984 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14985 .doit = nl80211_start_p2p_device, 14986 .flags = GENL_UNS_ADMIN_PERM, 14987 .internal_flags = NL80211_FLAG_NEED_WDEV | 14988 NL80211_FLAG_NEED_RTNL, 14989 }, 14990 { 14991 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 14992 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14993 .doit = nl80211_stop_p2p_device, 14994 .flags = GENL_UNS_ADMIN_PERM, 14995 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14996 NL80211_FLAG_NEED_RTNL, 14997 }, 14998 { 14999 .cmd = NL80211_CMD_START_NAN, 15000 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15001 .doit = nl80211_start_nan, 15002 .flags = GENL_ADMIN_PERM, 15003 .internal_flags = NL80211_FLAG_NEED_WDEV | 15004 NL80211_FLAG_NEED_RTNL, 15005 }, 15006 { 15007 .cmd = NL80211_CMD_STOP_NAN, 15008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15009 .doit = nl80211_stop_nan, 15010 .flags = GENL_ADMIN_PERM, 15011 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15012 NL80211_FLAG_NEED_RTNL, 15013 }, 15014 { 15015 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 15016 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15017 .doit = nl80211_nan_add_func, 15018 .flags = GENL_ADMIN_PERM, 15019 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15020 NL80211_FLAG_NEED_RTNL, 15021 }, 15022 { 15023 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 15024 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15025 .doit = nl80211_nan_del_func, 15026 .flags = GENL_ADMIN_PERM, 15027 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15028 NL80211_FLAG_NEED_RTNL, 15029 }, 15030 { 15031 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 15032 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15033 .doit = nl80211_nan_change_config, 15034 .flags = GENL_ADMIN_PERM, 15035 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15036 NL80211_FLAG_NEED_RTNL, 15037 }, 15038 { 15039 .cmd = NL80211_CMD_SET_MCAST_RATE, 15040 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15041 .doit = nl80211_set_mcast_rate, 15042 .flags = GENL_UNS_ADMIN_PERM, 15043 .internal_flags = NL80211_FLAG_NEED_NETDEV | 15044 NL80211_FLAG_NEED_RTNL, 15045 }, 15046 { 15047 .cmd = NL80211_CMD_SET_MAC_ACL, 15048 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15049 .doit = nl80211_set_mac_acl, 15050 .flags = GENL_UNS_ADMIN_PERM, 15051 .internal_flags = NL80211_FLAG_NEED_NETDEV | 15052 NL80211_FLAG_NEED_RTNL, 15053 }, 15054 { 15055 .cmd = NL80211_CMD_RADAR_DETECT, 15056 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15057 .doit = nl80211_start_radar_detection, 15058 .flags = GENL_UNS_ADMIN_PERM, 15059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15060 NL80211_FLAG_NEED_RTNL, 15061 }, 15062 { 15063 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 15064 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15065 .doit = nl80211_get_protocol_features, 15066 }, 15067 { 15068 .cmd = NL80211_CMD_UPDATE_FT_IES, 15069 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15070 .doit = nl80211_update_ft_ies, 15071 .flags = GENL_UNS_ADMIN_PERM, 15072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15073 NL80211_FLAG_NEED_RTNL, 15074 }, 15075 { 15076 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 15077 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15078 .doit = nl80211_crit_protocol_start, 15079 .flags = GENL_UNS_ADMIN_PERM, 15080 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15081 NL80211_FLAG_NEED_RTNL, 15082 }, 15083 { 15084 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 15085 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15086 .doit = nl80211_crit_protocol_stop, 15087 .flags = GENL_UNS_ADMIN_PERM, 15088 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15089 NL80211_FLAG_NEED_RTNL, 15090 }, 15091 { 15092 .cmd = NL80211_CMD_GET_COALESCE, 15093 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15094 .doit = nl80211_get_coalesce, 15095 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15096 NL80211_FLAG_NEED_RTNL, 15097 }, 15098 { 15099 .cmd = NL80211_CMD_SET_COALESCE, 15100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15101 .doit = nl80211_set_coalesce, 15102 .flags = GENL_UNS_ADMIN_PERM, 15103 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15104 NL80211_FLAG_NEED_RTNL, 15105 }, 15106 { 15107 .cmd = NL80211_CMD_CHANNEL_SWITCH, 15108 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15109 .doit = nl80211_channel_switch, 15110 .flags = GENL_UNS_ADMIN_PERM, 15111 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15112 NL80211_FLAG_NEED_RTNL, 15113 }, 15114 { 15115 .cmd = NL80211_CMD_VENDOR, 15116 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15117 .doit = nl80211_vendor_cmd, 15118 .dumpit = nl80211_vendor_cmd_dump, 15119 .flags = GENL_UNS_ADMIN_PERM, 15120 .internal_flags = NL80211_FLAG_NEED_WIPHY | 15121 NL80211_FLAG_NEED_RTNL | 15122 NL80211_FLAG_CLEAR_SKB, 15123 }, 15124 { 15125 .cmd = NL80211_CMD_SET_QOS_MAP, 15126 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15127 .doit = nl80211_set_qos_map, 15128 .flags = GENL_UNS_ADMIN_PERM, 15129 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15130 NL80211_FLAG_NEED_RTNL, 15131 }, 15132 { 15133 .cmd = NL80211_CMD_ADD_TX_TS, 15134 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15135 .doit = nl80211_add_tx_ts, 15136 .flags = GENL_UNS_ADMIN_PERM, 15137 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15138 NL80211_FLAG_NEED_RTNL, 15139 }, 15140 { 15141 .cmd = NL80211_CMD_DEL_TX_TS, 15142 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15143 .doit = nl80211_del_tx_ts, 15144 .flags = GENL_UNS_ADMIN_PERM, 15145 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15146 NL80211_FLAG_NEED_RTNL, 15147 }, 15148 { 15149 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 15150 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15151 .doit = nl80211_tdls_channel_switch, 15152 .flags = GENL_UNS_ADMIN_PERM, 15153 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15154 NL80211_FLAG_NEED_RTNL, 15155 }, 15156 { 15157 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 15158 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15159 .doit = nl80211_tdls_cancel_channel_switch, 15160 .flags = GENL_UNS_ADMIN_PERM, 15161 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15162 NL80211_FLAG_NEED_RTNL, 15163 }, 15164 { 15165 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 15166 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15167 .doit = nl80211_set_multicast_to_unicast, 15168 .flags = GENL_UNS_ADMIN_PERM, 15169 .internal_flags = NL80211_FLAG_NEED_NETDEV | 15170 NL80211_FLAG_NEED_RTNL, 15171 }, 15172 { 15173 .cmd = NL80211_CMD_SET_PMK, 15174 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15175 .doit = nl80211_set_pmk, 15176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15177 NL80211_FLAG_NEED_RTNL | 15178 NL80211_FLAG_CLEAR_SKB, 15179 }, 15180 { 15181 .cmd = NL80211_CMD_DEL_PMK, 15182 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15183 .doit = nl80211_del_pmk, 15184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15185 NL80211_FLAG_NEED_RTNL, 15186 }, 15187 { 15188 .cmd = NL80211_CMD_EXTERNAL_AUTH, 15189 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15190 .doit = nl80211_external_auth, 15191 .flags = GENL_ADMIN_PERM, 15192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15193 NL80211_FLAG_NEED_RTNL, 15194 }, 15195 { 15196 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 15197 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15198 .doit = nl80211_tx_control_port, 15199 .flags = GENL_UNS_ADMIN_PERM, 15200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15201 NL80211_FLAG_NEED_RTNL, 15202 }, 15203 { 15204 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 15205 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15206 .doit = nl80211_get_ftm_responder_stats, 15207 .internal_flags = NL80211_FLAG_NEED_NETDEV | 15208 NL80211_FLAG_NEED_RTNL, 15209 }, 15210 { 15211 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 15212 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15213 .doit = nl80211_pmsr_start, 15214 .flags = GENL_UNS_ADMIN_PERM, 15215 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 15216 NL80211_FLAG_NEED_RTNL, 15217 }, 15218 { 15219 .cmd = NL80211_CMD_NOTIFY_RADAR, 15220 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 15221 .doit = nl80211_notify_radar_detection, 15222 .flags = GENL_UNS_ADMIN_PERM, 15223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15224 NL80211_FLAG_NEED_RTNL, 15225 }, 15226 { 15227 .cmd = NL80211_CMD_UPDATE_OWE_INFO, 15228 .doit = nl80211_update_owe_info, 15229 .flags = GENL_ADMIN_PERM, 15230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15231 NL80211_FLAG_NEED_RTNL, 15232 }, 15233 { 15234 .cmd = NL80211_CMD_PROBE_MESH_LINK, 15235 .doit = nl80211_probe_mesh_link, 15236 .flags = GENL_UNS_ADMIN_PERM, 15237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 15238 NL80211_FLAG_NEED_RTNL, 15239 }, 15240 { 15241 .cmd = NL80211_CMD_SET_TID_CONFIG, 15242 .doit = nl80211_set_tid_config, 15243 .flags = GENL_UNS_ADMIN_PERM, 15244 .internal_flags = NL80211_FLAG_NEED_NETDEV | 15245 NL80211_FLAG_NEED_RTNL, 15246 }, 15247 }; 15248 15249 static struct genl_family nl80211_fam __ro_after_init = { 15250 .name = NL80211_GENL_NAME, /* have users key off the name instead */ 15251 .hdrsize = 0, /* no private header */ 15252 .version = 1, /* no particular meaning now */ 15253 .maxattr = NL80211_ATTR_MAX, 15254 .policy = nl80211_policy, 15255 .netnsok = true, 15256 .pre_doit = nl80211_pre_doit, 15257 .post_doit = nl80211_post_doit, 15258 .module = THIS_MODULE, 15259 .ops = nl80211_ops, 15260 .n_ops = ARRAY_SIZE(nl80211_ops), 15261 .mcgrps = nl80211_mcgrps, 15262 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), 15263 .parallel_ops = true, 15264 }; 15265 15266 /* notification functions */ 15267 15268 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, 15269 enum nl80211_commands cmd) 15270 { 15271 struct sk_buff *msg; 15272 struct nl80211_dump_wiphy_state state = {}; 15273 15274 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && 15275 cmd != NL80211_CMD_DEL_WIPHY); 15276 15277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15278 if (!msg) 15279 return; 15280 15281 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { 15282 nlmsg_free(msg); 15283 return; 15284 } 15285 15286 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15287 NL80211_MCGRP_CONFIG, GFP_KERNEL); 15288 } 15289 15290 void nl80211_notify_iface(struct cfg80211_registered_device *rdev, 15291 struct wireless_dev *wdev, 15292 enum nl80211_commands cmd) 15293 { 15294 struct sk_buff *msg; 15295 15296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15297 if (!msg) 15298 return; 15299 15300 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { 15301 nlmsg_free(msg); 15302 return; 15303 } 15304 15305 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15306 NL80211_MCGRP_CONFIG, GFP_KERNEL); 15307 } 15308 15309 static int nl80211_add_scan_req(struct sk_buff *msg, 15310 struct cfg80211_registered_device *rdev) 15311 { 15312 struct cfg80211_scan_request *req = rdev->scan_req; 15313 struct nlattr *nest; 15314 int i; 15315 15316 if (WARN_ON(!req)) 15317 return 0; 15318 15319 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); 15320 if (!nest) 15321 goto nla_put_failure; 15322 for (i = 0; i < req->n_ssids; i++) { 15323 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 15324 goto nla_put_failure; 15325 } 15326 nla_nest_end(msg, nest); 15327 15328 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { 15329 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); 15330 if (!nest) 15331 goto nla_put_failure; 15332 for (i = 0; i < req->n_channels; i++) { 15333 if (nla_put_u32(msg, i, 15334 ieee80211_channel_to_khz(req->channels[i]))) 15335 goto nla_put_failure; 15336 } 15337 nla_nest_end(msg, nest); 15338 } else { 15339 nest = nla_nest_start_noflag(msg, 15340 NL80211_ATTR_SCAN_FREQUENCIES); 15341 if (!nest) 15342 goto nla_put_failure; 15343 for (i = 0; i < req->n_channels; i++) { 15344 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 15345 goto nla_put_failure; 15346 } 15347 nla_nest_end(msg, nest); 15348 } 15349 15350 if (req->ie && 15351 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) 15352 goto nla_put_failure; 15353 15354 if (req->flags && 15355 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) 15356 goto nla_put_failure; 15357 15358 if (req->info.scan_start_tsf && 15359 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, 15360 req->info.scan_start_tsf, NL80211_BSS_PAD) || 15361 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, 15362 req->info.tsf_bssid))) 15363 goto nla_put_failure; 15364 15365 return 0; 15366 nla_put_failure: 15367 return -ENOBUFS; 15368 } 15369 15370 static int nl80211_prep_scan_msg(struct sk_buff *msg, 15371 struct cfg80211_registered_device *rdev, 15372 struct wireless_dev *wdev, 15373 u32 portid, u32 seq, int flags, 15374 u32 cmd) 15375 { 15376 void *hdr; 15377 15378 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 15379 if (!hdr) 15380 return -1; 15381 15382 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15383 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 15384 wdev->netdev->ifindex)) || 15385 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 15386 NL80211_ATTR_PAD)) 15387 goto nla_put_failure; 15388 15389 /* ignore errors and send incomplete event anyway */ 15390 nl80211_add_scan_req(msg, rdev); 15391 15392 genlmsg_end(msg, hdr); 15393 return 0; 15394 15395 nla_put_failure: 15396 genlmsg_cancel(msg, hdr); 15397 return -EMSGSIZE; 15398 } 15399 15400 static int 15401 nl80211_prep_sched_scan_msg(struct sk_buff *msg, 15402 struct cfg80211_sched_scan_request *req, u32 cmd) 15403 { 15404 void *hdr; 15405 15406 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 15407 if (!hdr) 15408 return -1; 15409 15410 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, 15411 wiphy_to_rdev(req->wiphy)->wiphy_idx) || 15412 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || 15413 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, 15414 NL80211_ATTR_PAD)) 15415 goto nla_put_failure; 15416 15417 genlmsg_end(msg, hdr); 15418 return 0; 15419 15420 nla_put_failure: 15421 genlmsg_cancel(msg, hdr); 15422 return -EMSGSIZE; 15423 } 15424 15425 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 15426 struct wireless_dev *wdev) 15427 { 15428 struct sk_buff *msg; 15429 15430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15431 if (!msg) 15432 return; 15433 15434 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 15435 NL80211_CMD_TRIGGER_SCAN) < 0) { 15436 nlmsg_free(msg); 15437 return; 15438 } 15439 15440 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15441 NL80211_MCGRP_SCAN, GFP_KERNEL); 15442 } 15443 15444 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 15445 struct wireless_dev *wdev, bool aborted) 15446 { 15447 struct sk_buff *msg; 15448 15449 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15450 if (!msg) 15451 return NULL; 15452 15453 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 15454 aborted ? NL80211_CMD_SCAN_ABORTED : 15455 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 15456 nlmsg_free(msg); 15457 return NULL; 15458 } 15459 15460 return msg; 15461 } 15462 15463 /* send message created by nl80211_build_scan_msg() */ 15464 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, 15465 struct sk_buff *msg) 15466 { 15467 if (!msg) 15468 return; 15469 15470 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15471 NL80211_MCGRP_SCAN, GFP_KERNEL); 15472 } 15473 15474 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) 15475 { 15476 struct sk_buff *msg; 15477 15478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15479 if (!msg) 15480 return; 15481 15482 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { 15483 nlmsg_free(msg); 15484 return; 15485 } 15486 15487 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, 15488 NL80211_MCGRP_SCAN, GFP_KERNEL); 15489 } 15490 15491 static bool nl80211_reg_change_event_fill(struct sk_buff *msg, 15492 struct regulatory_request *request) 15493 { 15494 /* Userspace can always count this one always being set */ 15495 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) 15496 goto nla_put_failure; 15497 15498 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { 15499 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 15500 NL80211_REGDOM_TYPE_WORLD)) 15501 goto nla_put_failure; 15502 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { 15503 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 15504 NL80211_REGDOM_TYPE_CUSTOM_WORLD)) 15505 goto nla_put_failure; 15506 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || 15507 request->intersect) { 15508 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 15509 NL80211_REGDOM_TYPE_INTERSECTION)) 15510 goto nla_put_failure; 15511 } else { 15512 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 15513 NL80211_REGDOM_TYPE_COUNTRY) || 15514 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, 15515 request->alpha2)) 15516 goto nla_put_failure; 15517 } 15518 15519 if (request->wiphy_idx != WIPHY_IDX_INVALID) { 15520 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); 15521 15522 if (wiphy && 15523 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 15524 goto nla_put_failure; 15525 15526 if (wiphy && 15527 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 15528 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 15529 goto nla_put_failure; 15530 } 15531 15532 return true; 15533 15534 nla_put_failure: 15535 return false; 15536 } 15537 15538 /* 15539 * This can happen on global regulatory changes or device specific settings 15540 * based on custom regulatory domains. 15541 */ 15542 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, 15543 struct regulatory_request *request) 15544 { 15545 struct sk_buff *msg; 15546 void *hdr; 15547 15548 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15549 if (!msg) 15550 return; 15551 15552 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); 15553 if (!hdr) 15554 goto nla_put_failure; 15555 15556 if (!nl80211_reg_change_event_fill(msg, request)) 15557 goto nla_put_failure; 15558 15559 genlmsg_end(msg, hdr); 15560 15561 rcu_read_lock(); 15562 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 15563 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 15564 rcu_read_unlock(); 15565 15566 return; 15567 15568 nla_put_failure: 15569 nlmsg_free(msg); 15570 } 15571 15572 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 15573 struct net_device *netdev, 15574 const u8 *buf, size_t len, 15575 enum nl80211_commands cmd, gfp_t gfp, 15576 int uapsd_queues, const u8 *req_ies, 15577 size_t req_ies_len) 15578 { 15579 struct sk_buff *msg; 15580 void *hdr; 15581 15582 msg = nlmsg_new(100 + len + req_ies_len, gfp); 15583 if (!msg) 15584 return; 15585 15586 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 15587 if (!hdr) { 15588 nlmsg_free(msg); 15589 return; 15590 } 15591 15592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15593 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15594 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 15595 (req_ies && 15596 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) 15597 goto nla_put_failure; 15598 15599 if (uapsd_queues >= 0) { 15600 struct nlattr *nla_wmm = 15601 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); 15602 if (!nla_wmm) 15603 goto nla_put_failure; 15604 15605 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, 15606 uapsd_queues)) 15607 goto nla_put_failure; 15608 15609 nla_nest_end(msg, nla_wmm); 15610 } 15611 15612 genlmsg_end(msg, hdr); 15613 15614 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15615 NL80211_MCGRP_MLME, gfp); 15616 return; 15617 15618 nla_put_failure: 15619 nlmsg_free(msg); 15620 } 15621 15622 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 15623 struct net_device *netdev, const u8 *buf, 15624 size_t len, gfp_t gfp) 15625 { 15626 nl80211_send_mlme_event(rdev, netdev, buf, len, 15627 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); 15628 } 15629 15630 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 15631 struct net_device *netdev, const u8 *buf, 15632 size_t len, gfp_t gfp, int uapsd_queues, 15633 const u8 *req_ies, size_t req_ies_len) 15634 { 15635 nl80211_send_mlme_event(rdev, netdev, buf, len, 15636 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, 15637 req_ies, req_ies_len); 15638 } 15639 15640 void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 15641 struct net_device *netdev, const u8 *buf, 15642 size_t len, gfp_t gfp) 15643 { 15644 nl80211_send_mlme_event(rdev, netdev, buf, len, 15645 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); 15646 } 15647 15648 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 15649 struct net_device *netdev, const u8 *buf, 15650 size_t len, gfp_t gfp) 15651 { 15652 nl80211_send_mlme_event(rdev, netdev, buf, len, 15653 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); 15654 } 15655 15656 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, 15657 size_t len) 15658 { 15659 struct wireless_dev *wdev = dev->ieee80211_ptr; 15660 struct wiphy *wiphy = wdev->wiphy; 15661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15662 const struct ieee80211_mgmt *mgmt = (void *)buf; 15663 u32 cmd; 15664 15665 if (WARN_ON(len < 2)) 15666 return; 15667 15668 if (ieee80211_is_deauth(mgmt->frame_control)) { 15669 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; 15670 } else if (ieee80211_is_disassoc(mgmt->frame_control)) { 15671 cmd = NL80211_CMD_UNPROT_DISASSOCIATE; 15672 } else if (ieee80211_is_beacon(mgmt->frame_control)) { 15673 if (wdev->unprot_beacon_reported && 15674 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) 15675 return; 15676 cmd = NL80211_CMD_UNPROT_BEACON; 15677 wdev->unprot_beacon_reported = jiffies; 15678 } else { 15679 return; 15680 } 15681 15682 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); 15683 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, 15684 NULL, 0); 15685 } 15686 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); 15687 15688 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 15689 struct net_device *netdev, int cmd, 15690 const u8 *addr, gfp_t gfp) 15691 { 15692 struct sk_buff *msg; 15693 void *hdr; 15694 15695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15696 if (!msg) 15697 return; 15698 15699 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 15700 if (!hdr) { 15701 nlmsg_free(msg); 15702 return; 15703 } 15704 15705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15707 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 15708 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 15709 goto nla_put_failure; 15710 15711 genlmsg_end(msg, hdr); 15712 15713 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15714 NL80211_MCGRP_MLME, gfp); 15715 return; 15716 15717 nla_put_failure: 15718 nlmsg_free(msg); 15719 } 15720 15721 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 15722 struct net_device *netdev, const u8 *addr, 15723 gfp_t gfp) 15724 { 15725 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 15726 addr, gfp); 15727 } 15728 15729 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 15730 struct net_device *netdev, const u8 *addr, 15731 gfp_t gfp) 15732 { 15733 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, 15734 addr, gfp); 15735 } 15736 15737 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, 15738 struct net_device *netdev, 15739 struct cfg80211_connect_resp_params *cr, 15740 gfp_t gfp) 15741 { 15742 struct sk_buff *msg; 15743 void *hdr; 15744 15745 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + 15746 cr->fils.kek_len + cr->fils.pmk_len + 15747 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); 15748 if (!msg) 15749 return; 15750 15751 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); 15752 if (!hdr) { 15753 nlmsg_free(msg); 15754 return; 15755 } 15756 15757 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15758 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15759 (cr->bssid && 15760 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || 15761 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 15762 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : 15763 cr->status) || 15764 (cr->status < 0 && 15765 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 15766 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, 15767 cr->timeout_reason))) || 15768 (cr->req_ie && 15769 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || 15770 (cr->resp_ie && 15771 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, 15772 cr->resp_ie)) || 15773 (cr->fils.update_erp_next_seq_num && 15774 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 15775 cr->fils.erp_next_seq_num)) || 15776 (cr->status == WLAN_STATUS_SUCCESS && 15777 ((cr->fils.kek && 15778 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, 15779 cr->fils.kek)) || 15780 (cr->fils.pmk && 15781 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || 15782 (cr->fils.pmkid && 15783 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) 15784 goto nla_put_failure; 15785 15786 genlmsg_end(msg, hdr); 15787 15788 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15789 NL80211_MCGRP_MLME, gfp); 15790 return; 15791 15792 nla_put_failure: 15793 nlmsg_free(msg); 15794 } 15795 15796 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 15797 struct net_device *netdev, 15798 struct cfg80211_roam_info *info, gfp_t gfp) 15799 { 15800 struct sk_buff *msg; 15801 void *hdr; 15802 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; 15803 15804 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + 15805 info->fils.kek_len + info->fils.pmk_len + 15806 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); 15807 if (!msg) 15808 return; 15809 15810 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); 15811 if (!hdr) { 15812 nlmsg_free(msg); 15813 return; 15814 } 15815 15816 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15818 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || 15819 (info->req_ie && 15820 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 15821 info->req_ie)) || 15822 (info->resp_ie && 15823 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 15824 info->resp_ie)) || 15825 (info->fils.update_erp_next_seq_num && 15826 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 15827 info->fils.erp_next_seq_num)) || 15828 (info->fils.kek && 15829 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, 15830 info->fils.kek)) || 15831 (info->fils.pmk && 15832 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || 15833 (info->fils.pmkid && 15834 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) 15835 goto nla_put_failure; 15836 15837 genlmsg_end(msg, hdr); 15838 15839 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15840 NL80211_MCGRP_MLME, gfp); 15841 return; 15842 15843 nla_put_failure: 15844 nlmsg_free(msg); 15845 } 15846 15847 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, 15848 struct net_device *netdev, const u8 *bssid) 15849 { 15850 struct sk_buff *msg; 15851 void *hdr; 15852 15853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15854 if (!msg) 15855 return; 15856 15857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); 15858 if (!hdr) { 15859 nlmsg_free(msg); 15860 return; 15861 } 15862 15863 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15864 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15865 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 15866 goto nla_put_failure; 15867 15868 genlmsg_end(msg, hdr); 15869 15870 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15871 NL80211_MCGRP_MLME, GFP_KERNEL); 15872 return; 15873 15874 nla_put_failure: 15875 nlmsg_free(msg); 15876 } 15877 15878 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 15879 struct net_device *netdev, u16 reason, 15880 const u8 *ie, size_t ie_len, bool from_ap) 15881 { 15882 struct sk_buff *msg; 15883 void *hdr; 15884 15885 msg = nlmsg_new(100 + ie_len, GFP_KERNEL); 15886 if (!msg) 15887 return; 15888 15889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); 15890 if (!hdr) { 15891 nlmsg_free(msg); 15892 return; 15893 } 15894 15895 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15896 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15897 (reason && 15898 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || 15899 (from_ap && 15900 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || 15901 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) 15902 goto nla_put_failure; 15903 15904 genlmsg_end(msg, hdr); 15905 15906 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15907 NL80211_MCGRP_MLME, GFP_KERNEL); 15908 return; 15909 15910 nla_put_failure: 15911 nlmsg_free(msg); 15912 } 15913 15914 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 15915 struct net_device *netdev, const u8 *bssid, 15916 gfp_t gfp) 15917 { 15918 struct sk_buff *msg; 15919 void *hdr; 15920 15921 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15922 if (!msg) 15923 return; 15924 15925 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); 15926 if (!hdr) { 15927 nlmsg_free(msg); 15928 return; 15929 } 15930 15931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15932 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15933 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 15934 goto nla_put_failure; 15935 15936 genlmsg_end(msg, hdr); 15937 15938 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15939 NL80211_MCGRP_MLME, gfp); 15940 return; 15941 15942 nla_put_failure: 15943 nlmsg_free(msg); 15944 } 15945 15946 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, 15947 const u8 *ie, u8 ie_len, 15948 int sig_dbm, gfp_t gfp) 15949 { 15950 struct wireless_dev *wdev = dev->ieee80211_ptr; 15951 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 15952 struct sk_buff *msg; 15953 void *hdr; 15954 15955 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) 15956 return; 15957 15958 trace_cfg80211_notify_new_peer_candidate(dev, addr); 15959 15960 msg = nlmsg_new(100 + ie_len, gfp); 15961 if (!msg) 15962 return; 15963 15964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); 15965 if (!hdr) { 15966 nlmsg_free(msg); 15967 return; 15968 } 15969 15970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15971 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 15972 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 15973 (ie_len && ie && 15974 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || 15975 (sig_dbm && 15976 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) 15977 goto nla_put_failure; 15978 15979 genlmsg_end(msg, hdr); 15980 15981 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15982 NL80211_MCGRP_MLME, gfp); 15983 return; 15984 15985 nla_put_failure: 15986 nlmsg_free(msg); 15987 } 15988 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); 15989 15990 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 15991 struct net_device *netdev, const u8 *addr, 15992 enum nl80211_key_type key_type, int key_id, 15993 const u8 *tsc, gfp_t gfp) 15994 { 15995 struct sk_buff *msg; 15996 void *hdr; 15997 15998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15999 if (!msg) 16000 return; 16001 16002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); 16003 if (!hdr) { 16004 nlmsg_free(msg); 16005 return; 16006 } 16007 16008 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16009 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16010 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || 16011 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || 16012 (key_id != -1 && 16013 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || 16014 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) 16015 goto nla_put_failure; 16016 16017 genlmsg_end(msg, hdr); 16018 16019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16020 NL80211_MCGRP_MLME, gfp); 16021 return; 16022 16023 nla_put_failure: 16024 nlmsg_free(msg); 16025 } 16026 16027 void nl80211_send_beacon_hint_event(struct wiphy *wiphy, 16028 struct ieee80211_channel *channel_before, 16029 struct ieee80211_channel *channel_after) 16030 { 16031 struct sk_buff *msg; 16032 void *hdr; 16033 struct nlattr *nl_freq; 16034 16035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 16036 if (!msg) 16037 return; 16038 16039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); 16040 if (!hdr) { 16041 nlmsg_free(msg); 16042 return; 16043 } 16044 16045 /* 16046 * Since we are applying the beacon hint to a wiphy we know its 16047 * wiphy_idx is valid 16048 */ 16049 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 16050 goto nla_put_failure; 16051 16052 /* Before */ 16053 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); 16054 if (!nl_freq) 16055 goto nla_put_failure; 16056 16057 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) 16058 goto nla_put_failure; 16059 nla_nest_end(msg, nl_freq); 16060 16061 /* After */ 16062 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); 16063 if (!nl_freq) 16064 goto nla_put_failure; 16065 16066 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) 16067 goto nla_put_failure; 16068 nla_nest_end(msg, nl_freq); 16069 16070 genlmsg_end(msg, hdr); 16071 16072 rcu_read_lock(); 16073 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 16074 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 16075 rcu_read_unlock(); 16076 16077 return; 16078 16079 nla_put_failure: 16080 nlmsg_free(msg); 16081 } 16082 16083 static void nl80211_send_remain_on_chan_event( 16084 int cmd, struct cfg80211_registered_device *rdev, 16085 struct wireless_dev *wdev, u64 cookie, 16086 struct ieee80211_channel *chan, 16087 unsigned int duration, gfp_t gfp) 16088 { 16089 struct sk_buff *msg; 16090 void *hdr; 16091 16092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16093 if (!msg) 16094 return; 16095 16096 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 16097 if (!hdr) { 16098 nlmsg_free(msg); 16099 return; 16100 } 16101 16102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16103 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16104 wdev->netdev->ifindex)) || 16105 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16106 NL80211_ATTR_PAD) || 16107 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || 16108 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 16109 NL80211_CHAN_NO_HT) || 16110 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 16111 NL80211_ATTR_PAD)) 16112 goto nla_put_failure; 16113 16114 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && 16115 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) 16116 goto nla_put_failure; 16117 16118 genlmsg_end(msg, hdr); 16119 16120 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16121 NL80211_MCGRP_MLME, gfp); 16122 return; 16123 16124 nla_put_failure: 16125 nlmsg_free(msg); 16126 } 16127 16128 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, 16129 struct ieee80211_channel *chan, 16130 unsigned int duration, gfp_t gfp) 16131 { 16132 struct wiphy *wiphy = wdev->wiphy; 16133 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16134 16135 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); 16136 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, 16137 rdev, wdev, cookie, chan, 16138 duration, gfp); 16139 } 16140 EXPORT_SYMBOL(cfg80211_ready_on_channel); 16141 16142 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, 16143 struct ieee80211_channel *chan, 16144 gfp_t gfp) 16145 { 16146 struct wiphy *wiphy = wdev->wiphy; 16147 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16148 16149 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); 16150 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 16151 rdev, wdev, cookie, chan, 0, gfp); 16152 } 16153 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); 16154 16155 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, 16156 struct ieee80211_channel *chan, 16157 gfp_t gfp) 16158 { 16159 struct wiphy *wiphy = wdev->wiphy; 16160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16161 16162 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); 16163 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, 16164 rdev, wdev, cookie, chan, 0, gfp); 16165 } 16166 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); 16167 16168 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, 16169 struct station_info *sinfo, gfp_t gfp) 16170 { 16171 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 16172 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16173 struct sk_buff *msg; 16174 16175 trace_cfg80211_new_sta(dev, mac_addr, sinfo); 16176 16177 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16178 if (!msg) 16179 return; 16180 16181 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, 16182 rdev, dev, mac_addr, sinfo) < 0) { 16183 nlmsg_free(msg); 16184 return; 16185 } 16186 16187 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16188 NL80211_MCGRP_MLME, gfp); 16189 } 16190 EXPORT_SYMBOL(cfg80211_new_sta); 16191 16192 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, 16193 struct station_info *sinfo, gfp_t gfp) 16194 { 16195 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 16196 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16197 struct sk_buff *msg; 16198 struct station_info empty_sinfo = {}; 16199 16200 if (!sinfo) 16201 sinfo = &empty_sinfo; 16202 16203 trace_cfg80211_del_sta(dev, mac_addr); 16204 16205 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16206 if (!msg) { 16207 cfg80211_sinfo_release_content(sinfo); 16208 return; 16209 } 16210 16211 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, 16212 rdev, dev, mac_addr, sinfo) < 0) { 16213 nlmsg_free(msg); 16214 return; 16215 } 16216 16217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16218 NL80211_MCGRP_MLME, gfp); 16219 } 16220 EXPORT_SYMBOL(cfg80211_del_sta_sinfo); 16221 16222 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, 16223 enum nl80211_connect_failed_reason reason, 16224 gfp_t gfp) 16225 { 16226 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 16227 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16228 struct sk_buff *msg; 16229 void *hdr; 16230 16231 msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 16232 if (!msg) 16233 return; 16234 16235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); 16236 if (!hdr) { 16237 nlmsg_free(msg); 16238 return; 16239 } 16240 16241 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16242 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 16243 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) 16244 goto nla_put_failure; 16245 16246 genlmsg_end(msg, hdr); 16247 16248 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16249 NL80211_MCGRP_MLME, gfp); 16250 return; 16251 16252 nla_put_failure: 16253 nlmsg_free(msg); 16254 } 16255 EXPORT_SYMBOL(cfg80211_conn_failed); 16256 16257 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, 16258 const u8 *addr, gfp_t gfp) 16259 { 16260 struct wireless_dev *wdev = dev->ieee80211_ptr; 16261 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16262 struct sk_buff *msg; 16263 void *hdr; 16264 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); 16265 16266 if (!nlportid) 16267 return false; 16268 16269 msg = nlmsg_new(100, gfp); 16270 if (!msg) 16271 return true; 16272 16273 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 16274 if (!hdr) { 16275 nlmsg_free(msg); 16276 return true; 16277 } 16278 16279 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16280 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16281 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 16282 goto nla_put_failure; 16283 16284 genlmsg_end(msg, hdr); 16285 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 16286 return true; 16287 16288 nla_put_failure: 16289 nlmsg_free(msg); 16290 return true; 16291 } 16292 16293 bool cfg80211_rx_spurious_frame(struct net_device *dev, 16294 const u8 *addr, gfp_t gfp) 16295 { 16296 struct wireless_dev *wdev = dev->ieee80211_ptr; 16297 bool ret; 16298 16299 trace_cfg80211_rx_spurious_frame(dev, addr); 16300 16301 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 16302 wdev->iftype != NL80211_IFTYPE_P2P_GO)) { 16303 trace_cfg80211_return_bool(false); 16304 return false; 16305 } 16306 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, 16307 addr, gfp); 16308 trace_cfg80211_return_bool(ret); 16309 return ret; 16310 } 16311 EXPORT_SYMBOL(cfg80211_rx_spurious_frame); 16312 16313 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, 16314 const u8 *addr, gfp_t gfp) 16315 { 16316 struct wireless_dev *wdev = dev->ieee80211_ptr; 16317 bool ret; 16318 16319 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); 16320 16321 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 16322 wdev->iftype != NL80211_IFTYPE_P2P_GO && 16323 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { 16324 trace_cfg80211_return_bool(false); 16325 return false; 16326 } 16327 ret = __nl80211_unexpected_frame(dev, 16328 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, 16329 addr, gfp); 16330 trace_cfg80211_return_bool(ret); 16331 return ret; 16332 } 16333 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); 16334 16335 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, 16336 struct wireless_dev *wdev, u32 nlportid, 16337 int freq, int sig_dbm, 16338 const u8 *buf, size_t len, u32 flags, gfp_t gfp) 16339 { 16340 struct net_device *netdev = wdev->netdev; 16341 struct sk_buff *msg; 16342 void *hdr; 16343 16344 msg = nlmsg_new(100 + len, gfp); 16345 if (!msg) 16346 return -ENOMEM; 16347 16348 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 16349 if (!hdr) { 16350 nlmsg_free(msg); 16351 return -ENOMEM; 16352 } 16353 16354 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16355 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16356 netdev->ifindex)) || 16357 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16358 NL80211_ATTR_PAD) || 16359 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || 16360 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || 16361 (sig_dbm && 16362 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 16363 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 16364 (flags && 16365 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) 16366 goto nla_put_failure; 16367 16368 genlmsg_end(msg, hdr); 16369 16370 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 16371 16372 nla_put_failure: 16373 nlmsg_free(msg); 16374 return -ENOBUFS; 16375 } 16376 16377 static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, 16378 const u8 *buf, size_t len, bool ack, 16379 gfp_t gfp, enum nl80211_commands command) 16380 { 16381 struct wiphy *wiphy = wdev->wiphy; 16382 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16383 struct net_device *netdev = wdev->netdev; 16384 struct sk_buff *msg; 16385 void *hdr; 16386 16387 if (command == NL80211_CMD_FRAME_TX_STATUS) 16388 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); 16389 else 16390 trace_cfg80211_control_port_tx_status(wdev, cookie, ack); 16391 16392 msg = nlmsg_new(100 + len, gfp); 16393 if (!msg) 16394 return; 16395 16396 hdr = nl80211hdr_put(msg, 0, 0, 0, command); 16397 if (!hdr) { 16398 nlmsg_free(msg); 16399 return; 16400 } 16401 16402 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16403 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16404 netdev->ifindex)) || 16405 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16406 NL80211_ATTR_PAD) || 16407 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 16408 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 16409 NL80211_ATTR_PAD) || 16410 (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) 16411 goto nla_put_failure; 16412 16413 genlmsg_end(msg, hdr); 16414 16415 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16416 NL80211_MCGRP_MLME, gfp); 16417 return; 16418 16419 nla_put_failure: 16420 nlmsg_free(msg); 16421 } 16422 16423 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, 16424 const u8 *buf, size_t len, bool ack, 16425 gfp_t gfp) 16426 { 16427 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, 16428 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); 16429 } 16430 EXPORT_SYMBOL(cfg80211_control_port_tx_status); 16431 16432 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, 16433 const u8 *buf, size_t len, bool ack, gfp_t gfp) 16434 { 16435 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, 16436 NL80211_CMD_FRAME_TX_STATUS); 16437 } 16438 EXPORT_SYMBOL(cfg80211_mgmt_tx_status); 16439 16440 static int __nl80211_rx_control_port(struct net_device *dev, 16441 struct sk_buff *skb, 16442 bool unencrypted, gfp_t gfp) 16443 { 16444 struct wireless_dev *wdev = dev->ieee80211_ptr; 16445 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16446 struct ethhdr *ehdr = eth_hdr(skb); 16447 const u8 *addr = ehdr->h_source; 16448 u16 proto = be16_to_cpu(skb->protocol); 16449 struct sk_buff *msg; 16450 void *hdr; 16451 struct nlattr *frame; 16452 16453 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); 16454 16455 if (!nlportid) 16456 return -ENOENT; 16457 16458 msg = nlmsg_new(100 + skb->len, gfp); 16459 if (!msg) 16460 return -ENOMEM; 16461 16462 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); 16463 if (!hdr) { 16464 nlmsg_free(msg); 16465 return -ENOBUFS; 16466 } 16467 16468 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16470 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16471 NL80211_ATTR_PAD) || 16472 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 16473 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || 16474 (unencrypted && nla_put_flag(msg, 16475 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) 16476 goto nla_put_failure; 16477 16478 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); 16479 if (!frame) 16480 goto nla_put_failure; 16481 16482 skb_copy_bits(skb, 0, nla_data(frame), skb->len); 16483 genlmsg_end(msg, hdr); 16484 16485 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 16486 16487 nla_put_failure: 16488 nlmsg_free(msg); 16489 return -ENOBUFS; 16490 } 16491 16492 bool cfg80211_rx_control_port(struct net_device *dev, 16493 struct sk_buff *skb, bool unencrypted) 16494 { 16495 int ret; 16496 16497 trace_cfg80211_rx_control_port(dev, skb, unencrypted); 16498 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); 16499 trace_cfg80211_return_bool(ret == 0); 16500 return ret == 0; 16501 } 16502 EXPORT_SYMBOL(cfg80211_rx_control_port); 16503 16504 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 16505 const char *mac, gfp_t gfp) 16506 { 16507 struct wireless_dev *wdev = dev->ieee80211_ptr; 16508 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16509 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16510 void **cb; 16511 16512 if (!msg) 16513 return NULL; 16514 16515 cb = (void **)msg->cb; 16516 16517 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 16518 if (!cb[0]) { 16519 nlmsg_free(msg); 16520 return NULL; 16521 } 16522 16523 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16524 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 16525 goto nla_put_failure; 16526 16527 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 16528 goto nla_put_failure; 16529 16530 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); 16531 if (!cb[1]) 16532 goto nla_put_failure; 16533 16534 cb[2] = rdev; 16535 16536 return msg; 16537 nla_put_failure: 16538 nlmsg_free(msg); 16539 return NULL; 16540 } 16541 16542 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) 16543 { 16544 void **cb = (void **)msg->cb; 16545 struct cfg80211_registered_device *rdev = cb[2]; 16546 16547 nla_nest_end(msg, cb[1]); 16548 genlmsg_end(msg, cb[0]); 16549 16550 memset(msg->cb, 0, sizeof(msg->cb)); 16551 16552 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16553 NL80211_MCGRP_MLME, gfp); 16554 } 16555 16556 void cfg80211_cqm_rssi_notify(struct net_device *dev, 16557 enum nl80211_cqm_rssi_threshold_event rssi_event, 16558 s32 rssi_level, gfp_t gfp) 16559 { 16560 struct sk_buff *msg; 16561 struct wireless_dev *wdev = dev->ieee80211_ptr; 16562 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16563 16564 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); 16565 16566 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && 16567 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) 16568 return; 16569 16570 if (wdev->cqm_config) { 16571 wdev->cqm_config->last_rssi_event_value = rssi_level; 16572 16573 cfg80211_cqm_rssi_update(rdev, dev); 16574 16575 if (rssi_level == 0) 16576 rssi_level = wdev->cqm_config->last_rssi_event_value; 16577 } 16578 16579 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 16580 if (!msg) 16581 return; 16582 16583 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 16584 rssi_event)) 16585 goto nla_put_failure; 16586 16587 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, 16588 rssi_level)) 16589 goto nla_put_failure; 16590 16591 cfg80211_send_cqm(msg, gfp); 16592 16593 return; 16594 16595 nla_put_failure: 16596 nlmsg_free(msg); 16597 } 16598 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 16599 16600 void cfg80211_cqm_txe_notify(struct net_device *dev, 16601 const u8 *peer, u32 num_packets, 16602 u32 rate, u32 intvl, gfp_t gfp) 16603 { 16604 struct sk_buff *msg; 16605 16606 msg = cfg80211_prepare_cqm(dev, peer, gfp); 16607 if (!msg) 16608 return; 16609 16610 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 16611 goto nla_put_failure; 16612 16613 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 16614 goto nla_put_failure; 16615 16616 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 16617 goto nla_put_failure; 16618 16619 cfg80211_send_cqm(msg, gfp); 16620 return; 16621 16622 nla_put_failure: 16623 nlmsg_free(msg); 16624 } 16625 EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 16626 16627 void cfg80211_cqm_pktloss_notify(struct net_device *dev, 16628 const u8 *peer, u32 num_packets, gfp_t gfp) 16629 { 16630 struct sk_buff *msg; 16631 16632 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 16633 16634 msg = cfg80211_prepare_cqm(dev, peer, gfp); 16635 if (!msg) 16636 return; 16637 16638 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 16639 goto nla_put_failure; 16640 16641 cfg80211_send_cqm(msg, gfp); 16642 return; 16643 16644 nla_put_failure: 16645 nlmsg_free(msg); 16646 } 16647 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 16648 16649 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) 16650 { 16651 struct sk_buff *msg; 16652 16653 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 16654 if (!msg) 16655 return; 16656 16657 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) 16658 goto nla_put_failure; 16659 16660 cfg80211_send_cqm(msg, gfp); 16661 return; 16662 16663 nla_put_failure: 16664 nlmsg_free(msg); 16665 } 16666 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); 16667 16668 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 16669 struct net_device *netdev, const u8 *bssid, 16670 const u8 *replay_ctr, gfp_t gfp) 16671 { 16672 struct sk_buff *msg; 16673 struct nlattr *rekey_attr; 16674 void *hdr; 16675 16676 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16677 if (!msg) 16678 return; 16679 16680 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); 16681 if (!hdr) { 16682 nlmsg_free(msg); 16683 return; 16684 } 16685 16686 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16687 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16688 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 16689 goto nla_put_failure; 16690 16691 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); 16692 if (!rekey_attr) 16693 goto nla_put_failure; 16694 16695 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, 16696 NL80211_REPLAY_CTR_LEN, replay_ctr)) 16697 goto nla_put_failure; 16698 16699 nla_nest_end(msg, rekey_attr); 16700 16701 genlmsg_end(msg, hdr); 16702 16703 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16704 NL80211_MCGRP_MLME, gfp); 16705 return; 16706 16707 nla_put_failure: 16708 nlmsg_free(msg); 16709 } 16710 16711 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, 16712 const u8 *replay_ctr, gfp_t gfp) 16713 { 16714 struct wireless_dev *wdev = dev->ieee80211_ptr; 16715 struct wiphy *wiphy = wdev->wiphy; 16716 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16717 16718 trace_cfg80211_gtk_rekey_notify(dev, bssid); 16719 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); 16720 } 16721 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); 16722 16723 static void 16724 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, 16725 struct net_device *netdev, int index, 16726 const u8 *bssid, bool preauth, gfp_t gfp) 16727 { 16728 struct sk_buff *msg; 16729 struct nlattr *attr; 16730 void *hdr; 16731 16732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16733 if (!msg) 16734 return; 16735 16736 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); 16737 if (!hdr) { 16738 nlmsg_free(msg); 16739 return; 16740 } 16741 16742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16743 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 16744 goto nla_put_failure; 16745 16746 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); 16747 if (!attr) 16748 goto nla_put_failure; 16749 16750 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || 16751 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || 16752 (preauth && 16753 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) 16754 goto nla_put_failure; 16755 16756 nla_nest_end(msg, attr); 16757 16758 genlmsg_end(msg, hdr); 16759 16760 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16761 NL80211_MCGRP_MLME, gfp); 16762 return; 16763 16764 nla_put_failure: 16765 nlmsg_free(msg); 16766 } 16767 16768 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, 16769 const u8 *bssid, bool preauth, gfp_t gfp) 16770 { 16771 struct wireless_dev *wdev = dev->ieee80211_ptr; 16772 struct wiphy *wiphy = wdev->wiphy; 16773 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16774 16775 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); 16776 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 16777 } 16778 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 16779 16780 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, 16781 struct net_device *netdev, 16782 struct cfg80211_chan_def *chandef, 16783 gfp_t gfp, 16784 enum nl80211_commands notif, 16785 u8 count) 16786 { 16787 struct sk_buff *msg; 16788 void *hdr; 16789 16790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16791 if (!msg) 16792 return; 16793 16794 hdr = nl80211hdr_put(msg, 0, 0, 0, notif); 16795 if (!hdr) { 16796 nlmsg_free(msg); 16797 return; 16798 } 16799 16800 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 16801 goto nla_put_failure; 16802 16803 if (nl80211_send_chandef(msg, chandef)) 16804 goto nla_put_failure; 16805 16806 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && 16807 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) 16808 goto nla_put_failure; 16809 16810 genlmsg_end(msg, hdr); 16811 16812 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16813 NL80211_MCGRP_MLME, gfp); 16814 return; 16815 16816 nla_put_failure: 16817 nlmsg_free(msg); 16818 } 16819 16820 void cfg80211_ch_switch_notify(struct net_device *dev, 16821 struct cfg80211_chan_def *chandef) 16822 { 16823 struct wireless_dev *wdev = dev->ieee80211_ptr; 16824 struct wiphy *wiphy = wdev->wiphy; 16825 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16826 16827 ASSERT_WDEV_LOCK(wdev); 16828 16829 trace_cfg80211_ch_switch_notify(dev, chandef); 16830 16831 wdev->chandef = *chandef; 16832 wdev->preset_chandef = *chandef; 16833 16834 if (wdev->iftype == NL80211_IFTYPE_STATION && 16835 !WARN_ON(!wdev->current_bss)) 16836 cfg80211_update_assoc_bss_entry(wdev, chandef->chan); 16837 16838 cfg80211_sched_dfs_chan_update(rdev); 16839 16840 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 16841 NL80211_CMD_CH_SWITCH_NOTIFY, 0); 16842 } 16843 EXPORT_SYMBOL(cfg80211_ch_switch_notify); 16844 16845 void cfg80211_ch_switch_started_notify(struct net_device *dev, 16846 struct cfg80211_chan_def *chandef, 16847 u8 count) 16848 { 16849 struct wireless_dev *wdev = dev->ieee80211_ptr; 16850 struct wiphy *wiphy = wdev->wiphy; 16851 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16852 16853 trace_cfg80211_ch_switch_started_notify(dev, chandef); 16854 16855 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 16856 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); 16857 } 16858 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 16859 16860 void 16861 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 16862 const struct cfg80211_chan_def *chandef, 16863 enum nl80211_radar_event event, 16864 struct net_device *netdev, gfp_t gfp) 16865 { 16866 struct sk_buff *msg; 16867 void *hdr; 16868 16869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16870 if (!msg) 16871 return; 16872 16873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); 16874 if (!hdr) { 16875 nlmsg_free(msg); 16876 return; 16877 } 16878 16879 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 16880 goto nla_put_failure; 16881 16882 /* NOP and radar events don't need a netdev parameter */ 16883 if (netdev) { 16884 struct wireless_dev *wdev = netdev->ieee80211_ptr; 16885 16886 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16887 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16888 NL80211_ATTR_PAD)) 16889 goto nla_put_failure; 16890 } 16891 16892 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) 16893 goto nla_put_failure; 16894 16895 if (nl80211_send_chandef(msg, chandef)) 16896 goto nla_put_failure; 16897 16898 genlmsg_end(msg, hdr); 16899 16900 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16901 NL80211_MCGRP_MLME, gfp); 16902 return; 16903 16904 nla_put_failure: 16905 nlmsg_free(msg); 16906 } 16907 16908 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, 16909 struct sta_opmode_info *sta_opmode, 16910 gfp_t gfp) 16911 { 16912 struct sk_buff *msg; 16913 struct wireless_dev *wdev = dev->ieee80211_ptr; 16914 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16915 void *hdr; 16916 16917 if (WARN_ON(!mac)) 16918 return; 16919 16920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16921 if (!msg) 16922 return; 16923 16924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); 16925 if (!hdr) { 16926 nlmsg_free(msg); 16927 return; 16928 } 16929 16930 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 16931 goto nla_put_failure; 16932 16933 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 16934 goto nla_put_failure; 16935 16936 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 16937 goto nla_put_failure; 16938 16939 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && 16940 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) 16941 goto nla_put_failure; 16942 16943 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && 16944 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) 16945 goto nla_put_failure; 16946 16947 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && 16948 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) 16949 goto nla_put_failure; 16950 16951 genlmsg_end(msg, hdr); 16952 16953 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16954 NL80211_MCGRP_MLME, gfp); 16955 16956 return; 16957 16958 nla_put_failure: 16959 nlmsg_free(msg); 16960 } 16961 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); 16962 16963 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 16964 u64 cookie, bool acked, s32 ack_signal, 16965 bool is_valid_ack_signal, gfp_t gfp) 16966 { 16967 struct wireless_dev *wdev = dev->ieee80211_ptr; 16968 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16969 struct sk_buff *msg; 16970 void *hdr; 16971 16972 trace_cfg80211_probe_status(dev, addr, cookie, acked); 16973 16974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16975 16976 if (!msg) 16977 return; 16978 16979 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); 16980 if (!hdr) { 16981 nlmsg_free(msg); 16982 return; 16983 } 16984 16985 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16986 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16987 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 16988 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 16989 NL80211_ATTR_PAD) || 16990 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || 16991 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, 16992 ack_signal))) 16993 goto nla_put_failure; 16994 16995 genlmsg_end(msg, hdr); 16996 16997 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16998 NL80211_MCGRP_MLME, gfp); 16999 return; 17000 17001 nla_put_failure: 17002 nlmsg_free(msg); 17003 } 17004 EXPORT_SYMBOL(cfg80211_probe_status); 17005 17006 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, 17007 size_t len, int freq, int sig_dbm) 17008 { 17009 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17010 struct sk_buff *msg; 17011 void *hdr; 17012 struct cfg80211_beacon_registration *reg; 17013 17014 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); 17015 17016 spin_lock_bh(&rdev->beacon_registrations_lock); 17017 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 17018 msg = nlmsg_new(len + 100, GFP_ATOMIC); 17019 if (!msg) { 17020 spin_unlock_bh(&rdev->beacon_registrations_lock); 17021 return; 17022 } 17023 17024 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 17025 if (!hdr) 17026 goto nla_put_failure; 17027 17028 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17029 (freq && 17030 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 17031 KHZ_TO_MHZ(freq)) || 17032 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 17033 freq % 1000))) || 17034 (sig_dbm && 17035 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 17036 nla_put(msg, NL80211_ATTR_FRAME, len, frame)) 17037 goto nla_put_failure; 17038 17039 genlmsg_end(msg, hdr); 17040 17041 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); 17042 } 17043 spin_unlock_bh(&rdev->beacon_registrations_lock); 17044 return; 17045 17046 nla_put_failure: 17047 spin_unlock_bh(&rdev->beacon_registrations_lock); 17048 nlmsg_free(msg); 17049 } 17050 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); 17051 17052 #ifdef CONFIG_PM 17053 static int cfg80211_net_detect_results(struct sk_buff *msg, 17054 struct cfg80211_wowlan_wakeup *wakeup) 17055 { 17056 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; 17057 struct nlattr *nl_results, *nl_match, *nl_freqs; 17058 int i, j; 17059 17060 nl_results = nla_nest_start_noflag(msg, 17061 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 17062 if (!nl_results) 17063 return -EMSGSIZE; 17064 17065 for (i = 0; i < nd->n_matches; i++) { 17066 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 17067 17068 nl_match = nla_nest_start_noflag(msg, i); 17069 if (!nl_match) 17070 break; 17071 17072 /* The SSID attribute is optional in nl80211, but for 17073 * simplicity reasons it's always present in the 17074 * cfg80211 structure. If a driver can't pass the 17075 * SSID, that needs to be changed. A zero length SSID 17076 * is still a valid SSID (wildcard), so it cannot be 17077 * used for this purpose. 17078 */ 17079 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, 17080 match->ssid.ssid)) { 17081 nla_nest_cancel(msg, nl_match); 17082 goto out; 17083 } 17084 17085 if (match->n_channels) { 17086 nl_freqs = nla_nest_start_noflag(msg, 17087 NL80211_ATTR_SCAN_FREQUENCIES); 17088 if (!nl_freqs) { 17089 nla_nest_cancel(msg, nl_match); 17090 goto out; 17091 } 17092 17093 for (j = 0; j < match->n_channels; j++) { 17094 if (nla_put_u32(msg, j, match->channels[j])) { 17095 nla_nest_cancel(msg, nl_freqs); 17096 nla_nest_cancel(msg, nl_match); 17097 goto out; 17098 } 17099 } 17100 17101 nla_nest_end(msg, nl_freqs); 17102 } 17103 17104 nla_nest_end(msg, nl_match); 17105 } 17106 17107 out: 17108 nla_nest_end(msg, nl_results); 17109 return 0; 17110 } 17111 17112 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, 17113 struct cfg80211_wowlan_wakeup *wakeup, 17114 gfp_t gfp) 17115 { 17116 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17117 struct sk_buff *msg; 17118 void *hdr; 17119 int size = 200; 17120 17121 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); 17122 17123 if (wakeup) 17124 size += wakeup->packet_present_len; 17125 17126 msg = nlmsg_new(size, gfp); 17127 if (!msg) 17128 return; 17129 17130 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); 17131 if (!hdr) 17132 goto free_msg; 17133 17134 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17135 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17136 NL80211_ATTR_PAD)) 17137 goto free_msg; 17138 17139 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 17140 wdev->netdev->ifindex)) 17141 goto free_msg; 17142 17143 if (wakeup) { 17144 struct nlattr *reasons; 17145 17146 reasons = nla_nest_start_noflag(msg, 17147 NL80211_ATTR_WOWLAN_TRIGGERS); 17148 if (!reasons) 17149 goto free_msg; 17150 17151 if (wakeup->disconnect && 17152 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) 17153 goto free_msg; 17154 if (wakeup->magic_pkt && 17155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) 17156 goto free_msg; 17157 if (wakeup->gtk_rekey_failure && 17158 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) 17159 goto free_msg; 17160 if (wakeup->eap_identity_req && 17161 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) 17162 goto free_msg; 17163 if (wakeup->four_way_handshake && 17164 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) 17165 goto free_msg; 17166 if (wakeup->rfkill_release && 17167 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) 17168 goto free_msg; 17169 17170 if (wakeup->pattern_idx >= 0 && 17171 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 17172 wakeup->pattern_idx)) 17173 goto free_msg; 17174 17175 if (wakeup->tcp_match && 17176 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) 17177 goto free_msg; 17178 17179 if (wakeup->tcp_connlost && 17180 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) 17181 goto free_msg; 17182 17183 if (wakeup->tcp_nomoretokens && 17184 nla_put_flag(msg, 17185 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) 17186 goto free_msg; 17187 17188 if (wakeup->packet) { 17189 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; 17190 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; 17191 17192 if (!wakeup->packet_80211) { 17193 pkt_attr = 17194 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; 17195 len_attr = 17196 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; 17197 } 17198 17199 if (wakeup->packet_len && 17200 nla_put_u32(msg, len_attr, wakeup->packet_len)) 17201 goto free_msg; 17202 17203 if (nla_put(msg, pkt_attr, wakeup->packet_present_len, 17204 wakeup->packet)) 17205 goto free_msg; 17206 } 17207 17208 if (wakeup->net_detect && 17209 cfg80211_net_detect_results(msg, wakeup)) 17210 goto free_msg; 17211 17212 nla_nest_end(msg, reasons); 17213 } 17214 17215 genlmsg_end(msg, hdr); 17216 17217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17218 NL80211_MCGRP_MLME, gfp); 17219 return; 17220 17221 free_msg: 17222 nlmsg_free(msg); 17223 } 17224 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); 17225 #endif 17226 17227 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, 17228 enum nl80211_tdls_operation oper, 17229 u16 reason_code, gfp_t gfp) 17230 { 17231 struct wireless_dev *wdev = dev->ieee80211_ptr; 17232 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17233 struct sk_buff *msg; 17234 void *hdr; 17235 17236 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, 17237 reason_code); 17238 17239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17240 if (!msg) 17241 return; 17242 17243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); 17244 if (!hdr) { 17245 nlmsg_free(msg); 17246 return; 17247 } 17248 17249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 17251 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || 17252 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || 17253 (reason_code > 0 && 17254 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) 17255 goto nla_put_failure; 17256 17257 genlmsg_end(msg, hdr); 17258 17259 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17260 NL80211_MCGRP_MLME, gfp); 17261 return; 17262 17263 nla_put_failure: 17264 nlmsg_free(msg); 17265 } 17266 EXPORT_SYMBOL(cfg80211_tdls_oper_request); 17267 17268 static int nl80211_netlink_notify(struct notifier_block * nb, 17269 unsigned long state, 17270 void *_notify) 17271 { 17272 struct netlink_notify *notify = _notify; 17273 struct cfg80211_registered_device *rdev; 17274 struct wireless_dev *wdev; 17275 struct cfg80211_beacon_registration *reg, *tmp; 17276 17277 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) 17278 return NOTIFY_DONE; 17279 17280 rcu_read_lock(); 17281 17282 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 17283 struct cfg80211_sched_scan_request *sched_scan_req; 17284 17285 list_for_each_entry_rcu(sched_scan_req, 17286 &rdev->sched_scan_req_list, 17287 list) { 17288 if (sched_scan_req->owner_nlportid == notify->portid) { 17289 sched_scan_req->nl_owner_dead = true; 17290 schedule_work(&rdev->sched_scan_stop_wk); 17291 } 17292 } 17293 17294 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { 17295 cfg80211_mlme_unregister_socket(wdev, notify->portid); 17296 17297 if (wdev->owner_nlportid == notify->portid) { 17298 wdev->nl_owner_dead = true; 17299 schedule_work(&rdev->destroy_work); 17300 } else if (wdev->conn_owner_nlportid == notify->portid) { 17301 schedule_work(&wdev->disconnect_wk); 17302 } 17303 17304 cfg80211_release_pmsr(wdev, notify->portid); 17305 } 17306 17307 spin_lock_bh(&rdev->beacon_registrations_lock); 17308 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, 17309 list) { 17310 if (reg->nlportid == notify->portid) { 17311 list_del(®->list); 17312 kfree(reg); 17313 break; 17314 } 17315 } 17316 spin_unlock_bh(&rdev->beacon_registrations_lock); 17317 } 17318 17319 rcu_read_unlock(); 17320 17321 /* 17322 * It is possible that the user space process that is controlling the 17323 * indoor setting disappeared, so notify the regulatory core. 17324 */ 17325 regulatory_netlink_notify(notify->portid); 17326 return NOTIFY_OK; 17327 } 17328 17329 static struct notifier_block nl80211_netlink_notifier = { 17330 .notifier_call = nl80211_netlink_notify, 17331 }; 17332 17333 void cfg80211_ft_event(struct net_device *netdev, 17334 struct cfg80211_ft_event_params *ft_event) 17335 { 17336 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 17337 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17338 struct sk_buff *msg; 17339 void *hdr; 17340 17341 trace_cfg80211_ft_event(wiphy, netdev, ft_event); 17342 17343 if (!ft_event->target_ap) 17344 return; 17345 17346 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, 17347 GFP_KERNEL); 17348 if (!msg) 17349 return; 17350 17351 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); 17352 if (!hdr) 17353 goto out; 17354 17355 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17356 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17357 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) 17358 goto out; 17359 17360 if (ft_event->ies && 17361 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) 17362 goto out; 17363 if (ft_event->ric_ies && 17364 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, 17365 ft_event->ric_ies)) 17366 goto out; 17367 17368 genlmsg_end(msg, hdr); 17369 17370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17371 NL80211_MCGRP_MLME, GFP_KERNEL); 17372 return; 17373 out: 17374 nlmsg_free(msg); 17375 } 17376 EXPORT_SYMBOL(cfg80211_ft_event); 17377 17378 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) 17379 { 17380 struct cfg80211_registered_device *rdev; 17381 struct sk_buff *msg; 17382 void *hdr; 17383 u32 nlportid; 17384 17385 rdev = wiphy_to_rdev(wdev->wiphy); 17386 if (!rdev->crit_proto_nlportid) 17387 return; 17388 17389 nlportid = rdev->crit_proto_nlportid; 17390 rdev->crit_proto_nlportid = 0; 17391 17392 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17393 if (!msg) 17394 return; 17395 17396 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); 17397 if (!hdr) 17398 goto nla_put_failure; 17399 17400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17401 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17402 NL80211_ATTR_PAD)) 17403 goto nla_put_failure; 17404 17405 genlmsg_end(msg, hdr); 17406 17407 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 17408 return; 17409 17410 nla_put_failure: 17411 nlmsg_free(msg); 17412 } 17413 EXPORT_SYMBOL(cfg80211_crit_proto_stopped); 17414 17415 void nl80211_send_ap_stopped(struct wireless_dev *wdev) 17416 { 17417 struct wiphy *wiphy = wdev->wiphy; 17418 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17419 struct sk_buff *msg; 17420 void *hdr; 17421 17422 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17423 if (!msg) 17424 return; 17425 17426 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); 17427 if (!hdr) 17428 goto out; 17429 17430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17431 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 17432 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17433 NL80211_ATTR_PAD)) 17434 goto out; 17435 17436 genlmsg_end(msg, hdr); 17437 17438 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 17439 NL80211_MCGRP_MLME, GFP_KERNEL); 17440 return; 17441 out: 17442 nlmsg_free(msg); 17443 } 17444 17445 int cfg80211_external_auth_request(struct net_device *dev, 17446 struct cfg80211_external_auth_params *params, 17447 gfp_t gfp) 17448 { 17449 struct wireless_dev *wdev = dev->ieee80211_ptr; 17450 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 17451 struct sk_buff *msg; 17452 void *hdr; 17453 17454 if (!wdev->conn_owner_nlportid) 17455 return -EINVAL; 17456 17457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17458 if (!msg) 17459 return -ENOMEM; 17460 17461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); 17462 if (!hdr) 17463 goto nla_put_failure; 17464 17465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 17467 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || 17468 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, 17469 params->action) || 17470 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || 17471 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, 17472 params->ssid.ssid)) 17473 goto nla_put_failure; 17474 17475 genlmsg_end(msg, hdr); 17476 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 17477 wdev->conn_owner_nlportid); 17478 return 0; 17479 17480 nla_put_failure: 17481 nlmsg_free(msg); 17482 return -ENOBUFS; 17483 } 17484 EXPORT_SYMBOL(cfg80211_external_auth_request); 17485 17486 void cfg80211_update_owe_info_event(struct net_device *netdev, 17487 struct cfg80211_update_owe_info *owe_info, 17488 gfp_t gfp) 17489 { 17490 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 17491 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17492 struct sk_buff *msg; 17493 void *hdr; 17494 17495 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); 17496 17497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17498 if (!msg) 17499 return; 17500 17501 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); 17502 if (!hdr) 17503 goto nla_put_failure; 17504 17505 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17506 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17507 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) 17508 goto nla_put_failure; 17509 17510 if (!owe_info->ie_len || 17511 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) 17512 goto nla_put_failure; 17513 17514 genlmsg_end(msg, hdr); 17515 17516 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17517 NL80211_MCGRP_MLME, gfp); 17518 return; 17519 17520 nla_put_failure: 17521 genlmsg_cancel(msg, hdr); 17522 nlmsg_free(msg); 17523 } 17524 EXPORT_SYMBOL(cfg80211_update_owe_info_event); 17525 17526 /* initialisation/exit functions */ 17527 17528 int __init nl80211_init(void) 17529 { 17530 int err; 17531 17532 err = genl_register_family(&nl80211_fam); 17533 if (err) 17534 return err; 17535 17536 err = netlink_register_notifier(&nl80211_netlink_notifier); 17537 if (err) 17538 goto err_out; 17539 17540 return 0; 17541 err_out: 17542 genl_unregister_family(&nl80211_fam); 17543 return err; 17544 } 17545 17546 void nl80211_exit(void) 17547 { 17548 netlink_unregister_notifier(&nl80211_netlink_notifier); 17549 genl_unregister_family(&nl80211_fam); 17550 } 17551