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-2019 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 <net/net_namespace.h> 24 #include <net/genetlink.h> 25 #include <net/cfg80211.h> 26 #include <net/sock.h> 27 #include <net/inet_connection_sock.h> 28 #include "core.h" 29 #include "nl80211.h" 30 #include "reg.h" 31 #include "rdev-ops.h" 32 33 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 34 struct genl_info *info, 35 struct cfg80211_crypto_settings *settings, 36 int cipher_limit); 37 38 /* the netlink family */ 39 static struct genl_family nl80211_fam; 40 41 /* multicast groups */ 42 enum nl80211_multicast_groups { 43 NL80211_MCGRP_CONFIG, 44 NL80211_MCGRP_SCAN, 45 NL80211_MCGRP_REGULATORY, 46 NL80211_MCGRP_MLME, 47 NL80211_MCGRP_VENDOR, 48 NL80211_MCGRP_NAN, 49 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ 50 }; 51 52 static const struct genl_multicast_group nl80211_mcgrps[] = { 53 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, 54 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, 55 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, 56 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, 57 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, 58 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, 59 #ifdef CONFIG_NL80211_TESTMODE 60 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } 61 #endif 62 }; 63 64 /* returns ERR_PTR values */ 65 static struct wireless_dev * 66 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) 67 { 68 struct cfg80211_registered_device *rdev; 69 struct wireless_dev *result = NULL; 70 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; 71 bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; 72 u64 wdev_id; 73 int wiphy_idx = -1; 74 int ifidx = -1; 75 76 ASSERT_RTNL(); 77 78 if (!have_ifidx && !have_wdev_id) 79 return ERR_PTR(-EINVAL); 80 81 if (have_ifidx) 82 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 83 if (have_wdev_id) { 84 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 85 wiphy_idx = wdev_id >> 32; 86 } 87 88 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 89 struct wireless_dev *wdev; 90 91 if (wiphy_net(&rdev->wiphy) != netns) 92 continue; 93 94 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) 95 continue; 96 97 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 98 if (have_ifidx && wdev->netdev && 99 wdev->netdev->ifindex == ifidx) { 100 result = wdev; 101 break; 102 } 103 if (have_wdev_id && wdev->identifier == (u32)wdev_id) { 104 result = wdev; 105 break; 106 } 107 } 108 109 if (result) 110 break; 111 } 112 113 if (result) 114 return result; 115 return ERR_PTR(-ENODEV); 116 } 117 118 static struct cfg80211_registered_device * 119 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) 120 { 121 struct cfg80211_registered_device *rdev = NULL, *tmp; 122 struct net_device *netdev; 123 124 ASSERT_RTNL(); 125 126 if (!attrs[NL80211_ATTR_WIPHY] && 127 !attrs[NL80211_ATTR_IFINDEX] && 128 !attrs[NL80211_ATTR_WDEV]) 129 return ERR_PTR(-EINVAL); 130 131 if (attrs[NL80211_ATTR_WIPHY]) 132 rdev = cfg80211_rdev_by_wiphy_idx( 133 nla_get_u32(attrs[NL80211_ATTR_WIPHY])); 134 135 if (attrs[NL80211_ATTR_WDEV]) { 136 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 137 struct wireless_dev *wdev; 138 bool found = false; 139 140 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); 141 if (tmp) { 142 /* make sure wdev exists */ 143 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { 144 if (wdev->identifier != (u32)wdev_id) 145 continue; 146 found = true; 147 break; 148 } 149 150 if (!found) 151 tmp = NULL; 152 153 if (rdev && tmp != rdev) 154 return ERR_PTR(-EINVAL); 155 rdev = tmp; 156 } 157 } 158 159 if (attrs[NL80211_ATTR_IFINDEX]) { 160 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 161 162 netdev = __dev_get_by_index(netns, ifindex); 163 if (netdev) { 164 if (netdev->ieee80211_ptr) 165 tmp = wiphy_to_rdev( 166 netdev->ieee80211_ptr->wiphy); 167 else 168 tmp = NULL; 169 170 /* not wireless device -- return error */ 171 if (!tmp) 172 return ERR_PTR(-EINVAL); 173 174 /* mismatch -- return error */ 175 if (rdev && tmp != rdev) 176 return ERR_PTR(-EINVAL); 177 178 rdev = tmp; 179 } 180 } 181 182 if (!rdev) 183 return ERR_PTR(-ENODEV); 184 185 if (netns != wiphy_net(&rdev->wiphy)) 186 return ERR_PTR(-ENODEV); 187 188 return rdev; 189 } 190 191 /* 192 * This function returns a pointer to the driver 193 * that the genl_info item that is passed refers to. 194 * 195 * The result of this can be a PTR_ERR and hence must 196 * be checked with IS_ERR() for errors. 197 */ 198 static struct cfg80211_registered_device * 199 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) 200 { 201 return __cfg80211_rdev_from_attrs(netns, info->attrs); 202 } 203 204 static int validate_ie_attr(const struct nlattr *attr, 205 struct netlink_ext_ack *extack) 206 { 207 const u8 *data = nla_data(attr); 208 unsigned int len = nla_len(attr); 209 const struct element *elem; 210 211 for_each_element(elem, data, len) { 212 /* nothing */ 213 } 214 215 if (for_each_element_completed(elem, data, len)) 216 return 0; 217 218 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); 219 return -EINVAL; 220 } 221 222 /* policy for the attributes */ 223 static const struct nla_policy 224 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { 225 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, 226 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, 227 .len = U8_MAX }, 228 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, 229 .len = U8_MAX }, 230 }; 231 232 static const struct nla_policy 233 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { 234 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, 235 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, 236 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = 237 NLA_POLICY_MAX(NLA_U8, 15), 238 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, 239 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = 240 NLA_POLICY_MAX(NLA_U8, 15), 241 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = 242 NLA_POLICY_MAX(NLA_U8, 31), 243 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, 244 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, 245 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, 246 }; 247 248 static const struct nla_policy 249 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { 250 [NL80211_PMSR_TYPE_FTM] = 251 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), 252 }; 253 254 static const struct nla_policy 255 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { 256 [NL80211_PMSR_REQ_ATTR_DATA] = 257 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), 258 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, 259 }; 260 261 static const struct nla_policy 262 nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { 263 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, 264 /* 265 * we could specify this again to be the top-level policy, 266 * but that would open us up to recursion problems ... 267 */ 268 [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED }, 269 [NL80211_PMSR_PEER_ATTR_REQ] = 270 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), 271 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, 272 }; 273 274 static const struct nla_policy 275 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { 276 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, 277 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, 278 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, 279 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, 280 [NL80211_PMSR_ATTR_PEERS] = 281 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), 282 }; 283 284 const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { 285 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 286 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 287 .len = 20-1 }, 288 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, 289 290 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, 291 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, 292 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, 293 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, 294 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, 295 296 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 297 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 298 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, 299 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, 300 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, 301 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, 302 303 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), 304 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 305 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, 306 307 [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN }, 308 [NL80211_ATTR_PREV_BSSID] = { 309 .type = NLA_EXACT_LEN_WARN, 310 .len = ETH_ALEN 311 }, 312 313 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, 314 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, 315 .len = WLAN_MAX_KEY_LEN }, 316 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 5), 317 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, 318 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, 319 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 320 [NL80211_ATTR_KEY_TYPE] = 321 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), 322 323 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 324 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 325 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, 326 .len = IEEE80211_MAX_DATA_LEN }, 327 [NL80211_ATTR_BEACON_TAIL] = 328 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 329 IEEE80211_MAX_DATA_LEN), 330 [NL80211_ATTR_STA_AID] = 331 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 332 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, 333 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, 334 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, 335 .len = NL80211_MAX_SUPP_RATES }, 336 [NL80211_ATTR_STA_PLINK_ACTION] = 337 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), 338 [NL80211_ATTR_STA_TX_POWER_SETTING] = 339 NLA_POLICY_RANGE(NLA_U8, 340 NL80211_TX_POWER_AUTOMATIC, 341 NL80211_TX_POWER_FIXED), 342 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, 343 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 344 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 345 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 346 .len = IEEE80211_MAX_MESH_ID_LEN }, 347 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, 348 349 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, 350 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, 351 352 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 353 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 354 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 355 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 356 .len = NL80211_MAX_SUPP_RATES }, 357 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, 358 359 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, 360 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, 361 362 [NL80211_ATTR_HT_CAPABILITY] = { 363 .type = NLA_EXACT_LEN_WARN, 364 .len = NL80211_HT_CAPABILITY_LEN 365 }, 366 367 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, 368 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, 369 validate_ie_attr, 370 IEEE80211_MAX_DATA_LEN), 371 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, 372 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, 373 374 [NL80211_ATTR_SSID] = { .type = NLA_BINARY, 375 .len = IEEE80211_MAX_SSID_LEN }, 376 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, 377 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, 378 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, 379 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, 380 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, 381 NL80211_MFP_NO, 382 NL80211_MFP_OPTIONAL), 383 [NL80211_ATTR_STA_FLAGS2] = { 384 .len = sizeof(struct nl80211_sta_flag_update), 385 }, 386 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 387 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, 388 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, 389 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, 390 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, 391 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 392 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 393 [NL80211_ATTR_PID] = { .type = NLA_U32 }, 394 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, 395 [NL80211_ATTR_PMKID] = { 396 .type = NLA_EXACT_LEN_WARN, 397 .len = WLAN_PMKID_LEN 398 }, 399 [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, 400 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, 401 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, 402 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, 403 .len = IEEE80211_MAX_DATA_LEN }, 404 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, 405 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, 406 NL80211_PS_DISABLED, 407 NL80211_PS_ENABLED), 408 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, 409 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, 410 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, 411 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, 412 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, 413 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, 414 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, 415 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, 416 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, 417 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, 418 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 419 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, 420 [NL80211_ATTR_STA_PLINK_STATE] = 421 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), 422 [NL80211_ATTR_MESH_PEER_AID] = 423 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 424 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, 425 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, 426 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, 427 [NL80211_ATTR_HIDDEN_SSID] = 428 NLA_POLICY_RANGE(NLA_U32, 429 NL80211_HIDDEN_SSID_NOT_IN_USE, 430 NL80211_HIDDEN_SSID_ZERO_CONTENTS), 431 [NL80211_ATTR_IE_PROBE_RESP] = 432 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 433 IEEE80211_MAX_DATA_LEN), 434 [NL80211_ATTR_IE_ASSOC_RESP] = 435 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 436 IEEE80211_MAX_DATA_LEN), 437 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, 438 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, 439 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, 440 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, 441 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, 442 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, 443 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, 444 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, 445 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, 446 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, 447 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, 448 .len = IEEE80211_MAX_DATA_LEN }, 449 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, 450 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, 451 [NL80211_ATTR_HT_CAPABILITY_MASK] = { 452 .len = NL80211_HT_CAPABILITY_LEN 453 }, 454 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, 455 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, 456 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, 457 [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, 458 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, 459 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, 460 [NL80211_ATTR_VHT_CAPABILITY] = { 461 .type = NLA_EXACT_LEN_WARN, 462 .len = NL80211_VHT_CAPABILITY_LEN 463 }, 464 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, 465 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), 466 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), 467 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = 468 NLA_POLICY_RANGE(NLA_U32, 469 NL80211_MESH_POWER_UNKNOWN + 1, 470 NL80211_MESH_POWER_MAX), 471 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, 472 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, 473 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, 474 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, 475 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, 476 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, 477 [NL80211_ATTR_VHT_CAPABILITY_MASK] = { 478 .len = NL80211_VHT_CAPABILITY_LEN, 479 }, 480 [NL80211_ATTR_MDID] = { .type = NLA_U16 }, 481 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, 482 .len = IEEE80211_MAX_DATA_LEN }, 483 [NL80211_ATTR_PEER_AID] = 484 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 485 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, 486 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, 487 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, 488 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, 489 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, 490 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, 491 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, 492 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, 493 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, 494 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, 495 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, 496 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, 497 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, 498 .len = IEEE80211_QOS_MAP_LEN_MAX }, 499 [NL80211_ATTR_MAC_HINT] = { 500 .type = NLA_EXACT_LEN_WARN, 501 .len = ETH_ALEN 502 }, 503 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, 504 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, 505 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, 506 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, 507 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, 508 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), 509 [NL80211_ATTR_USER_PRIO] = 510 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), 511 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, 512 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, 513 [NL80211_ATTR_MAC_MASK] = { 514 .type = NLA_EXACT_LEN_WARN, 515 .len = ETH_ALEN 516 }, 517 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, 518 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, 519 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, 520 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, 521 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, 522 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, 523 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = 524 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), 525 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { 526 .len = VHT_MUMIMO_GROUPS_DATA_LEN 527 }, 528 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { 529 .type = NLA_EXACT_LEN_WARN, 530 .len = ETH_ALEN 531 }, 532 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), 533 [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, 534 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, 535 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, 536 .len = FILS_MAX_KEK_LEN }, 537 [NL80211_ATTR_FILS_NONCES] = { 538 .type = NLA_EXACT_LEN_WARN, 539 .len = 2 * FILS_NONCE_LEN 540 }, 541 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, 542 [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN }, 543 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, 544 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { 545 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 546 }, 547 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, 548 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, 549 .len = FILS_ERP_MAX_USERNAME_LEN }, 550 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, 551 .len = FILS_ERP_MAX_REALM_LEN }, 552 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, 553 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, 554 .len = FILS_ERP_MAX_RRK_LEN }, 555 [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 }, 556 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, 557 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, 558 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, 559 560 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, 561 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, 562 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, 563 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, 564 .len = NL80211_HE_MAX_CAPABILITY_LEN }, 565 566 [NL80211_ATTR_FTM_RESPONDER] = { 567 .type = NLA_NESTED, 568 .validation_data = nl80211_ftm_responder_policy, 569 }, 570 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), 571 [NL80211_ATTR_PEER_MEASUREMENTS] = 572 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), 573 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), 574 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, 575 .len = SAE_PASSWORD_MAX_LEN }, 576 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, 577 }; 578 579 /* policy for the key attributes */ 580 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { 581 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 582 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 583 [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, 584 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 585 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, 586 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 587 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), 588 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 589 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), 590 }; 591 592 /* policy for the key default flags */ 593 static const struct nla_policy 594 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { 595 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, 596 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, 597 }; 598 599 #ifdef CONFIG_PM 600 /* policy for WoWLAN attributes */ 601 static const struct nla_policy 602 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { 603 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, 604 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, 605 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, 606 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, 607 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, 608 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, 609 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, 610 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, 611 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, 612 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, 613 }; 614 615 static const struct nla_policy 616 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { 617 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, 618 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, 619 [NL80211_WOWLAN_TCP_DST_MAC] = { 620 .type = NLA_EXACT_LEN_WARN, 621 .len = ETH_ALEN 622 }, 623 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, 624 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, 625 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, 626 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { 627 .len = sizeof(struct nl80211_wowlan_tcp_data_seq) 628 }, 629 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { 630 .len = sizeof(struct nl80211_wowlan_tcp_data_token) 631 }, 632 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, 633 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 }, 634 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 }, 635 }; 636 #endif /* CONFIG_PM */ 637 638 /* policy for coalesce rule attributes */ 639 static const struct nla_policy 640 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { 641 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, 642 [NL80211_ATTR_COALESCE_RULE_CONDITION] = 643 NLA_POLICY_RANGE(NLA_U32, 644 NL80211_COALESCE_CONDITION_MATCH, 645 NL80211_COALESCE_CONDITION_NO_MATCH), 646 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, 647 }; 648 649 /* policy for GTK rekey offload attributes */ 650 static const struct nla_policy 651 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { 652 [NL80211_REKEY_DATA_KEK] = { 653 .type = NLA_EXACT_LEN_WARN, 654 .len = NL80211_KEK_LEN, 655 }, 656 [NL80211_REKEY_DATA_KCK] = { 657 .type = NLA_EXACT_LEN_WARN, 658 .len = NL80211_KCK_LEN, 659 }, 660 [NL80211_REKEY_DATA_REPLAY_CTR] = { 661 .type = NLA_EXACT_LEN_WARN, 662 .len = NL80211_REPLAY_CTR_LEN 663 }, 664 }; 665 666 static const struct nla_policy 667 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { 668 [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, 669 [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, 670 [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, 671 }; 672 673 static const struct nla_policy 674 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { 675 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, 676 .len = IEEE80211_MAX_SSID_LEN }, 677 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { 678 .type = NLA_EXACT_LEN_WARN, 679 .len = ETH_ALEN 680 }, 681 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, 682 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = 683 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), 684 }; 685 686 static const struct nla_policy 687 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { 688 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, 689 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, 690 }; 691 692 static const struct nla_policy 693 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { 694 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, 695 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, 696 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { 697 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 698 }, 699 }; 700 701 /* policy for NAN function attributes */ 702 static const struct nla_policy 703 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { 704 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, 705 [NL80211_NAN_FUNC_SERVICE_ID] = { 706 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, 707 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, 708 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, 709 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, 710 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, 711 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, 712 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { 713 .type = NLA_EXACT_LEN_WARN, 714 .len = ETH_ALEN 715 }, 716 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, 717 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, 718 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, 719 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, 720 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, 721 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, 722 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, 723 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, 724 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, 725 }; 726 727 /* policy for Service Response Filter attributes */ 728 static const struct nla_policy 729 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { 730 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, 731 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, 732 .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, 733 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, 734 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, 735 }; 736 737 /* policy for packet pattern attributes */ 738 static const struct nla_policy 739 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { 740 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, 741 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, 742 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, 743 }; 744 745 int nl80211_prepare_wdev_dump(struct netlink_callback *cb, 746 struct cfg80211_registered_device **rdev, 747 struct wireless_dev **wdev) 748 { 749 int err; 750 751 if (!cb->args[0]) { 752 err = nlmsg_parse_deprecated(cb->nlh, 753 GENL_HDRLEN + nl80211_fam.hdrsize, 754 genl_family_attrbuf(&nl80211_fam), 755 nl80211_fam.maxattr, 756 nl80211_policy, NULL); 757 if (err) 758 return err; 759 760 *wdev = __cfg80211_wdev_from_attrs( 761 sock_net(cb->skb->sk), 762 genl_family_attrbuf(&nl80211_fam)); 763 if (IS_ERR(*wdev)) 764 return PTR_ERR(*wdev); 765 *rdev = wiphy_to_rdev((*wdev)->wiphy); 766 /* 0 is the first index - add 1 to parse only once */ 767 cb->args[0] = (*rdev)->wiphy_idx + 1; 768 cb->args[1] = (*wdev)->identifier; 769 } else { 770 /* subtract the 1 again here */ 771 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 772 struct wireless_dev *tmp; 773 774 if (!wiphy) 775 return -ENODEV; 776 *rdev = wiphy_to_rdev(wiphy); 777 *wdev = NULL; 778 779 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { 780 if (tmp->identifier == cb->args[1]) { 781 *wdev = tmp; 782 break; 783 } 784 } 785 786 if (!*wdev) 787 return -ENODEV; 788 } 789 790 return 0; 791 } 792 793 /* message building helper */ 794 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, 795 int flags, u8 cmd) 796 { 797 /* since there is no private header just add the generic one */ 798 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); 799 } 800 801 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, 802 const struct ieee80211_reg_rule *rule) 803 { 804 int j; 805 struct nlattr *nl_wmm_rules = 806 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); 807 808 if (!nl_wmm_rules) 809 goto nla_put_failure; 810 811 for (j = 0; j < IEEE80211_NUM_ACS; j++) { 812 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); 813 814 if (!nl_wmm_rule) 815 goto nla_put_failure; 816 817 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, 818 rule->wmm_rule.client[j].cw_min) || 819 nla_put_u16(msg, NL80211_WMMR_CW_MAX, 820 rule->wmm_rule.client[j].cw_max) || 821 nla_put_u8(msg, NL80211_WMMR_AIFSN, 822 rule->wmm_rule.client[j].aifsn) || 823 nla_put_u16(msg, NL80211_WMMR_TXOP, 824 rule->wmm_rule.client[j].cot)) 825 goto nla_put_failure; 826 827 nla_nest_end(msg, nl_wmm_rule); 828 } 829 nla_nest_end(msg, nl_wmm_rules); 830 831 return 0; 832 833 nla_put_failure: 834 return -ENOBUFS; 835 } 836 837 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, 838 struct ieee80211_channel *chan, 839 bool large) 840 { 841 /* Some channels must be completely excluded from the 842 * list to protect old user-space tools from breaking 843 */ 844 if (!large && chan->flags & 845 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) 846 return 0; 847 848 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, 849 chan->center_freq)) 850 goto nla_put_failure; 851 852 if ((chan->flags & IEEE80211_CHAN_DISABLED) && 853 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) 854 goto nla_put_failure; 855 if (chan->flags & IEEE80211_CHAN_NO_IR) { 856 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) 857 goto nla_put_failure; 858 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) 859 goto nla_put_failure; 860 } 861 if (chan->flags & IEEE80211_CHAN_RADAR) { 862 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) 863 goto nla_put_failure; 864 if (large) { 865 u32 time; 866 867 time = elapsed_jiffies_msecs(chan->dfs_state_entered); 868 869 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, 870 chan->dfs_state)) 871 goto nla_put_failure; 872 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, 873 time)) 874 goto nla_put_failure; 875 if (nla_put_u32(msg, 876 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, 877 chan->dfs_cac_ms)) 878 goto nla_put_failure; 879 } 880 } 881 882 if (large) { 883 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && 884 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) 885 goto nla_put_failure; 886 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && 887 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) 888 goto nla_put_failure; 889 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && 890 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) 891 goto nla_put_failure; 892 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && 893 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) 894 goto nla_put_failure; 895 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && 896 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) 897 goto nla_put_failure; 898 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && 899 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) 900 goto nla_put_failure; 901 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && 902 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) 903 goto nla_put_failure; 904 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && 905 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) 906 goto nla_put_failure; 907 } 908 909 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 910 DBM_TO_MBM(chan->max_power))) 911 goto nla_put_failure; 912 913 if (large) { 914 const struct ieee80211_reg_rule *rule = 915 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); 916 917 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { 918 if (nl80211_msg_put_wmm_rules(msg, rule)) 919 goto nla_put_failure; 920 } 921 } 922 923 return 0; 924 925 nla_put_failure: 926 return -ENOBUFS; 927 } 928 929 static bool nl80211_put_txq_stats(struct sk_buff *msg, 930 struct cfg80211_txq_stats *txqstats, 931 int attrtype) 932 { 933 struct nlattr *txqattr; 934 935 #define PUT_TXQVAL_U32(attr, memb) do { \ 936 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ 937 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ 938 return false; \ 939 } while (0) 940 941 txqattr = nla_nest_start_noflag(msg, attrtype); 942 if (!txqattr) 943 return false; 944 945 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); 946 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); 947 PUT_TXQVAL_U32(FLOWS, flows); 948 PUT_TXQVAL_U32(DROPS, drops); 949 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); 950 PUT_TXQVAL_U32(OVERLIMIT, overlimit); 951 PUT_TXQVAL_U32(OVERMEMORY, overmemory); 952 PUT_TXQVAL_U32(COLLISIONS, collisions); 953 PUT_TXQVAL_U32(TX_BYTES, tx_bytes); 954 PUT_TXQVAL_U32(TX_PACKETS, tx_packets); 955 PUT_TXQVAL_U32(MAX_FLOWS, max_flows); 956 nla_nest_end(msg, txqattr); 957 958 #undef PUT_TXQVAL_U32 959 return true; 960 } 961 962 /* netlink command implementations */ 963 964 struct key_parse { 965 struct key_params p; 966 int idx; 967 int type; 968 bool def, defmgmt; 969 bool def_uni, def_multi; 970 }; 971 972 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, 973 struct key_parse *k) 974 { 975 struct nlattr *tb[NL80211_KEY_MAX + 1]; 976 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, 977 nl80211_key_policy, 978 info->extack); 979 if (err) 980 return err; 981 982 k->def = !!tb[NL80211_KEY_DEFAULT]; 983 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 984 985 if (k->def) { 986 k->def_uni = true; 987 k->def_multi = true; 988 } 989 if (k->defmgmt) 990 k->def_multi = true; 991 992 if (tb[NL80211_KEY_IDX]) 993 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 994 995 if (tb[NL80211_KEY_DATA]) { 996 k->p.key = nla_data(tb[NL80211_KEY_DATA]); 997 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); 998 } 999 1000 if (tb[NL80211_KEY_SEQ]) { 1001 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); 1002 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); 1003 } 1004 1005 if (tb[NL80211_KEY_CIPHER]) 1006 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 1007 1008 if (tb[NL80211_KEY_TYPE]) 1009 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); 1010 1011 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 1012 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1013 1014 err = nla_parse_nested_deprecated(kdt, 1015 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1016 tb[NL80211_KEY_DEFAULT_TYPES], 1017 nl80211_key_default_policy, 1018 info->extack); 1019 if (err) 1020 return err; 1021 1022 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1023 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1024 } 1025 1026 if (tb[NL80211_KEY_MODE]) 1027 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); 1028 1029 return 0; 1030 } 1031 1032 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) 1033 { 1034 if (info->attrs[NL80211_ATTR_KEY_DATA]) { 1035 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); 1036 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); 1037 } 1038 1039 if (info->attrs[NL80211_ATTR_KEY_SEQ]) { 1040 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); 1041 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); 1042 } 1043 1044 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1045 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1046 1047 if (info->attrs[NL80211_ATTR_KEY_CIPHER]) 1048 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); 1049 1050 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 1051 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 1052 1053 if (k->def) { 1054 k->def_uni = true; 1055 k->def_multi = true; 1056 } 1057 if (k->defmgmt) 1058 k->def_multi = true; 1059 1060 if (info->attrs[NL80211_ATTR_KEY_TYPE]) 1061 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 1062 1063 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1064 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1065 int err = nla_parse_nested_deprecated(kdt, 1066 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1067 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1068 nl80211_key_default_policy, 1069 info->extack); 1070 if (err) 1071 return err; 1072 1073 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1074 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1075 } 1076 1077 return 0; 1078 } 1079 1080 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) 1081 { 1082 int err; 1083 1084 memset(k, 0, sizeof(*k)); 1085 k->idx = -1; 1086 k->type = -1; 1087 1088 if (info->attrs[NL80211_ATTR_KEY]) 1089 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); 1090 else 1091 err = nl80211_parse_key_old(info, k); 1092 1093 if (err) 1094 return err; 1095 1096 if (k->def && k->defmgmt) { 1097 GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid"); 1098 return -EINVAL; 1099 } 1100 1101 if (k->defmgmt) { 1102 if (k->def_uni || !k->def_multi) { 1103 GENL_SET_ERR_MSG(info, "defmgmt key must be mcast"); 1104 return -EINVAL; 1105 } 1106 } 1107 1108 if (k->idx != -1) { 1109 if (k->defmgmt) { 1110 if (k->idx < 4 || k->idx > 5) { 1111 GENL_SET_ERR_MSG(info, 1112 "defmgmt key idx not 4 or 5"); 1113 return -EINVAL; 1114 } 1115 } else if (k->def) { 1116 if (k->idx < 0 || k->idx > 3) { 1117 GENL_SET_ERR_MSG(info, "def key idx not 0-3"); 1118 return -EINVAL; 1119 } 1120 } else { 1121 if (k->idx < 0 || k->idx > 5) { 1122 GENL_SET_ERR_MSG(info, "key idx not 0-5"); 1123 return -EINVAL; 1124 } 1125 } 1126 } 1127 1128 return 0; 1129 } 1130 1131 static struct cfg80211_cached_keys * 1132 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, 1133 struct genl_info *info, bool *no_ht) 1134 { 1135 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; 1136 struct key_parse parse; 1137 struct nlattr *key; 1138 struct cfg80211_cached_keys *result; 1139 int rem, err, def = 0; 1140 bool have_key = false; 1141 1142 nla_for_each_nested(key, keys, rem) { 1143 have_key = true; 1144 break; 1145 } 1146 1147 if (!have_key) 1148 return NULL; 1149 1150 result = kzalloc(sizeof(*result), GFP_KERNEL); 1151 if (!result) 1152 return ERR_PTR(-ENOMEM); 1153 1154 result->def = -1; 1155 1156 nla_for_each_nested(key, keys, rem) { 1157 memset(&parse, 0, sizeof(parse)); 1158 parse.idx = -1; 1159 1160 err = nl80211_parse_key_new(info, key, &parse); 1161 if (err) 1162 goto error; 1163 err = -EINVAL; 1164 if (!parse.p.key) 1165 goto error; 1166 if (parse.idx < 0 || parse.idx > 3) { 1167 GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); 1168 goto error; 1169 } 1170 if (parse.def) { 1171 if (def) { 1172 GENL_SET_ERR_MSG(info, 1173 "only one key can be default"); 1174 goto error; 1175 } 1176 def = 1; 1177 result->def = parse.idx; 1178 if (!parse.def_uni || !parse.def_multi) 1179 goto error; 1180 } else if (parse.defmgmt) 1181 goto error; 1182 err = cfg80211_validate_key_settings(rdev, &parse.p, 1183 parse.idx, false, NULL); 1184 if (err) 1185 goto error; 1186 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && 1187 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { 1188 GENL_SET_ERR_MSG(info, "connect key must be WEP"); 1189 err = -EINVAL; 1190 goto error; 1191 } 1192 result->params[parse.idx].cipher = parse.p.cipher; 1193 result->params[parse.idx].key_len = parse.p.key_len; 1194 result->params[parse.idx].key = result->data[parse.idx]; 1195 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); 1196 1197 /* must be WEP key if we got here */ 1198 if (no_ht) 1199 *no_ht = true; 1200 } 1201 1202 if (result->def < 0) { 1203 err = -EINVAL; 1204 GENL_SET_ERR_MSG(info, "need a default/TX key"); 1205 goto error; 1206 } 1207 1208 return result; 1209 error: 1210 kfree(result); 1211 return ERR_PTR(err); 1212 } 1213 1214 static int nl80211_key_allowed(struct wireless_dev *wdev) 1215 { 1216 ASSERT_WDEV_LOCK(wdev); 1217 1218 switch (wdev->iftype) { 1219 case NL80211_IFTYPE_AP: 1220 case NL80211_IFTYPE_AP_VLAN: 1221 case NL80211_IFTYPE_P2P_GO: 1222 case NL80211_IFTYPE_MESH_POINT: 1223 break; 1224 case NL80211_IFTYPE_ADHOC: 1225 case NL80211_IFTYPE_STATION: 1226 case NL80211_IFTYPE_P2P_CLIENT: 1227 if (!wdev->current_bss) 1228 return -ENOLINK; 1229 break; 1230 case NL80211_IFTYPE_UNSPECIFIED: 1231 case NL80211_IFTYPE_OCB: 1232 case NL80211_IFTYPE_MONITOR: 1233 case NL80211_IFTYPE_NAN: 1234 case NL80211_IFTYPE_P2P_DEVICE: 1235 case NL80211_IFTYPE_WDS: 1236 case NUM_NL80211_IFTYPES: 1237 return -EINVAL; 1238 } 1239 1240 return 0; 1241 } 1242 1243 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, 1244 struct nlattr *tb) 1245 { 1246 struct ieee80211_channel *chan; 1247 1248 if (tb == NULL) 1249 return NULL; 1250 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); 1251 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 1252 return NULL; 1253 return chan; 1254 } 1255 1256 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1257 { 1258 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); 1259 int i; 1260 1261 if (!nl_modes) 1262 goto nla_put_failure; 1263 1264 i = 0; 1265 while (ifmodes) { 1266 if ((ifmodes & 1) && nla_put_flag(msg, i)) 1267 goto nla_put_failure; 1268 ifmodes >>= 1; 1269 i++; 1270 } 1271 1272 nla_nest_end(msg, nl_modes); 1273 return 0; 1274 1275 nla_put_failure: 1276 return -ENOBUFS; 1277 } 1278 1279 static int nl80211_put_iface_combinations(struct wiphy *wiphy, 1280 struct sk_buff *msg, 1281 bool large) 1282 { 1283 struct nlattr *nl_combis; 1284 int i, j; 1285 1286 nl_combis = nla_nest_start_noflag(msg, 1287 NL80211_ATTR_INTERFACE_COMBINATIONS); 1288 if (!nl_combis) 1289 goto nla_put_failure; 1290 1291 for (i = 0; i < wiphy->n_iface_combinations; i++) { 1292 const struct ieee80211_iface_combination *c; 1293 struct nlattr *nl_combi, *nl_limits; 1294 1295 c = &wiphy->iface_combinations[i]; 1296 1297 nl_combi = nla_nest_start_noflag(msg, i + 1); 1298 if (!nl_combi) 1299 goto nla_put_failure; 1300 1301 nl_limits = nla_nest_start_noflag(msg, 1302 NL80211_IFACE_COMB_LIMITS); 1303 if (!nl_limits) 1304 goto nla_put_failure; 1305 1306 for (j = 0; j < c->n_limits; j++) { 1307 struct nlattr *nl_limit; 1308 1309 nl_limit = nla_nest_start_noflag(msg, j + 1); 1310 if (!nl_limit) 1311 goto nla_put_failure; 1312 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1313 c->limits[j].max)) 1314 goto nla_put_failure; 1315 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, 1316 c->limits[j].types)) 1317 goto nla_put_failure; 1318 nla_nest_end(msg, nl_limit); 1319 } 1320 1321 nla_nest_end(msg, nl_limits); 1322 1323 if (c->beacon_int_infra_match && 1324 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) 1325 goto nla_put_failure; 1326 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, 1327 c->num_different_channels) || 1328 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 1329 c->max_interfaces)) 1330 goto nla_put_failure; 1331 if (large && 1332 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, 1333 c->radar_detect_widths) || 1334 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, 1335 c->radar_detect_regions))) 1336 goto nla_put_failure; 1337 if (c->beacon_int_min_gcd && 1338 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, 1339 c->beacon_int_min_gcd)) 1340 goto nla_put_failure; 1341 1342 nla_nest_end(msg, nl_combi); 1343 } 1344 1345 nla_nest_end(msg, nl_combis); 1346 1347 return 0; 1348 nla_put_failure: 1349 return -ENOBUFS; 1350 } 1351 1352 #ifdef CONFIG_PM 1353 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, 1354 struct sk_buff *msg) 1355 { 1356 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; 1357 struct nlattr *nl_tcp; 1358 1359 if (!tcp) 1360 return 0; 1361 1362 nl_tcp = nla_nest_start_noflag(msg, 1363 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1364 if (!nl_tcp) 1365 return -ENOBUFS; 1366 1367 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1368 tcp->data_payload_max)) 1369 return -ENOBUFS; 1370 1371 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1372 tcp->data_payload_max)) 1373 return -ENOBUFS; 1374 1375 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) 1376 return -ENOBUFS; 1377 1378 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 1379 sizeof(*tcp->tok), tcp->tok)) 1380 return -ENOBUFS; 1381 1382 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 1383 tcp->data_interval_max)) 1384 return -ENOBUFS; 1385 1386 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 1387 tcp->wake_payload_max)) 1388 return -ENOBUFS; 1389 1390 nla_nest_end(msg, nl_tcp); 1391 return 0; 1392 } 1393 1394 static int nl80211_send_wowlan(struct sk_buff *msg, 1395 struct cfg80211_registered_device *rdev, 1396 bool large) 1397 { 1398 struct nlattr *nl_wowlan; 1399 1400 if (!rdev->wiphy.wowlan) 1401 return 0; 1402 1403 nl_wowlan = nla_nest_start_noflag(msg, 1404 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1405 if (!nl_wowlan) 1406 return -ENOBUFS; 1407 1408 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && 1409 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 1410 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && 1411 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 1412 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && 1413 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 1414 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && 1415 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || 1416 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 1417 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 1418 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && 1419 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 1420 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && 1421 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 1422 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && 1423 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 1424 return -ENOBUFS; 1425 1426 if (rdev->wiphy.wowlan->n_patterns) { 1427 struct nl80211_pattern_support pat = { 1428 .max_patterns = rdev->wiphy.wowlan->n_patterns, 1429 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, 1430 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, 1431 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, 1432 }; 1433 1434 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 1435 sizeof(pat), &pat)) 1436 return -ENOBUFS; 1437 } 1438 1439 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && 1440 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, 1441 rdev->wiphy.wowlan->max_nd_match_sets)) 1442 return -ENOBUFS; 1443 1444 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) 1445 return -ENOBUFS; 1446 1447 nla_nest_end(msg, nl_wowlan); 1448 1449 return 0; 1450 } 1451 #endif 1452 1453 static int nl80211_send_coalesce(struct sk_buff *msg, 1454 struct cfg80211_registered_device *rdev) 1455 { 1456 struct nl80211_coalesce_rule_support rule; 1457 1458 if (!rdev->wiphy.coalesce) 1459 return 0; 1460 1461 rule.max_rules = rdev->wiphy.coalesce->n_rules; 1462 rule.max_delay = rdev->wiphy.coalesce->max_delay; 1463 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; 1464 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; 1465 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; 1466 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; 1467 1468 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) 1469 return -ENOBUFS; 1470 1471 return 0; 1472 } 1473 1474 static int 1475 nl80211_send_iftype_data(struct sk_buff *msg, 1476 const struct ieee80211_sband_iftype_data *iftdata) 1477 { 1478 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; 1479 1480 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, 1481 iftdata->types_mask)) 1482 return -ENOBUFS; 1483 1484 if (he_cap->has_he) { 1485 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, 1486 sizeof(he_cap->he_cap_elem.mac_cap_info), 1487 he_cap->he_cap_elem.mac_cap_info) || 1488 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, 1489 sizeof(he_cap->he_cap_elem.phy_cap_info), 1490 he_cap->he_cap_elem.phy_cap_info) || 1491 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, 1492 sizeof(he_cap->he_mcs_nss_supp), 1493 &he_cap->he_mcs_nss_supp) || 1494 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, 1495 sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) 1496 return -ENOBUFS; 1497 } 1498 1499 return 0; 1500 } 1501 1502 static int nl80211_send_band_rateinfo(struct sk_buff *msg, 1503 struct ieee80211_supported_band *sband) 1504 { 1505 struct nlattr *nl_rates, *nl_rate; 1506 struct ieee80211_rate *rate; 1507 int i; 1508 1509 /* add HT info */ 1510 if (sband->ht_cap.ht_supported && 1511 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, 1512 sizeof(sband->ht_cap.mcs), 1513 &sband->ht_cap.mcs) || 1514 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, 1515 sband->ht_cap.cap) || 1516 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, 1517 sband->ht_cap.ampdu_factor) || 1518 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, 1519 sband->ht_cap.ampdu_density))) 1520 return -ENOBUFS; 1521 1522 /* add VHT info */ 1523 if (sband->vht_cap.vht_supported && 1524 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, 1525 sizeof(sband->vht_cap.vht_mcs), 1526 &sband->vht_cap.vht_mcs) || 1527 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, 1528 sband->vht_cap.cap))) 1529 return -ENOBUFS; 1530 1531 if (sband->n_iftype_data) { 1532 struct nlattr *nl_iftype_data = 1533 nla_nest_start_noflag(msg, 1534 NL80211_BAND_ATTR_IFTYPE_DATA); 1535 int err; 1536 1537 if (!nl_iftype_data) 1538 return -ENOBUFS; 1539 1540 for (i = 0; i < sband->n_iftype_data; i++) { 1541 struct nlattr *iftdata; 1542 1543 iftdata = nla_nest_start_noflag(msg, i + 1); 1544 if (!iftdata) 1545 return -ENOBUFS; 1546 1547 err = nl80211_send_iftype_data(msg, 1548 &sband->iftype_data[i]); 1549 if (err) 1550 return err; 1551 1552 nla_nest_end(msg, iftdata); 1553 } 1554 1555 nla_nest_end(msg, nl_iftype_data); 1556 } 1557 1558 /* add bitrates */ 1559 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); 1560 if (!nl_rates) 1561 return -ENOBUFS; 1562 1563 for (i = 0; i < sband->n_bitrates; i++) { 1564 nl_rate = nla_nest_start_noflag(msg, i); 1565 if (!nl_rate) 1566 return -ENOBUFS; 1567 1568 rate = &sband->bitrates[i]; 1569 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, 1570 rate->bitrate)) 1571 return -ENOBUFS; 1572 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && 1573 nla_put_flag(msg, 1574 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) 1575 return -ENOBUFS; 1576 1577 nla_nest_end(msg, nl_rate); 1578 } 1579 1580 nla_nest_end(msg, nl_rates); 1581 1582 return 0; 1583 } 1584 1585 static int 1586 nl80211_send_mgmt_stypes(struct sk_buff *msg, 1587 const struct ieee80211_txrx_stypes *mgmt_stypes) 1588 { 1589 u16 stypes; 1590 struct nlattr *nl_ftypes, *nl_ifs; 1591 enum nl80211_iftype ift; 1592 int i; 1593 1594 if (!mgmt_stypes) 1595 return 0; 1596 1597 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); 1598 if (!nl_ifs) 1599 return -ENOBUFS; 1600 1601 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1602 nl_ftypes = nla_nest_start_noflag(msg, ift); 1603 if (!nl_ftypes) 1604 return -ENOBUFS; 1605 i = 0; 1606 stypes = mgmt_stypes[ift].tx; 1607 while (stypes) { 1608 if ((stypes & 1) && 1609 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1610 (i << 4) | IEEE80211_FTYPE_MGMT)) 1611 return -ENOBUFS; 1612 stypes >>= 1; 1613 i++; 1614 } 1615 nla_nest_end(msg, nl_ftypes); 1616 } 1617 1618 nla_nest_end(msg, nl_ifs); 1619 1620 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); 1621 if (!nl_ifs) 1622 return -ENOBUFS; 1623 1624 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1625 nl_ftypes = nla_nest_start_noflag(msg, ift); 1626 if (!nl_ftypes) 1627 return -ENOBUFS; 1628 i = 0; 1629 stypes = mgmt_stypes[ift].rx; 1630 while (stypes) { 1631 if ((stypes & 1) && 1632 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 1633 (i << 4) | IEEE80211_FTYPE_MGMT)) 1634 return -ENOBUFS; 1635 stypes >>= 1; 1636 i++; 1637 } 1638 nla_nest_end(msg, nl_ftypes); 1639 } 1640 nla_nest_end(msg, nl_ifs); 1641 1642 return 0; 1643 } 1644 1645 #define CMD(op, n) \ 1646 do { \ 1647 if (rdev->ops->op) { \ 1648 i++; \ 1649 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ 1650 goto nla_put_failure; \ 1651 } \ 1652 } while (0) 1653 1654 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, 1655 struct sk_buff *msg) 1656 { 1657 int i = 0; 1658 1659 /* 1660 * do *NOT* add anything into this function, new things need to be 1661 * advertised only to new versions of userspace that can deal with 1662 * the split (and they can't possibly care about new features... 1663 */ 1664 CMD(add_virtual_intf, NEW_INTERFACE); 1665 CMD(change_virtual_intf, SET_INTERFACE); 1666 CMD(add_key, NEW_KEY); 1667 CMD(start_ap, START_AP); 1668 CMD(add_station, NEW_STATION); 1669 CMD(add_mpath, NEW_MPATH); 1670 CMD(update_mesh_config, SET_MESH_CONFIG); 1671 CMD(change_bss, SET_BSS); 1672 CMD(auth, AUTHENTICATE); 1673 CMD(assoc, ASSOCIATE); 1674 CMD(deauth, DEAUTHENTICATE); 1675 CMD(disassoc, DISASSOCIATE); 1676 CMD(join_ibss, JOIN_IBSS); 1677 CMD(join_mesh, JOIN_MESH); 1678 CMD(set_pmksa, SET_PMKSA); 1679 CMD(del_pmksa, DEL_PMKSA); 1680 CMD(flush_pmksa, FLUSH_PMKSA); 1681 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) 1682 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 1683 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 1684 CMD(mgmt_tx, FRAME); 1685 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); 1686 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 1687 i++; 1688 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 1689 goto nla_put_failure; 1690 } 1691 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || 1692 rdev->ops->join_mesh) { 1693 i++; 1694 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) 1695 goto nla_put_failure; 1696 } 1697 CMD(set_wds_peer, SET_WDS_PEER); 1698 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 1699 CMD(tdls_mgmt, TDLS_MGMT); 1700 CMD(tdls_oper, TDLS_OPER); 1701 } 1702 if (rdev->wiphy.max_sched_scan_reqs) 1703 CMD(sched_scan_start, START_SCHED_SCAN); 1704 CMD(probe_client, PROBE_CLIENT); 1705 CMD(set_noack_map, SET_NOACK_MAP); 1706 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { 1707 i++; 1708 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) 1709 goto nla_put_failure; 1710 } 1711 CMD(start_p2p_device, START_P2P_DEVICE); 1712 CMD(set_mcast_rate, SET_MCAST_RATE); 1713 #ifdef CONFIG_NL80211_TESTMODE 1714 CMD(testmode_cmd, TESTMODE); 1715 #endif 1716 1717 if (rdev->ops->connect || rdev->ops->auth) { 1718 i++; 1719 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) 1720 goto nla_put_failure; 1721 } 1722 1723 if (rdev->ops->disconnect || rdev->ops->deauth) { 1724 i++; 1725 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) 1726 goto nla_put_failure; 1727 } 1728 1729 return i; 1730 nla_put_failure: 1731 return -ENOBUFS; 1732 } 1733 1734 static int 1735 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, 1736 struct sk_buff *msg) 1737 { 1738 struct nlattr *ftm; 1739 1740 if (!cap->ftm.supported) 1741 return 0; 1742 1743 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); 1744 if (!ftm) 1745 return -ENOBUFS; 1746 1747 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) 1748 return -ENOBUFS; 1749 if (cap->ftm.non_asap && 1750 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) 1751 return -ENOBUFS; 1752 if (cap->ftm.request_lci && 1753 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) 1754 return -ENOBUFS; 1755 if (cap->ftm.request_civicloc && 1756 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) 1757 return -ENOBUFS; 1758 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, 1759 cap->ftm.preambles)) 1760 return -ENOBUFS; 1761 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, 1762 cap->ftm.bandwidths)) 1763 return -ENOBUFS; 1764 if (cap->ftm.max_bursts_exponent >= 0 && 1765 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, 1766 cap->ftm.max_bursts_exponent)) 1767 return -ENOBUFS; 1768 if (cap->ftm.max_ftms_per_burst && 1769 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, 1770 cap->ftm.max_ftms_per_burst)) 1771 return -ENOBUFS; 1772 1773 nla_nest_end(msg, ftm); 1774 return 0; 1775 } 1776 1777 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, 1778 struct sk_buff *msg) 1779 { 1780 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; 1781 struct nlattr *pmsr, *caps; 1782 1783 if (!cap) 1784 return 0; 1785 1786 /* 1787 * we don't need to clean up anything here since the caller 1788 * will genlmsg_cancel() if we fail 1789 */ 1790 1791 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 1792 if (!pmsr) 1793 return -ENOBUFS; 1794 1795 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) 1796 return -ENOBUFS; 1797 1798 if (cap->report_ap_tsf && 1799 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) 1800 return -ENOBUFS; 1801 1802 if (cap->randomize_mac_addr && 1803 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 1804 return -ENOBUFS; 1805 1806 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 1807 if (!caps) 1808 return -ENOBUFS; 1809 1810 if (nl80211_send_pmsr_ftm_capa(cap, msg)) 1811 return -ENOBUFS; 1812 1813 nla_nest_end(msg, caps); 1814 nla_nest_end(msg, pmsr); 1815 1816 return 0; 1817 } 1818 1819 struct nl80211_dump_wiphy_state { 1820 s64 filter_wiphy; 1821 long start; 1822 long split_start, band_start, chan_start, capa_start; 1823 bool split; 1824 }; 1825 1826 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 1827 enum nl80211_commands cmd, 1828 struct sk_buff *msg, u32 portid, u32 seq, 1829 int flags, struct nl80211_dump_wiphy_state *state) 1830 { 1831 void *hdr; 1832 struct nlattr *nl_bands, *nl_band; 1833 struct nlattr *nl_freqs, *nl_freq; 1834 struct nlattr *nl_cmds; 1835 enum nl80211_band band; 1836 struct ieee80211_channel *chan; 1837 int i; 1838 const struct ieee80211_txrx_stypes *mgmt_stypes = 1839 rdev->wiphy.mgmt_stypes; 1840 u32 features; 1841 1842 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 1843 if (!hdr) 1844 return -ENOBUFS; 1845 1846 if (WARN_ON(!state)) 1847 return -EINVAL; 1848 1849 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 1850 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, 1851 wiphy_name(&rdev->wiphy)) || 1852 nla_put_u32(msg, NL80211_ATTR_GENERATION, 1853 cfg80211_rdev_list_generation)) 1854 goto nla_put_failure; 1855 1856 if (cmd != NL80211_CMD_NEW_WIPHY) 1857 goto finish; 1858 1859 switch (state->split_start) { 1860 case 0: 1861 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 1862 rdev->wiphy.retry_short) || 1863 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, 1864 rdev->wiphy.retry_long) || 1865 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, 1866 rdev->wiphy.frag_threshold) || 1867 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 1868 rdev->wiphy.rts_threshold) || 1869 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 1870 rdev->wiphy.coverage_class) || 1871 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 1872 rdev->wiphy.max_scan_ssids) || 1873 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, 1874 rdev->wiphy.max_sched_scan_ssids) || 1875 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 1876 rdev->wiphy.max_scan_ie_len) || 1877 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, 1878 rdev->wiphy.max_sched_scan_ie_len) || 1879 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, 1880 rdev->wiphy.max_match_sets) || 1881 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, 1882 rdev->wiphy.max_sched_scan_plans) || 1883 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, 1884 rdev->wiphy.max_sched_scan_plan_interval) || 1885 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, 1886 rdev->wiphy.max_sched_scan_plan_iterations)) 1887 goto nla_put_failure; 1888 1889 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && 1890 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) 1891 goto nla_put_failure; 1892 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && 1893 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) 1894 goto nla_put_failure; 1895 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && 1896 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) 1897 goto nla_put_failure; 1898 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 1899 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) 1900 goto nla_put_failure; 1901 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && 1902 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) 1903 goto nla_put_failure; 1904 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && 1905 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) 1906 goto nla_put_failure; 1907 state->split_start++; 1908 if (state->split) 1909 break; 1910 /* fall through */ 1911 case 1: 1912 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, 1913 sizeof(u32) * rdev->wiphy.n_cipher_suites, 1914 rdev->wiphy.cipher_suites)) 1915 goto nla_put_failure; 1916 1917 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 1918 rdev->wiphy.max_num_pmkids)) 1919 goto nla_put_failure; 1920 1921 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 1922 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) 1923 goto nla_put_failure; 1924 1925 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, 1926 rdev->wiphy.available_antennas_tx) || 1927 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, 1928 rdev->wiphy.available_antennas_rx)) 1929 goto nla_put_failure; 1930 1931 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && 1932 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, 1933 rdev->wiphy.probe_resp_offload)) 1934 goto nla_put_failure; 1935 1936 if ((rdev->wiphy.available_antennas_tx || 1937 rdev->wiphy.available_antennas_rx) && 1938 rdev->ops->get_antenna) { 1939 u32 tx_ant = 0, rx_ant = 0; 1940 int res; 1941 1942 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); 1943 if (!res) { 1944 if (nla_put_u32(msg, 1945 NL80211_ATTR_WIPHY_ANTENNA_TX, 1946 tx_ant) || 1947 nla_put_u32(msg, 1948 NL80211_ATTR_WIPHY_ANTENNA_RX, 1949 rx_ant)) 1950 goto nla_put_failure; 1951 } 1952 } 1953 1954 state->split_start++; 1955 if (state->split) 1956 break; 1957 /* fall through */ 1958 case 2: 1959 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, 1960 rdev->wiphy.interface_modes)) 1961 goto nla_put_failure; 1962 state->split_start++; 1963 if (state->split) 1964 break; 1965 /* fall through */ 1966 case 3: 1967 nl_bands = nla_nest_start_noflag(msg, 1968 NL80211_ATTR_WIPHY_BANDS); 1969 if (!nl_bands) 1970 goto nla_put_failure; 1971 1972 for (band = state->band_start; 1973 band < NUM_NL80211_BANDS; band++) { 1974 struct ieee80211_supported_band *sband; 1975 1976 sband = rdev->wiphy.bands[band]; 1977 1978 if (!sband) 1979 continue; 1980 1981 nl_band = nla_nest_start_noflag(msg, band); 1982 if (!nl_band) 1983 goto nla_put_failure; 1984 1985 switch (state->chan_start) { 1986 case 0: 1987 if (nl80211_send_band_rateinfo(msg, sband)) 1988 goto nla_put_failure; 1989 state->chan_start++; 1990 if (state->split) 1991 break; 1992 /* fall through */ 1993 default: 1994 /* add frequencies */ 1995 nl_freqs = nla_nest_start_noflag(msg, 1996 NL80211_BAND_ATTR_FREQS); 1997 if (!nl_freqs) 1998 goto nla_put_failure; 1999 2000 for (i = state->chan_start - 1; 2001 i < sband->n_channels; 2002 i++) { 2003 nl_freq = nla_nest_start_noflag(msg, 2004 i); 2005 if (!nl_freq) 2006 goto nla_put_failure; 2007 2008 chan = &sband->channels[i]; 2009 2010 if (nl80211_msg_put_channel( 2011 msg, &rdev->wiphy, chan, 2012 state->split)) 2013 goto nla_put_failure; 2014 2015 nla_nest_end(msg, nl_freq); 2016 if (state->split) 2017 break; 2018 } 2019 if (i < sband->n_channels) 2020 state->chan_start = i + 2; 2021 else 2022 state->chan_start = 0; 2023 nla_nest_end(msg, nl_freqs); 2024 } 2025 2026 nla_nest_end(msg, nl_band); 2027 2028 if (state->split) { 2029 /* start again here */ 2030 if (state->chan_start) 2031 band--; 2032 break; 2033 } 2034 } 2035 nla_nest_end(msg, nl_bands); 2036 2037 if (band < NUM_NL80211_BANDS) 2038 state->band_start = band + 1; 2039 else 2040 state->band_start = 0; 2041 2042 /* if bands & channels are done, continue outside */ 2043 if (state->band_start == 0 && state->chan_start == 0) 2044 state->split_start++; 2045 if (state->split) 2046 break; 2047 /* fall through */ 2048 case 4: 2049 nl_cmds = nla_nest_start_noflag(msg, 2050 NL80211_ATTR_SUPPORTED_COMMANDS); 2051 if (!nl_cmds) 2052 goto nla_put_failure; 2053 2054 i = nl80211_add_commands_unsplit(rdev, msg); 2055 if (i < 0) 2056 goto nla_put_failure; 2057 if (state->split) { 2058 CMD(crit_proto_start, CRIT_PROTOCOL_START); 2059 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); 2060 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 2061 CMD(channel_switch, CHANNEL_SWITCH); 2062 CMD(set_qos_map, SET_QOS_MAP); 2063 if (rdev->wiphy.features & 2064 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 2065 CMD(add_tx_ts, ADD_TX_TS); 2066 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); 2067 CMD(update_connect_params, UPDATE_CONNECT_PARAMS); 2068 } 2069 #undef CMD 2070 2071 nla_nest_end(msg, nl_cmds); 2072 state->split_start++; 2073 if (state->split) 2074 break; 2075 /* fall through */ 2076 case 5: 2077 if (rdev->ops->remain_on_channel && 2078 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && 2079 nla_put_u32(msg, 2080 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, 2081 rdev->wiphy.max_remain_on_channel_duration)) 2082 goto nla_put_failure; 2083 2084 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && 2085 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) 2086 goto nla_put_failure; 2087 2088 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) 2089 goto nla_put_failure; 2090 state->split_start++; 2091 if (state->split) 2092 break; 2093 /* fall through */ 2094 case 6: 2095 #ifdef CONFIG_PM 2096 if (nl80211_send_wowlan(msg, rdev, state->split)) 2097 goto nla_put_failure; 2098 state->split_start++; 2099 if (state->split) 2100 break; 2101 #else 2102 state->split_start++; 2103 #endif 2104 /* fall through */ 2105 case 7: 2106 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, 2107 rdev->wiphy.software_iftypes)) 2108 goto nla_put_failure; 2109 2110 if (nl80211_put_iface_combinations(&rdev->wiphy, msg, 2111 state->split)) 2112 goto nla_put_failure; 2113 2114 state->split_start++; 2115 if (state->split) 2116 break; 2117 /* fall through */ 2118 case 8: 2119 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && 2120 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, 2121 rdev->wiphy.ap_sme_capa)) 2122 goto nla_put_failure; 2123 2124 features = rdev->wiphy.features; 2125 /* 2126 * We can only add the per-channel limit information if the 2127 * dump is split, otherwise it makes it too big. Therefore 2128 * only advertise it in that case. 2129 */ 2130 if (state->split) 2131 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; 2132 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) 2133 goto nla_put_failure; 2134 2135 if (rdev->wiphy.ht_capa_mod_mask && 2136 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, 2137 sizeof(*rdev->wiphy.ht_capa_mod_mask), 2138 rdev->wiphy.ht_capa_mod_mask)) 2139 goto nla_put_failure; 2140 2141 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && 2142 rdev->wiphy.max_acl_mac_addrs && 2143 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, 2144 rdev->wiphy.max_acl_mac_addrs)) 2145 goto nla_put_failure; 2146 2147 /* 2148 * Any information below this point is only available to 2149 * applications that can deal with it being split. This 2150 * helps ensure that newly added capabilities don't break 2151 * older tools by overrunning their buffers. 2152 * 2153 * We still increment split_start so that in the split 2154 * case we'll continue with more data in the next round, 2155 * but break unconditionally so unsplit data stops here. 2156 */ 2157 state->split_start++; 2158 break; 2159 case 9: 2160 if (rdev->wiphy.extended_capabilities && 2161 (nla_put(msg, NL80211_ATTR_EXT_CAPA, 2162 rdev->wiphy.extended_capabilities_len, 2163 rdev->wiphy.extended_capabilities) || 2164 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2165 rdev->wiphy.extended_capabilities_len, 2166 rdev->wiphy.extended_capabilities_mask))) 2167 goto nla_put_failure; 2168 2169 if (rdev->wiphy.vht_capa_mod_mask && 2170 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, 2171 sizeof(*rdev->wiphy.vht_capa_mod_mask), 2172 rdev->wiphy.vht_capa_mod_mask)) 2173 goto nla_put_failure; 2174 2175 state->split_start++; 2176 break; 2177 case 10: 2178 if (nl80211_send_coalesce(msg, rdev)) 2179 goto nla_put_failure; 2180 2181 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && 2182 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || 2183 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) 2184 goto nla_put_failure; 2185 2186 if (rdev->wiphy.max_ap_assoc_sta && 2187 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, 2188 rdev->wiphy.max_ap_assoc_sta)) 2189 goto nla_put_failure; 2190 2191 state->split_start++; 2192 break; 2193 case 11: 2194 if (rdev->wiphy.n_vendor_commands) { 2195 const struct nl80211_vendor_cmd_info *info; 2196 struct nlattr *nested; 2197 2198 nested = nla_nest_start_noflag(msg, 2199 NL80211_ATTR_VENDOR_DATA); 2200 if (!nested) 2201 goto nla_put_failure; 2202 2203 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 2204 info = &rdev->wiphy.vendor_commands[i].info; 2205 if (nla_put(msg, i + 1, sizeof(*info), info)) 2206 goto nla_put_failure; 2207 } 2208 nla_nest_end(msg, nested); 2209 } 2210 2211 if (rdev->wiphy.n_vendor_events) { 2212 const struct nl80211_vendor_cmd_info *info; 2213 struct nlattr *nested; 2214 2215 nested = nla_nest_start_noflag(msg, 2216 NL80211_ATTR_VENDOR_EVENTS); 2217 if (!nested) 2218 goto nla_put_failure; 2219 2220 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { 2221 info = &rdev->wiphy.vendor_events[i]; 2222 if (nla_put(msg, i + 1, sizeof(*info), info)) 2223 goto nla_put_failure; 2224 } 2225 nla_nest_end(msg, nested); 2226 } 2227 state->split_start++; 2228 break; 2229 case 12: 2230 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && 2231 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, 2232 rdev->wiphy.max_num_csa_counters)) 2233 goto nla_put_failure; 2234 2235 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 2236 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 2237 goto nla_put_failure; 2238 2239 if (rdev->wiphy.max_sched_scan_reqs && 2240 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, 2241 rdev->wiphy.max_sched_scan_reqs)) 2242 goto nla_put_failure; 2243 2244 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, 2245 sizeof(rdev->wiphy.ext_features), 2246 rdev->wiphy.ext_features)) 2247 goto nla_put_failure; 2248 2249 if (rdev->wiphy.bss_select_support) { 2250 struct nlattr *nested; 2251 u32 bss_select_support = rdev->wiphy.bss_select_support; 2252 2253 nested = nla_nest_start_noflag(msg, 2254 NL80211_ATTR_BSS_SELECT); 2255 if (!nested) 2256 goto nla_put_failure; 2257 2258 i = 0; 2259 while (bss_select_support) { 2260 if ((bss_select_support & 1) && 2261 nla_put_flag(msg, i)) 2262 goto nla_put_failure; 2263 i++; 2264 bss_select_support >>= 1; 2265 } 2266 nla_nest_end(msg, nested); 2267 } 2268 2269 state->split_start++; 2270 break; 2271 case 13: 2272 if (rdev->wiphy.num_iftype_ext_capab && 2273 rdev->wiphy.iftype_ext_capab) { 2274 struct nlattr *nested_ext_capab, *nested; 2275 2276 nested = nla_nest_start_noflag(msg, 2277 NL80211_ATTR_IFTYPE_EXT_CAPA); 2278 if (!nested) 2279 goto nla_put_failure; 2280 2281 for (i = state->capa_start; 2282 i < rdev->wiphy.num_iftype_ext_capab; i++) { 2283 const struct wiphy_iftype_ext_capab *capab; 2284 2285 capab = &rdev->wiphy.iftype_ext_capab[i]; 2286 2287 nested_ext_capab = nla_nest_start_noflag(msg, 2288 i); 2289 if (!nested_ext_capab || 2290 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2291 capab->iftype) || 2292 nla_put(msg, NL80211_ATTR_EXT_CAPA, 2293 capab->extended_capabilities_len, 2294 capab->extended_capabilities) || 2295 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2296 capab->extended_capabilities_len, 2297 capab->extended_capabilities_mask)) 2298 goto nla_put_failure; 2299 2300 nla_nest_end(msg, nested_ext_capab); 2301 if (state->split) 2302 break; 2303 } 2304 nla_nest_end(msg, nested); 2305 if (i < rdev->wiphy.num_iftype_ext_capab) { 2306 state->capa_start = i + 1; 2307 break; 2308 } 2309 } 2310 2311 if (nla_put_u32(msg, NL80211_ATTR_BANDS, 2312 rdev->wiphy.nan_supported_bands)) 2313 goto nla_put_failure; 2314 2315 if (wiphy_ext_feature_isset(&rdev->wiphy, 2316 NL80211_EXT_FEATURE_TXQS)) { 2317 struct cfg80211_txq_stats txqstats = {}; 2318 int res; 2319 2320 res = rdev_get_txq_stats(rdev, NULL, &txqstats); 2321 if (!res && 2322 !nl80211_put_txq_stats(msg, &txqstats, 2323 NL80211_ATTR_TXQ_STATS)) 2324 goto nla_put_failure; 2325 2326 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, 2327 rdev->wiphy.txq_limit)) 2328 goto nla_put_failure; 2329 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, 2330 rdev->wiphy.txq_memory_limit)) 2331 goto nla_put_failure; 2332 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, 2333 rdev->wiphy.txq_quantum)) 2334 goto nla_put_failure; 2335 } 2336 2337 state->split_start++; 2338 break; 2339 case 14: 2340 if (nl80211_send_pmsr_capa(rdev, msg)) 2341 goto nla_put_failure; 2342 2343 state->split_start++; 2344 break; 2345 case 15: 2346 if (rdev->wiphy.akm_suites && 2347 nla_put(msg, NL80211_ATTR_AKM_SUITES, 2348 sizeof(u32) * rdev->wiphy.n_akm_suites, 2349 rdev->wiphy.akm_suites)) 2350 goto nla_put_failure; 2351 2352 /* done */ 2353 state->split_start = 0; 2354 break; 2355 } 2356 finish: 2357 genlmsg_end(msg, hdr); 2358 return 0; 2359 2360 nla_put_failure: 2361 genlmsg_cancel(msg, hdr); 2362 return -EMSGSIZE; 2363 } 2364 2365 static int nl80211_dump_wiphy_parse(struct sk_buff *skb, 2366 struct netlink_callback *cb, 2367 struct nl80211_dump_wiphy_state *state) 2368 { 2369 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); 2370 int ret = nlmsg_parse_deprecated(cb->nlh, 2371 GENL_HDRLEN + nl80211_fam.hdrsize, 2372 tb, nl80211_fam.maxattr, 2373 nl80211_policy, NULL); 2374 /* ignore parse errors for backward compatibility */ 2375 if (ret) 2376 return 0; 2377 2378 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; 2379 if (tb[NL80211_ATTR_WIPHY]) 2380 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 2381 if (tb[NL80211_ATTR_WDEV]) 2382 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; 2383 if (tb[NL80211_ATTR_IFINDEX]) { 2384 struct net_device *netdev; 2385 struct cfg80211_registered_device *rdev; 2386 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); 2387 2388 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); 2389 if (!netdev) 2390 return -ENODEV; 2391 if (netdev->ieee80211_ptr) { 2392 rdev = wiphy_to_rdev( 2393 netdev->ieee80211_ptr->wiphy); 2394 state->filter_wiphy = rdev->wiphy_idx; 2395 } 2396 } 2397 2398 return 0; 2399 } 2400 2401 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) 2402 { 2403 int idx = 0, ret; 2404 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; 2405 struct cfg80211_registered_device *rdev; 2406 2407 rtnl_lock(); 2408 if (!state) { 2409 state = kzalloc(sizeof(*state), GFP_KERNEL); 2410 if (!state) { 2411 rtnl_unlock(); 2412 return -ENOMEM; 2413 } 2414 state->filter_wiphy = -1; 2415 ret = nl80211_dump_wiphy_parse(skb, cb, state); 2416 if (ret) { 2417 kfree(state); 2418 rtnl_unlock(); 2419 return ret; 2420 } 2421 cb->args[0] = (long)state; 2422 } 2423 2424 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 2425 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 2426 continue; 2427 if (++idx <= state->start) 2428 continue; 2429 if (state->filter_wiphy != -1 && 2430 state->filter_wiphy != rdev->wiphy_idx) 2431 continue; 2432 /* attempt to fit multiple wiphy data chunks into the skb */ 2433 do { 2434 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, 2435 skb, 2436 NETLINK_CB(cb->skb).portid, 2437 cb->nlh->nlmsg_seq, 2438 NLM_F_MULTI, state); 2439 if (ret < 0) { 2440 /* 2441 * If sending the wiphy data didn't fit (ENOBUFS 2442 * or EMSGSIZE returned), this SKB is still 2443 * empty (so it's not too big because another 2444 * wiphy dataset is already in the skb) and 2445 * we've not tried to adjust the dump allocation 2446 * yet ... then adjust the alloc size to be 2447 * bigger, and return 1 but with the empty skb. 2448 * This results in an empty message being RX'ed 2449 * in userspace, but that is ignored. 2450 * 2451 * We can then retry with the larger buffer. 2452 */ 2453 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 2454 !skb->len && !state->split && 2455 cb->min_dump_alloc < 4096) { 2456 cb->min_dump_alloc = 4096; 2457 state->split_start = 0; 2458 rtnl_unlock(); 2459 return 1; 2460 } 2461 idx--; 2462 break; 2463 } 2464 } while (state->split_start > 0); 2465 break; 2466 } 2467 rtnl_unlock(); 2468 2469 state->start = idx; 2470 2471 return skb->len; 2472 } 2473 2474 static int nl80211_dump_wiphy_done(struct netlink_callback *cb) 2475 { 2476 kfree((void *)cb->args[0]); 2477 return 0; 2478 } 2479 2480 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 2481 { 2482 struct sk_buff *msg; 2483 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2484 struct nl80211_dump_wiphy_state state = {}; 2485 2486 msg = nlmsg_new(4096, GFP_KERNEL); 2487 if (!msg) 2488 return -ENOMEM; 2489 2490 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, 2491 info->snd_portid, info->snd_seq, 0, 2492 &state) < 0) { 2493 nlmsg_free(msg); 2494 return -ENOBUFS; 2495 } 2496 2497 return genlmsg_reply(msg, info); 2498 } 2499 2500 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 2501 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, 2502 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, 2503 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, 2504 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, 2505 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, 2506 }; 2507 2508 static int parse_txq_params(struct nlattr *tb[], 2509 struct ieee80211_txq_params *txq_params) 2510 { 2511 u8 ac; 2512 2513 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || 2514 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || 2515 !tb[NL80211_TXQ_ATTR_AIFS]) 2516 return -EINVAL; 2517 2518 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); 2519 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); 2520 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); 2521 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); 2522 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); 2523 2524 if (ac >= NL80211_NUM_ACS) 2525 return -EINVAL; 2526 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); 2527 return 0; 2528 } 2529 2530 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 2531 { 2532 /* 2533 * You can only set the channel explicitly for WDS interfaces, 2534 * all others have their channel managed via their respective 2535 * "establish a connection" command (connect, join, ...) 2536 * 2537 * For AP/GO and mesh mode, the channel can be set with the 2538 * channel userspace API, but is only stored and passed to the 2539 * low-level driver when the AP starts or the mesh is joined. 2540 * This is for backward compatibility, userspace can also give 2541 * the channel in the start-ap or join-mesh commands instead. 2542 * 2543 * Monitors are special as they are normally slaved to 2544 * whatever else is going on, so they have their own special 2545 * operation to set the monitor channel if possible. 2546 */ 2547 return !wdev || 2548 wdev->iftype == NL80211_IFTYPE_AP || 2549 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 2550 wdev->iftype == NL80211_IFTYPE_MONITOR || 2551 wdev->iftype == NL80211_IFTYPE_P2P_GO; 2552 } 2553 2554 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, 2555 struct genl_info *info, 2556 struct cfg80211_chan_def *chandef) 2557 { 2558 struct netlink_ext_ack *extack = info->extack; 2559 struct nlattr **attrs = info->attrs; 2560 u32 control_freq; 2561 2562 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) 2563 return -EINVAL; 2564 2565 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]); 2566 2567 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); 2568 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 2569 chandef->center_freq1 = control_freq; 2570 chandef->center_freq2 = 0; 2571 2572 /* Primary channel not allowed */ 2573 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { 2574 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 2575 "Channel is disabled"); 2576 return -EINVAL; 2577 } 2578 2579 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 2580 enum nl80211_channel_type chantype; 2581 2582 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); 2583 2584 switch (chantype) { 2585 case NL80211_CHAN_NO_HT: 2586 case NL80211_CHAN_HT20: 2587 case NL80211_CHAN_HT40PLUS: 2588 case NL80211_CHAN_HT40MINUS: 2589 cfg80211_chandef_create(chandef, chandef->chan, 2590 chantype); 2591 /* user input for center_freq is incorrect */ 2592 if (attrs[NL80211_ATTR_CENTER_FREQ1] && 2593 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { 2594 NL_SET_ERR_MSG_ATTR(extack, 2595 attrs[NL80211_ATTR_CENTER_FREQ1], 2596 "bad center frequency 1"); 2597 return -EINVAL; 2598 } 2599 /* center_freq2 must be zero */ 2600 if (attrs[NL80211_ATTR_CENTER_FREQ2] && 2601 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { 2602 NL_SET_ERR_MSG_ATTR(extack, 2603 attrs[NL80211_ATTR_CENTER_FREQ2], 2604 "center frequency 2 can't be used"); 2605 return -EINVAL; 2606 } 2607 break; 2608 default: 2609 NL_SET_ERR_MSG_ATTR(extack, 2610 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], 2611 "invalid channel type"); 2612 return -EINVAL; 2613 } 2614 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { 2615 chandef->width = 2616 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); 2617 if (attrs[NL80211_ATTR_CENTER_FREQ1]) 2618 chandef->center_freq1 = 2619 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 2620 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 2621 chandef->center_freq2 = 2622 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); 2623 } 2624 2625 if (!cfg80211_chandef_valid(chandef)) { 2626 NL_SET_ERR_MSG(extack, "invalid channel definition"); 2627 return -EINVAL; 2628 } 2629 2630 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, 2631 IEEE80211_CHAN_DISABLED)) { 2632 NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); 2633 return -EINVAL; 2634 } 2635 2636 if ((chandef->width == NL80211_CHAN_WIDTH_5 || 2637 chandef->width == NL80211_CHAN_WIDTH_10) && 2638 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { 2639 NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); 2640 return -EINVAL; 2641 } 2642 2643 return 0; 2644 } 2645 2646 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 2647 struct net_device *dev, 2648 struct genl_info *info) 2649 { 2650 struct cfg80211_chan_def chandef; 2651 int result; 2652 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; 2653 struct wireless_dev *wdev = NULL; 2654 2655 if (dev) 2656 wdev = dev->ieee80211_ptr; 2657 if (!nl80211_can_set_dev_channel(wdev)) 2658 return -EOPNOTSUPP; 2659 if (wdev) 2660 iftype = wdev->iftype; 2661 2662 result = nl80211_parse_chandef(rdev, info, &chandef); 2663 if (result) 2664 return result; 2665 2666 switch (iftype) { 2667 case NL80211_IFTYPE_AP: 2668 case NL80211_IFTYPE_P2P_GO: 2669 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 2670 iftype)) { 2671 result = -EINVAL; 2672 break; 2673 } 2674 if (wdev->beacon_interval) { 2675 if (!dev || !rdev->ops->set_ap_chanwidth || 2676 !(rdev->wiphy.features & 2677 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { 2678 result = -EBUSY; 2679 break; 2680 } 2681 2682 /* Only allow dynamic channel width changes */ 2683 if (chandef.chan != wdev->preset_chandef.chan) { 2684 result = -EBUSY; 2685 break; 2686 } 2687 result = rdev_set_ap_chanwidth(rdev, dev, &chandef); 2688 if (result) 2689 break; 2690 } 2691 wdev->preset_chandef = chandef; 2692 result = 0; 2693 break; 2694 case NL80211_IFTYPE_MESH_POINT: 2695 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); 2696 break; 2697 case NL80211_IFTYPE_MONITOR: 2698 result = cfg80211_set_monitor_channel(rdev, &chandef); 2699 break; 2700 default: 2701 result = -EINVAL; 2702 } 2703 2704 return result; 2705 } 2706 2707 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 2708 { 2709 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2710 struct net_device *netdev = info->user_ptr[1]; 2711 2712 return __nl80211_set_channel(rdev, netdev, info); 2713 } 2714 2715 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) 2716 { 2717 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2718 struct net_device *dev = info->user_ptr[1]; 2719 struct wireless_dev *wdev = dev->ieee80211_ptr; 2720 const u8 *bssid; 2721 2722 if (!info->attrs[NL80211_ATTR_MAC]) 2723 return -EINVAL; 2724 2725 if (netif_running(dev)) 2726 return -EBUSY; 2727 2728 if (!rdev->ops->set_wds_peer) 2729 return -EOPNOTSUPP; 2730 2731 if (wdev->iftype != NL80211_IFTYPE_WDS) 2732 return -EOPNOTSUPP; 2733 2734 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 2735 return rdev_set_wds_peer(rdev, dev, bssid); 2736 } 2737 2738 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 2739 { 2740 struct cfg80211_registered_device *rdev; 2741 struct net_device *netdev = NULL; 2742 struct wireless_dev *wdev; 2743 int result = 0, rem_txq_params = 0; 2744 struct nlattr *nl_txq_params; 2745 u32 changed; 2746 u8 retry_short = 0, retry_long = 0; 2747 u32 frag_threshold = 0, rts_threshold = 0; 2748 u8 coverage_class = 0; 2749 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; 2750 2751 ASSERT_RTNL(); 2752 2753 /* 2754 * Try to find the wiphy and netdev. Normally this 2755 * function shouldn't need the netdev, but this is 2756 * done for backward compatibility -- previously 2757 * setting the channel was done per wiphy, but now 2758 * it is per netdev. Previous userland like hostapd 2759 * also passed a netdev to set_wiphy, so that it is 2760 * possible to let that go to the right netdev! 2761 */ 2762 2763 if (info->attrs[NL80211_ATTR_IFINDEX]) { 2764 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 2765 2766 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 2767 if (netdev && netdev->ieee80211_ptr) 2768 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); 2769 else 2770 netdev = NULL; 2771 } 2772 2773 if (!netdev) { 2774 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), 2775 info->attrs); 2776 if (IS_ERR(rdev)) 2777 return PTR_ERR(rdev); 2778 wdev = NULL; 2779 netdev = NULL; 2780 result = 0; 2781 } else 2782 wdev = netdev->ieee80211_ptr; 2783 2784 /* 2785 * end workaround code, by now the rdev is available 2786 * and locked, and wdev may or may not be NULL. 2787 */ 2788 2789 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) 2790 result = cfg80211_dev_rename( 2791 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 2792 2793 if (result) 2794 return result; 2795 2796 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 2797 struct ieee80211_txq_params txq_params; 2798 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 2799 2800 if (!rdev->ops->set_txq_params) 2801 return -EOPNOTSUPP; 2802 2803 if (!netdev) 2804 return -EINVAL; 2805 2806 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 2807 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 2808 return -EINVAL; 2809 2810 if (!netif_running(netdev)) 2811 return -ENETDOWN; 2812 2813 nla_for_each_nested(nl_txq_params, 2814 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 2815 rem_txq_params) { 2816 result = nla_parse_nested_deprecated(tb, 2817 NL80211_TXQ_ATTR_MAX, 2818 nl_txq_params, 2819 txq_params_policy, 2820 info->extack); 2821 if (result) 2822 return result; 2823 result = parse_txq_params(tb, &txq_params); 2824 if (result) 2825 return result; 2826 2827 result = rdev_set_txq_params(rdev, netdev, 2828 &txq_params); 2829 if (result) 2830 return result; 2831 } 2832 } 2833 2834 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 2835 result = __nl80211_set_channel( 2836 rdev, 2837 nl80211_can_set_dev_channel(wdev) ? netdev : NULL, 2838 info); 2839 if (result) 2840 return result; 2841 } 2842 2843 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { 2844 struct wireless_dev *txp_wdev = wdev; 2845 enum nl80211_tx_power_setting type; 2846 int idx, mbm = 0; 2847 2848 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 2849 txp_wdev = NULL; 2850 2851 if (!rdev->ops->set_tx_power) 2852 return -EOPNOTSUPP; 2853 2854 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 2855 type = nla_get_u32(info->attrs[idx]); 2856 2857 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 2858 (type != NL80211_TX_POWER_AUTOMATIC)) 2859 return -EINVAL; 2860 2861 if (type != NL80211_TX_POWER_AUTOMATIC) { 2862 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; 2863 mbm = nla_get_u32(info->attrs[idx]); 2864 } 2865 2866 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 2867 if (result) 2868 return result; 2869 } 2870 2871 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && 2872 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { 2873 u32 tx_ant, rx_ant; 2874 2875 if ((!rdev->wiphy.available_antennas_tx && 2876 !rdev->wiphy.available_antennas_rx) || 2877 !rdev->ops->set_antenna) 2878 return -EOPNOTSUPP; 2879 2880 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 2881 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); 2882 2883 /* reject antenna configurations which don't match the 2884 * available antenna masks, except for the "all" mask */ 2885 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 2886 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) 2887 return -EINVAL; 2888 2889 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 2890 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 2891 2892 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 2893 if (result) 2894 return result; 2895 } 2896 2897 changed = 0; 2898 2899 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 2900 retry_short = nla_get_u8( 2901 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); 2902 2903 changed |= WIPHY_PARAM_RETRY_SHORT; 2904 } 2905 2906 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { 2907 retry_long = nla_get_u8( 2908 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); 2909 2910 changed |= WIPHY_PARAM_RETRY_LONG; 2911 } 2912 2913 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 2914 frag_threshold = nla_get_u32( 2915 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 2916 if (frag_threshold < 256) 2917 return -EINVAL; 2918 2919 if (frag_threshold != (u32) -1) { 2920 /* 2921 * Fragments (apart from the last one) are required to 2922 * have even length. Make the fragmentation code 2923 * simpler by stripping LSB should someone try to use 2924 * odd threshold value. 2925 */ 2926 frag_threshold &= ~0x1; 2927 } 2928 changed |= WIPHY_PARAM_FRAG_THRESHOLD; 2929 } 2930 2931 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { 2932 rts_threshold = nla_get_u32( 2933 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); 2934 changed |= WIPHY_PARAM_RTS_THRESHOLD; 2935 } 2936 2937 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 2938 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) 2939 return -EINVAL; 2940 2941 coverage_class = nla_get_u8( 2942 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); 2943 changed |= WIPHY_PARAM_COVERAGE_CLASS; 2944 } 2945 2946 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 2947 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) 2948 return -EOPNOTSUPP; 2949 2950 changed |= WIPHY_PARAM_DYN_ACK; 2951 } 2952 2953 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 2954 if (!wiphy_ext_feature_isset(&rdev->wiphy, 2955 NL80211_EXT_FEATURE_TXQS)) 2956 return -EOPNOTSUPP; 2957 txq_limit = nla_get_u32( 2958 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 2959 changed |= WIPHY_PARAM_TXQ_LIMIT; 2960 } 2961 2962 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 2963 if (!wiphy_ext_feature_isset(&rdev->wiphy, 2964 NL80211_EXT_FEATURE_TXQS)) 2965 return -EOPNOTSUPP; 2966 txq_memory_limit = nla_get_u32( 2967 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 2968 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; 2969 } 2970 2971 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 2972 if (!wiphy_ext_feature_isset(&rdev->wiphy, 2973 NL80211_EXT_FEATURE_TXQS)) 2974 return -EOPNOTSUPP; 2975 txq_quantum = nla_get_u32( 2976 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 2977 changed |= WIPHY_PARAM_TXQ_QUANTUM; 2978 } 2979 2980 if (changed) { 2981 u8 old_retry_short, old_retry_long; 2982 u32 old_frag_threshold, old_rts_threshold; 2983 u8 old_coverage_class; 2984 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 2985 2986 if (!rdev->ops->set_wiphy_params) 2987 return -EOPNOTSUPP; 2988 2989 old_retry_short = rdev->wiphy.retry_short; 2990 old_retry_long = rdev->wiphy.retry_long; 2991 old_frag_threshold = rdev->wiphy.frag_threshold; 2992 old_rts_threshold = rdev->wiphy.rts_threshold; 2993 old_coverage_class = rdev->wiphy.coverage_class; 2994 old_txq_limit = rdev->wiphy.txq_limit; 2995 old_txq_memory_limit = rdev->wiphy.txq_memory_limit; 2996 old_txq_quantum = rdev->wiphy.txq_quantum; 2997 2998 if (changed & WIPHY_PARAM_RETRY_SHORT) 2999 rdev->wiphy.retry_short = retry_short; 3000 if (changed & WIPHY_PARAM_RETRY_LONG) 3001 rdev->wiphy.retry_long = retry_long; 3002 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 3003 rdev->wiphy.frag_threshold = frag_threshold; 3004 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 3005 rdev->wiphy.rts_threshold = rts_threshold; 3006 if (changed & WIPHY_PARAM_COVERAGE_CLASS) 3007 rdev->wiphy.coverage_class = coverage_class; 3008 if (changed & WIPHY_PARAM_TXQ_LIMIT) 3009 rdev->wiphy.txq_limit = txq_limit; 3010 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) 3011 rdev->wiphy.txq_memory_limit = txq_memory_limit; 3012 if (changed & WIPHY_PARAM_TXQ_QUANTUM) 3013 rdev->wiphy.txq_quantum = txq_quantum; 3014 3015 result = rdev_set_wiphy_params(rdev, changed); 3016 if (result) { 3017 rdev->wiphy.retry_short = old_retry_short; 3018 rdev->wiphy.retry_long = old_retry_long; 3019 rdev->wiphy.frag_threshold = old_frag_threshold; 3020 rdev->wiphy.rts_threshold = old_rts_threshold; 3021 rdev->wiphy.coverage_class = old_coverage_class; 3022 rdev->wiphy.txq_limit = old_txq_limit; 3023 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3024 rdev->wiphy.txq_quantum = old_txq_quantum; 3025 return result; 3026 } 3027 } 3028 return 0; 3029 } 3030 3031 static int nl80211_send_chandef(struct sk_buff *msg, 3032 const struct cfg80211_chan_def *chandef) 3033 { 3034 if (WARN_ON(!cfg80211_chandef_valid(chandef))) 3035 return -EINVAL; 3036 3037 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 3038 chandef->chan->center_freq)) 3039 return -ENOBUFS; 3040 switch (chandef->width) { 3041 case NL80211_CHAN_WIDTH_20_NOHT: 3042 case NL80211_CHAN_WIDTH_20: 3043 case NL80211_CHAN_WIDTH_40: 3044 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 3045 cfg80211_get_chandef_type(chandef))) 3046 return -ENOBUFS; 3047 break; 3048 default: 3049 break; 3050 } 3051 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) 3052 return -ENOBUFS; 3053 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) 3054 return -ENOBUFS; 3055 if (chandef->center_freq2 && 3056 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) 3057 return -ENOBUFS; 3058 return 0; 3059 } 3060 3061 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, 3062 struct cfg80211_registered_device *rdev, 3063 struct wireless_dev *wdev, 3064 enum nl80211_commands cmd) 3065 { 3066 struct net_device *dev = wdev->netdev; 3067 void *hdr; 3068 3069 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && 3070 cmd != NL80211_CMD_DEL_INTERFACE && 3071 cmd != NL80211_CMD_SET_INTERFACE); 3072 3073 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 3074 if (!hdr) 3075 return -1; 3076 3077 if (dev && 3078 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3079 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) 3080 goto nla_put_failure; 3081 3082 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3083 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || 3084 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3085 NL80211_ATTR_PAD) || 3086 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || 3087 nla_put_u32(msg, NL80211_ATTR_GENERATION, 3088 rdev->devlist_generation ^ 3089 (cfg80211_rdev_list_generation << 2)) || 3090 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) 3091 goto nla_put_failure; 3092 3093 if (rdev->ops->get_channel) { 3094 int ret; 3095 struct cfg80211_chan_def chandef; 3096 3097 ret = rdev_get_channel(rdev, wdev, &chandef); 3098 if (ret == 0) { 3099 if (nl80211_send_chandef(msg, &chandef)) 3100 goto nla_put_failure; 3101 } 3102 } 3103 3104 if (rdev->ops->get_tx_power) { 3105 int dbm, ret; 3106 3107 ret = rdev_get_tx_power(rdev, wdev, &dbm); 3108 if (ret == 0 && 3109 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, 3110 DBM_TO_MBM(dbm))) 3111 goto nla_put_failure; 3112 } 3113 3114 wdev_lock(wdev); 3115 switch (wdev->iftype) { 3116 case NL80211_IFTYPE_AP: 3117 if (wdev->ssid_len && 3118 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) 3119 goto nla_put_failure_locked; 3120 break; 3121 case NL80211_IFTYPE_STATION: 3122 case NL80211_IFTYPE_P2P_CLIENT: 3123 case NL80211_IFTYPE_ADHOC: { 3124 const u8 *ssid_ie; 3125 if (!wdev->current_bss) 3126 break; 3127 rcu_read_lock(); 3128 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, 3129 WLAN_EID_SSID); 3130 if (ssid_ie && 3131 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) 3132 goto nla_put_failure_rcu_locked; 3133 rcu_read_unlock(); 3134 break; 3135 } 3136 default: 3137 /* nothing */ 3138 break; 3139 } 3140 wdev_unlock(wdev); 3141 3142 if (rdev->ops->get_txq_stats) { 3143 struct cfg80211_txq_stats txqstats = {}; 3144 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); 3145 3146 if (ret == 0 && 3147 !nl80211_put_txq_stats(msg, &txqstats, 3148 NL80211_ATTR_TXQ_STATS)) 3149 goto nla_put_failure; 3150 } 3151 3152 genlmsg_end(msg, hdr); 3153 return 0; 3154 3155 nla_put_failure_rcu_locked: 3156 rcu_read_unlock(); 3157 nla_put_failure_locked: 3158 wdev_unlock(wdev); 3159 nla_put_failure: 3160 genlmsg_cancel(msg, hdr); 3161 return -EMSGSIZE; 3162 } 3163 3164 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) 3165 { 3166 int wp_idx = 0; 3167 int if_idx = 0; 3168 int wp_start = cb->args[0]; 3169 int if_start = cb->args[1]; 3170 int filter_wiphy = -1; 3171 struct cfg80211_registered_device *rdev; 3172 struct wireless_dev *wdev; 3173 int ret; 3174 3175 rtnl_lock(); 3176 if (!cb->args[2]) { 3177 struct nl80211_dump_wiphy_state state = { 3178 .filter_wiphy = -1, 3179 }; 3180 3181 ret = nl80211_dump_wiphy_parse(skb, cb, &state); 3182 if (ret) 3183 goto out_unlock; 3184 3185 filter_wiphy = state.filter_wiphy; 3186 3187 /* 3188 * if filtering, set cb->args[2] to +1 since 0 is the default 3189 * value needed to determine that parsing is necessary. 3190 */ 3191 if (filter_wiphy >= 0) 3192 cb->args[2] = filter_wiphy + 1; 3193 else 3194 cb->args[2] = -1; 3195 } else if (cb->args[2] > 0) { 3196 filter_wiphy = cb->args[2] - 1; 3197 } 3198 3199 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3200 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3201 continue; 3202 if (wp_idx < wp_start) { 3203 wp_idx++; 3204 continue; 3205 } 3206 3207 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) 3208 continue; 3209 3210 if_idx = 0; 3211 3212 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 3213 if (if_idx < if_start) { 3214 if_idx++; 3215 continue; 3216 } 3217 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 3218 cb->nlh->nlmsg_seq, NLM_F_MULTI, 3219 rdev, wdev, 3220 NL80211_CMD_NEW_INTERFACE) < 0) { 3221 goto out; 3222 } 3223 if_idx++; 3224 } 3225 3226 wp_idx++; 3227 } 3228 out: 3229 cb->args[0] = wp_idx; 3230 cb->args[1] = if_idx; 3231 3232 ret = skb->len; 3233 out_unlock: 3234 rtnl_unlock(); 3235 3236 return ret; 3237 } 3238 3239 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 3240 { 3241 struct sk_buff *msg; 3242 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3243 struct wireless_dev *wdev = info->user_ptr[1]; 3244 3245 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3246 if (!msg) 3247 return -ENOMEM; 3248 3249 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 3250 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 3251 nlmsg_free(msg); 3252 return -ENOBUFS; 3253 } 3254 3255 return genlmsg_reply(msg, info); 3256 } 3257 3258 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 3259 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, 3260 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, 3261 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, 3262 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, 3263 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, 3264 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, 3265 }; 3266 3267 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) 3268 { 3269 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; 3270 int flag; 3271 3272 *mntrflags = 0; 3273 3274 if (!nla) 3275 return -EINVAL; 3276 3277 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) 3278 return -EINVAL; 3279 3280 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 3281 if (flags[flag]) 3282 *mntrflags |= (1<<flag); 3283 3284 *mntrflags |= MONITOR_FLAG_CHANGED; 3285 3286 return 0; 3287 } 3288 3289 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, 3290 enum nl80211_iftype type, 3291 struct genl_info *info, 3292 struct vif_params *params) 3293 { 3294 bool change = false; 3295 int err; 3296 3297 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 3298 if (type != NL80211_IFTYPE_MONITOR) 3299 return -EINVAL; 3300 3301 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 3302 ¶ms->flags); 3303 if (err) 3304 return err; 3305 3306 change = true; 3307 } 3308 3309 if (params->flags & MONITOR_FLAG_ACTIVE && 3310 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 3311 return -EOPNOTSUPP; 3312 3313 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { 3314 const u8 *mumimo_groups; 3315 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 3316 3317 if (type != NL80211_IFTYPE_MONITOR) 3318 return -EINVAL; 3319 3320 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 3321 return -EOPNOTSUPP; 3322 3323 mumimo_groups = 3324 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); 3325 3326 /* bits 0 and 63 are reserved and must be zero */ 3327 if ((mumimo_groups[0] & BIT(0)) || 3328 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) 3329 return -EINVAL; 3330 3331 params->vht_mumimo_groups = mumimo_groups; 3332 change = true; 3333 } 3334 3335 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { 3336 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 3337 3338 if (type != NL80211_IFTYPE_MONITOR) 3339 return -EINVAL; 3340 3341 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 3342 return -EOPNOTSUPP; 3343 3344 params->vht_mumimo_follow_addr = 3345 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); 3346 change = true; 3347 } 3348 3349 return change ? 1 : 0; 3350 } 3351 3352 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, 3353 struct net_device *netdev, u8 use_4addr, 3354 enum nl80211_iftype iftype) 3355 { 3356 if (!use_4addr) { 3357 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) 3358 return -EBUSY; 3359 return 0; 3360 } 3361 3362 switch (iftype) { 3363 case NL80211_IFTYPE_AP_VLAN: 3364 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) 3365 return 0; 3366 break; 3367 case NL80211_IFTYPE_STATION: 3368 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) 3369 return 0; 3370 break; 3371 default: 3372 break; 3373 } 3374 3375 return -EOPNOTSUPP; 3376 } 3377 3378 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 3379 { 3380 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3381 struct vif_params params; 3382 int err; 3383 enum nl80211_iftype otype, ntype; 3384 struct net_device *dev = info->user_ptr[1]; 3385 bool change = false; 3386 3387 memset(¶ms, 0, sizeof(params)); 3388 3389 otype = ntype = dev->ieee80211_ptr->iftype; 3390 3391 if (info->attrs[NL80211_ATTR_IFTYPE]) { 3392 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 3393 if (otype != ntype) 3394 change = true; 3395 } 3396 3397 if (info->attrs[NL80211_ATTR_MESH_ID]) { 3398 struct wireless_dev *wdev = dev->ieee80211_ptr; 3399 3400 if (ntype != NL80211_IFTYPE_MESH_POINT) 3401 return -EINVAL; 3402 if (netif_running(dev)) 3403 return -EBUSY; 3404 3405 wdev_lock(wdev); 3406 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 3407 IEEE80211_MAX_MESH_ID_LEN); 3408 wdev->mesh_id_up_len = 3409 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 3410 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 3411 wdev->mesh_id_up_len); 3412 wdev_unlock(wdev); 3413 } 3414 3415 if (info->attrs[NL80211_ATTR_4ADDR]) { 3416 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 3417 change = true; 3418 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 3419 if (err) 3420 return err; 3421 } else { 3422 params.use_4addr = -1; 3423 } 3424 3425 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); 3426 if (err < 0) 3427 return err; 3428 if (err > 0) 3429 change = true; 3430 3431 if (change) 3432 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); 3433 else 3434 err = 0; 3435 3436 if (!err && params.use_4addr != -1) 3437 dev->ieee80211_ptr->use_4addr = params.use_4addr; 3438 3439 if (change && !err) { 3440 struct wireless_dev *wdev = dev->ieee80211_ptr; 3441 3442 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); 3443 } 3444 3445 return err; 3446 } 3447 3448 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 3449 { 3450 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3451 struct vif_params params; 3452 struct wireless_dev *wdev; 3453 struct sk_buff *msg; 3454 int err; 3455 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 3456 3457 /* to avoid failing a new interface creation due to pending removal */ 3458 cfg80211_destroy_ifaces(rdev); 3459 3460 memset(¶ms, 0, sizeof(params)); 3461 3462 if (!info->attrs[NL80211_ATTR_IFNAME]) 3463 return -EINVAL; 3464 3465 if (info->attrs[NL80211_ATTR_IFTYPE]) 3466 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 3467 3468 if (!rdev->ops->add_virtual_intf) 3469 return -EOPNOTSUPP; 3470 3471 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || 3472 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && 3473 info->attrs[NL80211_ATTR_MAC]) { 3474 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 3475 ETH_ALEN); 3476 if (!is_valid_ether_addr(params.macaddr)) 3477 return -EADDRNOTAVAIL; 3478 } 3479 3480 if (info->attrs[NL80211_ATTR_4ADDR]) { 3481 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 3482 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 3483 if (err) 3484 return err; 3485 } 3486 3487 if (!(rdev->wiphy.interface_modes & (1 << type)) && 3488 !(type == NL80211_IFTYPE_AP_VLAN && params.use_4addr && 3489 rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)) 3490 return -EOPNOTSUPP; 3491 3492 err = nl80211_parse_mon_options(rdev, type, info, ¶ms); 3493 if (err < 0) 3494 return err; 3495 3496 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3497 if (!msg) 3498 return -ENOMEM; 3499 3500 wdev = rdev_add_virtual_intf(rdev, 3501 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 3502 NET_NAME_USER, type, ¶ms); 3503 if (WARN_ON(!wdev)) { 3504 nlmsg_free(msg); 3505 return -EPROTO; 3506 } else if (IS_ERR(wdev)) { 3507 nlmsg_free(msg); 3508 return PTR_ERR(wdev); 3509 } 3510 3511 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 3512 wdev->owner_nlportid = info->snd_portid; 3513 3514 switch (type) { 3515 case NL80211_IFTYPE_MESH_POINT: 3516 if (!info->attrs[NL80211_ATTR_MESH_ID]) 3517 break; 3518 wdev_lock(wdev); 3519 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 3520 IEEE80211_MAX_MESH_ID_LEN); 3521 wdev->mesh_id_up_len = 3522 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 3523 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 3524 wdev->mesh_id_up_len); 3525 wdev_unlock(wdev); 3526 break; 3527 case NL80211_IFTYPE_NAN: 3528 case NL80211_IFTYPE_P2P_DEVICE: 3529 /* 3530 * P2P Device and NAN do not have a netdev, so don't go 3531 * through the netdev notifier and must be added here 3532 */ 3533 cfg80211_init_wdev(rdev, wdev); 3534 break; 3535 default: 3536 break; 3537 } 3538 3539 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 3540 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 3541 nlmsg_free(msg); 3542 return -ENOBUFS; 3543 } 3544 3545 return genlmsg_reply(msg, info); 3546 } 3547 3548 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 3549 { 3550 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3551 struct wireless_dev *wdev = info->user_ptr[1]; 3552 3553 if (!rdev->ops->del_virtual_intf) 3554 return -EOPNOTSUPP; 3555 3556 /* 3557 * If we remove a wireless device without a netdev then clear 3558 * user_ptr[1] so that nl80211_post_doit won't dereference it 3559 * to check if it needs to do dev_put(). Otherwise it crashes 3560 * since the wdev has been freed, unlike with a netdev where 3561 * we need the dev_put() for the netdev to really be freed. 3562 */ 3563 if (!wdev->netdev) 3564 info->user_ptr[1] = NULL; 3565 3566 return rdev_del_virtual_intf(rdev, wdev); 3567 } 3568 3569 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) 3570 { 3571 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3572 struct net_device *dev = info->user_ptr[1]; 3573 u16 noack_map; 3574 3575 if (!info->attrs[NL80211_ATTR_NOACK_MAP]) 3576 return -EINVAL; 3577 3578 if (!rdev->ops->set_noack_map) 3579 return -EOPNOTSUPP; 3580 3581 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); 3582 3583 return rdev_set_noack_map(rdev, dev, noack_map); 3584 } 3585 3586 struct get_key_cookie { 3587 struct sk_buff *msg; 3588 int error; 3589 int idx; 3590 }; 3591 3592 static void get_key_callback(void *c, struct key_params *params) 3593 { 3594 struct nlattr *key; 3595 struct get_key_cookie *cookie = c; 3596 3597 if ((params->key && 3598 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, 3599 params->key_len, params->key)) || 3600 (params->seq && 3601 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, 3602 params->seq_len, params->seq)) || 3603 (params->cipher && 3604 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, 3605 params->cipher))) 3606 goto nla_put_failure; 3607 3608 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); 3609 if (!key) 3610 goto nla_put_failure; 3611 3612 if ((params->key && 3613 nla_put(cookie->msg, NL80211_KEY_DATA, 3614 params->key_len, params->key)) || 3615 (params->seq && 3616 nla_put(cookie->msg, NL80211_KEY_SEQ, 3617 params->seq_len, params->seq)) || 3618 (params->cipher && 3619 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, 3620 params->cipher))) 3621 goto nla_put_failure; 3622 3623 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) 3624 goto nla_put_failure; 3625 3626 nla_nest_end(cookie->msg, key); 3627 3628 return; 3629 nla_put_failure: 3630 cookie->error = 1; 3631 } 3632 3633 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 3634 { 3635 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3636 int err; 3637 struct net_device *dev = info->user_ptr[1]; 3638 u8 key_idx = 0; 3639 const u8 *mac_addr = NULL; 3640 bool pairwise; 3641 struct get_key_cookie cookie = { 3642 .error = 0, 3643 }; 3644 void *hdr; 3645 struct sk_buff *msg; 3646 3647 if (info->attrs[NL80211_ATTR_KEY_IDX]) 3648 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 3649 3650 if (info->attrs[NL80211_ATTR_MAC]) 3651 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3652 3653 pairwise = !!mac_addr; 3654 if (info->attrs[NL80211_ATTR_KEY_TYPE]) { 3655 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 3656 3657 if (kt != NL80211_KEYTYPE_GROUP && 3658 kt != NL80211_KEYTYPE_PAIRWISE) 3659 return -EINVAL; 3660 pairwise = kt == NL80211_KEYTYPE_PAIRWISE; 3661 } 3662 3663 if (!rdev->ops->get_key) 3664 return -EOPNOTSUPP; 3665 3666 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 3667 return -ENOENT; 3668 3669 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3670 if (!msg) 3671 return -ENOMEM; 3672 3673 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 3674 NL80211_CMD_NEW_KEY); 3675 if (!hdr) 3676 goto nla_put_failure; 3677 3678 cookie.msg = msg; 3679 cookie.idx = key_idx; 3680 3681 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3682 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) 3683 goto nla_put_failure; 3684 if (mac_addr && 3685 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) 3686 goto nla_put_failure; 3687 3688 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, 3689 get_key_callback); 3690 3691 if (err) 3692 goto free_msg; 3693 3694 if (cookie.error) 3695 goto nla_put_failure; 3696 3697 genlmsg_end(msg, hdr); 3698 return genlmsg_reply(msg, info); 3699 3700 nla_put_failure: 3701 err = -ENOBUFS; 3702 free_msg: 3703 nlmsg_free(msg); 3704 return err; 3705 } 3706 3707 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 3708 { 3709 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3710 struct key_parse key; 3711 int err; 3712 struct net_device *dev = info->user_ptr[1]; 3713 3714 err = nl80211_parse_key(info, &key); 3715 if (err) 3716 return err; 3717 3718 if (key.idx < 0) 3719 return -EINVAL; 3720 3721 /* Only support setting default key and 3722 * Extended Key ID action NL80211_KEY_SET_TX. 3723 */ 3724 if (!key.def && !key.defmgmt && 3725 !(key.p.mode == NL80211_KEY_SET_TX)) 3726 return -EINVAL; 3727 3728 wdev_lock(dev->ieee80211_ptr); 3729 3730 if (key.def) { 3731 if (!rdev->ops->set_default_key) { 3732 err = -EOPNOTSUPP; 3733 goto out; 3734 } 3735 3736 err = nl80211_key_allowed(dev->ieee80211_ptr); 3737 if (err) 3738 goto out; 3739 3740 err = rdev_set_default_key(rdev, dev, key.idx, 3741 key.def_uni, key.def_multi); 3742 3743 if (err) 3744 goto out; 3745 3746 #ifdef CONFIG_CFG80211_WEXT 3747 dev->ieee80211_ptr->wext.default_key = key.idx; 3748 #endif 3749 } else if (key.defmgmt) { 3750 if (key.def_uni || !key.def_multi) { 3751 err = -EINVAL; 3752 goto out; 3753 } 3754 3755 if (!rdev->ops->set_default_mgmt_key) { 3756 err = -EOPNOTSUPP; 3757 goto out; 3758 } 3759 3760 err = nl80211_key_allowed(dev->ieee80211_ptr); 3761 if (err) 3762 goto out; 3763 3764 err = rdev_set_default_mgmt_key(rdev, dev, key.idx); 3765 if (err) 3766 goto out; 3767 3768 #ifdef CONFIG_CFG80211_WEXT 3769 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; 3770 #endif 3771 } else if (key.p.mode == NL80211_KEY_SET_TX && 3772 wiphy_ext_feature_isset(&rdev->wiphy, 3773 NL80211_EXT_FEATURE_EXT_KEY_ID)) { 3774 u8 *mac_addr = NULL; 3775 3776 if (info->attrs[NL80211_ATTR_MAC]) 3777 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3778 3779 if (!mac_addr || key.idx < 0 || key.idx > 1) { 3780 err = -EINVAL; 3781 goto out; 3782 } 3783 3784 err = rdev_add_key(rdev, dev, key.idx, 3785 NL80211_KEYTYPE_PAIRWISE, 3786 mac_addr, &key.p); 3787 } else { 3788 err = -EINVAL; 3789 } 3790 out: 3791 wdev_unlock(dev->ieee80211_ptr); 3792 3793 return err; 3794 } 3795 3796 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 3797 { 3798 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3799 int err; 3800 struct net_device *dev = info->user_ptr[1]; 3801 struct key_parse key; 3802 const u8 *mac_addr = NULL; 3803 3804 err = nl80211_parse_key(info, &key); 3805 if (err) 3806 return err; 3807 3808 if (!key.p.key) 3809 return -EINVAL; 3810 3811 if (info->attrs[NL80211_ATTR_MAC]) 3812 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3813 3814 if (key.type == -1) { 3815 if (mac_addr) 3816 key.type = NL80211_KEYTYPE_PAIRWISE; 3817 else 3818 key.type = NL80211_KEYTYPE_GROUP; 3819 } 3820 3821 /* for now */ 3822 if (key.type != NL80211_KEYTYPE_PAIRWISE && 3823 key.type != NL80211_KEYTYPE_GROUP) 3824 return -EINVAL; 3825 3826 if (!rdev->ops->add_key) 3827 return -EOPNOTSUPP; 3828 3829 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, 3830 key.type == NL80211_KEYTYPE_PAIRWISE, 3831 mac_addr)) 3832 return -EINVAL; 3833 3834 wdev_lock(dev->ieee80211_ptr); 3835 err = nl80211_key_allowed(dev->ieee80211_ptr); 3836 if (!err) 3837 err = rdev_add_key(rdev, dev, key.idx, 3838 key.type == NL80211_KEYTYPE_PAIRWISE, 3839 mac_addr, &key.p); 3840 wdev_unlock(dev->ieee80211_ptr); 3841 3842 return err; 3843 } 3844 3845 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 3846 { 3847 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3848 int err; 3849 struct net_device *dev = info->user_ptr[1]; 3850 u8 *mac_addr = NULL; 3851 struct key_parse key; 3852 3853 err = nl80211_parse_key(info, &key); 3854 if (err) 3855 return err; 3856 3857 if (info->attrs[NL80211_ATTR_MAC]) 3858 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3859 3860 if (key.type == -1) { 3861 if (mac_addr) 3862 key.type = NL80211_KEYTYPE_PAIRWISE; 3863 else 3864 key.type = NL80211_KEYTYPE_GROUP; 3865 } 3866 3867 /* for now */ 3868 if (key.type != NL80211_KEYTYPE_PAIRWISE && 3869 key.type != NL80211_KEYTYPE_GROUP) 3870 return -EINVAL; 3871 3872 if (!rdev->ops->del_key) 3873 return -EOPNOTSUPP; 3874 3875 wdev_lock(dev->ieee80211_ptr); 3876 err = nl80211_key_allowed(dev->ieee80211_ptr); 3877 3878 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && 3879 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 3880 err = -ENOENT; 3881 3882 if (!err) 3883 err = rdev_del_key(rdev, dev, key.idx, 3884 key.type == NL80211_KEYTYPE_PAIRWISE, 3885 mac_addr); 3886 3887 #ifdef CONFIG_CFG80211_WEXT 3888 if (!err) { 3889 if (key.idx == dev->ieee80211_ptr->wext.default_key) 3890 dev->ieee80211_ptr->wext.default_key = -1; 3891 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) 3892 dev->ieee80211_ptr->wext.default_mgmt_key = -1; 3893 } 3894 #endif 3895 wdev_unlock(dev->ieee80211_ptr); 3896 3897 return err; 3898 } 3899 3900 /* This function returns an error or the number of nested attributes */ 3901 static int validate_acl_mac_addrs(struct nlattr *nl_attr) 3902 { 3903 struct nlattr *attr; 3904 int n_entries = 0, tmp; 3905 3906 nla_for_each_nested(attr, nl_attr, tmp) { 3907 if (nla_len(attr) != ETH_ALEN) 3908 return -EINVAL; 3909 3910 n_entries++; 3911 } 3912 3913 return n_entries; 3914 } 3915 3916 /* 3917 * This function parses ACL information and allocates memory for ACL data. 3918 * On successful return, the calling function is responsible to free the 3919 * ACL buffer returned by this function. 3920 */ 3921 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, 3922 struct genl_info *info) 3923 { 3924 enum nl80211_acl_policy acl_policy; 3925 struct nlattr *attr; 3926 struct cfg80211_acl_data *acl; 3927 int i = 0, n_entries, tmp; 3928 3929 if (!wiphy->max_acl_mac_addrs) 3930 return ERR_PTR(-EOPNOTSUPP); 3931 3932 if (!info->attrs[NL80211_ATTR_ACL_POLICY]) 3933 return ERR_PTR(-EINVAL); 3934 3935 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); 3936 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && 3937 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) 3938 return ERR_PTR(-EINVAL); 3939 3940 if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) 3941 return ERR_PTR(-EINVAL); 3942 3943 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); 3944 if (n_entries < 0) 3945 return ERR_PTR(n_entries); 3946 3947 if (n_entries > wiphy->max_acl_mac_addrs) 3948 return ERR_PTR(-ENOTSUPP); 3949 3950 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); 3951 if (!acl) 3952 return ERR_PTR(-ENOMEM); 3953 3954 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { 3955 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); 3956 i++; 3957 } 3958 3959 acl->n_acl_entries = n_entries; 3960 acl->acl_policy = acl_policy; 3961 3962 return acl; 3963 } 3964 3965 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) 3966 { 3967 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3968 struct net_device *dev = info->user_ptr[1]; 3969 struct cfg80211_acl_data *acl; 3970 int err; 3971 3972 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3973 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 3974 return -EOPNOTSUPP; 3975 3976 if (!dev->ieee80211_ptr->beacon_interval) 3977 return -EINVAL; 3978 3979 acl = parse_acl_data(&rdev->wiphy, info); 3980 if (IS_ERR(acl)) 3981 return PTR_ERR(acl); 3982 3983 err = rdev_set_mac_acl(rdev, dev, acl); 3984 3985 kfree(acl); 3986 3987 return err; 3988 } 3989 3990 static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 3991 u8 *rates, u8 rates_len) 3992 { 3993 u8 i; 3994 u32 mask = 0; 3995 3996 for (i = 0; i < rates_len; i++) { 3997 int rate = (rates[i] & 0x7f) * 5; 3998 int ridx; 3999 4000 for (ridx = 0; ridx < sband->n_bitrates; ridx++) { 4001 struct ieee80211_rate *srate = 4002 &sband->bitrates[ridx]; 4003 if (rate == srate->bitrate) { 4004 mask |= 1 << ridx; 4005 break; 4006 } 4007 } 4008 if (ridx == sband->n_bitrates) 4009 return 0; /* rate not found */ 4010 } 4011 4012 return mask; 4013 } 4014 4015 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, 4016 u8 *rates, u8 rates_len, 4017 u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) 4018 { 4019 u8 i; 4020 4021 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); 4022 4023 for (i = 0; i < rates_len; i++) { 4024 int ridx, rbit; 4025 4026 ridx = rates[i] / 8; 4027 rbit = BIT(rates[i] % 8); 4028 4029 /* check validity */ 4030 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) 4031 return false; 4032 4033 /* check availability */ 4034 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); 4035 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) 4036 mcs[ridx] |= rbit; 4037 else 4038 return false; 4039 } 4040 4041 return true; 4042 } 4043 4044 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) 4045 { 4046 u16 mcs_mask = 0; 4047 4048 switch (vht_mcs_map) { 4049 case IEEE80211_VHT_MCS_NOT_SUPPORTED: 4050 break; 4051 case IEEE80211_VHT_MCS_SUPPORT_0_7: 4052 mcs_mask = 0x00FF; 4053 break; 4054 case IEEE80211_VHT_MCS_SUPPORT_0_8: 4055 mcs_mask = 0x01FF; 4056 break; 4057 case IEEE80211_VHT_MCS_SUPPORT_0_9: 4058 mcs_mask = 0x03FF; 4059 break; 4060 default: 4061 break; 4062 } 4063 4064 return mcs_mask; 4065 } 4066 4067 static void vht_build_mcs_mask(u16 vht_mcs_map, 4068 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) 4069 { 4070 u8 nss; 4071 4072 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 4073 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); 4074 vht_mcs_map >>= 2; 4075 } 4076 } 4077 4078 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, 4079 struct nl80211_txrate_vht *txrate, 4080 u16 mcs[NL80211_VHT_NSS_MAX]) 4081 { 4082 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4083 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; 4084 u8 i; 4085 4086 if (!sband->vht_cap.vht_supported) 4087 return false; 4088 4089 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); 4090 4091 /* Build vht_mcs_mask from VHT capabilities */ 4092 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 4093 4094 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4095 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 4096 mcs[i] = txrate->mcs[i]; 4097 else 4098 return false; 4099 } 4100 4101 return true; 4102 } 4103 4104 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { 4105 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, 4106 .len = NL80211_MAX_SUPP_RATES }, 4107 [NL80211_TXRATE_HT] = { .type = NLA_BINARY, 4108 .len = NL80211_MAX_SUPP_HT_RATES }, 4109 [NL80211_TXRATE_VHT] = { 4110 .type = NLA_EXACT_LEN_WARN, 4111 .len = sizeof(struct nl80211_txrate_vht), 4112 }, 4113 [NL80211_TXRATE_GI] = { .type = NLA_U8 }, 4114 }; 4115 4116 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, 4117 struct cfg80211_bitrate_mask *mask) 4118 { 4119 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 4120 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4121 int rem, i; 4122 struct nlattr *tx_rates; 4123 struct ieee80211_supported_band *sband; 4124 u16 vht_tx_mcs_map; 4125 4126 memset(mask, 0, sizeof(*mask)); 4127 /* Default to all rates enabled */ 4128 for (i = 0; i < NUM_NL80211_BANDS; i++) { 4129 sband = rdev->wiphy.bands[i]; 4130 4131 if (!sband) 4132 continue; 4133 4134 mask->control[i].legacy = (1 << sband->n_bitrates) - 1; 4135 memcpy(mask->control[i].ht_mcs, 4136 sband->ht_cap.mcs.rx_mask, 4137 sizeof(mask->control[i].ht_mcs)); 4138 4139 if (!sband->vht_cap.vht_supported) 4140 continue; 4141 4142 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4143 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); 4144 } 4145 4146 /* if no rates are given set it back to the defaults */ 4147 if (!info->attrs[NL80211_ATTR_TX_RATES]) 4148 goto out; 4149 4150 /* The nested attribute uses enum nl80211_band as the index. This maps 4151 * directly to the enum nl80211_band values used in cfg80211. 4152 */ 4153 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); 4154 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { 4155 enum nl80211_band band = nla_type(tx_rates); 4156 int err; 4157 4158 if (band < 0 || band >= NUM_NL80211_BANDS) 4159 return -EINVAL; 4160 sband = rdev->wiphy.bands[band]; 4161 if (sband == NULL) 4162 return -EINVAL; 4163 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, 4164 tx_rates, 4165 nl80211_txattr_policy, 4166 info->extack); 4167 if (err) 4168 return err; 4169 if (tb[NL80211_TXRATE_LEGACY]) { 4170 mask->control[band].legacy = rateset_to_mask( 4171 sband, 4172 nla_data(tb[NL80211_TXRATE_LEGACY]), 4173 nla_len(tb[NL80211_TXRATE_LEGACY])); 4174 if ((mask->control[band].legacy == 0) && 4175 nla_len(tb[NL80211_TXRATE_LEGACY])) 4176 return -EINVAL; 4177 } 4178 if (tb[NL80211_TXRATE_HT]) { 4179 if (!ht_rateset_to_mask( 4180 sband, 4181 nla_data(tb[NL80211_TXRATE_HT]), 4182 nla_len(tb[NL80211_TXRATE_HT]), 4183 mask->control[band].ht_mcs)) 4184 return -EINVAL; 4185 } 4186 if (tb[NL80211_TXRATE_VHT]) { 4187 if (!vht_set_mcs_mask( 4188 sband, 4189 nla_data(tb[NL80211_TXRATE_VHT]), 4190 mask->control[band].vht_mcs)) 4191 return -EINVAL; 4192 } 4193 if (tb[NL80211_TXRATE_GI]) { 4194 mask->control[band].gi = 4195 nla_get_u8(tb[NL80211_TXRATE_GI]); 4196 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) 4197 return -EINVAL; 4198 } 4199 4200 if (mask->control[band].legacy == 0) { 4201 /* don't allow empty legacy rates if HT or VHT 4202 * are not even supported. 4203 */ 4204 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || 4205 rdev->wiphy.bands[band]->vht_cap.vht_supported)) 4206 return -EINVAL; 4207 4208 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) 4209 if (mask->control[band].ht_mcs[i]) 4210 goto out; 4211 4212 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) 4213 if (mask->control[band].vht_mcs[i]) 4214 goto out; 4215 4216 /* legacy and mcs rates may not be both empty */ 4217 return -EINVAL; 4218 } 4219 } 4220 4221 out: 4222 return 0; 4223 } 4224 4225 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, 4226 enum nl80211_band band, 4227 struct cfg80211_bitrate_mask *beacon_rate) 4228 { 4229 u32 count_ht, count_vht, i; 4230 u32 rate = beacon_rate->control[band].legacy; 4231 4232 /* Allow only one rate */ 4233 if (hweight32(rate) > 1) 4234 return -EINVAL; 4235 4236 count_ht = 0; 4237 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 4238 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { 4239 return -EINVAL; 4240 } else if (beacon_rate->control[band].ht_mcs[i]) { 4241 count_ht++; 4242 if (count_ht > 1) 4243 return -EINVAL; 4244 } 4245 if (count_ht && rate) 4246 return -EINVAL; 4247 } 4248 4249 count_vht = 0; 4250 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 4251 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { 4252 return -EINVAL; 4253 } else if (beacon_rate->control[band].vht_mcs[i]) { 4254 count_vht++; 4255 if (count_vht > 1) 4256 return -EINVAL; 4257 } 4258 if (count_vht && rate) 4259 return -EINVAL; 4260 } 4261 4262 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) 4263 return -EINVAL; 4264 4265 if (rate && 4266 !wiphy_ext_feature_isset(&rdev->wiphy, 4267 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 4268 return -EINVAL; 4269 if (count_ht && 4270 !wiphy_ext_feature_isset(&rdev->wiphy, 4271 NL80211_EXT_FEATURE_BEACON_RATE_HT)) 4272 return -EINVAL; 4273 if (count_vht && 4274 !wiphy_ext_feature_isset(&rdev->wiphy, 4275 NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 4276 return -EINVAL; 4277 4278 return 0; 4279 } 4280 4281 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, 4282 struct nlattr *attrs[], 4283 struct cfg80211_beacon_data *bcn) 4284 { 4285 bool haveinfo = false; 4286 int err; 4287 4288 memset(bcn, 0, sizeof(*bcn)); 4289 4290 if (attrs[NL80211_ATTR_BEACON_HEAD]) { 4291 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); 4292 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); 4293 if (!bcn->head_len) 4294 return -EINVAL; 4295 haveinfo = true; 4296 } 4297 4298 if (attrs[NL80211_ATTR_BEACON_TAIL]) { 4299 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); 4300 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); 4301 haveinfo = true; 4302 } 4303 4304 if (!haveinfo) 4305 return -EINVAL; 4306 4307 if (attrs[NL80211_ATTR_IE]) { 4308 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); 4309 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); 4310 } 4311 4312 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { 4313 bcn->proberesp_ies = 4314 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); 4315 bcn->proberesp_ies_len = 4316 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); 4317 } 4318 4319 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { 4320 bcn->assocresp_ies = 4321 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 4322 bcn->assocresp_ies_len = 4323 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 4324 } 4325 4326 if (attrs[NL80211_ATTR_PROBE_RESP]) { 4327 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); 4328 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); 4329 } 4330 4331 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 4332 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 4333 4334 err = nla_parse_nested_deprecated(tb, 4335 NL80211_FTM_RESP_ATTR_MAX, 4336 attrs[NL80211_ATTR_FTM_RESPONDER], 4337 NULL, NULL); 4338 if (err) 4339 return err; 4340 4341 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && 4342 wiphy_ext_feature_isset(&rdev->wiphy, 4343 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 4344 bcn->ftm_responder = 1; 4345 else 4346 return -EOPNOTSUPP; 4347 4348 if (tb[NL80211_FTM_RESP_ATTR_LCI]) { 4349 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); 4350 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); 4351 } 4352 4353 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { 4354 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 4355 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 4356 } 4357 } else { 4358 bcn->ftm_responder = -1; 4359 } 4360 4361 return 0; 4362 } 4363 4364 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, 4365 const u8 *rates) 4366 { 4367 int i; 4368 4369 if (!rates) 4370 return; 4371 4372 for (i = 0; i < rates[1]; i++) { 4373 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 4374 params->ht_required = true; 4375 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) 4376 params->vht_required = true; 4377 } 4378 } 4379 4380 /* 4381 * Since the nl80211 API didn't include, from the beginning, attributes about 4382 * HT/VHT requirements/capabilities, we parse them out of the IEs for the 4383 * benefit of drivers that rebuild IEs in the firmware. 4384 */ 4385 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) 4386 { 4387 const struct cfg80211_beacon_data *bcn = ¶ms->beacon; 4388 size_t ies_len = bcn->tail_len; 4389 const u8 *ies = bcn->tail; 4390 const u8 *rates; 4391 const u8 *cap; 4392 4393 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); 4394 nl80211_check_ap_rate_selectors(params, rates); 4395 4396 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); 4397 nl80211_check_ap_rate_selectors(params, rates); 4398 4399 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); 4400 if (cap && cap[1] >= sizeof(*params->ht_cap)) 4401 params->ht_cap = (void *)(cap + 2); 4402 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); 4403 if (cap && cap[1] >= sizeof(*params->vht_cap)) 4404 params->vht_cap = (void *)(cap + 2); 4405 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); 4406 if (cap && cap[1] >= sizeof(*params->he_cap) + 1) 4407 params->he_cap = (void *)(cap + 3); 4408 } 4409 4410 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, 4411 struct cfg80211_ap_settings *params) 4412 { 4413 struct wireless_dev *wdev; 4414 bool ret = false; 4415 4416 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 4417 if (wdev->iftype != NL80211_IFTYPE_AP && 4418 wdev->iftype != NL80211_IFTYPE_P2P_GO) 4419 continue; 4420 4421 if (!wdev->preset_chandef.chan) 4422 continue; 4423 4424 params->chandef = wdev->preset_chandef; 4425 ret = true; 4426 break; 4427 } 4428 4429 return ret; 4430 } 4431 4432 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, 4433 enum nl80211_auth_type auth_type, 4434 enum nl80211_commands cmd) 4435 { 4436 if (auth_type > NL80211_AUTHTYPE_MAX) 4437 return false; 4438 4439 switch (cmd) { 4440 case NL80211_CMD_AUTHENTICATE: 4441 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 4442 auth_type == NL80211_AUTHTYPE_SAE) 4443 return false; 4444 if (!wiphy_ext_feature_isset(&rdev->wiphy, 4445 NL80211_EXT_FEATURE_FILS_STA) && 4446 (auth_type == NL80211_AUTHTYPE_FILS_SK || 4447 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 4448 auth_type == NL80211_AUTHTYPE_FILS_PK)) 4449 return false; 4450 return true; 4451 case NL80211_CMD_CONNECT: 4452 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 4453 !wiphy_ext_feature_isset(&rdev->wiphy, 4454 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 4455 auth_type == NL80211_AUTHTYPE_SAE) 4456 return false; 4457 4458 /* FILS with SK PFS or PK not supported yet */ 4459 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 4460 auth_type == NL80211_AUTHTYPE_FILS_PK) 4461 return false; 4462 if (!wiphy_ext_feature_isset( 4463 &rdev->wiphy, 4464 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 4465 auth_type == NL80211_AUTHTYPE_FILS_SK) 4466 return false; 4467 return true; 4468 case NL80211_CMD_START_AP: 4469 /* SAE not supported yet */ 4470 if (auth_type == NL80211_AUTHTYPE_SAE) 4471 return false; 4472 /* FILS not supported yet */ 4473 if (auth_type == NL80211_AUTHTYPE_FILS_SK || 4474 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 4475 auth_type == NL80211_AUTHTYPE_FILS_PK) 4476 return false; 4477 return true; 4478 default: 4479 return false; 4480 } 4481 } 4482 4483 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) 4484 { 4485 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4486 struct net_device *dev = info->user_ptr[1]; 4487 struct wireless_dev *wdev = dev->ieee80211_ptr; 4488 struct cfg80211_ap_settings params; 4489 int err; 4490 4491 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4492 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4493 return -EOPNOTSUPP; 4494 4495 if (!rdev->ops->start_ap) 4496 return -EOPNOTSUPP; 4497 4498 if (wdev->beacon_interval) 4499 return -EALREADY; 4500 4501 memset(¶ms, 0, sizeof(params)); 4502 4503 /* these are required for START_AP */ 4504 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 4505 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 4506 !info->attrs[NL80211_ATTR_BEACON_HEAD]) 4507 return -EINVAL; 4508 4509 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); 4510 if (err) 4511 return err; 4512 4513 params.beacon_interval = 4514 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 4515 params.dtim_period = 4516 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 4517 4518 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, 4519 params.beacon_interval); 4520 if (err) 4521 return err; 4522 4523 /* 4524 * In theory, some of these attributes should be required here 4525 * but since they were not used when the command was originally 4526 * added, keep them optional for old user space programs to let 4527 * them continue to work with drivers that do not need the 4528 * additional information -- drivers must check! 4529 */ 4530 if (info->attrs[NL80211_ATTR_SSID]) { 4531 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 4532 params.ssid_len = 4533 nla_len(info->attrs[NL80211_ATTR_SSID]); 4534 if (params.ssid_len == 0 || 4535 params.ssid_len > IEEE80211_MAX_SSID_LEN) 4536 return -EINVAL; 4537 } 4538 4539 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) 4540 params.hidden_ssid = nla_get_u32( 4541 info->attrs[NL80211_ATTR_HIDDEN_SSID]); 4542 4543 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 4544 4545 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 4546 params.auth_type = nla_get_u32( 4547 info->attrs[NL80211_ATTR_AUTH_TYPE]); 4548 if (!nl80211_valid_auth_type(rdev, params.auth_type, 4549 NL80211_CMD_START_AP)) 4550 return -EINVAL; 4551 } else 4552 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 4553 4554 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, 4555 NL80211_MAX_NR_CIPHER_SUITES); 4556 if (err) 4557 return err; 4558 4559 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { 4560 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) 4561 return -EOPNOTSUPP; 4562 params.inactivity_timeout = nla_get_u16( 4563 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 4564 } 4565 4566 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 4567 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4568 return -EINVAL; 4569 params.p2p_ctwindow = 4570 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 4571 if (params.p2p_ctwindow != 0 && 4572 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 4573 return -EINVAL; 4574 } 4575 4576 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 4577 u8 tmp; 4578 4579 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4580 return -EINVAL; 4581 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 4582 params.p2p_opp_ps = tmp; 4583 if (params.p2p_opp_ps != 0 && 4584 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 4585 return -EINVAL; 4586 } 4587 4588 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 4589 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 4590 if (err) 4591 return err; 4592 } else if (wdev->preset_chandef.chan) { 4593 params.chandef = wdev->preset_chandef; 4594 } else if (!nl80211_get_ap_channel(rdev, ¶ms)) 4595 return -EINVAL; 4596 4597 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 4598 wdev->iftype)) 4599 return -EINVAL; 4600 4601 if (info->attrs[NL80211_ATTR_TX_RATES]) { 4602 err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); 4603 if (err) 4604 return err; 4605 4606 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, 4607 ¶ms.beacon_rate); 4608 if (err) 4609 return err; 4610 } 4611 4612 if (info->attrs[NL80211_ATTR_SMPS_MODE]) { 4613 params.smps_mode = 4614 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); 4615 switch (params.smps_mode) { 4616 case NL80211_SMPS_OFF: 4617 break; 4618 case NL80211_SMPS_STATIC: 4619 if (!(rdev->wiphy.features & 4620 NL80211_FEATURE_STATIC_SMPS)) 4621 return -EINVAL; 4622 break; 4623 case NL80211_SMPS_DYNAMIC: 4624 if (!(rdev->wiphy.features & 4625 NL80211_FEATURE_DYNAMIC_SMPS)) 4626 return -EINVAL; 4627 break; 4628 default: 4629 return -EINVAL; 4630 } 4631 } else { 4632 params.smps_mode = NL80211_SMPS_OFF; 4633 } 4634 4635 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 4636 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) 4637 return -EOPNOTSUPP; 4638 4639 if (info->attrs[NL80211_ATTR_ACL_POLICY]) { 4640 params.acl = parse_acl_data(&rdev->wiphy, info); 4641 if (IS_ERR(params.acl)) 4642 return PTR_ERR(params.acl); 4643 } 4644 4645 params.twt_responder = 4646 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); 4647 4648 nl80211_calculate_ap_params(¶ms); 4649 4650 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) 4651 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; 4652 4653 wdev_lock(wdev); 4654 err = rdev_start_ap(rdev, dev, ¶ms); 4655 if (!err) { 4656 wdev->preset_chandef = params.chandef; 4657 wdev->beacon_interval = params.beacon_interval; 4658 wdev->chandef = params.chandef; 4659 wdev->ssid_len = params.ssid_len; 4660 memcpy(wdev->ssid, params.ssid, wdev->ssid_len); 4661 4662 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 4663 wdev->conn_owner_nlportid = info->snd_portid; 4664 } 4665 wdev_unlock(wdev); 4666 4667 kfree(params.acl); 4668 4669 return err; 4670 } 4671 4672 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) 4673 { 4674 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4675 struct net_device *dev = info->user_ptr[1]; 4676 struct wireless_dev *wdev = dev->ieee80211_ptr; 4677 struct cfg80211_beacon_data params; 4678 int err; 4679 4680 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4681 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4682 return -EOPNOTSUPP; 4683 4684 if (!rdev->ops->change_beacon) 4685 return -EOPNOTSUPP; 4686 4687 if (!wdev->beacon_interval) 4688 return -EINVAL; 4689 4690 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); 4691 if (err) 4692 return err; 4693 4694 wdev_lock(wdev); 4695 err = rdev_change_beacon(rdev, dev, ¶ms); 4696 wdev_unlock(wdev); 4697 4698 return err; 4699 } 4700 4701 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) 4702 { 4703 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4704 struct net_device *dev = info->user_ptr[1]; 4705 4706 return cfg80211_stop_ap(rdev, dev, false); 4707 } 4708 4709 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { 4710 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, 4711 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 4712 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 4713 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 4714 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, 4715 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, 4716 }; 4717 4718 static int parse_station_flags(struct genl_info *info, 4719 enum nl80211_iftype iftype, 4720 struct station_parameters *params) 4721 { 4722 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 4723 struct nlattr *nla; 4724 int flag; 4725 4726 /* 4727 * Try parsing the new attribute first so userspace 4728 * can specify both for older kernels. 4729 */ 4730 nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; 4731 if (nla) { 4732 struct nl80211_sta_flag_update *sta_flags; 4733 4734 sta_flags = nla_data(nla); 4735 params->sta_flags_mask = sta_flags->mask; 4736 params->sta_flags_set = sta_flags->set; 4737 params->sta_flags_set &= params->sta_flags_mask; 4738 if ((params->sta_flags_mask | 4739 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) 4740 return -EINVAL; 4741 return 0; 4742 } 4743 4744 /* if present, parse the old attribute */ 4745 4746 nla = info->attrs[NL80211_ATTR_STA_FLAGS]; 4747 if (!nla) 4748 return 0; 4749 4750 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) 4751 return -EINVAL; 4752 4753 /* 4754 * Only allow certain flags for interface types so that 4755 * other attributes are silently ignored. Remember that 4756 * this is backward compatibility code with old userspace 4757 * and shouldn't be hit in other cases anyway. 4758 */ 4759 switch (iftype) { 4760 case NL80211_IFTYPE_AP: 4761 case NL80211_IFTYPE_AP_VLAN: 4762 case NL80211_IFTYPE_P2P_GO: 4763 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 4764 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 4765 BIT(NL80211_STA_FLAG_WME) | 4766 BIT(NL80211_STA_FLAG_MFP); 4767 break; 4768 case NL80211_IFTYPE_P2P_CLIENT: 4769 case NL80211_IFTYPE_STATION: 4770 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 4771 BIT(NL80211_STA_FLAG_TDLS_PEER); 4772 break; 4773 case NL80211_IFTYPE_MESH_POINT: 4774 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 4775 BIT(NL80211_STA_FLAG_MFP) | 4776 BIT(NL80211_STA_FLAG_AUTHORIZED); 4777 break; 4778 default: 4779 return -EINVAL; 4780 } 4781 4782 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { 4783 if (flags[flag]) { 4784 params->sta_flags_set |= (1<<flag); 4785 4786 /* no longer support new API additions in old API */ 4787 if (flag > NL80211_STA_FLAG_MAX_OLD_API) 4788 return -EINVAL; 4789 } 4790 } 4791 4792 return 0; 4793 } 4794 4795 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) 4796 { 4797 struct nlattr *rate; 4798 u32 bitrate; 4799 u16 bitrate_compat; 4800 enum nl80211_rate_info rate_flg; 4801 4802 rate = nla_nest_start_noflag(msg, attr); 4803 if (!rate) 4804 return false; 4805 4806 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ 4807 bitrate = cfg80211_calculate_bitrate(info); 4808 /* report 16-bit bitrate only if we can */ 4809 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; 4810 if (bitrate > 0 && 4811 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) 4812 return false; 4813 if (bitrate_compat > 0 && 4814 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) 4815 return false; 4816 4817 switch (info->bw) { 4818 case RATE_INFO_BW_5: 4819 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; 4820 break; 4821 case RATE_INFO_BW_10: 4822 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; 4823 break; 4824 default: 4825 WARN_ON(1); 4826 /* fall through */ 4827 case RATE_INFO_BW_20: 4828 rate_flg = 0; 4829 break; 4830 case RATE_INFO_BW_40: 4831 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; 4832 break; 4833 case RATE_INFO_BW_80: 4834 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; 4835 break; 4836 case RATE_INFO_BW_160: 4837 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; 4838 break; 4839 case RATE_INFO_BW_HE_RU: 4840 rate_flg = 0; 4841 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); 4842 } 4843 4844 if (rate_flg && nla_put_flag(msg, rate_flg)) 4845 return false; 4846 4847 if (info->flags & RATE_INFO_FLAGS_MCS) { 4848 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) 4849 return false; 4850 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 4851 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 4852 return false; 4853 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { 4854 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) 4855 return false; 4856 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) 4857 return false; 4858 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 4859 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 4860 return false; 4861 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { 4862 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) 4863 return false; 4864 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) 4865 return false; 4866 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) 4867 return false; 4868 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) 4869 return false; 4870 if (info->bw == RATE_INFO_BW_HE_RU && 4871 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, 4872 info->he_ru_alloc)) 4873 return false; 4874 } 4875 4876 nla_nest_end(msg, rate); 4877 return true; 4878 } 4879 4880 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, 4881 int id) 4882 { 4883 void *attr; 4884 int i = 0; 4885 4886 if (!mask) 4887 return true; 4888 4889 attr = nla_nest_start_noflag(msg, id); 4890 if (!attr) 4891 return false; 4892 4893 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 4894 if (!(mask & BIT(i))) 4895 continue; 4896 4897 if (nla_put_u8(msg, i, signal[i])) 4898 return false; 4899 } 4900 4901 nla_nest_end(msg, attr); 4902 4903 return true; 4904 } 4905 4906 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, 4907 u32 seq, int flags, 4908 struct cfg80211_registered_device *rdev, 4909 struct net_device *dev, 4910 const u8 *mac_addr, struct station_info *sinfo) 4911 { 4912 void *hdr; 4913 struct nlattr *sinfoattr, *bss_param; 4914 4915 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 4916 if (!hdr) { 4917 cfg80211_sinfo_release_content(sinfo); 4918 return -1; 4919 } 4920 4921 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 4922 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 4923 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 4924 goto nla_put_failure; 4925 4926 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); 4927 if (!sinfoattr) 4928 goto nla_put_failure; 4929 4930 #define PUT_SINFO(attr, memb, type) do { \ 4931 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ 4932 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 4933 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ 4934 sinfo->memb)) \ 4935 goto nla_put_failure; \ 4936 } while (0) 4937 #define PUT_SINFO_U64(attr, memb) do { \ 4938 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 4939 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ 4940 sinfo->memb, NL80211_STA_INFO_PAD)) \ 4941 goto nla_put_failure; \ 4942 } while (0) 4943 4944 PUT_SINFO(CONNECTED_TIME, connected_time, u32); 4945 PUT_SINFO(INACTIVE_TIME, inactive_time, u32); 4946 4947 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | 4948 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && 4949 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, 4950 (u32)sinfo->rx_bytes)) 4951 goto nla_put_failure; 4952 4953 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 4954 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && 4955 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, 4956 (u32)sinfo->tx_bytes)) 4957 goto nla_put_failure; 4958 4959 PUT_SINFO_U64(RX_BYTES64, rx_bytes); 4960 PUT_SINFO_U64(TX_BYTES64, tx_bytes); 4961 PUT_SINFO(LLID, llid, u16); 4962 PUT_SINFO(PLID, plid, u16); 4963 PUT_SINFO(PLINK_STATE, plink_state, u8); 4964 PUT_SINFO_U64(RX_DURATION, rx_duration); 4965 PUT_SINFO_U64(TX_DURATION, tx_duration); 4966 4967 if (wiphy_ext_feature_isset(&rdev->wiphy, 4968 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 4969 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); 4970 4971 switch (rdev->wiphy.signal_type) { 4972 case CFG80211_SIGNAL_TYPE_MBM: 4973 PUT_SINFO(SIGNAL, signal, u8); 4974 PUT_SINFO(SIGNAL_AVG, signal_avg, u8); 4975 break; 4976 default: 4977 break; 4978 } 4979 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { 4980 if (!nl80211_put_signal(msg, sinfo->chains, 4981 sinfo->chain_signal, 4982 NL80211_STA_INFO_CHAIN_SIGNAL)) 4983 goto nla_put_failure; 4984 } 4985 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { 4986 if (!nl80211_put_signal(msg, sinfo->chains, 4987 sinfo->chain_signal_avg, 4988 NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) 4989 goto nla_put_failure; 4990 } 4991 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { 4992 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 4993 NL80211_STA_INFO_TX_BITRATE)) 4994 goto nla_put_failure; 4995 } 4996 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { 4997 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, 4998 NL80211_STA_INFO_RX_BITRATE)) 4999 goto nla_put_failure; 5000 } 5001 5002 PUT_SINFO(RX_PACKETS, rx_packets, u32); 5003 PUT_SINFO(TX_PACKETS, tx_packets, u32); 5004 PUT_SINFO(TX_RETRIES, tx_retries, u32); 5005 PUT_SINFO(TX_FAILED, tx_failed, u32); 5006 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 5007 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); 5008 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 5009 PUT_SINFO(LOCAL_PM, local_pm, u32); 5010 PUT_SINFO(PEER_PM, peer_pm, u32); 5011 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); 5012 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 5013 5014 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 5015 bss_param = nla_nest_start_noflag(msg, 5016 NL80211_STA_INFO_BSS_PARAM); 5017 if (!bss_param) 5018 goto nla_put_failure; 5019 5020 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && 5021 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || 5022 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && 5023 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || 5024 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && 5025 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || 5026 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, 5027 sinfo->bss_param.dtim_period) || 5028 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, 5029 sinfo->bss_param.beacon_interval)) 5030 goto nla_put_failure; 5031 5032 nla_nest_end(msg, bss_param); 5033 } 5034 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && 5035 nla_put(msg, NL80211_STA_INFO_STA_FLAGS, 5036 sizeof(struct nl80211_sta_flag_update), 5037 &sinfo->sta_flags)) 5038 goto nla_put_failure; 5039 5040 PUT_SINFO_U64(T_OFFSET, t_offset); 5041 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); 5042 PUT_SINFO_U64(BEACON_RX, rx_beacon); 5043 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); 5044 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); 5045 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); 5046 if (wiphy_ext_feature_isset(&rdev->wiphy, 5047 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { 5048 PUT_SINFO(ACK_SIGNAL, ack_signal, u8); 5049 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); 5050 } 5051 5052 #undef PUT_SINFO 5053 #undef PUT_SINFO_U64 5054 5055 if (sinfo->pertid) { 5056 struct nlattr *tidsattr; 5057 int tid; 5058 5059 tidsattr = nla_nest_start_noflag(msg, 5060 NL80211_STA_INFO_TID_STATS); 5061 if (!tidsattr) 5062 goto nla_put_failure; 5063 5064 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { 5065 struct cfg80211_tid_stats *tidstats; 5066 struct nlattr *tidattr; 5067 5068 tidstats = &sinfo->pertid[tid]; 5069 5070 if (!tidstats->filled) 5071 continue; 5072 5073 tidattr = nla_nest_start_noflag(msg, tid + 1); 5074 if (!tidattr) 5075 goto nla_put_failure; 5076 5077 #define PUT_TIDVAL_U64(attr, memb) do { \ 5078 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ 5079 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ 5080 tidstats->memb, NL80211_TID_STATS_PAD)) \ 5081 goto nla_put_failure; \ 5082 } while (0) 5083 5084 PUT_TIDVAL_U64(RX_MSDU, rx_msdu); 5085 PUT_TIDVAL_U64(TX_MSDU, tx_msdu); 5086 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); 5087 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); 5088 5089 #undef PUT_TIDVAL_U64 5090 if ((tidstats->filled & 5091 BIT(NL80211_TID_STATS_TXQ_STATS)) && 5092 !nl80211_put_txq_stats(msg, &tidstats->txq_stats, 5093 NL80211_TID_STATS_TXQ_STATS)) 5094 goto nla_put_failure; 5095 5096 nla_nest_end(msg, tidattr); 5097 } 5098 5099 nla_nest_end(msg, tidsattr); 5100 } 5101 5102 nla_nest_end(msg, sinfoattr); 5103 5104 if (sinfo->assoc_req_ies_len && 5105 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, 5106 sinfo->assoc_req_ies)) 5107 goto nla_put_failure; 5108 5109 cfg80211_sinfo_release_content(sinfo); 5110 genlmsg_end(msg, hdr); 5111 return 0; 5112 5113 nla_put_failure: 5114 cfg80211_sinfo_release_content(sinfo); 5115 genlmsg_cancel(msg, hdr); 5116 return -EMSGSIZE; 5117 } 5118 5119 static int nl80211_dump_station(struct sk_buff *skb, 5120 struct netlink_callback *cb) 5121 { 5122 struct station_info sinfo; 5123 struct cfg80211_registered_device *rdev; 5124 struct wireless_dev *wdev; 5125 u8 mac_addr[ETH_ALEN]; 5126 int sta_idx = cb->args[2]; 5127 int err; 5128 5129 rtnl_lock(); 5130 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 5131 if (err) 5132 goto out_err; 5133 5134 if (!wdev->netdev) { 5135 err = -EINVAL; 5136 goto out_err; 5137 } 5138 5139 if (!rdev->ops->dump_station) { 5140 err = -EOPNOTSUPP; 5141 goto out_err; 5142 } 5143 5144 while (1) { 5145 memset(&sinfo, 0, sizeof(sinfo)); 5146 err = rdev_dump_station(rdev, wdev->netdev, sta_idx, 5147 mac_addr, &sinfo); 5148 if (err == -ENOENT) 5149 break; 5150 if (err) 5151 goto out_err; 5152 5153 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, 5154 NETLINK_CB(cb->skb).portid, 5155 cb->nlh->nlmsg_seq, NLM_F_MULTI, 5156 rdev, wdev->netdev, mac_addr, 5157 &sinfo) < 0) 5158 goto out; 5159 5160 sta_idx++; 5161 } 5162 5163 out: 5164 cb->args[2] = sta_idx; 5165 err = skb->len; 5166 out_err: 5167 rtnl_unlock(); 5168 5169 return err; 5170 } 5171 5172 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 5173 { 5174 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5175 struct net_device *dev = info->user_ptr[1]; 5176 struct station_info sinfo; 5177 struct sk_buff *msg; 5178 u8 *mac_addr = NULL; 5179 int err; 5180 5181 memset(&sinfo, 0, sizeof(sinfo)); 5182 5183 if (!info->attrs[NL80211_ATTR_MAC]) 5184 return -EINVAL; 5185 5186 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 5187 5188 if (!rdev->ops->get_station) 5189 return -EOPNOTSUPP; 5190 5191 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 5192 if (err) 5193 return err; 5194 5195 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 5196 if (!msg) { 5197 cfg80211_sinfo_release_content(&sinfo); 5198 return -ENOMEM; 5199 } 5200 5201 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 5202 info->snd_portid, info->snd_seq, 0, 5203 rdev, dev, mac_addr, &sinfo) < 0) { 5204 nlmsg_free(msg); 5205 return -ENOBUFS; 5206 } 5207 5208 return genlmsg_reply(msg, info); 5209 } 5210 5211 int cfg80211_check_station_change(struct wiphy *wiphy, 5212 struct station_parameters *params, 5213 enum cfg80211_station_type statype) 5214 { 5215 if (params->listen_interval != -1 && 5216 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 5217 return -EINVAL; 5218 5219 if (params->support_p2p_ps != -1 && 5220 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 5221 return -EINVAL; 5222 5223 if (params->aid && 5224 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && 5225 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 5226 return -EINVAL; 5227 5228 /* When you run into this, adjust the code below for the new flag */ 5229 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 5230 5231 switch (statype) { 5232 case CFG80211_STA_MESH_PEER_KERNEL: 5233 case CFG80211_STA_MESH_PEER_USER: 5234 /* 5235 * No ignoring the TDLS flag here -- the userspace mesh 5236 * code doesn't have the bug of including TDLS in the 5237 * mask everywhere. 5238 */ 5239 if (params->sta_flags_mask & 5240 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5241 BIT(NL80211_STA_FLAG_MFP) | 5242 BIT(NL80211_STA_FLAG_AUTHORIZED))) 5243 return -EINVAL; 5244 break; 5245 case CFG80211_STA_TDLS_PEER_SETUP: 5246 case CFG80211_STA_TDLS_PEER_ACTIVE: 5247 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 5248 return -EINVAL; 5249 /* ignore since it can't change */ 5250 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 5251 break; 5252 default: 5253 /* disallow mesh-specific things */ 5254 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) 5255 return -EINVAL; 5256 if (params->local_pm) 5257 return -EINVAL; 5258 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 5259 return -EINVAL; 5260 } 5261 5262 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 5263 statype != CFG80211_STA_TDLS_PEER_ACTIVE) { 5264 /* TDLS can't be set, ... */ 5265 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 5266 return -EINVAL; 5267 /* 5268 * ... but don't bother the driver with it. This works around 5269 * a hostapd/wpa_supplicant issue -- it always includes the 5270 * TLDS_PEER flag in the mask even for AP mode. 5271 */ 5272 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 5273 } 5274 5275 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 5276 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 5277 /* reject other things that can't change */ 5278 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) 5279 return -EINVAL; 5280 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) 5281 return -EINVAL; 5282 if (params->supported_rates) 5283 return -EINVAL; 5284 if (params->ext_capab || params->ht_capa || params->vht_capa || 5285 params->he_capa) 5286 return -EINVAL; 5287 } 5288 5289 if (statype != CFG80211_STA_AP_CLIENT && 5290 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 5291 if (params->vlan) 5292 return -EINVAL; 5293 } 5294 5295 switch (statype) { 5296 case CFG80211_STA_AP_MLME_CLIENT: 5297 /* Use this only for authorizing/unauthorizing a station */ 5298 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 5299 return -EOPNOTSUPP; 5300 break; 5301 case CFG80211_STA_AP_CLIENT: 5302 case CFG80211_STA_AP_CLIENT_UNASSOC: 5303 /* accept only the listed bits */ 5304 if (params->sta_flags_mask & 5305 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 5306 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5307 BIT(NL80211_STA_FLAG_ASSOCIATED) | 5308 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 5309 BIT(NL80211_STA_FLAG_WME) | 5310 BIT(NL80211_STA_FLAG_MFP))) 5311 return -EINVAL; 5312 5313 /* but authenticated/associated only if driver handles it */ 5314 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 5315 params->sta_flags_mask & 5316 (BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5317 BIT(NL80211_STA_FLAG_ASSOCIATED))) 5318 return -EINVAL; 5319 break; 5320 case CFG80211_STA_IBSS: 5321 case CFG80211_STA_AP_STA: 5322 /* reject any changes other than AUTHORIZED */ 5323 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 5324 return -EINVAL; 5325 break; 5326 case CFG80211_STA_TDLS_PEER_SETUP: 5327 /* reject any changes other than AUTHORIZED or WME */ 5328 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 5329 BIT(NL80211_STA_FLAG_WME))) 5330 return -EINVAL; 5331 /* force (at least) rates when authorizing */ 5332 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && 5333 !params->supported_rates) 5334 return -EINVAL; 5335 break; 5336 case CFG80211_STA_TDLS_PEER_ACTIVE: 5337 /* reject any changes */ 5338 return -EINVAL; 5339 case CFG80211_STA_MESH_PEER_KERNEL: 5340 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 5341 return -EINVAL; 5342 break; 5343 case CFG80211_STA_MESH_PEER_USER: 5344 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && 5345 params->plink_action != NL80211_PLINK_ACTION_BLOCK) 5346 return -EINVAL; 5347 break; 5348 } 5349 5350 /* 5351 * Older kernel versions ignored this attribute entirely, so don't 5352 * reject attempts to update it but mark it as unused instead so the 5353 * driver won't look at the data. 5354 */ 5355 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && 5356 statype != CFG80211_STA_TDLS_PEER_SETUP) 5357 params->opmode_notif_used = false; 5358 5359 return 0; 5360 } 5361 EXPORT_SYMBOL(cfg80211_check_station_change); 5362 5363 /* 5364 * Get vlan interface making sure it is running and on the right wiphy. 5365 */ 5366 static struct net_device *get_vlan(struct genl_info *info, 5367 struct cfg80211_registered_device *rdev) 5368 { 5369 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; 5370 struct net_device *v; 5371 int ret; 5372 5373 if (!vlanattr) 5374 return NULL; 5375 5376 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); 5377 if (!v) 5378 return ERR_PTR(-ENODEV); 5379 5380 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { 5381 ret = -EINVAL; 5382 goto error; 5383 } 5384 5385 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 5386 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5387 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 5388 ret = -EINVAL; 5389 goto error; 5390 } 5391 5392 if (!netif_running(v)) { 5393 ret = -ENETDOWN; 5394 goto error; 5395 } 5396 5397 return v; 5398 error: 5399 dev_put(v); 5400 return ERR_PTR(ret); 5401 } 5402 5403 static const struct nla_policy 5404 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { 5405 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, 5406 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, 5407 }; 5408 5409 static int nl80211_parse_sta_wme(struct genl_info *info, 5410 struct station_parameters *params) 5411 { 5412 struct nlattr *tb[NL80211_STA_WME_MAX + 1]; 5413 struct nlattr *nla; 5414 int err; 5415 5416 /* parse WME attributes if present */ 5417 if (!info->attrs[NL80211_ATTR_STA_WME]) 5418 return 0; 5419 5420 nla = info->attrs[NL80211_ATTR_STA_WME]; 5421 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, 5422 nl80211_sta_wme_policy, 5423 info->extack); 5424 if (err) 5425 return err; 5426 5427 if (tb[NL80211_STA_WME_UAPSD_QUEUES]) 5428 params->uapsd_queues = nla_get_u8( 5429 tb[NL80211_STA_WME_UAPSD_QUEUES]); 5430 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) 5431 return -EINVAL; 5432 5433 if (tb[NL80211_STA_WME_MAX_SP]) 5434 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); 5435 5436 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) 5437 return -EINVAL; 5438 5439 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; 5440 5441 return 0; 5442 } 5443 5444 static int nl80211_parse_sta_channel_info(struct genl_info *info, 5445 struct station_parameters *params) 5446 { 5447 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { 5448 params->supported_channels = 5449 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 5450 params->supported_channels_len = 5451 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 5452 /* 5453 * Need to include at least one (first channel, number of 5454 * channels) tuple for each subband, and must have proper 5455 * tuples for the rest of the data as well. 5456 */ 5457 if (params->supported_channels_len < 2) 5458 return -EINVAL; 5459 if (params->supported_channels_len % 2) 5460 return -EINVAL; 5461 } 5462 5463 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { 5464 params->supported_oper_classes = 5465 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 5466 params->supported_oper_classes_len = 5467 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 5468 /* 5469 * The value of the Length field of the Supported Operating 5470 * Classes element is between 2 and 253. 5471 */ 5472 if (params->supported_oper_classes_len < 2 || 5473 params->supported_oper_classes_len > 253) 5474 return -EINVAL; 5475 } 5476 return 0; 5477 } 5478 5479 static int nl80211_set_station_tdls(struct genl_info *info, 5480 struct station_parameters *params) 5481 { 5482 int err; 5483 /* Dummy STA entry gets updated once the peer capabilities are known */ 5484 if (info->attrs[NL80211_ATTR_PEER_AID]) 5485 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 5486 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 5487 params->ht_capa = 5488 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 5489 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 5490 params->vht_capa = 5491 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 5492 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 5493 params->he_capa = 5494 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 5495 params->he_capa_len = 5496 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 5497 5498 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) 5499 return -EINVAL; 5500 } 5501 5502 err = nl80211_parse_sta_channel_info(info, params); 5503 if (err) 5504 return err; 5505 5506 return nl80211_parse_sta_wme(info, params); 5507 } 5508 5509 static int nl80211_parse_sta_txpower_setting(struct genl_info *info, 5510 struct station_parameters *params) 5511 { 5512 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5513 int idx; 5514 5515 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { 5516 if (!rdev->ops->set_tx_power || 5517 !wiphy_ext_feature_isset(&rdev->wiphy, 5518 NL80211_EXT_FEATURE_STA_TX_PWR)) 5519 return -EOPNOTSUPP; 5520 5521 idx = NL80211_ATTR_STA_TX_POWER_SETTING; 5522 params->txpwr.type = nla_get_u8(info->attrs[idx]); 5523 5524 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { 5525 idx = NL80211_ATTR_STA_TX_POWER; 5526 5527 if (info->attrs[idx]) 5528 params->txpwr.power = 5529 nla_get_s16(info->attrs[idx]); 5530 else 5531 return -EINVAL; 5532 } 5533 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; 5534 } 5535 5536 return 0; 5537 } 5538 5539 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 5540 { 5541 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5542 struct net_device *dev = info->user_ptr[1]; 5543 struct station_parameters params; 5544 u8 *mac_addr; 5545 int err; 5546 5547 memset(¶ms, 0, sizeof(params)); 5548 5549 if (!rdev->ops->change_station) 5550 return -EOPNOTSUPP; 5551 5552 /* 5553 * AID and listen_interval properties can be set only for unassociated 5554 * station. Include these parameters here and will check them in 5555 * cfg80211_check_station_change(). 5556 */ 5557 if (info->attrs[NL80211_ATTR_STA_AID]) 5558 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 5559 5560 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 5561 params.listen_interval = 5562 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 5563 else 5564 params.listen_interval = -1; 5565 5566 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) 5567 params.support_p2p_ps = 5568 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 5569 else 5570 params.support_p2p_ps = -1; 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 (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 5578 params.supported_rates = 5579 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 5580 params.supported_rates_len = 5581 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 5582 } 5583 5584 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 5585 params.capability = 5586 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 5587 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 5588 } 5589 5590 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 5591 params.ext_capab = 5592 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 5593 params.ext_capab_len = 5594 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 5595 } 5596 5597 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 5598 return -EINVAL; 5599 5600 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 5601 params.plink_action = 5602 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 5603 5604 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { 5605 params.plink_state = 5606 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 5607 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) 5608 params.peer_aid = nla_get_u16( 5609 info->attrs[NL80211_ATTR_MESH_PEER_AID]); 5610 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; 5611 } 5612 5613 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) 5614 params.local_pm = nla_get_u32( 5615 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); 5616 5617 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 5618 params.opmode_notif_used = true; 5619 params.opmode_notif = 5620 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 5621 } 5622 5623 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 5624 params.airtime_weight = 5625 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 5626 5627 if (params.airtime_weight && 5628 !wiphy_ext_feature_isset(&rdev->wiphy, 5629 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 5630 return -EOPNOTSUPP; 5631 5632 err = nl80211_parse_sta_txpower_setting(info, ¶ms); 5633 if (err) 5634 return err; 5635 5636 /* Include parameters for TDLS peer (will check later) */ 5637 err = nl80211_set_station_tdls(info, ¶ms); 5638 if (err) 5639 return err; 5640 5641 params.vlan = get_vlan(info, rdev); 5642 if (IS_ERR(params.vlan)) 5643 return PTR_ERR(params.vlan); 5644 5645 switch (dev->ieee80211_ptr->iftype) { 5646 case NL80211_IFTYPE_AP: 5647 case NL80211_IFTYPE_AP_VLAN: 5648 case NL80211_IFTYPE_P2P_GO: 5649 case NL80211_IFTYPE_P2P_CLIENT: 5650 case NL80211_IFTYPE_STATION: 5651 case NL80211_IFTYPE_ADHOC: 5652 case NL80211_IFTYPE_MESH_POINT: 5653 break; 5654 default: 5655 err = -EOPNOTSUPP; 5656 goto out_put_vlan; 5657 } 5658 5659 /* driver will call cfg80211_check_station_change() */ 5660 err = rdev_change_station(rdev, dev, mac_addr, ¶ms); 5661 5662 out_put_vlan: 5663 if (params.vlan) 5664 dev_put(params.vlan); 5665 5666 return err; 5667 } 5668 5669 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 5670 { 5671 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5672 int err; 5673 struct net_device *dev = info->user_ptr[1]; 5674 struct station_parameters params; 5675 u8 *mac_addr = NULL; 5676 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 5677 BIT(NL80211_STA_FLAG_ASSOCIATED); 5678 5679 memset(¶ms, 0, sizeof(params)); 5680 5681 if (!rdev->ops->add_station) 5682 return -EOPNOTSUPP; 5683 5684 if (!info->attrs[NL80211_ATTR_MAC]) 5685 return -EINVAL; 5686 5687 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 5688 return -EINVAL; 5689 5690 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 5691 return -EINVAL; 5692 5693 if (!info->attrs[NL80211_ATTR_STA_AID] && 5694 !info->attrs[NL80211_ATTR_PEER_AID]) 5695 return -EINVAL; 5696 5697 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 5698 params.supported_rates = 5699 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 5700 params.supported_rates_len = 5701 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 5702 params.listen_interval = 5703 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 5704 5705 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { 5706 params.support_p2p_ps = 5707 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 5708 } else { 5709 /* 5710 * if not specified, assume it's supported for P2P GO interface, 5711 * and is NOT supported for AP interface 5712 */ 5713 params.support_p2p_ps = 5714 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; 5715 } 5716 5717 if (info->attrs[NL80211_ATTR_PEER_AID]) 5718 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 5719 else 5720 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 5721 5722 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 5723 params.capability = 5724 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 5725 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 5726 } 5727 5728 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 5729 params.ext_capab = 5730 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 5731 params.ext_capab_len = 5732 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 5733 } 5734 5735 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 5736 params.ht_capa = 5737 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 5738 5739 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 5740 params.vht_capa = 5741 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 5742 5743 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 5744 params.he_capa = 5745 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 5746 params.he_capa_len = 5747 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 5748 5749 /* max len is validated in nla policy */ 5750 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) 5751 return -EINVAL; 5752 } 5753 5754 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 5755 params.opmode_notif_used = true; 5756 params.opmode_notif = 5757 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 5758 } 5759 5760 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 5761 params.plink_action = 5762 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 5763 5764 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 5765 params.airtime_weight = 5766 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 5767 5768 if (params.airtime_weight && 5769 !wiphy_ext_feature_isset(&rdev->wiphy, 5770 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 5771 return -EOPNOTSUPP; 5772 5773 err = nl80211_parse_sta_txpower_setting(info, ¶ms); 5774 if (err) 5775 return err; 5776 5777 err = nl80211_parse_sta_channel_info(info, ¶ms); 5778 if (err) 5779 return err; 5780 5781 err = nl80211_parse_sta_wme(info, ¶ms); 5782 if (err) 5783 return err; 5784 5785 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 5786 return -EINVAL; 5787 5788 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT 5789 * as userspace might just pass through the capabilities from the IEs 5790 * directly, rather than enforcing this restriction and returning an 5791 * error in this case. 5792 */ 5793 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { 5794 params.ht_capa = NULL; 5795 params.vht_capa = NULL; 5796 5797 /* HE requires WME */ 5798 if (params.he_capa_len) 5799 return -EINVAL; 5800 } 5801 5802 /* When you run into this, adjust the code below for the new flag */ 5803 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 5804 5805 switch (dev->ieee80211_ptr->iftype) { 5806 case NL80211_IFTYPE_AP: 5807 case NL80211_IFTYPE_AP_VLAN: 5808 case NL80211_IFTYPE_P2P_GO: 5809 /* ignore WME attributes if iface/sta is not capable */ 5810 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || 5811 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) 5812 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 5813 5814 /* TDLS peers cannot be added */ 5815 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 5816 info->attrs[NL80211_ATTR_PEER_AID]) 5817 return -EINVAL; 5818 /* but don't bother the driver with it */ 5819 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 5820 5821 /* allow authenticated/associated only if driver handles it */ 5822 if (!(rdev->wiphy.features & 5823 NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 5824 params.sta_flags_mask & auth_assoc) 5825 return -EINVAL; 5826 5827 /* Older userspace, or userspace wanting to be compatible with 5828 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth 5829 * and assoc flags in the mask, but assumes the station will be 5830 * added as associated anyway since this was the required driver 5831 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was 5832 * introduced. 5833 * In order to not bother drivers with this quirk in the API 5834 * set the flags in both the mask and set for new stations in 5835 * this case. 5836 */ 5837 if (!(params.sta_flags_mask & auth_assoc)) { 5838 params.sta_flags_mask |= auth_assoc; 5839 params.sta_flags_set |= auth_assoc; 5840 } 5841 5842 /* must be last in here for error handling */ 5843 params.vlan = get_vlan(info, rdev); 5844 if (IS_ERR(params.vlan)) 5845 return PTR_ERR(params.vlan); 5846 break; 5847 case NL80211_IFTYPE_MESH_POINT: 5848 /* ignore uAPSD data */ 5849 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 5850 5851 /* associated is disallowed */ 5852 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) 5853 return -EINVAL; 5854 /* TDLS peers cannot be added */ 5855 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 5856 info->attrs[NL80211_ATTR_PEER_AID]) 5857 return -EINVAL; 5858 break; 5859 case NL80211_IFTYPE_STATION: 5860 case NL80211_IFTYPE_P2P_CLIENT: 5861 /* ignore uAPSD data */ 5862 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 5863 5864 /* these are disallowed */ 5865 if (params.sta_flags_mask & 5866 (BIT(NL80211_STA_FLAG_ASSOCIATED) | 5867 BIT(NL80211_STA_FLAG_AUTHENTICATED))) 5868 return -EINVAL; 5869 /* Only TDLS peers can be added */ 5870 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 5871 return -EINVAL; 5872 /* Can only add if TDLS ... */ 5873 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) 5874 return -EOPNOTSUPP; 5875 /* ... with external setup is supported */ 5876 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 5877 return -EOPNOTSUPP; 5878 /* 5879 * Older wpa_supplicant versions always mark the TDLS peer 5880 * as authorized, but it shouldn't yet be. 5881 */ 5882 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); 5883 break; 5884 default: 5885 return -EOPNOTSUPP; 5886 } 5887 5888 /* be aware of params.vlan when changing code here */ 5889 5890 err = rdev_add_station(rdev, dev, mac_addr, ¶ms); 5891 5892 if (params.vlan) 5893 dev_put(params.vlan); 5894 return err; 5895 } 5896 5897 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 5898 { 5899 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5900 struct net_device *dev = info->user_ptr[1]; 5901 struct station_del_parameters params; 5902 5903 memset(¶ms, 0, sizeof(params)); 5904 5905 if (info->attrs[NL80211_ATTR_MAC]) 5906 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 5907 5908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5909 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 5910 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 5911 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5912 return -EINVAL; 5913 5914 if (!rdev->ops->del_station) 5915 return -EOPNOTSUPP; 5916 5917 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { 5918 params.subtype = 5919 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); 5920 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && 5921 params.subtype != IEEE80211_STYPE_DEAUTH >> 4) 5922 return -EINVAL; 5923 } else { 5924 /* Default to Deauthentication frame */ 5925 params.subtype = IEEE80211_STYPE_DEAUTH >> 4; 5926 } 5927 5928 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 5929 params.reason_code = 5930 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 5931 if (params.reason_code == 0) 5932 return -EINVAL; /* 0 is reserved */ 5933 } else { 5934 /* Default to reason code 2 */ 5935 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; 5936 } 5937 5938 return rdev_del_station(rdev, dev, ¶ms); 5939 } 5940 5941 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 5942 int flags, struct net_device *dev, 5943 u8 *dst, u8 *next_hop, 5944 struct mpath_info *pinfo) 5945 { 5946 void *hdr; 5947 struct nlattr *pinfoattr; 5948 5949 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); 5950 if (!hdr) 5951 return -1; 5952 5953 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 5954 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || 5955 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || 5956 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 5957 goto nla_put_failure; 5958 5959 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); 5960 if (!pinfoattr) 5961 goto nla_put_failure; 5962 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 5963 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 5964 pinfo->frame_qlen)) 5965 goto nla_put_failure; 5966 if (((pinfo->filled & MPATH_INFO_SN) && 5967 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || 5968 ((pinfo->filled & MPATH_INFO_METRIC) && 5969 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, 5970 pinfo->metric)) || 5971 ((pinfo->filled & MPATH_INFO_EXPTIME) && 5972 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, 5973 pinfo->exptime)) || 5974 ((pinfo->filled & MPATH_INFO_FLAGS) && 5975 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, 5976 pinfo->flags)) || 5977 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && 5978 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, 5979 pinfo->discovery_timeout)) || 5980 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && 5981 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, 5982 pinfo->discovery_retries)) || 5983 ((pinfo->filled & MPATH_INFO_HOP_COUNT) && 5984 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, 5985 pinfo->hop_count)) || 5986 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && 5987 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, 5988 pinfo->path_change_count))) 5989 goto nla_put_failure; 5990 5991 nla_nest_end(msg, pinfoattr); 5992 5993 genlmsg_end(msg, hdr); 5994 return 0; 5995 5996 nla_put_failure: 5997 genlmsg_cancel(msg, hdr); 5998 return -EMSGSIZE; 5999 } 6000 6001 static int nl80211_dump_mpath(struct sk_buff *skb, 6002 struct netlink_callback *cb) 6003 { 6004 struct mpath_info pinfo; 6005 struct cfg80211_registered_device *rdev; 6006 struct wireless_dev *wdev; 6007 u8 dst[ETH_ALEN]; 6008 u8 next_hop[ETH_ALEN]; 6009 int path_idx = cb->args[2]; 6010 int err; 6011 6012 rtnl_lock(); 6013 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 6014 if (err) 6015 goto out_err; 6016 6017 if (!rdev->ops->dump_mpath) { 6018 err = -EOPNOTSUPP; 6019 goto out_err; 6020 } 6021 6022 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 6023 err = -EOPNOTSUPP; 6024 goto out_err; 6025 } 6026 6027 while (1) { 6028 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, 6029 next_hop, &pinfo); 6030 if (err == -ENOENT) 6031 break; 6032 if (err) 6033 goto out_err; 6034 6035 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 6036 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6037 wdev->netdev, dst, next_hop, 6038 &pinfo) < 0) 6039 goto out; 6040 6041 path_idx++; 6042 } 6043 6044 out: 6045 cb->args[2] = path_idx; 6046 err = skb->len; 6047 out_err: 6048 rtnl_unlock(); 6049 return err; 6050 } 6051 6052 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 6053 { 6054 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6055 int err; 6056 struct net_device *dev = info->user_ptr[1]; 6057 struct mpath_info pinfo; 6058 struct sk_buff *msg; 6059 u8 *dst = NULL; 6060 u8 next_hop[ETH_ALEN]; 6061 6062 memset(&pinfo, 0, sizeof(pinfo)); 6063 6064 if (!info->attrs[NL80211_ATTR_MAC]) 6065 return -EINVAL; 6066 6067 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6068 6069 if (!rdev->ops->get_mpath) 6070 return -EOPNOTSUPP; 6071 6072 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6073 return -EOPNOTSUPP; 6074 6075 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); 6076 if (err) 6077 return err; 6078 6079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6080 if (!msg) 6081 return -ENOMEM; 6082 6083 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 6084 dev, dst, next_hop, &pinfo) < 0) { 6085 nlmsg_free(msg); 6086 return -ENOBUFS; 6087 } 6088 6089 return genlmsg_reply(msg, info); 6090 } 6091 6092 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 6093 { 6094 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6095 struct net_device *dev = info->user_ptr[1]; 6096 u8 *dst = NULL; 6097 u8 *next_hop = NULL; 6098 6099 if (!info->attrs[NL80211_ATTR_MAC]) 6100 return -EINVAL; 6101 6102 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 6103 return -EINVAL; 6104 6105 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6106 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 6107 6108 if (!rdev->ops->change_mpath) 6109 return -EOPNOTSUPP; 6110 6111 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6112 return -EOPNOTSUPP; 6113 6114 return rdev_change_mpath(rdev, dev, dst, next_hop); 6115 } 6116 6117 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 6118 { 6119 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6120 struct net_device *dev = info->user_ptr[1]; 6121 u8 *dst = NULL; 6122 u8 *next_hop = NULL; 6123 6124 if (!info->attrs[NL80211_ATTR_MAC]) 6125 return -EINVAL; 6126 6127 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 6128 return -EINVAL; 6129 6130 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6131 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 6132 6133 if (!rdev->ops->add_mpath) 6134 return -EOPNOTSUPP; 6135 6136 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6137 return -EOPNOTSUPP; 6138 6139 return rdev_add_mpath(rdev, dev, dst, next_hop); 6140 } 6141 6142 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 6143 { 6144 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6145 struct net_device *dev = info->user_ptr[1]; 6146 u8 *dst = NULL; 6147 6148 if (info->attrs[NL80211_ATTR_MAC]) 6149 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6150 6151 if (!rdev->ops->del_mpath) 6152 return -EOPNOTSUPP; 6153 6154 return rdev_del_mpath(rdev, dev, dst); 6155 } 6156 6157 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) 6158 { 6159 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6160 int err; 6161 struct net_device *dev = info->user_ptr[1]; 6162 struct mpath_info pinfo; 6163 struct sk_buff *msg; 6164 u8 *dst = NULL; 6165 u8 mpp[ETH_ALEN]; 6166 6167 memset(&pinfo, 0, sizeof(pinfo)); 6168 6169 if (!info->attrs[NL80211_ATTR_MAC]) 6170 return -EINVAL; 6171 6172 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 6173 6174 if (!rdev->ops->get_mpp) 6175 return -EOPNOTSUPP; 6176 6177 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 6178 return -EOPNOTSUPP; 6179 6180 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); 6181 if (err) 6182 return err; 6183 6184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6185 if (!msg) 6186 return -ENOMEM; 6187 6188 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 6189 dev, dst, mpp, &pinfo) < 0) { 6190 nlmsg_free(msg); 6191 return -ENOBUFS; 6192 } 6193 6194 return genlmsg_reply(msg, info); 6195 } 6196 6197 static int nl80211_dump_mpp(struct sk_buff *skb, 6198 struct netlink_callback *cb) 6199 { 6200 struct mpath_info pinfo; 6201 struct cfg80211_registered_device *rdev; 6202 struct wireless_dev *wdev; 6203 u8 dst[ETH_ALEN]; 6204 u8 mpp[ETH_ALEN]; 6205 int path_idx = cb->args[2]; 6206 int err; 6207 6208 rtnl_lock(); 6209 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 6210 if (err) 6211 goto out_err; 6212 6213 if (!rdev->ops->dump_mpp) { 6214 err = -EOPNOTSUPP; 6215 goto out_err; 6216 } 6217 6218 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 6219 err = -EOPNOTSUPP; 6220 goto out_err; 6221 } 6222 6223 while (1) { 6224 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, 6225 mpp, &pinfo); 6226 if (err == -ENOENT) 6227 break; 6228 if (err) 6229 goto out_err; 6230 6231 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 6232 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6233 wdev->netdev, dst, mpp, 6234 &pinfo) < 0) 6235 goto out; 6236 6237 path_idx++; 6238 } 6239 6240 out: 6241 cb->args[2] = path_idx; 6242 err = skb->len; 6243 out_err: 6244 rtnl_unlock(); 6245 return err; 6246 } 6247 6248 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 6249 { 6250 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6251 struct net_device *dev = info->user_ptr[1]; 6252 struct wireless_dev *wdev = dev->ieee80211_ptr; 6253 struct bss_parameters params; 6254 int err; 6255 6256 memset(¶ms, 0, sizeof(params)); 6257 /* default to not changing parameters */ 6258 params.use_cts_prot = -1; 6259 params.use_short_preamble = -1; 6260 params.use_short_slot_time = -1; 6261 params.ap_isolate = -1; 6262 params.ht_opmode = -1; 6263 params.p2p_ctwindow = -1; 6264 params.p2p_opp_ps = -1; 6265 6266 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 6267 params.use_cts_prot = 6268 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); 6269 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) 6270 params.use_short_preamble = 6271 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); 6272 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 6273 params.use_short_slot_time = 6274 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 6275 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 6276 params.basic_rates = 6277 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 6278 params.basic_rates_len = 6279 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 6280 } 6281 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 6282 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 6283 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) 6284 params.ht_opmode = 6285 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); 6286 6287 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 6288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6289 return -EINVAL; 6290 params.p2p_ctwindow = 6291 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 6292 if (params.p2p_ctwindow != 0 && 6293 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 6294 return -EINVAL; 6295 } 6296 6297 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 6298 u8 tmp; 6299 6300 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6301 return -EINVAL; 6302 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 6303 params.p2p_opp_ps = tmp; 6304 if (params.p2p_opp_ps && 6305 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 6306 return -EINVAL; 6307 } 6308 6309 if (!rdev->ops->change_bss) 6310 return -EOPNOTSUPP; 6311 6312 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6313 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6314 return -EOPNOTSUPP; 6315 6316 wdev_lock(wdev); 6317 err = rdev_change_bss(rdev, dev, ¶ms); 6318 wdev_unlock(wdev); 6319 6320 return err; 6321 } 6322 6323 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) 6324 { 6325 char *data = NULL; 6326 bool is_indoor; 6327 enum nl80211_user_reg_hint_type user_reg_hint_type; 6328 u32 owner_nlportid; 6329 6330 /* 6331 * You should only get this when cfg80211 hasn't yet initialized 6332 * completely when built-in to the kernel right between the time 6333 * window between nl80211_init() and regulatory_init(), if that is 6334 * even possible. 6335 */ 6336 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 6337 return -EINPROGRESS; 6338 6339 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 6340 user_reg_hint_type = 6341 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 6342 else 6343 user_reg_hint_type = NL80211_USER_REG_HINT_USER; 6344 6345 switch (user_reg_hint_type) { 6346 case NL80211_USER_REG_HINT_USER: 6347 case NL80211_USER_REG_HINT_CELL_BASE: 6348 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 6349 return -EINVAL; 6350 6351 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 6352 return regulatory_hint_user(data, user_reg_hint_type); 6353 case NL80211_USER_REG_HINT_INDOOR: 6354 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 6355 owner_nlportid = info->snd_portid; 6356 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; 6357 } else { 6358 owner_nlportid = 0; 6359 is_indoor = true; 6360 } 6361 6362 return regulatory_hint_indoor(is_indoor, owner_nlportid); 6363 default: 6364 return -EINVAL; 6365 } 6366 } 6367 6368 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) 6369 { 6370 return reg_reload_regdb(); 6371 } 6372 6373 static int nl80211_get_mesh_config(struct sk_buff *skb, 6374 struct genl_info *info) 6375 { 6376 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6377 struct net_device *dev = info->user_ptr[1]; 6378 struct wireless_dev *wdev = dev->ieee80211_ptr; 6379 struct mesh_config cur_params; 6380 int err = 0; 6381 void *hdr; 6382 struct nlattr *pinfoattr; 6383 struct sk_buff *msg; 6384 6385 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 6386 return -EOPNOTSUPP; 6387 6388 if (!rdev->ops->get_mesh_config) 6389 return -EOPNOTSUPP; 6390 6391 wdev_lock(wdev); 6392 /* If not connected, get default parameters */ 6393 if (!wdev->mesh_id_len) 6394 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); 6395 else 6396 err = rdev_get_mesh_config(rdev, dev, &cur_params); 6397 wdev_unlock(wdev); 6398 6399 if (err) 6400 return err; 6401 6402 /* Draw up a netlink message to send back */ 6403 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6404 if (!msg) 6405 return -ENOMEM; 6406 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 6407 NL80211_CMD_GET_MESH_CONFIG); 6408 if (!hdr) 6409 goto out; 6410 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); 6411 if (!pinfoattr) 6412 goto nla_put_failure; 6413 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6414 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, 6415 cur_params.dot11MeshRetryTimeout) || 6416 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, 6417 cur_params.dot11MeshConfirmTimeout) || 6418 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, 6419 cur_params.dot11MeshHoldingTimeout) || 6420 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, 6421 cur_params.dot11MeshMaxPeerLinks) || 6422 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, 6423 cur_params.dot11MeshMaxRetries) || 6424 nla_put_u8(msg, NL80211_MESHCONF_TTL, 6425 cur_params.dot11MeshTTL) || 6426 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, 6427 cur_params.element_ttl) || 6428 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 6429 cur_params.auto_open_plinks) || 6430 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 6431 cur_params.dot11MeshNbrOffsetMaxNeighbor) || 6432 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 6433 cur_params.dot11MeshHWMPmaxPREQretries) || 6434 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, 6435 cur_params.path_refresh_time) || 6436 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 6437 cur_params.min_discovery_timeout) || 6438 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 6439 cur_params.dot11MeshHWMPactivePathTimeout) || 6440 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 6441 cur_params.dot11MeshHWMPpreqMinInterval) || 6442 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 6443 cur_params.dot11MeshHWMPperrMinInterval) || 6444 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 6445 cur_params.dot11MeshHWMPnetDiameterTraversalTime) || 6446 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, 6447 cur_params.dot11MeshHWMPRootMode) || 6448 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, 6449 cur_params.dot11MeshHWMPRannInterval) || 6450 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 6451 cur_params.dot11MeshGateAnnouncementProtocol) || 6452 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, 6453 cur_params.dot11MeshForwarding) || 6454 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, 6455 cur_params.rssi_threshold) || 6456 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, 6457 cur_params.ht_opmode) || 6458 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 6459 cur_params.dot11MeshHWMPactivePathToRootTimeout) || 6460 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 6461 cur_params.dot11MeshHWMProotInterval) || 6462 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 6463 cur_params.dot11MeshHWMPconfirmationInterval) || 6464 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, 6465 cur_params.power_mode) || 6466 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, 6467 cur_params.dot11MeshAwakeWindowDuration) || 6468 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, 6469 cur_params.plink_timeout) || 6470 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, 6471 cur_params.dot11MeshConnectedToMeshGate)) 6472 goto nla_put_failure; 6473 nla_nest_end(msg, pinfoattr); 6474 genlmsg_end(msg, hdr); 6475 return genlmsg_reply(msg, info); 6476 6477 nla_put_failure: 6478 out: 6479 nlmsg_free(msg); 6480 return -ENOBUFS; 6481 } 6482 6483 static const struct nla_policy 6484 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 6485 [NL80211_MESHCONF_RETRY_TIMEOUT] = 6486 NLA_POLICY_RANGE(NLA_U16, 1, 255), 6487 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = 6488 NLA_POLICY_RANGE(NLA_U16, 1, 255), 6489 [NL80211_MESHCONF_HOLDING_TIMEOUT] = 6490 NLA_POLICY_RANGE(NLA_U16, 1, 255), 6491 [NL80211_MESHCONF_MAX_PEER_LINKS] = 6492 NLA_POLICY_RANGE(NLA_U16, 0, 255), 6493 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), 6494 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 6495 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 6496 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), 6497 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = 6498 NLA_POLICY_RANGE(NLA_U32, 1, 255), 6499 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 6500 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, 6501 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), 6502 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, 6503 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = 6504 NLA_POLICY_MIN(NLA_U16, 1), 6505 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = 6506 NLA_POLICY_MIN(NLA_U16, 1), 6507 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = 6508 NLA_POLICY_MIN(NLA_U16, 1), 6509 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), 6510 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = 6511 NLA_POLICY_MIN(NLA_U16, 1), 6512 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), 6513 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), 6514 [NL80211_MESHCONF_RSSI_THRESHOLD] = 6515 NLA_POLICY_RANGE(NLA_S32, -255, 0), 6516 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, 6517 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 6518 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = 6519 NLA_POLICY_MIN(NLA_U16, 1), 6520 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = 6521 NLA_POLICY_MIN(NLA_U16, 1), 6522 [NL80211_MESHCONF_POWER_MODE] = 6523 NLA_POLICY_RANGE(NLA_U32, 6524 NL80211_MESH_POWER_ACTIVE, 6525 NL80211_MESH_POWER_MAX), 6526 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, 6527 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, 6528 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 6529 }; 6530 6531 static const struct nla_policy 6532 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { 6533 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, 6534 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, 6535 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, 6536 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, 6537 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, 6538 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, 6539 [NL80211_MESH_SETUP_IE] = 6540 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 6541 IEEE80211_MAX_DATA_LEN), 6542 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, 6543 }; 6544 6545 static int nl80211_parse_mesh_config(struct genl_info *info, 6546 struct mesh_config *cfg, 6547 u32 *mask_out) 6548 { 6549 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 6550 u32 mask = 0; 6551 u16 ht_opmode; 6552 6553 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ 6554 do { \ 6555 if (tb[attr]) { \ 6556 cfg->param = fn(tb[attr]); \ 6557 mask |= BIT((attr) - 1); \ 6558 } \ 6559 } while (0) 6560 6561 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 6562 return -EINVAL; 6563 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) 6564 return -EINVAL; 6565 6566 /* This makes sure that there aren't more than 32 mesh config 6567 * parameters (otherwise our bitfield scheme would not work.) */ 6568 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 6569 6570 /* Fill in the params struct */ 6571 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, 6572 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 6573 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, 6574 NL80211_MESHCONF_CONFIRM_TIMEOUT, 6575 nla_get_u16); 6576 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, 6577 NL80211_MESHCONF_HOLDING_TIMEOUT, 6578 nla_get_u16); 6579 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, 6580 NL80211_MESHCONF_MAX_PEER_LINKS, 6581 nla_get_u16); 6582 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, 6583 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 6584 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, 6585 NL80211_MESHCONF_TTL, nla_get_u8); 6586 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, 6587 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); 6588 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, 6589 NL80211_MESHCONF_AUTO_OPEN_PLINKS, 6590 nla_get_u8); 6591 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, 6592 mask, 6593 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 6594 nla_get_u32); 6595 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, 6596 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 6597 nla_get_u8); 6598 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, 6599 NL80211_MESHCONF_PATH_REFRESH_TIME, 6600 nla_get_u32); 6601 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && 6602 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) 6603 return -EINVAL; 6604 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, 6605 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 6606 nla_get_u16); 6607 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, 6608 mask, 6609 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 6610 nla_get_u32); 6611 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && 6612 (cfg->dot11MeshHWMPactivePathTimeout < 1 || 6613 cfg->dot11MeshHWMPactivePathTimeout > 65535)) 6614 return -EINVAL; 6615 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, 6616 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 6617 nla_get_u16); 6618 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, 6619 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 6620 nla_get_u16); 6621 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 6622 dot11MeshHWMPnetDiameterTraversalTime, mask, 6623 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 6624 nla_get_u16); 6625 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 6626 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 6627 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 6628 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 6629 nla_get_u16); 6630 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, 6631 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 6632 nla_get_u8); 6633 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, 6634 NL80211_MESHCONF_FORWARDING, nla_get_u8); 6635 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, 6636 NL80211_MESHCONF_RSSI_THRESHOLD, 6637 nla_get_s32); 6638 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, 6639 NL80211_MESHCONF_CONNECTED_TO_GATE, 6640 nla_get_u8); 6641 /* 6642 * Check HT operation mode based on 6643 * IEEE 802.11-2016 9.4.2.57 HT Operation element. 6644 */ 6645 if (tb[NL80211_MESHCONF_HT_OPMODE]) { 6646 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); 6647 6648 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | 6649 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | 6650 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) 6651 return -EINVAL; 6652 6653 /* NON_HT_STA bit is reserved, but some programs set it */ 6654 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; 6655 6656 cfg->ht_opmode = ht_opmode; 6657 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); 6658 } 6659 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 6660 dot11MeshHWMPactivePathToRootTimeout, mask, 6661 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 6662 nla_get_u32); 6663 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && 6664 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || 6665 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) 6666 return -EINVAL; 6667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, 6668 NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 6669 nla_get_u16); 6670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, 6671 mask, 6672 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 6673 nla_get_u16); 6674 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, 6675 NL80211_MESHCONF_POWER_MODE, nla_get_u32); 6676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, 6677 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); 6678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, 6679 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); 6680 if (mask_out) 6681 *mask_out = mask; 6682 6683 return 0; 6684 6685 #undef FILL_IN_MESH_PARAM_IF_SET 6686 } 6687 6688 static int nl80211_parse_mesh_setup(struct genl_info *info, 6689 struct mesh_setup *setup) 6690 { 6691 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6692 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; 6693 6694 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 6695 return -EINVAL; 6696 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) 6697 return -EINVAL; 6698 6699 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 6700 setup->sync_method = 6701 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? 6702 IEEE80211_SYNC_METHOD_VENDOR : 6703 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; 6704 6705 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) 6706 setup->path_sel_proto = 6707 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? 6708 IEEE80211_PATH_PROTOCOL_VENDOR : 6709 IEEE80211_PATH_PROTOCOL_HWMP; 6710 6711 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) 6712 setup->path_metric = 6713 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? 6714 IEEE80211_PATH_METRIC_VENDOR : 6715 IEEE80211_PATH_METRIC_AIRTIME; 6716 6717 if (tb[NL80211_MESH_SETUP_IE]) { 6718 struct nlattr *ieattr = 6719 tb[NL80211_MESH_SETUP_IE]; 6720 setup->ie = nla_data(ieattr); 6721 setup->ie_len = nla_len(ieattr); 6722 } 6723 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && 6724 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) 6725 return -EINVAL; 6726 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); 6727 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); 6728 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); 6729 if (setup->is_secure) 6730 setup->user_mpm = true; 6731 6732 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { 6733 if (!setup->user_mpm) 6734 return -EINVAL; 6735 setup->auth_id = 6736 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); 6737 } 6738 6739 return 0; 6740 } 6741 6742 static int nl80211_update_mesh_config(struct sk_buff *skb, 6743 struct genl_info *info) 6744 { 6745 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6746 struct net_device *dev = info->user_ptr[1]; 6747 struct wireless_dev *wdev = dev->ieee80211_ptr; 6748 struct mesh_config cfg; 6749 u32 mask; 6750 int err; 6751 6752 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 6753 return -EOPNOTSUPP; 6754 6755 if (!rdev->ops->update_mesh_config) 6756 return -EOPNOTSUPP; 6757 6758 err = nl80211_parse_mesh_config(info, &cfg, &mask); 6759 if (err) 6760 return err; 6761 6762 wdev_lock(wdev); 6763 if (!wdev->mesh_id_len) 6764 err = -ENOLINK; 6765 6766 if (!err) 6767 err = rdev_update_mesh_config(rdev, dev, mask, &cfg); 6768 6769 wdev_unlock(wdev); 6770 6771 return err; 6772 } 6773 6774 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, 6775 struct sk_buff *msg) 6776 { 6777 struct nlattr *nl_reg_rules; 6778 unsigned int i; 6779 6780 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || 6781 (regdom->dfs_region && 6782 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 6783 goto nla_put_failure; 6784 6785 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); 6786 if (!nl_reg_rules) 6787 goto nla_put_failure; 6788 6789 for (i = 0; i < regdom->n_reg_rules; i++) { 6790 struct nlattr *nl_reg_rule; 6791 const struct ieee80211_reg_rule *reg_rule; 6792 const struct ieee80211_freq_range *freq_range; 6793 const struct ieee80211_power_rule *power_rule; 6794 unsigned int max_bandwidth_khz; 6795 6796 reg_rule = ®dom->reg_rules[i]; 6797 freq_range = ®_rule->freq_range; 6798 power_rule = ®_rule->power_rule; 6799 6800 nl_reg_rule = nla_nest_start_noflag(msg, i); 6801 if (!nl_reg_rule) 6802 goto nla_put_failure; 6803 6804 max_bandwidth_khz = freq_range->max_bandwidth_khz; 6805 if (!max_bandwidth_khz) 6806 max_bandwidth_khz = reg_get_max_bandwidth(regdom, 6807 reg_rule); 6808 6809 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 6810 reg_rule->flags) || 6811 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, 6812 freq_range->start_freq_khz) || 6813 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, 6814 freq_range->end_freq_khz) || 6815 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, 6816 max_bandwidth_khz) || 6817 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, 6818 power_rule->max_antenna_gain) || 6819 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 6820 power_rule->max_eirp) || 6821 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 6822 reg_rule->dfs_cac_ms)) 6823 goto nla_put_failure; 6824 6825 nla_nest_end(msg, nl_reg_rule); 6826 } 6827 6828 nla_nest_end(msg, nl_reg_rules); 6829 return 0; 6830 6831 nla_put_failure: 6832 return -EMSGSIZE; 6833 } 6834 6835 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) 6836 { 6837 const struct ieee80211_regdomain *regdom = NULL; 6838 struct cfg80211_registered_device *rdev; 6839 struct wiphy *wiphy = NULL; 6840 struct sk_buff *msg; 6841 void *hdr; 6842 6843 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6844 if (!msg) 6845 return -ENOBUFS; 6846 6847 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 6848 NL80211_CMD_GET_REG); 6849 if (!hdr) 6850 goto put_failure; 6851 6852 if (info->attrs[NL80211_ATTR_WIPHY]) { 6853 bool self_managed; 6854 6855 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 6856 if (IS_ERR(rdev)) { 6857 nlmsg_free(msg); 6858 return PTR_ERR(rdev); 6859 } 6860 6861 wiphy = &rdev->wiphy; 6862 self_managed = wiphy->regulatory_flags & 6863 REGULATORY_WIPHY_SELF_MANAGED; 6864 regdom = get_wiphy_regdom(wiphy); 6865 6866 /* a self-managed-reg device must have a private regdom */ 6867 if (WARN_ON(!regdom && self_managed)) { 6868 nlmsg_free(msg); 6869 return -EINVAL; 6870 } 6871 6872 if (regdom && 6873 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 6874 goto nla_put_failure; 6875 } 6876 6877 if (!wiphy && reg_last_request_cell_base() && 6878 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 6879 NL80211_USER_REG_HINT_CELL_BASE)) 6880 goto nla_put_failure; 6881 6882 rcu_read_lock(); 6883 6884 if (!regdom) 6885 regdom = rcu_dereference(cfg80211_regdomain); 6886 6887 if (nl80211_put_regdom(regdom, msg)) 6888 goto nla_put_failure_rcu; 6889 6890 rcu_read_unlock(); 6891 6892 genlmsg_end(msg, hdr); 6893 return genlmsg_reply(msg, info); 6894 6895 nla_put_failure_rcu: 6896 rcu_read_unlock(); 6897 nla_put_failure: 6898 put_failure: 6899 nlmsg_free(msg); 6900 return -EMSGSIZE; 6901 } 6902 6903 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, 6904 u32 seq, int flags, struct wiphy *wiphy, 6905 const struct ieee80211_regdomain *regdom) 6906 { 6907 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 6908 NL80211_CMD_GET_REG); 6909 6910 if (!hdr) 6911 return -1; 6912 6913 genl_dump_check_consistent(cb, hdr); 6914 6915 if (nl80211_put_regdom(regdom, msg)) 6916 goto nla_put_failure; 6917 6918 if (!wiphy && reg_last_request_cell_base() && 6919 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 6920 NL80211_USER_REG_HINT_CELL_BASE)) 6921 goto nla_put_failure; 6922 6923 if (wiphy && 6924 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 6925 goto nla_put_failure; 6926 6927 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 6928 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 6929 goto nla_put_failure; 6930 6931 genlmsg_end(msg, hdr); 6932 return 0; 6933 6934 nla_put_failure: 6935 genlmsg_cancel(msg, hdr); 6936 return -EMSGSIZE; 6937 } 6938 6939 static int nl80211_get_reg_dump(struct sk_buff *skb, 6940 struct netlink_callback *cb) 6941 { 6942 const struct ieee80211_regdomain *regdom = NULL; 6943 struct cfg80211_registered_device *rdev; 6944 int err, reg_idx, start = cb->args[2]; 6945 6946 rtnl_lock(); 6947 6948 if (cfg80211_regdomain && start == 0) { 6949 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 6950 NLM_F_MULTI, NULL, 6951 rtnl_dereference(cfg80211_regdomain)); 6952 if (err < 0) 6953 goto out_err; 6954 } 6955 6956 /* the global regdom is idx 0 */ 6957 reg_idx = 1; 6958 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 6959 regdom = get_wiphy_regdom(&rdev->wiphy); 6960 if (!regdom) 6961 continue; 6962 6963 if (++reg_idx <= start) 6964 continue; 6965 6966 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 6967 NLM_F_MULTI, &rdev->wiphy, regdom); 6968 if (err < 0) { 6969 reg_idx--; 6970 break; 6971 } 6972 } 6973 6974 cb->args[2] = reg_idx; 6975 err = skb->len; 6976 out_err: 6977 rtnl_unlock(); 6978 return err; 6979 } 6980 6981 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 6982 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 6983 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 6984 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 6985 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 6986 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 6987 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 6988 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 6989 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, 6990 }; 6991 6992 static int parse_reg_rule(struct nlattr *tb[], 6993 struct ieee80211_reg_rule *reg_rule) 6994 { 6995 struct ieee80211_freq_range *freq_range = ®_rule->freq_range; 6996 struct ieee80211_power_rule *power_rule = ®_rule->power_rule; 6997 6998 if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) 6999 return -EINVAL; 7000 if (!tb[NL80211_ATTR_FREQ_RANGE_START]) 7001 return -EINVAL; 7002 if (!tb[NL80211_ATTR_FREQ_RANGE_END]) 7003 return -EINVAL; 7004 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 7005 return -EINVAL; 7006 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 7007 return -EINVAL; 7008 7009 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); 7010 7011 freq_range->start_freq_khz = 7012 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); 7013 freq_range->end_freq_khz = 7014 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); 7015 freq_range->max_bandwidth_khz = 7016 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); 7017 7018 power_rule->max_eirp = 7019 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); 7020 7021 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) 7022 power_rule->max_antenna_gain = 7023 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); 7024 7025 if (tb[NL80211_ATTR_DFS_CAC_TIME]) 7026 reg_rule->dfs_cac_ms = 7027 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); 7028 7029 return 0; 7030 } 7031 7032 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 7033 { 7034 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 7035 struct nlattr *nl_reg_rule; 7036 char *alpha2; 7037 int rem_reg_rules, r; 7038 u32 num_rules = 0, rule_idx = 0; 7039 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 7040 struct ieee80211_regdomain *rd; 7041 7042 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 7043 return -EINVAL; 7044 7045 if (!info->attrs[NL80211_ATTR_REG_RULES]) 7046 return -EINVAL; 7047 7048 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 7049 7050 if (info->attrs[NL80211_ATTR_DFS_REGION]) 7051 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 7052 7053 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7054 rem_reg_rules) { 7055 num_rules++; 7056 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 7057 return -EINVAL; 7058 } 7059 7060 if (!reg_is_valid_request(alpha2)) 7061 return -EINVAL; 7062 7063 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); 7064 if (!rd) 7065 return -ENOMEM; 7066 7067 rd->n_reg_rules = num_rules; 7068 rd->alpha2[0] = alpha2[0]; 7069 rd->alpha2[1] = alpha2[1]; 7070 7071 /* 7072 * Disable DFS master mode if the DFS region was 7073 * not supported or known on this kernel. 7074 */ 7075 if (reg_supported_dfs_region(dfs_region)) 7076 rd->dfs_region = dfs_region; 7077 7078 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7079 rem_reg_rules) { 7080 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, 7081 nl_reg_rule, reg_rule_policy, 7082 info->extack); 7083 if (r) 7084 goto bad_reg; 7085 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 7086 if (r) 7087 goto bad_reg; 7088 7089 rule_idx++; 7090 7091 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { 7092 r = -EINVAL; 7093 goto bad_reg; 7094 } 7095 } 7096 7097 /* set_regdom takes ownership of rd */ 7098 return set_regdom(rd, REGD_SOURCE_CRDA); 7099 bad_reg: 7100 kfree(rd); 7101 return r; 7102 } 7103 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ 7104 7105 static int validate_scan_freqs(struct nlattr *freqs) 7106 { 7107 struct nlattr *attr1, *attr2; 7108 int n_channels = 0, tmp1, tmp2; 7109 7110 nla_for_each_nested(attr1, freqs, tmp1) 7111 if (nla_len(attr1) != sizeof(u32)) 7112 return 0; 7113 7114 nla_for_each_nested(attr1, freqs, tmp1) { 7115 n_channels++; 7116 /* 7117 * Some hardware has a limited channel list for 7118 * scanning, and it is pretty much nonsensical 7119 * to scan for a channel twice, so disallow that 7120 * and don't require drivers to check that the 7121 * channel list they get isn't longer than what 7122 * they can scan, as long as they can scan all 7123 * the channels they registered at once. 7124 */ 7125 nla_for_each_nested(attr2, freqs, tmp2) 7126 if (attr1 != attr2 && 7127 nla_get_u32(attr1) == nla_get_u32(attr2)) 7128 return 0; 7129 } 7130 7131 return n_channels; 7132 } 7133 7134 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) 7135 { 7136 return b < NUM_NL80211_BANDS && wiphy->bands[b]; 7137 } 7138 7139 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, 7140 struct cfg80211_bss_selection *bss_select) 7141 { 7142 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; 7143 struct nlattr *nest; 7144 int err; 7145 bool found = false; 7146 int i; 7147 7148 /* only process one nested attribute */ 7149 nest = nla_data(nla); 7150 if (!nla_ok(nest, nla_len(nest))) 7151 return -EINVAL; 7152 7153 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, 7154 nest, nl80211_bss_select_policy, 7155 NULL); 7156 if (err) 7157 return err; 7158 7159 /* only one attribute may be given */ 7160 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { 7161 if (attr[i]) { 7162 if (found) 7163 return -EINVAL; 7164 found = true; 7165 } 7166 } 7167 7168 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; 7169 7170 if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) 7171 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; 7172 7173 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { 7174 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; 7175 bss_select->param.band_pref = 7176 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); 7177 if (!is_band_valid(wiphy, bss_select->param.band_pref)) 7178 return -EINVAL; 7179 } 7180 7181 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { 7182 struct nl80211_bss_select_rssi_adjust *adj_param; 7183 7184 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); 7185 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; 7186 bss_select->param.adjust.band = adj_param->band; 7187 bss_select->param.adjust.delta = adj_param->delta; 7188 if (!is_band_valid(wiphy, bss_select->param.adjust.band)) 7189 return -EINVAL; 7190 } 7191 7192 /* user-space did not provide behaviour attribute */ 7193 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) 7194 return -EINVAL; 7195 7196 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) 7197 return -EINVAL; 7198 7199 return 0; 7200 } 7201 7202 int nl80211_parse_random_mac(struct nlattr **attrs, 7203 u8 *mac_addr, u8 *mac_addr_mask) 7204 { 7205 int i; 7206 7207 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { 7208 eth_zero_addr(mac_addr); 7209 eth_zero_addr(mac_addr_mask); 7210 mac_addr[0] = 0x2; 7211 mac_addr_mask[0] = 0x3; 7212 7213 return 0; 7214 } 7215 7216 /* need both or none */ 7217 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) 7218 return -EINVAL; 7219 7220 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); 7221 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); 7222 7223 /* don't allow or configure an mcast address */ 7224 if (!is_multicast_ether_addr(mac_addr_mask) || 7225 is_multicast_ether_addr(mac_addr)) 7226 return -EINVAL; 7227 7228 /* 7229 * allow users to pass a MAC address that has bits set outside 7230 * of the mask, but don't bother drivers with having to deal 7231 * with such bits 7232 */ 7233 for (i = 0; i < ETH_ALEN; i++) 7234 mac_addr[i] &= mac_addr_mask[i]; 7235 7236 return 0; 7237 } 7238 7239 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) 7240 { 7241 ASSERT_WDEV_LOCK(wdev); 7242 7243 if (!cfg80211_beaconing_iface_active(wdev)) 7244 return true; 7245 7246 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) 7247 return true; 7248 7249 return regulatory_pre_cac_allowed(wdev->wiphy); 7250 } 7251 7252 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, 7253 enum nl80211_ext_feature_index feat) 7254 { 7255 if (!(flags & flag)) 7256 return true; 7257 if (wiphy_ext_feature_isset(wiphy, feat)) 7258 return true; 7259 return false; 7260 } 7261 7262 static int 7263 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, 7264 void *request, struct nlattr **attrs, 7265 bool is_sched_scan) 7266 { 7267 u8 *mac_addr, *mac_addr_mask; 7268 u32 *flags; 7269 enum nl80211_feature_flags randomness_flag; 7270 7271 if (!attrs[NL80211_ATTR_SCAN_FLAGS]) 7272 return 0; 7273 7274 if (is_sched_scan) { 7275 struct cfg80211_sched_scan_request *req = request; 7276 7277 randomness_flag = wdev ? 7278 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : 7279 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 7280 flags = &req->flags; 7281 mac_addr = req->mac_addr; 7282 mac_addr_mask = req->mac_addr_mask; 7283 } else { 7284 struct cfg80211_scan_request *req = request; 7285 7286 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 7287 flags = &req->flags; 7288 mac_addr = req->mac_addr; 7289 mac_addr_mask = req->mac_addr_mask; 7290 } 7291 7292 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); 7293 7294 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && 7295 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || 7296 !nl80211_check_scan_feat(wiphy, *flags, 7297 NL80211_SCAN_FLAG_LOW_SPAN, 7298 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || 7299 !nl80211_check_scan_feat(wiphy, *flags, 7300 NL80211_SCAN_FLAG_LOW_POWER, 7301 NL80211_EXT_FEATURE_LOW_POWER_SCAN) || 7302 !nl80211_check_scan_feat(wiphy, *flags, 7303 NL80211_SCAN_FLAG_HIGH_ACCURACY, 7304 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || 7305 !nl80211_check_scan_feat(wiphy, *flags, 7306 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, 7307 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || 7308 !nl80211_check_scan_feat(wiphy, *flags, 7309 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, 7310 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || 7311 !nl80211_check_scan_feat(wiphy, *flags, 7312 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, 7313 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || 7314 !nl80211_check_scan_feat(wiphy, *flags, 7315 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, 7316 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || 7317 !nl80211_check_scan_feat(wiphy, *flags, 7318 NL80211_SCAN_FLAG_RANDOM_SN, 7319 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || 7320 !nl80211_check_scan_feat(wiphy, *flags, 7321 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, 7322 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) 7323 return -EOPNOTSUPP; 7324 7325 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 7326 int err; 7327 7328 if (!(wiphy->features & randomness_flag) || 7329 (wdev && wdev->current_bss)) 7330 return -EOPNOTSUPP; 7331 7332 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); 7333 if (err) 7334 return err; 7335 } 7336 7337 return 0; 7338 } 7339 7340 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 7341 { 7342 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7343 struct wireless_dev *wdev = info->user_ptr[1]; 7344 struct cfg80211_scan_request *request; 7345 struct nlattr *attr; 7346 struct wiphy *wiphy; 7347 int err, tmp, n_ssids = 0, n_channels, i; 7348 size_t ie_len; 7349 7350 wiphy = &rdev->wiphy; 7351 7352 if (wdev->iftype == NL80211_IFTYPE_NAN) 7353 return -EOPNOTSUPP; 7354 7355 if (!rdev->ops->scan) 7356 return -EOPNOTSUPP; 7357 7358 if (rdev->scan_req || rdev->scan_msg) { 7359 err = -EBUSY; 7360 goto unlock; 7361 } 7362 7363 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 7364 n_channels = validate_scan_freqs( 7365 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 7366 if (!n_channels) { 7367 err = -EINVAL; 7368 goto unlock; 7369 } 7370 } else { 7371 n_channels = ieee80211_get_num_supported_channels(wiphy); 7372 } 7373 7374 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 7375 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 7376 n_ssids++; 7377 7378 if (n_ssids > wiphy->max_scan_ssids) { 7379 err = -EINVAL; 7380 goto unlock; 7381 } 7382 7383 if (info->attrs[NL80211_ATTR_IE]) 7384 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 7385 else 7386 ie_len = 0; 7387 7388 if (ie_len > wiphy->max_scan_ie_len) { 7389 err = -EINVAL; 7390 goto unlock; 7391 } 7392 7393 request = kzalloc(sizeof(*request) 7394 + sizeof(*request->ssids) * n_ssids 7395 + sizeof(*request->channels) * n_channels 7396 + ie_len, GFP_KERNEL); 7397 if (!request) { 7398 err = -ENOMEM; 7399 goto unlock; 7400 } 7401 7402 if (n_ssids) 7403 request->ssids = (void *)&request->channels[n_channels]; 7404 request->n_ssids = n_ssids; 7405 if (ie_len) { 7406 if (n_ssids) 7407 request->ie = (void *)(request->ssids + n_ssids); 7408 else 7409 request->ie = (void *)(request->channels + n_channels); 7410 } 7411 7412 i = 0; 7413 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 7414 /* user specified, bail out if channel not found */ 7415 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { 7416 struct ieee80211_channel *chan; 7417 7418 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 7419 7420 if (!chan) { 7421 err = -EINVAL; 7422 goto out_free; 7423 } 7424 7425 /* ignore disabled channels */ 7426 if (chan->flags & IEEE80211_CHAN_DISABLED) 7427 continue; 7428 7429 request->channels[i] = chan; 7430 i++; 7431 } 7432 } else { 7433 enum nl80211_band band; 7434 7435 /* all channels */ 7436 for (band = 0; band < NUM_NL80211_BANDS; band++) { 7437 int j; 7438 7439 if (!wiphy->bands[band]) 7440 continue; 7441 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 7442 struct ieee80211_channel *chan; 7443 7444 chan = &wiphy->bands[band]->channels[j]; 7445 7446 if (chan->flags & IEEE80211_CHAN_DISABLED) 7447 continue; 7448 7449 request->channels[i] = chan; 7450 i++; 7451 } 7452 } 7453 } 7454 7455 if (!i) { 7456 err = -EINVAL; 7457 goto out_free; 7458 } 7459 7460 request->n_channels = i; 7461 7462 wdev_lock(wdev); 7463 if (!cfg80211_off_channel_oper_allowed(wdev)) { 7464 struct ieee80211_channel *chan; 7465 7466 if (request->n_channels != 1) { 7467 wdev_unlock(wdev); 7468 err = -EBUSY; 7469 goto out_free; 7470 } 7471 7472 chan = request->channels[0]; 7473 if (chan->center_freq != wdev->chandef.chan->center_freq) { 7474 wdev_unlock(wdev); 7475 err = -EBUSY; 7476 goto out_free; 7477 } 7478 } 7479 wdev_unlock(wdev); 7480 7481 i = 0; 7482 if (n_ssids) { 7483 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 7484 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 7485 err = -EINVAL; 7486 goto out_free; 7487 } 7488 request->ssids[i].ssid_len = nla_len(attr); 7489 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); 7490 i++; 7491 } 7492 } 7493 7494 if (info->attrs[NL80211_ATTR_IE]) { 7495 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 7496 memcpy((void *)request->ie, 7497 nla_data(info->attrs[NL80211_ATTR_IE]), 7498 request->ie_len); 7499 } 7500 7501 for (i = 0; i < NUM_NL80211_BANDS; i++) 7502 if (wiphy->bands[i]) 7503 request->rates[i] = 7504 (1 << wiphy->bands[i]->n_bitrates) - 1; 7505 7506 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { 7507 nla_for_each_nested(attr, 7508 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], 7509 tmp) { 7510 enum nl80211_band band = nla_type(attr); 7511 7512 if (band < 0 || band >= NUM_NL80211_BANDS) { 7513 err = -EINVAL; 7514 goto out_free; 7515 } 7516 7517 if (!wiphy->bands[band]) 7518 continue; 7519 7520 err = ieee80211_get_ratemask(wiphy->bands[band], 7521 nla_data(attr), 7522 nla_len(attr), 7523 &request->rates[band]); 7524 if (err) 7525 goto out_free; 7526 } 7527 } 7528 7529 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { 7530 if (!wiphy_ext_feature_isset(wiphy, 7531 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { 7532 err = -EOPNOTSUPP; 7533 goto out_free; 7534 } 7535 7536 request->duration = 7537 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); 7538 request->duration_mandatory = 7539 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); 7540 } 7541 7542 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, 7543 false); 7544 if (err) 7545 goto out_free; 7546 7547 request->no_cck = 7548 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 7549 7550 /* Initial implementation used NL80211_ATTR_MAC to set the specific 7551 * BSSID to scan for. This was problematic because that same attribute 7552 * was already used for another purpose (local random MAC address). The 7553 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards 7554 * compatibility with older userspace components, also use the 7555 * NL80211_ATTR_MAC value here if it can be determined to be used for 7556 * the specific BSSID use case instead of the random MAC address 7557 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). 7558 */ 7559 if (info->attrs[NL80211_ATTR_BSSID]) 7560 memcpy(request->bssid, 7561 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); 7562 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && 7563 info->attrs[NL80211_ATTR_MAC]) 7564 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), 7565 ETH_ALEN); 7566 else 7567 eth_broadcast_addr(request->bssid); 7568 7569 request->wdev = wdev; 7570 request->wiphy = &rdev->wiphy; 7571 request->scan_start = jiffies; 7572 7573 rdev->scan_req = request; 7574 err = rdev_scan(rdev, request); 7575 7576 if (!err) { 7577 nl80211_send_scan_start(rdev, wdev); 7578 if (wdev->netdev) 7579 dev_hold(wdev->netdev); 7580 } else { 7581 out_free: 7582 rdev->scan_req = NULL; 7583 kfree(request); 7584 } 7585 7586 unlock: 7587 return err; 7588 } 7589 7590 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) 7591 { 7592 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7593 struct wireless_dev *wdev = info->user_ptr[1]; 7594 7595 if (!rdev->ops->abort_scan) 7596 return -EOPNOTSUPP; 7597 7598 if (rdev->scan_msg) 7599 return 0; 7600 7601 if (!rdev->scan_req) 7602 return -ENOENT; 7603 7604 rdev_abort_scan(rdev, wdev); 7605 return 0; 7606 } 7607 7608 static int 7609 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, 7610 struct cfg80211_sched_scan_request *request, 7611 struct nlattr **attrs) 7612 { 7613 int tmp, err, i = 0; 7614 struct nlattr *attr; 7615 7616 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 7617 u32 interval; 7618 7619 /* 7620 * If scan plans are not specified, 7621 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this 7622 * case one scan plan will be set with the specified scan 7623 * interval and infinite number of iterations. 7624 */ 7625 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); 7626 if (!interval) 7627 return -EINVAL; 7628 7629 request->scan_plans[0].interval = 7630 DIV_ROUND_UP(interval, MSEC_PER_SEC); 7631 if (!request->scan_plans[0].interval) 7632 return -EINVAL; 7633 7634 if (request->scan_plans[0].interval > 7635 wiphy->max_sched_scan_plan_interval) 7636 request->scan_plans[0].interval = 7637 wiphy->max_sched_scan_plan_interval; 7638 7639 return 0; 7640 } 7641 7642 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { 7643 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; 7644 7645 if (WARN_ON(i >= n_plans)) 7646 return -EINVAL; 7647 7648 err = nla_parse_nested_deprecated(plan, 7649 NL80211_SCHED_SCAN_PLAN_MAX, 7650 attr, nl80211_plan_policy, 7651 NULL); 7652 if (err) 7653 return err; 7654 7655 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) 7656 return -EINVAL; 7657 7658 request->scan_plans[i].interval = 7659 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); 7660 if (!request->scan_plans[i].interval || 7661 request->scan_plans[i].interval > 7662 wiphy->max_sched_scan_plan_interval) 7663 return -EINVAL; 7664 7665 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { 7666 request->scan_plans[i].iterations = 7667 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); 7668 if (!request->scan_plans[i].iterations || 7669 (request->scan_plans[i].iterations > 7670 wiphy->max_sched_scan_plan_iterations)) 7671 return -EINVAL; 7672 } else if (i < n_plans - 1) { 7673 /* 7674 * All scan plans but the last one must specify 7675 * a finite number of iterations 7676 */ 7677 return -EINVAL; 7678 } 7679 7680 i++; 7681 } 7682 7683 /* 7684 * The last scan plan must not specify the number of 7685 * iterations, it is supposed to run infinitely 7686 */ 7687 if (request->scan_plans[n_plans - 1].iterations) 7688 return -EINVAL; 7689 7690 return 0; 7691 } 7692 7693 static int 7694 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, 7695 struct cfg80211_match_set *match_sets, 7696 struct nlattr *tb_band_rssi, 7697 s32 rssi_thold) 7698 { 7699 struct nlattr *attr; 7700 int i, tmp, ret = 0; 7701 7702 if (!wiphy_ext_feature_isset(wiphy, 7703 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { 7704 if (tb_band_rssi) 7705 ret = -EOPNOTSUPP; 7706 else 7707 for (i = 0; i < NUM_NL80211_BANDS; i++) 7708 match_sets->per_band_rssi_thold[i] = 7709 NL80211_SCAN_RSSI_THOLD_OFF; 7710 return ret; 7711 } 7712 7713 for (i = 0; i < NUM_NL80211_BANDS; i++) 7714 match_sets->per_band_rssi_thold[i] = rssi_thold; 7715 7716 nla_for_each_nested(attr, tb_band_rssi, tmp) { 7717 enum nl80211_band band = nla_type(attr); 7718 7719 if (band < 0 || band >= NUM_NL80211_BANDS) 7720 return -EINVAL; 7721 7722 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); 7723 } 7724 7725 return 0; 7726 } 7727 7728 static struct cfg80211_sched_scan_request * 7729 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 7730 struct nlattr **attrs, int max_match_sets) 7731 { 7732 struct cfg80211_sched_scan_request *request; 7733 struct nlattr *attr; 7734 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; 7735 enum nl80211_band band; 7736 size_t ie_len; 7737 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; 7738 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; 7739 7740 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 7741 n_channels = validate_scan_freqs( 7742 attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 7743 if (!n_channels) 7744 return ERR_PTR(-EINVAL); 7745 } else { 7746 n_channels = ieee80211_get_num_supported_channels(wiphy); 7747 } 7748 7749 if (attrs[NL80211_ATTR_SCAN_SSIDS]) 7750 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 7751 tmp) 7752 n_ssids++; 7753 7754 if (n_ssids > wiphy->max_sched_scan_ssids) 7755 return ERR_PTR(-EINVAL); 7756 7757 /* 7758 * First, count the number of 'real' matchsets. Due to an issue with 7759 * the old implementation, matchsets containing only the RSSI attribute 7760 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' 7761 * RSSI for all matchsets, rather than their own matchset for reporting 7762 * all APs with a strong RSSI. This is needed to be compatible with 7763 * older userspace that treated a matchset with only the RSSI as the 7764 * global RSSI for all other matchsets - if there are other matchsets. 7765 */ 7766 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 7767 nla_for_each_nested(attr, 7768 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 7769 tmp) { 7770 struct nlattr *rssi; 7771 7772 err = nla_parse_nested_deprecated(tb, 7773 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 7774 attr, 7775 nl80211_match_policy, 7776 NULL); 7777 if (err) 7778 return ERR_PTR(err); 7779 7780 /* SSID and BSSID are mutually exclusive */ 7781 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && 7782 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) 7783 return ERR_PTR(-EINVAL); 7784 7785 /* add other standalone attributes here */ 7786 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || 7787 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { 7788 n_match_sets++; 7789 continue; 7790 } 7791 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 7792 if (rssi) 7793 default_match_rssi = nla_get_s32(rssi); 7794 } 7795 } 7796 7797 /* However, if there's no other matchset, add the RSSI one */ 7798 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) 7799 n_match_sets = 1; 7800 7801 if (n_match_sets > max_match_sets) 7802 return ERR_PTR(-EINVAL); 7803 7804 if (attrs[NL80211_ATTR_IE]) 7805 ie_len = nla_len(attrs[NL80211_ATTR_IE]); 7806 else 7807 ie_len = 0; 7808 7809 if (ie_len > wiphy->max_sched_scan_ie_len) 7810 return ERR_PTR(-EINVAL); 7811 7812 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 7813 /* 7814 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since 7815 * each scan plan already specifies its own interval 7816 */ 7817 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 7818 return ERR_PTR(-EINVAL); 7819 7820 nla_for_each_nested(attr, 7821 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) 7822 n_plans++; 7823 } else { 7824 /* 7825 * The scan interval attribute is kept for backward 7826 * compatibility. If no scan plans are specified and sched scan 7827 * interval is specified, one scan plan will be set with this 7828 * scan interval and infinite number of iterations. 7829 */ 7830 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 7831 return ERR_PTR(-EINVAL); 7832 7833 n_plans = 1; 7834 } 7835 7836 if (!n_plans || n_plans > wiphy->max_sched_scan_plans) 7837 return ERR_PTR(-EINVAL); 7838 7839 if (!wiphy_ext_feature_isset( 7840 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && 7841 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || 7842 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) 7843 return ERR_PTR(-EINVAL); 7844 7845 request = kzalloc(sizeof(*request) 7846 + sizeof(*request->ssids) * n_ssids 7847 + sizeof(*request->match_sets) * n_match_sets 7848 + sizeof(*request->scan_plans) * n_plans 7849 + sizeof(*request->channels) * n_channels 7850 + ie_len, GFP_KERNEL); 7851 if (!request) 7852 return ERR_PTR(-ENOMEM); 7853 7854 if (n_ssids) 7855 request->ssids = (void *)&request->channels[n_channels]; 7856 request->n_ssids = n_ssids; 7857 if (ie_len) { 7858 if (n_ssids) 7859 request->ie = (void *)(request->ssids + n_ssids); 7860 else 7861 request->ie = (void *)(request->channels + n_channels); 7862 } 7863 7864 if (n_match_sets) { 7865 if (request->ie) 7866 request->match_sets = (void *)(request->ie + ie_len); 7867 else if (n_ssids) 7868 request->match_sets = 7869 (void *)(request->ssids + n_ssids); 7870 else 7871 request->match_sets = 7872 (void *)(request->channels + n_channels); 7873 } 7874 request->n_match_sets = n_match_sets; 7875 7876 if (n_match_sets) 7877 request->scan_plans = (void *)(request->match_sets + 7878 n_match_sets); 7879 else if (request->ie) 7880 request->scan_plans = (void *)(request->ie + ie_len); 7881 else if (n_ssids) 7882 request->scan_plans = (void *)(request->ssids + n_ssids); 7883 else 7884 request->scan_plans = (void *)(request->channels + n_channels); 7885 7886 request->n_scan_plans = n_plans; 7887 7888 i = 0; 7889 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 7890 /* user specified, bail out if channel not found */ 7891 nla_for_each_nested(attr, 7892 attrs[NL80211_ATTR_SCAN_FREQUENCIES], 7893 tmp) { 7894 struct ieee80211_channel *chan; 7895 7896 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 7897 7898 if (!chan) { 7899 err = -EINVAL; 7900 goto out_free; 7901 } 7902 7903 /* ignore disabled channels */ 7904 if (chan->flags & IEEE80211_CHAN_DISABLED) 7905 continue; 7906 7907 request->channels[i] = chan; 7908 i++; 7909 } 7910 } else { 7911 /* all channels */ 7912 for (band = 0; band < NUM_NL80211_BANDS; band++) { 7913 int j; 7914 7915 if (!wiphy->bands[band]) 7916 continue; 7917 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 7918 struct ieee80211_channel *chan; 7919 7920 chan = &wiphy->bands[band]->channels[j]; 7921 7922 if (chan->flags & IEEE80211_CHAN_DISABLED) 7923 continue; 7924 7925 request->channels[i] = chan; 7926 i++; 7927 } 7928 } 7929 } 7930 7931 if (!i) { 7932 err = -EINVAL; 7933 goto out_free; 7934 } 7935 7936 request->n_channels = i; 7937 7938 i = 0; 7939 if (n_ssids) { 7940 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 7941 tmp) { 7942 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 7943 err = -EINVAL; 7944 goto out_free; 7945 } 7946 request->ssids[i].ssid_len = nla_len(attr); 7947 memcpy(request->ssids[i].ssid, nla_data(attr), 7948 nla_len(attr)); 7949 i++; 7950 } 7951 } 7952 7953 i = 0; 7954 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 7955 nla_for_each_nested(attr, 7956 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 7957 tmp) { 7958 struct nlattr *ssid, *bssid, *rssi; 7959 7960 err = nla_parse_nested_deprecated(tb, 7961 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 7962 attr, 7963 nl80211_match_policy, 7964 NULL); 7965 if (err) 7966 goto out_free; 7967 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 7968 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 7969 7970 if (!ssid && !bssid) { 7971 i++; 7972 continue; 7973 } 7974 7975 if (WARN_ON(i >= n_match_sets)) { 7976 /* this indicates a programming error, 7977 * the loop above should have verified 7978 * things properly 7979 */ 7980 err = -EINVAL; 7981 goto out_free; 7982 } 7983 7984 if (ssid) { 7985 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { 7986 err = -EINVAL; 7987 goto out_free; 7988 } 7989 memcpy(request->match_sets[i].ssid.ssid, 7990 nla_data(ssid), nla_len(ssid)); 7991 request->match_sets[i].ssid.ssid_len = 7992 nla_len(ssid); 7993 } 7994 if (bssid) { 7995 if (nla_len(bssid) != ETH_ALEN) { 7996 err = -EINVAL; 7997 goto out_free; 7998 } 7999 memcpy(request->match_sets[i].bssid, 8000 nla_data(bssid), ETH_ALEN); 8001 } 8002 8003 /* special attribute - old implementation w/a */ 8004 request->match_sets[i].rssi_thold = default_match_rssi; 8005 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 8006 if (rssi) 8007 request->match_sets[i].rssi_thold = 8008 nla_get_s32(rssi); 8009 8010 /* Parse per band RSSI attribute */ 8011 err = nl80211_parse_sched_scan_per_band_rssi(wiphy, 8012 &request->match_sets[i], 8013 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], 8014 request->match_sets[i].rssi_thold); 8015 if (err) 8016 goto out_free; 8017 8018 i++; 8019 } 8020 8021 /* there was no other matchset, so the RSSI one is alone */ 8022 if (i == 0 && n_match_sets) 8023 request->match_sets[0].rssi_thold = default_match_rssi; 8024 8025 request->min_rssi_thold = INT_MAX; 8026 for (i = 0; i < n_match_sets; i++) 8027 request->min_rssi_thold = 8028 min(request->match_sets[i].rssi_thold, 8029 request->min_rssi_thold); 8030 } else { 8031 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; 8032 } 8033 8034 if (ie_len) { 8035 request->ie_len = ie_len; 8036 memcpy((void *)request->ie, 8037 nla_data(attrs[NL80211_ATTR_IE]), 8038 request->ie_len); 8039 } 8040 8041 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); 8042 if (err) 8043 goto out_free; 8044 8045 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) 8046 request->delay = 8047 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); 8048 8049 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { 8050 request->relative_rssi = nla_get_s8( 8051 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); 8052 request->relative_rssi_set = true; 8053 } 8054 8055 if (request->relative_rssi_set && 8056 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { 8057 struct nl80211_bss_select_rssi_adjust *rssi_adjust; 8058 8059 rssi_adjust = nla_data( 8060 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); 8061 request->rssi_adjust.band = rssi_adjust->band; 8062 request->rssi_adjust.delta = rssi_adjust->delta; 8063 if (!is_band_valid(wiphy, request->rssi_adjust.band)) { 8064 err = -EINVAL; 8065 goto out_free; 8066 } 8067 } 8068 8069 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); 8070 if (err) 8071 goto out_free; 8072 8073 request->scan_start = jiffies; 8074 8075 return request; 8076 8077 out_free: 8078 kfree(request); 8079 return ERR_PTR(err); 8080 } 8081 8082 static int nl80211_start_sched_scan(struct sk_buff *skb, 8083 struct genl_info *info) 8084 { 8085 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8086 struct net_device *dev = info->user_ptr[1]; 8087 struct wireless_dev *wdev = dev->ieee80211_ptr; 8088 struct cfg80211_sched_scan_request *sched_scan_req; 8089 bool want_multi; 8090 int err; 8091 8092 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) 8093 return -EOPNOTSUPP; 8094 8095 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; 8096 err = cfg80211_sched_scan_req_possible(rdev, want_multi); 8097 if (err) 8098 return err; 8099 8100 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, 8101 info->attrs, 8102 rdev->wiphy.max_match_sets); 8103 8104 err = PTR_ERR_OR_ZERO(sched_scan_req); 8105 if (err) 8106 goto out_err; 8107 8108 /* leave request id zero for legacy request 8109 * or if driver does not support multi-scheduled scan 8110 */ 8111 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { 8112 while (!sched_scan_req->reqid) 8113 sched_scan_req->reqid = cfg80211_assign_cookie(rdev); 8114 } 8115 8116 err = rdev_sched_scan_start(rdev, dev, sched_scan_req); 8117 if (err) 8118 goto out_free; 8119 8120 sched_scan_req->dev = dev; 8121 sched_scan_req->wiphy = &rdev->wiphy; 8122 8123 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 8124 sched_scan_req->owner_nlportid = info->snd_portid; 8125 8126 cfg80211_add_sched_scan_req(rdev, sched_scan_req); 8127 8128 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); 8129 return 0; 8130 8131 out_free: 8132 kfree(sched_scan_req); 8133 out_err: 8134 return err; 8135 } 8136 8137 static int nl80211_stop_sched_scan(struct sk_buff *skb, 8138 struct genl_info *info) 8139 { 8140 struct cfg80211_sched_scan_request *req; 8141 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8142 u64 cookie; 8143 8144 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) 8145 return -EOPNOTSUPP; 8146 8147 if (info->attrs[NL80211_ATTR_COOKIE]) { 8148 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 8149 return __cfg80211_stop_sched_scan(rdev, cookie, false); 8150 } 8151 8152 req = list_first_or_null_rcu(&rdev->sched_scan_req_list, 8153 struct cfg80211_sched_scan_request, 8154 list); 8155 if (!req || req->reqid || 8156 (req->owner_nlportid && 8157 req->owner_nlportid != info->snd_portid)) 8158 return -ENOENT; 8159 8160 return cfg80211_stop_sched_scan_req(rdev, req, false); 8161 } 8162 8163 static int nl80211_start_radar_detection(struct sk_buff *skb, 8164 struct genl_info *info) 8165 { 8166 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8167 struct net_device *dev = info->user_ptr[1]; 8168 struct wireless_dev *wdev = dev->ieee80211_ptr; 8169 struct wiphy *wiphy = wdev->wiphy; 8170 struct cfg80211_chan_def chandef; 8171 enum nl80211_dfs_regions dfs_region; 8172 unsigned int cac_time_ms; 8173 int err; 8174 8175 dfs_region = reg_get_dfs_region(wiphy); 8176 if (dfs_region == NL80211_DFS_UNSET) 8177 return -EINVAL; 8178 8179 err = nl80211_parse_chandef(rdev, info, &chandef); 8180 if (err) 8181 return err; 8182 8183 if (netif_carrier_ok(dev)) 8184 return -EBUSY; 8185 8186 if (wdev->cac_started) 8187 return -EBUSY; 8188 8189 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 8190 if (err < 0) 8191 return err; 8192 8193 if (err == 0) 8194 return -EINVAL; 8195 8196 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) 8197 return -EINVAL; 8198 8199 /* CAC start is offloaded to HW and can't be started manually */ 8200 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) 8201 return -EOPNOTSUPP; 8202 8203 if (!rdev->ops->start_radar_detection) 8204 return -EOPNOTSUPP; 8205 8206 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 8207 if (WARN_ON(!cac_time_ms)) 8208 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; 8209 8210 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); 8211 if (!err) { 8212 wdev->chandef = chandef; 8213 wdev->cac_started = true; 8214 wdev->cac_start_time = jiffies; 8215 wdev->cac_time_ms = cac_time_ms; 8216 } 8217 return err; 8218 } 8219 8220 static int nl80211_notify_radar_detection(struct sk_buff *skb, 8221 struct genl_info *info) 8222 { 8223 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8224 struct net_device *dev = info->user_ptr[1]; 8225 struct wireless_dev *wdev = dev->ieee80211_ptr; 8226 struct wiphy *wiphy = wdev->wiphy; 8227 struct cfg80211_chan_def chandef; 8228 enum nl80211_dfs_regions dfs_region; 8229 int err; 8230 8231 dfs_region = reg_get_dfs_region(wiphy); 8232 if (dfs_region == NL80211_DFS_UNSET) { 8233 GENL_SET_ERR_MSG(info, 8234 "DFS Region is not set. Unexpected Radar indication"); 8235 return -EINVAL; 8236 } 8237 8238 err = nl80211_parse_chandef(rdev, info, &chandef); 8239 if (err) { 8240 GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); 8241 return err; 8242 } 8243 8244 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 8245 if (err < 0) { 8246 GENL_SET_ERR_MSG(info, "chandef is invalid"); 8247 return err; 8248 } 8249 8250 if (err == 0) { 8251 GENL_SET_ERR_MSG(info, 8252 "Unexpected Radar indication for chandef/iftype"); 8253 return -EINVAL; 8254 } 8255 8256 /* Do not process this notification if radar is already detected 8257 * by kernel on this channel, and return success. 8258 */ 8259 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) 8260 return 0; 8261 8262 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); 8263 8264 cfg80211_sched_dfs_chan_update(rdev); 8265 8266 rdev->radar_chandef = chandef; 8267 8268 /* Propagate this notification to other radios as well */ 8269 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 8270 8271 return 0; 8272 } 8273 8274 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) 8275 { 8276 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8277 struct net_device *dev = info->user_ptr[1]; 8278 struct wireless_dev *wdev = dev->ieee80211_ptr; 8279 struct cfg80211_csa_settings params; 8280 /* csa_attrs is defined static to avoid waste of stack size - this 8281 * function is called under RTNL lock, so this should not be a problem. 8282 */ 8283 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; 8284 int err; 8285 bool need_new_beacon = false; 8286 bool need_handle_dfs_flag = true; 8287 int len, i; 8288 u32 cs_count; 8289 8290 if (!rdev->ops->channel_switch || 8291 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 8292 return -EOPNOTSUPP; 8293 8294 switch (dev->ieee80211_ptr->iftype) { 8295 case NL80211_IFTYPE_AP: 8296 case NL80211_IFTYPE_P2P_GO: 8297 need_new_beacon = true; 8298 /* For all modes except AP the handle_dfs flag needs to be 8299 * supplied to tell the kernel that userspace will handle radar 8300 * events when they happen. Otherwise a switch to a channel 8301 * requiring DFS will be rejected. 8302 */ 8303 need_handle_dfs_flag = false; 8304 8305 /* useless if AP is not running */ 8306 if (!wdev->beacon_interval) 8307 return -ENOTCONN; 8308 break; 8309 case NL80211_IFTYPE_ADHOC: 8310 if (!wdev->ssid_len) 8311 return -ENOTCONN; 8312 break; 8313 case NL80211_IFTYPE_MESH_POINT: 8314 if (!wdev->mesh_id_len) 8315 return -ENOTCONN; 8316 break; 8317 default: 8318 return -EOPNOTSUPP; 8319 } 8320 8321 memset(¶ms, 0, sizeof(params)); 8322 params.beacon_csa.ftm_responder = -1; 8323 8324 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 8325 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) 8326 return -EINVAL; 8327 8328 /* only important for AP, IBSS and mesh create IEs internally */ 8329 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) 8330 return -EINVAL; 8331 8332 /* Even though the attribute is u32, the specification says 8333 * u8, so let's make sure we don't overflow. 8334 */ 8335 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); 8336 if (cs_count > 255) 8337 return -EINVAL; 8338 8339 params.count = cs_count; 8340 8341 if (!need_new_beacon) 8342 goto skip_beacons; 8343 8344 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); 8345 if (err) 8346 return err; 8347 8348 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, 8349 info->attrs[NL80211_ATTR_CSA_IES], 8350 nl80211_policy, info->extack); 8351 if (err) 8352 return err; 8353 8354 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); 8355 if (err) 8356 return err; 8357 8358 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) 8359 return -EINVAL; 8360 8361 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); 8362 if (!len || (len % sizeof(u16))) 8363 return -EINVAL; 8364 8365 params.n_counter_offsets_beacon = len / sizeof(u16); 8366 if (rdev->wiphy.max_num_csa_counters && 8367 (params.n_counter_offsets_beacon > 8368 rdev->wiphy.max_num_csa_counters)) 8369 return -EINVAL; 8370 8371 params.counter_offsets_beacon = 8372 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); 8373 8374 /* sanity checks - counters should fit and be the same */ 8375 for (i = 0; i < params.n_counter_offsets_beacon; i++) { 8376 u16 offset = params.counter_offsets_beacon[i]; 8377 8378 if (offset >= params.beacon_csa.tail_len) 8379 return -EINVAL; 8380 8381 if (params.beacon_csa.tail[offset] != params.count) 8382 return -EINVAL; 8383 } 8384 8385 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { 8386 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); 8387 if (!len || (len % sizeof(u16))) 8388 return -EINVAL; 8389 8390 params.n_counter_offsets_presp = len / sizeof(u16); 8391 if (rdev->wiphy.max_num_csa_counters && 8392 (params.n_counter_offsets_presp > 8393 rdev->wiphy.max_num_csa_counters)) 8394 return -EINVAL; 8395 8396 params.counter_offsets_presp = 8397 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); 8398 8399 /* sanity checks - counters should fit and be the same */ 8400 for (i = 0; i < params.n_counter_offsets_presp; i++) { 8401 u16 offset = params.counter_offsets_presp[i]; 8402 8403 if (offset >= params.beacon_csa.probe_resp_len) 8404 return -EINVAL; 8405 8406 if (params.beacon_csa.probe_resp[offset] != 8407 params.count) 8408 return -EINVAL; 8409 } 8410 } 8411 8412 skip_beacons: 8413 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 8414 if (err) 8415 return err; 8416 8417 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 8418 wdev->iftype)) 8419 return -EINVAL; 8420 8421 err = cfg80211_chandef_dfs_required(wdev->wiphy, 8422 ¶ms.chandef, 8423 wdev->iftype); 8424 if (err < 0) 8425 return err; 8426 8427 if (err > 0) { 8428 params.radar_required = true; 8429 if (need_handle_dfs_flag && 8430 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { 8431 return -EINVAL; 8432 } 8433 } 8434 8435 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 8436 params.block_tx = true; 8437 8438 wdev_lock(wdev); 8439 err = rdev_channel_switch(rdev, dev, ¶ms); 8440 wdev_unlock(wdev); 8441 8442 return err; 8443 } 8444 8445 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, 8446 u32 seq, int flags, 8447 struct cfg80211_registered_device *rdev, 8448 struct wireless_dev *wdev, 8449 struct cfg80211_internal_bss *intbss) 8450 { 8451 struct cfg80211_bss *res = &intbss->pub; 8452 const struct cfg80211_bss_ies *ies; 8453 void *hdr; 8454 struct nlattr *bss; 8455 8456 ASSERT_WDEV_LOCK(wdev); 8457 8458 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 8459 NL80211_CMD_NEW_SCAN_RESULTS); 8460 if (!hdr) 8461 return -1; 8462 8463 genl_dump_check_consistent(cb, hdr); 8464 8465 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) 8466 goto nla_put_failure; 8467 if (wdev->netdev && 8468 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) 8469 goto nla_put_failure; 8470 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 8471 NL80211_ATTR_PAD)) 8472 goto nla_put_failure; 8473 8474 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); 8475 if (!bss) 8476 goto nla_put_failure; 8477 if ((!is_zero_ether_addr(res->bssid) && 8478 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) 8479 goto nla_put_failure; 8480 8481 rcu_read_lock(); 8482 /* indicate whether we have probe response data or not */ 8483 if (rcu_access_pointer(res->proberesp_ies) && 8484 nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) 8485 goto fail_unlock_rcu; 8486 8487 /* this pointer prefers to be pointed to probe response data 8488 * but is always valid 8489 */ 8490 ies = rcu_dereference(res->ies); 8491 if (ies) { 8492 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, 8493 NL80211_BSS_PAD)) 8494 goto fail_unlock_rcu; 8495 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, 8496 ies->len, ies->data)) 8497 goto fail_unlock_rcu; 8498 } 8499 8500 /* and this pointer is always (unless driver didn't know) beacon data */ 8501 ies = rcu_dereference(res->beacon_ies); 8502 if (ies && ies->from_beacon) { 8503 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, 8504 NL80211_BSS_PAD)) 8505 goto fail_unlock_rcu; 8506 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, 8507 ies->len, ies->data)) 8508 goto fail_unlock_rcu; 8509 } 8510 rcu_read_unlock(); 8511 8512 if (res->beacon_interval && 8513 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) 8514 goto nla_put_failure; 8515 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || 8516 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || 8517 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || 8518 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, 8519 jiffies_to_msecs(jiffies - intbss->ts))) 8520 goto nla_put_failure; 8521 8522 if (intbss->parent_tsf && 8523 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, 8524 intbss->parent_tsf, NL80211_BSS_PAD) || 8525 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, 8526 intbss->parent_bssid))) 8527 goto nla_put_failure; 8528 8529 if (intbss->ts_boottime && 8530 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, 8531 intbss->ts_boottime, NL80211_BSS_PAD)) 8532 goto nla_put_failure; 8533 8534 if (!nl80211_put_signal(msg, intbss->pub.chains, 8535 intbss->pub.chain_signal, 8536 NL80211_BSS_CHAIN_SIGNAL)) 8537 goto nla_put_failure; 8538 8539 switch (rdev->wiphy.signal_type) { 8540 case CFG80211_SIGNAL_TYPE_MBM: 8541 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) 8542 goto nla_put_failure; 8543 break; 8544 case CFG80211_SIGNAL_TYPE_UNSPEC: 8545 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) 8546 goto nla_put_failure; 8547 break; 8548 default: 8549 break; 8550 } 8551 8552 switch (wdev->iftype) { 8553 case NL80211_IFTYPE_P2P_CLIENT: 8554 case NL80211_IFTYPE_STATION: 8555 if (intbss == wdev->current_bss && 8556 nla_put_u32(msg, NL80211_BSS_STATUS, 8557 NL80211_BSS_STATUS_ASSOCIATED)) 8558 goto nla_put_failure; 8559 break; 8560 case NL80211_IFTYPE_ADHOC: 8561 if (intbss == wdev->current_bss && 8562 nla_put_u32(msg, NL80211_BSS_STATUS, 8563 NL80211_BSS_STATUS_IBSS_JOINED)) 8564 goto nla_put_failure; 8565 break; 8566 default: 8567 break; 8568 } 8569 8570 nla_nest_end(msg, bss); 8571 8572 genlmsg_end(msg, hdr); 8573 return 0; 8574 8575 fail_unlock_rcu: 8576 rcu_read_unlock(); 8577 nla_put_failure: 8578 genlmsg_cancel(msg, hdr); 8579 return -EMSGSIZE; 8580 } 8581 8582 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) 8583 { 8584 struct cfg80211_registered_device *rdev; 8585 struct cfg80211_internal_bss *scan; 8586 struct wireless_dev *wdev; 8587 int start = cb->args[2], idx = 0; 8588 int err; 8589 8590 rtnl_lock(); 8591 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 8592 if (err) { 8593 rtnl_unlock(); 8594 return err; 8595 } 8596 8597 wdev_lock(wdev); 8598 spin_lock_bh(&rdev->bss_lock); 8599 8600 /* 8601 * dump_scan will be called multiple times to break up the scan results 8602 * into multiple messages. It is unlikely that any more bss-es will be 8603 * expired after the first call, so only call only call this on the 8604 * first dump_scan invocation. 8605 */ 8606 if (start == 0) 8607 cfg80211_bss_expire(rdev); 8608 8609 cb->seq = rdev->bss_generation; 8610 8611 list_for_each_entry(scan, &rdev->bss_list, list) { 8612 if (++idx <= start) 8613 continue; 8614 if (nl80211_send_bss(skb, cb, 8615 cb->nlh->nlmsg_seq, NLM_F_MULTI, 8616 rdev, wdev, scan) < 0) { 8617 idx--; 8618 break; 8619 } 8620 } 8621 8622 spin_unlock_bh(&rdev->bss_lock); 8623 wdev_unlock(wdev); 8624 8625 cb->args[2] = idx; 8626 rtnl_unlock(); 8627 8628 return skb->len; 8629 } 8630 8631 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, 8632 int flags, struct net_device *dev, 8633 bool allow_radio_stats, 8634 struct survey_info *survey) 8635 { 8636 void *hdr; 8637 struct nlattr *infoattr; 8638 8639 /* skip radio stats if userspace didn't request them */ 8640 if (!survey->channel && !allow_radio_stats) 8641 return 0; 8642 8643 hdr = nl80211hdr_put(msg, portid, seq, flags, 8644 NL80211_CMD_NEW_SURVEY_RESULTS); 8645 if (!hdr) 8646 return -ENOMEM; 8647 8648 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 8649 goto nla_put_failure; 8650 8651 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); 8652 if (!infoattr) 8653 goto nla_put_failure; 8654 8655 if (survey->channel && 8656 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, 8657 survey->channel->center_freq)) 8658 goto nla_put_failure; 8659 8660 if ((survey->filled & SURVEY_INFO_NOISE_DBM) && 8661 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) 8662 goto nla_put_failure; 8663 if ((survey->filled & SURVEY_INFO_IN_USE) && 8664 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) 8665 goto nla_put_failure; 8666 if ((survey->filled & SURVEY_INFO_TIME) && 8667 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, 8668 survey->time, NL80211_SURVEY_INFO_PAD)) 8669 goto nla_put_failure; 8670 if ((survey->filled & SURVEY_INFO_TIME_BUSY) && 8671 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, 8672 survey->time_busy, NL80211_SURVEY_INFO_PAD)) 8673 goto nla_put_failure; 8674 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && 8675 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, 8676 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) 8677 goto nla_put_failure; 8678 if ((survey->filled & SURVEY_INFO_TIME_RX) && 8679 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, 8680 survey->time_rx, NL80211_SURVEY_INFO_PAD)) 8681 goto nla_put_failure; 8682 if ((survey->filled & SURVEY_INFO_TIME_TX) && 8683 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, 8684 survey->time_tx, NL80211_SURVEY_INFO_PAD)) 8685 goto nla_put_failure; 8686 if ((survey->filled & SURVEY_INFO_TIME_SCAN) && 8687 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, 8688 survey->time_scan, NL80211_SURVEY_INFO_PAD)) 8689 goto nla_put_failure; 8690 8691 nla_nest_end(msg, infoattr); 8692 8693 genlmsg_end(msg, hdr); 8694 return 0; 8695 8696 nla_put_failure: 8697 genlmsg_cancel(msg, hdr); 8698 return -EMSGSIZE; 8699 } 8700 8701 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) 8702 { 8703 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); 8704 struct survey_info survey; 8705 struct cfg80211_registered_device *rdev; 8706 struct wireless_dev *wdev; 8707 int survey_idx = cb->args[2]; 8708 int res; 8709 bool radio_stats; 8710 8711 rtnl_lock(); 8712 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); 8713 if (res) 8714 goto out_err; 8715 8716 /* prepare_wdev_dump parsed the attributes */ 8717 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; 8718 8719 if (!wdev->netdev) { 8720 res = -EINVAL; 8721 goto out_err; 8722 } 8723 8724 if (!rdev->ops->dump_survey) { 8725 res = -EOPNOTSUPP; 8726 goto out_err; 8727 } 8728 8729 while (1) { 8730 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); 8731 if (res == -ENOENT) 8732 break; 8733 if (res) 8734 goto out_err; 8735 8736 /* don't send disabled channels, but do send non-channel data */ 8737 if (survey.channel && 8738 survey.channel->flags & IEEE80211_CHAN_DISABLED) { 8739 survey_idx++; 8740 continue; 8741 } 8742 8743 if (nl80211_send_survey(skb, 8744 NETLINK_CB(cb->skb).portid, 8745 cb->nlh->nlmsg_seq, NLM_F_MULTI, 8746 wdev->netdev, radio_stats, &survey) < 0) 8747 goto out; 8748 survey_idx++; 8749 } 8750 8751 out: 8752 cb->args[2] = survey_idx; 8753 res = skb->len; 8754 out_err: 8755 rtnl_unlock(); 8756 return res; 8757 } 8758 8759 static bool nl80211_valid_wpa_versions(u32 wpa_versions) 8760 { 8761 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | 8762 NL80211_WPA_VERSION_2 | 8763 NL80211_WPA_VERSION_3)); 8764 } 8765 8766 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 8767 { 8768 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8769 struct net_device *dev = info->user_ptr[1]; 8770 struct ieee80211_channel *chan; 8771 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; 8772 int err, ssid_len, ie_len = 0, auth_data_len = 0; 8773 enum nl80211_auth_type auth_type; 8774 struct key_parse key; 8775 bool local_state_change; 8776 8777 if (!info->attrs[NL80211_ATTR_MAC]) 8778 return -EINVAL; 8779 8780 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 8781 return -EINVAL; 8782 8783 if (!info->attrs[NL80211_ATTR_SSID]) 8784 return -EINVAL; 8785 8786 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 8787 return -EINVAL; 8788 8789 err = nl80211_parse_key(info, &key); 8790 if (err) 8791 return err; 8792 8793 if (key.idx >= 0) { 8794 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) 8795 return -EINVAL; 8796 if (!key.p.key || !key.p.key_len) 8797 return -EINVAL; 8798 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 8799 key.p.key_len != WLAN_KEY_LEN_WEP40) && 8800 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || 8801 key.p.key_len != WLAN_KEY_LEN_WEP104)) 8802 return -EINVAL; 8803 if (key.idx > 3) 8804 return -EINVAL; 8805 } else { 8806 key.p.key_len = 0; 8807 key.p.key = NULL; 8808 } 8809 8810 if (key.idx >= 0) { 8811 int i; 8812 bool ok = false; 8813 8814 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { 8815 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { 8816 ok = true; 8817 break; 8818 } 8819 } 8820 if (!ok) 8821 return -EINVAL; 8822 } 8823 8824 if (!rdev->ops->auth) 8825 return -EOPNOTSUPP; 8826 8827 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 8828 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 8829 return -EOPNOTSUPP; 8830 8831 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 8832 chan = nl80211_get_valid_chan(&rdev->wiphy, 8833 info->attrs[NL80211_ATTR_WIPHY_FREQ]); 8834 if (!chan) 8835 return -EINVAL; 8836 8837 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 8838 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 8839 8840 if (info->attrs[NL80211_ATTR_IE]) { 8841 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 8842 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 8843 } 8844 8845 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 8846 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) 8847 return -EINVAL; 8848 8849 if ((auth_type == NL80211_AUTHTYPE_SAE || 8850 auth_type == NL80211_AUTHTYPE_FILS_SK || 8851 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 8852 auth_type == NL80211_AUTHTYPE_FILS_PK) && 8853 !info->attrs[NL80211_ATTR_AUTH_DATA]) 8854 return -EINVAL; 8855 8856 if (info->attrs[NL80211_ATTR_AUTH_DATA]) { 8857 if (auth_type != NL80211_AUTHTYPE_SAE && 8858 auth_type != NL80211_AUTHTYPE_FILS_SK && 8859 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && 8860 auth_type != NL80211_AUTHTYPE_FILS_PK) 8861 return -EINVAL; 8862 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); 8863 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); 8864 /* need to include at least Auth Transaction and Status Code */ 8865 if (auth_data_len < 4) 8866 return -EINVAL; 8867 } 8868 8869 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 8870 8871 /* 8872 * Since we no longer track auth state, ignore 8873 * requests to only change local state. 8874 */ 8875 if (local_state_change) 8876 return 0; 8877 8878 wdev_lock(dev->ieee80211_ptr); 8879 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, 8880 ssid, ssid_len, ie, ie_len, 8881 key.p.key, key.p.key_len, key.idx, 8882 auth_data, auth_data_len); 8883 wdev_unlock(dev->ieee80211_ptr); 8884 return err; 8885 } 8886 8887 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, 8888 struct genl_info *info) 8889 { 8890 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 8891 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); 8892 return -EINVAL; 8893 } 8894 8895 if (!rdev->ops->tx_control_port || 8896 !wiphy_ext_feature_isset(&rdev->wiphy, 8897 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 8898 return -EOPNOTSUPP; 8899 8900 return 0; 8901 } 8902 8903 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 8904 struct genl_info *info, 8905 struct cfg80211_crypto_settings *settings, 8906 int cipher_limit) 8907 { 8908 memset(settings, 0, sizeof(*settings)); 8909 8910 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 8911 8912 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 8913 u16 proto; 8914 8915 proto = nla_get_u16( 8916 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 8917 settings->control_port_ethertype = cpu_to_be16(proto); 8918 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 8919 proto != ETH_P_PAE) 8920 return -EINVAL; 8921 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) 8922 settings->control_port_no_encrypt = true; 8923 } else 8924 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); 8925 8926 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 8927 int r = validate_pae_over_nl80211(rdev, info); 8928 8929 if (r < 0) 8930 return r; 8931 8932 settings->control_port_over_nl80211 = true; 8933 } 8934 8935 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 8936 void *data; 8937 int len, i; 8938 8939 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 8940 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 8941 settings->n_ciphers_pairwise = len / sizeof(u32); 8942 8943 if (len % sizeof(u32)) 8944 return -EINVAL; 8945 8946 if (settings->n_ciphers_pairwise > cipher_limit) 8947 return -EINVAL; 8948 8949 memcpy(settings->ciphers_pairwise, data, len); 8950 8951 for (i = 0; i < settings->n_ciphers_pairwise; i++) 8952 if (!cfg80211_supported_cipher_suite( 8953 &rdev->wiphy, 8954 settings->ciphers_pairwise[i])) 8955 return -EINVAL; 8956 } 8957 8958 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { 8959 settings->cipher_group = 8960 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); 8961 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, 8962 settings->cipher_group)) 8963 return -EINVAL; 8964 } 8965 8966 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { 8967 settings->wpa_versions = 8968 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); 8969 if (!nl80211_valid_wpa_versions(settings->wpa_versions)) 8970 return -EINVAL; 8971 } 8972 8973 if (info->attrs[NL80211_ATTR_AKM_SUITES]) { 8974 void *data; 8975 int len; 8976 8977 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); 8978 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); 8979 settings->n_akm_suites = len / sizeof(u32); 8980 8981 if (len % sizeof(u32)) 8982 return -EINVAL; 8983 8984 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) 8985 return -EINVAL; 8986 8987 memcpy(settings->akm_suites, data, len); 8988 } 8989 8990 if (info->attrs[NL80211_ATTR_PMK]) { 8991 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) 8992 return -EINVAL; 8993 if (!wiphy_ext_feature_isset(&rdev->wiphy, 8994 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) 8995 return -EINVAL; 8996 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); 8997 } 8998 8999 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { 9000 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9001 NL80211_EXT_FEATURE_SAE_OFFLOAD)) 9002 return -EINVAL; 9003 settings->sae_pwd = 9004 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 9005 settings->sae_pwd_len = 9006 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 9007 } 9008 9009 return 0; 9010 } 9011 9012 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 9013 { 9014 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9015 struct net_device *dev = info->user_ptr[1]; 9016 struct ieee80211_channel *chan; 9017 struct cfg80211_assoc_request req = {}; 9018 const u8 *bssid, *ssid; 9019 int err, ssid_len = 0; 9020 9021 if (dev->ieee80211_ptr->conn_owner_nlportid && 9022 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9023 return -EPERM; 9024 9025 if (!info->attrs[NL80211_ATTR_MAC] || 9026 !info->attrs[NL80211_ATTR_SSID] || 9027 !info->attrs[NL80211_ATTR_WIPHY_FREQ]) 9028 return -EINVAL; 9029 9030 if (!rdev->ops->assoc) 9031 return -EOPNOTSUPP; 9032 9033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9034 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9035 return -EOPNOTSUPP; 9036 9037 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9038 9039 chan = nl80211_get_valid_chan(&rdev->wiphy, 9040 info->attrs[NL80211_ATTR_WIPHY_FREQ]); 9041 if (!chan) 9042 return -EINVAL; 9043 9044 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9045 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9046 9047 if (info->attrs[NL80211_ATTR_IE]) { 9048 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9049 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9050 } 9051 9052 if (info->attrs[NL80211_ATTR_USE_MFP]) { 9053 enum nl80211_mfp mfp = 9054 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 9055 if (mfp == NL80211_MFP_REQUIRED) 9056 req.use_mfp = true; 9057 else if (mfp != NL80211_MFP_NO) 9058 return -EINVAL; 9059 } 9060 9061 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 9062 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 9063 9064 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 9065 req.flags |= ASSOC_REQ_DISABLE_HT; 9066 9067 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9068 memcpy(&req.ht_capa_mask, 9069 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 9070 sizeof(req.ht_capa_mask)); 9071 9072 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 9073 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9074 return -EINVAL; 9075 memcpy(&req.ht_capa, 9076 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 9077 sizeof(req.ht_capa)); 9078 } 9079 9080 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 9081 req.flags |= ASSOC_REQ_DISABLE_VHT; 9082 9083 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 9084 memcpy(&req.vht_capa_mask, 9085 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 9086 sizeof(req.vht_capa_mask)); 9087 9088 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 9089 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 9090 return -EINVAL; 9091 memcpy(&req.vht_capa, 9092 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 9093 sizeof(req.vht_capa)); 9094 } 9095 9096 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 9097 if (!((rdev->wiphy.features & 9098 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 9099 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 9100 !wiphy_ext_feature_isset(&rdev->wiphy, 9101 NL80211_EXT_FEATURE_RRM)) 9102 return -EINVAL; 9103 req.flags |= ASSOC_REQ_USE_RRM; 9104 } 9105 9106 if (info->attrs[NL80211_ATTR_FILS_KEK]) { 9107 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 9108 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 9109 if (!info->attrs[NL80211_ATTR_FILS_NONCES]) 9110 return -EINVAL; 9111 req.fils_nonces = 9112 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 9113 } 9114 9115 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); 9116 if (!err) { 9117 wdev_lock(dev->ieee80211_ptr); 9118 9119 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, 9120 ssid, ssid_len, &req); 9121 9122 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 9123 dev->ieee80211_ptr->conn_owner_nlportid = 9124 info->snd_portid; 9125 memcpy(dev->ieee80211_ptr->disconnect_bssid, 9126 bssid, ETH_ALEN); 9127 } 9128 9129 wdev_unlock(dev->ieee80211_ptr); 9130 } 9131 9132 return err; 9133 } 9134 9135 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 9136 { 9137 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9138 struct net_device *dev = info->user_ptr[1]; 9139 const u8 *ie = NULL, *bssid; 9140 int ie_len = 0, err; 9141 u16 reason_code; 9142 bool local_state_change; 9143 9144 if (dev->ieee80211_ptr->conn_owner_nlportid && 9145 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9146 return -EPERM; 9147 9148 if (!info->attrs[NL80211_ATTR_MAC]) 9149 return -EINVAL; 9150 9151 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 9152 return -EINVAL; 9153 9154 if (!rdev->ops->deauth) 9155 return -EOPNOTSUPP; 9156 9157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9158 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9159 return -EOPNOTSUPP; 9160 9161 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9162 9163 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 9164 if (reason_code == 0) { 9165 /* Reason Code 0 is reserved */ 9166 return -EINVAL; 9167 } 9168 9169 if (info->attrs[NL80211_ATTR_IE]) { 9170 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9171 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9172 } 9173 9174 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 9175 9176 wdev_lock(dev->ieee80211_ptr); 9177 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 9178 local_state_change); 9179 wdev_unlock(dev->ieee80211_ptr); 9180 return err; 9181 } 9182 9183 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 9184 { 9185 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9186 struct net_device *dev = info->user_ptr[1]; 9187 const u8 *ie = NULL, *bssid; 9188 int ie_len = 0, err; 9189 u16 reason_code; 9190 bool local_state_change; 9191 9192 if (dev->ieee80211_ptr->conn_owner_nlportid && 9193 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 9194 return -EPERM; 9195 9196 if (!info->attrs[NL80211_ATTR_MAC]) 9197 return -EINVAL; 9198 9199 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 9200 return -EINVAL; 9201 9202 if (!rdev->ops->disassoc) 9203 return -EOPNOTSUPP; 9204 9205 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9206 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9207 return -EOPNOTSUPP; 9208 9209 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9210 9211 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 9212 if (reason_code == 0) { 9213 /* Reason Code 0 is reserved */ 9214 return -EINVAL; 9215 } 9216 9217 if (info->attrs[NL80211_ATTR_IE]) { 9218 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9219 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9220 } 9221 9222 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 9223 9224 wdev_lock(dev->ieee80211_ptr); 9225 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 9226 local_state_change); 9227 wdev_unlock(dev->ieee80211_ptr); 9228 return err; 9229 } 9230 9231 static bool 9232 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, 9233 int mcast_rate[NUM_NL80211_BANDS], 9234 int rateval) 9235 { 9236 struct wiphy *wiphy = &rdev->wiphy; 9237 bool found = false; 9238 int band, i; 9239 9240 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9241 struct ieee80211_supported_band *sband; 9242 9243 sband = wiphy->bands[band]; 9244 if (!sband) 9245 continue; 9246 9247 for (i = 0; i < sband->n_bitrates; i++) { 9248 if (sband->bitrates[i].bitrate == rateval) { 9249 mcast_rate[band] = i + 1; 9250 found = true; 9251 break; 9252 } 9253 } 9254 } 9255 9256 return found; 9257 } 9258 9259 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 9260 { 9261 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9262 struct net_device *dev = info->user_ptr[1]; 9263 struct cfg80211_ibss_params ibss; 9264 struct wiphy *wiphy; 9265 struct cfg80211_cached_keys *connkeys = NULL; 9266 int err; 9267 9268 memset(&ibss, 0, sizeof(ibss)); 9269 9270 if (!info->attrs[NL80211_ATTR_SSID] || 9271 !nla_len(info->attrs[NL80211_ATTR_SSID])) 9272 return -EINVAL; 9273 9274 ibss.beacon_interval = 100; 9275 9276 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) 9277 ibss.beacon_interval = 9278 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 9279 9280 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, 9281 ibss.beacon_interval); 9282 if (err) 9283 return err; 9284 9285 if (!rdev->ops->join_ibss) 9286 return -EOPNOTSUPP; 9287 9288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 9289 return -EOPNOTSUPP; 9290 9291 wiphy = &rdev->wiphy; 9292 9293 if (info->attrs[NL80211_ATTR_MAC]) { 9294 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9295 9296 if (!is_valid_ether_addr(ibss.bssid)) 9297 return -EINVAL; 9298 } 9299 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9300 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9301 9302 if (info->attrs[NL80211_ATTR_IE]) { 9303 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9304 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9305 } 9306 9307 err = nl80211_parse_chandef(rdev, info, &ibss.chandef); 9308 if (err) 9309 return err; 9310 9311 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, 9312 NL80211_IFTYPE_ADHOC)) 9313 return -EINVAL; 9314 9315 switch (ibss.chandef.width) { 9316 case NL80211_CHAN_WIDTH_5: 9317 case NL80211_CHAN_WIDTH_10: 9318 case NL80211_CHAN_WIDTH_20_NOHT: 9319 break; 9320 case NL80211_CHAN_WIDTH_20: 9321 case NL80211_CHAN_WIDTH_40: 9322 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 9323 return -EINVAL; 9324 break; 9325 case NL80211_CHAN_WIDTH_80: 9326 case NL80211_CHAN_WIDTH_80P80: 9327 case NL80211_CHAN_WIDTH_160: 9328 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 9329 return -EINVAL; 9330 if (!wiphy_ext_feature_isset(&rdev->wiphy, 9331 NL80211_EXT_FEATURE_VHT_IBSS)) 9332 return -EINVAL; 9333 break; 9334 default: 9335 return -EINVAL; 9336 } 9337 9338 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 9339 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 9340 9341 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 9342 u8 *rates = 9343 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 9344 int n_rates = 9345 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 9346 struct ieee80211_supported_band *sband = 9347 wiphy->bands[ibss.chandef.chan->band]; 9348 9349 err = ieee80211_get_ratemask(sband, rates, n_rates, 9350 &ibss.basic_rates); 9351 if (err) 9352 return err; 9353 } 9354 9355 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9356 memcpy(&ibss.ht_capa_mask, 9357 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 9358 sizeof(ibss.ht_capa_mask)); 9359 9360 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 9361 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9362 return -EINVAL; 9363 memcpy(&ibss.ht_capa, 9364 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 9365 sizeof(ibss.ht_capa)); 9366 } 9367 9368 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 9369 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, 9370 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 9371 return -EINVAL; 9372 9373 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { 9374 bool no_ht = false; 9375 9376 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); 9377 if (IS_ERR(connkeys)) 9378 return PTR_ERR(connkeys); 9379 9380 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && 9381 no_ht) { 9382 kzfree(connkeys); 9383 return -EINVAL; 9384 } 9385 } 9386 9387 ibss.control_port = 9388 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); 9389 9390 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 9391 int r = validate_pae_over_nl80211(rdev, info); 9392 9393 if (r < 0) { 9394 kzfree(connkeys); 9395 return r; 9396 } 9397 9398 ibss.control_port_over_nl80211 = true; 9399 } 9400 9401 ibss.userspace_handles_dfs = 9402 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 9403 9404 wdev_lock(dev->ieee80211_ptr); 9405 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 9406 if (err) 9407 kzfree(connkeys); 9408 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 9409 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 9410 wdev_unlock(dev->ieee80211_ptr); 9411 9412 return err; 9413 } 9414 9415 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 9416 { 9417 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9418 struct net_device *dev = info->user_ptr[1]; 9419 9420 if (!rdev->ops->leave_ibss) 9421 return -EOPNOTSUPP; 9422 9423 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 9424 return -EOPNOTSUPP; 9425 9426 return cfg80211_leave_ibss(rdev, dev, false); 9427 } 9428 9429 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) 9430 { 9431 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9432 struct net_device *dev = info->user_ptr[1]; 9433 int mcast_rate[NUM_NL80211_BANDS]; 9434 u32 nla_rate; 9435 int err; 9436 9437 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && 9438 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 9439 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) 9440 return -EOPNOTSUPP; 9441 9442 if (!rdev->ops->set_mcast_rate) 9443 return -EOPNOTSUPP; 9444 9445 memset(mcast_rate, 0, sizeof(mcast_rate)); 9446 9447 if (!info->attrs[NL80211_ATTR_MCAST_RATE]) 9448 return -EINVAL; 9449 9450 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); 9451 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) 9452 return -EINVAL; 9453 9454 err = rdev_set_mcast_rate(rdev, dev, mcast_rate); 9455 9456 return err; 9457 } 9458 9459 static struct sk_buff * 9460 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, 9461 struct wireless_dev *wdev, int approxlen, 9462 u32 portid, u32 seq, enum nl80211_commands cmd, 9463 enum nl80211_attrs attr, 9464 const struct nl80211_vendor_cmd_info *info, 9465 gfp_t gfp) 9466 { 9467 struct sk_buff *skb; 9468 void *hdr; 9469 struct nlattr *data; 9470 9471 skb = nlmsg_new(approxlen + 100, gfp); 9472 if (!skb) 9473 return NULL; 9474 9475 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); 9476 if (!hdr) { 9477 kfree_skb(skb); 9478 return NULL; 9479 } 9480 9481 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 9482 goto nla_put_failure; 9483 9484 if (info) { 9485 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, 9486 info->vendor_id)) 9487 goto nla_put_failure; 9488 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, 9489 info->subcmd)) 9490 goto nla_put_failure; 9491 } 9492 9493 if (wdev) { 9494 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 9495 wdev_id(wdev), NL80211_ATTR_PAD)) 9496 goto nla_put_failure; 9497 if (wdev->netdev && 9498 nla_put_u32(skb, NL80211_ATTR_IFINDEX, 9499 wdev->netdev->ifindex)) 9500 goto nla_put_failure; 9501 } 9502 9503 data = nla_nest_start_noflag(skb, attr); 9504 if (!data) 9505 goto nla_put_failure; 9506 9507 ((void **)skb->cb)[0] = rdev; 9508 ((void **)skb->cb)[1] = hdr; 9509 ((void **)skb->cb)[2] = data; 9510 9511 return skb; 9512 9513 nla_put_failure: 9514 kfree_skb(skb); 9515 return NULL; 9516 } 9517 9518 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, 9519 struct wireless_dev *wdev, 9520 enum nl80211_commands cmd, 9521 enum nl80211_attrs attr, 9522 unsigned int portid, 9523 int vendor_event_idx, 9524 int approxlen, gfp_t gfp) 9525 { 9526 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 9527 const struct nl80211_vendor_cmd_info *info; 9528 9529 switch (cmd) { 9530 case NL80211_CMD_TESTMODE: 9531 if (WARN_ON(vendor_event_idx != -1)) 9532 return NULL; 9533 info = NULL; 9534 break; 9535 case NL80211_CMD_VENDOR: 9536 if (WARN_ON(vendor_event_idx < 0 || 9537 vendor_event_idx >= wiphy->n_vendor_events)) 9538 return NULL; 9539 info = &wiphy->vendor_events[vendor_event_idx]; 9540 break; 9541 default: 9542 WARN_ON(1); 9543 return NULL; 9544 } 9545 9546 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, 9547 cmd, attr, info, gfp); 9548 } 9549 EXPORT_SYMBOL(__cfg80211_alloc_event_skb); 9550 9551 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) 9552 { 9553 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 9554 void *hdr = ((void **)skb->cb)[1]; 9555 struct nlmsghdr *nlhdr = nlmsg_hdr(skb); 9556 struct nlattr *data = ((void **)skb->cb)[2]; 9557 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; 9558 9559 /* clear CB data for netlink core to own from now on */ 9560 memset(skb->cb, 0, sizeof(skb->cb)); 9561 9562 nla_nest_end(skb, data); 9563 genlmsg_end(skb, hdr); 9564 9565 if (nlhdr->nlmsg_pid) { 9566 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, 9567 nlhdr->nlmsg_pid); 9568 } else { 9569 if (data->nla_type == NL80211_ATTR_VENDOR_DATA) 9570 mcgrp = NL80211_MCGRP_VENDOR; 9571 9572 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 9573 skb, 0, mcgrp, gfp); 9574 } 9575 } 9576 EXPORT_SYMBOL(__cfg80211_send_event_skb); 9577 9578 #ifdef CONFIG_NL80211_TESTMODE 9579 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 9580 { 9581 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9582 struct wireless_dev *wdev = 9583 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); 9584 int err; 9585 9586 if (!rdev->ops->testmode_cmd) 9587 return -EOPNOTSUPP; 9588 9589 if (IS_ERR(wdev)) { 9590 err = PTR_ERR(wdev); 9591 if (err != -EINVAL) 9592 return err; 9593 wdev = NULL; 9594 } else if (wdev->wiphy != &rdev->wiphy) { 9595 return -EINVAL; 9596 } 9597 9598 if (!info->attrs[NL80211_ATTR_TESTDATA]) 9599 return -EINVAL; 9600 9601 rdev->cur_cmd_info = info; 9602 err = rdev_testmode_cmd(rdev, wdev, 9603 nla_data(info->attrs[NL80211_ATTR_TESTDATA]), 9604 nla_len(info->attrs[NL80211_ATTR_TESTDATA])); 9605 rdev->cur_cmd_info = NULL; 9606 9607 return err; 9608 } 9609 9610 static int nl80211_testmode_dump(struct sk_buff *skb, 9611 struct netlink_callback *cb) 9612 { 9613 struct cfg80211_registered_device *rdev; 9614 int err; 9615 long phy_idx; 9616 void *data = NULL; 9617 int data_len = 0; 9618 9619 rtnl_lock(); 9620 9621 if (cb->args[0]) { 9622 /* 9623 * 0 is a valid index, but not valid for args[0], 9624 * so we need to offset by 1. 9625 */ 9626 phy_idx = cb->args[0] - 1; 9627 9628 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); 9629 if (!rdev) { 9630 err = -ENOENT; 9631 goto out_err; 9632 } 9633 } else { 9634 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); 9635 9636 err = nlmsg_parse_deprecated(cb->nlh, 9637 GENL_HDRLEN + nl80211_fam.hdrsize, 9638 attrbuf, nl80211_fam.maxattr, 9639 nl80211_policy, NULL); 9640 if (err) 9641 goto out_err; 9642 9643 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 9644 if (IS_ERR(rdev)) { 9645 err = PTR_ERR(rdev); 9646 goto out_err; 9647 } 9648 phy_idx = rdev->wiphy_idx; 9649 9650 if (attrbuf[NL80211_ATTR_TESTDATA]) 9651 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; 9652 } 9653 9654 if (cb->args[1]) { 9655 data = nla_data((void *)cb->args[1]); 9656 data_len = nla_len((void *)cb->args[1]); 9657 } 9658 9659 if (!rdev->ops->testmode_dump) { 9660 err = -EOPNOTSUPP; 9661 goto out_err; 9662 } 9663 9664 while (1) { 9665 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 9666 cb->nlh->nlmsg_seq, NLM_F_MULTI, 9667 NL80211_CMD_TESTMODE); 9668 struct nlattr *tmdata; 9669 9670 if (!hdr) 9671 break; 9672 9673 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { 9674 genlmsg_cancel(skb, hdr); 9675 break; 9676 } 9677 9678 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); 9679 if (!tmdata) { 9680 genlmsg_cancel(skb, hdr); 9681 break; 9682 } 9683 err = rdev_testmode_dump(rdev, skb, cb, data, data_len); 9684 nla_nest_end(skb, tmdata); 9685 9686 if (err == -ENOBUFS || err == -ENOENT) { 9687 genlmsg_cancel(skb, hdr); 9688 break; 9689 } else if (err) { 9690 genlmsg_cancel(skb, hdr); 9691 goto out_err; 9692 } 9693 9694 genlmsg_end(skb, hdr); 9695 } 9696 9697 err = skb->len; 9698 /* see above */ 9699 cb->args[0] = phy_idx + 1; 9700 out_err: 9701 rtnl_unlock(); 9702 return err; 9703 } 9704 #endif 9705 9706 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 9707 { 9708 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9709 struct net_device *dev = info->user_ptr[1]; 9710 struct cfg80211_connect_params connect; 9711 struct wiphy *wiphy; 9712 struct cfg80211_cached_keys *connkeys = NULL; 9713 int err; 9714 9715 memset(&connect, 0, sizeof(connect)); 9716 9717 if (!info->attrs[NL80211_ATTR_SSID] || 9718 !nla_len(info->attrs[NL80211_ATTR_SSID])) 9719 return -EINVAL; 9720 9721 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 9722 connect.auth_type = 9723 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 9724 if (!nl80211_valid_auth_type(rdev, connect.auth_type, 9725 NL80211_CMD_CONNECT)) 9726 return -EINVAL; 9727 } else 9728 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 9729 9730 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 9731 9732 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && 9733 !wiphy_ext_feature_isset(&rdev->wiphy, 9734 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 9735 return -EINVAL; 9736 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; 9737 9738 err = nl80211_crypto_settings(rdev, info, &connect.crypto, 9739 NL80211_MAX_NR_CIPHER_SUITES); 9740 if (err) 9741 return err; 9742 9743 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 9744 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 9745 return -EOPNOTSUPP; 9746 9747 wiphy = &rdev->wiphy; 9748 9749 connect.bg_scan_period = -1; 9750 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && 9751 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { 9752 connect.bg_scan_period = 9753 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); 9754 } 9755 9756 if (info->attrs[NL80211_ATTR_MAC]) 9757 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 9758 else if (info->attrs[NL80211_ATTR_MAC_HINT]) 9759 connect.bssid_hint = 9760 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); 9761 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 9762 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 9763 9764 if (info->attrs[NL80211_ATTR_IE]) { 9765 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9766 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9767 } 9768 9769 if (info->attrs[NL80211_ATTR_USE_MFP]) { 9770 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 9771 if (connect.mfp == NL80211_MFP_OPTIONAL && 9772 !wiphy_ext_feature_isset(&rdev->wiphy, 9773 NL80211_EXT_FEATURE_MFP_OPTIONAL)) 9774 return -EOPNOTSUPP; 9775 } else { 9776 connect.mfp = NL80211_MFP_NO; 9777 } 9778 9779 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 9780 connect.prev_bssid = 9781 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 9782 9783 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 9784 connect.channel = nl80211_get_valid_chan( 9785 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); 9786 if (!connect.channel) 9787 return -EINVAL; 9788 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { 9789 connect.channel_hint = nl80211_get_valid_chan( 9790 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); 9791 if (!connect.channel_hint) 9792 return -EINVAL; 9793 } 9794 9795 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 9796 connkeys = nl80211_parse_connkeys(rdev, info, NULL); 9797 if (IS_ERR(connkeys)) 9798 return PTR_ERR(connkeys); 9799 } 9800 9801 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 9802 connect.flags |= ASSOC_REQ_DISABLE_HT; 9803 9804 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 9805 memcpy(&connect.ht_capa_mask, 9806 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 9807 sizeof(connect.ht_capa_mask)); 9808 9809 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 9810 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { 9811 kzfree(connkeys); 9812 return -EINVAL; 9813 } 9814 memcpy(&connect.ht_capa, 9815 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 9816 sizeof(connect.ht_capa)); 9817 } 9818 9819 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 9820 connect.flags |= ASSOC_REQ_DISABLE_VHT; 9821 9822 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 9823 memcpy(&connect.vht_capa_mask, 9824 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 9825 sizeof(connect.vht_capa_mask)); 9826 9827 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 9828 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { 9829 kzfree(connkeys); 9830 return -EINVAL; 9831 } 9832 memcpy(&connect.vht_capa, 9833 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 9834 sizeof(connect.vht_capa)); 9835 } 9836 9837 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 9838 if (!((rdev->wiphy.features & 9839 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 9840 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 9841 !wiphy_ext_feature_isset(&rdev->wiphy, 9842 NL80211_EXT_FEATURE_RRM)) { 9843 kzfree(connkeys); 9844 return -EINVAL; 9845 } 9846 connect.flags |= ASSOC_REQ_USE_RRM; 9847 } 9848 9849 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 9850 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 9851 kzfree(connkeys); 9852 return -EOPNOTSUPP; 9853 } 9854 9855 if (info->attrs[NL80211_ATTR_BSS_SELECT]) { 9856 /* bss selection makes no sense if bssid is set */ 9857 if (connect.bssid) { 9858 kzfree(connkeys); 9859 return -EINVAL; 9860 } 9861 9862 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], 9863 wiphy, &connect.bss_select); 9864 if (err) { 9865 kzfree(connkeys); 9866 return err; 9867 } 9868 } 9869 9870 if (wiphy_ext_feature_isset(&rdev->wiphy, 9871 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 9872 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 9873 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 9874 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 9875 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 9876 connect.fils_erp_username = 9877 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 9878 connect.fils_erp_username_len = 9879 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 9880 connect.fils_erp_realm = 9881 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 9882 connect.fils_erp_realm_len = 9883 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 9884 connect.fils_erp_next_seq_num = 9885 nla_get_u16( 9886 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 9887 connect.fils_erp_rrk = 9888 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 9889 connect.fils_erp_rrk_len = 9890 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 9891 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 9892 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 9893 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 9894 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 9895 kzfree(connkeys); 9896 return -EINVAL; 9897 } 9898 9899 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { 9900 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 9901 kzfree(connkeys); 9902 GENL_SET_ERR_MSG(info, 9903 "external auth requires connection ownership"); 9904 return -EINVAL; 9905 } 9906 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; 9907 } 9908 9909 wdev_lock(dev->ieee80211_ptr); 9910 9911 err = cfg80211_connect(rdev, dev, &connect, connkeys, 9912 connect.prev_bssid); 9913 if (err) 9914 kzfree(connkeys); 9915 9916 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 9917 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 9918 if (connect.bssid) 9919 memcpy(dev->ieee80211_ptr->disconnect_bssid, 9920 connect.bssid, ETH_ALEN); 9921 else 9922 memset(dev->ieee80211_ptr->disconnect_bssid, 9923 0, ETH_ALEN); 9924 } 9925 9926 wdev_unlock(dev->ieee80211_ptr); 9927 9928 return err; 9929 } 9930 9931 static int nl80211_update_connect_params(struct sk_buff *skb, 9932 struct genl_info *info) 9933 { 9934 struct cfg80211_connect_params connect = {}; 9935 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9936 struct net_device *dev = info->user_ptr[1]; 9937 struct wireless_dev *wdev = dev->ieee80211_ptr; 9938 bool fils_sk_offload; 9939 u32 auth_type; 9940 u32 changed = 0; 9941 int ret; 9942 9943 if (!rdev->ops->update_connect_params) 9944 return -EOPNOTSUPP; 9945 9946 if (info->attrs[NL80211_ATTR_IE]) { 9947 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 9948 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9949 changed |= UPDATE_ASSOC_IES; 9950 } 9951 9952 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, 9953 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); 9954 9955 /* 9956 * when driver supports fils-sk offload all attributes must be 9957 * provided. So the else covers "fils-sk-not-all" and 9958 * "no-fils-sk-any". 9959 */ 9960 if (fils_sk_offload && 9961 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 9962 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 9963 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 9964 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 9965 connect.fils_erp_username = 9966 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 9967 connect.fils_erp_username_len = 9968 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 9969 connect.fils_erp_realm = 9970 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 9971 connect.fils_erp_realm_len = 9972 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 9973 connect.fils_erp_next_seq_num = 9974 nla_get_u16( 9975 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 9976 connect.fils_erp_rrk = 9977 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 9978 connect.fils_erp_rrk_len = 9979 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 9980 changed |= UPDATE_FILS_ERP_INFO; 9981 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 9982 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 9983 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 9984 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 9985 return -EINVAL; 9986 } 9987 9988 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 9989 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 9990 if (!nl80211_valid_auth_type(rdev, auth_type, 9991 NL80211_CMD_CONNECT)) 9992 return -EINVAL; 9993 9994 if (auth_type == NL80211_AUTHTYPE_FILS_SK && 9995 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) 9996 return -EINVAL; 9997 9998 connect.auth_type = auth_type; 9999 changed |= UPDATE_AUTH_TYPE; 10000 } 10001 10002 wdev_lock(dev->ieee80211_ptr); 10003 if (!wdev->current_bss) 10004 ret = -ENOLINK; 10005 else 10006 ret = rdev_update_connect_params(rdev, dev, &connect, changed); 10007 wdev_unlock(dev->ieee80211_ptr); 10008 10009 return ret; 10010 } 10011 10012 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 10013 { 10014 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10015 struct net_device *dev = info->user_ptr[1]; 10016 u16 reason; 10017 int ret; 10018 10019 if (dev->ieee80211_ptr->conn_owner_nlportid && 10020 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10021 return -EPERM; 10022 10023 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 10024 reason = WLAN_REASON_DEAUTH_LEAVING; 10025 else 10026 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 10027 10028 if (reason == 0) 10029 return -EINVAL; 10030 10031 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10032 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10033 return -EOPNOTSUPP; 10034 10035 wdev_lock(dev->ieee80211_ptr); 10036 ret = cfg80211_disconnect(rdev, dev, reason, true); 10037 wdev_unlock(dev->ieee80211_ptr); 10038 return ret; 10039 } 10040 10041 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 10042 { 10043 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10044 struct net *net; 10045 int err; 10046 10047 if (info->attrs[NL80211_ATTR_PID]) { 10048 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 10049 10050 net = get_net_ns_by_pid(pid); 10051 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { 10052 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); 10053 10054 net = get_net_ns_by_fd(fd); 10055 } else { 10056 return -EINVAL; 10057 } 10058 10059 if (IS_ERR(net)) 10060 return PTR_ERR(net); 10061 10062 err = 0; 10063 10064 /* check if anything to do */ 10065 if (!net_eq(wiphy_net(&rdev->wiphy), net)) 10066 err = cfg80211_switch_netns(rdev, net); 10067 10068 put_net(net); 10069 return err; 10070 } 10071 10072 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 10073 { 10074 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10075 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 10076 struct cfg80211_pmksa *pmksa) = NULL; 10077 struct net_device *dev = info->user_ptr[1]; 10078 struct cfg80211_pmksa pmksa; 10079 10080 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 10081 10082 if (!info->attrs[NL80211_ATTR_PMKID]) 10083 return -EINVAL; 10084 10085 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 10086 10087 if (info->attrs[NL80211_ATTR_MAC]) { 10088 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10089 } else if (info->attrs[NL80211_ATTR_SSID] && 10090 info->attrs[NL80211_ATTR_FILS_CACHE_ID] && 10091 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || 10092 info->attrs[NL80211_ATTR_PMK])) { 10093 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10094 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10095 pmksa.cache_id = 10096 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); 10097 } else { 10098 return -EINVAL; 10099 } 10100 if (info->attrs[NL80211_ATTR_PMK]) { 10101 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 10102 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 10103 } 10104 10105 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10106 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && 10107 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && 10108 wiphy_ext_feature_isset(&rdev->wiphy, 10109 NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) 10110 return -EOPNOTSUPP; 10111 10112 switch (info->genlhdr->cmd) { 10113 case NL80211_CMD_SET_PMKSA: 10114 rdev_ops = rdev->ops->set_pmksa; 10115 break; 10116 case NL80211_CMD_DEL_PMKSA: 10117 rdev_ops = rdev->ops->del_pmksa; 10118 break; 10119 default: 10120 WARN_ON(1); 10121 break; 10122 } 10123 10124 if (!rdev_ops) 10125 return -EOPNOTSUPP; 10126 10127 return rdev_ops(&rdev->wiphy, dev, &pmksa); 10128 } 10129 10130 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 10131 { 10132 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10133 struct net_device *dev = info->user_ptr[1]; 10134 10135 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10136 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10137 return -EOPNOTSUPP; 10138 10139 if (!rdev->ops->flush_pmksa) 10140 return -EOPNOTSUPP; 10141 10142 return rdev_flush_pmksa(rdev, dev); 10143 } 10144 10145 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) 10146 { 10147 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10148 struct net_device *dev = info->user_ptr[1]; 10149 u8 action_code, dialog_token; 10150 u32 peer_capability = 0; 10151 u16 status_code; 10152 u8 *peer; 10153 bool initiator; 10154 10155 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 10156 !rdev->ops->tdls_mgmt) 10157 return -EOPNOTSUPP; 10158 10159 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || 10160 !info->attrs[NL80211_ATTR_STATUS_CODE] || 10161 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || 10162 !info->attrs[NL80211_ATTR_IE] || 10163 !info->attrs[NL80211_ATTR_MAC]) 10164 return -EINVAL; 10165 10166 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 10167 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); 10168 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 10169 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); 10170 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); 10171 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) 10172 peer_capability = 10173 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); 10174 10175 return rdev_tdls_mgmt(rdev, dev, peer, action_code, 10176 dialog_token, status_code, peer_capability, 10177 initiator, 10178 nla_data(info->attrs[NL80211_ATTR_IE]), 10179 nla_len(info->attrs[NL80211_ATTR_IE])); 10180 } 10181 10182 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) 10183 { 10184 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10185 struct net_device *dev = info->user_ptr[1]; 10186 enum nl80211_tdls_operation operation; 10187 u8 *peer; 10188 10189 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 10190 !rdev->ops->tdls_oper) 10191 return -EOPNOTSUPP; 10192 10193 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || 10194 !info->attrs[NL80211_ATTR_MAC]) 10195 return -EINVAL; 10196 10197 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); 10198 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 10199 10200 return rdev_tdls_oper(rdev, dev, peer, operation); 10201 } 10202 10203 static int nl80211_remain_on_channel(struct sk_buff *skb, 10204 struct genl_info *info) 10205 { 10206 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10207 struct wireless_dev *wdev = info->user_ptr[1]; 10208 struct cfg80211_chan_def chandef; 10209 const struct cfg80211_chan_def *compat_chandef; 10210 struct sk_buff *msg; 10211 void *hdr; 10212 u64 cookie; 10213 u32 duration; 10214 int err; 10215 10216 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 10217 !info->attrs[NL80211_ATTR_DURATION]) 10218 return -EINVAL; 10219 10220 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 10221 10222 if (!rdev->ops->remain_on_channel || 10223 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) 10224 return -EOPNOTSUPP; 10225 10226 /* 10227 * We should be on that channel for at least a minimum amount of 10228 * time (10ms) but no longer than the driver supports. 10229 */ 10230 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 10231 duration > rdev->wiphy.max_remain_on_channel_duration) 10232 return -EINVAL; 10233 10234 err = nl80211_parse_chandef(rdev, info, &chandef); 10235 if (err) 10236 return err; 10237 10238 wdev_lock(wdev); 10239 if (!cfg80211_off_channel_oper_allowed(wdev) && 10240 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { 10241 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, 10242 &chandef); 10243 if (compat_chandef != &chandef) { 10244 wdev_unlock(wdev); 10245 return -EBUSY; 10246 } 10247 } 10248 wdev_unlock(wdev); 10249 10250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10251 if (!msg) 10252 return -ENOMEM; 10253 10254 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 10255 NL80211_CMD_REMAIN_ON_CHANNEL); 10256 if (!hdr) { 10257 err = -ENOBUFS; 10258 goto free_msg; 10259 } 10260 10261 err = rdev_remain_on_channel(rdev, wdev, chandef.chan, 10262 duration, &cookie); 10263 10264 if (err) 10265 goto free_msg; 10266 10267 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 10268 NL80211_ATTR_PAD)) 10269 goto nla_put_failure; 10270 10271 genlmsg_end(msg, hdr); 10272 10273 return genlmsg_reply(msg, info); 10274 10275 nla_put_failure: 10276 err = -ENOBUFS; 10277 free_msg: 10278 nlmsg_free(msg); 10279 return err; 10280 } 10281 10282 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 10283 struct genl_info *info) 10284 { 10285 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10286 struct wireless_dev *wdev = info->user_ptr[1]; 10287 u64 cookie; 10288 10289 if (!info->attrs[NL80211_ATTR_COOKIE]) 10290 return -EINVAL; 10291 10292 if (!rdev->ops->cancel_remain_on_channel) 10293 return -EOPNOTSUPP; 10294 10295 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 10296 10297 return rdev_cancel_remain_on_channel(rdev, wdev, cookie); 10298 } 10299 10300 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, 10301 struct genl_info *info) 10302 { 10303 struct cfg80211_bitrate_mask mask; 10304 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10305 struct net_device *dev = info->user_ptr[1]; 10306 int err; 10307 10308 if (!rdev->ops->set_bitrate_mask) 10309 return -EOPNOTSUPP; 10310 10311 err = nl80211_parse_tx_bitrate_mask(info, &mask); 10312 if (err) 10313 return err; 10314 10315 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); 10316 } 10317 10318 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) 10319 { 10320 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10321 struct wireless_dev *wdev = info->user_ptr[1]; 10322 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; 10323 10324 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 10325 return -EINVAL; 10326 10327 if (info->attrs[NL80211_ATTR_FRAME_TYPE]) 10328 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); 10329 10330 switch (wdev->iftype) { 10331 case NL80211_IFTYPE_STATION: 10332 case NL80211_IFTYPE_ADHOC: 10333 case NL80211_IFTYPE_P2P_CLIENT: 10334 case NL80211_IFTYPE_AP: 10335 case NL80211_IFTYPE_AP_VLAN: 10336 case NL80211_IFTYPE_MESH_POINT: 10337 case NL80211_IFTYPE_P2P_GO: 10338 case NL80211_IFTYPE_P2P_DEVICE: 10339 break; 10340 case NL80211_IFTYPE_NAN: 10341 default: 10342 return -EOPNOTSUPP; 10343 } 10344 10345 /* not much point in registering if we can't reply */ 10346 if (!rdev->ops->mgmt_tx) 10347 return -EOPNOTSUPP; 10348 10349 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, 10350 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 10351 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); 10352 } 10353 10354 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) 10355 { 10356 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10357 struct wireless_dev *wdev = info->user_ptr[1]; 10358 struct cfg80211_chan_def chandef; 10359 int err; 10360 void *hdr = NULL; 10361 u64 cookie; 10362 struct sk_buff *msg = NULL; 10363 struct cfg80211_mgmt_tx_params params = { 10364 .dont_wait_for_ack = 10365 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], 10366 }; 10367 10368 if (!info->attrs[NL80211_ATTR_FRAME]) 10369 return -EINVAL; 10370 10371 if (!rdev->ops->mgmt_tx) 10372 return -EOPNOTSUPP; 10373 10374 switch (wdev->iftype) { 10375 case NL80211_IFTYPE_P2P_DEVICE: 10376 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10377 return -EINVAL; 10378 case NL80211_IFTYPE_STATION: 10379 case NL80211_IFTYPE_ADHOC: 10380 case NL80211_IFTYPE_P2P_CLIENT: 10381 case NL80211_IFTYPE_AP: 10382 case NL80211_IFTYPE_AP_VLAN: 10383 case NL80211_IFTYPE_MESH_POINT: 10384 case NL80211_IFTYPE_P2P_GO: 10385 break; 10386 case NL80211_IFTYPE_NAN: 10387 default: 10388 return -EOPNOTSUPP; 10389 } 10390 10391 if (info->attrs[NL80211_ATTR_DURATION]) { 10392 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 10393 return -EINVAL; 10394 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 10395 10396 /* 10397 * We should wait on the channel for at least a minimum amount 10398 * of time (10ms) but no longer than the driver supports. 10399 */ 10400 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 10401 params.wait > rdev->wiphy.max_remain_on_channel_duration) 10402 return -EINVAL; 10403 } 10404 10405 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; 10406 10407 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 10408 return -EINVAL; 10409 10410 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 10411 10412 /* get the channel if any has been specified, otherwise pass NULL to 10413 * the driver. The latter will use the current one 10414 */ 10415 chandef.chan = NULL; 10416 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 10417 err = nl80211_parse_chandef(rdev, info, &chandef); 10418 if (err) 10419 return err; 10420 } 10421 10422 if (!chandef.chan && params.offchan) 10423 return -EINVAL; 10424 10425 wdev_lock(wdev); 10426 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { 10427 wdev_unlock(wdev); 10428 return -EBUSY; 10429 } 10430 wdev_unlock(wdev); 10431 10432 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 10433 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 10434 10435 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { 10436 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 10437 int i; 10438 10439 if (len % sizeof(u16)) 10440 return -EINVAL; 10441 10442 params.n_csa_offsets = len / sizeof(u16); 10443 params.csa_offsets = 10444 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 10445 10446 /* check that all the offsets fit the frame */ 10447 for (i = 0; i < params.n_csa_offsets; i++) { 10448 if (params.csa_offsets[i] >= params.len) 10449 return -EINVAL; 10450 } 10451 } 10452 10453 if (!params.dont_wait_for_ack) { 10454 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10455 if (!msg) 10456 return -ENOMEM; 10457 10458 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 10459 NL80211_CMD_FRAME); 10460 if (!hdr) { 10461 err = -ENOBUFS; 10462 goto free_msg; 10463 } 10464 } 10465 10466 params.chan = chandef.chan; 10467 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); 10468 if (err) 10469 goto free_msg; 10470 10471 if (msg) { 10472 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 10473 NL80211_ATTR_PAD)) 10474 goto nla_put_failure; 10475 10476 genlmsg_end(msg, hdr); 10477 return genlmsg_reply(msg, info); 10478 } 10479 10480 return 0; 10481 10482 nla_put_failure: 10483 err = -ENOBUFS; 10484 free_msg: 10485 nlmsg_free(msg); 10486 return err; 10487 } 10488 10489 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) 10490 { 10491 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10492 struct wireless_dev *wdev = info->user_ptr[1]; 10493 u64 cookie; 10494 10495 if (!info->attrs[NL80211_ATTR_COOKIE]) 10496 return -EINVAL; 10497 10498 if (!rdev->ops->mgmt_tx_cancel_wait) 10499 return -EOPNOTSUPP; 10500 10501 switch (wdev->iftype) { 10502 case NL80211_IFTYPE_STATION: 10503 case NL80211_IFTYPE_ADHOC: 10504 case NL80211_IFTYPE_P2P_CLIENT: 10505 case NL80211_IFTYPE_AP: 10506 case NL80211_IFTYPE_AP_VLAN: 10507 case NL80211_IFTYPE_P2P_GO: 10508 case NL80211_IFTYPE_P2P_DEVICE: 10509 break; 10510 case NL80211_IFTYPE_NAN: 10511 default: 10512 return -EOPNOTSUPP; 10513 } 10514 10515 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 10516 10517 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); 10518 } 10519 10520 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 10521 { 10522 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10523 struct wireless_dev *wdev; 10524 struct net_device *dev = info->user_ptr[1]; 10525 u8 ps_state; 10526 bool state; 10527 int err; 10528 10529 if (!info->attrs[NL80211_ATTR_PS_STATE]) 10530 return -EINVAL; 10531 10532 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 10533 10534 wdev = dev->ieee80211_ptr; 10535 10536 if (!rdev->ops->set_power_mgmt) 10537 return -EOPNOTSUPP; 10538 10539 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 10540 10541 if (state == wdev->ps) 10542 return 0; 10543 10544 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); 10545 if (!err) 10546 wdev->ps = state; 10547 return err; 10548 } 10549 10550 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 10551 { 10552 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10553 enum nl80211_ps_state ps_state; 10554 struct wireless_dev *wdev; 10555 struct net_device *dev = info->user_ptr[1]; 10556 struct sk_buff *msg; 10557 void *hdr; 10558 int err; 10559 10560 wdev = dev->ieee80211_ptr; 10561 10562 if (!rdev->ops->set_power_mgmt) 10563 return -EOPNOTSUPP; 10564 10565 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10566 if (!msg) 10567 return -ENOMEM; 10568 10569 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 10570 NL80211_CMD_GET_POWER_SAVE); 10571 if (!hdr) { 10572 err = -ENOBUFS; 10573 goto free_msg; 10574 } 10575 10576 if (wdev->ps) 10577 ps_state = NL80211_PS_ENABLED; 10578 else 10579 ps_state = NL80211_PS_DISABLED; 10580 10581 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) 10582 goto nla_put_failure; 10583 10584 genlmsg_end(msg, hdr); 10585 return genlmsg_reply(msg, info); 10586 10587 nla_put_failure: 10588 err = -ENOBUFS; 10589 free_msg: 10590 nlmsg_free(msg); 10591 return err; 10592 } 10593 10594 static const struct nla_policy 10595 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { 10596 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, 10597 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, 10598 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, 10599 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, 10600 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, 10601 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, 10602 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, 10603 }; 10604 10605 static int nl80211_set_cqm_txe(struct genl_info *info, 10606 u32 rate, u32 pkts, u32 intvl) 10607 { 10608 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10609 struct net_device *dev = info->user_ptr[1]; 10610 struct wireless_dev *wdev = dev->ieee80211_ptr; 10611 10612 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) 10613 return -EINVAL; 10614 10615 if (!rdev->ops->set_cqm_txe_config) 10616 return -EOPNOTSUPP; 10617 10618 if (wdev->iftype != NL80211_IFTYPE_STATION && 10619 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 10620 return -EOPNOTSUPP; 10621 10622 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); 10623 } 10624 10625 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, 10626 struct net_device *dev) 10627 { 10628 struct wireless_dev *wdev = dev->ieee80211_ptr; 10629 s32 last, low, high; 10630 u32 hyst; 10631 int i, n, low_index; 10632 int err; 10633 10634 /* RSSI reporting disabled? */ 10635 if (!wdev->cqm_config) 10636 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); 10637 10638 /* 10639 * Obtain current RSSI value if possible, if not and no RSSI threshold 10640 * event has been received yet, we should receive an event after a 10641 * connection is established and enough beacons received to calculate 10642 * the average. 10643 */ 10644 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && 10645 rdev->ops->get_station) { 10646 struct station_info sinfo = {}; 10647 u8 *mac_addr; 10648 10649 mac_addr = wdev->current_bss->pub.bssid; 10650 10651 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 10652 if (err) 10653 return err; 10654 10655 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) 10656 wdev->cqm_config->last_rssi_event_value = 10657 (s8) sinfo.rx_beacon_signal_avg; 10658 } 10659 10660 last = wdev->cqm_config->last_rssi_event_value; 10661 hyst = wdev->cqm_config->rssi_hyst; 10662 n = wdev->cqm_config->n_rssi_thresholds; 10663 10664 for (i = 0; i < n; i++) 10665 if (last < wdev->cqm_config->rssi_thresholds[i]) 10666 break; 10667 10668 low_index = i - 1; 10669 if (low_index >= 0) { 10670 low_index = array_index_nospec(low_index, n); 10671 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; 10672 } else { 10673 low = S32_MIN; 10674 } 10675 if (i < n) { 10676 i = array_index_nospec(i, n); 10677 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; 10678 } else { 10679 high = S32_MAX; 10680 } 10681 10682 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); 10683 } 10684 10685 static int nl80211_set_cqm_rssi(struct genl_info *info, 10686 const s32 *thresholds, int n_thresholds, 10687 u32 hysteresis) 10688 { 10689 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10690 struct net_device *dev = info->user_ptr[1]; 10691 struct wireless_dev *wdev = dev->ieee80211_ptr; 10692 int i, err; 10693 s32 prev = S32_MIN; 10694 10695 /* Check all values negative and sorted */ 10696 for (i = 0; i < n_thresholds; i++) { 10697 if (thresholds[i] > 0 || thresholds[i] <= prev) 10698 return -EINVAL; 10699 10700 prev = thresholds[i]; 10701 } 10702 10703 if (wdev->iftype != NL80211_IFTYPE_STATION && 10704 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 10705 return -EOPNOTSUPP; 10706 10707 wdev_lock(wdev); 10708 cfg80211_cqm_config_free(wdev); 10709 wdev_unlock(wdev); 10710 10711 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { 10712 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ 10713 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); 10714 10715 return rdev_set_cqm_rssi_config(rdev, dev, 10716 thresholds[0], hysteresis); 10717 } 10718 10719 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10720 NL80211_EXT_FEATURE_CQM_RSSI_LIST)) 10721 return -EOPNOTSUPP; 10722 10723 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ 10724 n_thresholds = 0; 10725 10726 wdev_lock(wdev); 10727 if (n_thresholds) { 10728 struct cfg80211_cqm_config *cqm_config; 10729 10730 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + 10731 n_thresholds * sizeof(s32), GFP_KERNEL); 10732 if (!cqm_config) { 10733 err = -ENOMEM; 10734 goto unlock; 10735 } 10736 10737 cqm_config->rssi_hyst = hysteresis; 10738 cqm_config->n_rssi_thresholds = n_thresholds; 10739 memcpy(cqm_config->rssi_thresholds, thresholds, 10740 n_thresholds * sizeof(s32)); 10741 10742 wdev->cqm_config = cqm_config; 10743 } 10744 10745 err = cfg80211_cqm_rssi_update(rdev, dev); 10746 10747 unlock: 10748 wdev_unlock(wdev); 10749 10750 return err; 10751 } 10752 10753 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 10754 { 10755 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; 10756 struct nlattr *cqm; 10757 int err; 10758 10759 cqm = info->attrs[NL80211_ATTR_CQM]; 10760 if (!cqm) 10761 return -EINVAL; 10762 10763 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, 10764 nl80211_attr_cqm_policy, 10765 info->extack); 10766 if (err) 10767 return err; 10768 10769 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && 10770 attrs[NL80211_ATTR_CQM_RSSI_HYST]) { 10771 const s32 *thresholds = 10772 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 10773 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 10774 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); 10775 10776 if (len % 4) 10777 return -EINVAL; 10778 10779 return nl80211_set_cqm_rssi(info, thresholds, len / 4, 10780 hysteresis); 10781 } 10782 10783 if (attrs[NL80211_ATTR_CQM_TXE_RATE] && 10784 attrs[NL80211_ATTR_CQM_TXE_PKTS] && 10785 attrs[NL80211_ATTR_CQM_TXE_INTVL]) { 10786 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); 10787 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); 10788 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); 10789 10790 return nl80211_set_cqm_txe(info, rate, pkts, intvl); 10791 } 10792 10793 return -EINVAL; 10794 } 10795 10796 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) 10797 { 10798 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10799 struct net_device *dev = info->user_ptr[1]; 10800 struct ocb_setup setup = {}; 10801 int err; 10802 10803 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 10804 if (err) 10805 return err; 10806 10807 return cfg80211_join_ocb(rdev, dev, &setup); 10808 } 10809 10810 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) 10811 { 10812 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10813 struct net_device *dev = info->user_ptr[1]; 10814 10815 return cfg80211_leave_ocb(rdev, dev); 10816 } 10817 10818 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 10819 { 10820 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10821 struct net_device *dev = info->user_ptr[1]; 10822 struct mesh_config cfg; 10823 struct mesh_setup setup; 10824 int err; 10825 10826 /* start with default */ 10827 memcpy(&cfg, &default_mesh_config, sizeof(cfg)); 10828 memcpy(&setup, &default_mesh_setup, sizeof(setup)); 10829 10830 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { 10831 /* and parse parameters if given */ 10832 err = nl80211_parse_mesh_config(info, &cfg, NULL); 10833 if (err) 10834 return err; 10835 } 10836 10837 if (!info->attrs[NL80211_ATTR_MESH_ID] || 10838 !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) 10839 return -EINVAL; 10840 10841 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 10842 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 10843 10844 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 10845 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, 10846 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 10847 return -EINVAL; 10848 10849 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { 10850 setup.beacon_interval = 10851 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 10852 10853 err = cfg80211_validate_beacon_int(rdev, 10854 NL80211_IFTYPE_MESH_POINT, 10855 setup.beacon_interval); 10856 if (err) 10857 return err; 10858 } 10859 10860 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 10861 setup.dtim_period = 10862 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 10863 if (setup.dtim_period < 1 || setup.dtim_period > 100) 10864 return -EINVAL; 10865 } 10866 10867 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 10868 /* parse additional setup parameters if given */ 10869 err = nl80211_parse_mesh_setup(info, &setup); 10870 if (err) 10871 return err; 10872 } 10873 10874 if (setup.user_mpm) 10875 cfg.auto_open_plinks = false; 10876 10877 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 10878 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 10879 if (err) 10880 return err; 10881 } else { 10882 /* __cfg80211_join_mesh() will sort it out */ 10883 setup.chandef.chan = NULL; 10884 } 10885 10886 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 10887 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 10888 int n_rates = 10889 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 10890 struct ieee80211_supported_band *sband; 10891 10892 if (!setup.chandef.chan) 10893 return -EINVAL; 10894 10895 sband = rdev->wiphy.bands[setup.chandef.chan->band]; 10896 10897 err = ieee80211_get_ratemask(sband, rates, n_rates, 10898 &setup.basic_rates); 10899 if (err) 10900 return err; 10901 } 10902 10903 if (info->attrs[NL80211_ATTR_TX_RATES]) { 10904 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); 10905 if (err) 10906 return err; 10907 10908 if (!setup.chandef.chan) 10909 return -EINVAL; 10910 10911 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, 10912 &setup.beacon_rate); 10913 if (err) 10914 return err; 10915 } 10916 10917 setup.userspace_handles_dfs = 10918 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 10919 10920 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 10921 int r = validate_pae_over_nl80211(rdev, info); 10922 10923 if (r < 0) 10924 return r; 10925 10926 setup.control_port_over_nl80211 = true; 10927 } 10928 10929 wdev_lock(dev->ieee80211_ptr); 10930 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); 10931 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) 10932 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 10933 wdev_unlock(dev->ieee80211_ptr); 10934 10935 return err; 10936 } 10937 10938 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) 10939 { 10940 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10941 struct net_device *dev = info->user_ptr[1]; 10942 10943 return cfg80211_leave_mesh(rdev, dev); 10944 } 10945 10946 #ifdef CONFIG_PM 10947 static int nl80211_send_wowlan_patterns(struct sk_buff *msg, 10948 struct cfg80211_registered_device *rdev) 10949 { 10950 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; 10951 struct nlattr *nl_pats, *nl_pat; 10952 int i, pat_len; 10953 10954 if (!wowlan->n_patterns) 10955 return 0; 10956 10957 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 10958 if (!nl_pats) 10959 return -ENOBUFS; 10960 10961 for (i = 0; i < wowlan->n_patterns; i++) { 10962 nl_pat = nla_nest_start_noflag(msg, i + 1); 10963 if (!nl_pat) 10964 return -ENOBUFS; 10965 pat_len = wowlan->patterns[i].pattern_len; 10966 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), 10967 wowlan->patterns[i].mask) || 10968 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 10969 wowlan->patterns[i].pattern) || 10970 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 10971 wowlan->patterns[i].pkt_offset)) 10972 return -ENOBUFS; 10973 nla_nest_end(msg, nl_pat); 10974 } 10975 nla_nest_end(msg, nl_pats); 10976 10977 return 0; 10978 } 10979 10980 static int nl80211_send_wowlan_tcp(struct sk_buff *msg, 10981 struct cfg80211_wowlan_tcp *tcp) 10982 { 10983 struct nlattr *nl_tcp; 10984 10985 if (!tcp) 10986 return 0; 10987 10988 nl_tcp = nla_nest_start_noflag(msg, 10989 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 10990 if (!nl_tcp) 10991 return -ENOBUFS; 10992 10993 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 10994 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 10995 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 10996 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 10997 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || 10998 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 10999 tcp->payload_len, tcp->payload) || 11000 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 11001 tcp->data_interval) || 11002 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 11003 tcp->wake_len, tcp->wake_data) || 11004 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, 11005 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) 11006 return -ENOBUFS; 11007 11008 if (tcp->payload_seq.len && 11009 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, 11010 sizeof(tcp->payload_seq), &tcp->payload_seq)) 11011 return -ENOBUFS; 11012 11013 if (tcp->payload_tok.len && 11014 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 11015 sizeof(tcp->payload_tok) + tcp->tokens_size, 11016 &tcp->payload_tok)) 11017 return -ENOBUFS; 11018 11019 nla_nest_end(msg, nl_tcp); 11020 11021 return 0; 11022 } 11023 11024 static int nl80211_send_wowlan_nd(struct sk_buff *msg, 11025 struct cfg80211_sched_scan_request *req) 11026 { 11027 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; 11028 int i; 11029 11030 if (!req) 11031 return 0; 11032 11033 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 11034 if (!nd) 11035 return -ENOBUFS; 11036 11037 if (req->n_scan_plans == 1 && 11038 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, 11039 req->scan_plans[0].interval * 1000)) 11040 return -ENOBUFS; 11041 11042 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) 11043 return -ENOBUFS; 11044 11045 if (req->relative_rssi_set) { 11046 struct nl80211_bss_select_rssi_adjust rssi_adjust; 11047 11048 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, 11049 req->relative_rssi)) 11050 return -ENOBUFS; 11051 11052 rssi_adjust.band = req->rssi_adjust.band; 11053 rssi_adjust.delta = req->rssi_adjust.delta; 11054 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, 11055 sizeof(rssi_adjust), &rssi_adjust)) 11056 return -ENOBUFS; 11057 } 11058 11059 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 11060 if (!freqs) 11061 return -ENOBUFS; 11062 11063 for (i = 0; i < req->n_channels; i++) { 11064 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 11065 return -ENOBUFS; 11066 } 11067 11068 nla_nest_end(msg, freqs); 11069 11070 if (req->n_match_sets) { 11071 matches = nla_nest_start_noflag(msg, 11072 NL80211_ATTR_SCHED_SCAN_MATCH); 11073 if (!matches) 11074 return -ENOBUFS; 11075 11076 for (i = 0; i < req->n_match_sets; i++) { 11077 match = nla_nest_start_noflag(msg, i); 11078 if (!match) 11079 return -ENOBUFS; 11080 11081 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, 11082 req->match_sets[i].ssid.ssid_len, 11083 req->match_sets[i].ssid.ssid)) 11084 return -ENOBUFS; 11085 nla_nest_end(msg, match); 11086 } 11087 nla_nest_end(msg, matches); 11088 } 11089 11090 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 11091 if (!scan_plans) 11092 return -ENOBUFS; 11093 11094 for (i = 0; i < req->n_scan_plans; i++) { 11095 scan_plan = nla_nest_start_noflag(msg, i + 1); 11096 if (!scan_plan) 11097 return -ENOBUFS; 11098 11099 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, 11100 req->scan_plans[i].interval) || 11101 (req->scan_plans[i].iterations && 11102 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, 11103 req->scan_plans[i].iterations))) 11104 return -ENOBUFS; 11105 nla_nest_end(msg, scan_plan); 11106 } 11107 nla_nest_end(msg, scan_plans); 11108 11109 nla_nest_end(msg, nd); 11110 11111 return 0; 11112 } 11113 11114 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) 11115 { 11116 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11117 struct sk_buff *msg; 11118 void *hdr; 11119 u32 size = NLMSG_DEFAULT_SIZE; 11120 11121 if (!rdev->wiphy.wowlan) 11122 return -EOPNOTSUPP; 11123 11124 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { 11125 /* adjust size to have room for all the data */ 11126 size += rdev->wiphy.wowlan_config->tcp->tokens_size + 11127 rdev->wiphy.wowlan_config->tcp->payload_len + 11128 rdev->wiphy.wowlan_config->tcp->wake_len + 11129 rdev->wiphy.wowlan_config->tcp->wake_len / 8; 11130 } 11131 11132 msg = nlmsg_new(size, GFP_KERNEL); 11133 if (!msg) 11134 return -ENOMEM; 11135 11136 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11137 NL80211_CMD_GET_WOWLAN); 11138 if (!hdr) 11139 goto nla_put_failure; 11140 11141 if (rdev->wiphy.wowlan_config) { 11142 struct nlattr *nl_wowlan; 11143 11144 nl_wowlan = nla_nest_start_noflag(msg, 11145 NL80211_ATTR_WOWLAN_TRIGGERS); 11146 if (!nl_wowlan) 11147 goto nla_put_failure; 11148 11149 if ((rdev->wiphy.wowlan_config->any && 11150 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 11151 (rdev->wiphy.wowlan_config->disconnect && 11152 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 11153 (rdev->wiphy.wowlan_config->magic_pkt && 11154 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 11155 (rdev->wiphy.wowlan_config->gtk_rekey_failure && 11156 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 11157 (rdev->wiphy.wowlan_config->eap_identity_req && 11158 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 11159 (rdev->wiphy.wowlan_config->four_way_handshake && 11160 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 11161 (rdev->wiphy.wowlan_config->rfkill_release && 11162 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 11163 goto nla_put_failure; 11164 11165 if (nl80211_send_wowlan_patterns(msg, rdev)) 11166 goto nla_put_failure; 11167 11168 if (nl80211_send_wowlan_tcp(msg, 11169 rdev->wiphy.wowlan_config->tcp)) 11170 goto nla_put_failure; 11171 11172 if (nl80211_send_wowlan_nd( 11173 msg, 11174 rdev->wiphy.wowlan_config->nd_config)) 11175 goto nla_put_failure; 11176 11177 nla_nest_end(msg, nl_wowlan); 11178 } 11179 11180 genlmsg_end(msg, hdr); 11181 return genlmsg_reply(msg, info); 11182 11183 nla_put_failure: 11184 nlmsg_free(msg); 11185 return -ENOBUFS; 11186 } 11187 11188 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, 11189 struct nlattr *attr, 11190 struct cfg80211_wowlan *trig) 11191 { 11192 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; 11193 struct cfg80211_wowlan_tcp *cfg; 11194 struct nl80211_wowlan_tcp_data_token *tok = NULL; 11195 struct nl80211_wowlan_tcp_data_seq *seq = NULL; 11196 u32 size; 11197 u32 data_size, wake_size, tokens_size = 0, wake_mask_size; 11198 int err, port; 11199 11200 if (!rdev->wiphy.wowlan->tcp) 11201 return -EINVAL; 11202 11203 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, 11204 nl80211_wowlan_tcp_policy, NULL); 11205 if (err) 11206 return err; 11207 11208 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || 11209 !tb[NL80211_WOWLAN_TCP_DST_IPV4] || 11210 !tb[NL80211_WOWLAN_TCP_DST_MAC] || 11211 !tb[NL80211_WOWLAN_TCP_DST_PORT] || 11212 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || 11213 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || 11214 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || 11215 !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) 11216 return -EINVAL; 11217 11218 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); 11219 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) 11220 return -EINVAL; 11221 11222 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > 11223 rdev->wiphy.wowlan->tcp->data_interval_max || 11224 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) 11225 return -EINVAL; 11226 11227 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); 11228 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) 11229 return -EINVAL; 11230 11231 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); 11232 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) 11233 return -EINVAL; 11234 11235 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { 11236 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 11237 11238 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 11239 tokens_size = tokln - sizeof(*tok); 11240 11241 if (!tok->len || tokens_size % tok->len) 11242 return -EINVAL; 11243 if (!rdev->wiphy.wowlan->tcp->tok) 11244 return -EINVAL; 11245 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) 11246 return -EINVAL; 11247 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) 11248 return -EINVAL; 11249 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) 11250 return -EINVAL; 11251 if (tok->offset + tok->len > data_size) 11252 return -EINVAL; 11253 } 11254 11255 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { 11256 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); 11257 if (!rdev->wiphy.wowlan->tcp->seq) 11258 return -EINVAL; 11259 if (seq->len == 0 || seq->len > 4) 11260 return -EINVAL; 11261 if (seq->len + seq->offset > data_size) 11262 return -EINVAL; 11263 } 11264 11265 size = sizeof(*cfg); 11266 size += data_size; 11267 size += wake_size + wake_mask_size; 11268 size += tokens_size; 11269 11270 cfg = kzalloc(size, GFP_KERNEL); 11271 if (!cfg) 11272 return -ENOMEM; 11273 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); 11274 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 11275 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 11276 ETH_ALEN); 11277 if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 11278 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 11279 else 11280 port = 0; 11281 #ifdef CONFIG_INET 11282 /* allocate a socket and port for it and use it */ 11283 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, 11284 IPPROTO_TCP, &cfg->sock, 1); 11285 if (err) { 11286 kfree(cfg); 11287 return err; 11288 } 11289 if (inet_csk_get_port(cfg->sock->sk, port)) { 11290 sock_release(cfg->sock); 11291 kfree(cfg); 11292 return -EADDRINUSE; 11293 } 11294 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; 11295 #else 11296 if (!port) { 11297 kfree(cfg); 11298 return -EINVAL; 11299 } 11300 cfg->src_port = port; 11301 #endif 11302 11303 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); 11304 cfg->payload_len = data_size; 11305 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; 11306 memcpy((void *)cfg->payload, 11307 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), 11308 data_size); 11309 if (seq) 11310 cfg->payload_seq = *seq; 11311 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); 11312 cfg->wake_len = wake_size; 11313 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; 11314 memcpy((void *)cfg->wake_data, 11315 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), 11316 wake_size); 11317 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + 11318 data_size + wake_size; 11319 memcpy((void *)cfg->wake_mask, 11320 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), 11321 wake_mask_size); 11322 if (tok) { 11323 cfg->tokens_size = tokens_size; 11324 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); 11325 } 11326 11327 trig->tcp = cfg; 11328 11329 return 0; 11330 } 11331 11332 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, 11333 const struct wiphy_wowlan_support *wowlan, 11334 struct nlattr *attr, 11335 struct cfg80211_wowlan *trig) 11336 { 11337 struct nlattr **tb; 11338 int err; 11339 11340 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 11341 if (!tb) 11342 return -ENOMEM; 11343 11344 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { 11345 err = -EOPNOTSUPP; 11346 goto out; 11347 } 11348 11349 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, 11350 nl80211_policy, NULL); 11351 if (err) 11352 goto out; 11353 11354 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, 11355 wowlan->max_nd_match_sets); 11356 err = PTR_ERR_OR_ZERO(trig->nd_config); 11357 if (err) 11358 trig->nd_config = NULL; 11359 11360 out: 11361 kfree(tb); 11362 return err; 11363 } 11364 11365 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) 11366 { 11367 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11368 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; 11369 struct cfg80211_wowlan new_triggers = {}; 11370 struct cfg80211_wowlan *ntrig; 11371 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; 11372 int err, i; 11373 bool prev_enabled = rdev->wiphy.wowlan_config; 11374 bool regular = false; 11375 11376 if (!wowlan) 11377 return -EOPNOTSUPP; 11378 11379 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { 11380 cfg80211_rdev_free_wowlan(rdev); 11381 rdev->wiphy.wowlan_config = NULL; 11382 goto set_wakeup; 11383 } 11384 11385 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, 11386 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 11387 nl80211_wowlan_policy, info->extack); 11388 if (err) 11389 return err; 11390 11391 if (tb[NL80211_WOWLAN_TRIG_ANY]) { 11392 if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) 11393 return -EINVAL; 11394 new_triggers.any = true; 11395 } 11396 11397 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { 11398 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) 11399 return -EINVAL; 11400 new_triggers.disconnect = true; 11401 regular = true; 11402 } 11403 11404 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { 11405 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) 11406 return -EINVAL; 11407 new_triggers.magic_pkt = true; 11408 regular = true; 11409 } 11410 11411 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) 11412 return -EINVAL; 11413 11414 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { 11415 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) 11416 return -EINVAL; 11417 new_triggers.gtk_rekey_failure = true; 11418 regular = true; 11419 } 11420 11421 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { 11422 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) 11423 return -EINVAL; 11424 new_triggers.eap_identity_req = true; 11425 regular = true; 11426 } 11427 11428 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { 11429 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) 11430 return -EINVAL; 11431 new_triggers.four_way_handshake = true; 11432 regular = true; 11433 } 11434 11435 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { 11436 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) 11437 return -EINVAL; 11438 new_triggers.rfkill_release = true; 11439 regular = true; 11440 } 11441 11442 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { 11443 struct nlattr *pat; 11444 int n_patterns = 0; 11445 int rem, pat_len, mask_len, pkt_offset; 11446 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 11447 11448 regular = true; 11449 11450 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 11451 rem) 11452 n_patterns++; 11453 if (n_patterns > wowlan->n_patterns) 11454 return -EINVAL; 11455 11456 new_triggers.patterns = kcalloc(n_patterns, 11457 sizeof(new_triggers.patterns[0]), 11458 GFP_KERNEL); 11459 if (!new_triggers.patterns) 11460 return -ENOMEM; 11461 11462 new_triggers.n_patterns = n_patterns; 11463 i = 0; 11464 11465 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 11466 rem) { 11467 u8 *mask_pat; 11468 11469 err = nla_parse_nested_deprecated(pat_tb, 11470 MAX_NL80211_PKTPAT, 11471 pat, 11472 nl80211_packet_pattern_policy, 11473 info->extack); 11474 if (err) 11475 goto error; 11476 11477 err = -EINVAL; 11478 if (!pat_tb[NL80211_PKTPAT_MASK] || 11479 !pat_tb[NL80211_PKTPAT_PATTERN]) 11480 goto error; 11481 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 11482 mask_len = DIV_ROUND_UP(pat_len, 8); 11483 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 11484 goto error; 11485 if (pat_len > wowlan->pattern_max_len || 11486 pat_len < wowlan->pattern_min_len) 11487 goto error; 11488 11489 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 11490 pkt_offset = 0; 11491 else 11492 pkt_offset = nla_get_u32( 11493 pat_tb[NL80211_PKTPAT_OFFSET]); 11494 if (pkt_offset > wowlan->max_pkt_offset) 11495 goto error; 11496 new_triggers.patterns[i].pkt_offset = pkt_offset; 11497 11498 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 11499 if (!mask_pat) { 11500 err = -ENOMEM; 11501 goto error; 11502 } 11503 new_triggers.patterns[i].mask = mask_pat; 11504 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 11505 mask_len); 11506 mask_pat += mask_len; 11507 new_triggers.patterns[i].pattern = mask_pat; 11508 new_triggers.patterns[i].pattern_len = pat_len; 11509 memcpy(mask_pat, 11510 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 11511 pat_len); 11512 i++; 11513 } 11514 } 11515 11516 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { 11517 regular = true; 11518 err = nl80211_parse_wowlan_tcp( 11519 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], 11520 &new_triggers); 11521 if (err) 11522 goto error; 11523 } 11524 11525 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { 11526 regular = true; 11527 err = nl80211_parse_wowlan_nd( 11528 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], 11529 &new_triggers); 11530 if (err) 11531 goto error; 11532 } 11533 11534 /* The 'any' trigger means the device continues operating more or less 11535 * as in its normal operation mode and wakes up the host on most of the 11536 * normal interrupts (like packet RX, ...) 11537 * It therefore makes little sense to combine with the more constrained 11538 * wakeup trigger modes. 11539 */ 11540 if (new_triggers.any && regular) { 11541 err = -EINVAL; 11542 goto error; 11543 } 11544 11545 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); 11546 if (!ntrig) { 11547 err = -ENOMEM; 11548 goto error; 11549 } 11550 cfg80211_rdev_free_wowlan(rdev); 11551 rdev->wiphy.wowlan_config = ntrig; 11552 11553 set_wakeup: 11554 if (rdev->ops->set_wakeup && 11555 prev_enabled != !!rdev->wiphy.wowlan_config) 11556 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); 11557 11558 return 0; 11559 error: 11560 for (i = 0; i < new_triggers.n_patterns; i++) 11561 kfree(new_triggers.patterns[i].mask); 11562 kfree(new_triggers.patterns); 11563 if (new_triggers.tcp && new_triggers.tcp->sock) 11564 sock_release(new_triggers.tcp->sock); 11565 kfree(new_triggers.tcp); 11566 kfree(new_triggers.nd_config); 11567 return err; 11568 } 11569 #endif 11570 11571 static int nl80211_send_coalesce_rules(struct sk_buff *msg, 11572 struct cfg80211_registered_device *rdev) 11573 { 11574 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; 11575 int i, j, pat_len; 11576 struct cfg80211_coalesce_rules *rule; 11577 11578 if (!rdev->coalesce->n_rules) 11579 return 0; 11580 11581 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); 11582 if (!nl_rules) 11583 return -ENOBUFS; 11584 11585 for (i = 0; i < rdev->coalesce->n_rules; i++) { 11586 nl_rule = nla_nest_start_noflag(msg, i + 1); 11587 if (!nl_rule) 11588 return -ENOBUFS; 11589 11590 rule = &rdev->coalesce->rules[i]; 11591 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, 11592 rule->delay)) 11593 return -ENOBUFS; 11594 11595 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, 11596 rule->condition)) 11597 return -ENOBUFS; 11598 11599 nl_pats = nla_nest_start_noflag(msg, 11600 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 11601 if (!nl_pats) 11602 return -ENOBUFS; 11603 11604 for (j = 0; j < rule->n_patterns; j++) { 11605 nl_pat = nla_nest_start_noflag(msg, j + 1); 11606 if (!nl_pat) 11607 return -ENOBUFS; 11608 pat_len = rule->patterns[j].pattern_len; 11609 if (nla_put(msg, NL80211_PKTPAT_MASK, 11610 DIV_ROUND_UP(pat_len, 8), 11611 rule->patterns[j].mask) || 11612 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 11613 rule->patterns[j].pattern) || 11614 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 11615 rule->patterns[j].pkt_offset)) 11616 return -ENOBUFS; 11617 nla_nest_end(msg, nl_pat); 11618 } 11619 nla_nest_end(msg, nl_pats); 11620 nla_nest_end(msg, nl_rule); 11621 } 11622 nla_nest_end(msg, nl_rules); 11623 11624 return 0; 11625 } 11626 11627 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) 11628 { 11629 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11630 struct sk_buff *msg; 11631 void *hdr; 11632 11633 if (!rdev->wiphy.coalesce) 11634 return -EOPNOTSUPP; 11635 11636 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 11637 if (!msg) 11638 return -ENOMEM; 11639 11640 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11641 NL80211_CMD_GET_COALESCE); 11642 if (!hdr) 11643 goto nla_put_failure; 11644 11645 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) 11646 goto nla_put_failure; 11647 11648 genlmsg_end(msg, hdr); 11649 return genlmsg_reply(msg, info); 11650 11651 nla_put_failure: 11652 nlmsg_free(msg); 11653 return -ENOBUFS; 11654 } 11655 11656 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) 11657 { 11658 struct cfg80211_coalesce *coalesce = rdev->coalesce; 11659 int i, j; 11660 struct cfg80211_coalesce_rules *rule; 11661 11662 if (!coalesce) 11663 return; 11664 11665 for (i = 0; i < coalesce->n_rules; i++) { 11666 rule = &coalesce->rules[i]; 11667 for (j = 0; j < rule->n_patterns; j++) 11668 kfree(rule->patterns[j].mask); 11669 kfree(rule->patterns); 11670 } 11671 kfree(coalesce->rules); 11672 kfree(coalesce); 11673 rdev->coalesce = NULL; 11674 } 11675 11676 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, 11677 struct nlattr *rule, 11678 struct cfg80211_coalesce_rules *new_rule) 11679 { 11680 int err, i; 11681 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 11682 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; 11683 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 11684 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 11685 11686 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, 11687 rule, nl80211_coalesce_policy, NULL); 11688 if (err) 11689 return err; 11690 11691 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) 11692 new_rule->delay = 11693 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); 11694 if (new_rule->delay > coalesce->max_delay) 11695 return -EINVAL; 11696 11697 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) 11698 new_rule->condition = 11699 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); 11700 11701 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) 11702 return -EINVAL; 11703 11704 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 11705 rem) 11706 n_patterns++; 11707 if (n_patterns > coalesce->n_patterns) 11708 return -EINVAL; 11709 11710 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), 11711 GFP_KERNEL); 11712 if (!new_rule->patterns) 11713 return -ENOMEM; 11714 11715 new_rule->n_patterns = n_patterns; 11716 i = 0; 11717 11718 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 11719 rem) { 11720 u8 *mask_pat; 11721 11722 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, 11723 pat, 11724 nl80211_packet_pattern_policy, 11725 NULL); 11726 if (err) 11727 return err; 11728 11729 if (!pat_tb[NL80211_PKTPAT_MASK] || 11730 !pat_tb[NL80211_PKTPAT_PATTERN]) 11731 return -EINVAL; 11732 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 11733 mask_len = DIV_ROUND_UP(pat_len, 8); 11734 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 11735 return -EINVAL; 11736 if (pat_len > coalesce->pattern_max_len || 11737 pat_len < coalesce->pattern_min_len) 11738 return -EINVAL; 11739 11740 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 11741 pkt_offset = 0; 11742 else 11743 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 11744 if (pkt_offset > coalesce->max_pkt_offset) 11745 return -EINVAL; 11746 new_rule->patterns[i].pkt_offset = pkt_offset; 11747 11748 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 11749 if (!mask_pat) 11750 return -ENOMEM; 11751 11752 new_rule->patterns[i].mask = mask_pat; 11753 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 11754 mask_len); 11755 11756 mask_pat += mask_len; 11757 new_rule->patterns[i].pattern = mask_pat; 11758 new_rule->patterns[i].pattern_len = pat_len; 11759 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 11760 pat_len); 11761 i++; 11762 } 11763 11764 return 0; 11765 } 11766 11767 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) 11768 { 11769 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11770 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 11771 struct cfg80211_coalesce new_coalesce = {}; 11772 struct cfg80211_coalesce *n_coalesce; 11773 int err, rem_rule, n_rules = 0, i, j; 11774 struct nlattr *rule; 11775 struct cfg80211_coalesce_rules *tmp_rule; 11776 11777 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) 11778 return -EOPNOTSUPP; 11779 11780 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { 11781 cfg80211_rdev_free_coalesce(rdev); 11782 rdev_set_coalesce(rdev, NULL); 11783 return 0; 11784 } 11785 11786 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 11787 rem_rule) 11788 n_rules++; 11789 if (n_rules > coalesce->n_rules) 11790 return -EINVAL; 11791 11792 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), 11793 GFP_KERNEL); 11794 if (!new_coalesce.rules) 11795 return -ENOMEM; 11796 11797 new_coalesce.n_rules = n_rules; 11798 i = 0; 11799 11800 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 11801 rem_rule) { 11802 err = nl80211_parse_coalesce_rule(rdev, rule, 11803 &new_coalesce.rules[i]); 11804 if (err) 11805 goto error; 11806 11807 i++; 11808 } 11809 11810 err = rdev_set_coalesce(rdev, &new_coalesce); 11811 if (err) 11812 goto error; 11813 11814 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); 11815 if (!n_coalesce) { 11816 err = -ENOMEM; 11817 goto error; 11818 } 11819 cfg80211_rdev_free_coalesce(rdev); 11820 rdev->coalesce = n_coalesce; 11821 11822 return 0; 11823 error: 11824 for (i = 0; i < new_coalesce.n_rules; i++) { 11825 tmp_rule = &new_coalesce.rules[i]; 11826 for (j = 0; j < tmp_rule->n_patterns; j++) 11827 kfree(tmp_rule->patterns[j].mask); 11828 kfree(tmp_rule->patterns); 11829 } 11830 kfree(new_coalesce.rules); 11831 11832 return err; 11833 } 11834 11835 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) 11836 { 11837 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11838 struct net_device *dev = info->user_ptr[1]; 11839 struct wireless_dev *wdev = dev->ieee80211_ptr; 11840 struct nlattr *tb[NUM_NL80211_REKEY_DATA]; 11841 struct cfg80211_gtk_rekey_data rekey_data; 11842 int err; 11843 11844 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 11845 return -EINVAL; 11846 11847 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, 11848 info->attrs[NL80211_ATTR_REKEY_DATA], 11849 nl80211_rekey_policy, info->extack); 11850 if (err) 11851 return err; 11852 11853 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || 11854 !tb[NL80211_REKEY_DATA_KCK]) 11855 return -EINVAL; 11856 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) 11857 return -ERANGE; 11858 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) 11859 return -ERANGE; 11860 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) 11861 return -ERANGE; 11862 11863 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); 11864 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); 11865 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); 11866 11867 wdev_lock(wdev); 11868 if (!wdev->current_bss) { 11869 err = -ENOTCONN; 11870 goto out; 11871 } 11872 11873 if (!rdev->ops->set_rekey_data) { 11874 err = -EOPNOTSUPP; 11875 goto out; 11876 } 11877 11878 err = rdev_set_rekey_data(rdev, dev, &rekey_data); 11879 out: 11880 wdev_unlock(wdev); 11881 return err; 11882 } 11883 11884 static int nl80211_register_unexpected_frame(struct sk_buff *skb, 11885 struct genl_info *info) 11886 { 11887 struct net_device *dev = info->user_ptr[1]; 11888 struct wireless_dev *wdev = dev->ieee80211_ptr; 11889 11890 if (wdev->iftype != NL80211_IFTYPE_AP && 11891 wdev->iftype != NL80211_IFTYPE_P2P_GO) 11892 return -EINVAL; 11893 11894 if (wdev->ap_unexpected_nlportid) 11895 return -EBUSY; 11896 11897 wdev->ap_unexpected_nlportid = info->snd_portid; 11898 return 0; 11899 } 11900 11901 static int nl80211_probe_client(struct sk_buff *skb, 11902 struct genl_info *info) 11903 { 11904 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11905 struct net_device *dev = info->user_ptr[1]; 11906 struct wireless_dev *wdev = dev->ieee80211_ptr; 11907 struct sk_buff *msg; 11908 void *hdr; 11909 const u8 *addr; 11910 u64 cookie; 11911 int err; 11912 11913 if (wdev->iftype != NL80211_IFTYPE_AP && 11914 wdev->iftype != NL80211_IFTYPE_P2P_GO) 11915 return -EOPNOTSUPP; 11916 11917 if (!info->attrs[NL80211_ATTR_MAC]) 11918 return -EINVAL; 11919 11920 if (!rdev->ops->probe_client) 11921 return -EOPNOTSUPP; 11922 11923 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 11924 if (!msg) 11925 return -ENOMEM; 11926 11927 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 11928 NL80211_CMD_PROBE_CLIENT); 11929 if (!hdr) { 11930 err = -ENOBUFS; 11931 goto free_msg; 11932 } 11933 11934 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 11935 11936 err = rdev_probe_client(rdev, dev, addr, &cookie); 11937 if (err) 11938 goto free_msg; 11939 11940 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 11941 NL80211_ATTR_PAD)) 11942 goto nla_put_failure; 11943 11944 genlmsg_end(msg, hdr); 11945 11946 return genlmsg_reply(msg, info); 11947 11948 nla_put_failure: 11949 err = -ENOBUFS; 11950 free_msg: 11951 nlmsg_free(msg); 11952 return err; 11953 } 11954 11955 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) 11956 { 11957 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11958 struct cfg80211_beacon_registration *reg, *nreg; 11959 int rv; 11960 11961 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) 11962 return -EOPNOTSUPP; 11963 11964 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); 11965 if (!nreg) 11966 return -ENOMEM; 11967 11968 /* First, check if already registered. */ 11969 spin_lock_bh(&rdev->beacon_registrations_lock); 11970 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 11971 if (reg->nlportid == info->snd_portid) { 11972 rv = -EALREADY; 11973 goto out_err; 11974 } 11975 } 11976 /* Add it to the list */ 11977 nreg->nlportid = info->snd_portid; 11978 list_add(&nreg->list, &rdev->beacon_registrations); 11979 11980 spin_unlock_bh(&rdev->beacon_registrations_lock); 11981 11982 return 0; 11983 out_err: 11984 spin_unlock_bh(&rdev->beacon_registrations_lock); 11985 kfree(nreg); 11986 return rv; 11987 } 11988 11989 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) 11990 { 11991 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11992 struct wireless_dev *wdev = info->user_ptr[1]; 11993 int err; 11994 11995 if (!rdev->ops->start_p2p_device) 11996 return -EOPNOTSUPP; 11997 11998 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 11999 return -EOPNOTSUPP; 12000 12001 if (wdev_running(wdev)) 12002 return 0; 12003 12004 if (rfkill_blocked(rdev->rfkill)) 12005 return -ERFKILL; 12006 12007 err = rdev_start_p2p_device(rdev, wdev); 12008 if (err) 12009 return err; 12010 12011 wdev->is_running = true; 12012 rdev->opencount++; 12013 12014 return 0; 12015 } 12016 12017 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) 12018 { 12019 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12020 struct wireless_dev *wdev = info->user_ptr[1]; 12021 12022 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 12023 return -EOPNOTSUPP; 12024 12025 if (!rdev->ops->stop_p2p_device) 12026 return -EOPNOTSUPP; 12027 12028 cfg80211_stop_p2p_device(rdev, wdev); 12029 12030 return 0; 12031 } 12032 12033 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) 12034 { 12035 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12036 struct wireless_dev *wdev = info->user_ptr[1]; 12037 struct cfg80211_nan_conf conf = {}; 12038 int err; 12039 12040 if (wdev->iftype != NL80211_IFTYPE_NAN) 12041 return -EOPNOTSUPP; 12042 12043 if (wdev_running(wdev)) 12044 return -EEXIST; 12045 12046 if (rfkill_blocked(rdev->rfkill)) 12047 return -ERFKILL; 12048 12049 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) 12050 return -EINVAL; 12051 12052 conf.master_pref = 12053 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 12054 12055 if (info->attrs[NL80211_ATTR_BANDS]) { 12056 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 12057 12058 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 12059 return -EOPNOTSUPP; 12060 12061 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 12062 return -EINVAL; 12063 12064 conf.bands = bands; 12065 } 12066 12067 err = rdev_start_nan(rdev, wdev, &conf); 12068 if (err) 12069 return err; 12070 12071 wdev->is_running = true; 12072 rdev->opencount++; 12073 12074 return 0; 12075 } 12076 12077 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) 12078 { 12079 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12080 struct wireless_dev *wdev = info->user_ptr[1]; 12081 12082 if (wdev->iftype != NL80211_IFTYPE_NAN) 12083 return -EOPNOTSUPP; 12084 12085 cfg80211_stop_nan(rdev, wdev); 12086 12087 return 0; 12088 } 12089 12090 static int validate_nan_filter(struct nlattr *filter_attr) 12091 { 12092 struct nlattr *attr; 12093 int len = 0, n_entries = 0, rem; 12094 12095 nla_for_each_nested(attr, filter_attr, rem) { 12096 len += nla_len(attr); 12097 n_entries++; 12098 } 12099 12100 if (len >= U8_MAX) 12101 return -EINVAL; 12102 12103 return n_entries; 12104 } 12105 12106 static int handle_nan_filter(struct nlattr *attr_filter, 12107 struct cfg80211_nan_func *func, 12108 bool tx) 12109 { 12110 struct nlattr *attr; 12111 int n_entries, rem, i; 12112 struct cfg80211_nan_func_filter *filter; 12113 12114 n_entries = validate_nan_filter(attr_filter); 12115 if (n_entries < 0) 12116 return n_entries; 12117 12118 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); 12119 12120 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); 12121 if (!filter) 12122 return -ENOMEM; 12123 12124 i = 0; 12125 nla_for_each_nested(attr, attr_filter, rem) { 12126 filter[i].filter = nla_memdup(attr, GFP_KERNEL); 12127 filter[i].len = nla_len(attr); 12128 i++; 12129 } 12130 if (tx) { 12131 func->num_tx_filters = n_entries; 12132 func->tx_filters = filter; 12133 } else { 12134 func->num_rx_filters = n_entries; 12135 func->rx_filters = filter; 12136 } 12137 12138 return 0; 12139 } 12140 12141 static int nl80211_nan_add_func(struct sk_buff *skb, 12142 struct genl_info *info) 12143 { 12144 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12145 struct wireless_dev *wdev = info->user_ptr[1]; 12146 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; 12147 struct cfg80211_nan_func *func; 12148 struct sk_buff *msg = NULL; 12149 void *hdr = NULL; 12150 int err = 0; 12151 12152 if (wdev->iftype != NL80211_IFTYPE_NAN) 12153 return -EOPNOTSUPP; 12154 12155 if (!wdev_running(wdev)) 12156 return -ENOTCONN; 12157 12158 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 12159 return -EINVAL; 12160 12161 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, 12162 info->attrs[NL80211_ATTR_NAN_FUNC], 12163 nl80211_nan_func_policy, 12164 info->extack); 12165 if (err) 12166 return err; 12167 12168 func = kzalloc(sizeof(*func), GFP_KERNEL); 12169 if (!func) 12170 return -ENOMEM; 12171 12172 func->cookie = cfg80211_assign_cookie(rdev); 12173 12174 if (!tb[NL80211_NAN_FUNC_TYPE] || 12175 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { 12176 err = -EINVAL; 12177 goto out; 12178 } 12179 12180 12181 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); 12182 12183 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { 12184 err = -EINVAL; 12185 goto out; 12186 } 12187 12188 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), 12189 sizeof(func->service_id)); 12190 12191 func->close_range = 12192 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); 12193 12194 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { 12195 func->serv_spec_info_len = 12196 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); 12197 func->serv_spec_info = 12198 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), 12199 func->serv_spec_info_len, 12200 GFP_KERNEL); 12201 if (!func->serv_spec_info) { 12202 err = -ENOMEM; 12203 goto out; 12204 } 12205 } 12206 12207 if (tb[NL80211_NAN_FUNC_TTL]) 12208 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); 12209 12210 switch (func->type) { 12211 case NL80211_NAN_FUNC_PUBLISH: 12212 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { 12213 err = -EINVAL; 12214 goto out; 12215 } 12216 12217 func->publish_type = 12218 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); 12219 func->publish_bcast = 12220 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); 12221 12222 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && 12223 func->publish_bcast) { 12224 err = -EINVAL; 12225 goto out; 12226 } 12227 break; 12228 case NL80211_NAN_FUNC_SUBSCRIBE: 12229 func->subscribe_active = 12230 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); 12231 break; 12232 case NL80211_NAN_FUNC_FOLLOW_UP: 12233 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || 12234 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || 12235 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { 12236 err = -EINVAL; 12237 goto out; 12238 } 12239 12240 func->followup_id = 12241 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); 12242 func->followup_reqid = 12243 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); 12244 memcpy(func->followup_dest.addr, 12245 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), 12246 sizeof(func->followup_dest.addr)); 12247 if (func->ttl) { 12248 err = -EINVAL; 12249 goto out; 12250 } 12251 break; 12252 default: 12253 err = -EINVAL; 12254 goto out; 12255 } 12256 12257 if (tb[NL80211_NAN_FUNC_SRF]) { 12258 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 12259 12260 err = nla_parse_nested_deprecated(srf_tb, 12261 NL80211_NAN_SRF_ATTR_MAX, 12262 tb[NL80211_NAN_FUNC_SRF], 12263 nl80211_nan_srf_policy, 12264 info->extack); 12265 if (err) 12266 goto out; 12267 12268 func->srf_include = 12269 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); 12270 12271 if (srf_tb[NL80211_NAN_SRF_BF]) { 12272 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || 12273 !srf_tb[NL80211_NAN_SRF_BF_IDX]) { 12274 err = -EINVAL; 12275 goto out; 12276 } 12277 12278 func->srf_bf_len = 12279 nla_len(srf_tb[NL80211_NAN_SRF_BF]); 12280 func->srf_bf = 12281 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), 12282 func->srf_bf_len, GFP_KERNEL); 12283 if (!func->srf_bf) { 12284 err = -ENOMEM; 12285 goto out; 12286 } 12287 12288 func->srf_bf_idx = 12289 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); 12290 } else { 12291 struct nlattr *attr, *mac_attr = 12292 srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; 12293 int n_entries, rem, i = 0; 12294 12295 if (!mac_attr) { 12296 err = -EINVAL; 12297 goto out; 12298 } 12299 12300 n_entries = validate_acl_mac_addrs(mac_attr); 12301 if (n_entries <= 0) { 12302 err = -EINVAL; 12303 goto out; 12304 } 12305 12306 func->srf_num_macs = n_entries; 12307 func->srf_macs = 12308 kcalloc(n_entries, sizeof(*func->srf_macs), 12309 GFP_KERNEL); 12310 if (!func->srf_macs) { 12311 err = -ENOMEM; 12312 goto out; 12313 } 12314 12315 nla_for_each_nested(attr, mac_attr, rem) 12316 memcpy(func->srf_macs[i++].addr, nla_data(attr), 12317 sizeof(*func->srf_macs)); 12318 } 12319 } 12320 12321 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { 12322 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], 12323 func, true); 12324 if (err) 12325 goto out; 12326 } 12327 12328 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { 12329 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], 12330 func, false); 12331 if (err) 12332 goto out; 12333 } 12334 12335 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12336 if (!msg) { 12337 err = -ENOMEM; 12338 goto out; 12339 } 12340 12341 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12342 NL80211_CMD_ADD_NAN_FUNCTION); 12343 /* This can't really happen - we just allocated 4KB */ 12344 if (WARN_ON(!hdr)) { 12345 err = -ENOMEM; 12346 goto out; 12347 } 12348 12349 err = rdev_add_nan_func(rdev, wdev, func); 12350 out: 12351 if (err < 0) { 12352 cfg80211_free_nan_func(func); 12353 nlmsg_free(msg); 12354 return err; 12355 } 12356 12357 /* propagate the instance id and cookie to userspace */ 12358 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, 12359 NL80211_ATTR_PAD)) 12360 goto nla_put_failure; 12361 12362 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 12363 if (!func_attr) 12364 goto nla_put_failure; 12365 12366 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, 12367 func->instance_id)) 12368 goto nla_put_failure; 12369 12370 nla_nest_end(msg, func_attr); 12371 12372 genlmsg_end(msg, hdr); 12373 return genlmsg_reply(msg, info); 12374 12375 nla_put_failure: 12376 nlmsg_free(msg); 12377 return -ENOBUFS; 12378 } 12379 12380 static int nl80211_nan_del_func(struct sk_buff *skb, 12381 struct genl_info *info) 12382 { 12383 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12384 struct wireless_dev *wdev = info->user_ptr[1]; 12385 u64 cookie; 12386 12387 if (wdev->iftype != NL80211_IFTYPE_NAN) 12388 return -EOPNOTSUPP; 12389 12390 if (!wdev_running(wdev)) 12391 return -ENOTCONN; 12392 12393 if (!info->attrs[NL80211_ATTR_COOKIE]) 12394 return -EINVAL; 12395 12396 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12397 12398 rdev_del_nan_func(rdev, wdev, cookie); 12399 12400 return 0; 12401 } 12402 12403 static int nl80211_nan_change_config(struct sk_buff *skb, 12404 struct genl_info *info) 12405 { 12406 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12407 struct wireless_dev *wdev = info->user_ptr[1]; 12408 struct cfg80211_nan_conf conf = {}; 12409 u32 changed = 0; 12410 12411 if (wdev->iftype != NL80211_IFTYPE_NAN) 12412 return -EOPNOTSUPP; 12413 12414 if (!wdev_running(wdev)) 12415 return -ENOTCONN; 12416 12417 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { 12418 conf.master_pref = 12419 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 12420 if (conf.master_pref <= 1 || conf.master_pref == 255) 12421 return -EINVAL; 12422 12423 changed |= CFG80211_NAN_CONF_CHANGED_PREF; 12424 } 12425 12426 if (info->attrs[NL80211_ATTR_BANDS]) { 12427 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 12428 12429 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 12430 return -EOPNOTSUPP; 12431 12432 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 12433 return -EINVAL; 12434 12435 conf.bands = bands; 12436 changed |= CFG80211_NAN_CONF_CHANGED_BANDS; 12437 } 12438 12439 if (!changed) 12440 return -EINVAL; 12441 12442 return rdev_nan_change_conf(rdev, wdev, &conf, changed); 12443 } 12444 12445 void cfg80211_nan_match(struct wireless_dev *wdev, 12446 struct cfg80211_nan_match_params *match, gfp_t gfp) 12447 { 12448 struct wiphy *wiphy = wdev->wiphy; 12449 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 12450 struct nlattr *match_attr, *local_func_attr, *peer_func_attr; 12451 struct sk_buff *msg; 12452 void *hdr; 12453 12454 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) 12455 return; 12456 12457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 12458 if (!msg) 12459 return; 12460 12461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); 12462 if (!hdr) { 12463 nlmsg_free(msg); 12464 return; 12465 } 12466 12467 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 12468 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 12469 wdev->netdev->ifindex)) || 12470 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 12471 NL80211_ATTR_PAD)) 12472 goto nla_put_failure; 12473 12474 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, 12475 NL80211_ATTR_PAD) || 12476 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 12477 goto nla_put_failure; 12478 12479 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); 12480 if (!match_attr) 12481 goto nla_put_failure; 12482 12483 local_func_attr = nla_nest_start_noflag(msg, 12484 NL80211_NAN_MATCH_FUNC_LOCAL); 12485 if (!local_func_attr) 12486 goto nla_put_failure; 12487 12488 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) 12489 goto nla_put_failure; 12490 12491 nla_nest_end(msg, local_func_attr); 12492 12493 peer_func_attr = nla_nest_start_noflag(msg, 12494 NL80211_NAN_MATCH_FUNC_PEER); 12495 if (!peer_func_attr) 12496 goto nla_put_failure; 12497 12498 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || 12499 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) 12500 goto nla_put_failure; 12501 12502 if (match->info && match->info_len && 12503 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, 12504 match->info)) 12505 goto nla_put_failure; 12506 12507 nla_nest_end(msg, peer_func_attr); 12508 nla_nest_end(msg, match_attr); 12509 genlmsg_end(msg, hdr); 12510 12511 if (!wdev->owner_nlportid) 12512 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 12513 msg, 0, NL80211_MCGRP_NAN, gfp); 12514 else 12515 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 12516 wdev->owner_nlportid); 12517 12518 return; 12519 12520 nla_put_failure: 12521 nlmsg_free(msg); 12522 } 12523 EXPORT_SYMBOL(cfg80211_nan_match); 12524 12525 void cfg80211_nan_func_terminated(struct wireless_dev *wdev, 12526 u8 inst_id, 12527 enum nl80211_nan_func_term_reason reason, 12528 u64 cookie, gfp_t gfp) 12529 { 12530 struct wiphy *wiphy = wdev->wiphy; 12531 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 12532 struct sk_buff *msg; 12533 struct nlattr *func_attr; 12534 void *hdr; 12535 12536 if (WARN_ON(!inst_id)) 12537 return; 12538 12539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 12540 if (!msg) 12541 return; 12542 12543 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); 12544 if (!hdr) { 12545 nlmsg_free(msg); 12546 return; 12547 } 12548 12549 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 12550 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 12551 wdev->netdev->ifindex)) || 12552 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 12553 NL80211_ATTR_PAD)) 12554 goto nla_put_failure; 12555 12556 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12557 NL80211_ATTR_PAD)) 12558 goto nla_put_failure; 12559 12560 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 12561 if (!func_attr) 12562 goto nla_put_failure; 12563 12564 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || 12565 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) 12566 goto nla_put_failure; 12567 12568 nla_nest_end(msg, func_attr); 12569 genlmsg_end(msg, hdr); 12570 12571 if (!wdev->owner_nlportid) 12572 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 12573 msg, 0, NL80211_MCGRP_NAN, gfp); 12574 else 12575 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 12576 wdev->owner_nlportid); 12577 12578 return; 12579 12580 nla_put_failure: 12581 nlmsg_free(msg); 12582 } 12583 EXPORT_SYMBOL(cfg80211_nan_func_terminated); 12584 12585 static int nl80211_get_protocol_features(struct sk_buff *skb, 12586 struct genl_info *info) 12587 { 12588 void *hdr; 12589 struct sk_buff *msg; 12590 12591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12592 if (!msg) 12593 return -ENOMEM; 12594 12595 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12596 NL80211_CMD_GET_PROTOCOL_FEATURES); 12597 if (!hdr) 12598 goto nla_put_failure; 12599 12600 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, 12601 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) 12602 goto nla_put_failure; 12603 12604 genlmsg_end(msg, hdr); 12605 return genlmsg_reply(msg, info); 12606 12607 nla_put_failure: 12608 kfree_skb(msg); 12609 return -ENOBUFS; 12610 } 12611 12612 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) 12613 { 12614 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12615 struct cfg80211_update_ft_ies_params ft_params; 12616 struct net_device *dev = info->user_ptr[1]; 12617 12618 if (!rdev->ops->update_ft_ies) 12619 return -EOPNOTSUPP; 12620 12621 if (!info->attrs[NL80211_ATTR_MDID] || 12622 !info->attrs[NL80211_ATTR_IE]) 12623 return -EINVAL; 12624 12625 memset(&ft_params, 0, sizeof(ft_params)); 12626 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); 12627 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 12628 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 12629 12630 return rdev_update_ft_ies(rdev, dev, &ft_params); 12631 } 12632 12633 static int nl80211_crit_protocol_start(struct sk_buff *skb, 12634 struct genl_info *info) 12635 { 12636 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12637 struct wireless_dev *wdev = info->user_ptr[1]; 12638 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; 12639 u16 duration; 12640 int ret; 12641 12642 if (!rdev->ops->crit_proto_start) 12643 return -EOPNOTSUPP; 12644 12645 if (WARN_ON(!rdev->ops->crit_proto_stop)) 12646 return -EINVAL; 12647 12648 if (rdev->crit_proto_nlportid) 12649 return -EBUSY; 12650 12651 /* determine protocol if provided */ 12652 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) 12653 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); 12654 12655 if (proto >= NUM_NL80211_CRIT_PROTO) 12656 return -EINVAL; 12657 12658 /* timeout must be provided */ 12659 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) 12660 return -EINVAL; 12661 12662 duration = 12663 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); 12664 12665 if (duration > NL80211_CRIT_PROTO_MAX_DURATION) 12666 return -ERANGE; 12667 12668 ret = rdev_crit_proto_start(rdev, wdev, proto, duration); 12669 if (!ret) 12670 rdev->crit_proto_nlportid = info->snd_portid; 12671 12672 return ret; 12673 } 12674 12675 static int nl80211_crit_protocol_stop(struct sk_buff *skb, 12676 struct genl_info *info) 12677 { 12678 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12679 struct wireless_dev *wdev = info->user_ptr[1]; 12680 12681 if (!rdev->ops->crit_proto_stop) 12682 return -EOPNOTSUPP; 12683 12684 if (rdev->crit_proto_nlportid) { 12685 rdev->crit_proto_nlportid = 0; 12686 rdev_crit_proto_stop(rdev, wdev); 12687 } 12688 return 0; 12689 } 12690 12691 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, 12692 struct nlattr *attr, 12693 struct netlink_ext_ack *extack) 12694 { 12695 if (vcmd->policy == VENDOR_CMD_RAW_DATA) { 12696 if (attr->nla_type & NLA_F_NESTED) { 12697 NL_SET_ERR_MSG_ATTR(extack, attr, 12698 "unexpected nested data"); 12699 return -EINVAL; 12700 } 12701 12702 return 0; 12703 } 12704 12705 if (!(attr->nla_type & NLA_F_NESTED)) { 12706 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); 12707 return -EINVAL; 12708 } 12709 12710 return nl80211_validate_nested(attr, vcmd->maxattr, vcmd->policy, 12711 extack); 12712 } 12713 12714 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) 12715 { 12716 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12717 struct wireless_dev *wdev = 12718 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); 12719 int i, err; 12720 u32 vid, subcmd; 12721 12722 if (!rdev->wiphy.vendor_commands) 12723 return -EOPNOTSUPP; 12724 12725 if (IS_ERR(wdev)) { 12726 err = PTR_ERR(wdev); 12727 if (err != -EINVAL) 12728 return err; 12729 wdev = NULL; 12730 } else if (wdev->wiphy != &rdev->wiphy) { 12731 return -EINVAL; 12732 } 12733 12734 if (!info->attrs[NL80211_ATTR_VENDOR_ID] || 12735 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) 12736 return -EINVAL; 12737 12738 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); 12739 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); 12740 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 12741 const struct wiphy_vendor_command *vcmd; 12742 void *data = NULL; 12743 int len = 0; 12744 12745 vcmd = &rdev->wiphy.vendor_commands[i]; 12746 12747 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 12748 continue; 12749 12750 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 12751 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 12752 if (!wdev) 12753 return -EINVAL; 12754 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 12755 !wdev->netdev) 12756 return -EINVAL; 12757 12758 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 12759 if (!wdev_running(wdev)) 12760 return -ENETDOWN; 12761 } 12762 12763 if (!vcmd->doit) 12764 return -EOPNOTSUPP; 12765 } else { 12766 wdev = NULL; 12767 } 12768 12769 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { 12770 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); 12771 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); 12772 12773 err = nl80211_vendor_check_policy(vcmd, 12774 info->attrs[NL80211_ATTR_VENDOR_DATA], 12775 info->extack); 12776 if (err) 12777 return err; 12778 } 12779 12780 rdev->cur_cmd_info = info; 12781 err = vcmd->doit(&rdev->wiphy, wdev, data, len); 12782 rdev->cur_cmd_info = NULL; 12783 return err; 12784 } 12785 12786 return -EOPNOTSUPP; 12787 } 12788 12789 static int nl80211_prepare_vendor_dump(struct sk_buff *skb, 12790 struct netlink_callback *cb, 12791 struct cfg80211_registered_device **rdev, 12792 struct wireless_dev **wdev) 12793 { 12794 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); 12795 u32 vid, subcmd; 12796 unsigned int i; 12797 int vcmd_idx = -1; 12798 int err; 12799 void *data = NULL; 12800 unsigned int data_len = 0; 12801 12802 if (cb->args[0]) { 12803 /* subtract the 1 again here */ 12804 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 12805 struct wireless_dev *tmp; 12806 12807 if (!wiphy) 12808 return -ENODEV; 12809 *rdev = wiphy_to_rdev(wiphy); 12810 *wdev = NULL; 12811 12812 if (cb->args[1]) { 12813 list_for_each_entry(tmp, &wiphy->wdev_list, list) { 12814 if (tmp->identifier == cb->args[1] - 1) { 12815 *wdev = tmp; 12816 break; 12817 } 12818 } 12819 } 12820 12821 /* keep rtnl locked in successful case */ 12822 return 0; 12823 } 12824 12825 err = nlmsg_parse_deprecated(cb->nlh, 12826 GENL_HDRLEN + nl80211_fam.hdrsize, 12827 attrbuf, nl80211_fam.maxattr, 12828 nl80211_policy, NULL); 12829 if (err) 12830 return err; 12831 12832 if (!attrbuf[NL80211_ATTR_VENDOR_ID] || 12833 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) 12834 return -EINVAL; 12835 12836 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); 12837 if (IS_ERR(*wdev)) 12838 *wdev = NULL; 12839 12840 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 12841 if (IS_ERR(*rdev)) 12842 return PTR_ERR(*rdev); 12843 12844 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); 12845 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); 12846 12847 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { 12848 const struct wiphy_vendor_command *vcmd; 12849 12850 vcmd = &(*rdev)->wiphy.vendor_commands[i]; 12851 12852 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 12853 continue; 12854 12855 if (!vcmd->dumpit) 12856 return -EOPNOTSUPP; 12857 12858 vcmd_idx = i; 12859 break; 12860 } 12861 12862 if (vcmd_idx < 0) 12863 return -EOPNOTSUPP; 12864 12865 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { 12866 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); 12867 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); 12868 12869 err = nl80211_vendor_check_policy( 12870 &(*rdev)->wiphy.vendor_commands[vcmd_idx], 12871 attrbuf[NL80211_ATTR_VENDOR_DATA], 12872 cb->extack); 12873 if (err) 12874 return err; 12875 } 12876 12877 /* 0 is the first index - add 1 to parse only once */ 12878 cb->args[0] = (*rdev)->wiphy_idx + 1; 12879 /* add 1 to know if it was NULL */ 12880 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; 12881 cb->args[2] = vcmd_idx; 12882 cb->args[3] = (unsigned long)data; 12883 cb->args[4] = data_len; 12884 12885 /* keep rtnl locked in successful case */ 12886 return 0; 12887 } 12888 12889 static int nl80211_vendor_cmd_dump(struct sk_buff *skb, 12890 struct netlink_callback *cb) 12891 { 12892 struct cfg80211_registered_device *rdev; 12893 struct wireless_dev *wdev; 12894 unsigned int vcmd_idx; 12895 const struct wiphy_vendor_command *vcmd; 12896 void *data; 12897 int data_len; 12898 int err; 12899 struct nlattr *vendor_data; 12900 12901 rtnl_lock(); 12902 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); 12903 if (err) 12904 goto out; 12905 12906 vcmd_idx = cb->args[2]; 12907 data = (void *)cb->args[3]; 12908 data_len = cb->args[4]; 12909 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; 12910 12911 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 12912 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 12913 if (!wdev) { 12914 err = -EINVAL; 12915 goto out; 12916 } 12917 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 12918 !wdev->netdev) { 12919 err = -EINVAL; 12920 goto out; 12921 } 12922 12923 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 12924 if (!wdev_running(wdev)) { 12925 err = -ENETDOWN; 12926 goto out; 12927 } 12928 } 12929 } 12930 12931 while (1) { 12932 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 12933 cb->nlh->nlmsg_seq, NLM_F_MULTI, 12934 NL80211_CMD_VENDOR); 12935 if (!hdr) 12936 break; 12937 12938 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 12939 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 12940 wdev_id(wdev), 12941 NL80211_ATTR_PAD))) { 12942 genlmsg_cancel(skb, hdr); 12943 break; 12944 } 12945 12946 vendor_data = nla_nest_start_noflag(skb, 12947 NL80211_ATTR_VENDOR_DATA); 12948 if (!vendor_data) { 12949 genlmsg_cancel(skb, hdr); 12950 break; 12951 } 12952 12953 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, 12954 (unsigned long *)&cb->args[5]); 12955 nla_nest_end(skb, vendor_data); 12956 12957 if (err == -ENOBUFS || err == -ENOENT) { 12958 genlmsg_cancel(skb, hdr); 12959 break; 12960 } else if (err) { 12961 genlmsg_cancel(skb, hdr); 12962 goto out; 12963 } 12964 12965 genlmsg_end(skb, hdr); 12966 } 12967 12968 err = skb->len; 12969 out: 12970 rtnl_unlock(); 12971 return err; 12972 } 12973 12974 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, 12975 enum nl80211_commands cmd, 12976 enum nl80211_attrs attr, 12977 int approxlen) 12978 { 12979 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 12980 12981 if (WARN_ON(!rdev->cur_cmd_info)) 12982 return NULL; 12983 12984 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, 12985 rdev->cur_cmd_info->snd_portid, 12986 rdev->cur_cmd_info->snd_seq, 12987 cmd, attr, NULL, GFP_KERNEL); 12988 } 12989 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); 12990 12991 int cfg80211_vendor_cmd_reply(struct sk_buff *skb) 12992 { 12993 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 12994 void *hdr = ((void **)skb->cb)[1]; 12995 struct nlattr *data = ((void **)skb->cb)[2]; 12996 12997 /* clear CB data for netlink core to own from now on */ 12998 memset(skb->cb, 0, sizeof(skb->cb)); 12999 13000 if (WARN_ON(!rdev->cur_cmd_info)) { 13001 kfree_skb(skb); 13002 return -EINVAL; 13003 } 13004 13005 nla_nest_end(skb, data); 13006 genlmsg_end(skb, hdr); 13007 return genlmsg_reply(skb, rdev->cur_cmd_info); 13008 } 13009 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); 13010 13011 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) 13012 { 13013 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 13014 13015 if (WARN_ON(!rdev->cur_cmd_info)) 13016 return 0; 13017 13018 return rdev->cur_cmd_info->snd_portid; 13019 } 13020 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); 13021 13022 static int nl80211_set_qos_map(struct sk_buff *skb, 13023 struct genl_info *info) 13024 { 13025 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13026 struct cfg80211_qos_map *qos_map = NULL; 13027 struct net_device *dev = info->user_ptr[1]; 13028 u8 *pos, len, num_des, des_len, des; 13029 int ret; 13030 13031 if (!rdev->ops->set_qos_map) 13032 return -EOPNOTSUPP; 13033 13034 if (info->attrs[NL80211_ATTR_QOS_MAP]) { 13035 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); 13036 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); 13037 13038 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || 13039 len > IEEE80211_QOS_MAP_LEN_MAX) 13040 return -EINVAL; 13041 13042 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); 13043 if (!qos_map) 13044 return -ENOMEM; 13045 13046 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; 13047 if (num_des) { 13048 des_len = num_des * 13049 sizeof(struct cfg80211_dscp_exception); 13050 memcpy(qos_map->dscp_exception, pos, des_len); 13051 qos_map->num_des = num_des; 13052 for (des = 0; des < num_des; des++) { 13053 if (qos_map->dscp_exception[des].up > 7) { 13054 kfree(qos_map); 13055 return -EINVAL; 13056 } 13057 } 13058 pos += des_len; 13059 } 13060 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); 13061 } 13062 13063 wdev_lock(dev->ieee80211_ptr); 13064 ret = nl80211_key_allowed(dev->ieee80211_ptr); 13065 if (!ret) 13066 ret = rdev_set_qos_map(rdev, dev, qos_map); 13067 wdev_unlock(dev->ieee80211_ptr); 13068 13069 kfree(qos_map); 13070 return ret; 13071 } 13072 13073 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) 13074 { 13075 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13076 struct net_device *dev = info->user_ptr[1]; 13077 struct wireless_dev *wdev = dev->ieee80211_ptr; 13078 const u8 *peer; 13079 u8 tsid, up; 13080 u16 admitted_time = 0; 13081 int err; 13082 13083 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) 13084 return -EOPNOTSUPP; 13085 13086 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 13087 !info->attrs[NL80211_ATTR_USER_PRIO]) 13088 return -EINVAL; 13089 13090 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 13091 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); 13092 13093 /* WMM uses TIDs 0-7 even for TSPEC */ 13094 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { 13095 /* TODO: handle 802.11 TSPEC/admission control 13096 * need more attributes for that (e.g. BA session requirement); 13097 * change the WMM adminssion test above to allow both then 13098 */ 13099 return -EINVAL; 13100 } 13101 13102 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 13103 13104 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { 13105 admitted_time = 13106 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); 13107 if (!admitted_time) 13108 return -EINVAL; 13109 } 13110 13111 wdev_lock(wdev); 13112 switch (wdev->iftype) { 13113 case NL80211_IFTYPE_STATION: 13114 case NL80211_IFTYPE_P2P_CLIENT: 13115 if (wdev->current_bss) 13116 break; 13117 err = -ENOTCONN; 13118 goto out; 13119 default: 13120 err = -EOPNOTSUPP; 13121 goto out; 13122 } 13123 13124 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); 13125 13126 out: 13127 wdev_unlock(wdev); 13128 return err; 13129 } 13130 13131 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) 13132 { 13133 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13134 struct net_device *dev = info->user_ptr[1]; 13135 struct wireless_dev *wdev = dev->ieee80211_ptr; 13136 const u8 *peer; 13137 u8 tsid; 13138 int err; 13139 13140 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) 13141 return -EINVAL; 13142 13143 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 13144 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 13145 13146 wdev_lock(wdev); 13147 err = rdev_del_tx_ts(rdev, dev, tsid, peer); 13148 wdev_unlock(wdev); 13149 13150 return err; 13151 } 13152 13153 static int nl80211_tdls_channel_switch(struct sk_buff *skb, 13154 struct genl_info *info) 13155 { 13156 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13157 struct net_device *dev = info->user_ptr[1]; 13158 struct wireless_dev *wdev = dev->ieee80211_ptr; 13159 struct cfg80211_chan_def chandef = {}; 13160 const u8 *addr; 13161 u8 oper_class; 13162 int err; 13163 13164 if (!rdev->ops->tdls_channel_switch || 13165 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 13166 return -EOPNOTSUPP; 13167 13168 switch (dev->ieee80211_ptr->iftype) { 13169 case NL80211_IFTYPE_STATION: 13170 case NL80211_IFTYPE_P2P_CLIENT: 13171 break; 13172 default: 13173 return -EOPNOTSUPP; 13174 } 13175 13176 if (!info->attrs[NL80211_ATTR_MAC] || 13177 !info->attrs[NL80211_ATTR_OPER_CLASS]) 13178 return -EINVAL; 13179 13180 err = nl80211_parse_chandef(rdev, info, &chandef); 13181 if (err) 13182 return err; 13183 13184 /* 13185 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 13186 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the 13187 * specification is not defined for them. 13188 */ 13189 if (chandef.chan->band == NL80211_BAND_2GHZ && 13190 chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 13191 chandef.width != NL80211_CHAN_WIDTH_20) 13192 return -EINVAL; 13193 13194 /* we will be active on the TDLS link */ 13195 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 13196 wdev->iftype)) 13197 return -EINVAL; 13198 13199 /* don't allow switching to DFS channels */ 13200 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) 13201 return -EINVAL; 13202 13203 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 13204 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); 13205 13206 wdev_lock(wdev); 13207 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); 13208 wdev_unlock(wdev); 13209 13210 return err; 13211 } 13212 13213 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, 13214 struct genl_info *info) 13215 { 13216 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13217 struct net_device *dev = info->user_ptr[1]; 13218 struct wireless_dev *wdev = dev->ieee80211_ptr; 13219 const u8 *addr; 13220 13221 if (!rdev->ops->tdls_channel_switch || 13222 !rdev->ops->tdls_cancel_channel_switch || 13223 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 13224 return -EOPNOTSUPP; 13225 13226 switch (dev->ieee80211_ptr->iftype) { 13227 case NL80211_IFTYPE_STATION: 13228 case NL80211_IFTYPE_P2P_CLIENT: 13229 break; 13230 default: 13231 return -EOPNOTSUPP; 13232 } 13233 13234 if (!info->attrs[NL80211_ATTR_MAC]) 13235 return -EINVAL; 13236 13237 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 13238 13239 wdev_lock(wdev); 13240 rdev_tdls_cancel_channel_switch(rdev, dev, addr); 13241 wdev_unlock(wdev); 13242 13243 return 0; 13244 } 13245 13246 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, 13247 struct genl_info *info) 13248 { 13249 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13250 struct net_device *dev = info->user_ptr[1]; 13251 struct wireless_dev *wdev = dev->ieee80211_ptr; 13252 const struct nlattr *nla; 13253 bool enabled; 13254 13255 if (!rdev->ops->set_multicast_to_unicast) 13256 return -EOPNOTSUPP; 13257 13258 if (wdev->iftype != NL80211_IFTYPE_AP && 13259 wdev->iftype != NL80211_IFTYPE_P2P_GO) 13260 return -EOPNOTSUPP; 13261 13262 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; 13263 enabled = nla_get_flag(nla); 13264 13265 return rdev_set_multicast_to_unicast(rdev, dev, enabled); 13266 } 13267 13268 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) 13269 { 13270 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13271 struct net_device *dev = info->user_ptr[1]; 13272 struct wireless_dev *wdev = dev->ieee80211_ptr; 13273 struct cfg80211_pmk_conf pmk_conf = {}; 13274 int ret; 13275 13276 if (wdev->iftype != NL80211_IFTYPE_STATION && 13277 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 13278 return -EOPNOTSUPP; 13279 13280 if (!wiphy_ext_feature_isset(&rdev->wiphy, 13281 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 13282 return -EOPNOTSUPP; 13283 13284 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) 13285 return -EINVAL; 13286 13287 wdev_lock(wdev); 13288 if (!wdev->current_bss) { 13289 ret = -ENOTCONN; 13290 goto out; 13291 } 13292 13293 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 13294 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { 13295 ret = -EINVAL; 13296 goto out; 13297 } 13298 13299 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 13300 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 13301 if (pmk_conf.pmk_len != WLAN_PMK_LEN && 13302 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { 13303 ret = -EINVAL; 13304 goto out; 13305 } 13306 13307 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { 13308 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); 13309 13310 if (r0_name_len != WLAN_PMK_NAME_LEN) { 13311 ret = -EINVAL; 13312 goto out; 13313 } 13314 13315 pmk_conf.pmk_r0_name = 13316 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); 13317 } 13318 13319 ret = rdev_set_pmk(rdev, dev, &pmk_conf); 13320 out: 13321 wdev_unlock(wdev); 13322 return ret; 13323 } 13324 13325 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) 13326 { 13327 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13328 struct net_device *dev = info->user_ptr[1]; 13329 struct wireless_dev *wdev = dev->ieee80211_ptr; 13330 const u8 *aa; 13331 int ret; 13332 13333 if (wdev->iftype != NL80211_IFTYPE_STATION && 13334 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 13335 return -EOPNOTSUPP; 13336 13337 if (!wiphy_ext_feature_isset(&rdev->wiphy, 13338 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 13339 return -EOPNOTSUPP; 13340 13341 if (!info->attrs[NL80211_ATTR_MAC]) 13342 return -EINVAL; 13343 13344 wdev_lock(wdev); 13345 aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 13346 ret = rdev_del_pmk(rdev, dev, aa); 13347 wdev_unlock(wdev); 13348 13349 return ret; 13350 } 13351 13352 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) 13353 { 13354 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13355 struct net_device *dev = info->user_ptr[1]; 13356 struct cfg80211_external_auth_params params; 13357 13358 if (!rdev->ops->external_auth) 13359 return -EOPNOTSUPP; 13360 13361 if (!info->attrs[NL80211_ATTR_SSID] && 13362 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 13363 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 13364 return -EINVAL; 13365 13366 if (!info->attrs[NL80211_ATTR_BSSID]) 13367 return -EINVAL; 13368 13369 if (!info->attrs[NL80211_ATTR_STATUS_CODE]) 13370 return -EINVAL; 13371 13372 memset(¶ms, 0, sizeof(params)); 13373 13374 if (info->attrs[NL80211_ATTR_SSID]) { 13375 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 13376 if (params.ssid.ssid_len == 0 || 13377 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) 13378 return -EINVAL; 13379 memcpy(params.ssid.ssid, 13380 nla_data(info->attrs[NL80211_ATTR_SSID]), 13381 params.ssid.ssid_len); 13382 } 13383 13384 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), 13385 ETH_ALEN); 13386 13387 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 13388 13389 if (info->attrs[NL80211_ATTR_PMKID]) 13390 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 13391 13392 return rdev_external_auth(rdev, dev, ¶ms); 13393 } 13394 13395 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) 13396 { 13397 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13398 struct net_device *dev = info->user_ptr[1]; 13399 struct wireless_dev *wdev = dev->ieee80211_ptr; 13400 const u8 *buf; 13401 size_t len; 13402 u8 *dest; 13403 u16 proto; 13404 bool noencrypt; 13405 int err; 13406 13407 if (!wiphy_ext_feature_isset(&rdev->wiphy, 13408 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 13409 return -EOPNOTSUPP; 13410 13411 if (!rdev->ops->tx_control_port) 13412 return -EOPNOTSUPP; 13413 13414 if (!info->attrs[NL80211_ATTR_FRAME] || 13415 !info->attrs[NL80211_ATTR_MAC] || 13416 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 13417 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); 13418 return -EINVAL; 13419 } 13420 13421 wdev_lock(wdev); 13422 13423 switch (wdev->iftype) { 13424 case NL80211_IFTYPE_AP: 13425 case NL80211_IFTYPE_P2P_GO: 13426 case NL80211_IFTYPE_MESH_POINT: 13427 break; 13428 case NL80211_IFTYPE_ADHOC: 13429 case NL80211_IFTYPE_STATION: 13430 case NL80211_IFTYPE_P2P_CLIENT: 13431 if (wdev->current_bss) 13432 break; 13433 err = -ENOTCONN; 13434 goto out; 13435 default: 13436 err = -EOPNOTSUPP; 13437 goto out; 13438 } 13439 13440 wdev_unlock(wdev); 13441 13442 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 13443 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 13444 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 13445 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 13446 noencrypt = 13447 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); 13448 13449 return rdev_tx_control_port(rdev, dev, buf, len, 13450 dest, cpu_to_be16(proto), noencrypt); 13451 13452 out: 13453 wdev_unlock(wdev); 13454 return err; 13455 } 13456 13457 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, 13458 struct genl_info *info) 13459 { 13460 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13461 struct net_device *dev = info->user_ptr[1]; 13462 struct wireless_dev *wdev = dev->ieee80211_ptr; 13463 struct cfg80211_ftm_responder_stats ftm_stats = {}; 13464 struct sk_buff *msg; 13465 void *hdr; 13466 struct nlattr *ftm_stats_attr; 13467 int err; 13468 13469 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) 13470 return -EOPNOTSUPP; 13471 13472 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); 13473 if (err) 13474 return err; 13475 13476 if (!ftm_stats.filled) 13477 return -ENODATA; 13478 13479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13480 if (!msg) 13481 return -ENOMEM; 13482 13483 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13484 NL80211_CMD_GET_FTM_RESPONDER_STATS); 13485 if (!hdr) 13486 return -ENOBUFS; 13487 13488 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 13489 goto nla_put_failure; 13490 13491 ftm_stats_attr = nla_nest_start_noflag(msg, 13492 NL80211_ATTR_FTM_RESPONDER_STATS); 13493 if (!ftm_stats_attr) 13494 goto nla_put_failure; 13495 13496 #define SET_FTM(field, name, type) \ 13497 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 13498 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ 13499 ftm_stats.field)) \ 13500 goto nla_put_failure; } while (0) 13501 #define SET_FTM_U64(field, name) \ 13502 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 13503 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ 13504 ftm_stats.field, NL80211_FTM_STATS_PAD)) \ 13505 goto nla_put_failure; } while (0) 13506 13507 SET_FTM(success_num, SUCCESS_NUM, u32); 13508 SET_FTM(partial_num, PARTIAL_NUM, u32); 13509 SET_FTM(failed_num, FAILED_NUM, u32); 13510 SET_FTM(asap_num, ASAP_NUM, u32); 13511 SET_FTM(non_asap_num, NON_ASAP_NUM, u32); 13512 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); 13513 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); 13514 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); 13515 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); 13516 #undef SET_FTM 13517 13518 nla_nest_end(msg, ftm_stats_attr); 13519 13520 genlmsg_end(msg, hdr); 13521 return genlmsg_reply(msg, info); 13522 13523 nla_put_failure: 13524 nlmsg_free(msg); 13525 return -ENOBUFS; 13526 } 13527 13528 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) 13529 { 13530 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13531 struct cfg80211_update_owe_info owe_info; 13532 struct net_device *dev = info->user_ptr[1]; 13533 13534 if (!rdev->ops->update_owe_info) 13535 return -EOPNOTSUPP; 13536 13537 if (!info->attrs[NL80211_ATTR_STATUS_CODE] || 13538 !info->attrs[NL80211_ATTR_MAC]) 13539 return -EINVAL; 13540 13541 memset(&owe_info, 0, sizeof(owe_info)); 13542 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 13543 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); 13544 13545 if (info->attrs[NL80211_ATTR_IE]) { 13546 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 13547 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 13548 } 13549 13550 return rdev_update_owe_info(rdev, dev, &owe_info); 13551 } 13552 13553 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) 13554 { 13555 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13556 struct net_device *dev = info->user_ptr[1]; 13557 struct wireless_dev *wdev = dev->ieee80211_ptr; 13558 struct station_info sinfo = {}; 13559 const u8 *buf; 13560 size_t len; 13561 u8 *dest; 13562 int err; 13563 13564 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) 13565 return -EOPNOTSUPP; 13566 13567 if (!info->attrs[NL80211_ATTR_MAC] || 13568 !info->attrs[NL80211_ATTR_FRAME]) { 13569 GENL_SET_ERR_MSG(info, "Frame or MAC missing"); 13570 return -EINVAL; 13571 } 13572 13573 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 13574 return -EOPNOTSUPP; 13575 13576 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 13577 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 13578 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 13579 13580 if (len < sizeof(struct ethhdr)) 13581 return -EINVAL; 13582 13583 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || 13584 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) 13585 return -EINVAL; 13586 13587 err = rdev_get_station(rdev, dev, dest, &sinfo); 13588 if (err) 13589 return err; 13590 13591 return rdev_probe_mesh_link(rdev, dev, dest, buf, len); 13592 } 13593 13594 #define NL80211_FLAG_NEED_WIPHY 0x01 13595 #define NL80211_FLAG_NEED_NETDEV 0x02 13596 #define NL80211_FLAG_NEED_RTNL 0x04 13597 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 13598 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ 13599 NL80211_FLAG_CHECK_NETDEV_UP) 13600 #define NL80211_FLAG_NEED_WDEV 0x10 13601 /* If a netdev is associated, it must be UP, P2P must be started */ 13602 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ 13603 NL80211_FLAG_CHECK_NETDEV_UP) 13604 #define NL80211_FLAG_CLEAR_SKB 0x20 13605 13606 static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, 13607 struct genl_info *info) 13608 { 13609 struct cfg80211_registered_device *rdev; 13610 struct wireless_dev *wdev; 13611 struct net_device *dev; 13612 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; 13613 13614 if (rtnl) 13615 rtnl_lock(); 13616 13617 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { 13618 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 13619 if (IS_ERR(rdev)) { 13620 if (rtnl) 13621 rtnl_unlock(); 13622 return PTR_ERR(rdev); 13623 } 13624 info->user_ptr[0] = rdev; 13625 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || 13626 ops->internal_flags & NL80211_FLAG_NEED_WDEV) { 13627 ASSERT_RTNL(); 13628 13629 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), 13630 info->attrs); 13631 if (IS_ERR(wdev)) { 13632 if (rtnl) 13633 rtnl_unlock(); 13634 return PTR_ERR(wdev); 13635 } 13636 13637 dev = wdev->netdev; 13638 rdev = wiphy_to_rdev(wdev->wiphy); 13639 13640 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { 13641 if (!dev) { 13642 if (rtnl) 13643 rtnl_unlock(); 13644 return -EINVAL; 13645 } 13646 13647 info->user_ptr[1] = dev; 13648 } else { 13649 info->user_ptr[1] = wdev; 13650 } 13651 13652 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && 13653 !wdev_running(wdev)) { 13654 if (rtnl) 13655 rtnl_unlock(); 13656 return -ENETDOWN; 13657 } 13658 13659 if (dev) 13660 dev_hold(dev); 13661 13662 info->user_ptr[0] = rdev; 13663 } 13664 13665 return 0; 13666 } 13667 13668 static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, 13669 struct genl_info *info) 13670 { 13671 if (info->user_ptr[1]) { 13672 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { 13673 struct wireless_dev *wdev = info->user_ptr[1]; 13674 13675 if (wdev->netdev) 13676 dev_put(wdev->netdev); 13677 } else { 13678 dev_put(info->user_ptr[1]); 13679 } 13680 } 13681 13682 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) 13683 rtnl_unlock(); 13684 13685 /* If needed, clear the netlink message payload from the SKB 13686 * as it might contain key data that shouldn't stick around on 13687 * the heap after the SKB is freed. The netlink message header 13688 * is still needed for further processing, so leave it intact. 13689 */ 13690 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { 13691 struct nlmsghdr *nlh = nlmsg_hdr(skb); 13692 13693 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); 13694 } 13695 } 13696 13697 static const struct genl_ops nl80211_ops[] = { 13698 { 13699 .cmd = NL80211_CMD_GET_WIPHY, 13700 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13701 .doit = nl80211_get_wiphy, 13702 .dumpit = nl80211_dump_wiphy, 13703 .done = nl80211_dump_wiphy_done, 13704 /* can be retrieved by unprivileged users */ 13705 .internal_flags = NL80211_FLAG_NEED_WIPHY | 13706 NL80211_FLAG_NEED_RTNL, 13707 }, 13708 { 13709 .cmd = NL80211_CMD_SET_WIPHY, 13710 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13711 .doit = nl80211_set_wiphy, 13712 .flags = GENL_UNS_ADMIN_PERM, 13713 .internal_flags = NL80211_FLAG_NEED_RTNL, 13714 }, 13715 { 13716 .cmd = NL80211_CMD_GET_INTERFACE, 13717 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13718 .doit = nl80211_get_interface, 13719 .dumpit = nl80211_dump_interface, 13720 /* can be retrieved by unprivileged users */ 13721 .internal_flags = NL80211_FLAG_NEED_WDEV | 13722 NL80211_FLAG_NEED_RTNL, 13723 }, 13724 { 13725 .cmd = NL80211_CMD_SET_INTERFACE, 13726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13727 .doit = nl80211_set_interface, 13728 .flags = GENL_UNS_ADMIN_PERM, 13729 .internal_flags = NL80211_FLAG_NEED_NETDEV | 13730 NL80211_FLAG_NEED_RTNL, 13731 }, 13732 { 13733 .cmd = NL80211_CMD_NEW_INTERFACE, 13734 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13735 .doit = nl80211_new_interface, 13736 .flags = GENL_UNS_ADMIN_PERM, 13737 .internal_flags = NL80211_FLAG_NEED_WIPHY | 13738 NL80211_FLAG_NEED_RTNL, 13739 }, 13740 { 13741 .cmd = NL80211_CMD_DEL_INTERFACE, 13742 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13743 .doit = nl80211_del_interface, 13744 .flags = GENL_UNS_ADMIN_PERM, 13745 .internal_flags = NL80211_FLAG_NEED_WDEV | 13746 NL80211_FLAG_NEED_RTNL, 13747 }, 13748 { 13749 .cmd = NL80211_CMD_GET_KEY, 13750 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13751 .doit = nl80211_get_key, 13752 .flags = GENL_UNS_ADMIN_PERM, 13753 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13754 NL80211_FLAG_NEED_RTNL, 13755 }, 13756 { 13757 .cmd = NL80211_CMD_SET_KEY, 13758 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13759 .doit = nl80211_set_key, 13760 .flags = GENL_UNS_ADMIN_PERM, 13761 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13762 NL80211_FLAG_NEED_RTNL | 13763 NL80211_FLAG_CLEAR_SKB, 13764 }, 13765 { 13766 .cmd = NL80211_CMD_NEW_KEY, 13767 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13768 .doit = nl80211_new_key, 13769 .flags = GENL_UNS_ADMIN_PERM, 13770 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13771 NL80211_FLAG_NEED_RTNL | 13772 NL80211_FLAG_CLEAR_SKB, 13773 }, 13774 { 13775 .cmd = NL80211_CMD_DEL_KEY, 13776 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13777 .doit = nl80211_del_key, 13778 .flags = GENL_UNS_ADMIN_PERM, 13779 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13780 NL80211_FLAG_NEED_RTNL, 13781 }, 13782 { 13783 .cmd = NL80211_CMD_SET_BEACON, 13784 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13785 .flags = GENL_UNS_ADMIN_PERM, 13786 .doit = nl80211_set_beacon, 13787 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13788 NL80211_FLAG_NEED_RTNL, 13789 }, 13790 { 13791 .cmd = NL80211_CMD_START_AP, 13792 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13793 .flags = GENL_UNS_ADMIN_PERM, 13794 .doit = nl80211_start_ap, 13795 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13796 NL80211_FLAG_NEED_RTNL, 13797 }, 13798 { 13799 .cmd = NL80211_CMD_STOP_AP, 13800 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13801 .flags = GENL_UNS_ADMIN_PERM, 13802 .doit = nl80211_stop_ap, 13803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13804 NL80211_FLAG_NEED_RTNL, 13805 }, 13806 { 13807 .cmd = NL80211_CMD_GET_STATION, 13808 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13809 .doit = nl80211_get_station, 13810 .dumpit = nl80211_dump_station, 13811 .internal_flags = NL80211_FLAG_NEED_NETDEV | 13812 NL80211_FLAG_NEED_RTNL, 13813 }, 13814 { 13815 .cmd = NL80211_CMD_SET_STATION, 13816 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13817 .doit = nl80211_set_station, 13818 .flags = GENL_UNS_ADMIN_PERM, 13819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13820 NL80211_FLAG_NEED_RTNL, 13821 }, 13822 { 13823 .cmd = NL80211_CMD_NEW_STATION, 13824 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13825 .doit = nl80211_new_station, 13826 .flags = GENL_UNS_ADMIN_PERM, 13827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13828 NL80211_FLAG_NEED_RTNL, 13829 }, 13830 { 13831 .cmd = NL80211_CMD_DEL_STATION, 13832 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13833 .doit = nl80211_del_station, 13834 .flags = GENL_UNS_ADMIN_PERM, 13835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13836 NL80211_FLAG_NEED_RTNL, 13837 }, 13838 { 13839 .cmd = NL80211_CMD_GET_MPATH, 13840 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13841 .doit = nl80211_get_mpath, 13842 .dumpit = nl80211_dump_mpath, 13843 .flags = GENL_UNS_ADMIN_PERM, 13844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13845 NL80211_FLAG_NEED_RTNL, 13846 }, 13847 { 13848 .cmd = NL80211_CMD_GET_MPP, 13849 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13850 .doit = nl80211_get_mpp, 13851 .dumpit = nl80211_dump_mpp, 13852 .flags = GENL_UNS_ADMIN_PERM, 13853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13854 NL80211_FLAG_NEED_RTNL, 13855 }, 13856 { 13857 .cmd = NL80211_CMD_SET_MPATH, 13858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13859 .doit = nl80211_set_mpath, 13860 .flags = GENL_UNS_ADMIN_PERM, 13861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13862 NL80211_FLAG_NEED_RTNL, 13863 }, 13864 { 13865 .cmd = NL80211_CMD_NEW_MPATH, 13866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13867 .doit = nl80211_new_mpath, 13868 .flags = GENL_UNS_ADMIN_PERM, 13869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13870 NL80211_FLAG_NEED_RTNL, 13871 }, 13872 { 13873 .cmd = NL80211_CMD_DEL_MPATH, 13874 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13875 .doit = nl80211_del_mpath, 13876 .flags = GENL_UNS_ADMIN_PERM, 13877 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13878 NL80211_FLAG_NEED_RTNL, 13879 }, 13880 { 13881 .cmd = NL80211_CMD_SET_BSS, 13882 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13883 .doit = nl80211_set_bss, 13884 .flags = GENL_UNS_ADMIN_PERM, 13885 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13886 NL80211_FLAG_NEED_RTNL, 13887 }, 13888 { 13889 .cmd = NL80211_CMD_GET_REG, 13890 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13891 .doit = nl80211_get_reg_do, 13892 .dumpit = nl80211_get_reg_dump, 13893 .internal_flags = NL80211_FLAG_NEED_RTNL, 13894 /* can be retrieved by unprivileged users */ 13895 }, 13896 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 13897 { 13898 .cmd = NL80211_CMD_SET_REG, 13899 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13900 .doit = nl80211_set_reg, 13901 .flags = GENL_ADMIN_PERM, 13902 .internal_flags = NL80211_FLAG_NEED_RTNL, 13903 }, 13904 #endif 13905 { 13906 .cmd = NL80211_CMD_REQ_SET_REG, 13907 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13908 .doit = nl80211_req_set_reg, 13909 .flags = GENL_ADMIN_PERM, 13910 }, 13911 { 13912 .cmd = NL80211_CMD_RELOAD_REGDB, 13913 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13914 .doit = nl80211_reload_regdb, 13915 .flags = GENL_ADMIN_PERM, 13916 }, 13917 { 13918 .cmd = NL80211_CMD_GET_MESH_CONFIG, 13919 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13920 .doit = nl80211_get_mesh_config, 13921 /* can be retrieved by unprivileged users */ 13922 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13923 NL80211_FLAG_NEED_RTNL, 13924 }, 13925 { 13926 .cmd = NL80211_CMD_SET_MESH_CONFIG, 13927 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13928 .doit = nl80211_update_mesh_config, 13929 .flags = GENL_UNS_ADMIN_PERM, 13930 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13931 NL80211_FLAG_NEED_RTNL, 13932 }, 13933 { 13934 .cmd = NL80211_CMD_TRIGGER_SCAN, 13935 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13936 .doit = nl80211_trigger_scan, 13937 .flags = GENL_UNS_ADMIN_PERM, 13938 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 13939 NL80211_FLAG_NEED_RTNL, 13940 }, 13941 { 13942 .cmd = NL80211_CMD_ABORT_SCAN, 13943 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13944 .doit = nl80211_abort_scan, 13945 .flags = GENL_UNS_ADMIN_PERM, 13946 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 13947 NL80211_FLAG_NEED_RTNL, 13948 }, 13949 { 13950 .cmd = NL80211_CMD_GET_SCAN, 13951 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13952 .dumpit = nl80211_dump_scan, 13953 }, 13954 { 13955 .cmd = NL80211_CMD_START_SCHED_SCAN, 13956 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13957 .doit = nl80211_start_sched_scan, 13958 .flags = GENL_UNS_ADMIN_PERM, 13959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13960 NL80211_FLAG_NEED_RTNL, 13961 }, 13962 { 13963 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 13964 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13965 .doit = nl80211_stop_sched_scan, 13966 .flags = GENL_UNS_ADMIN_PERM, 13967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13968 NL80211_FLAG_NEED_RTNL, 13969 }, 13970 { 13971 .cmd = NL80211_CMD_AUTHENTICATE, 13972 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13973 .doit = nl80211_authenticate, 13974 .flags = GENL_UNS_ADMIN_PERM, 13975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13976 NL80211_FLAG_NEED_RTNL | 13977 NL80211_FLAG_CLEAR_SKB, 13978 }, 13979 { 13980 .cmd = NL80211_CMD_ASSOCIATE, 13981 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13982 .doit = nl80211_associate, 13983 .flags = GENL_UNS_ADMIN_PERM, 13984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13985 NL80211_FLAG_NEED_RTNL | 13986 NL80211_FLAG_CLEAR_SKB, 13987 }, 13988 { 13989 .cmd = NL80211_CMD_DEAUTHENTICATE, 13990 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13991 .doit = nl80211_deauthenticate, 13992 .flags = GENL_UNS_ADMIN_PERM, 13993 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13994 NL80211_FLAG_NEED_RTNL, 13995 }, 13996 { 13997 .cmd = NL80211_CMD_DISASSOCIATE, 13998 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 13999 .doit = nl80211_disassociate, 14000 .flags = GENL_UNS_ADMIN_PERM, 14001 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14002 NL80211_FLAG_NEED_RTNL, 14003 }, 14004 { 14005 .cmd = NL80211_CMD_JOIN_IBSS, 14006 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14007 .doit = nl80211_join_ibss, 14008 .flags = GENL_UNS_ADMIN_PERM, 14009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14010 NL80211_FLAG_NEED_RTNL, 14011 }, 14012 { 14013 .cmd = NL80211_CMD_LEAVE_IBSS, 14014 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14015 .doit = nl80211_leave_ibss, 14016 .flags = GENL_UNS_ADMIN_PERM, 14017 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14018 NL80211_FLAG_NEED_RTNL, 14019 }, 14020 #ifdef CONFIG_NL80211_TESTMODE 14021 { 14022 .cmd = NL80211_CMD_TESTMODE, 14023 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14024 .doit = nl80211_testmode_do, 14025 .dumpit = nl80211_testmode_dump, 14026 .flags = GENL_UNS_ADMIN_PERM, 14027 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14028 NL80211_FLAG_NEED_RTNL, 14029 }, 14030 #endif 14031 { 14032 .cmd = NL80211_CMD_CONNECT, 14033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14034 .doit = nl80211_connect, 14035 .flags = GENL_UNS_ADMIN_PERM, 14036 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14037 NL80211_FLAG_NEED_RTNL | 14038 NL80211_FLAG_CLEAR_SKB, 14039 }, 14040 { 14041 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 14042 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14043 .doit = nl80211_update_connect_params, 14044 .flags = GENL_ADMIN_PERM, 14045 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14046 NL80211_FLAG_NEED_RTNL | 14047 NL80211_FLAG_CLEAR_SKB, 14048 }, 14049 { 14050 .cmd = NL80211_CMD_DISCONNECT, 14051 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14052 .doit = nl80211_disconnect, 14053 .flags = GENL_UNS_ADMIN_PERM, 14054 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14055 NL80211_FLAG_NEED_RTNL, 14056 }, 14057 { 14058 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 14059 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14060 .doit = nl80211_wiphy_netns, 14061 .flags = GENL_UNS_ADMIN_PERM, 14062 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14063 NL80211_FLAG_NEED_RTNL, 14064 }, 14065 { 14066 .cmd = NL80211_CMD_GET_SURVEY, 14067 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14068 .dumpit = nl80211_dump_survey, 14069 }, 14070 { 14071 .cmd = NL80211_CMD_SET_PMKSA, 14072 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14073 .doit = nl80211_setdel_pmksa, 14074 .flags = GENL_UNS_ADMIN_PERM, 14075 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14076 NL80211_FLAG_NEED_RTNL | 14077 NL80211_FLAG_CLEAR_SKB, 14078 }, 14079 { 14080 .cmd = NL80211_CMD_DEL_PMKSA, 14081 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14082 .doit = nl80211_setdel_pmksa, 14083 .flags = GENL_UNS_ADMIN_PERM, 14084 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14085 NL80211_FLAG_NEED_RTNL, 14086 }, 14087 { 14088 .cmd = NL80211_CMD_FLUSH_PMKSA, 14089 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14090 .doit = nl80211_flush_pmksa, 14091 .flags = GENL_UNS_ADMIN_PERM, 14092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14093 NL80211_FLAG_NEED_RTNL, 14094 }, 14095 { 14096 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 14097 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14098 .doit = nl80211_remain_on_channel, 14099 .flags = GENL_UNS_ADMIN_PERM, 14100 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14101 NL80211_FLAG_NEED_RTNL, 14102 }, 14103 { 14104 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 14105 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14106 .doit = nl80211_cancel_remain_on_channel, 14107 .flags = GENL_UNS_ADMIN_PERM, 14108 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14109 NL80211_FLAG_NEED_RTNL, 14110 }, 14111 { 14112 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 14113 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14114 .doit = nl80211_set_tx_bitrate_mask, 14115 .flags = GENL_UNS_ADMIN_PERM, 14116 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14117 NL80211_FLAG_NEED_RTNL, 14118 }, 14119 { 14120 .cmd = NL80211_CMD_REGISTER_FRAME, 14121 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14122 .doit = nl80211_register_mgmt, 14123 .flags = GENL_UNS_ADMIN_PERM, 14124 .internal_flags = NL80211_FLAG_NEED_WDEV | 14125 NL80211_FLAG_NEED_RTNL, 14126 }, 14127 { 14128 .cmd = NL80211_CMD_FRAME, 14129 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14130 .doit = nl80211_tx_mgmt, 14131 .flags = GENL_UNS_ADMIN_PERM, 14132 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14133 NL80211_FLAG_NEED_RTNL, 14134 }, 14135 { 14136 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 14137 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14138 .doit = nl80211_tx_mgmt_cancel_wait, 14139 .flags = GENL_UNS_ADMIN_PERM, 14140 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14141 NL80211_FLAG_NEED_RTNL, 14142 }, 14143 { 14144 .cmd = NL80211_CMD_SET_POWER_SAVE, 14145 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14146 .doit = nl80211_set_power_save, 14147 .flags = GENL_UNS_ADMIN_PERM, 14148 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14149 NL80211_FLAG_NEED_RTNL, 14150 }, 14151 { 14152 .cmd = NL80211_CMD_GET_POWER_SAVE, 14153 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14154 .doit = nl80211_get_power_save, 14155 /* can be retrieved by unprivileged users */ 14156 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14157 NL80211_FLAG_NEED_RTNL, 14158 }, 14159 { 14160 .cmd = NL80211_CMD_SET_CQM, 14161 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14162 .doit = nl80211_set_cqm, 14163 .flags = GENL_UNS_ADMIN_PERM, 14164 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14165 NL80211_FLAG_NEED_RTNL, 14166 }, 14167 { 14168 .cmd = NL80211_CMD_SET_CHANNEL, 14169 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14170 .doit = nl80211_set_channel, 14171 .flags = GENL_UNS_ADMIN_PERM, 14172 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14173 NL80211_FLAG_NEED_RTNL, 14174 }, 14175 { 14176 .cmd = NL80211_CMD_SET_WDS_PEER, 14177 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14178 .doit = nl80211_set_wds_peer, 14179 .flags = GENL_UNS_ADMIN_PERM, 14180 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14181 NL80211_FLAG_NEED_RTNL, 14182 }, 14183 { 14184 .cmd = NL80211_CMD_JOIN_MESH, 14185 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14186 .doit = nl80211_join_mesh, 14187 .flags = GENL_UNS_ADMIN_PERM, 14188 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14189 NL80211_FLAG_NEED_RTNL, 14190 }, 14191 { 14192 .cmd = NL80211_CMD_LEAVE_MESH, 14193 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14194 .doit = nl80211_leave_mesh, 14195 .flags = GENL_UNS_ADMIN_PERM, 14196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14197 NL80211_FLAG_NEED_RTNL, 14198 }, 14199 { 14200 .cmd = NL80211_CMD_JOIN_OCB, 14201 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14202 .doit = nl80211_join_ocb, 14203 .flags = GENL_UNS_ADMIN_PERM, 14204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14205 NL80211_FLAG_NEED_RTNL, 14206 }, 14207 { 14208 .cmd = NL80211_CMD_LEAVE_OCB, 14209 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14210 .doit = nl80211_leave_ocb, 14211 .flags = GENL_UNS_ADMIN_PERM, 14212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14213 NL80211_FLAG_NEED_RTNL, 14214 }, 14215 #ifdef CONFIG_PM 14216 { 14217 .cmd = NL80211_CMD_GET_WOWLAN, 14218 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14219 .doit = nl80211_get_wowlan, 14220 /* can be retrieved by unprivileged users */ 14221 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14222 NL80211_FLAG_NEED_RTNL, 14223 }, 14224 { 14225 .cmd = NL80211_CMD_SET_WOWLAN, 14226 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14227 .doit = nl80211_set_wowlan, 14228 .flags = GENL_UNS_ADMIN_PERM, 14229 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14230 NL80211_FLAG_NEED_RTNL, 14231 }, 14232 #endif 14233 { 14234 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 14235 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14236 .doit = nl80211_set_rekey_data, 14237 .flags = GENL_UNS_ADMIN_PERM, 14238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14239 NL80211_FLAG_NEED_RTNL | 14240 NL80211_FLAG_CLEAR_SKB, 14241 }, 14242 { 14243 .cmd = NL80211_CMD_TDLS_MGMT, 14244 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14245 .doit = nl80211_tdls_mgmt, 14246 .flags = GENL_UNS_ADMIN_PERM, 14247 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14248 NL80211_FLAG_NEED_RTNL, 14249 }, 14250 { 14251 .cmd = NL80211_CMD_TDLS_OPER, 14252 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14253 .doit = nl80211_tdls_oper, 14254 .flags = GENL_UNS_ADMIN_PERM, 14255 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14256 NL80211_FLAG_NEED_RTNL, 14257 }, 14258 { 14259 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 14260 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14261 .doit = nl80211_register_unexpected_frame, 14262 .flags = GENL_UNS_ADMIN_PERM, 14263 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14264 NL80211_FLAG_NEED_RTNL, 14265 }, 14266 { 14267 .cmd = NL80211_CMD_PROBE_CLIENT, 14268 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14269 .doit = nl80211_probe_client, 14270 .flags = GENL_UNS_ADMIN_PERM, 14271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14272 NL80211_FLAG_NEED_RTNL, 14273 }, 14274 { 14275 .cmd = NL80211_CMD_REGISTER_BEACONS, 14276 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14277 .doit = nl80211_register_beacons, 14278 .flags = GENL_UNS_ADMIN_PERM, 14279 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14280 NL80211_FLAG_NEED_RTNL, 14281 }, 14282 { 14283 .cmd = NL80211_CMD_SET_NOACK_MAP, 14284 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14285 .doit = nl80211_set_noack_map, 14286 .flags = GENL_UNS_ADMIN_PERM, 14287 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14288 NL80211_FLAG_NEED_RTNL, 14289 }, 14290 { 14291 .cmd = NL80211_CMD_START_P2P_DEVICE, 14292 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14293 .doit = nl80211_start_p2p_device, 14294 .flags = GENL_UNS_ADMIN_PERM, 14295 .internal_flags = NL80211_FLAG_NEED_WDEV | 14296 NL80211_FLAG_NEED_RTNL, 14297 }, 14298 { 14299 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 14300 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14301 .doit = nl80211_stop_p2p_device, 14302 .flags = GENL_UNS_ADMIN_PERM, 14303 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14304 NL80211_FLAG_NEED_RTNL, 14305 }, 14306 { 14307 .cmd = NL80211_CMD_START_NAN, 14308 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14309 .doit = nl80211_start_nan, 14310 .flags = GENL_ADMIN_PERM, 14311 .internal_flags = NL80211_FLAG_NEED_WDEV | 14312 NL80211_FLAG_NEED_RTNL, 14313 }, 14314 { 14315 .cmd = NL80211_CMD_STOP_NAN, 14316 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14317 .doit = nl80211_stop_nan, 14318 .flags = GENL_ADMIN_PERM, 14319 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14320 NL80211_FLAG_NEED_RTNL, 14321 }, 14322 { 14323 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 14324 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14325 .doit = nl80211_nan_add_func, 14326 .flags = GENL_ADMIN_PERM, 14327 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14328 NL80211_FLAG_NEED_RTNL, 14329 }, 14330 { 14331 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 14332 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14333 .doit = nl80211_nan_del_func, 14334 .flags = GENL_ADMIN_PERM, 14335 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14336 NL80211_FLAG_NEED_RTNL, 14337 }, 14338 { 14339 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 14340 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14341 .doit = nl80211_nan_change_config, 14342 .flags = GENL_ADMIN_PERM, 14343 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14344 NL80211_FLAG_NEED_RTNL, 14345 }, 14346 { 14347 .cmd = NL80211_CMD_SET_MCAST_RATE, 14348 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14349 .doit = nl80211_set_mcast_rate, 14350 .flags = GENL_UNS_ADMIN_PERM, 14351 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14352 NL80211_FLAG_NEED_RTNL, 14353 }, 14354 { 14355 .cmd = NL80211_CMD_SET_MAC_ACL, 14356 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14357 .doit = nl80211_set_mac_acl, 14358 .flags = GENL_UNS_ADMIN_PERM, 14359 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14360 NL80211_FLAG_NEED_RTNL, 14361 }, 14362 { 14363 .cmd = NL80211_CMD_RADAR_DETECT, 14364 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14365 .doit = nl80211_start_radar_detection, 14366 .flags = GENL_UNS_ADMIN_PERM, 14367 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14368 NL80211_FLAG_NEED_RTNL, 14369 }, 14370 { 14371 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 14372 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14373 .doit = nl80211_get_protocol_features, 14374 }, 14375 { 14376 .cmd = NL80211_CMD_UPDATE_FT_IES, 14377 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14378 .doit = nl80211_update_ft_ies, 14379 .flags = GENL_UNS_ADMIN_PERM, 14380 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14381 NL80211_FLAG_NEED_RTNL, 14382 }, 14383 { 14384 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 14385 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14386 .doit = nl80211_crit_protocol_start, 14387 .flags = GENL_UNS_ADMIN_PERM, 14388 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14389 NL80211_FLAG_NEED_RTNL, 14390 }, 14391 { 14392 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 14393 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14394 .doit = nl80211_crit_protocol_stop, 14395 .flags = GENL_UNS_ADMIN_PERM, 14396 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14397 NL80211_FLAG_NEED_RTNL, 14398 }, 14399 { 14400 .cmd = NL80211_CMD_GET_COALESCE, 14401 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14402 .doit = nl80211_get_coalesce, 14403 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14404 NL80211_FLAG_NEED_RTNL, 14405 }, 14406 { 14407 .cmd = NL80211_CMD_SET_COALESCE, 14408 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14409 .doit = nl80211_set_coalesce, 14410 .flags = GENL_UNS_ADMIN_PERM, 14411 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14412 NL80211_FLAG_NEED_RTNL, 14413 }, 14414 { 14415 .cmd = NL80211_CMD_CHANNEL_SWITCH, 14416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14417 .doit = nl80211_channel_switch, 14418 .flags = GENL_UNS_ADMIN_PERM, 14419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14420 NL80211_FLAG_NEED_RTNL, 14421 }, 14422 { 14423 .cmd = NL80211_CMD_VENDOR, 14424 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14425 .doit = nl80211_vendor_cmd, 14426 .dumpit = nl80211_vendor_cmd_dump, 14427 .flags = GENL_UNS_ADMIN_PERM, 14428 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14429 NL80211_FLAG_NEED_RTNL | 14430 NL80211_FLAG_CLEAR_SKB, 14431 }, 14432 { 14433 .cmd = NL80211_CMD_SET_QOS_MAP, 14434 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14435 .doit = nl80211_set_qos_map, 14436 .flags = GENL_UNS_ADMIN_PERM, 14437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14438 NL80211_FLAG_NEED_RTNL, 14439 }, 14440 { 14441 .cmd = NL80211_CMD_ADD_TX_TS, 14442 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14443 .doit = nl80211_add_tx_ts, 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_DEL_TX_TS, 14450 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14451 .doit = nl80211_del_tx_ts, 14452 .flags = GENL_UNS_ADMIN_PERM, 14453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14454 NL80211_FLAG_NEED_RTNL, 14455 }, 14456 { 14457 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 14458 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14459 .doit = nl80211_tdls_channel_switch, 14460 .flags = GENL_UNS_ADMIN_PERM, 14461 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14462 NL80211_FLAG_NEED_RTNL, 14463 }, 14464 { 14465 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 14466 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14467 .doit = nl80211_tdls_cancel_channel_switch, 14468 .flags = GENL_UNS_ADMIN_PERM, 14469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14470 NL80211_FLAG_NEED_RTNL, 14471 }, 14472 { 14473 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 14474 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14475 .doit = nl80211_set_multicast_to_unicast, 14476 .flags = GENL_UNS_ADMIN_PERM, 14477 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14478 NL80211_FLAG_NEED_RTNL, 14479 }, 14480 { 14481 .cmd = NL80211_CMD_SET_PMK, 14482 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14483 .doit = nl80211_set_pmk, 14484 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14485 NL80211_FLAG_NEED_RTNL | 14486 NL80211_FLAG_CLEAR_SKB, 14487 }, 14488 { 14489 .cmd = NL80211_CMD_DEL_PMK, 14490 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14491 .doit = nl80211_del_pmk, 14492 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14493 NL80211_FLAG_NEED_RTNL, 14494 }, 14495 { 14496 .cmd = NL80211_CMD_EXTERNAL_AUTH, 14497 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14498 .doit = nl80211_external_auth, 14499 .flags = GENL_ADMIN_PERM, 14500 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14501 NL80211_FLAG_NEED_RTNL, 14502 }, 14503 { 14504 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 14505 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14506 .doit = nl80211_tx_control_port, 14507 .flags = GENL_UNS_ADMIN_PERM, 14508 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14509 NL80211_FLAG_NEED_RTNL, 14510 }, 14511 { 14512 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 14513 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14514 .doit = nl80211_get_ftm_responder_stats, 14515 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14516 NL80211_FLAG_NEED_RTNL, 14517 }, 14518 { 14519 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 14520 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14521 .doit = nl80211_pmsr_start, 14522 .flags = GENL_UNS_ADMIN_PERM, 14523 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14524 NL80211_FLAG_NEED_RTNL, 14525 }, 14526 { 14527 .cmd = NL80211_CMD_NOTIFY_RADAR, 14528 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 14529 .doit = nl80211_notify_radar_detection, 14530 .flags = GENL_UNS_ADMIN_PERM, 14531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14532 NL80211_FLAG_NEED_RTNL, 14533 }, 14534 { 14535 .cmd = NL80211_CMD_UPDATE_OWE_INFO, 14536 .doit = nl80211_update_owe_info, 14537 .flags = GENL_ADMIN_PERM, 14538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14539 NL80211_FLAG_NEED_RTNL, 14540 }, 14541 { 14542 .cmd = NL80211_CMD_PROBE_MESH_LINK, 14543 .doit = nl80211_probe_mesh_link, 14544 .flags = GENL_UNS_ADMIN_PERM, 14545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14546 NL80211_FLAG_NEED_RTNL, 14547 }, 14548 }; 14549 14550 static struct genl_family nl80211_fam __ro_after_init = { 14551 .name = NL80211_GENL_NAME, /* have users key off the name instead */ 14552 .hdrsize = 0, /* no private header */ 14553 .version = 1, /* no particular meaning now */ 14554 .maxattr = NL80211_ATTR_MAX, 14555 .policy = nl80211_policy, 14556 .netnsok = true, 14557 .pre_doit = nl80211_pre_doit, 14558 .post_doit = nl80211_post_doit, 14559 .module = THIS_MODULE, 14560 .ops = nl80211_ops, 14561 .n_ops = ARRAY_SIZE(nl80211_ops), 14562 .mcgrps = nl80211_mcgrps, 14563 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), 14564 }; 14565 14566 /* notification functions */ 14567 14568 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, 14569 enum nl80211_commands cmd) 14570 { 14571 struct sk_buff *msg; 14572 struct nl80211_dump_wiphy_state state = {}; 14573 14574 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && 14575 cmd != NL80211_CMD_DEL_WIPHY); 14576 14577 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14578 if (!msg) 14579 return; 14580 14581 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { 14582 nlmsg_free(msg); 14583 return; 14584 } 14585 14586 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 14587 NL80211_MCGRP_CONFIG, GFP_KERNEL); 14588 } 14589 14590 void nl80211_notify_iface(struct cfg80211_registered_device *rdev, 14591 struct wireless_dev *wdev, 14592 enum nl80211_commands cmd) 14593 { 14594 struct sk_buff *msg; 14595 14596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14597 if (!msg) 14598 return; 14599 14600 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { 14601 nlmsg_free(msg); 14602 return; 14603 } 14604 14605 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 14606 NL80211_MCGRP_CONFIG, GFP_KERNEL); 14607 } 14608 14609 static int nl80211_add_scan_req(struct sk_buff *msg, 14610 struct cfg80211_registered_device *rdev) 14611 { 14612 struct cfg80211_scan_request *req = rdev->scan_req; 14613 struct nlattr *nest; 14614 int i; 14615 14616 if (WARN_ON(!req)) 14617 return 0; 14618 14619 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); 14620 if (!nest) 14621 goto nla_put_failure; 14622 for (i = 0; i < req->n_ssids; i++) { 14623 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 14624 goto nla_put_failure; 14625 } 14626 nla_nest_end(msg, nest); 14627 14628 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 14629 if (!nest) 14630 goto nla_put_failure; 14631 for (i = 0; i < req->n_channels; i++) { 14632 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 14633 goto nla_put_failure; 14634 } 14635 nla_nest_end(msg, nest); 14636 14637 if (req->ie && 14638 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) 14639 goto nla_put_failure; 14640 14641 if (req->flags && 14642 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) 14643 goto nla_put_failure; 14644 14645 if (req->info.scan_start_tsf && 14646 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, 14647 req->info.scan_start_tsf, NL80211_BSS_PAD) || 14648 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, 14649 req->info.tsf_bssid))) 14650 goto nla_put_failure; 14651 14652 return 0; 14653 nla_put_failure: 14654 return -ENOBUFS; 14655 } 14656 14657 static int nl80211_prep_scan_msg(struct sk_buff *msg, 14658 struct cfg80211_registered_device *rdev, 14659 struct wireless_dev *wdev, 14660 u32 portid, u32 seq, int flags, 14661 u32 cmd) 14662 { 14663 void *hdr; 14664 14665 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 14666 if (!hdr) 14667 return -1; 14668 14669 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14670 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14671 wdev->netdev->ifindex)) || 14672 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14673 NL80211_ATTR_PAD)) 14674 goto nla_put_failure; 14675 14676 /* ignore errors and send incomplete event anyway */ 14677 nl80211_add_scan_req(msg, rdev); 14678 14679 genlmsg_end(msg, hdr); 14680 return 0; 14681 14682 nla_put_failure: 14683 genlmsg_cancel(msg, hdr); 14684 return -EMSGSIZE; 14685 } 14686 14687 static int 14688 nl80211_prep_sched_scan_msg(struct sk_buff *msg, 14689 struct cfg80211_sched_scan_request *req, u32 cmd) 14690 { 14691 void *hdr; 14692 14693 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 14694 if (!hdr) 14695 return -1; 14696 14697 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, 14698 wiphy_to_rdev(req->wiphy)->wiphy_idx) || 14699 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || 14700 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, 14701 NL80211_ATTR_PAD)) 14702 goto nla_put_failure; 14703 14704 genlmsg_end(msg, hdr); 14705 return 0; 14706 14707 nla_put_failure: 14708 genlmsg_cancel(msg, hdr); 14709 return -EMSGSIZE; 14710 } 14711 14712 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 14713 struct wireless_dev *wdev) 14714 { 14715 struct sk_buff *msg; 14716 14717 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14718 if (!msg) 14719 return; 14720 14721 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 14722 NL80211_CMD_TRIGGER_SCAN) < 0) { 14723 nlmsg_free(msg); 14724 return; 14725 } 14726 14727 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 14728 NL80211_MCGRP_SCAN, GFP_KERNEL); 14729 } 14730 14731 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 14732 struct wireless_dev *wdev, bool aborted) 14733 { 14734 struct sk_buff *msg; 14735 14736 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14737 if (!msg) 14738 return NULL; 14739 14740 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 14741 aborted ? NL80211_CMD_SCAN_ABORTED : 14742 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 14743 nlmsg_free(msg); 14744 return NULL; 14745 } 14746 14747 return msg; 14748 } 14749 14750 /* send message created by nl80211_build_scan_msg() */ 14751 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, 14752 struct sk_buff *msg) 14753 { 14754 if (!msg) 14755 return; 14756 14757 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 14758 NL80211_MCGRP_SCAN, GFP_KERNEL); 14759 } 14760 14761 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) 14762 { 14763 struct sk_buff *msg; 14764 14765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14766 if (!msg) 14767 return; 14768 14769 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { 14770 nlmsg_free(msg); 14771 return; 14772 } 14773 14774 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, 14775 NL80211_MCGRP_SCAN, GFP_KERNEL); 14776 } 14777 14778 static bool nl80211_reg_change_event_fill(struct sk_buff *msg, 14779 struct regulatory_request *request) 14780 { 14781 /* Userspace can always count this one always being set */ 14782 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) 14783 goto nla_put_failure; 14784 14785 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { 14786 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 14787 NL80211_REGDOM_TYPE_WORLD)) 14788 goto nla_put_failure; 14789 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { 14790 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 14791 NL80211_REGDOM_TYPE_CUSTOM_WORLD)) 14792 goto nla_put_failure; 14793 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || 14794 request->intersect) { 14795 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 14796 NL80211_REGDOM_TYPE_INTERSECTION)) 14797 goto nla_put_failure; 14798 } else { 14799 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 14800 NL80211_REGDOM_TYPE_COUNTRY) || 14801 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, 14802 request->alpha2)) 14803 goto nla_put_failure; 14804 } 14805 14806 if (request->wiphy_idx != WIPHY_IDX_INVALID) { 14807 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); 14808 14809 if (wiphy && 14810 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 14811 goto nla_put_failure; 14812 14813 if (wiphy && 14814 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 14815 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 14816 goto nla_put_failure; 14817 } 14818 14819 return true; 14820 14821 nla_put_failure: 14822 return false; 14823 } 14824 14825 /* 14826 * This can happen on global regulatory changes or device specific settings 14827 * based on custom regulatory domains. 14828 */ 14829 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, 14830 struct regulatory_request *request) 14831 { 14832 struct sk_buff *msg; 14833 void *hdr; 14834 14835 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14836 if (!msg) 14837 return; 14838 14839 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); 14840 if (!hdr) { 14841 nlmsg_free(msg); 14842 return; 14843 } 14844 14845 if (nl80211_reg_change_event_fill(msg, request) == false) 14846 goto nla_put_failure; 14847 14848 genlmsg_end(msg, hdr); 14849 14850 rcu_read_lock(); 14851 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 14852 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 14853 rcu_read_unlock(); 14854 14855 return; 14856 14857 nla_put_failure: 14858 nlmsg_free(msg); 14859 } 14860 14861 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 14862 struct net_device *netdev, 14863 const u8 *buf, size_t len, 14864 enum nl80211_commands cmd, gfp_t gfp, 14865 int uapsd_queues, const u8 *req_ies, 14866 size_t req_ies_len) 14867 { 14868 struct sk_buff *msg; 14869 void *hdr; 14870 14871 msg = nlmsg_new(100 + len + req_ies_len, gfp); 14872 if (!msg) 14873 return; 14874 14875 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 14876 if (!hdr) { 14877 nlmsg_free(msg); 14878 return; 14879 } 14880 14881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 14883 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 14884 (req_ies && 14885 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) 14886 goto nla_put_failure; 14887 14888 if (uapsd_queues >= 0) { 14889 struct nlattr *nla_wmm = 14890 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); 14891 if (!nla_wmm) 14892 goto nla_put_failure; 14893 14894 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, 14895 uapsd_queues)) 14896 goto nla_put_failure; 14897 14898 nla_nest_end(msg, nla_wmm); 14899 } 14900 14901 genlmsg_end(msg, hdr); 14902 14903 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 14904 NL80211_MCGRP_MLME, gfp); 14905 return; 14906 14907 nla_put_failure: 14908 nlmsg_free(msg); 14909 } 14910 14911 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 14912 struct net_device *netdev, const u8 *buf, 14913 size_t len, gfp_t gfp) 14914 { 14915 nl80211_send_mlme_event(rdev, netdev, buf, len, 14916 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); 14917 } 14918 14919 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 14920 struct net_device *netdev, const u8 *buf, 14921 size_t len, gfp_t gfp, int uapsd_queues, 14922 const u8 *req_ies, size_t req_ies_len) 14923 { 14924 nl80211_send_mlme_event(rdev, netdev, buf, len, 14925 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, 14926 req_ies, req_ies_len); 14927 } 14928 14929 void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 14930 struct net_device *netdev, const u8 *buf, 14931 size_t len, gfp_t gfp) 14932 { 14933 nl80211_send_mlme_event(rdev, netdev, buf, len, 14934 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); 14935 } 14936 14937 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 14938 struct net_device *netdev, const u8 *buf, 14939 size_t len, gfp_t gfp) 14940 { 14941 nl80211_send_mlme_event(rdev, netdev, buf, len, 14942 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); 14943 } 14944 14945 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, 14946 size_t len) 14947 { 14948 struct wireless_dev *wdev = dev->ieee80211_ptr; 14949 struct wiphy *wiphy = wdev->wiphy; 14950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14951 const struct ieee80211_mgmt *mgmt = (void *)buf; 14952 u32 cmd; 14953 14954 if (WARN_ON(len < 2)) 14955 return; 14956 14957 if (ieee80211_is_deauth(mgmt->frame_control)) 14958 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; 14959 else 14960 cmd = NL80211_CMD_UNPROT_DISASSOCIATE; 14961 14962 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); 14963 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, 14964 NULL, 0); 14965 } 14966 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); 14967 14968 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 14969 struct net_device *netdev, int cmd, 14970 const u8 *addr, gfp_t gfp) 14971 { 14972 struct sk_buff *msg; 14973 void *hdr; 14974 14975 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14976 if (!msg) 14977 return; 14978 14979 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 14980 if (!hdr) { 14981 nlmsg_free(msg); 14982 return; 14983 } 14984 14985 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14986 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 14987 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 14988 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 14989 goto nla_put_failure; 14990 14991 genlmsg_end(msg, hdr); 14992 14993 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 14994 NL80211_MCGRP_MLME, gfp); 14995 return; 14996 14997 nla_put_failure: 14998 nlmsg_free(msg); 14999 } 15000 15001 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 15002 struct net_device *netdev, const u8 *addr, 15003 gfp_t gfp) 15004 { 15005 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 15006 addr, gfp); 15007 } 15008 15009 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 15010 struct net_device *netdev, const u8 *addr, 15011 gfp_t gfp) 15012 { 15013 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, 15014 addr, gfp); 15015 } 15016 15017 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, 15018 struct net_device *netdev, 15019 struct cfg80211_connect_resp_params *cr, 15020 gfp_t gfp) 15021 { 15022 struct sk_buff *msg; 15023 void *hdr; 15024 15025 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + 15026 cr->fils.kek_len + cr->fils.pmk_len + 15027 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); 15028 if (!msg) 15029 return; 15030 15031 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); 15032 if (!hdr) { 15033 nlmsg_free(msg); 15034 return; 15035 } 15036 15037 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15038 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15039 (cr->bssid && 15040 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || 15041 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 15042 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : 15043 cr->status) || 15044 (cr->status < 0 && 15045 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 15046 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, 15047 cr->timeout_reason))) || 15048 (cr->req_ie && 15049 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || 15050 (cr->resp_ie && 15051 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, 15052 cr->resp_ie)) || 15053 (cr->fils.update_erp_next_seq_num && 15054 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 15055 cr->fils.erp_next_seq_num)) || 15056 (cr->status == WLAN_STATUS_SUCCESS && 15057 ((cr->fils.kek && 15058 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, 15059 cr->fils.kek)) || 15060 (cr->fils.pmk && 15061 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || 15062 (cr->fils.pmkid && 15063 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) 15064 goto nla_put_failure; 15065 15066 genlmsg_end(msg, hdr); 15067 15068 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15069 NL80211_MCGRP_MLME, gfp); 15070 return; 15071 15072 nla_put_failure: 15073 nlmsg_free(msg); 15074 } 15075 15076 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 15077 struct net_device *netdev, 15078 struct cfg80211_roam_info *info, gfp_t gfp) 15079 { 15080 struct sk_buff *msg; 15081 void *hdr; 15082 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; 15083 15084 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + 15085 info->fils.kek_len + info->fils.pmk_len + 15086 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); 15087 if (!msg) 15088 return; 15089 15090 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); 15091 if (!hdr) { 15092 nlmsg_free(msg); 15093 return; 15094 } 15095 15096 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15097 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15098 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || 15099 (info->req_ie && 15100 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 15101 info->req_ie)) || 15102 (info->resp_ie && 15103 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 15104 info->resp_ie)) || 15105 (info->fils.update_erp_next_seq_num && 15106 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 15107 info->fils.erp_next_seq_num)) || 15108 (info->fils.kek && 15109 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, 15110 info->fils.kek)) || 15111 (info->fils.pmk && 15112 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || 15113 (info->fils.pmkid && 15114 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) 15115 goto nla_put_failure; 15116 15117 genlmsg_end(msg, hdr); 15118 15119 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15120 NL80211_MCGRP_MLME, gfp); 15121 return; 15122 15123 nla_put_failure: 15124 nlmsg_free(msg); 15125 } 15126 15127 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, 15128 struct net_device *netdev, const u8 *bssid) 15129 { 15130 struct sk_buff *msg; 15131 void *hdr; 15132 15133 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15134 if (!msg) 15135 return; 15136 15137 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); 15138 if (!hdr) { 15139 nlmsg_free(msg); 15140 return; 15141 } 15142 15143 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15144 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15145 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 15146 goto nla_put_failure; 15147 15148 genlmsg_end(msg, hdr); 15149 15150 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15151 NL80211_MCGRP_MLME, GFP_KERNEL); 15152 return; 15153 15154 nla_put_failure: 15155 nlmsg_free(msg); 15156 } 15157 15158 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 15159 struct net_device *netdev, u16 reason, 15160 const u8 *ie, size_t ie_len, bool from_ap) 15161 { 15162 struct sk_buff *msg; 15163 void *hdr; 15164 15165 msg = nlmsg_new(100 + ie_len, GFP_KERNEL); 15166 if (!msg) 15167 return; 15168 15169 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); 15170 if (!hdr) { 15171 nlmsg_free(msg); 15172 return; 15173 } 15174 15175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15176 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15177 (reason && 15178 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || 15179 (from_ap && 15180 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || 15181 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) 15182 goto nla_put_failure; 15183 15184 genlmsg_end(msg, hdr); 15185 15186 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15187 NL80211_MCGRP_MLME, GFP_KERNEL); 15188 return; 15189 15190 nla_put_failure: 15191 nlmsg_free(msg); 15192 } 15193 15194 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 15195 struct net_device *netdev, const u8 *bssid, 15196 gfp_t gfp) 15197 { 15198 struct sk_buff *msg; 15199 void *hdr; 15200 15201 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15202 if (!msg) 15203 return; 15204 15205 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); 15206 if (!hdr) { 15207 nlmsg_free(msg); 15208 return; 15209 } 15210 15211 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15212 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15213 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 15214 goto nla_put_failure; 15215 15216 genlmsg_end(msg, hdr); 15217 15218 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15219 NL80211_MCGRP_MLME, gfp); 15220 return; 15221 15222 nla_put_failure: 15223 nlmsg_free(msg); 15224 } 15225 15226 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, 15227 const u8 *ie, u8 ie_len, 15228 int sig_dbm, gfp_t gfp) 15229 { 15230 struct wireless_dev *wdev = dev->ieee80211_ptr; 15231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 15232 struct sk_buff *msg; 15233 void *hdr; 15234 15235 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) 15236 return; 15237 15238 trace_cfg80211_notify_new_peer_candidate(dev, addr); 15239 15240 msg = nlmsg_new(100 + ie_len, gfp); 15241 if (!msg) 15242 return; 15243 15244 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); 15245 if (!hdr) { 15246 nlmsg_free(msg); 15247 return; 15248 } 15249 15250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 15252 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 15253 (ie_len && ie && 15254 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || 15255 (sig_dbm && 15256 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) 15257 goto nla_put_failure; 15258 15259 genlmsg_end(msg, hdr); 15260 15261 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15262 NL80211_MCGRP_MLME, gfp); 15263 return; 15264 15265 nla_put_failure: 15266 nlmsg_free(msg); 15267 } 15268 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); 15269 15270 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 15271 struct net_device *netdev, const u8 *addr, 15272 enum nl80211_key_type key_type, int key_id, 15273 const u8 *tsc, gfp_t gfp) 15274 { 15275 struct sk_buff *msg; 15276 void *hdr; 15277 15278 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15279 if (!msg) 15280 return; 15281 15282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); 15283 if (!hdr) { 15284 nlmsg_free(msg); 15285 return; 15286 } 15287 15288 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15289 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15290 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || 15291 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || 15292 (key_id != -1 && 15293 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || 15294 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) 15295 goto nla_put_failure; 15296 15297 genlmsg_end(msg, hdr); 15298 15299 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15300 NL80211_MCGRP_MLME, gfp); 15301 return; 15302 15303 nla_put_failure: 15304 nlmsg_free(msg); 15305 } 15306 15307 void nl80211_send_beacon_hint_event(struct wiphy *wiphy, 15308 struct ieee80211_channel *channel_before, 15309 struct ieee80211_channel *channel_after) 15310 { 15311 struct sk_buff *msg; 15312 void *hdr; 15313 struct nlattr *nl_freq; 15314 15315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 15316 if (!msg) 15317 return; 15318 15319 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); 15320 if (!hdr) { 15321 nlmsg_free(msg); 15322 return; 15323 } 15324 15325 /* 15326 * Since we are applying the beacon hint to a wiphy we know its 15327 * wiphy_idx is valid 15328 */ 15329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 15330 goto nla_put_failure; 15331 15332 /* Before */ 15333 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); 15334 if (!nl_freq) 15335 goto nla_put_failure; 15336 15337 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) 15338 goto nla_put_failure; 15339 nla_nest_end(msg, nl_freq); 15340 15341 /* After */ 15342 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); 15343 if (!nl_freq) 15344 goto nla_put_failure; 15345 15346 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) 15347 goto nla_put_failure; 15348 nla_nest_end(msg, nl_freq); 15349 15350 genlmsg_end(msg, hdr); 15351 15352 rcu_read_lock(); 15353 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 15354 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 15355 rcu_read_unlock(); 15356 15357 return; 15358 15359 nla_put_failure: 15360 nlmsg_free(msg); 15361 } 15362 15363 static void nl80211_send_remain_on_chan_event( 15364 int cmd, struct cfg80211_registered_device *rdev, 15365 struct wireless_dev *wdev, u64 cookie, 15366 struct ieee80211_channel *chan, 15367 unsigned int duration, gfp_t gfp) 15368 { 15369 struct sk_buff *msg; 15370 void *hdr; 15371 15372 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15373 if (!msg) 15374 return; 15375 15376 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 15377 if (!hdr) { 15378 nlmsg_free(msg); 15379 return; 15380 } 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 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || 15388 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 15389 NL80211_CHAN_NO_HT) || 15390 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 15391 NL80211_ATTR_PAD)) 15392 goto nla_put_failure; 15393 15394 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && 15395 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) 15396 goto nla_put_failure; 15397 15398 genlmsg_end(msg, hdr); 15399 15400 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15401 NL80211_MCGRP_MLME, gfp); 15402 return; 15403 15404 nla_put_failure: 15405 nlmsg_free(msg); 15406 } 15407 15408 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, 15409 struct ieee80211_channel *chan, 15410 unsigned int duration, gfp_t gfp) 15411 { 15412 struct wiphy *wiphy = wdev->wiphy; 15413 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15414 15415 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); 15416 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, 15417 rdev, wdev, cookie, chan, 15418 duration, gfp); 15419 } 15420 EXPORT_SYMBOL(cfg80211_ready_on_channel); 15421 15422 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, 15423 struct ieee80211_channel *chan, 15424 gfp_t gfp) 15425 { 15426 struct wiphy *wiphy = wdev->wiphy; 15427 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15428 15429 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); 15430 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 15431 rdev, wdev, cookie, chan, 0, gfp); 15432 } 15433 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); 15434 15435 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, 15436 struct ieee80211_channel *chan, 15437 gfp_t gfp) 15438 { 15439 struct wiphy *wiphy = wdev->wiphy; 15440 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15441 15442 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); 15443 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, 15444 rdev, wdev, cookie, chan, 0, gfp); 15445 } 15446 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); 15447 15448 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, 15449 struct station_info *sinfo, gfp_t gfp) 15450 { 15451 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 15452 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15453 struct sk_buff *msg; 15454 15455 trace_cfg80211_new_sta(dev, mac_addr, sinfo); 15456 15457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15458 if (!msg) 15459 return; 15460 15461 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, 15462 rdev, dev, mac_addr, sinfo) < 0) { 15463 nlmsg_free(msg); 15464 return; 15465 } 15466 15467 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15468 NL80211_MCGRP_MLME, gfp); 15469 } 15470 EXPORT_SYMBOL(cfg80211_new_sta); 15471 15472 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, 15473 struct station_info *sinfo, gfp_t gfp) 15474 { 15475 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 15476 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15477 struct sk_buff *msg; 15478 struct station_info empty_sinfo = {}; 15479 15480 if (!sinfo) 15481 sinfo = &empty_sinfo; 15482 15483 trace_cfg80211_del_sta(dev, mac_addr); 15484 15485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15486 if (!msg) { 15487 cfg80211_sinfo_release_content(sinfo); 15488 return; 15489 } 15490 15491 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, 15492 rdev, dev, mac_addr, sinfo) < 0) { 15493 nlmsg_free(msg); 15494 return; 15495 } 15496 15497 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15498 NL80211_MCGRP_MLME, gfp); 15499 } 15500 EXPORT_SYMBOL(cfg80211_del_sta_sinfo); 15501 15502 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, 15503 enum nl80211_connect_failed_reason reason, 15504 gfp_t gfp) 15505 { 15506 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 15507 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15508 struct sk_buff *msg; 15509 void *hdr; 15510 15511 msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 15512 if (!msg) 15513 return; 15514 15515 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); 15516 if (!hdr) { 15517 nlmsg_free(msg); 15518 return; 15519 } 15520 15521 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 15522 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 15523 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) 15524 goto nla_put_failure; 15525 15526 genlmsg_end(msg, hdr); 15527 15528 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15529 NL80211_MCGRP_MLME, gfp); 15530 return; 15531 15532 nla_put_failure: 15533 nlmsg_free(msg); 15534 } 15535 EXPORT_SYMBOL(cfg80211_conn_failed); 15536 15537 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, 15538 const u8 *addr, gfp_t gfp) 15539 { 15540 struct wireless_dev *wdev = dev->ieee80211_ptr; 15541 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 15542 struct sk_buff *msg; 15543 void *hdr; 15544 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); 15545 15546 if (!nlportid) 15547 return false; 15548 15549 msg = nlmsg_new(100, gfp); 15550 if (!msg) 15551 return true; 15552 15553 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 15554 if (!hdr) { 15555 nlmsg_free(msg); 15556 return true; 15557 } 15558 15559 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 15561 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 15562 goto nla_put_failure; 15563 15564 genlmsg_end(msg, hdr); 15565 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 15566 return true; 15567 15568 nla_put_failure: 15569 nlmsg_free(msg); 15570 return true; 15571 } 15572 15573 bool cfg80211_rx_spurious_frame(struct net_device *dev, 15574 const u8 *addr, gfp_t gfp) 15575 { 15576 struct wireless_dev *wdev = dev->ieee80211_ptr; 15577 bool ret; 15578 15579 trace_cfg80211_rx_spurious_frame(dev, addr); 15580 15581 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 15582 wdev->iftype != NL80211_IFTYPE_P2P_GO)) { 15583 trace_cfg80211_return_bool(false); 15584 return false; 15585 } 15586 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, 15587 addr, gfp); 15588 trace_cfg80211_return_bool(ret); 15589 return ret; 15590 } 15591 EXPORT_SYMBOL(cfg80211_rx_spurious_frame); 15592 15593 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, 15594 const u8 *addr, gfp_t gfp) 15595 { 15596 struct wireless_dev *wdev = dev->ieee80211_ptr; 15597 bool ret; 15598 15599 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); 15600 15601 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 15602 wdev->iftype != NL80211_IFTYPE_P2P_GO && 15603 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { 15604 trace_cfg80211_return_bool(false); 15605 return false; 15606 } 15607 ret = __nl80211_unexpected_frame(dev, 15608 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, 15609 addr, gfp); 15610 trace_cfg80211_return_bool(ret); 15611 return ret; 15612 } 15613 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); 15614 15615 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, 15616 struct wireless_dev *wdev, u32 nlportid, 15617 int freq, int sig_dbm, 15618 const u8 *buf, size_t len, u32 flags, gfp_t gfp) 15619 { 15620 struct net_device *netdev = wdev->netdev; 15621 struct sk_buff *msg; 15622 void *hdr; 15623 15624 msg = nlmsg_new(100 + len, gfp); 15625 if (!msg) 15626 return -ENOMEM; 15627 15628 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 15629 if (!hdr) { 15630 nlmsg_free(msg); 15631 return -ENOMEM; 15632 } 15633 15634 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15635 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 15636 netdev->ifindex)) || 15637 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 15638 NL80211_ATTR_PAD) || 15639 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || 15640 (sig_dbm && 15641 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 15642 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 15643 (flags && 15644 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) 15645 goto nla_put_failure; 15646 15647 genlmsg_end(msg, hdr); 15648 15649 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 15650 15651 nla_put_failure: 15652 nlmsg_free(msg); 15653 return -ENOBUFS; 15654 } 15655 15656 void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, 15657 const u8 *buf, size_t len, bool ack, gfp_t gfp) 15658 { 15659 struct wiphy *wiphy = wdev->wiphy; 15660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15661 struct net_device *netdev = wdev->netdev; 15662 struct sk_buff *msg; 15663 void *hdr; 15664 15665 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); 15666 15667 msg = nlmsg_new(100 + len, gfp); 15668 if (!msg) 15669 return; 15670 15671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); 15672 if (!hdr) { 15673 nlmsg_free(msg); 15674 return; 15675 } 15676 15677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15678 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 15679 netdev->ifindex)) || 15680 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 15681 NL80211_ATTR_PAD) || 15682 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 15683 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 15684 NL80211_ATTR_PAD) || 15685 (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) 15686 goto nla_put_failure; 15687 15688 genlmsg_end(msg, hdr); 15689 15690 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15691 NL80211_MCGRP_MLME, gfp); 15692 return; 15693 15694 nla_put_failure: 15695 nlmsg_free(msg); 15696 } 15697 EXPORT_SYMBOL(cfg80211_mgmt_tx_status); 15698 15699 static int __nl80211_rx_control_port(struct net_device *dev, 15700 struct sk_buff *skb, 15701 bool unencrypted, gfp_t gfp) 15702 { 15703 struct wireless_dev *wdev = dev->ieee80211_ptr; 15704 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 15705 struct ethhdr *ehdr = eth_hdr(skb); 15706 const u8 *addr = ehdr->h_source; 15707 u16 proto = be16_to_cpu(skb->protocol); 15708 struct sk_buff *msg; 15709 void *hdr; 15710 struct nlattr *frame; 15711 15712 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); 15713 15714 if (!nlportid) 15715 return -ENOENT; 15716 15717 msg = nlmsg_new(100 + skb->len, gfp); 15718 if (!msg) 15719 return -ENOMEM; 15720 15721 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); 15722 if (!hdr) { 15723 nlmsg_free(msg); 15724 return -ENOBUFS; 15725 } 15726 15727 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 15729 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 15730 NL80211_ATTR_PAD) || 15731 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 15732 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || 15733 (unencrypted && nla_put_flag(msg, 15734 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) 15735 goto nla_put_failure; 15736 15737 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); 15738 if (!frame) 15739 goto nla_put_failure; 15740 15741 skb_copy_bits(skb, 0, nla_data(frame), skb->len); 15742 genlmsg_end(msg, hdr); 15743 15744 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 15745 15746 nla_put_failure: 15747 nlmsg_free(msg); 15748 return -ENOBUFS; 15749 } 15750 15751 bool cfg80211_rx_control_port(struct net_device *dev, 15752 struct sk_buff *skb, bool unencrypted) 15753 { 15754 int ret; 15755 15756 trace_cfg80211_rx_control_port(dev, skb, unencrypted); 15757 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); 15758 trace_cfg80211_return_bool(ret == 0); 15759 return ret == 0; 15760 } 15761 EXPORT_SYMBOL(cfg80211_rx_control_port); 15762 15763 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 15764 const char *mac, gfp_t gfp) 15765 { 15766 struct wireless_dev *wdev = dev->ieee80211_ptr; 15767 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 15768 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15769 void **cb; 15770 15771 if (!msg) 15772 return NULL; 15773 15774 cb = (void **)msg->cb; 15775 15776 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 15777 if (!cb[0]) { 15778 nlmsg_free(msg); 15779 return NULL; 15780 } 15781 15782 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15783 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 15784 goto nla_put_failure; 15785 15786 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 15787 goto nla_put_failure; 15788 15789 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); 15790 if (!cb[1]) 15791 goto nla_put_failure; 15792 15793 cb[2] = rdev; 15794 15795 return msg; 15796 nla_put_failure: 15797 nlmsg_free(msg); 15798 return NULL; 15799 } 15800 15801 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) 15802 { 15803 void **cb = (void **)msg->cb; 15804 struct cfg80211_registered_device *rdev = cb[2]; 15805 15806 nla_nest_end(msg, cb[1]); 15807 genlmsg_end(msg, cb[0]); 15808 15809 memset(msg->cb, 0, sizeof(msg->cb)); 15810 15811 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15812 NL80211_MCGRP_MLME, gfp); 15813 } 15814 15815 void cfg80211_cqm_rssi_notify(struct net_device *dev, 15816 enum nl80211_cqm_rssi_threshold_event rssi_event, 15817 s32 rssi_level, gfp_t gfp) 15818 { 15819 struct sk_buff *msg; 15820 struct wireless_dev *wdev = dev->ieee80211_ptr; 15821 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 15822 15823 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); 15824 15825 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && 15826 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) 15827 return; 15828 15829 if (wdev->cqm_config) { 15830 wdev->cqm_config->last_rssi_event_value = rssi_level; 15831 15832 cfg80211_cqm_rssi_update(rdev, dev); 15833 15834 if (rssi_level == 0) 15835 rssi_level = wdev->cqm_config->last_rssi_event_value; 15836 } 15837 15838 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 15839 if (!msg) 15840 return; 15841 15842 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 15843 rssi_event)) 15844 goto nla_put_failure; 15845 15846 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, 15847 rssi_level)) 15848 goto nla_put_failure; 15849 15850 cfg80211_send_cqm(msg, gfp); 15851 15852 return; 15853 15854 nla_put_failure: 15855 nlmsg_free(msg); 15856 } 15857 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 15858 15859 void cfg80211_cqm_txe_notify(struct net_device *dev, 15860 const u8 *peer, u32 num_packets, 15861 u32 rate, u32 intvl, gfp_t gfp) 15862 { 15863 struct sk_buff *msg; 15864 15865 msg = cfg80211_prepare_cqm(dev, peer, gfp); 15866 if (!msg) 15867 return; 15868 15869 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 15870 goto nla_put_failure; 15871 15872 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 15873 goto nla_put_failure; 15874 15875 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 15876 goto nla_put_failure; 15877 15878 cfg80211_send_cqm(msg, gfp); 15879 return; 15880 15881 nla_put_failure: 15882 nlmsg_free(msg); 15883 } 15884 EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 15885 15886 void cfg80211_cqm_pktloss_notify(struct net_device *dev, 15887 const u8 *peer, u32 num_packets, gfp_t gfp) 15888 { 15889 struct sk_buff *msg; 15890 15891 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 15892 15893 msg = cfg80211_prepare_cqm(dev, peer, gfp); 15894 if (!msg) 15895 return; 15896 15897 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 15898 goto nla_put_failure; 15899 15900 cfg80211_send_cqm(msg, gfp); 15901 return; 15902 15903 nla_put_failure: 15904 nlmsg_free(msg); 15905 } 15906 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 15907 15908 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) 15909 { 15910 struct sk_buff *msg; 15911 15912 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 15913 if (!msg) 15914 return; 15915 15916 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) 15917 goto nla_put_failure; 15918 15919 cfg80211_send_cqm(msg, gfp); 15920 return; 15921 15922 nla_put_failure: 15923 nlmsg_free(msg); 15924 } 15925 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); 15926 15927 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 15928 struct net_device *netdev, const u8 *bssid, 15929 const u8 *replay_ctr, gfp_t gfp) 15930 { 15931 struct sk_buff *msg; 15932 struct nlattr *rekey_attr; 15933 void *hdr; 15934 15935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15936 if (!msg) 15937 return; 15938 15939 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); 15940 if (!hdr) { 15941 nlmsg_free(msg); 15942 return; 15943 } 15944 15945 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15946 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 15947 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 15948 goto nla_put_failure; 15949 15950 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); 15951 if (!rekey_attr) 15952 goto nla_put_failure; 15953 15954 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, 15955 NL80211_REPLAY_CTR_LEN, replay_ctr)) 15956 goto nla_put_failure; 15957 15958 nla_nest_end(msg, rekey_attr); 15959 15960 genlmsg_end(msg, hdr); 15961 15962 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 15963 NL80211_MCGRP_MLME, gfp); 15964 return; 15965 15966 nla_put_failure: 15967 nlmsg_free(msg); 15968 } 15969 15970 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, 15971 const u8 *replay_ctr, gfp_t gfp) 15972 { 15973 struct wireless_dev *wdev = dev->ieee80211_ptr; 15974 struct wiphy *wiphy = wdev->wiphy; 15975 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15976 15977 trace_cfg80211_gtk_rekey_notify(dev, bssid); 15978 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); 15979 } 15980 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); 15981 15982 static void 15983 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, 15984 struct net_device *netdev, int index, 15985 const u8 *bssid, bool preauth, gfp_t gfp) 15986 { 15987 struct sk_buff *msg; 15988 struct nlattr *attr; 15989 void *hdr; 15990 15991 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 15992 if (!msg) 15993 return; 15994 15995 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); 15996 if (!hdr) { 15997 nlmsg_free(msg); 15998 return; 15999 } 16000 16001 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16002 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 16003 goto nla_put_failure; 16004 16005 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); 16006 if (!attr) 16007 goto nla_put_failure; 16008 16009 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || 16010 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || 16011 (preauth && 16012 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) 16013 goto nla_put_failure; 16014 16015 nla_nest_end(msg, attr); 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 cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, 16028 const u8 *bssid, bool preauth, gfp_t gfp) 16029 { 16030 struct wireless_dev *wdev = dev->ieee80211_ptr; 16031 struct wiphy *wiphy = wdev->wiphy; 16032 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16033 16034 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); 16035 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 16036 } 16037 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 16038 16039 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, 16040 struct net_device *netdev, 16041 struct cfg80211_chan_def *chandef, 16042 gfp_t gfp, 16043 enum nl80211_commands notif, 16044 u8 count) 16045 { 16046 struct sk_buff *msg; 16047 void *hdr; 16048 16049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16050 if (!msg) 16051 return; 16052 16053 hdr = nl80211hdr_put(msg, 0, 0, 0, notif); 16054 if (!hdr) { 16055 nlmsg_free(msg); 16056 return; 16057 } 16058 16059 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 16060 goto nla_put_failure; 16061 16062 if (nl80211_send_chandef(msg, chandef)) 16063 goto nla_put_failure; 16064 16065 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && 16066 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) 16067 goto nla_put_failure; 16068 16069 genlmsg_end(msg, hdr); 16070 16071 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16072 NL80211_MCGRP_MLME, gfp); 16073 return; 16074 16075 nla_put_failure: 16076 nlmsg_free(msg); 16077 } 16078 16079 void cfg80211_ch_switch_notify(struct net_device *dev, 16080 struct cfg80211_chan_def *chandef) 16081 { 16082 struct wireless_dev *wdev = dev->ieee80211_ptr; 16083 struct wiphy *wiphy = wdev->wiphy; 16084 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16085 16086 ASSERT_WDEV_LOCK(wdev); 16087 16088 trace_cfg80211_ch_switch_notify(dev, chandef); 16089 16090 wdev->chandef = *chandef; 16091 wdev->preset_chandef = *chandef; 16092 16093 if (wdev->iftype == NL80211_IFTYPE_STATION && 16094 !WARN_ON(!wdev->current_bss)) 16095 wdev->current_bss->pub.channel = chandef->chan; 16096 16097 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 16098 NL80211_CMD_CH_SWITCH_NOTIFY, 0); 16099 } 16100 EXPORT_SYMBOL(cfg80211_ch_switch_notify); 16101 16102 void cfg80211_ch_switch_started_notify(struct net_device *dev, 16103 struct cfg80211_chan_def *chandef, 16104 u8 count) 16105 { 16106 struct wireless_dev *wdev = dev->ieee80211_ptr; 16107 struct wiphy *wiphy = wdev->wiphy; 16108 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16109 16110 trace_cfg80211_ch_switch_started_notify(dev, chandef); 16111 16112 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 16113 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); 16114 } 16115 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 16116 16117 void 16118 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 16119 const struct cfg80211_chan_def *chandef, 16120 enum nl80211_radar_event event, 16121 struct net_device *netdev, gfp_t gfp) 16122 { 16123 struct sk_buff *msg; 16124 void *hdr; 16125 16126 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16127 if (!msg) 16128 return; 16129 16130 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); 16131 if (!hdr) { 16132 nlmsg_free(msg); 16133 return; 16134 } 16135 16136 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 16137 goto nla_put_failure; 16138 16139 /* NOP and radar events don't need a netdev parameter */ 16140 if (netdev) { 16141 struct wireless_dev *wdev = netdev->ieee80211_ptr; 16142 16143 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16144 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16145 NL80211_ATTR_PAD)) 16146 goto nla_put_failure; 16147 } 16148 16149 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) 16150 goto nla_put_failure; 16151 16152 if (nl80211_send_chandef(msg, chandef)) 16153 goto nla_put_failure; 16154 16155 genlmsg_end(msg, hdr); 16156 16157 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16158 NL80211_MCGRP_MLME, gfp); 16159 return; 16160 16161 nla_put_failure: 16162 nlmsg_free(msg); 16163 } 16164 16165 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, 16166 struct sta_opmode_info *sta_opmode, 16167 gfp_t gfp) 16168 { 16169 struct sk_buff *msg; 16170 struct wireless_dev *wdev = dev->ieee80211_ptr; 16171 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16172 void *hdr; 16173 16174 if (WARN_ON(!mac)) 16175 return; 16176 16177 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16178 if (!msg) 16179 return; 16180 16181 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); 16182 if (!hdr) { 16183 nlmsg_free(msg); 16184 return; 16185 } 16186 16187 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 16188 goto nla_put_failure; 16189 16190 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 16191 goto nla_put_failure; 16192 16193 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 16194 goto nla_put_failure; 16195 16196 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && 16197 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) 16198 goto nla_put_failure; 16199 16200 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && 16201 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) 16202 goto nla_put_failure; 16203 16204 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && 16205 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) 16206 goto nla_put_failure; 16207 16208 genlmsg_end(msg, hdr); 16209 16210 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16211 NL80211_MCGRP_MLME, gfp); 16212 16213 return; 16214 16215 nla_put_failure: 16216 nlmsg_free(msg); 16217 } 16218 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); 16219 16220 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 16221 u64 cookie, bool acked, s32 ack_signal, 16222 bool is_valid_ack_signal, gfp_t gfp) 16223 { 16224 struct wireless_dev *wdev = dev->ieee80211_ptr; 16225 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16226 struct sk_buff *msg; 16227 void *hdr; 16228 16229 trace_cfg80211_probe_status(dev, addr, cookie, acked); 16230 16231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16232 16233 if (!msg) 16234 return; 16235 16236 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); 16237 if (!hdr) { 16238 nlmsg_free(msg); 16239 return; 16240 } 16241 16242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16243 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16244 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 16245 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 16246 NL80211_ATTR_PAD) || 16247 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || 16248 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, 16249 ack_signal))) 16250 goto nla_put_failure; 16251 16252 genlmsg_end(msg, hdr); 16253 16254 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16255 NL80211_MCGRP_MLME, gfp); 16256 return; 16257 16258 nla_put_failure: 16259 nlmsg_free(msg); 16260 } 16261 EXPORT_SYMBOL(cfg80211_probe_status); 16262 16263 void cfg80211_report_obss_beacon(struct wiphy *wiphy, 16264 const u8 *frame, size_t len, 16265 int freq, int sig_dbm) 16266 { 16267 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16268 struct sk_buff *msg; 16269 void *hdr; 16270 struct cfg80211_beacon_registration *reg; 16271 16272 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); 16273 16274 spin_lock_bh(&rdev->beacon_registrations_lock); 16275 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 16276 msg = nlmsg_new(len + 100, GFP_ATOMIC); 16277 if (!msg) { 16278 spin_unlock_bh(&rdev->beacon_registrations_lock); 16279 return; 16280 } 16281 16282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 16283 if (!hdr) 16284 goto nla_put_failure; 16285 16286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16287 (freq && 16288 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || 16289 (sig_dbm && 16290 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 16291 nla_put(msg, NL80211_ATTR_FRAME, len, frame)) 16292 goto nla_put_failure; 16293 16294 genlmsg_end(msg, hdr); 16295 16296 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); 16297 } 16298 spin_unlock_bh(&rdev->beacon_registrations_lock); 16299 return; 16300 16301 nla_put_failure: 16302 spin_unlock_bh(&rdev->beacon_registrations_lock); 16303 nlmsg_free(msg); 16304 } 16305 EXPORT_SYMBOL(cfg80211_report_obss_beacon); 16306 16307 #ifdef CONFIG_PM 16308 static int cfg80211_net_detect_results(struct sk_buff *msg, 16309 struct cfg80211_wowlan_wakeup *wakeup) 16310 { 16311 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; 16312 struct nlattr *nl_results, *nl_match, *nl_freqs; 16313 int i, j; 16314 16315 nl_results = nla_nest_start_noflag(msg, 16316 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 16317 if (!nl_results) 16318 return -EMSGSIZE; 16319 16320 for (i = 0; i < nd->n_matches; i++) { 16321 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 16322 16323 nl_match = nla_nest_start_noflag(msg, i); 16324 if (!nl_match) 16325 break; 16326 16327 /* The SSID attribute is optional in nl80211, but for 16328 * simplicity reasons it's always present in the 16329 * cfg80211 structure. If a driver can't pass the 16330 * SSID, that needs to be changed. A zero length SSID 16331 * is still a valid SSID (wildcard), so it cannot be 16332 * used for this purpose. 16333 */ 16334 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, 16335 match->ssid.ssid)) { 16336 nla_nest_cancel(msg, nl_match); 16337 goto out; 16338 } 16339 16340 if (match->n_channels) { 16341 nl_freqs = nla_nest_start_noflag(msg, 16342 NL80211_ATTR_SCAN_FREQUENCIES); 16343 if (!nl_freqs) { 16344 nla_nest_cancel(msg, nl_match); 16345 goto out; 16346 } 16347 16348 for (j = 0; j < match->n_channels; j++) { 16349 if (nla_put_u32(msg, j, match->channels[j])) { 16350 nla_nest_cancel(msg, nl_freqs); 16351 nla_nest_cancel(msg, nl_match); 16352 goto out; 16353 } 16354 } 16355 16356 nla_nest_end(msg, nl_freqs); 16357 } 16358 16359 nla_nest_end(msg, nl_match); 16360 } 16361 16362 out: 16363 nla_nest_end(msg, nl_results); 16364 return 0; 16365 } 16366 16367 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, 16368 struct cfg80211_wowlan_wakeup *wakeup, 16369 gfp_t gfp) 16370 { 16371 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16372 struct sk_buff *msg; 16373 void *hdr; 16374 int size = 200; 16375 16376 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); 16377 16378 if (wakeup) 16379 size += wakeup->packet_present_len; 16380 16381 msg = nlmsg_new(size, gfp); 16382 if (!msg) 16383 return; 16384 16385 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); 16386 if (!hdr) 16387 goto free_msg; 16388 16389 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16390 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16391 NL80211_ATTR_PAD)) 16392 goto free_msg; 16393 16394 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 16395 wdev->netdev->ifindex)) 16396 goto free_msg; 16397 16398 if (wakeup) { 16399 struct nlattr *reasons; 16400 16401 reasons = nla_nest_start_noflag(msg, 16402 NL80211_ATTR_WOWLAN_TRIGGERS); 16403 if (!reasons) 16404 goto free_msg; 16405 16406 if (wakeup->disconnect && 16407 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) 16408 goto free_msg; 16409 if (wakeup->magic_pkt && 16410 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) 16411 goto free_msg; 16412 if (wakeup->gtk_rekey_failure && 16413 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) 16414 goto free_msg; 16415 if (wakeup->eap_identity_req && 16416 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) 16417 goto free_msg; 16418 if (wakeup->four_way_handshake && 16419 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) 16420 goto free_msg; 16421 if (wakeup->rfkill_release && 16422 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) 16423 goto free_msg; 16424 16425 if (wakeup->pattern_idx >= 0 && 16426 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 16427 wakeup->pattern_idx)) 16428 goto free_msg; 16429 16430 if (wakeup->tcp_match && 16431 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) 16432 goto free_msg; 16433 16434 if (wakeup->tcp_connlost && 16435 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) 16436 goto free_msg; 16437 16438 if (wakeup->tcp_nomoretokens && 16439 nla_put_flag(msg, 16440 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) 16441 goto free_msg; 16442 16443 if (wakeup->packet) { 16444 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; 16445 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; 16446 16447 if (!wakeup->packet_80211) { 16448 pkt_attr = 16449 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; 16450 len_attr = 16451 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; 16452 } 16453 16454 if (wakeup->packet_len && 16455 nla_put_u32(msg, len_attr, wakeup->packet_len)) 16456 goto free_msg; 16457 16458 if (nla_put(msg, pkt_attr, wakeup->packet_present_len, 16459 wakeup->packet)) 16460 goto free_msg; 16461 } 16462 16463 if (wakeup->net_detect && 16464 cfg80211_net_detect_results(msg, wakeup)) 16465 goto free_msg; 16466 16467 nla_nest_end(msg, reasons); 16468 } 16469 16470 genlmsg_end(msg, hdr); 16471 16472 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16473 NL80211_MCGRP_MLME, gfp); 16474 return; 16475 16476 free_msg: 16477 nlmsg_free(msg); 16478 } 16479 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); 16480 #endif 16481 16482 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, 16483 enum nl80211_tdls_operation oper, 16484 u16 reason_code, gfp_t gfp) 16485 { 16486 struct wireless_dev *wdev = dev->ieee80211_ptr; 16487 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16488 struct sk_buff *msg; 16489 void *hdr; 16490 16491 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, 16492 reason_code); 16493 16494 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16495 if (!msg) 16496 return; 16497 16498 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); 16499 if (!hdr) { 16500 nlmsg_free(msg); 16501 return; 16502 } 16503 16504 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16505 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16506 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || 16507 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || 16508 (reason_code > 0 && 16509 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) 16510 goto nla_put_failure; 16511 16512 genlmsg_end(msg, hdr); 16513 16514 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16515 NL80211_MCGRP_MLME, gfp); 16516 return; 16517 16518 nla_put_failure: 16519 nlmsg_free(msg); 16520 } 16521 EXPORT_SYMBOL(cfg80211_tdls_oper_request); 16522 16523 static int nl80211_netlink_notify(struct notifier_block * nb, 16524 unsigned long state, 16525 void *_notify) 16526 { 16527 struct netlink_notify *notify = _notify; 16528 struct cfg80211_registered_device *rdev; 16529 struct wireless_dev *wdev; 16530 struct cfg80211_beacon_registration *reg, *tmp; 16531 16532 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) 16533 return NOTIFY_DONE; 16534 16535 rcu_read_lock(); 16536 16537 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 16538 struct cfg80211_sched_scan_request *sched_scan_req; 16539 16540 list_for_each_entry_rcu(sched_scan_req, 16541 &rdev->sched_scan_req_list, 16542 list) { 16543 if (sched_scan_req->owner_nlportid == notify->portid) { 16544 sched_scan_req->nl_owner_dead = true; 16545 schedule_work(&rdev->sched_scan_stop_wk); 16546 } 16547 } 16548 16549 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { 16550 cfg80211_mlme_unregister_socket(wdev, notify->portid); 16551 16552 if (wdev->owner_nlportid == notify->portid) { 16553 wdev->nl_owner_dead = true; 16554 schedule_work(&rdev->destroy_work); 16555 } else if (wdev->conn_owner_nlportid == notify->portid) { 16556 schedule_work(&wdev->disconnect_wk); 16557 } 16558 16559 cfg80211_release_pmsr(wdev, notify->portid); 16560 } 16561 16562 spin_lock_bh(&rdev->beacon_registrations_lock); 16563 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, 16564 list) { 16565 if (reg->nlportid == notify->portid) { 16566 list_del(®->list); 16567 kfree(reg); 16568 break; 16569 } 16570 } 16571 spin_unlock_bh(&rdev->beacon_registrations_lock); 16572 } 16573 16574 rcu_read_unlock(); 16575 16576 /* 16577 * It is possible that the user space process that is controlling the 16578 * indoor setting disappeared, so notify the regulatory core. 16579 */ 16580 regulatory_netlink_notify(notify->portid); 16581 return NOTIFY_OK; 16582 } 16583 16584 static struct notifier_block nl80211_netlink_notifier = { 16585 .notifier_call = nl80211_netlink_notify, 16586 }; 16587 16588 void cfg80211_ft_event(struct net_device *netdev, 16589 struct cfg80211_ft_event_params *ft_event) 16590 { 16591 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 16592 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16593 struct sk_buff *msg; 16594 void *hdr; 16595 16596 trace_cfg80211_ft_event(wiphy, netdev, ft_event); 16597 16598 if (!ft_event->target_ap) 16599 return; 16600 16601 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, 16602 GFP_KERNEL); 16603 if (!msg) 16604 return; 16605 16606 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); 16607 if (!hdr) 16608 goto out; 16609 16610 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16611 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16612 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) 16613 goto out; 16614 16615 if (ft_event->ies && 16616 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) 16617 goto out; 16618 if (ft_event->ric_ies && 16619 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, 16620 ft_event->ric_ies)) 16621 goto out; 16622 16623 genlmsg_end(msg, hdr); 16624 16625 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16626 NL80211_MCGRP_MLME, GFP_KERNEL); 16627 return; 16628 out: 16629 nlmsg_free(msg); 16630 } 16631 EXPORT_SYMBOL(cfg80211_ft_event); 16632 16633 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) 16634 { 16635 struct cfg80211_registered_device *rdev; 16636 struct sk_buff *msg; 16637 void *hdr; 16638 u32 nlportid; 16639 16640 rdev = wiphy_to_rdev(wdev->wiphy); 16641 if (!rdev->crit_proto_nlportid) 16642 return; 16643 16644 nlportid = rdev->crit_proto_nlportid; 16645 rdev->crit_proto_nlportid = 0; 16646 16647 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16648 if (!msg) 16649 return; 16650 16651 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); 16652 if (!hdr) 16653 goto nla_put_failure; 16654 16655 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16656 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16657 NL80211_ATTR_PAD)) 16658 goto nla_put_failure; 16659 16660 genlmsg_end(msg, hdr); 16661 16662 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 16663 return; 16664 16665 nla_put_failure: 16666 nlmsg_free(msg); 16667 } 16668 EXPORT_SYMBOL(cfg80211_crit_proto_stopped); 16669 16670 void nl80211_send_ap_stopped(struct wireless_dev *wdev) 16671 { 16672 struct wiphy *wiphy = wdev->wiphy; 16673 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16674 struct sk_buff *msg; 16675 void *hdr; 16676 16677 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 16678 if (!msg) 16679 return; 16680 16681 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); 16682 if (!hdr) 16683 goto out; 16684 16685 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16686 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 16687 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 16688 NL80211_ATTR_PAD)) 16689 goto out; 16690 16691 genlmsg_end(msg, hdr); 16692 16693 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 16694 NL80211_MCGRP_MLME, GFP_KERNEL); 16695 return; 16696 out: 16697 nlmsg_free(msg); 16698 } 16699 16700 int cfg80211_external_auth_request(struct net_device *dev, 16701 struct cfg80211_external_auth_params *params, 16702 gfp_t gfp) 16703 { 16704 struct wireless_dev *wdev = dev->ieee80211_ptr; 16705 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 16706 struct sk_buff *msg; 16707 void *hdr; 16708 16709 if (!wdev->conn_owner_nlportid) 16710 return -EINVAL; 16711 16712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16713 if (!msg) 16714 return -ENOMEM; 16715 16716 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); 16717 if (!hdr) 16718 goto nla_put_failure; 16719 16720 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16721 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 16722 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || 16723 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, 16724 params->action) || 16725 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || 16726 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, 16727 params->ssid.ssid)) 16728 goto nla_put_failure; 16729 16730 genlmsg_end(msg, hdr); 16731 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 16732 wdev->conn_owner_nlportid); 16733 return 0; 16734 16735 nla_put_failure: 16736 nlmsg_free(msg); 16737 return -ENOBUFS; 16738 } 16739 EXPORT_SYMBOL(cfg80211_external_auth_request); 16740 16741 void cfg80211_update_owe_info_event(struct net_device *netdev, 16742 struct cfg80211_update_owe_info *owe_info, 16743 gfp_t gfp) 16744 { 16745 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 16746 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 16747 struct sk_buff *msg; 16748 void *hdr; 16749 16750 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); 16751 16752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 16753 if (!msg) 16754 return; 16755 16756 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); 16757 if (!hdr) 16758 goto nla_put_failure; 16759 16760 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 16761 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 16762 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) 16763 goto nla_put_failure; 16764 16765 if (!owe_info->ie_len || 16766 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) 16767 goto nla_put_failure; 16768 16769 genlmsg_end(msg, hdr); 16770 16771 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 16772 NL80211_MCGRP_MLME, gfp); 16773 return; 16774 16775 nla_put_failure: 16776 genlmsg_cancel(msg, hdr); 16777 nlmsg_free(msg); 16778 } 16779 EXPORT_SYMBOL(cfg80211_update_owe_info_event); 16780 16781 /* initialisation/exit functions */ 16782 16783 int __init nl80211_init(void) 16784 { 16785 int err; 16786 16787 err = genl_register_family(&nl80211_fam); 16788 if (err) 16789 return err; 16790 16791 err = netlink_register_notifier(&nl80211_netlink_notifier); 16792 if (err) 16793 goto err_out; 16794 16795 return 0; 16796 err_out: 16797 genl_unregister_family(&nl80211_fam); 16798 return err; 16799 } 16800 16801 void nl80211_exit(void) 16802 { 16803 netlink_unregister_notifier(&nl80211_netlink_notifier); 16804 genl_unregister_family(&nl80211_fam); 16805 } 16806