| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * This is the new netlink-based wireless configuration interface. | 
|  | 3 | * | 
|  | 4 | * Copyright 2006-2010	Johannes Berg <johannes@sipsolutions.net> | 
|  | 5 | * Copyright 2013-2014  Intel Mobile Communications GmbH | 
|  | 6 | * Copyright 2015-2017	Intel Deutschland GmbH | 
|  | 7 | * Copyright (C) 2018 Intel Corporation | 
|  | 8 | */ | 
|  | 9 |  | 
|  | 10 | #include <linux/if.h> | 
|  | 11 | #include <linux/module.h> | 
|  | 12 | #include <linux/err.h> | 
|  | 13 | #include <linux/slab.h> | 
|  | 14 | #include <linux/list.h> | 
|  | 15 | #include <linux/if_ether.h> | 
|  | 16 | #include <linux/ieee80211.h> | 
|  | 17 | #include <linux/nl80211.h> | 
|  | 18 | #include <linux/rtnetlink.h> | 
|  | 19 | #include <linux/netlink.h> | 
|  | 20 | #include <linux/nospec.h> | 
|  | 21 | #include <linux/etherdevice.h> | 
|  | 22 | #include <net/net_namespace.h> | 
|  | 23 | #include <net/genetlink.h> | 
|  | 24 | #include <net/cfg80211.h> | 
|  | 25 | #include <net/sock.h> | 
|  | 26 | #include <net/inet_connection_sock.h> | 
|  | 27 | #include "core.h" | 
|  | 28 | #include "nl80211.h" | 
|  | 29 | #include "reg.h" | 
|  | 30 | #include "rdev-ops.h" | 
|  | 31 |  | 
|  | 32 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, | 
|  | 33 | struct genl_info *info, | 
|  | 34 | struct cfg80211_crypto_settings *settings, | 
|  | 35 | int cipher_limit); | 
|  | 36 |  | 
|  | 37 | /* the netlink family */ | 
|  | 38 | static struct genl_family nl80211_fam; | 
|  | 39 |  | 
|  | 40 | /* multicast groups */ | 
|  | 41 | enum nl80211_multicast_groups { | 
|  | 42 | NL80211_MCGRP_CONFIG, | 
|  | 43 | NL80211_MCGRP_SCAN, | 
|  | 44 | NL80211_MCGRP_REGULATORY, | 
|  | 45 | NL80211_MCGRP_MLME, | 
|  | 46 | NL80211_MCGRP_VENDOR, | 
|  | 47 | NL80211_MCGRP_NAN, | 
|  | 48 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ | 
|  | 49 | }; | 
|  | 50 |  | 
|  | 51 | static const struct genl_multicast_group nl80211_mcgrps[] = { | 
|  | 52 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, | 
|  | 53 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | 
|  | 54 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | 
|  | 55 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | 
|  | 56 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | 
|  | 57 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, | 
|  | 58 | #ifdef CONFIG_NL80211_TESTMODE | 
|  | 59 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } | 
|  | 60 | #endif | 
|  | 61 | }; | 
|  | 62 |  | 
|  | 63 | /* returns ERR_PTR values */ | 
|  | 64 | static struct wireless_dev * | 
|  | 65 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | 
|  | 66 | { | 
|  | 67 | struct cfg80211_registered_device *rdev; | 
|  | 68 | struct wireless_dev *result = NULL; | 
|  | 69 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | 
|  | 70 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | 
|  | 71 | u64 wdev_id; | 
|  | 72 | int wiphy_idx = -1; | 
|  | 73 | int ifidx = -1; | 
|  | 74 |  | 
|  | 75 | ASSERT_RTNL(); | 
|  | 76 |  | 
|  | 77 | if (!have_ifidx && !have_wdev_id) | 
|  | 78 | return ERR_PTR(-EINVAL); | 
|  | 79 |  | 
|  | 80 | if (have_ifidx) | 
|  | 81 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | 
|  | 82 | if (have_wdev_id) { | 
|  | 83 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | 
|  | 84 | wiphy_idx = wdev_id >> 32; | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
|  | 88 | struct wireless_dev *wdev; | 
|  | 89 |  | 
|  | 90 | if (wiphy_net(&rdev->wiphy) != netns) | 
|  | 91 | continue; | 
|  | 92 |  | 
|  | 93 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | 
|  | 94 | continue; | 
|  | 95 |  | 
|  | 96 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { | 
|  | 97 | if (have_ifidx && wdev->netdev && | 
|  | 98 | wdev->netdev->ifindex == ifidx) { | 
|  | 99 | result = wdev; | 
|  | 100 | break; | 
|  | 101 | } | 
|  | 102 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | 
|  | 103 | result = wdev; | 
|  | 104 | break; | 
|  | 105 | } | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | if (result) | 
|  | 109 | break; | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | if (result) | 
|  | 113 | return result; | 
|  | 114 | return ERR_PTR(-ENODEV); | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | static struct cfg80211_registered_device * | 
|  | 118 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) | 
|  | 119 | { | 
|  | 120 | struct cfg80211_registered_device *rdev = NULL, *tmp; | 
|  | 121 | struct net_device *netdev; | 
|  | 122 |  | 
|  | 123 | ASSERT_RTNL(); | 
|  | 124 |  | 
|  | 125 | if (!attrs[NL80211_ATTR_WIPHY] && | 
|  | 126 | !attrs[NL80211_ATTR_IFINDEX] && | 
|  | 127 | !attrs[NL80211_ATTR_WDEV]) | 
|  | 128 | return ERR_PTR(-EINVAL); | 
|  | 129 |  | 
|  | 130 | if (attrs[NL80211_ATTR_WIPHY]) | 
|  | 131 | rdev = cfg80211_rdev_by_wiphy_idx( | 
|  | 132 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); | 
|  | 133 |  | 
|  | 134 | if (attrs[NL80211_ATTR_WDEV]) { | 
|  | 135 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | 
|  | 136 | struct wireless_dev *wdev; | 
|  | 137 | bool found = false; | 
|  | 138 |  | 
|  | 139 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | 
|  | 140 | if (tmp) { | 
|  | 141 | /* make sure wdev exists */ | 
|  | 142 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { | 
|  | 143 | if (wdev->identifier != (u32)wdev_id) | 
|  | 144 | continue; | 
|  | 145 | found = true; | 
|  | 146 | break; | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | if (!found) | 
|  | 150 | tmp = NULL; | 
|  | 151 |  | 
|  | 152 | if (rdev && tmp != rdev) | 
|  | 153 | return ERR_PTR(-EINVAL); | 
|  | 154 | rdev = tmp; | 
|  | 155 | } | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | if (attrs[NL80211_ATTR_IFINDEX]) { | 
|  | 159 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | 
|  | 160 |  | 
|  | 161 | netdev = __dev_get_by_index(netns, ifindex); | 
|  | 162 | if (netdev) { | 
|  | 163 | if (netdev->ieee80211_ptr) | 
|  | 164 | tmp = wiphy_to_rdev( | 
|  | 165 | netdev->ieee80211_ptr->wiphy); | 
|  | 166 | else | 
|  | 167 | tmp = NULL; | 
|  | 168 |  | 
|  | 169 | /* not wireless device -- return error */ | 
|  | 170 | if (!tmp) | 
|  | 171 | return ERR_PTR(-EINVAL); | 
|  | 172 |  | 
|  | 173 | /* mismatch -- return error */ | 
|  | 174 | if (rdev && tmp != rdev) | 
|  | 175 | return ERR_PTR(-EINVAL); | 
|  | 176 |  | 
|  | 177 | rdev = tmp; | 
|  | 178 | } | 
|  | 179 | } | 
|  | 180 |  | 
|  | 181 | if (!rdev) | 
|  | 182 | return ERR_PTR(-ENODEV); | 
|  | 183 |  | 
|  | 184 | if (netns != wiphy_net(&rdev->wiphy)) | 
|  | 185 | return ERR_PTR(-ENODEV); | 
|  | 186 |  | 
|  | 187 | return rdev; | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | /* | 
|  | 191 | * This function returns a pointer to the driver | 
|  | 192 | * that the genl_info item that is passed refers to. | 
|  | 193 | * | 
|  | 194 | * The result of this can be a PTR_ERR and hence must | 
|  | 195 | * be checked with IS_ERR() for errors. | 
|  | 196 | */ | 
|  | 197 | static struct cfg80211_registered_device * | 
|  | 198 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) | 
|  | 199 | { | 
|  | 200 | return __cfg80211_rdev_from_attrs(netns, info->attrs); | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | static int validate_beacon_head(const struct nlattr *attr, | 
|  | 204 | struct netlink_ext_ack *extack) | 
|  | 205 | { | 
|  | 206 | const u8 *data = nla_data(attr); | 
|  | 207 | unsigned int len = nla_len(attr); | 
|  | 208 | const struct element *elem; | 
|  | 209 | const struct ieee80211_mgmt *mgmt = (void *)data; | 
|  | 210 | unsigned int fixedlen = offsetof(struct ieee80211_mgmt, | 
|  | 211 | u.beacon.variable); | 
|  | 212 |  | 
|  | 213 | if (len < fixedlen) | 
|  | 214 | goto err; | 
|  | 215 |  | 
|  | 216 | if (ieee80211_hdrlen(mgmt->frame_control) != | 
|  | 217 | offsetof(struct ieee80211_mgmt, u.beacon)) | 
|  | 218 | goto err; | 
|  | 219 |  | 
|  | 220 | data += fixedlen; | 
|  | 221 | len -= fixedlen; | 
|  | 222 |  | 
|  | 223 | for_each_element(elem, data, len) { | 
|  | 224 | /* nothing */ | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | if (for_each_element_completed(elem, data, len)) | 
|  | 228 | return 0; | 
|  | 229 |  | 
|  | 230 | err: | 
|  | 231 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); | 
|  | 232 | return -EINVAL; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | /* policy for the attributes */ | 
|  | 236 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { | 
|  | 237 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, | 
|  | 238 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | 
|  | 239 | .len = 20-1 }, | 
|  | 240 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, | 
|  | 241 |  | 
|  | 242 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, | 
|  | 243 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, | 
|  | 244 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, | 
|  | 245 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | 
|  | 246 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | 
|  | 247 |  | 
|  | 248 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, | 
|  | 249 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | 
|  | 250 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | 
|  | 251 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | 
|  | 252 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, | 
|  | 253 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, | 
|  | 254 |  | 
|  | 255 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | 
|  | 256 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | 
|  | 257 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | 
|  | 258 |  | 
|  | 259 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, | 
|  | 260 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | 
|  | 261 |  | 
|  | 262 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, | 
|  | 263 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, | 
|  | 264 | .len = WLAN_MAX_KEY_LEN }, | 
|  | 265 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | 
|  | 266 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | 
|  | 267 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | 
|  | 268 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, | 
|  | 269 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, | 
|  | 270 |  | 
|  | 271 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | 
|  | 272 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | 
|  | 273 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | 
|  | 274 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 275 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | 
|  | 276 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 277 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, | 
|  | 278 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | 
|  | 279 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | 
|  | 280 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | 
|  | 281 | .len = NL80211_MAX_SUPP_RATES }, | 
|  | 282 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, | 
|  | 283 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, | 
|  | 284 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, | 
|  | 285 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, | 
|  | 286 | .len = IEEE80211_MAX_MESH_ID_LEN }, | 
|  | 287 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_BINARY, | 
|  | 288 | .len = ETH_ALEN }, | 
|  | 289 |  | 
|  | 290 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, | 
|  | 291 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | 
|  | 292 |  | 
|  | 293 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, | 
|  | 294 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | 
|  | 295 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | 
|  | 296 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, | 
|  | 297 | .len = NL80211_MAX_SUPP_RATES }, | 
|  | 298 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, | 
|  | 299 |  | 
|  | 300 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, | 
|  | 301 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, | 
|  | 302 |  | 
|  | 303 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, | 
|  | 304 |  | 
|  | 305 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | 
|  | 306 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | 
|  | 307 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 308 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, | 
|  | 309 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | 
|  | 310 |  | 
|  | 311 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | 
|  | 312 | .len = IEEE80211_MAX_SSID_LEN }, | 
|  | 313 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | 
|  | 314 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | 
|  | 315 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, | 
|  | 316 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, | 
|  | 317 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, | 
|  | 318 | [NL80211_ATTR_STA_FLAGS2] = { | 
|  | 319 | .len = sizeof(struct nl80211_sta_flag_update), | 
|  | 320 | }, | 
|  | 321 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, | 
|  | 322 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, | 
|  | 323 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | 
|  | 324 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, | 
|  | 325 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, | 
|  | 326 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | 
|  | 327 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | 
|  | 328 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, | 
|  | 329 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, | 
|  | 330 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, | 
|  | 331 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, | 
|  | 332 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | 
|  | 333 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, | 
|  | 334 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, | 
|  | 335 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 336 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | 
|  | 337 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, | 
|  | 338 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, | 
|  | 339 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, | 
|  | 340 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, | 
|  | 341 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, | 
|  | 342 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | 
|  | 343 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, | 
|  | 344 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, | 
|  | 345 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | 
|  | 346 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, | 
|  | 347 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, | 
|  | 348 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, | 
|  | 349 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, | 
|  | 350 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, | 
|  | 351 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, | 
|  | 352 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, | 
|  | 353 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, | 
|  | 354 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, | 
|  | 355 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, | 
|  | 356 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 357 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | 
|  | 358 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 359 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, | 
|  | 360 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, | 
|  | 361 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, | 
|  | 362 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, | 
|  | 363 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | 
|  | 364 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | 
|  | 365 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | 
|  | 366 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | 
|  | 367 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, | 
|  | 368 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, | 
|  | 369 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, | 
|  | 370 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 371 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, | 
|  | 372 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, | 
|  | 373 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | 
|  | 374 | .len = NL80211_HT_CAPABILITY_LEN | 
|  | 375 | }, | 
|  | 376 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, | 
|  | 377 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, | 
|  | 378 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, | 
|  | 379 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, | 
|  | 380 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, | 
|  | 381 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, | 
|  | 382 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, | 
|  | 383 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, | 
|  | 384 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, | 
|  | 385 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | 
|  | 386 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 }, | 
|  | 387 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, | 
|  | 388 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | 
|  | 389 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, | 
|  | 390 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | 
|  | 391 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, | 
|  | 392 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, | 
|  | 393 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | 
|  | 394 | .len = NL80211_VHT_CAPABILITY_LEN, | 
|  | 395 | }, | 
|  | 396 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, | 
|  | 397 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | 
|  | 398 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 399 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, | 
|  | 400 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, | 
|  | 401 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | 
|  | 402 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | 
|  | 403 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, | 
|  | 404 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | 
|  | 405 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, | 
|  | 406 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | 
|  | 407 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, | 
|  | 408 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, | 
|  | 409 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, | 
|  | 410 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | 
|  | 411 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | 
|  | 412 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, | 
|  | 413 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | 
|  | 414 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, | 
|  | 415 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | 
|  | 416 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, | 
|  | 417 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, | 
|  | 418 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, | 
|  | 419 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, | 
|  | 420 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, | 
|  | 421 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | 
|  | 422 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | 
|  | 423 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, | 
|  | 424 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, | 
|  | 425 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, | 
|  | 426 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, | 
|  | 427 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, | 
|  | 428 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, | 
|  | 429 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, | 
|  | 430 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, | 
|  | 431 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, | 
|  | 432 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { | 
|  | 433 | .len = VHT_MUMIMO_GROUPS_DATA_LEN | 
|  | 434 | }, | 
|  | 435 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, | 
|  | 436 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, | 
|  | 437 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, | 
|  | 438 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, | 
|  | 439 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, | 
|  | 440 | .len = FILS_MAX_KEK_LEN }, | 
|  | 441 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, | 
|  | 442 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, | 
|  | 443 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, | 
|  | 444 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, | 
|  | 445 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { | 
|  | 446 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | 
|  | 447 | }, | 
|  | 448 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, | 
|  | 449 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, | 
|  | 450 | .len = FILS_ERP_MAX_USERNAME_LEN }, | 
|  | 451 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, | 
|  | 452 | .len = FILS_ERP_MAX_REALM_LEN }, | 
|  | 453 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, | 
|  | 454 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, | 
|  | 455 | .len = FILS_ERP_MAX_RRK_LEN }, | 
|  | 456 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, | 
|  | 457 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, | 
|  | 458 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, | 
|  | 459 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, | 
|  | 460 |  | 
|  | 461 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, | 
|  | 462 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, | 
|  | 463 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, | 
|  | 464 | [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY, | 
|  | 465 | .len = NL80211_HE_MAX_CAPABILITY_LEN }, | 
|  | 466 | }; | 
|  | 467 |  | 
|  | 468 | /* policy for the key attributes */ | 
|  | 469 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { | 
|  | 470 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, | 
|  | 471 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, | 
|  | 472 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | 
|  | 473 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, | 
|  | 474 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, | 
|  | 475 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | 
|  | 476 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, | 
|  | 477 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, | 
|  | 478 | }; | 
|  | 479 |  | 
|  | 480 | /* policy for the key default flags */ | 
|  | 481 | static const struct nla_policy | 
|  | 482 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | 
|  | 483 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | 
|  | 484 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | 
|  | 485 | }; | 
|  | 486 |  | 
|  | 487 | #ifdef CONFIG_PM | 
|  | 488 | /* policy for WoWLAN attributes */ | 
|  | 489 | static const struct nla_policy | 
|  | 490 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | 
|  | 491 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | 
|  | 492 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | 
|  | 493 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | 
|  | 494 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | 
|  | 495 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, | 
|  | 496 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | 
|  | 497 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | 
|  | 498 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | 
|  | 499 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, | 
|  | 500 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, | 
|  | 501 | }; | 
|  | 502 |  | 
|  | 503 | static const struct nla_policy | 
|  | 504 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | 
|  | 505 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | 
|  | 506 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | 
|  | 507 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | 
|  | 508 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | 
|  | 509 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | 
|  | 510 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | 
|  | 511 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | 
|  | 512 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | 
|  | 513 | }, | 
|  | 514 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | 
|  | 515 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | 
|  | 516 | }, | 
|  | 517 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | 
|  | 518 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | 
|  | 519 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | 
|  | 520 | }; | 
|  | 521 | #endif /* CONFIG_PM */ | 
|  | 522 |  | 
|  | 523 | /* policy for coalesce rule attributes */ | 
|  | 524 | static const struct nla_policy | 
|  | 525 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | 
|  | 526 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | 
|  | 527 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | 
|  | 528 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | 
|  | 529 | }; | 
|  | 530 |  | 
|  | 531 | /* policy for GTK rekey offload attributes */ | 
|  | 532 | static const struct nla_policy | 
|  | 533 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | 
|  | 534 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | 
|  | 535 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | 
|  | 536 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | 
|  | 537 | }; | 
|  | 538 |  | 
|  | 539 | static const struct nla_policy | 
|  | 540 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | 
|  | 541 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, | 
|  | 542 | .len = IEEE80211_MAX_SSID_LEN }, | 
|  | 543 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN }, | 
|  | 544 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, | 
|  | 545 | }; | 
|  | 546 |  | 
|  | 547 | static const struct nla_policy | 
|  | 548 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | 
|  | 549 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | 
|  | 550 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | 
|  | 551 | }; | 
|  | 552 |  | 
|  | 553 | static const struct nla_policy | 
|  | 554 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | 
|  | 555 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | 
|  | 556 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | 
|  | 557 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | 
|  | 558 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | 
|  | 559 | }, | 
|  | 560 | }; | 
|  | 561 |  | 
|  | 562 | /* policy for NAN function attributes */ | 
|  | 563 | static const struct nla_policy | 
|  | 564 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | 
|  | 565 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, | 
|  | 566 | [NL80211_NAN_FUNC_SERVICE_ID] = { | 
|  | 567 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, | 
|  | 568 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | 
|  | 569 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | 
|  | 570 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | 
|  | 571 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | 
|  | 572 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | 
|  | 573 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, | 
|  | 574 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, | 
|  | 575 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | 
|  | 576 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, | 
|  | 577 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, | 
|  | 578 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | 
|  | 579 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | 
|  | 580 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | 
|  | 581 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, | 
|  | 582 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, | 
|  | 583 | }; | 
|  | 584 |  | 
|  | 585 | /* policy for Service Response Filter attributes */ | 
|  | 586 | static const struct nla_policy | 
|  | 587 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { | 
|  | 588 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, | 
|  | 589 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, | 
|  | 590 | .len =  NL80211_NAN_FUNC_SRF_MAX_LEN }, | 
|  | 591 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, | 
|  | 592 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, | 
|  | 593 | }; | 
|  | 594 |  | 
|  | 595 | /* policy for packet pattern attributes */ | 
|  | 596 | static const struct nla_policy | 
|  | 597 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { | 
|  | 598 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, | 
|  | 599 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, | 
|  | 600 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, | 
|  | 601 | }; | 
|  | 602 |  | 
|  | 603 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, | 
|  | 604 | struct netlink_callback *cb, | 
|  | 605 | struct cfg80211_registered_device **rdev, | 
|  | 606 | struct wireless_dev **wdev) | 
|  | 607 | { | 
|  | 608 | int err; | 
|  | 609 |  | 
|  | 610 | if (!cb->args[0]) { | 
|  | 611 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | 
|  | 612 | genl_family_attrbuf(&nl80211_fam), | 
|  | 613 | nl80211_fam.maxattr, nl80211_policy, NULL); | 
|  | 614 | if (err) | 
|  | 615 | return err; | 
|  | 616 |  | 
|  | 617 | *wdev = __cfg80211_wdev_from_attrs( | 
|  | 618 | sock_net(skb->sk), | 
|  | 619 | genl_family_attrbuf(&nl80211_fam)); | 
|  | 620 | if (IS_ERR(*wdev)) | 
|  | 621 | return PTR_ERR(*wdev); | 
|  | 622 | *rdev = wiphy_to_rdev((*wdev)->wiphy); | 
|  | 623 | /* 0 is the first index - add 1 to parse only once */ | 
|  | 624 | cb->args[0] = (*rdev)->wiphy_idx + 1; | 
|  | 625 | cb->args[1] = (*wdev)->identifier; | 
|  | 626 | } else { | 
|  | 627 | /* subtract the 1 again here */ | 
|  | 628 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | 
|  | 629 | struct wireless_dev *tmp; | 
|  | 630 |  | 
|  | 631 | if (!wiphy) | 
|  | 632 | return -ENODEV; | 
|  | 633 | *rdev = wiphy_to_rdev(wiphy); | 
|  | 634 | *wdev = NULL; | 
|  | 635 |  | 
|  | 636 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { | 
|  | 637 | if (tmp->identifier == cb->args[1]) { | 
|  | 638 | *wdev = tmp; | 
|  | 639 | break; | 
|  | 640 | } | 
|  | 641 | } | 
|  | 642 |  | 
|  | 643 | if (!*wdev) | 
|  | 644 | return -ENODEV; | 
|  | 645 | } | 
|  | 646 |  | 
|  | 647 | return 0; | 
|  | 648 | } | 
|  | 649 |  | 
|  | 650 | /* IE validation */ | 
|  | 651 | static bool is_valid_ie_attr(const struct nlattr *attr) | 
|  | 652 | { | 
|  | 653 | const u8 *pos; | 
|  | 654 | int len; | 
|  | 655 |  | 
|  | 656 | if (!attr) | 
|  | 657 | return true; | 
|  | 658 |  | 
|  | 659 | pos = nla_data(attr); | 
|  | 660 | len = nla_len(attr); | 
|  | 661 |  | 
|  | 662 | while (len) { | 
|  | 663 | u8 elemlen; | 
|  | 664 |  | 
|  | 665 | if (len < 2) | 
|  | 666 | return false; | 
|  | 667 | len -= 2; | 
|  | 668 |  | 
|  | 669 | elemlen = pos[1]; | 
|  | 670 | if (elemlen > len) | 
|  | 671 | return false; | 
|  | 672 |  | 
|  | 673 | len -= elemlen; | 
|  | 674 | pos += 2 + elemlen; | 
|  | 675 | } | 
|  | 676 |  | 
|  | 677 | return true; | 
|  | 678 | } | 
|  | 679 |  | 
|  | 680 | /* message building helper */ | 
|  | 681 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, | 
|  | 682 | int flags, u8 cmd) | 
|  | 683 | { | 
|  | 684 | /* since there is no private header just add the generic one */ | 
|  | 685 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); | 
|  | 686 | } | 
|  | 687 |  | 
|  | 688 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, | 
|  | 689 | const struct ieee80211_reg_rule *rule) | 
|  | 690 | { | 
|  | 691 | int j; | 
|  | 692 | struct nlattr *nl_wmm_rules = | 
|  | 693 | nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM); | 
|  | 694 |  | 
|  | 695 | if (!nl_wmm_rules) | 
|  | 696 | goto nla_put_failure; | 
|  | 697 |  | 
|  | 698 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { | 
|  | 699 | struct nlattr *nl_wmm_rule = nla_nest_start(msg, j); | 
|  | 700 |  | 
|  | 701 | if (!nl_wmm_rule) | 
|  | 702 | goto nla_put_failure; | 
|  | 703 |  | 
|  | 704 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, | 
|  | 705 | rule->wmm_rule.client[j].cw_min) || | 
|  | 706 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, | 
|  | 707 | rule->wmm_rule.client[j].cw_max) || | 
|  | 708 | nla_put_u8(msg, NL80211_WMMR_AIFSN, | 
|  | 709 | rule->wmm_rule.client[j].aifsn) || | 
|  | 710 | nla_put_u16(msg, NL80211_WMMR_TXOP, | 
|  | 711 | rule->wmm_rule.client[j].cot)) | 
|  | 712 | goto nla_put_failure; | 
|  | 713 |  | 
|  | 714 | nla_nest_end(msg, nl_wmm_rule); | 
|  | 715 | } | 
|  | 716 | nla_nest_end(msg, nl_wmm_rules); | 
|  | 717 |  | 
|  | 718 | return 0; | 
|  | 719 |  | 
|  | 720 | nla_put_failure: | 
|  | 721 | return -ENOBUFS; | 
|  | 722 | } | 
|  | 723 |  | 
|  | 724 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, | 
|  | 725 | struct ieee80211_channel *chan, | 
|  | 726 | bool large) | 
|  | 727 | { | 
|  | 728 | /* Some channels must be completely excluded from the | 
|  | 729 | * list to protect old user-space tools from breaking | 
|  | 730 | */ | 
|  | 731 | if (!large && chan->flags & | 
|  | 732 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | 
|  | 733 | return 0; | 
|  | 734 |  | 
|  | 735 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, | 
|  | 736 | chan->center_freq)) | 
|  | 737 | goto nla_put_failure; | 
|  | 738 |  | 
|  | 739 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && | 
|  | 740 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | 
|  | 741 | goto nla_put_failure; | 
|  | 742 | if (chan->flags & IEEE80211_CHAN_NO_IR) { | 
|  | 743 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | 
|  | 744 | goto nla_put_failure; | 
|  | 745 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | 
|  | 746 | goto nla_put_failure; | 
|  | 747 | } | 
|  | 748 | if (chan->flags & IEEE80211_CHAN_RADAR) { | 
|  | 749 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | 
|  | 750 | goto nla_put_failure; | 
|  | 751 | if (large) { | 
|  | 752 | u32 time; | 
|  | 753 |  | 
|  | 754 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | 
|  | 755 |  | 
|  | 756 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | 
|  | 757 | chan->dfs_state)) | 
|  | 758 | goto nla_put_failure; | 
|  | 759 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | 
|  | 760 | time)) | 
|  | 761 | goto nla_put_failure; | 
|  | 762 | if (nla_put_u32(msg, | 
|  | 763 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | 
|  | 764 | chan->dfs_cac_ms)) | 
|  | 765 | goto nla_put_failure; | 
|  | 766 | } | 
|  | 767 | } | 
|  | 768 |  | 
|  | 769 | if (large) { | 
|  | 770 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | 
|  | 771 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | 
|  | 772 | goto nla_put_failure; | 
|  | 773 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | 
|  | 774 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | 
|  | 775 | goto nla_put_failure; | 
|  | 776 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | 
|  | 777 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | 
|  | 778 | goto nla_put_failure; | 
|  | 779 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | 
|  | 780 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | 
|  | 781 | goto nla_put_failure; | 
|  | 782 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && | 
|  | 783 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | 
|  | 784 | goto nla_put_failure; | 
|  | 785 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && | 
|  | 786 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | 
|  | 787 | goto nla_put_failure; | 
|  | 788 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && | 
|  | 789 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | 
|  | 790 | goto nla_put_failure; | 
|  | 791 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | 
|  | 792 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | 
|  | 793 | goto nla_put_failure; | 
|  | 794 | } | 
|  | 795 |  | 
|  | 796 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, | 
|  | 797 | DBM_TO_MBM(chan->max_power))) | 
|  | 798 | goto nla_put_failure; | 
|  | 799 |  | 
|  | 800 | if (large) { | 
|  | 801 | const struct ieee80211_reg_rule *rule = | 
|  | 802 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); | 
|  | 803 |  | 
|  | 804 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { | 
|  | 805 | if (nl80211_msg_put_wmm_rules(msg, rule)) | 
|  | 806 | goto nla_put_failure; | 
|  | 807 | } | 
|  | 808 | } | 
|  | 809 |  | 
|  | 810 | return 0; | 
|  | 811 |  | 
|  | 812 | nla_put_failure: | 
|  | 813 | return -ENOBUFS; | 
|  | 814 | } | 
|  | 815 |  | 
|  | 816 | static bool nl80211_put_txq_stats(struct sk_buff *msg, | 
|  | 817 | struct cfg80211_txq_stats *txqstats, | 
|  | 818 | int attrtype) | 
|  | 819 | { | 
|  | 820 | struct nlattr *txqattr; | 
|  | 821 |  | 
|  | 822 | #define PUT_TXQVAL_U32(attr, memb) do {					  \ | 
|  | 823 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) &&	  \ | 
|  | 824 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ | 
|  | 825 | return false;						  \ | 
|  | 826 | } while (0) | 
|  | 827 |  | 
|  | 828 | txqattr = nla_nest_start(msg, attrtype); | 
|  | 829 | if (!txqattr) | 
|  | 830 | return false; | 
|  | 831 |  | 
|  | 832 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); | 
|  | 833 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); | 
|  | 834 | PUT_TXQVAL_U32(FLOWS, flows); | 
|  | 835 | PUT_TXQVAL_U32(DROPS, drops); | 
|  | 836 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); | 
|  | 837 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); | 
|  | 838 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); | 
|  | 839 | PUT_TXQVAL_U32(COLLISIONS, collisions); | 
|  | 840 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); | 
|  | 841 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); | 
|  | 842 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); | 
|  | 843 | nla_nest_end(msg, txqattr); | 
|  | 844 |  | 
|  | 845 | #undef PUT_TXQVAL_U32 | 
|  | 846 | return true; | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 | /* netlink command implementations */ | 
|  | 850 |  | 
|  | 851 | struct key_parse { | 
|  | 852 | struct key_params p; | 
|  | 853 | int idx; | 
|  | 854 | int type; | 
|  | 855 | bool def, defmgmt; | 
|  | 856 | bool def_uni, def_multi; | 
|  | 857 | }; | 
|  | 858 |  | 
|  | 859 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, | 
|  | 860 | struct key_parse *k) | 
|  | 861 | { | 
|  | 862 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | 
|  | 863 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | 
|  | 864 | nl80211_key_policy, info->extack); | 
|  | 865 | if (err) | 
|  | 866 | return err; | 
|  | 867 |  | 
|  | 868 | k->def = !!tb[NL80211_KEY_DEFAULT]; | 
|  | 869 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | 
|  | 870 |  | 
|  | 871 | if (k->def) { | 
|  | 872 | k->def_uni = true; | 
|  | 873 | k->def_multi = true; | 
|  | 874 | } | 
|  | 875 | if (k->defmgmt) | 
|  | 876 | k->def_multi = true; | 
|  | 877 |  | 
|  | 878 | if (tb[NL80211_KEY_IDX]) | 
|  | 879 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | 
|  | 880 |  | 
|  | 881 | if (tb[NL80211_KEY_DATA]) { | 
|  | 882 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | 
|  | 883 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | 
|  | 884 | } | 
|  | 885 |  | 
|  | 886 | if (tb[NL80211_KEY_SEQ]) { | 
|  | 887 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | 
|  | 888 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | 
|  | 889 | } | 
|  | 890 |  | 
|  | 891 | if (tb[NL80211_KEY_CIPHER]) | 
|  | 892 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | 
|  | 893 |  | 
|  | 894 | if (tb[NL80211_KEY_TYPE]) { | 
|  | 895 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | 
|  | 896 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | 
|  | 897 | return genl_err_attr(info, -EINVAL, | 
|  | 898 | tb[NL80211_KEY_TYPE]); | 
|  | 899 | } | 
|  | 900 |  | 
|  | 901 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { | 
|  | 902 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | 
|  | 903 |  | 
|  | 904 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | 
|  | 905 | tb[NL80211_KEY_DEFAULT_TYPES], | 
|  | 906 | nl80211_key_default_policy, | 
|  | 907 | info->extack); | 
|  | 908 | if (err) | 
|  | 909 | return err; | 
|  | 910 |  | 
|  | 911 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | 
|  | 912 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | 
|  | 913 | } | 
|  | 914 |  | 
|  | 915 | return 0; | 
|  | 916 | } | 
|  | 917 |  | 
|  | 918 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | 
|  | 919 | { | 
|  | 920 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | 
|  | 921 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | 
|  | 922 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | 
|  | 923 | } | 
|  | 924 |  | 
|  | 925 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | 
|  | 926 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | 
|  | 927 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | 
|  | 928 | } | 
|  | 929 |  | 
|  | 930 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | 
|  | 931 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | 
|  | 932 |  | 
|  | 933 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | 
|  | 934 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | 
|  | 935 |  | 
|  | 936 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | 
|  | 937 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | 
|  | 938 |  | 
|  | 939 | if (k->def) { | 
|  | 940 | k->def_uni = true; | 
|  | 941 | k->def_multi = true; | 
|  | 942 | } | 
|  | 943 | if (k->defmgmt) | 
|  | 944 | k->def_multi = true; | 
|  | 945 |  | 
|  | 946 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | 
|  | 947 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | 
|  | 948 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) { | 
|  | 949 | GENL_SET_ERR_MSG(info, "key type out of range"); | 
|  | 950 | return -EINVAL; | 
|  | 951 | } | 
|  | 952 | } | 
|  | 953 |  | 
|  | 954 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { | 
|  | 955 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | 
|  | 956 | int err = nla_parse_nested(kdt, | 
|  | 957 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | 
|  | 958 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | 
|  | 959 | nl80211_key_default_policy, | 
|  | 960 | info->extack); | 
|  | 961 | if (err) | 
|  | 962 | return err; | 
|  | 963 |  | 
|  | 964 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | 
|  | 965 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | 
|  | 966 | } | 
|  | 967 |  | 
|  | 968 | return 0; | 
|  | 969 | } | 
|  | 970 |  | 
|  | 971 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | 
|  | 972 | { | 
|  | 973 | int err; | 
|  | 974 |  | 
|  | 975 | memset(k, 0, sizeof(*k)); | 
|  | 976 | k->idx = -1; | 
|  | 977 | k->type = -1; | 
|  | 978 |  | 
|  | 979 | if (info->attrs[NL80211_ATTR_KEY]) | 
|  | 980 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); | 
|  | 981 | else | 
|  | 982 | err = nl80211_parse_key_old(info, k); | 
|  | 983 |  | 
|  | 984 | if (err) | 
|  | 985 | return err; | 
|  | 986 |  | 
|  | 987 | if (k->def && k->defmgmt) { | 
|  | 988 | GENL_SET_ERR_MSG(info, "key with def && defmgmt is invalid"); | 
|  | 989 | return -EINVAL; | 
|  | 990 | } | 
|  | 991 |  | 
|  | 992 | if (k->defmgmt) { | 
|  | 993 | if (k->def_uni || !k->def_multi) { | 
|  | 994 | GENL_SET_ERR_MSG(info, "defmgmt key must be mcast"); | 
|  | 995 | return -EINVAL; | 
|  | 996 | } | 
|  | 997 | } | 
|  | 998 |  | 
|  | 999 | if (k->idx != -1) { | 
|  | 1000 | if (k->defmgmt) { | 
|  | 1001 | if (k->idx < 4 || k->idx > 5) { | 
|  | 1002 | GENL_SET_ERR_MSG(info, | 
|  | 1003 | "defmgmt key idx not 4 or 5"); | 
|  | 1004 | return -EINVAL; | 
|  | 1005 | } | 
|  | 1006 | } else if (k->def) { | 
|  | 1007 | if (k->idx < 0 || k->idx > 3) { | 
|  | 1008 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); | 
|  | 1009 | return -EINVAL; | 
|  | 1010 | } | 
|  | 1011 | } else { | 
|  | 1012 | if (k->idx < 0 || k->idx > 5) { | 
|  | 1013 | GENL_SET_ERR_MSG(info, "key idx not 0-5"); | 
|  | 1014 | return -EINVAL; | 
|  | 1015 | } | 
|  | 1016 | } | 
|  | 1017 | } | 
|  | 1018 |  | 
|  | 1019 | return 0; | 
|  | 1020 | } | 
|  | 1021 |  | 
|  | 1022 | static struct cfg80211_cached_keys * | 
|  | 1023 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | 
|  | 1024 | struct genl_info *info, bool *no_ht) | 
|  | 1025 | { | 
|  | 1026 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; | 
|  | 1027 | struct key_parse parse; | 
|  | 1028 | struct nlattr *key; | 
|  | 1029 | struct cfg80211_cached_keys *result; | 
|  | 1030 | int rem, err, def = 0; | 
|  | 1031 | bool have_key = false; | 
|  | 1032 |  | 
|  | 1033 | nla_for_each_nested(key, keys, rem) { | 
|  | 1034 | have_key = true; | 
|  | 1035 | break; | 
|  | 1036 | } | 
|  | 1037 |  | 
|  | 1038 | if (!have_key) | 
|  | 1039 | return NULL; | 
|  | 1040 |  | 
|  | 1041 | result = kzalloc(sizeof(*result), GFP_KERNEL); | 
|  | 1042 | if (!result) | 
|  | 1043 | return ERR_PTR(-ENOMEM); | 
|  | 1044 |  | 
|  | 1045 | result->def = -1; | 
|  | 1046 |  | 
|  | 1047 | nla_for_each_nested(key, keys, rem) { | 
|  | 1048 | memset(&parse, 0, sizeof(parse)); | 
|  | 1049 | parse.idx = -1; | 
|  | 1050 |  | 
|  | 1051 | err = nl80211_parse_key_new(info, key, &parse); | 
|  | 1052 | if (err) | 
|  | 1053 | goto error; | 
|  | 1054 | err = -EINVAL; | 
|  | 1055 | if (!parse.p.key) | 
|  | 1056 | goto error; | 
|  | 1057 | if (parse.idx < 0 || parse.idx > 3) { | 
|  | 1058 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); | 
|  | 1059 | goto error; | 
|  | 1060 | } | 
|  | 1061 | if (parse.def) { | 
|  | 1062 | if (def) { | 
|  | 1063 | GENL_SET_ERR_MSG(info, | 
|  | 1064 | "only one key can be default"); | 
|  | 1065 | goto error; | 
|  | 1066 | } | 
|  | 1067 | def = 1; | 
|  | 1068 | result->def = parse.idx; | 
|  | 1069 | if (!parse.def_uni || !parse.def_multi) | 
|  | 1070 | goto error; | 
|  | 1071 | } else if (parse.defmgmt) | 
|  | 1072 | goto error; | 
|  | 1073 | err = cfg80211_validate_key_settings(rdev, &parse.p, | 
|  | 1074 | parse.idx, false, NULL); | 
|  | 1075 | if (err) | 
|  | 1076 | goto error; | 
|  | 1077 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && | 
|  | 1078 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | 
|  | 1079 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); | 
|  | 1080 | err = -EINVAL; | 
|  | 1081 | goto error; | 
|  | 1082 | } | 
|  | 1083 | result->params[parse.idx].cipher = parse.p.cipher; | 
|  | 1084 | result->params[parse.idx].key_len = parse.p.key_len; | 
|  | 1085 | result->params[parse.idx].key = result->data[parse.idx]; | 
|  | 1086 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | 
|  | 1087 |  | 
|  | 1088 | /* must be WEP key if we got here */ | 
|  | 1089 | if (no_ht) | 
|  | 1090 | *no_ht = true; | 
|  | 1091 | } | 
|  | 1092 |  | 
|  | 1093 | if (result->def < 0) { | 
|  | 1094 | err = -EINVAL; | 
|  | 1095 | GENL_SET_ERR_MSG(info, "need a default/TX key"); | 
|  | 1096 | goto error; | 
|  | 1097 | } | 
|  | 1098 |  | 
|  | 1099 | return result; | 
|  | 1100 | error: | 
|  | 1101 | kfree(result); | 
|  | 1102 | return ERR_PTR(err); | 
|  | 1103 | } | 
|  | 1104 |  | 
|  | 1105 | static int nl80211_key_allowed(struct wireless_dev *wdev) | 
|  | 1106 | { | 
|  | 1107 | ASSERT_WDEV_LOCK(wdev); | 
|  | 1108 |  | 
|  | 1109 | switch (wdev->iftype) { | 
|  | 1110 | case NL80211_IFTYPE_AP: | 
|  | 1111 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 1112 | case NL80211_IFTYPE_P2P_GO: | 
|  | 1113 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 1114 | break; | 
|  | 1115 | case NL80211_IFTYPE_ADHOC: | 
|  | 1116 | case NL80211_IFTYPE_STATION: | 
|  | 1117 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 1118 | if (!wdev->current_bss) | 
|  | 1119 | return -ENOLINK; | 
|  | 1120 | break; | 
|  | 1121 | case NL80211_IFTYPE_UNSPECIFIED: | 
|  | 1122 | case NL80211_IFTYPE_OCB: | 
|  | 1123 | case NL80211_IFTYPE_MONITOR: | 
|  | 1124 | case NL80211_IFTYPE_NAN: | 
|  | 1125 | case NL80211_IFTYPE_P2P_DEVICE: | 
|  | 1126 | case NL80211_IFTYPE_WDS: | 
|  | 1127 | case NUM_NL80211_IFTYPES: | 
|  | 1128 | return -EINVAL; | 
|  | 1129 | } | 
|  | 1130 |  | 
|  | 1131 | return 0; | 
|  | 1132 | } | 
|  | 1133 |  | 
|  | 1134 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, | 
|  | 1135 | struct nlattr *tb) | 
|  | 1136 | { | 
|  | 1137 | struct ieee80211_channel *chan; | 
|  | 1138 |  | 
|  | 1139 | if (tb == NULL) | 
|  | 1140 | return NULL; | 
|  | 1141 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | 
|  | 1142 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | 
|  | 1143 | return NULL; | 
|  | 1144 | return chan; | 
|  | 1145 | } | 
|  | 1146 |  | 
|  | 1147 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) | 
|  | 1148 | { | 
|  | 1149 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | 
|  | 1150 | int i; | 
|  | 1151 |  | 
|  | 1152 | if (!nl_modes) | 
|  | 1153 | goto nla_put_failure; | 
|  | 1154 |  | 
|  | 1155 | i = 0; | 
|  | 1156 | while (ifmodes) { | 
|  | 1157 | if ((ifmodes & 1) && nla_put_flag(msg, i)) | 
|  | 1158 | goto nla_put_failure; | 
|  | 1159 | ifmodes >>= 1; | 
|  | 1160 | i++; | 
|  | 1161 | } | 
|  | 1162 |  | 
|  | 1163 | nla_nest_end(msg, nl_modes); | 
|  | 1164 | return 0; | 
|  | 1165 |  | 
|  | 1166 | nla_put_failure: | 
|  | 1167 | return -ENOBUFS; | 
|  | 1168 | } | 
|  | 1169 |  | 
|  | 1170 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | 
|  | 1171 | struct sk_buff *msg, | 
|  | 1172 | bool large) | 
|  | 1173 | { | 
|  | 1174 | struct nlattr *nl_combis; | 
|  | 1175 | int i, j; | 
|  | 1176 |  | 
|  | 1177 | nl_combis = nla_nest_start(msg, | 
|  | 1178 | NL80211_ATTR_INTERFACE_COMBINATIONS); | 
|  | 1179 | if (!nl_combis) | 
|  | 1180 | goto nla_put_failure; | 
|  | 1181 |  | 
|  | 1182 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | 
|  | 1183 | const struct ieee80211_iface_combination *c; | 
|  | 1184 | struct nlattr *nl_combi, *nl_limits; | 
|  | 1185 |  | 
|  | 1186 | c = &wiphy->iface_combinations[i]; | 
|  | 1187 |  | 
|  | 1188 | nl_combi = nla_nest_start(msg, i + 1); | 
|  | 1189 | if (!nl_combi) | 
|  | 1190 | goto nla_put_failure; | 
|  | 1191 |  | 
|  | 1192 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | 
|  | 1193 | if (!nl_limits) | 
|  | 1194 | goto nla_put_failure; | 
|  | 1195 |  | 
|  | 1196 | for (j = 0; j < c->n_limits; j++) { | 
|  | 1197 | struct nlattr *nl_limit; | 
|  | 1198 |  | 
|  | 1199 | nl_limit = nla_nest_start(msg, j + 1); | 
|  | 1200 | if (!nl_limit) | 
|  | 1201 | goto nla_put_failure; | 
|  | 1202 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, | 
|  | 1203 | c->limits[j].max)) | 
|  | 1204 | goto nla_put_failure; | 
|  | 1205 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, | 
|  | 1206 | c->limits[j].types)) | 
|  | 1207 | goto nla_put_failure; | 
|  | 1208 | nla_nest_end(msg, nl_limit); | 
|  | 1209 | } | 
|  | 1210 |  | 
|  | 1211 | nla_nest_end(msg, nl_limits); | 
|  | 1212 |  | 
|  | 1213 | if (c->beacon_int_infra_match && | 
|  | 1214 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | 
|  | 1215 | goto nla_put_failure; | 
|  | 1216 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | 
|  | 1217 | c->num_different_channels) || | 
|  | 1218 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | 
|  | 1219 | c->max_interfaces)) | 
|  | 1220 | goto nla_put_failure; | 
|  | 1221 | if (large && | 
|  | 1222 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | 
|  | 1223 | c->radar_detect_widths) || | 
|  | 1224 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | 
|  | 1225 | c->radar_detect_regions))) | 
|  | 1226 | goto nla_put_failure; | 
|  | 1227 | if (c->beacon_int_min_gcd && | 
|  | 1228 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, | 
|  | 1229 | c->beacon_int_min_gcd)) | 
|  | 1230 | goto nla_put_failure; | 
|  | 1231 |  | 
|  | 1232 | nla_nest_end(msg, nl_combi); | 
|  | 1233 | } | 
|  | 1234 |  | 
|  | 1235 | nla_nest_end(msg, nl_combis); | 
|  | 1236 |  | 
|  | 1237 | return 0; | 
|  | 1238 | nla_put_failure: | 
|  | 1239 | return -ENOBUFS; | 
|  | 1240 | } | 
|  | 1241 |  | 
|  | 1242 | #ifdef CONFIG_PM | 
|  | 1243 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, | 
|  | 1244 | struct sk_buff *msg) | 
|  | 1245 | { | 
|  | 1246 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; | 
|  | 1247 | struct nlattr *nl_tcp; | 
|  | 1248 |  | 
|  | 1249 | if (!tcp) | 
|  | 1250 | return 0; | 
|  | 1251 |  | 
|  | 1252 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | 
|  | 1253 | if (!nl_tcp) | 
|  | 1254 | return -ENOBUFS; | 
|  | 1255 |  | 
|  | 1256 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | 
|  | 1257 | tcp->data_payload_max)) | 
|  | 1258 | return -ENOBUFS; | 
|  | 1259 |  | 
|  | 1260 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | 
|  | 1261 | tcp->data_payload_max)) | 
|  | 1262 | return -ENOBUFS; | 
|  | 1263 |  | 
|  | 1264 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | 
|  | 1265 | return -ENOBUFS; | 
|  | 1266 |  | 
|  | 1267 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | 
|  | 1268 | sizeof(*tcp->tok), tcp->tok)) | 
|  | 1269 | return -ENOBUFS; | 
|  | 1270 |  | 
|  | 1271 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | 
|  | 1272 | tcp->data_interval_max)) | 
|  | 1273 | return -ENOBUFS; | 
|  | 1274 |  | 
|  | 1275 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | 
|  | 1276 | tcp->wake_payload_max)) | 
|  | 1277 | return -ENOBUFS; | 
|  | 1278 |  | 
|  | 1279 | nla_nest_end(msg, nl_tcp); | 
|  | 1280 | return 0; | 
|  | 1281 | } | 
|  | 1282 |  | 
|  | 1283 | static int nl80211_send_wowlan(struct sk_buff *msg, | 
|  | 1284 | struct cfg80211_registered_device *rdev, | 
|  | 1285 | bool large) | 
|  | 1286 | { | 
|  | 1287 | struct nlattr *nl_wowlan; | 
|  | 1288 |  | 
|  | 1289 | if (!rdev->wiphy.wowlan) | 
|  | 1290 | return 0; | 
|  | 1291 |  | 
|  | 1292 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | 
|  | 1293 | if (!nl_wowlan) | 
|  | 1294 | return -ENOBUFS; | 
|  | 1295 |  | 
|  | 1296 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && | 
|  | 1297 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | 
|  | 1298 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && | 
|  | 1299 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | 
|  | 1300 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && | 
|  | 1301 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | 
|  | 1302 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | 
|  | 1303 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | 
|  | 1304 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | 
|  | 1305 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | 
|  | 1306 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | 
|  | 1307 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | 
|  | 1308 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | 
|  | 1309 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | 
|  | 1310 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | 
|  | 1311 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | 
|  | 1312 | return -ENOBUFS; | 
|  | 1313 |  | 
|  | 1314 | if (rdev->wiphy.wowlan->n_patterns) { | 
|  | 1315 | struct nl80211_pattern_support pat = { | 
|  | 1316 | .max_patterns = rdev->wiphy.wowlan->n_patterns, | 
|  | 1317 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | 
|  | 1318 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | 
|  | 1319 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | 
|  | 1320 | }; | 
|  | 1321 |  | 
|  | 1322 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | 
|  | 1323 | sizeof(pat), &pat)) | 
|  | 1324 | return -ENOBUFS; | 
|  | 1325 | } | 
|  | 1326 |  | 
|  | 1327 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && | 
|  | 1328 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | 
|  | 1329 | rdev->wiphy.wowlan->max_nd_match_sets)) | 
|  | 1330 | return -ENOBUFS; | 
|  | 1331 |  | 
|  | 1332 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) | 
|  | 1333 | return -ENOBUFS; | 
|  | 1334 |  | 
|  | 1335 | nla_nest_end(msg, nl_wowlan); | 
|  | 1336 |  | 
|  | 1337 | return 0; | 
|  | 1338 | } | 
|  | 1339 | #endif | 
|  | 1340 |  | 
|  | 1341 | static int nl80211_send_coalesce(struct sk_buff *msg, | 
|  | 1342 | struct cfg80211_registered_device *rdev) | 
|  | 1343 | { | 
|  | 1344 | struct nl80211_coalesce_rule_support rule; | 
|  | 1345 |  | 
|  | 1346 | if (!rdev->wiphy.coalesce) | 
|  | 1347 | return 0; | 
|  | 1348 |  | 
|  | 1349 | rule.max_rules = rdev->wiphy.coalesce->n_rules; | 
|  | 1350 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | 
|  | 1351 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | 
|  | 1352 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | 
|  | 1353 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | 
|  | 1354 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | 
|  | 1355 |  | 
|  | 1356 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | 
|  | 1357 | return -ENOBUFS; | 
|  | 1358 |  | 
|  | 1359 | return 0; | 
|  | 1360 | } | 
|  | 1361 |  | 
|  | 1362 | static int | 
|  | 1363 | nl80211_send_iftype_data(struct sk_buff *msg, | 
|  | 1364 | const struct ieee80211_sband_iftype_data *iftdata) | 
|  | 1365 | { | 
|  | 1366 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; | 
|  | 1367 |  | 
|  | 1368 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, | 
|  | 1369 | iftdata->types_mask)) | 
|  | 1370 | return -ENOBUFS; | 
|  | 1371 |  | 
|  | 1372 | if (he_cap->has_he) { | 
|  | 1373 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, | 
|  | 1374 | sizeof(he_cap->he_cap_elem.mac_cap_info), | 
|  | 1375 | he_cap->he_cap_elem.mac_cap_info) || | 
|  | 1376 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, | 
|  | 1377 | sizeof(he_cap->he_cap_elem.phy_cap_info), | 
|  | 1378 | he_cap->he_cap_elem.phy_cap_info) || | 
|  | 1379 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, | 
|  | 1380 | sizeof(he_cap->he_mcs_nss_supp), | 
|  | 1381 | &he_cap->he_mcs_nss_supp) || | 
|  | 1382 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, | 
|  | 1383 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) | 
|  | 1384 | return -ENOBUFS; | 
|  | 1385 | } | 
|  | 1386 |  | 
|  | 1387 | return 0; | 
|  | 1388 | } | 
|  | 1389 |  | 
|  | 1390 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, | 
|  | 1391 | struct ieee80211_supported_band *sband) | 
|  | 1392 | { | 
|  | 1393 | struct nlattr *nl_rates, *nl_rate; | 
|  | 1394 | struct ieee80211_rate *rate; | 
|  | 1395 | int i; | 
|  | 1396 |  | 
|  | 1397 | /* add HT info */ | 
|  | 1398 | if (sband->ht_cap.ht_supported && | 
|  | 1399 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | 
|  | 1400 | sizeof(sband->ht_cap.mcs), | 
|  | 1401 | &sband->ht_cap.mcs) || | 
|  | 1402 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | 
|  | 1403 | sband->ht_cap.cap) || | 
|  | 1404 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | 
|  | 1405 | sband->ht_cap.ampdu_factor) || | 
|  | 1406 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | 
|  | 1407 | sband->ht_cap.ampdu_density))) | 
|  | 1408 | return -ENOBUFS; | 
|  | 1409 |  | 
|  | 1410 | /* add VHT info */ | 
|  | 1411 | if (sband->vht_cap.vht_supported && | 
|  | 1412 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | 
|  | 1413 | sizeof(sband->vht_cap.vht_mcs), | 
|  | 1414 | &sband->vht_cap.vht_mcs) || | 
|  | 1415 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | 
|  | 1416 | sband->vht_cap.cap))) | 
|  | 1417 | return -ENOBUFS; | 
|  | 1418 |  | 
|  | 1419 | if (sband->n_iftype_data) { | 
|  | 1420 | struct nlattr *nl_iftype_data = | 
|  | 1421 | nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA); | 
|  | 1422 | int err; | 
|  | 1423 |  | 
|  | 1424 | if (!nl_iftype_data) | 
|  | 1425 | return -ENOBUFS; | 
|  | 1426 |  | 
|  | 1427 | for (i = 0; i < sband->n_iftype_data; i++) { | 
|  | 1428 | struct nlattr *iftdata; | 
|  | 1429 |  | 
|  | 1430 | iftdata = nla_nest_start(msg, i + 1); | 
|  | 1431 | if (!iftdata) | 
|  | 1432 | return -ENOBUFS; | 
|  | 1433 |  | 
|  | 1434 | err = nl80211_send_iftype_data(msg, | 
|  | 1435 | &sband->iftype_data[i]); | 
|  | 1436 | if (err) | 
|  | 1437 | return err; | 
|  | 1438 |  | 
|  | 1439 | nla_nest_end(msg, iftdata); | 
|  | 1440 | } | 
|  | 1441 |  | 
|  | 1442 | nla_nest_end(msg, nl_iftype_data); | 
|  | 1443 | } | 
|  | 1444 |  | 
|  | 1445 | /* add bitrates */ | 
|  | 1446 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | 
|  | 1447 | if (!nl_rates) | 
|  | 1448 | return -ENOBUFS; | 
|  | 1449 |  | 
|  | 1450 | for (i = 0; i < sband->n_bitrates; i++) { | 
|  | 1451 | nl_rate = nla_nest_start(msg, i); | 
|  | 1452 | if (!nl_rate) | 
|  | 1453 | return -ENOBUFS; | 
|  | 1454 |  | 
|  | 1455 | rate = &sband->bitrates[i]; | 
|  | 1456 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | 
|  | 1457 | rate->bitrate)) | 
|  | 1458 | return -ENOBUFS; | 
|  | 1459 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | 
|  | 1460 | nla_put_flag(msg, | 
|  | 1461 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | 
|  | 1462 | return -ENOBUFS; | 
|  | 1463 |  | 
|  | 1464 | nla_nest_end(msg, nl_rate); | 
|  | 1465 | } | 
|  | 1466 |  | 
|  | 1467 | nla_nest_end(msg, nl_rates); | 
|  | 1468 |  | 
|  | 1469 | return 0; | 
|  | 1470 | } | 
|  | 1471 |  | 
|  | 1472 | static int | 
|  | 1473 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | 
|  | 1474 | const struct ieee80211_txrx_stypes *mgmt_stypes) | 
|  | 1475 | { | 
|  | 1476 | u16 stypes; | 
|  | 1477 | struct nlattr *nl_ftypes, *nl_ifs; | 
|  | 1478 | enum nl80211_iftype ift; | 
|  | 1479 | int i; | 
|  | 1480 |  | 
|  | 1481 | if (!mgmt_stypes) | 
|  | 1482 | return 0; | 
|  | 1483 |  | 
|  | 1484 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | 
|  | 1485 | if (!nl_ifs) | 
|  | 1486 | return -ENOBUFS; | 
|  | 1487 |  | 
|  | 1488 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | 
|  | 1489 | nl_ftypes = nla_nest_start(msg, ift); | 
|  | 1490 | if (!nl_ftypes) | 
|  | 1491 | return -ENOBUFS; | 
|  | 1492 | i = 0; | 
|  | 1493 | stypes = mgmt_stypes[ift].tx; | 
|  | 1494 | while (stypes) { | 
|  | 1495 | if ((stypes & 1) && | 
|  | 1496 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | 
|  | 1497 | (i << 4) | IEEE80211_FTYPE_MGMT)) | 
|  | 1498 | return -ENOBUFS; | 
|  | 1499 | stypes >>= 1; | 
|  | 1500 | i++; | 
|  | 1501 | } | 
|  | 1502 | nla_nest_end(msg, nl_ftypes); | 
|  | 1503 | } | 
|  | 1504 |  | 
|  | 1505 | nla_nest_end(msg, nl_ifs); | 
|  | 1506 |  | 
|  | 1507 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); | 
|  | 1508 | if (!nl_ifs) | 
|  | 1509 | return -ENOBUFS; | 
|  | 1510 |  | 
|  | 1511 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | 
|  | 1512 | nl_ftypes = nla_nest_start(msg, ift); | 
|  | 1513 | if (!nl_ftypes) | 
|  | 1514 | return -ENOBUFS; | 
|  | 1515 | i = 0; | 
|  | 1516 | stypes = mgmt_stypes[ift].rx; | 
|  | 1517 | while (stypes) { | 
|  | 1518 | if ((stypes & 1) && | 
|  | 1519 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | 
|  | 1520 | (i << 4) | IEEE80211_FTYPE_MGMT)) | 
|  | 1521 | return -ENOBUFS; | 
|  | 1522 | stypes >>= 1; | 
|  | 1523 | i++; | 
|  | 1524 | } | 
|  | 1525 | nla_nest_end(msg, nl_ftypes); | 
|  | 1526 | } | 
|  | 1527 | nla_nest_end(msg, nl_ifs); | 
|  | 1528 |  | 
|  | 1529 | return 0; | 
|  | 1530 | } | 
|  | 1531 |  | 
|  | 1532 | #define CMD(op, n)							\ | 
|  | 1533 | do {								\ | 
|  | 1534 | if (rdev->ops->op) {					\ | 
|  | 1535 | i++;						\ | 
|  | 1536 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) 	\ | 
|  | 1537 | goto nla_put_failure;			\ | 
|  | 1538 | }							\ | 
|  | 1539 | } while (0) | 
|  | 1540 |  | 
|  | 1541 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, | 
|  | 1542 | struct sk_buff *msg) | 
|  | 1543 | { | 
|  | 1544 | int i = 0; | 
|  | 1545 |  | 
|  | 1546 | /* | 
|  | 1547 | * do *NOT* add anything into this function, new things need to be | 
|  | 1548 | * advertised only to new versions of userspace that can deal with | 
|  | 1549 | * the split (and they can't possibly care about new features... | 
|  | 1550 | */ | 
|  | 1551 | CMD(add_virtual_intf, NEW_INTERFACE); | 
|  | 1552 | CMD(change_virtual_intf, SET_INTERFACE); | 
|  | 1553 | CMD(add_key, NEW_KEY); | 
|  | 1554 | CMD(start_ap, START_AP); | 
|  | 1555 | CMD(add_station, NEW_STATION); | 
|  | 1556 | CMD(add_mpath, NEW_MPATH); | 
|  | 1557 | CMD(update_mesh_config, SET_MESH_CONFIG); | 
|  | 1558 | CMD(change_bss, SET_BSS); | 
|  | 1559 | CMD(auth, AUTHENTICATE); | 
|  | 1560 | CMD(assoc, ASSOCIATE); | 
|  | 1561 | CMD(deauth, DEAUTHENTICATE); | 
|  | 1562 | CMD(disassoc, DISASSOCIATE); | 
|  | 1563 | CMD(join_ibss, JOIN_IBSS); | 
|  | 1564 | CMD(join_mesh, JOIN_MESH); | 
|  | 1565 | CMD(set_pmksa, SET_PMKSA); | 
|  | 1566 | CMD(del_pmksa, DEL_PMKSA); | 
|  | 1567 | CMD(flush_pmksa, FLUSH_PMKSA); | 
|  | 1568 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | 
|  | 1569 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | 
|  | 1570 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | 
|  | 1571 | CMD(mgmt_tx, FRAME); | 
|  | 1572 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | 
|  | 1573 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | 
|  | 1574 | i++; | 
|  | 1575 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | 
|  | 1576 | goto nla_put_failure; | 
|  | 1577 | } | 
|  | 1578 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || | 
|  | 1579 | rdev->ops->join_mesh) { | 
|  | 1580 | i++; | 
|  | 1581 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | 
|  | 1582 | goto nla_put_failure; | 
|  | 1583 | } | 
|  | 1584 | CMD(set_wds_peer, SET_WDS_PEER); | 
|  | 1585 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | 
|  | 1586 | CMD(tdls_mgmt, TDLS_MGMT); | 
|  | 1587 | CMD(tdls_oper, TDLS_OPER); | 
|  | 1588 | } | 
|  | 1589 | if (rdev->wiphy.max_sched_scan_reqs) | 
|  | 1590 | CMD(sched_scan_start, START_SCHED_SCAN); | 
|  | 1591 | CMD(probe_client, PROBE_CLIENT); | 
|  | 1592 | CMD(set_noack_map, SET_NOACK_MAP); | 
|  | 1593 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | 
|  | 1594 | i++; | 
|  | 1595 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | 
|  | 1596 | goto nla_put_failure; | 
|  | 1597 | } | 
|  | 1598 | CMD(start_p2p_device, START_P2P_DEVICE); | 
|  | 1599 | CMD(set_mcast_rate, SET_MCAST_RATE); | 
|  | 1600 | #ifdef CONFIG_NL80211_TESTMODE | 
|  | 1601 | CMD(testmode_cmd, TESTMODE); | 
|  | 1602 | #endif | 
|  | 1603 |  | 
|  | 1604 | if (rdev->ops->connect || rdev->ops->auth) { | 
|  | 1605 | i++; | 
|  | 1606 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | 
|  | 1607 | goto nla_put_failure; | 
|  | 1608 | } | 
|  | 1609 |  | 
|  | 1610 | if (rdev->ops->disconnect || rdev->ops->deauth) { | 
|  | 1611 | i++; | 
|  | 1612 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | 
|  | 1613 | goto nla_put_failure; | 
|  | 1614 | } | 
|  | 1615 |  | 
|  | 1616 | return i; | 
|  | 1617 | nla_put_failure: | 
|  | 1618 | return -ENOBUFS; | 
|  | 1619 | } | 
|  | 1620 |  | 
|  | 1621 | struct nl80211_dump_wiphy_state { | 
|  | 1622 | s64 filter_wiphy; | 
|  | 1623 | long start; | 
|  | 1624 | long split_start, band_start, chan_start, capa_start; | 
|  | 1625 | bool split; | 
|  | 1626 | }; | 
|  | 1627 |  | 
|  | 1628 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, | 
|  | 1629 | enum nl80211_commands cmd, | 
|  | 1630 | struct sk_buff *msg, u32 portid, u32 seq, | 
|  | 1631 | int flags, struct nl80211_dump_wiphy_state *state) | 
|  | 1632 | { | 
|  | 1633 | void *hdr; | 
|  | 1634 | struct nlattr *nl_bands, *nl_band; | 
|  | 1635 | struct nlattr *nl_freqs, *nl_freq; | 
|  | 1636 | struct nlattr *nl_cmds; | 
|  | 1637 | enum nl80211_band band; | 
|  | 1638 | struct ieee80211_channel *chan; | 
|  | 1639 | int i; | 
|  | 1640 | const struct ieee80211_txrx_stypes *mgmt_stypes = | 
|  | 1641 | rdev->wiphy.mgmt_stypes; | 
|  | 1642 | u32 features; | 
|  | 1643 |  | 
|  | 1644 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
|  | 1645 | if (!hdr) | 
|  | 1646 | return -ENOBUFS; | 
|  | 1647 |  | 
|  | 1648 | if (WARN_ON(!state)) | 
|  | 1649 | return -EINVAL; | 
|  | 1650 |  | 
|  | 1651 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 1652 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | 
|  | 1653 | wiphy_name(&rdev->wiphy)) || | 
|  | 1654 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | 
|  | 1655 | cfg80211_rdev_list_generation)) | 
|  | 1656 | goto nla_put_failure; | 
|  | 1657 |  | 
|  | 1658 | if (cmd != NL80211_CMD_NEW_WIPHY) | 
|  | 1659 | goto finish; | 
|  | 1660 |  | 
|  | 1661 | switch (state->split_start) { | 
|  | 1662 | case 0: | 
|  | 1663 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | 
|  | 1664 | rdev->wiphy.retry_short) || | 
|  | 1665 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | 
|  | 1666 | rdev->wiphy.retry_long) || | 
|  | 1667 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | 
|  | 1668 | rdev->wiphy.frag_threshold) || | 
|  | 1669 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | 
|  | 1670 | rdev->wiphy.rts_threshold) || | 
|  | 1671 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | 
|  | 1672 | rdev->wiphy.coverage_class) || | 
|  | 1673 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | 
|  | 1674 | rdev->wiphy.max_scan_ssids) || | 
|  | 1675 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | 
|  | 1676 | rdev->wiphy.max_sched_scan_ssids) || | 
|  | 1677 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | 
|  | 1678 | rdev->wiphy.max_scan_ie_len) || | 
|  | 1679 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | 
|  | 1680 | rdev->wiphy.max_sched_scan_ie_len) || | 
|  | 1681 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | 
|  | 1682 | rdev->wiphy.max_match_sets) || | 
|  | 1683 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | 
|  | 1684 | rdev->wiphy.max_sched_scan_plans) || | 
|  | 1685 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | 
|  | 1686 | rdev->wiphy.max_sched_scan_plan_interval) || | 
|  | 1687 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | 
|  | 1688 | rdev->wiphy.max_sched_scan_plan_iterations)) | 
|  | 1689 | goto nla_put_failure; | 
|  | 1690 |  | 
|  | 1691 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | 
|  | 1692 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | 
|  | 1693 | goto nla_put_failure; | 
|  | 1694 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && | 
|  | 1695 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | 
|  | 1696 | goto nla_put_failure; | 
|  | 1697 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | 
|  | 1698 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | 
|  | 1699 | goto nla_put_failure; | 
|  | 1700 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | 
|  | 1701 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | 
|  | 1702 | goto nla_put_failure; | 
|  | 1703 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | 
|  | 1704 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | 
|  | 1705 | goto nla_put_failure; | 
|  | 1706 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | 
|  | 1707 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | 
|  | 1708 | goto nla_put_failure; | 
|  | 1709 | state->split_start++; | 
|  | 1710 | if (state->split) | 
|  | 1711 | break; | 
|  | 1712 | case 1: | 
|  | 1713 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | 
|  | 1714 | sizeof(u32) * rdev->wiphy.n_cipher_suites, | 
|  | 1715 | rdev->wiphy.cipher_suites)) | 
|  | 1716 | goto nla_put_failure; | 
|  | 1717 |  | 
|  | 1718 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, | 
|  | 1719 | rdev->wiphy.max_num_pmkids)) | 
|  | 1720 | goto nla_put_failure; | 
|  | 1721 |  | 
|  | 1722 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | 
|  | 1723 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | 
|  | 1724 | goto nla_put_failure; | 
|  | 1725 |  | 
|  | 1726 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, | 
|  | 1727 | rdev->wiphy.available_antennas_tx) || | 
|  | 1728 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | 
|  | 1729 | rdev->wiphy.available_antennas_rx)) | 
|  | 1730 | goto nla_put_failure; | 
|  | 1731 |  | 
|  | 1732 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && | 
|  | 1733 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | 
|  | 1734 | rdev->wiphy.probe_resp_offload)) | 
|  | 1735 | goto nla_put_failure; | 
|  | 1736 |  | 
|  | 1737 | if ((rdev->wiphy.available_antennas_tx || | 
|  | 1738 | rdev->wiphy.available_antennas_rx) && | 
|  | 1739 | rdev->ops->get_antenna) { | 
|  | 1740 | u32 tx_ant = 0, rx_ant = 0; | 
|  | 1741 | int res; | 
|  | 1742 |  | 
|  | 1743 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); | 
|  | 1744 | if (!res) { | 
|  | 1745 | if (nla_put_u32(msg, | 
|  | 1746 | NL80211_ATTR_WIPHY_ANTENNA_TX, | 
|  | 1747 | tx_ant) || | 
|  | 1748 | nla_put_u32(msg, | 
|  | 1749 | NL80211_ATTR_WIPHY_ANTENNA_RX, | 
|  | 1750 | rx_ant)) | 
|  | 1751 | goto nla_put_failure; | 
|  | 1752 | } | 
|  | 1753 | } | 
|  | 1754 |  | 
|  | 1755 | state->split_start++; | 
|  | 1756 | if (state->split) | 
|  | 1757 | break; | 
|  | 1758 | case 2: | 
|  | 1759 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | 
|  | 1760 | rdev->wiphy.interface_modes)) | 
|  | 1761 | goto nla_put_failure; | 
|  | 1762 | state->split_start++; | 
|  | 1763 | if (state->split) | 
|  | 1764 | break; | 
|  | 1765 | case 3: | 
|  | 1766 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | 
|  | 1767 | if (!nl_bands) | 
|  | 1768 | goto nla_put_failure; | 
|  | 1769 |  | 
|  | 1770 | for (band = state->band_start; | 
|  | 1771 | band < NUM_NL80211_BANDS; band++) { | 
|  | 1772 | struct ieee80211_supported_band *sband; | 
|  | 1773 |  | 
|  | 1774 | sband = rdev->wiphy.bands[band]; | 
|  | 1775 |  | 
|  | 1776 | if (!sband) | 
|  | 1777 | continue; | 
|  | 1778 |  | 
|  | 1779 | nl_band = nla_nest_start(msg, band); | 
|  | 1780 | if (!nl_band) | 
|  | 1781 | goto nla_put_failure; | 
|  | 1782 |  | 
|  | 1783 | switch (state->chan_start) { | 
|  | 1784 | case 0: | 
|  | 1785 | if (nl80211_send_band_rateinfo(msg, sband)) | 
|  | 1786 | goto nla_put_failure; | 
|  | 1787 | state->chan_start++; | 
|  | 1788 | if (state->split) | 
|  | 1789 | break; | 
|  | 1790 | default: | 
|  | 1791 | /* add frequencies */ | 
|  | 1792 | nl_freqs = nla_nest_start( | 
|  | 1793 | msg, NL80211_BAND_ATTR_FREQS); | 
|  | 1794 | if (!nl_freqs) | 
|  | 1795 | goto nla_put_failure; | 
|  | 1796 |  | 
|  | 1797 | for (i = state->chan_start - 1; | 
|  | 1798 | i < sband->n_channels; | 
|  | 1799 | i++) { | 
|  | 1800 | nl_freq = nla_nest_start(msg, i); | 
|  | 1801 | if (!nl_freq) | 
|  | 1802 | goto nla_put_failure; | 
|  | 1803 |  | 
|  | 1804 | chan = &sband->channels[i]; | 
|  | 1805 |  | 
|  | 1806 | if (nl80211_msg_put_channel( | 
|  | 1807 | msg, &rdev->wiphy, chan, | 
|  | 1808 | state->split)) | 
|  | 1809 | goto nla_put_failure; | 
|  | 1810 |  | 
|  | 1811 | nla_nest_end(msg, nl_freq); | 
|  | 1812 | if (state->split) | 
|  | 1813 | break; | 
|  | 1814 | } | 
|  | 1815 | if (i < sband->n_channels) | 
|  | 1816 | state->chan_start = i + 2; | 
|  | 1817 | else | 
|  | 1818 | state->chan_start = 0; | 
|  | 1819 | nla_nest_end(msg, nl_freqs); | 
|  | 1820 | } | 
|  | 1821 |  | 
|  | 1822 | nla_nest_end(msg, nl_band); | 
|  | 1823 |  | 
|  | 1824 | if (state->split) { | 
|  | 1825 | /* start again here */ | 
|  | 1826 | if (state->chan_start) | 
|  | 1827 | band--; | 
|  | 1828 | break; | 
|  | 1829 | } | 
|  | 1830 | } | 
|  | 1831 | nla_nest_end(msg, nl_bands); | 
|  | 1832 |  | 
|  | 1833 | if (band < NUM_NL80211_BANDS) | 
|  | 1834 | state->band_start = band + 1; | 
|  | 1835 | else | 
|  | 1836 | state->band_start = 0; | 
|  | 1837 |  | 
|  | 1838 | /* if bands & channels are done, continue outside */ | 
|  | 1839 | if (state->band_start == 0 && state->chan_start == 0) | 
|  | 1840 | state->split_start++; | 
|  | 1841 | if (state->split) | 
|  | 1842 | break; | 
|  | 1843 | case 4: | 
|  | 1844 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | 
|  | 1845 | if (!nl_cmds) | 
|  | 1846 | goto nla_put_failure; | 
|  | 1847 |  | 
|  | 1848 | i = nl80211_add_commands_unsplit(rdev, msg); | 
|  | 1849 | if (i < 0) | 
|  | 1850 | goto nla_put_failure; | 
|  | 1851 | if (state->split) { | 
|  | 1852 | CMD(crit_proto_start, CRIT_PROTOCOL_START); | 
|  | 1853 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | 
|  | 1854 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) | 
|  | 1855 | CMD(channel_switch, CHANNEL_SWITCH); | 
|  | 1856 | CMD(set_qos_map, SET_QOS_MAP); | 
|  | 1857 | if (rdev->wiphy.features & | 
|  | 1858 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | 
|  | 1859 | CMD(add_tx_ts, ADD_TX_TS); | 
|  | 1860 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); | 
|  | 1861 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); | 
|  | 1862 | } | 
|  | 1863 | #undef CMD | 
|  | 1864 |  | 
|  | 1865 | nla_nest_end(msg, nl_cmds); | 
|  | 1866 | state->split_start++; | 
|  | 1867 | if (state->split) | 
|  | 1868 | break; | 
|  | 1869 | case 5: | 
|  | 1870 | if (rdev->ops->remain_on_channel && | 
|  | 1871 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | 
|  | 1872 | nla_put_u32(msg, | 
|  | 1873 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | 
|  | 1874 | rdev->wiphy.max_remain_on_channel_duration)) | 
|  | 1875 | goto nla_put_failure; | 
|  | 1876 |  | 
|  | 1877 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | 
|  | 1878 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | 
|  | 1879 | goto nla_put_failure; | 
|  | 1880 |  | 
|  | 1881 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | 
|  | 1882 | goto nla_put_failure; | 
|  | 1883 | state->split_start++; | 
|  | 1884 | if (state->split) | 
|  | 1885 | break; | 
|  | 1886 | case 6: | 
|  | 1887 | #ifdef CONFIG_PM | 
|  | 1888 | if (nl80211_send_wowlan(msg, rdev, state->split)) | 
|  | 1889 | goto nla_put_failure; | 
|  | 1890 | state->split_start++; | 
|  | 1891 | if (state->split) | 
|  | 1892 | break; | 
|  | 1893 | #else | 
|  | 1894 | state->split_start++; | 
|  | 1895 | #endif | 
|  | 1896 | case 7: | 
|  | 1897 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | 
|  | 1898 | rdev->wiphy.software_iftypes)) | 
|  | 1899 | goto nla_put_failure; | 
|  | 1900 |  | 
|  | 1901 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, | 
|  | 1902 | state->split)) | 
|  | 1903 | goto nla_put_failure; | 
|  | 1904 |  | 
|  | 1905 | state->split_start++; | 
|  | 1906 | if (state->split) | 
|  | 1907 | break; | 
|  | 1908 | case 8: | 
|  | 1909 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | 
|  | 1910 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | 
|  | 1911 | rdev->wiphy.ap_sme_capa)) | 
|  | 1912 | goto nla_put_failure; | 
|  | 1913 |  | 
|  | 1914 | features = rdev->wiphy.features; | 
|  | 1915 | /* | 
|  | 1916 | * We can only add the per-channel limit information if the | 
|  | 1917 | * dump is split, otherwise it makes it too big. Therefore | 
|  | 1918 | * only advertise it in that case. | 
|  | 1919 | */ | 
|  | 1920 | if (state->split) | 
|  | 1921 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | 
|  | 1922 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | 
|  | 1923 | goto nla_put_failure; | 
|  | 1924 |  | 
|  | 1925 | if (rdev->wiphy.ht_capa_mod_mask && | 
|  | 1926 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | 
|  | 1927 | sizeof(*rdev->wiphy.ht_capa_mod_mask), | 
|  | 1928 | rdev->wiphy.ht_capa_mod_mask)) | 
|  | 1929 | goto nla_put_failure; | 
|  | 1930 |  | 
|  | 1931 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && | 
|  | 1932 | rdev->wiphy.max_acl_mac_addrs && | 
|  | 1933 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | 
|  | 1934 | rdev->wiphy.max_acl_mac_addrs)) | 
|  | 1935 | goto nla_put_failure; | 
|  | 1936 |  | 
|  | 1937 | /* | 
|  | 1938 | * Any information below this point is only available to | 
|  | 1939 | * applications that can deal with it being split. This | 
|  | 1940 | * helps ensure that newly added capabilities don't break | 
|  | 1941 | * older tools by overrunning their buffers. | 
|  | 1942 | * | 
|  | 1943 | * We still increment split_start so that in the split | 
|  | 1944 | * case we'll continue with more data in the next round, | 
|  | 1945 | * but break unconditionally so unsplit data stops here. | 
|  | 1946 | */ | 
|  | 1947 | state->split_start++; | 
|  | 1948 | break; | 
|  | 1949 | case 9: | 
|  | 1950 | if (rdev->wiphy.extended_capabilities && | 
|  | 1951 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | 
|  | 1952 | rdev->wiphy.extended_capabilities_len, | 
|  | 1953 | rdev->wiphy.extended_capabilities) || | 
|  | 1954 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | 
|  | 1955 | rdev->wiphy.extended_capabilities_len, | 
|  | 1956 | rdev->wiphy.extended_capabilities_mask))) | 
|  | 1957 | goto nla_put_failure; | 
|  | 1958 |  | 
|  | 1959 | if (rdev->wiphy.vht_capa_mod_mask && | 
|  | 1960 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | 
|  | 1961 | sizeof(*rdev->wiphy.vht_capa_mod_mask), | 
|  | 1962 | rdev->wiphy.vht_capa_mod_mask)) | 
|  | 1963 | goto nla_put_failure; | 
|  | 1964 |  | 
|  | 1965 | state->split_start++; | 
|  | 1966 | break; | 
|  | 1967 | case 10: | 
|  | 1968 | if (nl80211_send_coalesce(msg, rdev)) | 
|  | 1969 | goto nla_put_failure; | 
|  | 1970 |  | 
|  | 1971 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && | 
|  | 1972 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || | 
|  | 1973 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | 
|  | 1974 | goto nla_put_failure; | 
|  | 1975 |  | 
|  | 1976 | if (rdev->wiphy.max_ap_assoc_sta && | 
|  | 1977 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, | 
|  | 1978 | rdev->wiphy.max_ap_assoc_sta)) | 
|  | 1979 | goto nla_put_failure; | 
|  | 1980 |  | 
|  | 1981 | state->split_start++; | 
|  | 1982 | break; | 
|  | 1983 | case 11: | 
|  | 1984 | if (rdev->wiphy.n_vendor_commands) { | 
|  | 1985 | const struct nl80211_vendor_cmd_info *info; | 
|  | 1986 | struct nlattr *nested; | 
|  | 1987 |  | 
|  | 1988 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | 
|  | 1989 | if (!nested) | 
|  | 1990 | goto nla_put_failure; | 
|  | 1991 |  | 
|  | 1992 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | 
|  | 1993 | info = &rdev->wiphy.vendor_commands[i].info; | 
|  | 1994 | if (nla_put(msg, i + 1, sizeof(*info), info)) | 
|  | 1995 | goto nla_put_failure; | 
|  | 1996 | } | 
|  | 1997 | nla_nest_end(msg, nested); | 
|  | 1998 | } | 
|  | 1999 |  | 
|  | 2000 | if (rdev->wiphy.n_vendor_events) { | 
|  | 2001 | const struct nl80211_vendor_cmd_info *info; | 
|  | 2002 | struct nlattr *nested; | 
|  | 2003 |  | 
|  | 2004 | nested = nla_nest_start(msg, | 
|  | 2005 | NL80211_ATTR_VENDOR_EVENTS); | 
|  | 2006 | if (!nested) | 
|  | 2007 | goto nla_put_failure; | 
|  | 2008 |  | 
|  | 2009 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { | 
|  | 2010 | info = &rdev->wiphy.vendor_events[i]; | 
|  | 2011 | if (nla_put(msg, i + 1, sizeof(*info), info)) | 
|  | 2012 | goto nla_put_failure; | 
|  | 2013 | } | 
|  | 2014 | nla_nest_end(msg, nested); | 
|  | 2015 | } | 
|  | 2016 | state->split_start++; | 
|  | 2017 | break; | 
|  | 2018 | case 12: | 
|  | 2019 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | 
|  | 2020 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | 
|  | 2021 | rdev->wiphy.max_num_csa_counters)) | 
|  | 2022 | goto nla_put_failure; | 
|  | 2023 |  | 
|  | 2024 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | 
|  | 2025 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | 
|  | 2026 | goto nla_put_failure; | 
|  | 2027 |  | 
|  | 2028 | if (rdev->wiphy.max_sched_scan_reqs && | 
|  | 2029 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, | 
|  | 2030 | rdev->wiphy.max_sched_scan_reqs)) | 
|  | 2031 | goto nla_put_failure; | 
|  | 2032 |  | 
|  | 2033 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, | 
|  | 2034 | sizeof(rdev->wiphy.ext_features), | 
|  | 2035 | rdev->wiphy.ext_features)) | 
|  | 2036 | goto nla_put_failure; | 
|  | 2037 |  | 
|  | 2038 | if (rdev->wiphy.bss_select_support) { | 
|  | 2039 | struct nlattr *nested; | 
|  | 2040 | u32 bss_select_support = rdev->wiphy.bss_select_support; | 
|  | 2041 |  | 
|  | 2042 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); | 
|  | 2043 | if (!nested) | 
|  | 2044 | goto nla_put_failure; | 
|  | 2045 |  | 
|  | 2046 | i = 0; | 
|  | 2047 | while (bss_select_support) { | 
|  | 2048 | if ((bss_select_support & 1) && | 
|  | 2049 | nla_put_flag(msg, i)) | 
|  | 2050 | goto nla_put_failure; | 
|  | 2051 | i++; | 
|  | 2052 | bss_select_support >>= 1; | 
|  | 2053 | } | 
|  | 2054 | nla_nest_end(msg, nested); | 
|  | 2055 | } | 
|  | 2056 |  | 
|  | 2057 | state->split_start++; | 
|  | 2058 | break; | 
|  | 2059 | case 13: | 
|  | 2060 | if (rdev->wiphy.num_iftype_ext_capab && | 
|  | 2061 | rdev->wiphy.iftype_ext_capab) { | 
|  | 2062 | struct nlattr *nested_ext_capab, *nested; | 
|  | 2063 |  | 
|  | 2064 | nested = nla_nest_start(msg, | 
|  | 2065 | NL80211_ATTR_IFTYPE_EXT_CAPA); | 
|  | 2066 | if (!nested) | 
|  | 2067 | goto nla_put_failure; | 
|  | 2068 |  | 
|  | 2069 | for (i = state->capa_start; | 
|  | 2070 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | 
|  | 2071 | const struct wiphy_iftype_ext_capab *capab; | 
|  | 2072 |  | 
|  | 2073 | capab = &rdev->wiphy.iftype_ext_capab[i]; | 
|  | 2074 |  | 
|  | 2075 | nested_ext_capab = nla_nest_start(msg, i); | 
|  | 2076 | if (!nested_ext_capab || | 
|  | 2077 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | 
|  | 2078 | capab->iftype) || | 
|  | 2079 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | 
|  | 2080 | capab->extended_capabilities_len, | 
|  | 2081 | capab->extended_capabilities) || | 
|  | 2082 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | 
|  | 2083 | capab->extended_capabilities_len, | 
|  | 2084 | capab->extended_capabilities_mask)) | 
|  | 2085 | goto nla_put_failure; | 
|  | 2086 |  | 
|  | 2087 | nla_nest_end(msg, nested_ext_capab); | 
|  | 2088 | if (state->split) | 
|  | 2089 | break; | 
|  | 2090 | } | 
|  | 2091 | nla_nest_end(msg, nested); | 
|  | 2092 | if (i < rdev->wiphy.num_iftype_ext_capab) { | 
|  | 2093 | state->capa_start = i + 1; | 
|  | 2094 | break; | 
|  | 2095 | } | 
|  | 2096 | } | 
|  | 2097 |  | 
|  | 2098 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, | 
|  | 2099 | rdev->wiphy.nan_supported_bands)) | 
|  | 2100 | goto nla_put_failure; | 
|  | 2101 |  | 
|  | 2102 | if (wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 2103 | NL80211_EXT_FEATURE_TXQS)) { | 
|  | 2104 | struct cfg80211_txq_stats txqstats = {}; | 
|  | 2105 | int res; | 
|  | 2106 |  | 
|  | 2107 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); | 
|  | 2108 | if (!res && | 
|  | 2109 | !nl80211_put_txq_stats(msg, &txqstats, | 
|  | 2110 | NL80211_ATTR_TXQ_STATS)) | 
|  | 2111 | goto nla_put_failure; | 
|  | 2112 |  | 
|  | 2113 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, | 
|  | 2114 | rdev->wiphy.txq_limit)) | 
|  | 2115 | goto nla_put_failure; | 
|  | 2116 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, | 
|  | 2117 | rdev->wiphy.txq_memory_limit)) | 
|  | 2118 | goto nla_put_failure; | 
|  | 2119 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, | 
|  | 2120 | rdev->wiphy.txq_quantum)) | 
|  | 2121 | goto nla_put_failure; | 
|  | 2122 | } | 
|  | 2123 |  | 
|  | 2124 | /* done */ | 
|  | 2125 | state->split_start = 0; | 
|  | 2126 | break; | 
|  | 2127 | } | 
|  | 2128 | finish: | 
|  | 2129 | genlmsg_end(msg, hdr); | 
|  | 2130 | return 0; | 
|  | 2131 |  | 
|  | 2132 | nla_put_failure: | 
|  | 2133 | genlmsg_cancel(msg, hdr); | 
|  | 2134 | return -EMSGSIZE; | 
|  | 2135 | } | 
|  | 2136 |  | 
|  | 2137 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, | 
|  | 2138 | struct netlink_callback *cb, | 
|  | 2139 | struct nl80211_dump_wiphy_state *state) | 
|  | 2140 | { | 
|  | 2141 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); | 
|  | 2142 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, | 
|  | 2143 | nl80211_fam.maxattr, nl80211_policy, NULL); | 
|  | 2144 | /* ignore parse errors for backward compatibility */ | 
|  | 2145 | if (ret) | 
|  | 2146 | return 0; | 
|  | 2147 |  | 
|  | 2148 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | 
|  | 2149 | if (tb[NL80211_ATTR_WIPHY]) | 
|  | 2150 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | 
|  | 2151 | if (tb[NL80211_ATTR_WDEV]) | 
|  | 2152 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | 
|  | 2153 | if (tb[NL80211_ATTR_IFINDEX]) { | 
|  | 2154 | struct net_device *netdev; | 
|  | 2155 | struct cfg80211_registered_device *rdev; | 
|  | 2156 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | 
|  | 2157 |  | 
|  | 2158 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | 
|  | 2159 | if (!netdev) | 
|  | 2160 | return -ENODEV; | 
|  | 2161 | if (netdev->ieee80211_ptr) { | 
|  | 2162 | rdev = wiphy_to_rdev( | 
|  | 2163 | netdev->ieee80211_ptr->wiphy); | 
|  | 2164 | state->filter_wiphy = rdev->wiphy_idx; | 
|  | 2165 | } | 
|  | 2166 | } | 
|  | 2167 |  | 
|  | 2168 | return 0; | 
|  | 2169 | } | 
|  | 2170 |  | 
|  | 2171 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | 
|  | 2172 | { | 
|  | 2173 | int idx = 0, ret; | 
|  | 2174 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; | 
|  | 2175 | struct cfg80211_registered_device *rdev; | 
|  | 2176 |  | 
|  | 2177 | rtnl_lock(); | 
|  | 2178 | if (!state) { | 
|  | 2179 | state = kzalloc(sizeof(*state), GFP_KERNEL); | 
|  | 2180 | if (!state) { | 
|  | 2181 | rtnl_unlock(); | 
|  | 2182 | return -ENOMEM; | 
|  | 2183 | } | 
|  | 2184 | state->filter_wiphy = -1; | 
|  | 2185 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | 
|  | 2186 | if (ret) { | 
|  | 2187 | kfree(state); | 
|  | 2188 | rtnl_unlock(); | 
|  | 2189 | return ret; | 
|  | 2190 | } | 
|  | 2191 | cb->args[0] = (long)state; | 
|  | 2192 | } | 
|  | 2193 |  | 
|  | 2194 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
|  | 2195 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | 
|  | 2196 | continue; | 
|  | 2197 | if (++idx <= state->start) | 
|  | 2198 | continue; | 
|  | 2199 | if (state->filter_wiphy != -1 && | 
|  | 2200 | state->filter_wiphy != rdev->wiphy_idx) | 
|  | 2201 | continue; | 
|  | 2202 | /* attempt to fit multiple wiphy data chunks into the skb */ | 
|  | 2203 | do { | 
|  | 2204 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, | 
|  | 2205 | skb, | 
|  | 2206 | NETLINK_CB(cb->skb).portid, | 
|  | 2207 | cb->nlh->nlmsg_seq, | 
|  | 2208 | NLM_F_MULTI, state); | 
|  | 2209 | if (ret < 0) { | 
|  | 2210 | /* | 
|  | 2211 | * If sending the wiphy data didn't fit (ENOBUFS | 
|  | 2212 | * or EMSGSIZE returned), this SKB is still | 
|  | 2213 | * empty (so it's not too big because another | 
|  | 2214 | * wiphy dataset is already in the skb) and | 
|  | 2215 | * we've not tried to adjust the dump allocation | 
|  | 2216 | * yet ... then adjust the alloc size to be | 
|  | 2217 | * bigger, and return 1 but with the empty skb. | 
|  | 2218 | * This results in an empty message being RX'ed | 
|  | 2219 | * in userspace, but that is ignored. | 
|  | 2220 | * | 
|  | 2221 | * We can then retry with the larger buffer. | 
|  | 2222 | */ | 
|  | 2223 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | 
|  | 2224 | !skb->len && !state->split && | 
|  | 2225 | cb->min_dump_alloc < 4096) { | 
|  | 2226 | cb->min_dump_alloc = 4096; | 
|  | 2227 | state->split_start = 0; | 
|  | 2228 | rtnl_unlock(); | 
|  | 2229 | return 1; | 
|  | 2230 | } | 
|  | 2231 | idx--; | 
|  | 2232 | break; | 
|  | 2233 | } | 
|  | 2234 | } while (state->split_start > 0); | 
|  | 2235 | break; | 
|  | 2236 | } | 
|  | 2237 | rtnl_unlock(); | 
|  | 2238 |  | 
|  | 2239 | state->start = idx; | 
|  | 2240 |  | 
|  | 2241 | return skb->len; | 
|  | 2242 | } | 
|  | 2243 |  | 
|  | 2244 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) | 
|  | 2245 | { | 
|  | 2246 | kfree((void *)cb->args[0]); | 
|  | 2247 | return 0; | 
|  | 2248 | } | 
|  | 2249 |  | 
|  | 2250 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | 
|  | 2251 | { | 
|  | 2252 | struct sk_buff *msg; | 
|  | 2253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 2254 | struct nl80211_dump_wiphy_state state = {}; | 
|  | 2255 |  | 
|  | 2256 | msg = nlmsg_new(4096, GFP_KERNEL); | 
|  | 2257 | if (!msg) | 
|  | 2258 | return -ENOMEM; | 
|  | 2259 |  | 
|  | 2260 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, | 
|  | 2261 | info->snd_portid, info->snd_seq, 0, | 
|  | 2262 | &state) < 0) { | 
|  | 2263 | nlmsg_free(msg); | 
|  | 2264 | return -ENOBUFS; | 
|  | 2265 | } | 
|  | 2266 |  | 
|  | 2267 | return genlmsg_reply(msg, info); | 
|  | 2268 | } | 
|  | 2269 |  | 
|  | 2270 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { | 
|  | 2271 | [NL80211_TXQ_ATTR_QUEUE]		= { .type = NLA_U8 }, | 
|  | 2272 | [NL80211_TXQ_ATTR_TXOP]			= { .type = NLA_U16 }, | 
|  | 2273 | [NL80211_TXQ_ATTR_CWMIN]		= { .type = NLA_U16 }, | 
|  | 2274 | [NL80211_TXQ_ATTR_CWMAX]		= { .type = NLA_U16 }, | 
|  | 2275 | [NL80211_TXQ_ATTR_AIFS]			= { .type = NLA_U8 }, | 
|  | 2276 | }; | 
|  | 2277 |  | 
|  | 2278 | static int parse_txq_params(struct nlattr *tb[], | 
|  | 2279 | struct ieee80211_txq_params *txq_params) | 
|  | 2280 | { | 
|  | 2281 | u8 ac; | 
|  | 2282 |  | 
|  | 2283 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || | 
|  | 2284 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || | 
|  | 2285 | !tb[NL80211_TXQ_ATTR_AIFS]) | 
|  | 2286 | return -EINVAL; | 
|  | 2287 |  | 
|  | 2288 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); | 
|  | 2289 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); | 
|  | 2290 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | 
|  | 2291 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | 
|  | 2292 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | 
|  | 2293 |  | 
|  | 2294 | if (ac >= NL80211_NUM_ACS) | 
|  | 2295 | return -EINVAL; | 
|  | 2296 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); | 
|  | 2297 | return 0; | 
|  | 2298 | } | 
|  | 2299 |  | 
|  | 2300 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) | 
|  | 2301 | { | 
|  | 2302 | /* | 
|  | 2303 | * You can only set the channel explicitly for WDS interfaces, | 
|  | 2304 | * all others have their channel managed via their respective | 
|  | 2305 | * "establish a connection" command (connect, join, ...) | 
|  | 2306 | * | 
|  | 2307 | * For AP/GO and mesh mode, the channel can be set with the | 
|  | 2308 | * channel userspace API, but is only stored and passed to the | 
|  | 2309 | * low-level driver when the AP starts or the mesh is joined. | 
|  | 2310 | * This is for backward compatibility, userspace can also give | 
|  | 2311 | * the channel in the start-ap or join-mesh commands instead. | 
|  | 2312 | * | 
|  | 2313 | * Monitors are special as they are normally slaved to | 
|  | 2314 | * whatever else is going on, so they have their own special | 
|  | 2315 | * operation to set the monitor channel if possible. | 
|  | 2316 | */ | 
|  | 2317 | return !wdev || | 
|  | 2318 | wdev->iftype == NL80211_IFTYPE_AP || | 
|  | 2319 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || | 
|  | 2320 | wdev->iftype == NL80211_IFTYPE_MONITOR || | 
|  | 2321 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | 
|  | 2322 | } | 
|  | 2323 |  | 
|  | 2324 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, | 
|  | 2325 | struct genl_info *info, | 
|  | 2326 | struct cfg80211_chan_def *chandef) | 
|  | 2327 | { | 
|  | 2328 | u32 control_freq; | 
|  | 2329 |  | 
|  | 2330 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
|  | 2331 | return -EINVAL; | 
|  | 2332 |  | 
|  | 2333 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
|  | 2334 |  | 
|  | 2335 | memset(chandef, 0, sizeof(*chandef)); | 
|  | 2336 |  | 
|  | 2337 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | 
|  | 2338 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; | 
|  | 2339 | chandef->center_freq1 = control_freq; | 
|  | 2340 | chandef->center_freq2 = 0; | 
|  | 2341 |  | 
|  | 2342 | /* Primary channel not allowed */ | 
|  | 2343 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | 
|  | 2344 | return -EINVAL; | 
|  | 2345 |  | 
|  | 2346 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | 
|  | 2347 | enum nl80211_channel_type chantype; | 
|  | 2348 |  | 
|  | 2349 | chantype = nla_get_u32( | 
|  | 2350 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | 
|  | 2351 |  | 
|  | 2352 | switch (chantype) { | 
|  | 2353 | case NL80211_CHAN_NO_HT: | 
|  | 2354 | case NL80211_CHAN_HT20: | 
|  | 2355 | case NL80211_CHAN_HT40PLUS: | 
|  | 2356 | case NL80211_CHAN_HT40MINUS: | 
|  | 2357 | cfg80211_chandef_create(chandef, chandef->chan, | 
|  | 2358 | chantype); | 
|  | 2359 | /* user input for center_freq is incorrect */ | 
|  | 2360 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1] && | 
|  | 2361 | chandef->center_freq1 != nla_get_u32( | 
|  | 2362 | info->attrs[NL80211_ATTR_CENTER_FREQ1])) | 
|  | 2363 | return -EINVAL; | 
|  | 2364 | /* center_freq2 must be zero */ | 
|  | 2365 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2] && | 
|  | 2366 | nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2])) | 
|  | 2367 | return -EINVAL; | 
|  | 2368 | break; | 
|  | 2369 | default: | 
|  | 2370 | return -EINVAL; | 
|  | 2371 | } | 
|  | 2372 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | 
|  | 2373 | chandef->width = | 
|  | 2374 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | 
|  | 2375 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | 
|  | 2376 | chandef->center_freq1 = | 
|  | 2377 | nla_get_u32( | 
|  | 2378 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | 
|  | 2379 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | 
|  | 2380 | chandef->center_freq2 = | 
|  | 2381 | nla_get_u32( | 
|  | 2382 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | 
|  | 2383 | } | 
|  | 2384 |  | 
|  | 2385 | if (!cfg80211_chandef_valid(chandef)) | 
|  | 2386 | return -EINVAL; | 
|  | 2387 |  | 
|  | 2388 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, | 
|  | 2389 | IEEE80211_CHAN_DISABLED)) | 
|  | 2390 | return -EINVAL; | 
|  | 2391 |  | 
|  | 2392 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || | 
|  | 2393 | chandef->width == NL80211_CHAN_WIDTH_10) && | 
|  | 2394 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | 
|  | 2395 | return -EINVAL; | 
|  | 2396 |  | 
|  | 2397 | return 0; | 
|  | 2398 | } | 
|  | 2399 |  | 
|  | 2400 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, | 
|  | 2401 | struct net_device *dev, | 
|  | 2402 | struct genl_info *info) | 
|  | 2403 | { | 
|  | 2404 | struct cfg80211_chan_def chandef; | 
|  | 2405 | int result; | 
|  | 2406 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; | 
|  | 2407 | struct wireless_dev *wdev = NULL; | 
|  | 2408 |  | 
|  | 2409 | if (dev) | 
|  | 2410 | wdev = dev->ieee80211_ptr; | 
|  | 2411 | if (!nl80211_can_set_dev_channel(wdev)) | 
|  | 2412 | return -EOPNOTSUPP; | 
|  | 2413 | if (wdev) | 
|  | 2414 | iftype = wdev->iftype; | 
|  | 2415 |  | 
|  | 2416 | result = nl80211_parse_chandef(rdev, info, &chandef); | 
|  | 2417 | if (result) | 
|  | 2418 | return result; | 
|  | 2419 |  | 
|  | 2420 | switch (iftype) { | 
|  | 2421 | case NL80211_IFTYPE_AP: | 
|  | 2422 | case NL80211_IFTYPE_P2P_GO: | 
|  | 2423 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, | 
|  | 2424 | iftype)) { | 
|  | 2425 | result = -EINVAL; | 
|  | 2426 | break; | 
|  | 2427 | } | 
|  | 2428 | if (wdev->beacon_interval) { | 
|  | 2429 | if (!dev || !rdev->ops->set_ap_chanwidth || | 
|  | 2430 | !(rdev->wiphy.features & | 
|  | 2431 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | 
|  | 2432 | result = -EBUSY; | 
|  | 2433 | break; | 
|  | 2434 | } | 
|  | 2435 |  | 
|  | 2436 | /* Only allow dynamic channel width changes */ | 
|  | 2437 | if (chandef.chan != wdev->preset_chandef.chan) { | 
|  | 2438 | result = -EBUSY; | 
|  | 2439 | break; | 
|  | 2440 | } | 
|  | 2441 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | 
|  | 2442 | if (result) | 
|  | 2443 | break; | 
|  | 2444 | } | 
|  | 2445 | wdev->preset_chandef = chandef; | 
|  | 2446 | result = 0; | 
|  | 2447 | break; | 
|  | 2448 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 2449 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); | 
|  | 2450 | break; | 
|  | 2451 | case NL80211_IFTYPE_MONITOR: | 
|  | 2452 | result = cfg80211_set_monitor_channel(rdev, &chandef); | 
|  | 2453 | break; | 
|  | 2454 | default: | 
|  | 2455 | result = -EINVAL; | 
|  | 2456 | } | 
|  | 2457 |  | 
|  | 2458 | return result; | 
|  | 2459 | } | 
|  | 2460 |  | 
|  | 2461 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | 
|  | 2462 | { | 
|  | 2463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 2464 | struct net_device *netdev = info->user_ptr[1]; | 
|  | 2465 |  | 
|  | 2466 | return __nl80211_set_channel(rdev, netdev, info); | 
|  | 2467 | } | 
|  | 2468 |  | 
|  | 2469 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) | 
|  | 2470 | { | 
|  | 2471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 2472 | struct net_device *dev = info->user_ptr[1]; | 
|  | 2473 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 2474 | const u8 *bssid; | 
|  | 2475 |  | 
|  | 2476 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 2477 | return -EINVAL; | 
|  | 2478 |  | 
|  | 2479 | if (netif_running(dev)) | 
|  | 2480 | return -EBUSY; | 
|  | 2481 |  | 
|  | 2482 | if (!rdev->ops->set_wds_peer) | 
|  | 2483 | return -EOPNOTSUPP; | 
|  | 2484 |  | 
|  | 2485 | if (wdev->iftype != NL80211_IFTYPE_WDS) | 
|  | 2486 | return -EOPNOTSUPP; | 
|  | 2487 |  | 
|  | 2488 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 2489 | return rdev_set_wds_peer(rdev, dev, bssid); | 
|  | 2490 | } | 
|  | 2491 |  | 
|  | 2492 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | 
|  | 2493 | { | 
|  | 2494 | struct cfg80211_registered_device *rdev; | 
|  | 2495 | struct net_device *netdev = NULL; | 
|  | 2496 | struct wireless_dev *wdev; | 
|  | 2497 | int result = 0, rem_txq_params = 0; | 
|  | 2498 | struct nlattr *nl_txq_params; | 
|  | 2499 | u32 changed; | 
|  | 2500 | u8 retry_short = 0, retry_long = 0; | 
|  | 2501 | u32 frag_threshold = 0, rts_threshold = 0; | 
|  | 2502 | u8 coverage_class = 0; | 
|  | 2503 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; | 
|  | 2504 |  | 
|  | 2505 | ASSERT_RTNL(); | 
|  | 2506 |  | 
|  | 2507 | /* | 
|  | 2508 | * Try to find the wiphy and netdev. Normally this | 
|  | 2509 | * function shouldn't need the netdev, but this is | 
|  | 2510 | * done for backward compatibility -- previously | 
|  | 2511 | * setting the channel was done per wiphy, but now | 
|  | 2512 | * it is per netdev. Previous userland like hostapd | 
|  | 2513 | * also passed a netdev to set_wiphy, so that it is | 
|  | 2514 | * possible to let that go to the right netdev! | 
|  | 2515 | */ | 
|  | 2516 |  | 
|  | 2517 | if (info->attrs[NL80211_ATTR_IFINDEX]) { | 
|  | 2518 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | 
|  | 2519 |  | 
|  | 2520 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); | 
|  | 2521 | if (netdev && netdev->ieee80211_ptr) | 
|  | 2522 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); | 
|  | 2523 | else | 
|  | 2524 | netdev = NULL; | 
|  | 2525 | } | 
|  | 2526 |  | 
|  | 2527 | if (!netdev) { | 
|  | 2528 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), | 
|  | 2529 | info->attrs); | 
|  | 2530 | if (IS_ERR(rdev)) | 
|  | 2531 | return PTR_ERR(rdev); | 
|  | 2532 | wdev = NULL; | 
|  | 2533 | netdev = NULL; | 
|  | 2534 | result = 0; | 
|  | 2535 | } else | 
|  | 2536 | wdev = netdev->ieee80211_ptr; | 
|  | 2537 |  | 
|  | 2538 | /* | 
|  | 2539 | * end workaround code, by now the rdev is available | 
|  | 2540 | * and locked, and wdev may or may not be NULL. | 
|  | 2541 | */ | 
|  | 2542 |  | 
|  | 2543 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | 
|  | 2544 | result = cfg80211_dev_rename( | 
|  | 2545 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | 
|  | 2546 |  | 
|  | 2547 | if (result) | 
|  | 2548 | return result; | 
|  | 2549 |  | 
|  | 2550 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | 
|  | 2551 | struct ieee80211_txq_params txq_params; | 
|  | 2552 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | 
|  | 2553 |  | 
|  | 2554 | if (!rdev->ops->set_txq_params) | 
|  | 2555 | return -EOPNOTSUPP; | 
|  | 2556 |  | 
|  | 2557 | if (!netdev) | 
|  | 2558 | return -EINVAL; | 
|  | 2559 |  | 
|  | 2560 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 2561 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 2562 | return -EINVAL; | 
|  | 2563 |  | 
|  | 2564 | if (!netif_running(netdev)) | 
|  | 2565 | return -ENETDOWN; | 
|  | 2566 |  | 
|  | 2567 | nla_for_each_nested(nl_txq_params, | 
|  | 2568 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | 
|  | 2569 | rem_txq_params) { | 
|  | 2570 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, | 
|  | 2571 | nl_txq_params, | 
|  | 2572 | txq_params_policy, | 
|  | 2573 | info->extack); | 
|  | 2574 | if (result) | 
|  | 2575 | return result; | 
|  | 2576 | result = parse_txq_params(tb, &txq_params); | 
|  | 2577 | if (result) | 
|  | 2578 | return result; | 
|  | 2579 |  | 
|  | 2580 | result = rdev_set_txq_params(rdev, netdev, | 
|  | 2581 | &txq_params); | 
|  | 2582 | if (result) | 
|  | 2583 | return result; | 
|  | 2584 | } | 
|  | 2585 | } | 
|  | 2586 |  | 
|  | 2587 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
|  | 2588 | result = __nl80211_set_channel( | 
|  | 2589 | rdev, | 
|  | 2590 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | 
|  | 2591 | info); | 
|  | 2592 | if (result) | 
|  | 2593 | return result; | 
|  | 2594 | } | 
|  | 2595 |  | 
|  | 2596 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { | 
|  | 2597 | struct wireless_dev *txp_wdev = wdev; | 
|  | 2598 | enum nl80211_tx_power_setting type; | 
|  | 2599 | int idx, mbm = 0; | 
|  | 2600 |  | 
|  | 2601 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) | 
|  | 2602 | txp_wdev = NULL; | 
|  | 2603 |  | 
|  | 2604 | if (!rdev->ops->set_tx_power) | 
|  | 2605 | return -EOPNOTSUPP; | 
|  | 2606 |  | 
|  | 2607 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | 
|  | 2608 | type = nla_get_u32(info->attrs[idx]); | 
|  | 2609 |  | 
|  | 2610 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | 
|  | 2611 | (type != NL80211_TX_POWER_AUTOMATIC)) | 
|  | 2612 | return -EINVAL; | 
|  | 2613 |  | 
|  | 2614 | if (type != NL80211_TX_POWER_AUTOMATIC) { | 
|  | 2615 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | 
|  | 2616 | mbm = nla_get_u32(info->attrs[idx]); | 
|  | 2617 | } | 
|  | 2618 |  | 
|  | 2619 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); | 
|  | 2620 | if (result) | 
|  | 2621 | return result; | 
|  | 2622 | } | 
|  | 2623 |  | 
|  | 2624 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && | 
|  | 2625 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | 
|  | 2626 | u32 tx_ant, rx_ant; | 
|  | 2627 |  | 
|  | 2628 | if ((!rdev->wiphy.available_antennas_tx && | 
|  | 2629 | !rdev->wiphy.available_antennas_rx) || | 
|  | 2630 | !rdev->ops->set_antenna) | 
|  | 2631 | return -EOPNOTSUPP; | 
|  | 2632 |  | 
|  | 2633 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | 
|  | 2634 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | 
|  | 2635 |  | 
|  | 2636 | /* reject antenna configurations which don't match the | 
|  | 2637 | * available antenna masks, except for the "all" mask */ | 
|  | 2638 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | 
|  | 2639 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) | 
|  | 2640 | return -EINVAL; | 
|  | 2641 |  | 
|  | 2642 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; | 
|  | 2643 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | 
|  | 2644 |  | 
|  | 2645 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); | 
|  | 2646 | if (result) | 
|  | 2647 | return result; | 
|  | 2648 | } | 
|  | 2649 |  | 
|  | 2650 | changed = 0; | 
|  | 2651 |  | 
|  | 2652 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | 
|  | 2653 | retry_short = nla_get_u8( | 
|  | 2654 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | 
|  | 2655 | if (retry_short == 0) | 
|  | 2656 | return -EINVAL; | 
|  | 2657 |  | 
|  | 2658 | changed |= WIPHY_PARAM_RETRY_SHORT; | 
|  | 2659 | } | 
|  | 2660 |  | 
|  | 2661 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | 
|  | 2662 | retry_long = nla_get_u8( | 
|  | 2663 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | 
|  | 2664 | if (retry_long == 0) | 
|  | 2665 | return -EINVAL; | 
|  | 2666 |  | 
|  | 2667 | changed |= WIPHY_PARAM_RETRY_LONG; | 
|  | 2668 | } | 
|  | 2669 |  | 
|  | 2670 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | 
|  | 2671 | frag_threshold = nla_get_u32( | 
|  | 2672 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | 
|  | 2673 | if (frag_threshold < 256) | 
|  | 2674 | return -EINVAL; | 
|  | 2675 |  | 
|  | 2676 | if (frag_threshold != (u32) -1) { | 
|  | 2677 | /* | 
|  | 2678 | * Fragments (apart from the last one) are required to | 
|  | 2679 | * have even length. Make the fragmentation code | 
|  | 2680 | * simpler by stripping LSB should someone try to use | 
|  | 2681 | * odd threshold value. | 
|  | 2682 | */ | 
|  | 2683 | frag_threshold &= ~0x1; | 
|  | 2684 | } | 
|  | 2685 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | 
|  | 2686 | } | 
|  | 2687 |  | 
|  | 2688 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | 
|  | 2689 | rts_threshold = nla_get_u32( | 
|  | 2690 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | 
|  | 2691 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | 
|  | 2692 | } | 
|  | 2693 |  | 
|  | 2694 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { | 
|  | 2695 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) | 
|  | 2696 | return -EINVAL; | 
|  | 2697 |  | 
|  | 2698 | coverage_class = nla_get_u8( | 
|  | 2699 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | 
|  | 2700 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | 
|  | 2701 | } | 
|  | 2702 |  | 
|  | 2703 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { | 
|  | 2704 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | 
|  | 2705 | return -EOPNOTSUPP; | 
|  | 2706 |  | 
|  | 2707 | changed |= WIPHY_PARAM_DYN_ACK; | 
|  | 2708 | } | 
|  | 2709 |  | 
|  | 2710 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { | 
|  | 2711 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 2712 | NL80211_EXT_FEATURE_TXQS)) | 
|  | 2713 | return -EOPNOTSUPP; | 
|  | 2714 | txq_limit = nla_get_u32( | 
|  | 2715 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); | 
|  | 2716 | changed |= WIPHY_PARAM_TXQ_LIMIT; | 
|  | 2717 | } | 
|  | 2718 |  | 
|  | 2719 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { | 
|  | 2720 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 2721 | NL80211_EXT_FEATURE_TXQS)) | 
|  | 2722 | return -EOPNOTSUPP; | 
|  | 2723 | txq_memory_limit = nla_get_u32( | 
|  | 2724 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); | 
|  | 2725 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; | 
|  | 2726 | } | 
|  | 2727 |  | 
|  | 2728 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { | 
|  | 2729 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 2730 | NL80211_EXT_FEATURE_TXQS)) | 
|  | 2731 | return -EOPNOTSUPP; | 
|  | 2732 | txq_quantum = nla_get_u32( | 
|  | 2733 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); | 
|  | 2734 | changed |= WIPHY_PARAM_TXQ_QUANTUM; | 
|  | 2735 | } | 
|  | 2736 |  | 
|  | 2737 | if (changed) { | 
|  | 2738 | u8 old_retry_short, old_retry_long; | 
|  | 2739 | u32 old_frag_threshold, old_rts_threshold; | 
|  | 2740 | u8 old_coverage_class; | 
|  | 2741 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; | 
|  | 2742 |  | 
|  | 2743 | if (!rdev->ops->set_wiphy_params) | 
|  | 2744 | return -EOPNOTSUPP; | 
|  | 2745 |  | 
|  | 2746 | old_retry_short = rdev->wiphy.retry_short; | 
|  | 2747 | old_retry_long = rdev->wiphy.retry_long; | 
|  | 2748 | old_frag_threshold = rdev->wiphy.frag_threshold; | 
|  | 2749 | old_rts_threshold = rdev->wiphy.rts_threshold; | 
|  | 2750 | old_coverage_class = rdev->wiphy.coverage_class; | 
|  | 2751 | old_txq_limit = rdev->wiphy.txq_limit; | 
|  | 2752 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; | 
|  | 2753 | old_txq_quantum = rdev->wiphy.txq_quantum; | 
|  | 2754 |  | 
|  | 2755 | if (changed & WIPHY_PARAM_RETRY_SHORT) | 
|  | 2756 | rdev->wiphy.retry_short = retry_short; | 
|  | 2757 | if (changed & WIPHY_PARAM_RETRY_LONG) | 
|  | 2758 | rdev->wiphy.retry_long = retry_long; | 
|  | 2759 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | 
|  | 2760 | rdev->wiphy.frag_threshold = frag_threshold; | 
|  | 2761 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | 
|  | 2762 | rdev->wiphy.rts_threshold = rts_threshold; | 
|  | 2763 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) | 
|  | 2764 | rdev->wiphy.coverage_class = coverage_class; | 
|  | 2765 | if (changed & WIPHY_PARAM_TXQ_LIMIT) | 
|  | 2766 | rdev->wiphy.txq_limit = txq_limit; | 
|  | 2767 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) | 
|  | 2768 | rdev->wiphy.txq_memory_limit = txq_memory_limit; | 
|  | 2769 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) | 
|  | 2770 | rdev->wiphy.txq_quantum = txq_quantum; | 
|  | 2771 |  | 
|  | 2772 | result = rdev_set_wiphy_params(rdev, changed); | 
|  | 2773 | if (result) { | 
|  | 2774 | rdev->wiphy.retry_short = old_retry_short; | 
|  | 2775 | rdev->wiphy.retry_long = old_retry_long; | 
|  | 2776 | rdev->wiphy.frag_threshold = old_frag_threshold; | 
|  | 2777 | rdev->wiphy.rts_threshold = old_rts_threshold; | 
|  | 2778 | rdev->wiphy.coverage_class = old_coverage_class; | 
|  | 2779 | rdev->wiphy.txq_limit = old_txq_limit; | 
|  | 2780 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; | 
|  | 2781 | rdev->wiphy.txq_quantum = old_txq_quantum; | 
|  | 2782 | return result; | 
|  | 2783 | } | 
|  | 2784 | } | 
|  | 2785 | return 0; | 
|  | 2786 | } | 
|  | 2787 |  | 
|  | 2788 | static inline u64 wdev_id(struct wireless_dev *wdev) | 
|  | 2789 | { | 
|  | 2790 | return (u64)wdev->identifier | | 
|  | 2791 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); | 
|  | 2792 | } | 
|  | 2793 |  | 
|  | 2794 | static int nl80211_send_chandef(struct sk_buff *msg, | 
|  | 2795 | const struct cfg80211_chan_def *chandef) | 
|  | 2796 | { | 
|  | 2797 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) | 
|  | 2798 | return -EINVAL; | 
|  | 2799 |  | 
|  | 2800 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, | 
|  | 2801 | chandef->chan->center_freq)) | 
|  | 2802 | return -ENOBUFS; | 
|  | 2803 | switch (chandef->width) { | 
|  | 2804 | case NL80211_CHAN_WIDTH_20_NOHT: | 
|  | 2805 | case NL80211_CHAN_WIDTH_20: | 
|  | 2806 | case NL80211_CHAN_WIDTH_40: | 
|  | 2807 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | 
|  | 2808 | cfg80211_get_chandef_type(chandef))) | 
|  | 2809 | return -ENOBUFS; | 
|  | 2810 | break; | 
|  | 2811 | default: | 
|  | 2812 | break; | 
|  | 2813 | } | 
|  | 2814 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | 
|  | 2815 | return -ENOBUFS; | 
|  | 2816 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | 
|  | 2817 | return -ENOBUFS; | 
|  | 2818 | if (chandef->center_freq2 && | 
|  | 2819 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | 
|  | 2820 | return -ENOBUFS; | 
|  | 2821 | return 0; | 
|  | 2822 | } | 
|  | 2823 |  | 
|  | 2824 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, | 
|  | 2825 | struct cfg80211_registered_device *rdev, | 
|  | 2826 | struct wireless_dev *wdev, bool removal) | 
|  | 2827 | { | 
|  | 2828 | struct net_device *dev = wdev->netdev; | 
|  | 2829 | u8 cmd = NL80211_CMD_NEW_INTERFACE; | 
|  | 2830 | void *hdr; | 
|  | 2831 |  | 
|  | 2832 | if (removal) | 
|  | 2833 | cmd = NL80211_CMD_DEL_INTERFACE; | 
|  | 2834 |  | 
|  | 2835 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
|  | 2836 | if (!hdr) | 
|  | 2837 | return -1; | 
|  | 2838 |  | 
|  | 2839 | if (dev && | 
|  | 2840 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 2841 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) | 
|  | 2842 | goto nla_put_failure; | 
|  | 2843 |  | 
|  | 2844 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 2845 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | 
|  | 2846 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 2847 | NL80211_ATTR_PAD) || | 
|  | 2848 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || | 
|  | 2849 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | 
|  | 2850 | rdev->devlist_generation ^ | 
|  | 2851 | (cfg80211_rdev_list_generation << 2)) || | 
|  | 2852 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) | 
|  | 2853 | goto nla_put_failure; | 
|  | 2854 |  | 
|  | 2855 | if (rdev->ops->get_channel) { | 
|  | 2856 | int ret; | 
|  | 2857 | struct cfg80211_chan_def chandef = {}; | 
|  | 2858 |  | 
|  | 2859 | ret = rdev_get_channel(rdev, wdev, &chandef); | 
|  | 2860 | if (ret == 0) { | 
|  | 2861 | if (nl80211_send_chandef(msg, &chandef)) | 
|  | 2862 | goto nla_put_failure; | 
|  | 2863 | } | 
|  | 2864 | } | 
|  | 2865 |  | 
|  | 2866 | if (rdev->ops->get_tx_power) { | 
|  | 2867 | int dbm, ret; | 
|  | 2868 |  | 
|  | 2869 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | 
|  | 2870 | if (ret == 0 && | 
|  | 2871 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | 
|  | 2872 | DBM_TO_MBM(dbm))) | 
|  | 2873 | goto nla_put_failure; | 
|  | 2874 | } | 
|  | 2875 |  | 
|  | 2876 | wdev_lock(wdev); | 
|  | 2877 | switch (wdev->iftype) { | 
|  | 2878 | case NL80211_IFTYPE_AP: | 
|  | 2879 | if (wdev->ssid_len && | 
|  | 2880 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | 
|  | 2881 | goto nla_put_failure_locked; | 
|  | 2882 | break; | 
|  | 2883 | case NL80211_IFTYPE_STATION: | 
|  | 2884 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 2885 | case NL80211_IFTYPE_ADHOC: { | 
|  | 2886 | const u8 *ssid_ie; | 
|  | 2887 | if (!wdev->current_bss) | 
|  | 2888 | break; | 
|  | 2889 | rcu_read_lock(); | 
|  | 2890 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, | 
|  | 2891 | WLAN_EID_SSID); | 
|  | 2892 | if (ssid_ie && | 
|  | 2893 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) | 
|  | 2894 | goto nla_put_failure_rcu_locked; | 
|  | 2895 | rcu_read_unlock(); | 
|  | 2896 | break; | 
|  | 2897 | } | 
|  | 2898 | default: | 
|  | 2899 | /* nothing */ | 
|  | 2900 | break; | 
|  | 2901 | } | 
|  | 2902 | wdev_unlock(wdev); | 
|  | 2903 |  | 
|  | 2904 | if (rdev->ops->get_txq_stats) { | 
|  | 2905 | struct cfg80211_txq_stats txqstats = {}; | 
|  | 2906 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); | 
|  | 2907 |  | 
|  | 2908 | if (ret == 0 && | 
|  | 2909 | !nl80211_put_txq_stats(msg, &txqstats, | 
|  | 2910 | NL80211_ATTR_TXQ_STATS)) | 
|  | 2911 | goto nla_put_failure; | 
|  | 2912 | } | 
|  | 2913 |  | 
|  | 2914 | genlmsg_end(msg, hdr); | 
|  | 2915 | return 0; | 
|  | 2916 |  | 
|  | 2917 | nla_put_failure_rcu_locked: | 
|  | 2918 | rcu_read_unlock(); | 
|  | 2919 | nla_put_failure_locked: | 
|  | 2920 | wdev_unlock(wdev); | 
|  | 2921 | nla_put_failure: | 
|  | 2922 | genlmsg_cancel(msg, hdr); | 
|  | 2923 | return -EMSGSIZE; | 
|  | 2924 | } | 
|  | 2925 |  | 
|  | 2926 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | 
|  | 2927 | { | 
|  | 2928 | int wp_idx = 0; | 
|  | 2929 | int if_idx = 0; | 
|  | 2930 | int wp_start = cb->args[0]; | 
|  | 2931 | int if_start = cb->args[1]; | 
|  | 2932 | int filter_wiphy = -1; | 
|  | 2933 | struct cfg80211_registered_device *rdev; | 
|  | 2934 | struct wireless_dev *wdev; | 
|  | 2935 | int ret; | 
|  | 2936 |  | 
|  | 2937 | rtnl_lock(); | 
|  | 2938 | if (!cb->args[2]) { | 
|  | 2939 | struct nl80211_dump_wiphy_state state = { | 
|  | 2940 | .filter_wiphy = -1, | 
|  | 2941 | }; | 
|  | 2942 |  | 
|  | 2943 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | 
|  | 2944 | if (ret) | 
|  | 2945 | goto out_unlock; | 
|  | 2946 |  | 
|  | 2947 | filter_wiphy = state.filter_wiphy; | 
|  | 2948 |  | 
|  | 2949 | /* | 
|  | 2950 | * if filtering, set cb->args[2] to +1 since 0 is the default | 
|  | 2951 | * value needed to determine that parsing is necessary. | 
|  | 2952 | */ | 
|  | 2953 | if (filter_wiphy >= 0) | 
|  | 2954 | cb->args[2] = filter_wiphy + 1; | 
|  | 2955 | else | 
|  | 2956 | cb->args[2] = -1; | 
|  | 2957 | } else if (cb->args[2] > 0) { | 
|  | 2958 | filter_wiphy = cb->args[2] - 1; | 
|  | 2959 | } | 
|  | 2960 |  | 
|  | 2961 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
|  | 2962 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | 
|  | 2963 | continue; | 
|  | 2964 | if (wp_idx < wp_start) { | 
|  | 2965 | wp_idx++; | 
|  | 2966 | continue; | 
|  | 2967 | } | 
|  | 2968 |  | 
|  | 2969 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | 
|  | 2970 | continue; | 
|  | 2971 |  | 
|  | 2972 | if_idx = 0; | 
|  | 2973 |  | 
|  | 2974 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { | 
|  | 2975 | if (if_idx < if_start) { | 
|  | 2976 | if_idx++; | 
|  | 2977 | continue; | 
|  | 2978 | } | 
|  | 2979 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, | 
|  | 2980 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 2981 | rdev, wdev, false) < 0) { | 
|  | 2982 | goto out; | 
|  | 2983 | } | 
|  | 2984 | if_idx++; | 
|  | 2985 | } | 
|  | 2986 |  | 
|  | 2987 | wp_idx++; | 
|  | 2988 | } | 
|  | 2989 | out: | 
|  | 2990 | cb->args[0] = wp_idx; | 
|  | 2991 | cb->args[1] = if_idx; | 
|  | 2992 |  | 
|  | 2993 | ret = skb->len; | 
|  | 2994 | out_unlock: | 
|  | 2995 | rtnl_unlock(); | 
|  | 2996 |  | 
|  | 2997 | return ret; | 
|  | 2998 | } | 
|  | 2999 |  | 
|  | 3000 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | 
|  | 3001 | { | 
|  | 3002 | struct sk_buff *msg; | 
|  | 3003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3004 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 3005 |  | 
|  | 3006 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 3007 | if (!msg) | 
|  | 3008 | return -ENOMEM; | 
|  | 3009 |  | 
|  | 3010 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 3011 | rdev, wdev, false) < 0) { | 
|  | 3012 | nlmsg_free(msg); | 
|  | 3013 | return -ENOBUFS; | 
|  | 3014 | } | 
|  | 3015 |  | 
|  | 3016 | return genlmsg_reply(msg, info); | 
|  | 3017 | } | 
|  | 3018 |  | 
|  | 3019 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { | 
|  | 3020 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | 
|  | 3021 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | 
|  | 3022 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | 
|  | 3023 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | 
|  | 3024 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | 
|  | 3025 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, | 
|  | 3026 | }; | 
|  | 3027 |  | 
|  | 3028 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | 
|  | 3029 | { | 
|  | 3030 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | 
|  | 3031 | int flag; | 
|  | 3032 |  | 
|  | 3033 | *mntrflags = 0; | 
|  | 3034 |  | 
|  | 3035 | if (!nla) | 
|  | 3036 | return -EINVAL; | 
|  | 3037 |  | 
|  | 3038 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, | 
|  | 3039 | mntr_flags_policy, NULL)) | 
|  | 3040 | return -EINVAL; | 
|  | 3041 |  | 
|  | 3042 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | 
|  | 3043 | if (flags[flag]) | 
|  | 3044 | *mntrflags |= (1<<flag); | 
|  | 3045 |  | 
|  | 3046 | *mntrflags |= MONITOR_FLAG_CHANGED; | 
|  | 3047 |  | 
|  | 3048 | return 0; | 
|  | 3049 | } | 
|  | 3050 |  | 
|  | 3051 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, | 
|  | 3052 | enum nl80211_iftype type, | 
|  | 3053 | struct genl_info *info, | 
|  | 3054 | struct vif_params *params) | 
|  | 3055 | { | 
|  | 3056 | bool change = false; | 
|  | 3057 | int err; | 
|  | 3058 |  | 
|  | 3059 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { | 
|  | 3060 | if (type != NL80211_IFTYPE_MONITOR) | 
|  | 3061 | return -EINVAL; | 
|  | 3062 |  | 
|  | 3063 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | 
|  | 3064 | ¶ms->flags); | 
|  | 3065 | if (err) | 
|  | 3066 | return err; | 
|  | 3067 |  | 
|  | 3068 | change = true; | 
|  | 3069 | } | 
|  | 3070 |  | 
|  | 3071 | if (params->flags & MONITOR_FLAG_ACTIVE && | 
|  | 3072 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | 
|  | 3073 | return -EOPNOTSUPP; | 
|  | 3074 |  | 
|  | 3075 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { | 
|  | 3076 | const u8 *mumimo_groups; | 
|  | 3077 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | 
|  | 3078 |  | 
|  | 3079 | if (type != NL80211_IFTYPE_MONITOR) | 
|  | 3080 | return -EINVAL; | 
|  | 3081 |  | 
|  | 3082 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | 
|  | 3083 | return -EOPNOTSUPP; | 
|  | 3084 |  | 
|  | 3085 | mumimo_groups = | 
|  | 3086 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | 
|  | 3087 |  | 
|  | 3088 | /* bits 0 and 63 are reserved and must be zero */ | 
|  | 3089 | if ((mumimo_groups[0] & BIT(0)) || | 
|  | 3090 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) | 
|  | 3091 | return -EINVAL; | 
|  | 3092 |  | 
|  | 3093 | params->vht_mumimo_groups = mumimo_groups; | 
|  | 3094 | change = true; | 
|  | 3095 | } | 
|  | 3096 |  | 
|  | 3097 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | 
|  | 3098 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | 
|  | 3099 |  | 
|  | 3100 | if (type != NL80211_IFTYPE_MONITOR) | 
|  | 3101 | return -EINVAL; | 
|  | 3102 |  | 
|  | 3103 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | 
|  | 3104 | return -EOPNOTSUPP; | 
|  | 3105 |  | 
|  | 3106 | params->vht_mumimo_follow_addr = | 
|  | 3107 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); | 
|  | 3108 | change = true; | 
|  | 3109 | } | 
|  | 3110 |  | 
|  | 3111 | return change ? 1 : 0; | 
|  | 3112 | } | 
|  | 3113 |  | 
|  | 3114 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, | 
|  | 3115 | struct net_device *netdev, u8 use_4addr, | 
|  | 3116 | enum nl80211_iftype iftype) | 
|  | 3117 | { | 
|  | 3118 | if (!use_4addr) { | 
|  | 3119 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) | 
|  | 3120 | return -EBUSY; | 
|  | 3121 | return 0; | 
|  | 3122 | } | 
|  | 3123 |  | 
|  | 3124 | switch (iftype) { | 
|  | 3125 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 3126 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | 
|  | 3127 | return 0; | 
|  | 3128 | break; | 
|  | 3129 | case NL80211_IFTYPE_STATION: | 
|  | 3130 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | 
|  | 3131 | return 0; | 
|  | 3132 | break; | 
|  | 3133 | default: | 
|  | 3134 | break; | 
|  | 3135 | } | 
|  | 3136 |  | 
|  | 3137 | return -EOPNOTSUPP; | 
|  | 3138 | } | 
|  | 3139 |  | 
|  | 3140 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) | 
|  | 3141 | { | 
|  | 3142 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3143 | struct vif_params params; | 
|  | 3144 | int err; | 
|  | 3145 | enum nl80211_iftype otype, ntype; | 
|  | 3146 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3147 | bool change = false; | 
|  | 3148 |  | 
|  | 3149 | memset(¶ms, 0, sizeof(params)); | 
|  | 3150 |  | 
|  | 3151 | otype = ntype = dev->ieee80211_ptr->iftype; | 
|  | 3152 |  | 
|  | 3153 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | 
|  | 3154 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | 
|  | 3155 | if (otype != ntype) | 
|  | 3156 | change = true; | 
|  | 3157 | if (ntype > NL80211_IFTYPE_MAX) | 
|  | 3158 | return -EINVAL; | 
|  | 3159 | } | 
|  | 3160 |  | 
|  | 3161 | if (info->attrs[NL80211_ATTR_MESH_ID]) { | 
|  | 3162 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 3163 |  | 
|  | 3164 | if (ntype != NL80211_IFTYPE_MESH_POINT) | 
|  | 3165 | return -EINVAL; | 
|  | 3166 | if (netif_running(dev)) | 
|  | 3167 | return -EBUSY; | 
|  | 3168 |  | 
|  | 3169 | wdev_lock(wdev); | 
|  | 3170 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | 
|  | 3171 | IEEE80211_MAX_MESH_ID_LEN); | 
|  | 3172 | wdev->mesh_id_up_len = | 
|  | 3173 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 
|  | 3174 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | 
|  | 3175 | wdev->mesh_id_up_len); | 
|  | 3176 | wdev_unlock(wdev); | 
|  | 3177 | } | 
|  | 3178 |  | 
|  | 3179 | if (info->attrs[NL80211_ATTR_4ADDR]) { | 
|  | 3180 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | 
|  | 3181 | change = true; | 
|  | 3182 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); | 
|  | 3183 | if (err) | 
|  | 3184 | return err; | 
|  | 3185 | } else { | 
|  | 3186 | params.use_4addr = -1; | 
|  | 3187 | } | 
|  | 3188 |  | 
|  | 3189 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); | 
|  | 3190 | if (err < 0) | 
|  | 3191 | return err; | 
|  | 3192 | if (err > 0) | 
|  | 3193 | change = true; | 
|  | 3194 |  | 
|  | 3195 | if (change) | 
|  | 3196 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); | 
|  | 3197 | else | 
|  | 3198 | err = 0; | 
|  | 3199 |  | 
|  | 3200 | if (!err && params.use_4addr != -1) | 
|  | 3201 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | 
|  | 3202 |  | 
|  | 3203 | return err; | 
|  | 3204 | } | 
|  | 3205 |  | 
|  | 3206 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | 
|  | 3207 | { | 
|  | 3208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3209 | struct vif_params params; | 
|  | 3210 | struct wireless_dev *wdev; | 
|  | 3211 | struct sk_buff *msg; | 
|  | 3212 | int err; | 
|  | 3213 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | 
|  | 3214 |  | 
|  | 3215 | /* to avoid failing a new interface creation due to pending removal */ | 
|  | 3216 | cfg80211_destroy_ifaces(rdev); | 
|  | 3217 |  | 
|  | 3218 | memset(¶ms, 0, sizeof(params)); | 
|  | 3219 |  | 
|  | 3220 | if (!info->attrs[NL80211_ATTR_IFNAME]) | 
|  | 3221 | return -EINVAL; | 
|  | 3222 |  | 
|  | 3223 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | 
|  | 3224 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | 
|  | 3225 | if (type > NL80211_IFTYPE_MAX) | 
|  | 3226 | return -EINVAL; | 
|  | 3227 | } | 
|  | 3228 |  | 
|  | 3229 | if (!rdev->ops->add_virtual_intf) | 
|  | 3230 | return -EOPNOTSUPP; | 
|  | 3231 |  | 
|  | 3232 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || | 
|  | 3233 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | 
|  | 3234 | info->attrs[NL80211_ATTR_MAC]) { | 
|  | 3235 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | 
|  | 3236 | ETH_ALEN); | 
|  | 3237 | if (!is_valid_ether_addr(params.macaddr)) | 
|  | 3238 | return -EADDRNOTAVAIL; | 
|  | 3239 | } | 
|  | 3240 |  | 
|  | 3241 | if (info->attrs[NL80211_ATTR_4ADDR]) { | 
|  | 3242 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | 
|  | 3243 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); | 
|  | 3244 | if (err) | 
|  | 3245 | return err; | 
|  | 3246 | } | 
|  | 3247 |  | 
|  | 3248 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) | 
|  | 3249 | return -EOPNOTSUPP; | 
|  | 3250 |  | 
|  | 3251 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); | 
|  | 3252 | if (err < 0) | 
|  | 3253 | return err; | 
|  | 3254 |  | 
|  | 3255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 3256 | if (!msg) | 
|  | 3257 | return -ENOMEM; | 
|  | 3258 |  | 
|  | 3259 | wdev = rdev_add_virtual_intf(rdev, | 
|  | 3260 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | 
|  | 3261 | NET_NAME_USER, type, ¶ms); | 
|  | 3262 | if (WARN_ON(!wdev)) { | 
|  | 3263 | nlmsg_free(msg); | 
|  | 3264 | return -EPROTO; | 
|  | 3265 | } else if (IS_ERR(wdev)) { | 
|  | 3266 | nlmsg_free(msg); | 
|  | 3267 | return PTR_ERR(wdev); | 
|  | 3268 | } | 
|  | 3269 |  | 
|  | 3270 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
|  | 3271 | wdev->owner_nlportid = info->snd_portid; | 
|  | 3272 |  | 
|  | 3273 | switch (type) { | 
|  | 3274 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 3275 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | 
|  | 3276 | break; | 
|  | 3277 | wdev_lock(wdev); | 
|  | 3278 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | 
|  | 3279 | IEEE80211_MAX_MESH_ID_LEN); | 
|  | 3280 | wdev->mesh_id_up_len = | 
|  | 3281 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 
|  | 3282 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | 
|  | 3283 | wdev->mesh_id_up_len); | 
|  | 3284 | wdev_unlock(wdev); | 
|  | 3285 | break; | 
|  | 3286 | case NL80211_IFTYPE_NAN: | 
|  | 3287 | case NL80211_IFTYPE_P2P_DEVICE: | 
|  | 3288 | /* | 
|  | 3289 | * P2P Device and NAN do not have a netdev, so don't go | 
|  | 3290 | * through the netdev notifier and must be added here | 
|  | 3291 | */ | 
|  | 3292 | mutex_init(&wdev->mtx); | 
|  | 3293 | INIT_LIST_HEAD(&wdev->event_list); | 
|  | 3294 | spin_lock_init(&wdev->event_lock); | 
|  | 3295 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | 
|  | 3296 | spin_lock_init(&wdev->mgmt_registrations_lock); | 
|  | 3297 |  | 
|  | 3298 | wdev->identifier = ++rdev->wdev_id; | 
|  | 3299 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); | 
|  | 3300 | rdev->devlist_generation++; | 
|  | 3301 | break; | 
|  | 3302 | default: | 
|  | 3303 | break; | 
|  | 3304 | } | 
|  | 3305 |  | 
|  | 3306 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 3307 | rdev, wdev, false) < 0) { | 
|  | 3308 | nlmsg_free(msg); | 
|  | 3309 | return -ENOBUFS; | 
|  | 3310 | } | 
|  | 3311 |  | 
|  | 3312 | /* | 
|  | 3313 | * For wdevs which have no associated netdev object (e.g. of type | 
|  | 3314 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. | 
|  | 3315 | * For all other types, the event will be generated from the | 
|  | 3316 | * netdev notifier | 
|  | 3317 | */ | 
|  | 3318 | if (!wdev->netdev) | 
|  | 3319 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); | 
|  | 3320 |  | 
|  | 3321 | return genlmsg_reply(msg, info); | 
|  | 3322 | } | 
|  | 3323 |  | 
|  | 3324 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | 
|  | 3325 | { | 
|  | 3326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3327 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 3328 |  | 
|  | 3329 | if (!rdev->ops->del_virtual_intf) | 
|  | 3330 | return -EOPNOTSUPP; | 
|  | 3331 |  | 
|  | 3332 | /* | 
|  | 3333 | * If we remove a wireless device without a netdev then clear | 
|  | 3334 | * user_ptr[1] so that nl80211_post_doit won't dereference it | 
|  | 3335 | * to check if it needs to do dev_put(). Otherwise it crashes | 
|  | 3336 | * since the wdev has been freed, unlike with a netdev where | 
|  | 3337 | * we need the dev_put() for the netdev to really be freed. | 
|  | 3338 | */ | 
|  | 3339 | if (!wdev->netdev) | 
|  | 3340 | info->user_ptr[1] = NULL; | 
|  | 3341 |  | 
|  | 3342 | return rdev_del_virtual_intf(rdev, wdev); | 
|  | 3343 | } | 
|  | 3344 |  | 
|  | 3345 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) | 
|  | 3346 | { | 
|  | 3347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3348 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3349 | u16 noack_map; | 
|  | 3350 |  | 
|  | 3351 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | 
|  | 3352 | return -EINVAL; | 
|  | 3353 |  | 
|  | 3354 | if (!rdev->ops->set_noack_map) | 
|  | 3355 | return -EOPNOTSUPP; | 
|  | 3356 |  | 
|  | 3357 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | 
|  | 3358 |  | 
|  | 3359 | return rdev_set_noack_map(rdev, dev, noack_map); | 
|  | 3360 | } | 
|  | 3361 |  | 
|  | 3362 | struct get_key_cookie { | 
|  | 3363 | struct sk_buff *msg; | 
|  | 3364 | int error; | 
|  | 3365 | int idx; | 
|  | 3366 | }; | 
|  | 3367 |  | 
|  | 3368 | static void get_key_callback(void *c, struct key_params *params) | 
|  | 3369 | { | 
|  | 3370 | struct nlattr *key; | 
|  | 3371 | struct get_key_cookie *cookie = c; | 
|  | 3372 |  | 
|  | 3373 | if ((params->key && | 
|  | 3374 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | 
|  | 3375 | params->key_len, params->key)) || | 
|  | 3376 | (params->seq && | 
|  | 3377 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | 
|  | 3378 | params->seq_len, params->seq)) || | 
|  | 3379 | (params->cipher && | 
|  | 3380 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | 
|  | 3381 | params->cipher))) | 
|  | 3382 | goto nla_put_failure; | 
|  | 3383 |  | 
|  | 3384 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); | 
|  | 3385 | if (!key) | 
|  | 3386 | goto nla_put_failure; | 
|  | 3387 |  | 
|  | 3388 | if ((params->key && | 
|  | 3389 | nla_put(cookie->msg, NL80211_KEY_DATA, | 
|  | 3390 | params->key_len, params->key)) || | 
|  | 3391 | (params->seq && | 
|  | 3392 | nla_put(cookie->msg, NL80211_KEY_SEQ, | 
|  | 3393 | params->seq_len, params->seq)) || | 
|  | 3394 | (params->cipher && | 
|  | 3395 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | 
|  | 3396 | params->cipher))) | 
|  | 3397 | goto nla_put_failure; | 
|  | 3398 |  | 
|  | 3399 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) | 
|  | 3400 | goto nla_put_failure; | 
|  | 3401 |  | 
|  | 3402 | nla_nest_end(cookie->msg, key); | 
|  | 3403 |  | 
|  | 3404 | return; | 
|  | 3405 | nla_put_failure: | 
|  | 3406 | cookie->error = 1; | 
|  | 3407 | } | 
|  | 3408 |  | 
|  | 3409 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | 
|  | 3410 | { | 
|  | 3411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3412 | int err; | 
|  | 3413 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3414 | u8 key_idx = 0; | 
|  | 3415 | const u8 *mac_addr = NULL; | 
|  | 3416 | bool pairwise; | 
|  | 3417 | struct get_key_cookie cookie = { | 
|  | 3418 | .error = 0, | 
|  | 3419 | }; | 
|  | 3420 | void *hdr; | 
|  | 3421 | struct sk_buff *msg; | 
|  | 3422 |  | 
|  | 3423 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | 
|  | 3424 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | 
|  | 3425 |  | 
|  | 3426 | if (key_idx > 5) | 
|  | 3427 | return -EINVAL; | 
|  | 3428 |  | 
|  | 3429 | if (info->attrs[NL80211_ATTR_MAC]) | 
|  | 3430 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 3431 |  | 
|  | 3432 | pairwise = !!mac_addr; | 
|  | 3433 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | 
|  | 3434 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | 
|  | 3435 |  | 
|  | 3436 | if (kt >= NUM_NL80211_KEYTYPES) | 
|  | 3437 | return -EINVAL; | 
|  | 3438 | if (kt != NL80211_KEYTYPE_GROUP && | 
|  | 3439 | kt != NL80211_KEYTYPE_PAIRWISE) | 
|  | 3440 | return -EINVAL; | 
|  | 3441 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | 
|  | 3442 | } | 
|  | 3443 |  | 
|  | 3444 | if (!rdev->ops->get_key) | 
|  | 3445 | return -EOPNOTSUPP; | 
|  | 3446 |  | 
|  | 3447 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | 
|  | 3448 | return -ENOENT; | 
|  | 3449 |  | 
|  | 3450 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 3451 | if (!msg) | 
|  | 3452 | return -ENOMEM; | 
|  | 3453 |  | 
|  | 3454 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 3455 | NL80211_CMD_NEW_KEY); | 
|  | 3456 | if (!hdr) | 
|  | 3457 | goto nla_put_failure; | 
|  | 3458 |  | 
|  | 3459 | cookie.msg = msg; | 
|  | 3460 | cookie.idx = key_idx; | 
|  | 3461 |  | 
|  | 3462 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 3463 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | 
|  | 3464 | goto nla_put_failure; | 
|  | 3465 | if (mac_addr && | 
|  | 3466 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | 
|  | 3467 | goto nla_put_failure; | 
|  | 3468 |  | 
|  | 3469 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, | 
|  | 3470 | get_key_callback); | 
|  | 3471 |  | 
|  | 3472 | if (err) | 
|  | 3473 | goto free_msg; | 
|  | 3474 |  | 
|  | 3475 | if (cookie.error) | 
|  | 3476 | goto nla_put_failure; | 
|  | 3477 |  | 
|  | 3478 | genlmsg_end(msg, hdr); | 
|  | 3479 | return genlmsg_reply(msg, info); | 
|  | 3480 |  | 
|  | 3481 | nla_put_failure: | 
|  | 3482 | err = -ENOBUFS; | 
|  | 3483 | free_msg: | 
|  | 3484 | nlmsg_free(msg); | 
|  | 3485 | return err; | 
|  | 3486 | } | 
|  | 3487 |  | 
|  | 3488 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | 
|  | 3489 | { | 
|  | 3490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3491 | struct key_parse key; | 
|  | 3492 | int err; | 
|  | 3493 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3494 |  | 
|  | 3495 | err = nl80211_parse_key(info, &key); | 
|  | 3496 | if (err) | 
|  | 3497 | return err; | 
|  | 3498 |  | 
|  | 3499 | if (key.idx < 0) | 
|  | 3500 | return -EINVAL; | 
|  | 3501 |  | 
|  | 3502 | /* only support setting default key */ | 
|  | 3503 | if (!key.def && !key.defmgmt) | 
|  | 3504 | return -EINVAL; | 
|  | 3505 |  | 
|  | 3506 | wdev_lock(dev->ieee80211_ptr); | 
|  | 3507 |  | 
|  | 3508 | if (key.def) { | 
|  | 3509 | if (!rdev->ops->set_default_key) { | 
|  | 3510 | err = -EOPNOTSUPP; | 
|  | 3511 | goto out; | 
|  | 3512 | } | 
|  | 3513 |  | 
|  | 3514 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 
|  | 3515 | if (err) | 
|  | 3516 | goto out; | 
|  | 3517 |  | 
|  | 3518 | err = rdev_set_default_key(rdev, dev, key.idx, | 
|  | 3519 | key.def_uni, key.def_multi); | 
|  | 3520 |  | 
|  | 3521 | if (err) | 
|  | 3522 | goto out; | 
|  | 3523 |  | 
|  | 3524 | #ifdef CONFIG_CFG80211_WEXT | 
|  | 3525 | dev->ieee80211_ptr->wext.default_key = key.idx; | 
|  | 3526 | #endif | 
|  | 3527 | } else { | 
|  | 3528 | if (key.def_uni || !key.def_multi) { | 
|  | 3529 | err = -EINVAL; | 
|  | 3530 | goto out; | 
|  | 3531 | } | 
|  | 3532 |  | 
|  | 3533 | if (!rdev->ops->set_default_mgmt_key) { | 
|  | 3534 | err = -EOPNOTSUPP; | 
|  | 3535 | goto out; | 
|  | 3536 | } | 
|  | 3537 |  | 
|  | 3538 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 
|  | 3539 | if (err) | 
|  | 3540 | goto out; | 
|  | 3541 |  | 
|  | 3542 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); | 
|  | 3543 | if (err) | 
|  | 3544 | goto out; | 
|  | 3545 |  | 
|  | 3546 | #ifdef CONFIG_CFG80211_WEXT | 
|  | 3547 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | 
|  | 3548 | #endif | 
|  | 3549 | } | 
|  | 3550 |  | 
|  | 3551 | out: | 
|  | 3552 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 3553 |  | 
|  | 3554 | return err; | 
|  | 3555 | } | 
|  | 3556 |  | 
|  | 3557 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | 
|  | 3558 | { | 
|  | 3559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3560 | int err; | 
|  | 3561 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3562 | struct key_parse key; | 
|  | 3563 | const u8 *mac_addr = NULL; | 
|  | 3564 |  | 
|  | 3565 | err = nl80211_parse_key(info, &key); | 
|  | 3566 | if (err) | 
|  | 3567 | return err; | 
|  | 3568 |  | 
|  | 3569 | if (!key.p.key) | 
|  | 3570 | return -EINVAL; | 
|  | 3571 |  | 
|  | 3572 | if (info->attrs[NL80211_ATTR_MAC]) | 
|  | 3573 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 3574 |  | 
|  | 3575 | if (key.type == -1) { | 
|  | 3576 | if (mac_addr) | 
|  | 3577 | key.type = NL80211_KEYTYPE_PAIRWISE; | 
|  | 3578 | else | 
|  | 3579 | key.type = NL80211_KEYTYPE_GROUP; | 
|  | 3580 | } | 
|  | 3581 |  | 
|  | 3582 | /* for now */ | 
|  | 3583 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | 
|  | 3584 | key.type != NL80211_KEYTYPE_GROUP) | 
|  | 3585 | return -EINVAL; | 
|  | 3586 |  | 
|  | 3587 | if (!rdev->ops->add_key) | 
|  | 3588 | return -EOPNOTSUPP; | 
|  | 3589 |  | 
|  | 3590 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, | 
|  | 3591 | key.type == NL80211_KEYTYPE_PAIRWISE, | 
|  | 3592 | mac_addr)) | 
|  | 3593 | return -EINVAL; | 
|  | 3594 |  | 
|  | 3595 | wdev_lock(dev->ieee80211_ptr); | 
|  | 3596 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 
|  | 3597 | if (!err) | 
|  | 3598 | err = rdev_add_key(rdev, dev, key.idx, | 
|  | 3599 | key.type == NL80211_KEYTYPE_PAIRWISE, | 
|  | 3600 | mac_addr, &key.p); | 
|  | 3601 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 3602 |  | 
|  | 3603 | return err; | 
|  | 3604 | } | 
|  | 3605 |  | 
|  | 3606 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | 
|  | 3607 | { | 
|  | 3608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3609 | int err; | 
|  | 3610 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3611 | u8 *mac_addr = NULL; | 
|  | 3612 | struct key_parse key; | 
|  | 3613 |  | 
|  | 3614 | err = nl80211_parse_key(info, &key); | 
|  | 3615 | if (err) | 
|  | 3616 | return err; | 
|  | 3617 |  | 
|  | 3618 | if (info->attrs[NL80211_ATTR_MAC]) | 
|  | 3619 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 3620 |  | 
|  | 3621 | if (key.type == -1) { | 
|  | 3622 | if (mac_addr) | 
|  | 3623 | key.type = NL80211_KEYTYPE_PAIRWISE; | 
|  | 3624 | else | 
|  | 3625 | key.type = NL80211_KEYTYPE_GROUP; | 
|  | 3626 | } | 
|  | 3627 |  | 
|  | 3628 | /* for now */ | 
|  | 3629 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | 
|  | 3630 | key.type != NL80211_KEYTYPE_GROUP) | 
|  | 3631 | return -EINVAL; | 
|  | 3632 |  | 
|  | 3633 | if (!rdev->ops->del_key) | 
|  | 3634 | return -EOPNOTSUPP; | 
|  | 3635 |  | 
|  | 3636 | wdev_lock(dev->ieee80211_ptr); | 
|  | 3637 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 
|  | 3638 |  | 
|  | 3639 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && | 
|  | 3640 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | 
|  | 3641 | err = -ENOENT; | 
|  | 3642 |  | 
|  | 3643 | if (!err) | 
|  | 3644 | err = rdev_del_key(rdev, dev, key.idx, | 
|  | 3645 | key.type == NL80211_KEYTYPE_PAIRWISE, | 
|  | 3646 | mac_addr); | 
|  | 3647 |  | 
|  | 3648 | #ifdef CONFIG_CFG80211_WEXT | 
|  | 3649 | if (!err) { | 
|  | 3650 | if (key.idx == dev->ieee80211_ptr->wext.default_key) | 
|  | 3651 | dev->ieee80211_ptr->wext.default_key = -1; | 
|  | 3652 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) | 
|  | 3653 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; | 
|  | 3654 | } | 
|  | 3655 | #endif | 
|  | 3656 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 3657 |  | 
|  | 3658 | return err; | 
|  | 3659 | } | 
|  | 3660 |  | 
|  | 3661 | /* This function returns an error or the number of nested attributes */ | 
|  | 3662 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | 
|  | 3663 | { | 
|  | 3664 | struct nlattr *attr; | 
|  | 3665 | int n_entries = 0, tmp; | 
|  | 3666 |  | 
|  | 3667 | nla_for_each_nested(attr, nl_attr, tmp) { | 
|  | 3668 | if (nla_len(attr) != ETH_ALEN) | 
|  | 3669 | return -EINVAL; | 
|  | 3670 |  | 
|  | 3671 | n_entries++; | 
|  | 3672 | } | 
|  | 3673 |  | 
|  | 3674 | return n_entries; | 
|  | 3675 | } | 
|  | 3676 |  | 
|  | 3677 | /* | 
|  | 3678 | * This function parses ACL information and allocates memory for ACL data. | 
|  | 3679 | * On successful return, the calling function is responsible to free the | 
|  | 3680 | * ACL buffer returned by this function. | 
|  | 3681 | */ | 
|  | 3682 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | 
|  | 3683 | struct genl_info *info) | 
|  | 3684 | { | 
|  | 3685 | enum nl80211_acl_policy acl_policy; | 
|  | 3686 | struct nlattr *attr; | 
|  | 3687 | struct cfg80211_acl_data *acl; | 
|  | 3688 | int i = 0, n_entries, tmp; | 
|  | 3689 |  | 
|  | 3690 | if (!wiphy->max_acl_mac_addrs) | 
|  | 3691 | return ERR_PTR(-EOPNOTSUPP); | 
|  | 3692 |  | 
|  | 3693 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | 
|  | 3694 | return ERR_PTR(-EINVAL); | 
|  | 3695 |  | 
|  | 3696 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | 
|  | 3697 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | 
|  | 3698 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | 
|  | 3699 | return ERR_PTR(-EINVAL); | 
|  | 3700 |  | 
|  | 3701 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | 
|  | 3702 | return ERR_PTR(-EINVAL); | 
|  | 3703 |  | 
|  | 3704 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | 
|  | 3705 | if (n_entries < 0) | 
|  | 3706 | return ERR_PTR(n_entries); | 
|  | 3707 |  | 
|  | 3708 | if (n_entries > wiphy->max_acl_mac_addrs) | 
|  | 3709 | return ERR_PTR(-ENOTSUPP); | 
|  | 3710 |  | 
|  | 3711 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | 
|  | 3712 | GFP_KERNEL); | 
|  | 3713 | if (!acl) | 
|  | 3714 | return ERR_PTR(-ENOMEM); | 
|  | 3715 |  | 
|  | 3716 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | 
|  | 3717 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | 
|  | 3718 | i++; | 
|  | 3719 | } | 
|  | 3720 |  | 
|  | 3721 | acl->n_acl_entries = n_entries; | 
|  | 3722 | acl->acl_policy = acl_policy; | 
|  | 3723 |  | 
|  | 3724 | return acl; | 
|  | 3725 | } | 
|  | 3726 |  | 
|  | 3727 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | 
|  | 3728 | { | 
|  | 3729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3730 | struct net_device *dev = info->user_ptr[1]; | 
|  | 3731 | struct cfg80211_acl_data *acl; | 
|  | 3732 | int err; | 
|  | 3733 |  | 
|  | 3734 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 3735 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 3736 | return -EOPNOTSUPP; | 
|  | 3737 |  | 
|  | 3738 | if (!dev->ieee80211_ptr->beacon_interval) | 
|  | 3739 | return -EINVAL; | 
|  | 3740 |  | 
|  | 3741 | acl = parse_acl_data(&rdev->wiphy, info); | 
|  | 3742 | if (IS_ERR(acl)) | 
|  | 3743 | return PTR_ERR(acl); | 
|  | 3744 |  | 
|  | 3745 | err = rdev_set_mac_acl(rdev, dev, acl); | 
|  | 3746 |  | 
|  | 3747 | kfree(acl); | 
|  | 3748 |  | 
|  | 3749 | return err; | 
|  | 3750 | } | 
|  | 3751 |  | 
|  | 3752 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, | 
|  | 3753 | u8 *rates, u8 rates_len) | 
|  | 3754 | { | 
|  | 3755 | u8 i; | 
|  | 3756 | u32 mask = 0; | 
|  | 3757 |  | 
|  | 3758 | for (i = 0; i < rates_len; i++) { | 
|  | 3759 | int rate = (rates[i] & 0x7f) * 5; | 
|  | 3760 | int ridx; | 
|  | 3761 |  | 
|  | 3762 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | 
|  | 3763 | struct ieee80211_rate *srate = | 
|  | 3764 | &sband->bitrates[ridx]; | 
|  | 3765 | if (rate == srate->bitrate) { | 
|  | 3766 | mask |= 1 << ridx; | 
|  | 3767 | break; | 
|  | 3768 | } | 
|  | 3769 | } | 
|  | 3770 | if (ridx == sband->n_bitrates) | 
|  | 3771 | return 0; /* rate not found */ | 
|  | 3772 | } | 
|  | 3773 |  | 
|  | 3774 | return mask; | 
|  | 3775 | } | 
|  | 3776 |  | 
|  | 3777 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | 
|  | 3778 | u8 *rates, u8 rates_len, | 
|  | 3779 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | 
|  | 3780 | { | 
|  | 3781 | u8 i; | 
|  | 3782 |  | 
|  | 3783 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | 
|  | 3784 |  | 
|  | 3785 | for (i = 0; i < rates_len; i++) { | 
|  | 3786 | int ridx, rbit; | 
|  | 3787 |  | 
|  | 3788 | ridx = rates[i] / 8; | 
|  | 3789 | rbit = BIT(rates[i] % 8); | 
|  | 3790 |  | 
|  | 3791 | /* check validity */ | 
|  | 3792 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | 
|  | 3793 | return false; | 
|  | 3794 |  | 
|  | 3795 | /* check availability */ | 
|  | 3796 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); | 
|  | 3797 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | 
|  | 3798 | mcs[ridx] |= rbit; | 
|  | 3799 | else | 
|  | 3800 | return false; | 
|  | 3801 | } | 
|  | 3802 |  | 
|  | 3803 | return true; | 
|  | 3804 | } | 
|  | 3805 |  | 
|  | 3806 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | 
|  | 3807 | { | 
|  | 3808 | u16 mcs_mask = 0; | 
|  | 3809 |  | 
|  | 3810 | switch (vht_mcs_map) { | 
|  | 3811 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | 
|  | 3812 | break; | 
|  | 3813 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | 
|  | 3814 | mcs_mask = 0x00FF; | 
|  | 3815 | break; | 
|  | 3816 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | 
|  | 3817 | mcs_mask = 0x01FF; | 
|  | 3818 | break; | 
|  | 3819 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | 
|  | 3820 | mcs_mask = 0x03FF; | 
|  | 3821 | break; | 
|  | 3822 | default: | 
|  | 3823 | break; | 
|  | 3824 | } | 
|  | 3825 |  | 
|  | 3826 | return mcs_mask; | 
|  | 3827 | } | 
|  | 3828 |  | 
|  | 3829 | static void vht_build_mcs_mask(u16 vht_mcs_map, | 
|  | 3830 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | 
|  | 3831 | { | 
|  | 3832 | u8 nss; | 
|  | 3833 |  | 
|  | 3834 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | 
|  | 3835 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | 
|  | 3836 | vht_mcs_map >>= 2; | 
|  | 3837 | } | 
|  | 3838 | } | 
|  | 3839 |  | 
|  | 3840 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | 
|  | 3841 | struct nl80211_txrate_vht *txrate, | 
|  | 3842 | u16 mcs[NL80211_VHT_NSS_MAX]) | 
|  | 3843 | { | 
|  | 3844 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | 
|  | 3845 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | 
|  | 3846 | u8 i; | 
|  | 3847 |  | 
|  | 3848 | if (!sband->vht_cap.vht_supported) | 
|  | 3849 | return false; | 
|  | 3850 |  | 
|  | 3851 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | 
|  | 3852 |  | 
|  | 3853 | /* Build vht_mcs_mask from VHT capabilities */ | 
|  | 3854 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | 
|  | 3855 |  | 
|  | 3856 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | 
|  | 3857 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | 
|  | 3858 | mcs[i] = txrate->mcs[i]; | 
|  | 3859 | else | 
|  | 3860 | return false; | 
|  | 3861 | } | 
|  | 3862 |  | 
|  | 3863 | return true; | 
|  | 3864 | } | 
|  | 3865 |  | 
|  | 3866 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | 
|  | 3867 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | 
|  | 3868 | .len = NL80211_MAX_SUPP_RATES }, | 
|  | 3869 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | 
|  | 3870 | .len = NL80211_MAX_SUPP_HT_RATES }, | 
|  | 3871 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, | 
|  | 3872 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, | 
|  | 3873 | }; | 
|  | 3874 |  | 
|  | 3875 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, | 
|  | 3876 | struct cfg80211_bitrate_mask *mask) | 
|  | 3877 | { | 
|  | 3878 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | 
|  | 3879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 3880 | int rem, i; | 
|  | 3881 | struct nlattr *tx_rates; | 
|  | 3882 | struct ieee80211_supported_band *sband; | 
|  | 3883 | u16 vht_tx_mcs_map; | 
|  | 3884 |  | 
|  | 3885 | memset(mask, 0, sizeof(*mask)); | 
|  | 3886 | /* Default to all rates enabled */ | 
|  | 3887 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | 
|  | 3888 | sband = rdev->wiphy.bands[i]; | 
|  | 3889 |  | 
|  | 3890 | if (!sband) | 
|  | 3891 | continue; | 
|  | 3892 |  | 
|  | 3893 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | 
|  | 3894 | memcpy(mask->control[i].ht_mcs, | 
|  | 3895 | sband->ht_cap.mcs.rx_mask, | 
|  | 3896 | sizeof(mask->control[i].ht_mcs)); | 
|  | 3897 |  | 
|  | 3898 | if (!sband->vht_cap.vht_supported) | 
|  | 3899 | continue; | 
|  | 3900 |  | 
|  | 3901 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | 
|  | 3902 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | 
|  | 3903 | } | 
|  | 3904 |  | 
|  | 3905 | /* if no rates are given set it back to the defaults */ | 
|  | 3906 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | 
|  | 3907 | goto out; | 
|  | 3908 |  | 
|  | 3909 | /* The nested attribute uses enum nl80211_band as the index. This maps | 
|  | 3910 | * directly to the enum nl80211_band values used in cfg80211. | 
|  | 3911 | */ | 
|  | 3912 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | 
|  | 3913 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { | 
|  | 3914 | enum nl80211_band band = nla_type(tx_rates); | 
|  | 3915 | int err; | 
|  | 3916 |  | 
|  | 3917 | if (band < 0 || band >= NUM_NL80211_BANDS) | 
|  | 3918 | return -EINVAL; | 
|  | 3919 | sband = rdev->wiphy.bands[band]; | 
|  | 3920 | if (sband == NULL) | 
|  | 3921 | return -EINVAL; | 
|  | 3922 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, | 
|  | 3923 | nl80211_txattr_policy, info->extack); | 
|  | 3924 | if (err) | 
|  | 3925 | return err; | 
|  | 3926 | if (tb[NL80211_TXRATE_LEGACY]) { | 
|  | 3927 | mask->control[band].legacy = rateset_to_mask( | 
|  | 3928 | sband, | 
|  | 3929 | nla_data(tb[NL80211_TXRATE_LEGACY]), | 
|  | 3930 | nla_len(tb[NL80211_TXRATE_LEGACY])); | 
|  | 3931 | if ((mask->control[band].legacy == 0) && | 
|  | 3932 | nla_len(tb[NL80211_TXRATE_LEGACY])) | 
|  | 3933 | return -EINVAL; | 
|  | 3934 | } | 
|  | 3935 | if (tb[NL80211_TXRATE_HT]) { | 
|  | 3936 | if (!ht_rateset_to_mask( | 
|  | 3937 | sband, | 
|  | 3938 | nla_data(tb[NL80211_TXRATE_HT]), | 
|  | 3939 | nla_len(tb[NL80211_TXRATE_HT]), | 
|  | 3940 | mask->control[band].ht_mcs)) | 
|  | 3941 | return -EINVAL; | 
|  | 3942 | } | 
|  | 3943 | if (tb[NL80211_TXRATE_VHT]) { | 
|  | 3944 | if (!vht_set_mcs_mask( | 
|  | 3945 | sband, | 
|  | 3946 | nla_data(tb[NL80211_TXRATE_VHT]), | 
|  | 3947 | mask->control[band].vht_mcs)) | 
|  | 3948 | return -EINVAL; | 
|  | 3949 | } | 
|  | 3950 | if (tb[NL80211_TXRATE_GI]) { | 
|  | 3951 | mask->control[band].gi = | 
|  | 3952 | nla_get_u8(tb[NL80211_TXRATE_GI]); | 
|  | 3953 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | 
|  | 3954 | return -EINVAL; | 
|  | 3955 | } | 
|  | 3956 |  | 
|  | 3957 | if (mask->control[band].legacy == 0) { | 
|  | 3958 | /* don't allow empty legacy rates if HT or VHT | 
|  | 3959 | * are not even supported. | 
|  | 3960 | */ | 
|  | 3961 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | 
|  | 3962 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | 
|  | 3963 | return -EINVAL; | 
|  | 3964 |  | 
|  | 3965 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | 
|  | 3966 | if (mask->control[band].ht_mcs[i]) | 
|  | 3967 | goto out; | 
|  | 3968 |  | 
|  | 3969 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | 
|  | 3970 | if (mask->control[band].vht_mcs[i]) | 
|  | 3971 | goto out; | 
|  | 3972 |  | 
|  | 3973 | /* legacy and mcs rates may not be both empty */ | 
|  | 3974 | return -EINVAL; | 
|  | 3975 | } | 
|  | 3976 | } | 
|  | 3977 |  | 
|  | 3978 | out: | 
|  | 3979 | return 0; | 
|  | 3980 | } | 
|  | 3981 |  | 
|  | 3982 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, | 
|  | 3983 | enum nl80211_band band, | 
|  | 3984 | struct cfg80211_bitrate_mask *beacon_rate) | 
|  | 3985 | { | 
|  | 3986 | u32 count_ht, count_vht, i; | 
|  | 3987 | u32 rate = beacon_rate->control[band].legacy; | 
|  | 3988 |  | 
|  | 3989 | /* Allow only one rate */ | 
|  | 3990 | if (hweight32(rate) > 1) | 
|  | 3991 | return -EINVAL; | 
|  | 3992 |  | 
|  | 3993 | count_ht = 0; | 
|  | 3994 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | 
|  | 3995 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { | 
|  | 3996 | return -EINVAL; | 
|  | 3997 | } else if (beacon_rate->control[band].ht_mcs[i]) { | 
|  | 3998 | count_ht++; | 
|  | 3999 | if (count_ht > 1) | 
|  | 4000 | return -EINVAL; | 
|  | 4001 | } | 
|  | 4002 | if (count_ht && rate) | 
|  | 4003 | return -EINVAL; | 
|  | 4004 | } | 
|  | 4005 |  | 
|  | 4006 | count_vht = 0; | 
|  | 4007 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | 
|  | 4008 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { | 
|  | 4009 | return -EINVAL; | 
|  | 4010 | } else if (beacon_rate->control[band].vht_mcs[i]) { | 
|  | 4011 | count_vht++; | 
|  | 4012 | if (count_vht > 1) | 
|  | 4013 | return -EINVAL; | 
|  | 4014 | } | 
|  | 4015 | if (count_vht && rate) | 
|  | 4016 | return -EINVAL; | 
|  | 4017 | } | 
|  | 4018 |  | 
|  | 4019 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) | 
|  | 4020 | return -EINVAL; | 
|  | 4021 |  | 
|  | 4022 | if (rate && | 
|  | 4023 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 4024 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | 
|  | 4025 | return -EINVAL; | 
|  | 4026 | if (count_ht && | 
|  | 4027 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 4028 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | 
|  | 4029 | return -EINVAL; | 
|  | 4030 | if (count_vht && | 
|  | 4031 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 4032 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | 
|  | 4033 | return -EINVAL; | 
|  | 4034 |  | 
|  | 4035 | return 0; | 
|  | 4036 | } | 
|  | 4037 |  | 
|  | 4038 | static int nl80211_parse_beacon(struct nlattr *attrs[], | 
|  | 4039 | struct cfg80211_beacon_data *bcn) | 
|  | 4040 | { | 
|  | 4041 | bool haveinfo = false; | 
|  | 4042 |  | 
|  | 4043 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || | 
|  | 4044 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | 
|  | 4045 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | 
|  | 4046 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | 
|  | 4047 | return -EINVAL; | 
|  | 4048 |  | 
|  | 4049 | memset(bcn, 0, sizeof(*bcn)); | 
|  | 4050 |  | 
|  | 4051 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { | 
|  | 4052 | int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD], | 
|  | 4053 | NULL); | 
|  | 4054 |  | 
|  | 4055 | if (ret) | 
|  | 4056 | return ret; | 
|  | 4057 |  | 
|  | 4058 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | 
|  | 4059 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | 
|  | 4060 | if (!bcn->head_len) | 
|  | 4061 | return -EINVAL; | 
|  | 4062 | haveinfo = true; | 
|  | 4063 | } | 
|  | 4064 |  | 
|  | 4065 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { | 
|  | 4066 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | 
|  | 4067 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | 
|  | 4068 | haveinfo = true; | 
|  | 4069 | } | 
|  | 4070 |  | 
|  | 4071 | if (!haveinfo) | 
|  | 4072 | return -EINVAL; | 
|  | 4073 |  | 
|  | 4074 | if (attrs[NL80211_ATTR_IE]) { | 
|  | 4075 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | 
|  | 4076 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | 
|  | 4077 | } | 
|  | 4078 |  | 
|  | 4079 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { | 
|  | 4080 | bcn->proberesp_ies = | 
|  | 4081 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); | 
|  | 4082 | bcn->proberesp_ies_len = | 
|  | 4083 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); | 
|  | 4084 | } | 
|  | 4085 |  | 
|  | 4086 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | 
|  | 4087 | bcn->assocresp_ies = | 
|  | 4088 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); | 
|  | 4089 | bcn->assocresp_ies_len = | 
|  | 4090 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); | 
|  | 4091 | } | 
|  | 4092 |  | 
|  | 4093 | if (attrs[NL80211_ATTR_PROBE_RESP]) { | 
|  | 4094 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | 
|  | 4095 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | 
|  | 4096 | } | 
|  | 4097 |  | 
|  | 4098 | return 0; | 
|  | 4099 | } | 
|  | 4100 |  | 
|  | 4101 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, | 
|  | 4102 | const u8 *rates) | 
|  | 4103 | { | 
|  | 4104 | int i; | 
|  | 4105 |  | 
|  | 4106 | if (!rates) | 
|  | 4107 | return; | 
|  | 4108 |  | 
|  | 4109 | for (i = 0; i < rates[1]; i++) { | 
|  | 4110 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) | 
|  | 4111 | params->ht_required = true; | 
|  | 4112 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) | 
|  | 4113 | params->vht_required = true; | 
|  | 4114 | } | 
|  | 4115 | } | 
|  | 4116 |  | 
|  | 4117 | /* | 
|  | 4118 | * Since the nl80211 API didn't include, from the beginning, attributes about | 
|  | 4119 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the | 
|  | 4120 | * benefit of drivers that rebuild IEs in the firmware. | 
|  | 4121 | */ | 
|  | 4122 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) | 
|  | 4123 | { | 
|  | 4124 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; | 
|  | 4125 | size_t ies_len = bcn->tail_len; | 
|  | 4126 | const u8 *ies = bcn->tail; | 
|  | 4127 | const u8 *rates; | 
|  | 4128 | const u8 *cap; | 
|  | 4129 |  | 
|  | 4130 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); | 
|  | 4131 | nl80211_check_ap_rate_selectors(params, rates); | 
|  | 4132 |  | 
|  | 4133 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); | 
|  | 4134 | nl80211_check_ap_rate_selectors(params, rates); | 
|  | 4135 |  | 
|  | 4136 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); | 
|  | 4137 | if (cap && cap[1] >= sizeof(*params->ht_cap)) | 
|  | 4138 | params->ht_cap = (void *)(cap + 2); | 
|  | 4139 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); | 
|  | 4140 | if (cap && cap[1] >= sizeof(*params->vht_cap)) | 
|  | 4141 | params->vht_cap = (void *)(cap + 2); | 
|  | 4142 | } | 
|  | 4143 |  | 
|  | 4144 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, | 
|  | 4145 | struct cfg80211_ap_settings *params) | 
|  | 4146 | { | 
|  | 4147 | struct wireless_dev *wdev; | 
|  | 4148 | bool ret = false; | 
|  | 4149 |  | 
|  | 4150 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { | 
|  | 4151 | if (wdev->iftype != NL80211_IFTYPE_AP && | 
|  | 4152 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 4153 | continue; | 
|  | 4154 |  | 
|  | 4155 | if (!wdev->preset_chandef.chan) | 
|  | 4156 | continue; | 
|  | 4157 |  | 
|  | 4158 | params->chandef = wdev->preset_chandef; | 
|  | 4159 | ret = true; | 
|  | 4160 | break; | 
|  | 4161 | } | 
|  | 4162 |  | 
|  | 4163 | return ret; | 
|  | 4164 | } | 
|  | 4165 |  | 
|  | 4166 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, | 
|  | 4167 | enum nl80211_auth_type auth_type, | 
|  | 4168 | enum nl80211_commands cmd) | 
|  | 4169 | { | 
|  | 4170 | if (auth_type > NL80211_AUTHTYPE_MAX) | 
|  | 4171 | return false; | 
|  | 4172 |  | 
|  | 4173 | switch (cmd) { | 
|  | 4174 | case NL80211_CMD_AUTHENTICATE: | 
|  | 4175 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | 
|  | 4176 | auth_type == NL80211_AUTHTYPE_SAE) | 
|  | 4177 | return false; | 
|  | 4178 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 4179 | NL80211_EXT_FEATURE_FILS_STA) && | 
|  | 4180 | (auth_type == NL80211_AUTHTYPE_FILS_SK || | 
|  | 4181 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | 
|  | 4182 | auth_type == NL80211_AUTHTYPE_FILS_PK)) | 
|  | 4183 | return false; | 
|  | 4184 | return true; | 
|  | 4185 | case NL80211_CMD_CONNECT: | 
|  | 4186 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 4187 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | 
|  | 4188 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 4189 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && | 
|  | 4190 | auth_type == NL80211_AUTHTYPE_SAE) | 
|  | 4191 | //tianyan@2021.7.27 modify for add wifi6 module end | 
|  | 4192 | return false; | 
|  | 4193 |  | 
|  | 4194 | /* FILS with SK PFS or PK not supported yet */ | 
|  | 4195 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | 
|  | 4196 | auth_type == NL80211_AUTHTYPE_FILS_PK) | 
|  | 4197 | return false; | 
|  | 4198 | if (!wiphy_ext_feature_isset( | 
|  | 4199 | &rdev->wiphy, | 
|  | 4200 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | 
|  | 4201 | auth_type == NL80211_AUTHTYPE_FILS_SK) | 
|  | 4202 | return false; | 
|  | 4203 | return true; | 
|  | 4204 | case NL80211_CMD_START_AP: | 
|  | 4205 | /* SAE not supported yet */ | 
|  | 4206 | if (auth_type == NL80211_AUTHTYPE_SAE) | 
|  | 4207 | return false; | 
|  | 4208 | /* FILS not supported yet */ | 
|  | 4209 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || | 
|  | 4210 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | 
|  | 4211 | auth_type == NL80211_AUTHTYPE_FILS_PK) | 
|  | 4212 | return false; | 
|  | 4213 | return true; | 
|  | 4214 | default: | 
|  | 4215 | return false; | 
|  | 4216 | } | 
|  | 4217 | } | 
|  | 4218 |  | 
|  | 4219 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) | 
|  | 4220 | { | 
|  | 4221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 4222 | struct net_device *dev = info->user_ptr[1]; | 
|  | 4223 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 4224 | struct cfg80211_ap_settings params; | 
|  | 4225 | int err; | 
|  | 4226 |  | 
|  | 4227 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 4228 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 4229 | return -EOPNOTSUPP; | 
|  | 4230 |  | 
|  | 4231 | if (!rdev->ops->start_ap) | 
|  | 4232 | return -EOPNOTSUPP; | 
|  | 4233 |  | 
|  | 4234 | if (wdev->beacon_interval) | 
|  | 4235 | return -EALREADY; | 
|  | 4236 |  | 
|  | 4237 | memset(¶ms, 0, sizeof(params)); | 
|  | 4238 |  | 
|  | 4239 | /* these are required for START_AP */ | 
|  | 4240 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | 
|  | 4241 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | 
|  | 4242 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | 
|  | 4243 | return -EINVAL; | 
|  | 4244 |  | 
|  | 4245 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); | 
|  | 4246 | if (err) | 
|  | 4247 | return err; | 
|  | 4248 |  | 
|  | 4249 | params.beacon_interval = | 
|  | 4250 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | 
|  | 4251 | params.dtim_period = | 
|  | 4252 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | 
|  | 4253 |  | 
|  | 4254 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, | 
|  | 4255 | params.beacon_interval); | 
|  | 4256 | if (err) | 
|  | 4257 | return err; | 
|  | 4258 |  | 
|  | 4259 | /* | 
|  | 4260 | * In theory, some of these attributes should be required here | 
|  | 4261 | * but since they were not used when the command was originally | 
|  | 4262 | * added, keep them optional for old user space programs to let | 
|  | 4263 | * them continue to work with drivers that do not need the | 
|  | 4264 | * additional information -- drivers must check! | 
|  | 4265 | */ | 
|  | 4266 | if (info->attrs[NL80211_ATTR_SSID]) { | 
|  | 4267 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
|  | 4268 | params.ssid_len = | 
|  | 4269 | nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 4270 | if (params.ssid_len == 0 || | 
|  | 4271 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | 
|  | 4272 | return -EINVAL; | 
|  | 4273 | } | 
|  | 4274 |  | 
|  | 4275 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | 
|  | 4276 | params.hidden_ssid = nla_get_u32( | 
|  | 4277 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | 
|  | 4278 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | 
|  | 4279 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | 
|  | 4280 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | 
|  | 4281 | return -EINVAL; | 
|  | 4282 | } | 
|  | 4283 |  | 
|  | 4284 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | 
|  | 4285 |  | 
|  | 4286 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | 
|  | 4287 | params.auth_type = nla_get_u32( | 
|  | 4288 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
|  | 4289 | if (!nl80211_valid_auth_type(rdev, params.auth_type, | 
|  | 4290 | NL80211_CMD_START_AP)) | 
|  | 4291 | return -EINVAL; | 
|  | 4292 | } else | 
|  | 4293 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | 
|  | 4294 |  | 
|  | 4295 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | 
|  | 4296 | NL80211_MAX_NR_CIPHER_SUITES); | 
|  | 4297 | if (err) | 
|  | 4298 | return err; | 
|  | 4299 |  | 
|  | 4300 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { | 
|  | 4301 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | 
|  | 4302 | return -EOPNOTSUPP; | 
|  | 4303 | params.inactivity_timeout = nla_get_u16( | 
|  | 4304 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | 
|  | 4305 | } | 
|  | 4306 |  | 
|  | 4307 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { | 
|  | 4308 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 4309 | return -EINVAL; | 
|  | 4310 | params.p2p_ctwindow = | 
|  | 4311 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | 
|  | 4312 | if (params.p2p_ctwindow > 127) | 
|  | 4313 | return -EINVAL; | 
|  | 4314 | if (params.p2p_ctwindow != 0 && | 
|  | 4315 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | 
|  | 4316 | return -EINVAL; | 
|  | 4317 | } | 
|  | 4318 |  | 
|  | 4319 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | 
|  | 4320 | u8 tmp; | 
|  | 4321 |  | 
|  | 4322 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 4323 | return -EINVAL; | 
|  | 4324 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | 
|  | 4325 | if (tmp > 1) | 
|  | 4326 | return -EINVAL; | 
|  | 4327 | params.p2p_opp_ps = tmp; | 
|  | 4328 | if (params.p2p_opp_ps != 0 && | 
|  | 4329 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | 
|  | 4330 | return -EINVAL; | 
|  | 4331 | } | 
|  | 4332 |  | 
|  | 4333 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
|  | 4334 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); | 
|  | 4335 | if (err) | 
|  | 4336 | return err; | 
|  | 4337 | } else if (wdev->preset_chandef.chan) { | 
|  | 4338 | params.chandef = wdev->preset_chandef; | 
|  | 4339 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) | 
|  | 4340 | return -EINVAL; | 
|  | 4341 |  | 
|  | 4342 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, | 
|  | 4343 | wdev->iftype)) | 
|  | 4344 | return -EINVAL; | 
|  | 4345 |  | 
|  | 4346 | if (info->attrs[NL80211_ATTR_TX_RATES]) { | 
|  | 4347 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); | 
|  | 4348 | if (err) | 
|  | 4349 | return err; | 
|  | 4350 |  | 
|  | 4351 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, | 
|  | 4352 | ¶ms.beacon_rate); | 
|  | 4353 | if (err) | 
|  | 4354 | return err; | 
|  | 4355 | } | 
|  | 4356 |  | 
|  | 4357 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { | 
|  | 4358 | params.smps_mode = | 
|  | 4359 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | 
|  | 4360 | switch (params.smps_mode) { | 
|  | 4361 | case NL80211_SMPS_OFF: | 
|  | 4362 | break; | 
|  | 4363 | case NL80211_SMPS_STATIC: | 
|  | 4364 | if (!(rdev->wiphy.features & | 
|  | 4365 | NL80211_FEATURE_STATIC_SMPS)) | 
|  | 4366 | return -EINVAL; | 
|  | 4367 | break; | 
|  | 4368 | case NL80211_SMPS_DYNAMIC: | 
|  | 4369 | if (!(rdev->wiphy.features & | 
|  | 4370 | NL80211_FEATURE_DYNAMIC_SMPS)) | 
|  | 4371 | return -EINVAL; | 
|  | 4372 | break; | 
|  | 4373 | default: | 
|  | 4374 | return -EINVAL; | 
|  | 4375 | } | 
|  | 4376 | } else { | 
|  | 4377 | params.smps_mode = NL80211_SMPS_OFF; | 
|  | 4378 | } | 
|  | 4379 |  | 
|  | 4380 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); | 
|  | 4381 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) | 
|  | 4382 | return -EOPNOTSUPP; | 
|  | 4383 |  | 
|  | 4384 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { | 
|  | 4385 | params.acl = parse_acl_data(&rdev->wiphy, info); | 
|  | 4386 | if (IS_ERR(params.acl)) | 
|  | 4387 | return PTR_ERR(params.acl); | 
|  | 4388 | } | 
|  | 4389 |  | 
|  | 4390 | nl80211_calculate_ap_params(¶ms); | 
|  | 4391 |  | 
|  | 4392 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 4393 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) | 
|  | 4394 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; | 
|  | 4395 | //tianyan@2021.7.27 modify for add wifi6 module end | 
|  | 4396 |  | 
|  | 4397 | wdev_lock(wdev); | 
|  | 4398 | err = rdev_start_ap(rdev, dev, ¶ms); | 
|  | 4399 | if (!err) { | 
|  | 4400 | wdev->preset_chandef = params.chandef; | 
|  | 4401 | wdev->beacon_interval = params.beacon_interval; | 
|  | 4402 | wdev->chandef = params.chandef; | 
|  | 4403 | wdev->ssid_len = params.ssid_len; | 
|  | 4404 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | 
|  | 4405 |  | 
|  | 4406 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
|  | 4407 | wdev->conn_owner_nlportid = info->snd_portid; | 
|  | 4408 | } | 
|  | 4409 | wdev_unlock(wdev); | 
|  | 4410 |  | 
|  | 4411 | kfree(params.acl); | 
|  | 4412 |  | 
|  | 4413 | return err; | 
|  | 4414 | } | 
|  | 4415 |  | 
|  | 4416 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) | 
|  | 4417 | { | 
|  | 4418 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 4419 | struct net_device *dev = info->user_ptr[1]; | 
|  | 4420 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 4421 | struct cfg80211_beacon_data params; | 
|  | 4422 | int err; | 
|  | 4423 |  | 
|  | 4424 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 4425 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 4426 | return -EOPNOTSUPP; | 
|  | 4427 |  | 
|  | 4428 | if (!rdev->ops->change_beacon) | 
|  | 4429 | return -EOPNOTSUPP; | 
|  | 4430 |  | 
|  | 4431 | if (!wdev->beacon_interval) | 
|  | 4432 | return -EINVAL; | 
|  | 4433 |  | 
|  | 4434 | err = nl80211_parse_beacon(info->attrs, ¶ms); | 
|  | 4435 | if (err) | 
|  | 4436 | return err; | 
|  | 4437 |  | 
|  | 4438 | wdev_lock(wdev); | 
|  | 4439 | err = rdev_change_beacon(rdev, dev, ¶ms); | 
|  | 4440 | wdev_unlock(wdev); | 
|  | 4441 |  | 
|  | 4442 | return err; | 
|  | 4443 | } | 
|  | 4444 |  | 
|  | 4445 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | 
|  | 4446 | { | 
|  | 4447 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 4448 | struct net_device *dev = info->user_ptr[1]; | 
|  | 4449 |  | 
|  | 4450 | return cfg80211_stop_ap(rdev, dev, false); | 
|  | 4451 | } | 
|  | 4452 |  | 
|  | 4453 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { | 
|  | 4454 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | 
|  | 4455 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | 
|  | 4456 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | 
|  | 4457 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, | 
|  | 4458 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, | 
|  | 4459 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, | 
|  | 4460 | }; | 
|  | 4461 |  | 
|  | 4462 | static int parse_station_flags(struct genl_info *info, | 
|  | 4463 | enum nl80211_iftype iftype, | 
|  | 4464 | struct station_parameters *params) | 
|  | 4465 | { | 
|  | 4466 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | 
|  | 4467 | struct nlattr *nla; | 
|  | 4468 | int flag; | 
|  | 4469 |  | 
|  | 4470 | /* | 
|  | 4471 | * Try parsing the new attribute first so userspace | 
|  | 4472 | * can specify both for older kernels. | 
|  | 4473 | */ | 
|  | 4474 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | 
|  | 4475 | if (nla) { | 
|  | 4476 | struct nl80211_sta_flag_update *sta_flags; | 
|  | 4477 |  | 
|  | 4478 | sta_flags = nla_data(nla); | 
|  | 4479 | params->sta_flags_mask = sta_flags->mask; | 
|  | 4480 | params->sta_flags_set = sta_flags->set; | 
|  | 4481 | params->sta_flags_set &= params->sta_flags_mask; | 
|  | 4482 | if ((params->sta_flags_mask | | 
|  | 4483 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | 
|  | 4484 | return -EINVAL; | 
|  | 4485 | return 0; | 
|  | 4486 | } | 
|  | 4487 |  | 
|  | 4488 | /* if present, parse the old attribute */ | 
|  | 4489 |  | 
|  | 4490 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; | 
|  | 4491 | if (!nla) | 
|  | 4492 | return 0; | 
|  | 4493 |  | 
|  | 4494 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, | 
|  | 4495 | sta_flags_policy, info->extack)) | 
|  | 4496 | return -EINVAL; | 
|  | 4497 |  | 
|  | 4498 | /* | 
|  | 4499 | * Only allow certain flags for interface types so that | 
|  | 4500 | * other attributes are silently ignored. Remember that | 
|  | 4501 | * this is backward compatibility code with old userspace | 
|  | 4502 | * and shouldn't be hit in other cases anyway. | 
|  | 4503 | */ | 
|  | 4504 | switch (iftype) { | 
|  | 4505 | case NL80211_IFTYPE_AP: | 
|  | 4506 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 4507 | case NL80211_IFTYPE_P2P_GO: | 
|  | 4508 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
|  | 4509 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | 
|  | 4510 | BIT(NL80211_STA_FLAG_WME) | | 
|  | 4511 | BIT(NL80211_STA_FLAG_MFP); | 
|  | 4512 | break; | 
|  | 4513 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 4514 | case NL80211_IFTYPE_STATION: | 
|  | 4515 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
|  | 4516 | BIT(NL80211_STA_FLAG_TDLS_PEER); | 
|  | 4517 | break; | 
|  | 4518 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 4519 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
|  | 4520 | BIT(NL80211_STA_FLAG_MFP) | | 
|  | 4521 | BIT(NL80211_STA_FLAG_AUTHORIZED); | 
|  | 4522 | break; | 
|  | 4523 | default: | 
|  | 4524 | return -EINVAL; | 
|  | 4525 | } | 
|  | 4526 |  | 
|  | 4527 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { | 
|  | 4528 | if (flags[flag]) { | 
|  | 4529 | params->sta_flags_set |= (1<<flag); | 
|  | 4530 |  | 
|  | 4531 | /* no longer support new API additions in old API */ | 
|  | 4532 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | 
|  | 4533 | return -EINVAL; | 
|  | 4534 | } | 
|  | 4535 | } | 
|  | 4536 |  | 
|  | 4537 | return 0; | 
|  | 4538 | } | 
|  | 4539 |  | 
|  | 4540 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, | 
|  | 4541 | int attr) | 
|  | 4542 | { | 
|  | 4543 | struct nlattr *rate; | 
|  | 4544 | u32 bitrate; | 
|  | 4545 | u16 bitrate_compat; | 
|  | 4546 | enum nl80211_rate_info rate_flg; | 
|  | 4547 |  | 
|  | 4548 | rate = nla_nest_start(msg, attr); | 
|  | 4549 | if (!rate) | 
|  | 4550 | return false; | 
|  | 4551 |  | 
|  | 4552 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | 
|  | 4553 | bitrate = cfg80211_calculate_bitrate(info); | 
|  | 4554 | /* report 16-bit bitrate only if we can */ | 
|  | 4555 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | 
|  | 4556 | if (bitrate > 0 && | 
|  | 4557 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | 
|  | 4558 | return false; | 
|  | 4559 | if (bitrate_compat > 0 && | 
|  | 4560 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | 
|  | 4561 | return false; | 
|  | 4562 |  | 
|  | 4563 | switch (info->bw) { | 
|  | 4564 | case RATE_INFO_BW_5: | 
|  | 4565 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | 
|  | 4566 | break; | 
|  | 4567 | case RATE_INFO_BW_10: | 
|  | 4568 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | 
|  | 4569 | break; | 
|  | 4570 | default: | 
|  | 4571 | WARN_ON(1); | 
|  | 4572 | /* fall through */ | 
|  | 4573 | case RATE_INFO_BW_20: | 
|  | 4574 | rate_flg = 0; | 
|  | 4575 | break; | 
|  | 4576 | case RATE_INFO_BW_40: | 
|  | 4577 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | 
|  | 4578 | break; | 
|  | 4579 | case RATE_INFO_BW_80: | 
|  | 4580 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | 
|  | 4581 | break; | 
|  | 4582 | case RATE_INFO_BW_160: | 
|  | 4583 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | 
|  | 4584 | break; | 
|  | 4585 | case RATE_INFO_BW_HE_RU: | 
|  | 4586 | rate_flg = 0; | 
|  | 4587 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); | 
|  | 4588 | } | 
|  | 4589 |  | 
|  | 4590 | if (rate_flg && nla_put_flag(msg, rate_flg)) | 
|  | 4591 | return false; | 
|  | 4592 |  | 
|  | 4593 | if (info->flags & RATE_INFO_FLAGS_MCS) { | 
|  | 4594 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | 
|  | 4595 | return false; | 
|  | 4596 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | 
|  | 4597 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | 
|  | 4598 | return false; | 
|  | 4599 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | 
|  | 4600 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | 
|  | 4601 | return false; | 
|  | 4602 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | 
|  | 4603 | return false; | 
|  | 4604 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | 
|  | 4605 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | 
|  | 4606 | return false; | 
|  | 4607 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { | 
|  | 4608 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) | 
|  | 4609 | return false; | 
|  | 4610 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) | 
|  | 4611 | return false; | 
|  | 4612 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) | 
|  | 4613 | return false; | 
|  | 4614 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) | 
|  | 4615 | return false; | 
|  | 4616 | if (info->bw == RATE_INFO_BW_HE_RU && | 
|  | 4617 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, | 
|  | 4618 | info->he_ru_alloc)) | 
|  | 4619 | return false; | 
|  | 4620 | } | 
|  | 4621 |  | 
|  | 4622 | nla_nest_end(msg, rate); | 
|  | 4623 | return true; | 
|  | 4624 | } | 
|  | 4625 |  | 
|  | 4626 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, | 
|  | 4627 | int id) | 
|  | 4628 | { | 
|  | 4629 | void *attr; | 
|  | 4630 | int i = 0; | 
|  | 4631 |  | 
|  | 4632 | if (!mask) | 
|  | 4633 | return true; | 
|  | 4634 |  | 
|  | 4635 | attr = nla_nest_start(msg, id); | 
|  | 4636 | if (!attr) | 
|  | 4637 | return false; | 
|  | 4638 |  | 
|  | 4639 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | 
|  | 4640 | if (!(mask & BIT(i))) | 
|  | 4641 | continue; | 
|  | 4642 |  | 
|  | 4643 | if (nla_put_u8(msg, i, signal[i])) | 
|  | 4644 | return false; | 
|  | 4645 | } | 
|  | 4646 |  | 
|  | 4647 | nla_nest_end(msg, attr); | 
|  | 4648 |  | 
|  | 4649 | return true; | 
|  | 4650 | } | 
|  | 4651 |  | 
|  | 4652 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, | 
|  | 4653 | u32 seq, int flags, | 
|  | 4654 | struct cfg80211_registered_device *rdev, | 
|  | 4655 | struct net_device *dev, | 
|  | 4656 | const u8 *mac_addr, struct station_info *sinfo) | 
|  | 4657 | { | 
|  | 4658 | void *hdr; | 
|  | 4659 | struct nlattr *sinfoattr, *bss_param; | 
|  | 4660 |  | 
|  | 4661 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
|  | 4662 | if (!hdr) { | 
|  | 4663 | cfg80211_sinfo_release_content(sinfo); | 
|  | 4664 | return -1; | 
|  | 4665 | } | 
|  | 4666 |  | 
|  | 4667 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 4668 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | 
|  | 4669 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | 
|  | 4670 | goto nla_put_failure; | 
|  | 4671 |  | 
|  | 4672 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); | 
|  | 4673 | if (!sinfoattr) | 
|  | 4674 | goto nla_put_failure; | 
|  | 4675 |  | 
|  | 4676 | #define PUT_SINFO(attr, memb, type) do {				\ | 
|  | 4677 | BUILD_BUG_ON(sizeof(type) == sizeof(u64));			\ | 
|  | 4678 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) &&	\ | 
|  | 4679 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr,		\ | 
|  | 4680 | sinfo->memb))				\ | 
|  | 4681 | goto nla_put_failure;					\ | 
|  | 4682 | } while (0) | 
|  | 4683 | #define PUT_SINFO_U64(attr, memb) do {					\ | 
|  | 4684 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) &&	\ | 
|  | 4685 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr,		\ | 
|  | 4686 | sinfo->memb, NL80211_STA_INFO_PAD))	\ | 
|  | 4687 | goto nla_put_failure;					\ | 
|  | 4688 | } while (0) | 
|  | 4689 |  | 
|  | 4690 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | 
|  | 4691 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | 
|  | 4692 |  | 
|  | 4693 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | | 
|  | 4694 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && | 
|  | 4695 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, | 
|  | 4696 | (u32)sinfo->rx_bytes)) | 
|  | 4697 | goto nla_put_failure; | 
|  | 4698 |  | 
|  | 4699 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | | 
|  | 4700 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && | 
|  | 4701 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, | 
|  | 4702 | (u32)sinfo->tx_bytes)) | 
|  | 4703 | goto nla_put_failure; | 
|  | 4704 |  | 
|  | 4705 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); | 
|  | 4706 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | 
|  | 4707 | PUT_SINFO(LLID, llid, u16); | 
|  | 4708 | PUT_SINFO(PLID, plid, u16); | 
|  | 4709 | PUT_SINFO(PLINK_STATE, plink_state, u8); | 
|  | 4710 | PUT_SINFO_U64(RX_DURATION, rx_duration); | 
|  | 4711 |  | 
|  | 4712 | switch (rdev->wiphy.signal_type) { | 
|  | 4713 | case CFG80211_SIGNAL_TYPE_MBM: | 
|  | 4714 | PUT_SINFO(SIGNAL, signal, u8); | 
|  | 4715 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | 
|  | 4716 | break; | 
|  | 4717 | default: | 
|  | 4718 | break; | 
|  | 4719 | } | 
|  | 4720 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { | 
|  | 4721 | if (!nl80211_put_signal(msg, sinfo->chains, | 
|  | 4722 | sinfo->chain_signal, | 
|  | 4723 | NL80211_STA_INFO_CHAIN_SIGNAL)) | 
|  | 4724 | goto nla_put_failure; | 
|  | 4725 | } | 
|  | 4726 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { | 
|  | 4727 | if (!nl80211_put_signal(msg, sinfo->chains, | 
|  | 4728 | sinfo->chain_signal_avg, | 
|  | 4729 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | 
|  | 4730 | goto nla_put_failure; | 
|  | 4731 | } | 
|  | 4732 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { | 
|  | 4733 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, | 
|  | 4734 | NL80211_STA_INFO_TX_BITRATE)) | 
|  | 4735 | goto nla_put_failure; | 
|  | 4736 | } | 
|  | 4737 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { | 
|  | 4738 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | 
|  | 4739 | NL80211_STA_INFO_RX_BITRATE)) | 
|  | 4740 | goto nla_put_failure; | 
|  | 4741 | } | 
|  | 4742 |  | 
|  | 4743 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | 
|  | 4744 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | 
|  | 4745 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | 
|  | 4746 | PUT_SINFO(TX_FAILED, tx_failed, u32); | 
|  | 4747 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | 
|  | 4748 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | 
|  | 4749 | PUT_SINFO(LOCAL_PM, local_pm, u32); | 
|  | 4750 | PUT_SINFO(PEER_PM, peer_pm, u32); | 
|  | 4751 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | 
|  | 4752 |  | 
|  | 4753 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { | 
|  | 4754 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | 
|  | 4755 | if (!bss_param) | 
|  | 4756 | goto nla_put_failure; | 
|  | 4757 |  | 
|  | 4758 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && | 
|  | 4759 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | 
|  | 4760 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | 
|  | 4761 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | 
|  | 4762 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | 
|  | 4763 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | 
|  | 4764 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | 
|  | 4765 | sinfo->bss_param.dtim_period) || | 
|  | 4766 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | 
|  | 4767 | sinfo->bss_param.beacon_interval)) | 
|  | 4768 | goto nla_put_failure; | 
|  | 4769 |  | 
|  | 4770 | nla_nest_end(msg, bss_param); | 
|  | 4771 | } | 
|  | 4772 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && | 
|  | 4773 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | 
|  | 4774 | sizeof(struct nl80211_sta_flag_update), | 
|  | 4775 | &sinfo->sta_flags)) | 
|  | 4776 | goto nla_put_failure; | 
|  | 4777 |  | 
|  | 4778 | PUT_SINFO_U64(T_OFFSET, t_offset); | 
|  | 4779 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | 
|  | 4780 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | 
|  | 4781 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | 
|  | 4782 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); | 
|  | 4783 | if (wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 4784 | NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT)) | 
|  | 4785 | PUT_SINFO(DATA_ACK_SIGNAL_AVG, avg_ack_signal, s8); | 
|  | 4786 |  | 
|  | 4787 | #undef PUT_SINFO | 
|  | 4788 | #undef PUT_SINFO_U64 | 
|  | 4789 |  | 
|  | 4790 | if (sinfo->pertid) { | 
|  | 4791 | struct nlattr *tidsattr; | 
|  | 4792 | int tid; | 
|  | 4793 |  | 
|  | 4794 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | 
|  | 4795 | if (!tidsattr) | 
|  | 4796 | goto nla_put_failure; | 
|  | 4797 |  | 
|  | 4798 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | 
|  | 4799 | struct cfg80211_tid_stats *tidstats; | 
|  | 4800 | struct nlattr *tidattr; | 
|  | 4801 |  | 
|  | 4802 | tidstats = &sinfo->pertid[tid]; | 
|  | 4803 |  | 
|  | 4804 | if (!tidstats->filled) | 
|  | 4805 | continue; | 
|  | 4806 |  | 
|  | 4807 | tidattr = nla_nest_start(msg, tid + 1); | 
|  | 4808 | if (!tidattr) | 
|  | 4809 | goto nla_put_failure; | 
|  | 4810 |  | 
|  | 4811 | #define PUT_TIDVAL_U64(attr, memb) do {					\ | 
|  | 4812 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) &&	\ | 
|  | 4813 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr,		\ | 
|  | 4814 | tidstats->memb, NL80211_TID_STATS_PAD))	\ | 
|  | 4815 | goto nla_put_failure;					\ | 
|  | 4816 | } while (0) | 
|  | 4817 |  | 
|  | 4818 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); | 
|  | 4819 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | 
|  | 4820 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | 
|  | 4821 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | 
|  | 4822 |  | 
|  | 4823 | #undef PUT_TIDVAL_U64 | 
|  | 4824 | if ((tidstats->filled & | 
|  | 4825 | BIT(NL80211_TID_STATS_TXQ_STATS)) && | 
|  | 4826 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, | 
|  | 4827 | NL80211_TID_STATS_TXQ_STATS)) | 
|  | 4828 | goto nla_put_failure; | 
|  | 4829 |  | 
|  | 4830 | nla_nest_end(msg, tidattr); | 
|  | 4831 | } | 
|  | 4832 |  | 
|  | 4833 | nla_nest_end(msg, tidsattr); | 
|  | 4834 | } | 
|  | 4835 |  | 
|  | 4836 | nla_nest_end(msg, sinfoattr); | 
|  | 4837 |  | 
|  | 4838 | if (sinfo->assoc_req_ies_len && | 
|  | 4839 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | 
|  | 4840 | sinfo->assoc_req_ies)) | 
|  | 4841 | goto nla_put_failure; | 
|  | 4842 |  | 
|  | 4843 | cfg80211_sinfo_release_content(sinfo); | 
|  | 4844 | genlmsg_end(msg, hdr); | 
|  | 4845 | return 0; | 
|  | 4846 |  | 
|  | 4847 | nla_put_failure: | 
|  | 4848 | cfg80211_sinfo_release_content(sinfo); | 
|  | 4849 | genlmsg_cancel(msg, hdr); | 
|  | 4850 | return -EMSGSIZE; | 
|  | 4851 | } | 
|  | 4852 |  | 
|  | 4853 | static int nl80211_dump_station(struct sk_buff *skb, | 
|  | 4854 | struct netlink_callback *cb) | 
|  | 4855 | { | 
|  | 4856 | struct station_info sinfo; | 
|  | 4857 | struct cfg80211_registered_device *rdev; | 
|  | 4858 | struct wireless_dev *wdev; | 
|  | 4859 | u8 mac_addr[ETH_ALEN]; | 
|  | 4860 | int sta_idx = cb->args[2]; | 
|  | 4861 | int err; | 
|  | 4862 |  | 
|  | 4863 | rtnl_lock(); | 
|  | 4864 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
|  | 4865 | if (err) | 
|  | 4866 | goto out_err; | 
|  | 4867 |  | 
|  | 4868 | if (!wdev->netdev) { | 
|  | 4869 | err = -EINVAL; | 
|  | 4870 | goto out_err; | 
|  | 4871 | } | 
|  | 4872 |  | 
|  | 4873 | if (!rdev->ops->dump_station) { | 
|  | 4874 | err = -EOPNOTSUPP; | 
|  | 4875 | goto out_err; | 
|  | 4876 | } | 
|  | 4877 |  | 
|  | 4878 | while (1) { | 
|  | 4879 | memset(&sinfo, 0, sizeof(sinfo)); | 
|  | 4880 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, | 
|  | 4881 | mac_addr, &sinfo); | 
|  | 4882 | if (err == -ENOENT) | 
|  | 4883 | break; | 
|  | 4884 | if (err) | 
|  | 4885 | goto out_err; | 
|  | 4886 |  | 
|  | 4887 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, | 
|  | 4888 | NETLINK_CB(cb->skb).portid, | 
|  | 4889 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 4890 | rdev, wdev->netdev, mac_addr, | 
|  | 4891 | &sinfo) < 0) | 
|  | 4892 | goto out; | 
|  | 4893 |  | 
|  | 4894 | sta_idx++; | 
|  | 4895 | } | 
|  | 4896 |  | 
|  | 4897 | out: | 
|  | 4898 | cb->args[2] = sta_idx; | 
|  | 4899 | err = skb->len; | 
|  | 4900 | out_err: | 
|  | 4901 | rtnl_unlock(); | 
|  | 4902 |  | 
|  | 4903 | return err; | 
|  | 4904 | } | 
|  | 4905 |  | 
|  | 4906 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) | 
|  | 4907 | { | 
|  | 4908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 4909 | struct net_device *dev = info->user_ptr[1]; | 
|  | 4910 | struct station_info sinfo; | 
|  | 4911 | struct sk_buff *msg; | 
|  | 4912 | u8 *mac_addr = NULL; | 
|  | 4913 | int err; | 
|  | 4914 |  | 
|  | 4915 | memset(&sinfo, 0, sizeof(sinfo)); | 
|  | 4916 |  | 
|  | 4917 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 4918 | return -EINVAL; | 
|  | 4919 |  | 
|  | 4920 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 4921 |  | 
|  | 4922 | if (!rdev->ops->get_station) | 
|  | 4923 | return -EOPNOTSUPP; | 
|  | 4924 |  | 
|  | 4925 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); | 
|  | 4926 | if (err) | 
|  | 4927 | return err; | 
|  | 4928 |  | 
|  | 4929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 4930 | if (!msg) { | 
|  | 4931 | cfg80211_sinfo_release_content(&sinfo); | 
|  | 4932 | return -ENOMEM; | 
|  | 4933 | } | 
|  | 4934 |  | 
|  | 4935 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, | 
|  | 4936 | info->snd_portid, info->snd_seq, 0, | 
|  | 4937 | rdev, dev, mac_addr, &sinfo) < 0) { | 
|  | 4938 | nlmsg_free(msg); | 
|  | 4939 | return -ENOBUFS; | 
|  | 4940 | } | 
|  | 4941 |  | 
|  | 4942 | return genlmsg_reply(msg, info); | 
|  | 4943 | } | 
|  | 4944 |  | 
|  | 4945 | int cfg80211_check_station_change(struct wiphy *wiphy, | 
|  | 4946 | struct station_parameters *params, | 
|  | 4947 | enum cfg80211_station_type statype) | 
|  | 4948 | { | 
|  | 4949 | if (params->listen_interval != -1 && | 
|  | 4950 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | 
|  | 4951 | return -EINVAL; | 
|  | 4952 |  | 
|  | 4953 | if (params->support_p2p_ps != -1 && | 
|  | 4954 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | 
|  | 4955 | return -EINVAL; | 
|  | 4956 |  | 
|  | 4957 | if (params->aid && | 
|  | 4958 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && | 
|  | 4959 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | 
|  | 4960 | return -EINVAL; | 
|  | 4961 |  | 
|  | 4962 | /* When you run into this, adjust the code below for the new flag */ | 
|  | 4963 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | 
|  | 4964 |  | 
|  | 4965 | switch (statype) { | 
|  | 4966 | case CFG80211_STA_MESH_PEER_KERNEL: | 
|  | 4967 | case CFG80211_STA_MESH_PEER_USER: | 
|  | 4968 | /* | 
|  | 4969 | * No ignoring the TDLS flag here -- the userspace mesh | 
|  | 4970 | * code doesn't have the bug of including TDLS in the | 
|  | 4971 | * mask everywhere. | 
|  | 4972 | */ | 
|  | 4973 | if (params->sta_flags_mask & | 
|  | 4974 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
|  | 4975 | BIT(NL80211_STA_FLAG_MFP) | | 
|  | 4976 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | 
|  | 4977 | return -EINVAL; | 
|  | 4978 | break; | 
|  | 4979 | case CFG80211_STA_TDLS_PEER_SETUP: | 
|  | 4980 | case CFG80211_STA_TDLS_PEER_ACTIVE: | 
|  | 4981 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | 
|  | 4982 | return -EINVAL; | 
|  | 4983 | /* ignore since it can't change */ | 
|  | 4984 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | 
|  | 4985 | break; | 
|  | 4986 | default: | 
|  | 4987 | /* disallow mesh-specific things */ | 
|  | 4988 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | 
|  | 4989 | return -EINVAL; | 
|  | 4990 | if (params->local_pm) | 
|  | 4991 | return -EINVAL; | 
|  | 4992 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | 
|  | 4993 | return -EINVAL; | 
|  | 4994 | } | 
|  | 4995 |  | 
|  | 4996 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | 
|  | 4997 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | 
|  | 4998 | /* TDLS can't be set, ... */ | 
|  | 4999 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | 
|  | 5000 | return -EINVAL; | 
|  | 5001 | /* | 
|  | 5002 | * ... but don't bother the driver with it. This works around | 
|  | 5003 | * a hostapd/wpa_supplicant issue -- it always includes the | 
|  | 5004 | * TLDS_PEER flag in the mask even for AP mode. | 
|  | 5005 | */ | 
|  | 5006 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | 
|  | 5007 | } | 
|  | 5008 |  | 
|  | 5009 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | 
|  | 5010 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | 
|  | 5011 | /* reject other things that can't change */ | 
|  | 5012 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | 
|  | 5013 | return -EINVAL; | 
|  | 5014 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | 
|  | 5015 | return -EINVAL; | 
|  | 5016 | if (params->supported_rates) | 
|  | 5017 | return -EINVAL; | 
|  | 5018 | if (params->ext_capab || params->ht_capa || params->vht_capa || | 
|  | 5019 | params->he_capa) | 
|  | 5020 | return -EINVAL; | 
|  | 5021 | } | 
|  | 5022 |  | 
|  | 5023 | if (statype != CFG80211_STA_AP_CLIENT && | 
|  | 5024 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | 
|  | 5025 | if (params->vlan) | 
|  | 5026 | return -EINVAL; | 
|  | 5027 | } | 
|  | 5028 |  | 
|  | 5029 | switch (statype) { | 
|  | 5030 | case CFG80211_STA_AP_MLME_CLIENT: | 
|  | 5031 | /* Use this only for authorizing/unauthorizing a station */ | 
|  | 5032 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | 
|  | 5033 | return -EOPNOTSUPP; | 
|  | 5034 | break; | 
|  | 5035 | case CFG80211_STA_AP_CLIENT: | 
|  | 5036 | case CFG80211_STA_AP_CLIENT_UNASSOC: | 
|  | 5037 | /* accept only the listed bits */ | 
|  | 5038 | if (params->sta_flags_mask & | 
|  | 5039 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
|  | 5040 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
|  | 5041 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | 
|  | 5042 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | 
|  | 5043 | BIT(NL80211_STA_FLAG_WME) | | 
|  | 5044 | BIT(NL80211_STA_FLAG_MFP))) | 
|  | 5045 | return -EINVAL; | 
|  | 5046 |  | 
|  | 5047 | /* but authenticated/associated only if driver handles it */ | 
|  | 5048 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | 
|  | 5049 | params->sta_flags_mask & | 
|  | 5050 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
|  | 5051 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | 
|  | 5052 | return -EINVAL; | 
|  | 5053 | break; | 
|  | 5054 | case CFG80211_STA_IBSS: | 
|  | 5055 | case CFG80211_STA_AP_STA: | 
|  | 5056 | /* reject any changes other than AUTHORIZED */ | 
|  | 5057 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | 
|  | 5058 | return -EINVAL; | 
|  | 5059 | break; | 
|  | 5060 | case CFG80211_STA_TDLS_PEER_SETUP: | 
|  | 5061 | /* reject any changes other than AUTHORIZED or WME */ | 
|  | 5062 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
|  | 5063 | BIT(NL80211_STA_FLAG_WME))) | 
|  | 5064 | return -EINVAL; | 
|  | 5065 | /* force (at least) rates when authorizing */ | 
|  | 5066 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | 
|  | 5067 | !params->supported_rates) | 
|  | 5068 | return -EINVAL; | 
|  | 5069 | break; | 
|  | 5070 | case CFG80211_STA_TDLS_PEER_ACTIVE: | 
|  | 5071 | /* reject any changes */ | 
|  | 5072 | return -EINVAL; | 
|  | 5073 | case CFG80211_STA_MESH_PEER_KERNEL: | 
|  | 5074 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | 
|  | 5075 | return -EINVAL; | 
|  | 5076 | break; | 
|  | 5077 | case CFG80211_STA_MESH_PEER_USER: | 
|  | 5078 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && | 
|  | 5079 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | 
|  | 5080 | return -EINVAL; | 
|  | 5081 | break; | 
|  | 5082 | } | 
|  | 5083 |  | 
|  | 5084 | /* | 
|  | 5085 | * Older kernel versions ignored this attribute entirely, so don't | 
|  | 5086 | * reject attempts to update it but mark it as unused instead so the | 
|  | 5087 | * driver won't look at the data. | 
|  | 5088 | */ | 
|  | 5089 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && | 
|  | 5090 | statype != CFG80211_STA_TDLS_PEER_SETUP) | 
|  | 5091 | params->opmode_notif_used = false; | 
|  | 5092 |  | 
|  | 5093 | return 0; | 
|  | 5094 | } | 
|  | 5095 | EXPORT_SYMBOL(cfg80211_check_station_change); | 
|  | 5096 |  | 
|  | 5097 | /* | 
|  | 5098 | * Get vlan interface making sure it is running and on the right wiphy. | 
|  | 5099 | */ | 
|  | 5100 | static struct net_device *get_vlan(struct genl_info *info, | 
|  | 5101 | struct cfg80211_registered_device *rdev) | 
|  | 5102 | { | 
|  | 5103 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; | 
|  | 5104 | struct net_device *v; | 
|  | 5105 | int ret; | 
|  | 5106 |  | 
|  | 5107 | if (!vlanattr) | 
|  | 5108 | return NULL; | 
|  | 5109 |  | 
|  | 5110 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | 
|  | 5111 | if (!v) | 
|  | 5112 | return ERR_PTR(-ENODEV); | 
|  | 5113 |  | 
|  | 5114 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | 
|  | 5115 | ret = -EINVAL; | 
|  | 5116 | goto error; | 
|  | 5117 | } | 
|  | 5118 |  | 
|  | 5119 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | 
|  | 5120 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 5121 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | 
|  | 5122 | ret = -EINVAL; | 
|  | 5123 | goto error; | 
|  | 5124 | } | 
|  | 5125 |  | 
|  | 5126 | if (!netif_running(v)) { | 
|  | 5127 | ret = -ENETDOWN; | 
|  | 5128 | goto error; | 
|  | 5129 | } | 
|  | 5130 |  | 
|  | 5131 | return v; | 
|  | 5132 | error: | 
|  | 5133 | dev_put(v); | 
|  | 5134 | return ERR_PTR(ret); | 
|  | 5135 | } | 
|  | 5136 |  | 
|  | 5137 | static const struct nla_policy | 
|  | 5138 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | 
|  | 5139 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | 
|  | 5140 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | 
|  | 5141 | }; | 
|  | 5142 |  | 
|  | 5143 | static int nl80211_parse_sta_wme(struct genl_info *info, | 
|  | 5144 | struct station_parameters *params) | 
|  | 5145 | { | 
|  | 5146 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; | 
|  | 5147 | struct nlattr *nla; | 
|  | 5148 | int err; | 
|  | 5149 |  | 
|  | 5150 | /* parse WME attributes if present */ | 
|  | 5151 | if (!info->attrs[NL80211_ATTR_STA_WME]) | 
|  | 5152 | return 0; | 
|  | 5153 |  | 
|  | 5154 | nla = info->attrs[NL80211_ATTR_STA_WME]; | 
|  | 5155 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | 
|  | 5156 | nl80211_sta_wme_policy, info->extack); | 
|  | 5157 | if (err) | 
|  | 5158 | return err; | 
|  | 5159 |  | 
|  | 5160 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | 
|  | 5161 | params->uapsd_queues = nla_get_u8( | 
|  | 5162 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | 
|  | 5163 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | 
|  | 5164 | return -EINVAL; | 
|  | 5165 |  | 
|  | 5166 | if (tb[NL80211_STA_WME_MAX_SP]) | 
|  | 5167 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | 
|  | 5168 |  | 
|  | 5169 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | 
|  | 5170 | return -EINVAL; | 
|  | 5171 |  | 
|  | 5172 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | 
|  | 5173 |  | 
|  | 5174 | return 0; | 
|  | 5175 | } | 
|  | 5176 |  | 
|  | 5177 | static int nl80211_parse_sta_channel_info(struct genl_info *info, | 
|  | 5178 | struct station_parameters *params) | 
|  | 5179 | { | 
|  | 5180 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | 
|  | 5181 | params->supported_channels = | 
|  | 5182 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | 
|  | 5183 | params->supported_channels_len = | 
|  | 5184 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | 
|  | 5185 | /* | 
|  | 5186 | * Need to include at least one (first channel, number of | 
|  | 5187 | * channels) tuple for each subband, and must have proper | 
|  | 5188 | * tuples for the rest of the data as well. | 
|  | 5189 | */ | 
|  | 5190 | if (params->supported_channels_len < 2) | 
|  | 5191 | return -EINVAL; | 
|  | 5192 | if (params->supported_channels_len % 2) | 
|  | 5193 | return -EINVAL; | 
|  | 5194 | } | 
|  | 5195 |  | 
|  | 5196 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | 
|  | 5197 | params->supported_oper_classes = | 
|  | 5198 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | 
|  | 5199 | params->supported_oper_classes_len = | 
|  | 5200 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | 
|  | 5201 | /* | 
|  | 5202 | * The value of the Length field of the Supported Operating | 
|  | 5203 | * Classes element is between 2 and 253. | 
|  | 5204 | */ | 
|  | 5205 | if (params->supported_oper_classes_len < 2 || | 
|  | 5206 | params->supported_oper_classes_len > 253) | 
|  | 5207 | return -EINVAL; | 
|  | 5208 | } | 
|  | 5209 | return 0; | 
|  | 5210 | } | 
|  | 5211 |  | 
|  | 5212 | static int nl80211_set_station_tdls(struct genl_info *info, | 
|  | 5213 | struct station_parameters *params) | 
|  | 5214 | { | 
|  | 5215 | int err; | 
|  | 5216 | /* Dummy STA entry gets updated once the peer capabilities are known */ | 
|  | 5217 | if (info->attrs[NL80211_ATTR_PEER_AID]) | 
|  | 5218 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | 
|  | 5219 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | 
|  | 5220 | params->ht_capa = | 
|  | 5221 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | 
|  | 5222 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | 
|  | 5223 | params->vht_capa = | 
|  | 5224 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | 
|  | 5225 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { | 
|  | 5226 | params->he_capa = | 
|  | 5227 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | 
|  | 5228 | params->he_capa_len = | 
|  | 5229 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | 
|  | 5230 |  | 
|  | 5231 | if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) | 
|  | 5232 | return -EINVAL; | 
|  | 5233 | } | 
|  | 5234 |  | 
|  | 5235 | err = nl80211_parse_sta_channel_info(info, params); | 
|  | 5236 | if (err) | 
|  | 5237 | return err; | 
|  | 5238 |  | 
|  | 5239 | return nl80211_parse_sta_wme(info, params); | 
|  | 5240 | } | 
|  | 5241 |  | 
|  | 5242 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | 
|  | 5243 | { | 
|  | 5244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5245 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5246 | struct station_parameters params; | 
|  | 5247 | u8 *mac_addr; | 
|  | 5248 | int err; | 
|  | 5249 |  | 
|  | 5250 | memset(¶ms, 0, sizeof(params)); | 
|  | 5251 |  | 
|  | 5252 | if (!rdev->ops->change_station) | 
|  | 5253 | return -EOPNOTSUPP; | 
|  | 5254 |  | 
|  | 5255 | /* | 
|  | 5256 | * AID and listen_interval properties can be set only for unassociated | 
|  | 5257 | * station. Include these parameters here and will check them in | 
|  | 5258 | * cfg80211_check_station_change(). | 
|  | 5259 | */ | 
|  | 5260 | if (info->attrs[NL80211_ATTR_STA_AID]) | 
|  | 5261 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | 
|  | 5262 |  | 
|  | 5263 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | 
|  | 5264 | params.listen_interval = | 
|  | 5265 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | 
|  | 5266 | else | 
|  | 5267 | params.listen_interval = -1; | 
|  | 5268 |  | 
|  | 5269 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { | 
|  | 5270 | u8 tmp; | 
|  | 5271 |  | 
|  | 5272 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | 
|  | 5273 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | 
|  | 5274 | return -EINVAL; | 
|  | 5275 |  | 
|  | 5276 | params.support_p2p_ps = tmp; | 
|  | 5277 | } else { | 
|  | 5278 | params.support_p2p_ps = -1; | 
|  | 5279 | } | 
|  | 5280 |  | 
|  | 5281 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 5282 | return -EINVAL; | 
|  | 5283 |  | 
|  | 5284 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5285 |  | 
|  | 5286 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | 
|  | 5287 | params.supported_rates = | 
|  | 5288 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
|  | 5289 | params.supported_rates_len = | 
|  | 5290 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
|  | 5291 | } | 
|  | 5292 |  | 
|  | 5293 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { | 
|  | 5294 | params.capability = | 
|  | 5295 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | 
|  | 5296 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | 
|  | 5297 | } | 
|  | 5298 |  | 
|  | 5299 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | 
|  | 5300 | params.ext_capab = | 
|  | 5301 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
|  | 5302 | params.ext_capab_len = | 
|  | 5303 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
|  | 5304 | } | 
|  | 5305 |  | 
|  | 5306 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) | 
|  | 5307 | return -EINVAL; | 
|  | 5308 |  | 
|  | 5309 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { | 
|  | 5310 | params.plink_action = | 
|  | 5311 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | 
|  | 5312 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | 
|  | 5313 | return -EINVAL; | 
|  | 5314 | } | 
|  | 5315 |  | 
|  | 5316 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { | 
|  | 5317 | params.plink_state = | 
|  | 5318 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | 
|  | 5319 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | 
|  | 5320 | return -EINVAL; | 
|  | 5321 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { | 
|  | 5322 | params.peer_aid = nla_get_u16( | 
|  | 5323 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | 
|  | 5324 | if (params.peer_aid > IEEE80211_MAX_AID) | 
|  | 5325 | return -EINVAL; | 
|  | 5326 | } | 
|  | 5327 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | 
|  | 5328 | } | 
|  | 5329 |  | 
|  | 5330 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { | 
|  | 5331 | enum nl80211_mesh_power_mode pm = nla_get_u32( | 
|  | 5332 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | 
|  | 5333 |  | 
|  | 5334 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | 
|  | 5335 | pm > NL80211_MESH_POWER_MAX) | 
|  | 5336 | return -EINVAL; | 
|  | 5337 |  | 
|  | 5338 | params.local_pm = pm; | 
|  | 5339 | } | 
|  | 5340 |  | 
|  | 5341 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { | 
|  | 5342 | params.opmode_notif_used = true; | 
|  | 5343 | params.opmode_notif = | 
|  | 5344 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | 
|  | 5345 | } | 
|  | 5346 |  | 
|  | 5347 | /* Include parameters for TDLS peer (will check later) */ | 
|  | 5348 | err = nl80211_set_station_tdls(info, ¶ms); | 
|  | 5349 | if (err) | 
|  | 5350 | return err; | 
|  | 5351 |  | 
|  | 5352 | params.vlan = get_vlan(info, rdev); | 
|  | 5353 | if (IS_ERR(params.vlan)) | 
|  | 5354 | return PTR_ERR(params.vlan); | 
|  | 5355 |  | 
|  | 5356 | switch (dev->ieee80211_ptr->iftype) { | 
|  | 5357 | case NL80211_IFTYPE_AP: | 
|  | 5358 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 5359 | case NL80211_IFTYPE_P2P_GO: | 
|  | 5360 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 5361 | case NL80211_IFTYPE_STATION: | 
|  | 5362 | case NL80211_IFTYPE_ADHOC: | 
|  | 5363 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 5364 | break; | 
|  | 5365 | default: | 
|  | 5366 | err = -EOPNOTSUPP; | 
|  | 5367 | goto out_put_vlan; | 
|  | 5368 | } | 
|  | 5369 |  | 
|  | 5370 | /* driver will call cfg80211_check_station_change() */ | 
|  | 5371 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); | 
|  | 5372 |  | 
|  | 5373 | out_put_vlan: | 
|  | 5374 | if (params.vlan) | 
|  | 5375 | dev_put(params.vlan); | 
|  | 5376 |  | 
|  | 5377 | return err; | 
|  | 5378 | } | 
|  | 5379 |  | 
|  | 5380 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | 
|  | 5381 | { | 
|  | 5382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5383 | int err; | 
|  | 5384 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5385 | struct station_parameters params; | 
|  | 5386 | u8 *mac_addr = NULL; | 
|  | 5387 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
|  | 5388 | BIT(NL80211_STA_FLAG_ASSOCIATED); | 
|  | 5389 |  | 
|  | 5390 | memset(¶ms, 0, sizeof(params)); | 
|  | 5391 |  | 
|  | 5392 | if (!rdev->ops->add_station) | 
|  | 5393 | return -EOPNOTSUPP; | 
|  | 5394 |  | 
|  | 5395 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 5396 | return -EINVAL; | 
|  | 5397 |  | 
|  | 5398 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | 
|  | 5399 | return -EINVAL; | 
|  | 5400 |  | 
|  | 5401 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | 
|  | 5402 | return -EINVAL; | 
|  | 5403 |  | 
|  | 5404 | if (!info->attrs[NL80211_ATTR_STA_AID] && | 
|  | 5405 | !info->attrs[NL80211_ATTR_PEER_AID]) | 
|  | 5406 | return -EINVAL; | 
|  | 5407 |  | 
|  | 5408 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5409 | params.supported_rates = | 
|  | 5410 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
|  | 5411 | params.supported_rates_len = | 
|  | 5412 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
|  | 5413 | params.listen_interval = | 
|  | 5414 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | 
|  | 5415 |  | 
|  | 5416 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { | 
|  | 5417 | u8 tmp; | 
|  | 5418 |  | 
|  | 5419 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | 
|  | 5420 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | 
|  | 5421 | return -EINVAL; | 
|  | 5422 |  | 
|  | 5423 | params.support_p2p_ps = tmp; | 
|  | 5424 | } else { | 
|  | 5425 | /* | 
|  | 5426 | * if not specified, assume it's supported for P2P GO interface, | 
|  | 5427 | * and is NOT supported for AP interface | 
|  | 5428 | */ | 
|  | 5429 | params.support_p2p_ps = | 
|  | 5430 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | 
|  | 5431 | } | 
|  | 5432 |  | 
|  | 5433 | if (info->attrs[NL80211_ATTR_PEER_AID]) | 
|  | 5434 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | 
|  | 5435 | else | 
|  | 5436 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | 
|  | 5437 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | 
|  | 5438 | return -EINVAL; | 
|  | 5439 |  | 
|  | 5440 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { | 
|  | 5441 | params.capability = | 
|  | 5442 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | 
|  | 5443 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | 
|  | 5444 | } | 
|  | 5445 |  | 
|  | 5446 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | 
|  | 5447 | params.ext_capab = | 
|  | 5448 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
|  | 5449 | params.ext_capab_len = | 
|  | 5450 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
|  | 5451 | } | 
|  | 5452 |  | 
|  | 5453 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | 
|  | 5454 | params.ht_capa = | 
|  | 5455 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | 
|  | 5456 |  | 
|  | 5457 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | 
|  | 5458 | params.vht_capa = | 
|  | 5459 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | 
|  | 5460 |  | 
|  | 5461 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { | 
|  | 5462 | params.he_capa = | 
|  | 5463 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | 
|  | 5464 | params.he_capa_len = | 
|  | 5465 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); | 
|  | 5466 |  | 
|  | 5467 | /* max len is validated in nla policy */ | 
|  | 5468 | if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN) | 
|  | 5469 | return -EINVAL; | 
|  | 5470 | } | 
|  | 5471 |  | 
|  | 5472 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { | 
|  | 5473 | params.opmode_notif_used = true; | 
|  | 5474 | params.opmode_notif = | 
|  | 5475 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | 
|  | 5476 | } | 
|  | 5477 |  | 
|  | 5478 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { | 
|  | 5479 | params.plink_action = | 
|  | 5480 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | 
|  | 5481 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | 
|  | 5482 | return -EINVAL; | 
|  | 5483 | } | 
|  | 5484 |  | 
|  | 5485 | err = nl80211_parse_sta_channel_info(info, ¶ms); | 
|  | 5486 | if (err) | 
|  | 5487 | return err; | 
|  | 5488 |  | 
|  | 5489 | err = nl80211_parse_sta_wme(info, ¶ms); | 
|  | 5490 | if (err) | 
|  | 5491 | return err; | 
|  | 5492 |  | 
|  | 5493 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) | 
|  | 5494 | return -EINVAL; | 
|  | 5495 |  | 
|  | 5496 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT | 
|  | 5497 | * as userspace might just pass through the capabilities from the IEs | 
|  | 5498 | * directly, rather than enforcing this restriction and returning an | 
|  | 5499 | * error in this case. | 
|  | 5500 | */ | 
|  | 5501 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | 
|  | 5502 | params.ht_capa = NULL; | 
|  | 5503 | params.vht_capa = NULL; | 
|  | 5504 |  | 
|  | 5505 | /* HE requires WME */ | 
|  | 5506 | if (params.he_capa_len) | 
|  | 5507 | return -EINVAL; | 
|  | 5508 | } | 
|  | 5509 |  | 
|  | 5510 | /* When you run into this, adjust the code below for the new flag */ | 
|  | 5511 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | 
|  | 5512 |  | 
|  | 5513 | switch (dev->ieee80211_ptr->iftype) { | 
|  | 5514 | case NL80211_IFTYPE_AP: | 
|  | 5515 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 5516 | case NL80211_IFTYPE_P2P_GO: | 
|  | 5517 | /* ignore WME attributes if iface/sta is not capable */ | 
|  | 5518 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | 
|  | 5519 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | 
|  | 5520 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | 
|  | 5521 |  | 
|  | 5522 | /* TDLS peers cannot be added */ | 
|  | 5523 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || | 
|  | 5524 | info->attrs[NL80211_ATTR_PEER_AID]) | 
|  | 5525 | return -EINVAL; | 
|  | 5526 | /* but don't bother the driver with it */ | 
|  | 5527 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | 
|  | 5528 |  | 
|  | 5529 | /* allow authenticated/associated only if driver handles it */ | 
|  | 5530 | if (!(rdev->wiphy.features & | 
|  | 5531 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | 
|  | 5532 | params.sta_flags_mask & auth_assoc) | 
|  | 5533 | return -EINVAL; | 
|  | 5534 |  | 
|  | 5535 | /* Older userspace, or userspace wanting to be compatible with | 
|  | 5536 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | 
|  | 5537 | * and assoc flags in the mask, but assumes the station will be | 
|  | 5538 | * added as associated anyway since this was the required driver | 
|  | 5539 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | 
|  | 5540 | * introduced. | 
|  | 5541 | * In order to not bother drivers with this quirk in the API | 
|  | 5542 | * set the flags in both the mask and set for new stations in | 
|  | 5543 | * this case. | 
|  | 5544 | */ | 
|  | 5545 | if (!(params.sta_flags_mask & auth_assoc)) { | 
|  | 5546 | params.sta_flags_mask |= auth_assoc; | 
|  | 5547 | params.sta_flags_set |= auth_assoc; | 
|  | 5548 | } | 
|  | 5549 |  | 
|  | 5550 | /* must be last in here for error handling */ | 
|  | 5551 | params.vlan = get_vlan(info, rdev); | 
|  | 5552 | if (IS_ERR(params.vlan)) | 
|  | 5553 | return PTR_ERR(params.vlan); | 
|  | 5554 | break; | 
|  | 5555 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 5556 | /* ignore uAPSD data */ | 
|  | 5557 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | 
|  | 5558 |  | 
|  | 5559 | /* associated is disallowed */ | 
|  | 5560 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | 
|  | 5561 | return -EINVAL; | 
|  | 5562 | /* TDLS peers cannot be added */ | 
|  | 5563 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || | 
|  | 5564 | info->attrs[NL80211_ATTR_PEER_AID]) | 
|  | 5565 | return -EINVAL; | 
|  | 5566 | break; | 
|  | 5567 | case NL80211_IFTYPE_STATION: | 
|  | 5568 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 5569 | /* ignore uAPSD data */ | 
|  | 5570 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | 
|  | 5571 |  | 
|  | 5572 | /* these are disallowed */ | 
|  | 5573 | if (params.sta_flags_mask & | 
|  | 5574 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | 
|  | 5575 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | 
|  | 5576 | return -EINVAL; | 
|  | 5577 | /* Only TDLS peers can be added */ | 
|  | 5578 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | 
|  | 5579 | return -EINVAL; | 
|  | 5580 | /* Can only add if TDLS ... */ | 
|  | 5581 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | 
|  | 5582 | return -EOPNOTSUPP; | 
|  | 5583 | /* ... with external setup is supported */ | 
|  | 5584 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | 
|  | 5585 | return -EOPNOTSUPP; | 
|  | 5586 | /* | 
|  | 5587 | * Older wpa_supplicant versions always mark the TDLS peer | 
|  | 5588 | * as authorized, but it shouldn't yet be. | 
|  | 5589 | */ | 
|  | 5590 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | 
|  | 5591 | break; | 
|  | 5592 | default: | 
|  | 5593 | return -EOPNOTSUPP; | 
|  | 5594 | } | 
|  | 5595 |  | 
|  | 5596 | /* be aware of params.vlan when changing code here */ | 
|  | 5597 |  | 
|  | 5598 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); | 
|  | 5599 |  | 
|  | 5600 | if (params.vlan) | 
|  | 5601 | dev_put(params.vlan); | 
|  | 5602 | return err; | 
|  | 5603 | } | 
|  | 5604 |  | 
|  | 5605 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | 
|  | 5606 | { | 
|  | 5607 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5608 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5609 | struct station_del_parameters params; | 
|  | 5610 |  | 
|  | 5611 | memset(¶ms, 0, sizeof(params)); | 
|  | 5612 |  | 
|  | 5613 | if (info->attrs[NL80211_ATTR_MAC]) | 
|  | 5614 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5615 |  | 
|  | 5616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 5617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | 
|  | 5618 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && | 
|  | 5619 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 5620 | return -EINVAL; | 
|  | 5621 |  | 
|  | 5622 | if (!rdev->ops->del_station) | 
|  | 5623 | return -EOPNOTSUPP; | 
|  | 5624 |  | 
|  | 5625 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { | 
|  | 5626 | params.subtype = | 
|  | 5627 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | 
|  | 5628 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | 
|  | 5629 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | 
|  | 5630 | return -EINVAL; | 
|  | 5631 | } else { | 
|  | 5632 | /* Default to Deauthentication frame */ | 
|  | 5633 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | 
|  | 5634 | } | 
|  | 5635 |  | 
|  | 5636 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | 
|  | 5637 | params.reason_code = | 
|  | 5638 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
|  | 5639 | if (params.reason_code == 0) | 
|  | 5640 | return -EINVAL; /* 0 is reserved */ | 
|  | 5641 | } else { | 
|  | 5642 | /* Default to reason code 2 */ | 
|  | 5643 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | 
|  | 5644 | } | 
|  | 5645 |  | 
|  | 5646 | return rdev_del_station(rdev, dev, ¶ms); | 
|  | 5647 | } | 
|  | 5648 |  | 
|  | 5649 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, | 
|  | 5650 | int flags, struct net_device *dev, | 
|  | 5651 | u8 *dst, u8 *next_hop, | 
|  | 5652 | struct mpath_info *pinfo) | 
|  | 5653 | { | 
|  | 5654 | void *hdr; | 
|  | 5655 | struct nlattr *pinfoattr; | 
|  | 5656 |  | 
|  | 5657 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); | 
|  | 5658 | if (!hdr) | 
|  | 5659 | return -1; | 
|  | 5660 |  | 
|  | 5661 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 5662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | 
|  | 5663 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | 
|  | 5664 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | 
|  | 5665 | goto nla_put_failure; | 
|  | 5666 |  | 
|  | 5667 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); | 
|  | 5668 | if (!pinfoattr) | 
|  | 5669 | goto nla_put_failure; | 
|  | 5670 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && | 
|  | 5671 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | 
|  | 5672 | pinfo->frame_qlen)) | 
|  | 5673 | goto nla_put_failure; | 
|  | 5674 | if (((pinfo->filled & MPATH_INFO_SN) && | 
|  | 5675 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | 
|  | 5676 | ((pinfo->filled & MPATH_INFO_METRIC) && | 
|  | 5677 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | 
|  | 5678 | pinfo->metric)) || | 
|  | 5679 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | 
|  | 5680 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | 
|  | 5681 | pinfo->exptime)) || | 
|  | 5682 | ((pinfo->filled & MPATH_INFO_FLAGS) && | 
|  | 5683 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | 
|  | 5684 | pinfo->flags)) || | 
|  | 5685 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | 
|  | 5686 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | 
|  | 5687 | pinfo->discovery_timeout)) || | 
|  | 5688 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | 
|  | 5689 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | 
|  | 5690 | pinfo->discovery_retries))) | 
|  | 5691 | goto nla_put_failure; | 
|  | 5692 |  | 
|  | 5693 | nla_nest_end(msg, pinfoattr); | 
|  | 5694 |  | 
|  | 5695 | genlmsg_end(msg, hdr); | 
|  | 5696 | return 0; | 
|  | 5697 |  | 
|  | 5698 | nla_put_failure: | 
|  | 5699 | genlmsg_cancel(msg, hdr); | 
|  | 5700 | return -EMSGSIZE; | 
|  | 5701 | } | 
|  | 5702 |  | 
|  | 5703 | static int nl80211_dump_mpath(struct sk_buff *skb, | 
|  | 5704 | struct netlink_callback *cb) | 
|  | 5705 | { | 
|  | 5706 | struct mpath_info pinfo; | 
|  | 5707 | struct cfg80211_registered_device *rdev; | 
|  | 5708 | struct wireless_dev *wdev; | 
|  | 5709 | u8 dst[ETH_ALEN]; | 
|  | 5710 | u8 next_hop[ETH_ALEN]; | 
|  | 5711 | int path_idx = cb->args[2]; | 
|  | 5712 | int err; | 
|  | 5713 |  | 
|  | 5714 | rtnl_lock(); | 
|  | 5715 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
|  | 5716 | if (err) | 
|  | 5717 | goto out_err; | 
|  | 5718 |  | 
|  | 5719 | if (!rdev->ops->dump_mpath) { | 
|  | 5720 | err = -EOPNOTSUPP; | 
|  | 5721 | goto out_err; | 
|  | 5722 | } | 
|  | 5723 |  | 
|  | 5724 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | 
|  | 5725 | err = -EOPNOTSUPP; | 
|  | 5726 | goto out_err; | 
|  | 5727 | } | 
|  | 5728 |  | 
|  | 5729 | while (1) { | 
|  | 5730 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, | 
|  | 5731 | next_hop, &pinfo); | 
|  | 5732 | if (err == -ENOENT) | 
|  | 5733 | break; | 
|  | 5734 | if (err) | 
|  | 5735 | goto out_err; | 
|  | 5736 |  | 
|  | 5737 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | 
|  | 5738 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 5739 | wdev->netdev, dst, next_hop, | 
|  | 5740 | &pinfo) < 0) | 
|  | 5741 | goto out; | 
|  | 5742 |  | 
|  | 5743 | path_idx++; | 
|  | 5744 | } | 
|  | 5745 |  | 
|  | 5746 | out: | 
|  | 5747 | cb->args[2] = path_idx; | 
|  | 5748 | err = skb->len; | 
|  | 5749 | out_err: | 
|  | 5750 | rtnl_unlock(); | 
|  | 5751 | return err; | 
|  | 5752 | } | 
|  | 5753 |  | 
|  | 5754 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | 
|  | 5755 | { | 
|  | 5756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5757 | int err; | 
|  | 5758 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5759 | struct mpath_info pinfo; | 
|  | 5760 | struct sk_buff *msg; | 
|  | 5761 | u8 *dst = NULL; | 
|  | 5762 | u8 next_hop[ETH_ALEN]; | 
|  | 5763 |  | 
|  | 5764 | memset(&pinfo, 0, sizeof(pinfo)); | 
|  | 5765 |  | 
|  | 5766 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 5767 | return -EINVAL; | 
|  | 5768 |  | 
|  | 5769 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5770 |  | 
|  | 5771 | if (!rdev->ops->get_mpath) | 
|  | 5772 | return -EOPNOTSUPP; | 
|  | 5773 |  | 
|  | 5774 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 5775 | return -EOPNOTSUPP; | 
|  | 5776 |  | 
|  | 5777 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); | 
|  | 5778 | if (err) | 
|  | 5779 | return err; | 
|  | 5780 |  | 
|  | 5781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 5782 | if (!msg) | 
|  | 5783 | return -ENOMEM; | 
|  | 5784 |  | 
|  | 5785 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 5786 | dev, dst, next_hop, &pinfo) < 0) { | 
|  | 5787 | nlmsg_free(msg); | 
|  | 5788 | return -ENOBUFS; | 
|  | 5789 | } | 
|  | 5790 |  | 
|  | 5791 | return genlmsg_reply(msg, info); | 
|  | 5792 | } | 
|  | 5793 |  | 
|  | 5794 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | 
|  | 5795 | { | 
|  | 5796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5797 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5798 | u8 *dst = NULL; | 
|  | 5799 | u8 *next_hop = NULL; | 
|  | 5800 |  | 
|  | 5801 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 5802 | return -EINVAL; | 
|  | 5803 |  | 
|  | 5804 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | 
|  | 5805 | return -EINVAL; | 
|  | 5806 |  | 
|  | 5807 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5808 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | 
|  | 5809 |  | 
|  | 5810 | if (!rdev->ops->change_mpath) | 
|  | 5811 | return -EOPNOTSUPP; | 
|  | 5812 |  | 
|  | 5813 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 5814 | return -EOPNOTSUPP; | 
|  | 5815 |  | 
|  | 5816 | return rdev_change_mpath(rdev, dev, dst, next_hop); | 
|  | 5817 | } | 
|  | 5818 |  | 
|  | 5819 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | 
|  | 5820 | { | 
|  | 5821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5822 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5823 | u8 *dst = NULL; | 
|  | 5824 | u8 *next_hop = NULL; | 
|  | 5825 |  | 
|  | 5826 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 5827 | return -EINVAL; | 
|  | 5828 |  | 
|  | 5829 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | 
|  | 5830 | return -EINVAL; | 
|  | 5831 |  | 
|  | 5832 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5833 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | 
|  | 5834 |  | 
|  | 5835 | if (!rdev->ops->add_mpath) | 
|  | 5836 | return -EOPNOTSUPP; | 
|  | 5837 |  | 
|  | 5838 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 5839 | return -EOPNOTSUPP; | 
|  | 5840 |  | 
|  | 5841 | return rdev_add_mpath(rdev, dev, dst, next_hop); | 
|  | 5842 | } | 
|  | 5843 |  | 
|  | 5844 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | 
|  | 5845 | { | 
|  | 5846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5847 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5848 | u8 *dst = NULL; | 
|  | 5849 |  | 
|  | 5850 | if (info->attrs[NL80211_ATTR_MAC]) | 
|  | 5851 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5852 |  | 
|  | 5853 | if (!rdev->ops->del_mpath) | 
|  | 5854 | return -EOPNOTSUPP; | 
|  | 5855 |  | 
|  | 5856 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 5857 | return -EOPNOTSUPP; | 
|  | 5858 |  | 
|  | 5859 | return rdev_del_mpath(rdev, dev, dst); | 
|  | 5860 | } | 
|  | 5861 |  | 
|  | 5862 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) | 
|  | 5863 | { | 
|  | 5864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5865 | int err; | 
|  | 5866 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5867 | struct mpath_info pinfo; | 
|  | 5868 | struct sk_buff *msg; | 
|  | 5869 | u8 *dst = NULL; | 
|  | 5870 | u8 mpp[ETH_ALEN]; | 
|  | 5871 |  | 
|  | 5872 | memset(&pinfo, 0, sizeof(pinfo)); | 
|  | 5873 |  | 
|  | 5874 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 5875 | return -EINVAL; | 
|  | 5876 |  | 
|  | 5877 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 5878 |  | 
|  | 5879 | if (!rdev->ops->get_mpp) | 
|  | 5880 | return -EOPNOTSUPP; | 
|  | 5881 |  | 
|  | 5882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 5883 | return -EOPNOTSUPP; | 
|  | 5884 |  | 
|  | 5885 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | 
|  | 5886 | if (err) | 
|  | 5887 | return err; | 
|  | 5888 |  | 
|  | 5889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 5890 | if (!msg) | 
|  | 5891 | return -ENOMEM; | 
|  | 5892 |  | 
|  | 5893 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 5894 | dev, dst, mpp, &pinfo) < 0) { | 
|  | 5895 | nlmsg_free(msg); | 
|  | 5896 | return -ENOBUFS; | 
|  | 5897 | } | 
|  | 5898 |  | 
|  | 5899 | return genlmsg_reply(msg, info); | 
|  | 5900 | } | 
|  | 5901 |  | 
|  | 5902 | static int nl80211_dump_mpp(struct sk_buff *skb, | 
|  | 5903 | struct netlink_callback *cb) | 
|  | 5904 | { | 
|  | 5905 | struct mpath_info pinfo; | 
|  | 5906 | struct cfg80211_registered_device *rdev; | 
|  | 5907 | struct wireless_dev *wdev; | 
|  | 5908 | u8 dst[ETH_ALEN]; | 
|  | 5909 | u8 mpp[ETH_ALEN]; | 
|  | 5910 | int path_idx = cb->args[2]; | 
|  | 5911 | int err; | 
|  | 5912 |  | 
|  | 5913 | rtnl_lock(); | 
|  | 5914 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
|  | 5915 | if (err) | 
|  | 5916 | goto out_err; | 
|  | 5917 |  | 
|  | 5918 | if (!rdev->ops->dump_mpp) { | 
|  | 5919 | err = -EOPNOTSUPP; | 
|  | 5920 | goto out_err; | 
|  | 5921 | } | 
|  | 5922 |  | 
|  | 5923 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | 
|  | 5924 | err = -EOPNOTSUPP; | 
|  | 5925 | goto out_err; | 
|  | 5926 | } | 
|  | 5927 |  | 
|  | 5928 | while (1) { | 
|  | 5929 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | 
|  | 5930 | mpp, &pinfo); | 
|  | 5931 | if (err == -ENOENT) | 
|  | 5932 | break; | 
|  | 5933 | if (err) | 
|  | 5934 | goto out_err; | 
|  | 5935 |  | 
|  | 5936 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | 
|  | 5937 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 5938 | wdev->netdev, dst, mpp, | 
|  | 5939 | &pinfo) < 0) | 
|  | 5940 | goto out; | 
|  | 5941 |  | 
|  | 5942 | path_idx++; | 
|  | 5943 | } | 
|  | 5944 |  | 
|  | 5945 | out: | 
|  | 5946 | cb->args[2] = path_idx; | 
|  | 5947 | err = skb->len; | 
|  | 5948 | out_err: | 
|  | 5949 | rtnl_unlock(); | 
|  | 5950 | return err; | 
|  | 5951 | } | 
|  | 5952 |  | 
|  | 5953 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) | 
|  | 5954 | { | 
|  | 5955 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 5956 | struct net_device *dev = info->user_ptr[1]; | 
|  | 5957 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 5958 | struct bss_parameters params; | 
|  | 5959 | int err; | 
|  | 5960 |  | 
|  | 5961 | memset(¶ms, 0, sizeof(params)); | 
|  | 5962 | /* default to not changing parameters */ | 
|  | 5963 | params.use_cts_prot = -1; | 
|  | 5964 | params.use_short_preamble = -1; | 
|  | 5965 | params.use_short_slot_time = -1; | 
|  | 5966 | params.ap_isolate = -1; | 
|  | 5967 | params.ht_opmode = -1; | 
|  | 5968 | params.p2p_ctwindow = -1; | 
|  | 5969 | params.p2p_opp_ps = -1; | 
|  | 5970 |  | 
|  | 5971 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | 
|  | 5972 | params.use_cts_prot = | 
|  | 5973 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | 
|  | 5974 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | 
|  | 5975 | params.use_short_preamble = | 
|  | 5976 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | 
|  | 5977 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | 
|  | 5978 | params.use_short_slot_time = | 
|  | 5979 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | 
|  | 5980 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 
|  | 5981 | params.basic_rates = | 
|  | 5982 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
|  | 5983 | params.basic_rates_len = | 
|  | 5984 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
|  | 5985 | } | 
|  | 5986 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) | 
|  | 5987 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | 
|  | 5988 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) | 
|  | 5989 | params.ht_opmode = | 
|  | 5990 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | 
|  | 5991 |  | 
|  | 5992 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { | 
|  | 5993 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 5994 | return -EINVAL; | 
|  | 5995 | params.p2p_ctwindow = | 
|  | 5996 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | 
|  | 5997 | if (params.p2p_ctwindow < 0) | 
|  | 5998 | return -EINVAL; | 
|  | 5999 | if (params.p2p_ctwindow != 0 && | 
|  | 6000 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | 
|  | 6001 | return -EINVAL; | 
|  | 6002 | } | 
|  | 6003 |  | 
|  | 6004 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | 
|  | 6005 | u8 tmp; | 
|  | 6006 |  | 
|  | 6007 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 6008 | return -EINVAL; | 
|  | 6009 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | 
|  | 6010 | if (tmp > 1) | 
|  | 6011 | return -EINVAL; | 
|  | 6012 | params.p2p_opp_ps = tmp; | 
|  | 6013 | if (params.p2p_opp_ps && | 
|  | 6014 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | 
|  | 6015 | return -EINVAL; | 
|  | 6016 | } | 
|  | 6017 |  | 
|  | 6018 | if (!rdev->ops->change_bss) | 
|  | 6019 | return -EOPNOTSUPP; | 
|  | 6020 |  | 
|  | 6021 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 6022 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 6023 | return -EOPNOTSUPP; | 
|  | 6024 |  | 
|  | 6025 | wdev_lock(wdev); | 
|  | 6026 | err = rdev_change_bss(rdev, dev, ¶ms); | 
|  | 6027 | wdev_unlock(wdev); | 
|  | 6028 |  | 
|  | 6029 | return err; | 
|  | 6030 | } | 
|  | 6031 |  | 
|  | 6032 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | 
|  | 6033 | { | 
|  | 6034 | char *data = NULL; | 
|  | 6035 | bool is_indoor; | 
|  | 6036 | enum nl80211_user_reg_hint_type user_reg_hint_type; | 
|  | 6037 | u32 owner_nlportid; | 
|  | 6038 |  | 
|  | 6039 | /* | 
|  | 6040 | * You should only get this when cfg80211 hasn't yet initialized | 
|  | 6041 | * completely when built-in to the kernel right between the time | 
|  | 6042 | * window between nl80211_init() and regulatory_init(), if that is | 
|  | 6043 | * even possible. | 
|  | 6044 | */ | 
|  | 6045 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) | 
|  | 6046 | return -EINPROGRESS; | 
|  | 6047 |  | 
|  | 6048 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) | 
|  | 6049 | user_reg_hint_type = | 
|  | 6050 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | 
|  | 6051 | else | 
|  | 6052 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | 
|  | 6053 |  | 
|  | 6054 | switch (user_reg_hint_type) { | 
|  | 6055 | case NL80211_USER_REG_HINT_USER: | 
|  | 6056 | case NL80211_USER_REG_HINT_CELL_BASE: | 
|  | 6057 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | 
|  | 6058 | return -EINVAL; | 
|  | 6059 |  | 
|  | 6060 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | 
|  | 6061 | return regulatory_hint_user(data, user_reg_hint_type); | 
|  | 6062 | case NL80211_USER_REG_HINT_INDOOR: | 
|  | 6063 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | 
|  | 6064 | owner_nlportid = info->snd_portid; | 
|  | 6065 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | 
|  | 6066 | } else { | 
|  | 6067 | owner_nlportid = 0; | 
|  | 6068 | is_indoor = true; | 
|  | 6069 | } | 
|  | 6070 |  | 
|  | 6071 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | 
|  | 6072 | default: | 
|  | 6073 | return -EINVAL; | 
|  | 6074 | } | 
|  | 6075 | } | 
|  | 6076 |  | 
|  | 6077 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) | 
|  | 6078 | { | 
|  | 6079 | return reg_reload_regdb(); | 
|  | 6080 | } | 
|  | 6081 |  | 
|  | 6082 | static int nl80211_get_mesh_config(struct sk_buff *skb, | 
|  | 6083 | struct genl_info *info) | 
|  | 6084 | { | 
|  | 6085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 6086 | struct net_device *dev = info->user_ptr[1]; | 
|  | 6087 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 6088 | struct mesh_config cur_params; | 
|  | 6089 | int err = 0; | 
|  | 6090 | void *hdr; | 
|  | 6091 | struct nlattr *pinfoattr; | 
|  | 6092 | struct sk_buff *msg; | 
|  | 6093 |  | 
|  | 6094 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 6095 | return -EOPNOTSUPP; | 
|  | 6096 |  | 
|  | 6097 | if (!rdev->ops->get_mesh_config) | 
|  | 6098 | return -EOPNOTSUPP; | 
|  | 6099 |  | 
|  | 6100 | wdev_lock(wdev); | 
|  | 6101 | /* If not connected, get default parameters */ | 
|  | 6102 | if (!wdev->mesh_id_len) | 
|  | 6103 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | 
|  | 6104 | else | 
|  | 6105 | err = rdev_get_mesh_config(rdev, dev, &cur_params); | 
|  | 6106 | wdev_unlock(wdev); | 
|  | 6107 |  | 
|  | 6108 | if (err) | 
|  | 6109 | return err; | 
|  | 6110 |  | 
|  | 6111 | /* Draw up a netlink message to send back */ | 
|  | 6112 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 6113 | if (!msg) | 
|  | 6114 | return -ENOMEM; | 
|  | 6115 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 6116 | NL80211_CMD_GET_MESH_CONFIG); | 
|  | 6117 | if (!hdr) | 
|  | 6118 | goto out; | 
|  | 6119 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | 
|  | 6120 | if (!pinfoattr) | 
|  | 6121 | goto nla_put_failure; | 
|  | 6122 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 6123 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | 
|  | 6124 | cur_params.dot11MeshRetryTimeout) || | 
|  | 6125 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | 
|  | 6126 | cur_params.dot11MeshConfirmTimeout) || | 
|  | 6127 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | 
|  | 6128 | cur_params.dot11MeshHoldingTimeout) || | 
|  | 6129 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | 
|  | 6130 | cur_params.dot11MeshMaxPeerLinks) || | 
|  | 6131 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | 
|  | 6132 | cur_params.dot11MeshMaxRetries) || | 
|  | 6133 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | 
|  | 6134 | cur_params.dot11MeshTTL) || | 
|  | 6135 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | 
|  | 6136 | cur_params.element_ttl) || | 
|  | 6137 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | 
|  | 6138 | cur_params.auto_open_plinks) || | 
|  | 6139 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, | 
|  | 6140 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | 
|  | 6141 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | 
|  | 6142 | cur_params.dot11MeshHWMPmaxPREQretries) || | 
|  | 6143 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | 
|  | 6144 | cur_params.path_refresh_time) || | 
|  | 6145 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | 
|  | 6146 | cur_params.min_discovery_timeout) || | 
|  | 6147 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | 
|  | 6148 | cur_params.dot11MeshHWMPactivePathTimeout) || | 
|  | 6149 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | 
|  | 6150 | cur_params.dot11MeshHWMPpreqMinInterval) || | 
|  | 6151 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | 
|  | 6152 | cur_params.dot11MeshHWMPperrMinInterval) || | 
|  | 6153 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | 
|  | 6154 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | 
|  | 6155 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | 
|  | 6156 | cur_params.dot11MeshHWMPRootMode) || | 
|  | 6157 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | 
|  | 6158 | cur_params.dot11MeshHWMPRannInterval) || | 
|  | 6159 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | 
|  | 6160 | cur_params.dot11MeshGateAnnouncementProtocol) || | 
|  | 6161 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | 
|  | 6162 | cur_params.dot11MeshForwarding) || | 
|  | 6163 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | 
|  | 6164 | cur_params.rssi_threshold) || | 
|  | 6165 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | 
|  | 6166 | cur_params.ht_opmode) || | 
|  | 6167 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | 
|  | 6168 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | 
|  | 6169 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | 
|  | 6170 | cur_params.dot11MeshHWMProotInterval) || | 
|  | 6171 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | 
|  | 6172 | cur_params.dot11MeshHWMPconfirmationInterval) || | 
|  | 6173 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | 
|  | 6174 | cur_params.power_mode) || | 
|  | 6175 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | 
|  | 6176 | cur_params.dot11MeshAwakeWindowDuration) || | 
|  | 6177 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | 
|  | 6178 | cur_params.plink_timeout)) | 
|  | 6179 | goto nla_put_failure; | 
|  | 6180 | nla_nest_end(msg, pinfoattr); | 
|  | 6181 | genlmsg_end(msg, hdr); | 
|  | 6182 | return genlmsg_reply(msg, info); | 
|  | 6183 |  | 
|  | 6184 | nla_put_failure: | 
|  | 6185 | out: | 
|  | 6186 | nlmsg_free(msg); | 
|  | 6187 | return -ENOBUFS; | 
|  | 6188 | } | 
|  | 6189 |  | 
|  | 6190 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { | 
|  | 6191 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, | 
|  | 6192 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | 
|  | 6193 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | 
|  | 6194 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | 
|  | 6195 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | 
|  | 6196 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | 
|  | 6197 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, | 
|  | 6198 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | 
|  | 6199 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, | 
|  | 6200 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | 
|  | 6201 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | 
|  | 6202 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | 
|  | 6203 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | 
|  | 6204 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | 
|  | 6205 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, | 
|  | 6206 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | 
|  | 6207 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, | 
|  | 6208 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, | 
|  | 6209 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, | 
|  | 6210 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, | 
|  | 6211 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, | 
|  | 6212 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | 
|  | 6213 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, | 
|  | 6214 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | 
|  | 6215 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, | 
|  | 6216 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, | 
|  | 6217 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | 
|  | 6218 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, | 
|  | 6219 | }; | 
|  | 6220 |  | 
|  | 6221 | static const struct nla_policy | 
|  | 6222 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | 
|  | 6223 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, | 
|  | 6224 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, | 
|  | 6225 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | 
|  | 6226 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, | 
|  | 6227 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, | 
|  | 6228 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, | 
|  | 6229 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, | 
|  | 6230 | .len = IEEE80211_MAX_DATA_LEN }, | 
|  | 6231 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, | 
|  | 6232 | }; | 
|  | 6233 |  | 
|  | 6234 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) | 
|  | 6235 | { | 
|  | 6236 | u8 val = nla_get_u8(nla); | 
|  | 6237 | if (val < min || val > max) | 
|  | 6238 | return -EINVAL; | 
|  | 6239 | *out = val; | 
|  | 6240 | return 0; | 
|  | 6241 | } | 
|  | 6242 |  | 
|  | 6243 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) | 
|  | 6244 | { | 
|  | 6245 | u8 val = nla_get_u8(nla); | 
|  | 6246 | if (val < min || val > max) | 
|  | 6247 | return -EINVAL; | 
|  | 6248 | *out = val; | 
|  | 6249 | return 0; | 
|  | 6250 | } | 
|  | 6251 |  | 
|  | 6252 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) | 
|  | 6253 | { | 
|  | 6254 | u16 val = nla_get_u16(nla); | 
|  | 6255 | if (val < min || val > max) | 
|  | 6256 | return -EINVAL; | 
|  | 6257 | *out = val; | 
|  | 6258 | return 0; | 
|  | 6259 | } | 
|  | 6260 |  | 
|  | 6261 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) | 
|  | 6262 | { | 
|  | 6263 | u32 val = nla_get_u32(nla); | 
|  | 6264 | if (val < min || val > max) | 
|  | 6265 | return -EINVAL; | 
|  | 6266 | *out = val; | 
|  | 6267 | return 0; | 
|  | 6268 | } | 
|  | 6269 |  | 
|  | 6270 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) | 
|  | 6271 | { | 
|  | 6272 | s32 val = nla_get_s32(nla); | 
|  | 6273 | if (val < min || val > max) | 
|  | 6274 | return -EINVAL; | 
|  | 6275 | *out = val; | 
|  | 6276 | return 0; | 
|  | 6277 | } | 
|  | 6278 |  | 
|  | 6279 | static int nl80211_check_power_mode(const struct nlattr *nla, | 
|  | 6280 | enum nl80211_mesh_power_mode min, | 
|  | 6281 | enum nl80211_mesh_power_mode max, | 
|  | 6282 | enum nl80211_mesh_power_mode *out) | 
|  | 6283 | { | 
|  | 6284 | u32 val = nla_get_u32(nla); | 
|  | 6285 | if (val < min || val > max) | 
|  | 6286 | return -EINVAL; | 
|  | 6287 | *out = val; | 
|  | 6288 | return 0; | 
|  | 6289 | } | 
|  | 6290 |  | 
|  | 6291 | static int nl80211_parse_mesh_config(struct genl_info *info, | 
|  | 6292 | struct mesh_config *cfg, | 
|  | 6293 | u32 *mask_out) | 
|  | 6294 | { | 
|  | 6295 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | 
|  | 6296 | u32 mask = 0; | 
|  | 6297 | u16 ht_opmode; | 
|  | 6298 |  | 
|  | 6299 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ | 
|  | 6300 | do {									    \ | 
|  | 6301 | if (tb[attr]) {							    \ | 
|  | 6302 | if (fn(tb[attr], min, max, &cfg->param))		    \ | 
|  | 6303 | return -EINVAL;					    \ | 
|  | 6304 | mask |= (1 << (attr - 1));				    \ | 
|  | 6305 | }								    \ | 
|  | 6306 | } while (0) | 
|  | 6307 |  | 
|  | 6308 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) | 
|  | 6309 | return -EINVAL; | 
|  | 6310 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | 
|  | 6311 | info->attrs[NL80211_ATTR_MESH_CONFIG], | 
|  | 6312 | nl80211_meshconf_params_policy, info->extack)) | 
|  | 6313 | return -EINVAL; | 
|  | 6314 |  | 
|  | 6315 | /* This makes sure that there aren't more than 32 mesh config | 
|  | 6316 | * parameters (otherwise our bitfield scheme would not work.) */ | 
|  | 6317 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | 
|  | 6318 |  | 
|  | 6319 | /* Fill in the params struct */ | 
|  | 6320 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, | 
|  | 6321 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, | 
|  | 6322 | nl80211_check_u16); | 
|  | 6323 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, | 
|  | 6324 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, | 
|  | 6325 | nl80211_check_u16); | 
|  | 6326 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, | 
|  | 6327 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, | 
|  | 6328 | nl80211_check_u16); | 
|  | 6329 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, | 
|  | 6330 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, | 
|  | 6331 | nl80211_check_u16); | 
|  | 6332 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, | 
|  | 6333 | mask, NL80211_MESHCONF_MAX_RETRIES, | 
|  | 6334 | nl80211_check_u8); | 
|  | 6335 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, | 
|  | 6336 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); | 
|  | 6337 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, | 
|  | 6338 | mask, NL80211_MESHCONF_ELEMENT_TTL, | 
|  | 6339 | nl80211_check_u8); | 
|  | 6340 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, | 
|  | 6341 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | 
|  | 6342 | nl80211_check_bool); | 
|  | 6343 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, | 
|  | 6344 | 1, 255, mask, | 
|  | 6345 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, | 
|  | 6346 | nl80211_check_u32); | 
|  | 6347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, | 
|  | 6348 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | 
|  | 6349 | nl80211_check_u8); | 
|  | 6350 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, | 
|  | 6351 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, | 
|  | 6352 | nl80211_check_u32); | 
|  | 6353 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, | 
|  | 6354 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | 
|  | 6355 | nl80211_check_u16); | 
|  | 6356 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | 
|  | 6357 | 1, 65535, mask, | 
|  | 6358 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | 
|  | 6359 | nl80211_check_u32); | 
|  | 6360 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | 
|  | 6361 | 1, 65535, mask, | 
|  | 6362 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | 
|  | 6363 | nl80211_check_u16); | 
|  | 6364 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, | 
|  | 6365 | 1, 65535, mask, | 
|  | 6366 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | 
|  | 6367 | nl80211_check_u16); | 
|  | 6368 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | 
|  | 6369 | dot11MeshHWMPnetDiameterTraversalTime, | 
|  | 6370 | 1, 65535, mask, | 
|  | 6371 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | 
|  | 6372 | nl80211_check_u16); | 
|  | 6373 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, | 
|  | 6374 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | 
|  | 6375 | nl80211_check_u8); | 
|  | 6376 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | 
|  | 6377 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | 
|  | 6378 | nl80211_check_u16); | 
|  | 6379 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | 
|  | 6380 | dot11MeshGateAnnouncementProtocol, 0, 1, | 
|  | 6381 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | 
|  | 6382 | nl80211_check_bool); | 
|  | 6383 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, | 
|  | 6384 | mask, NL80211_MESHCONF_FORWARDING, | 
|  | 6385 | nl80211_check_bool); | 
|  | 6386 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, | 
|  | 6387 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, | 
|  | 6388 | nl80211_check_s32); | 
|  | 6389 | /* | 
|  | 6390 | * Check HT operation mode based on | 
|  | 6391 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. | 
|  | 6392 | */ | 
|  | 6393 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | 
|  | 6394 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | 
|  | 6395 |  | 
|  | 6396 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | 
|  | 6397 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | 
|  | 6398 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | 
|  | 6399 | return -EINVAL; | 
|  | 6400 |  | 
|  | 6401 | /* NON_HT_STA bit is reserved, but some programs set it */ | 
|  | 6402 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; | 
|  | 6403 |  | 
|  | 6404 | cfg->ht_opmode = ht_opmode; | 
|  | 6405 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); | 
|  | 6406 | } | 
|  | 6407 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | 
|  | 6408 | 1, 65535, mask, | 
|  | 6409 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | 
|  | 6410 | nl80211_check_u32); | 
|  | 6411 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, | 
|  | 6412 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | 
|  | 6413 | nl80211_check_u16); | 
|  | 6414 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | 
|  | 6415 | dot11MeshHWMPconfirmationInterval, | 
|  | 6416 | 1, 65535, mask, | 
|  | 6417 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | 
|  | 6418 | nl80211_check_u16); | 
|  | 6419 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, | 
|  | 6420 | NL80211_MESH_POWER_ACTIVE, | 
|  | 6421 | NL80211_MESH_POWER_MAX, | 
|  | 6422 | mask, NL80211_MESHCONF_POWER_MODE, | 
|  | 6423 | nl80211_check_power_mode); | 
|  | 6424 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | 
|  | 6425 | 0, 65535, mask, | 
|  | 6426 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); | 
|  | 6427 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, | 
|  | 6428 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | 
|  | 6429 | nl80211_check_u32); | 
|  | 6430 | if (mask_out) | 
|  | 6431 | *mask_out = mask; | 
|  | 6432 |  | 
|  | 6433 | return 0; | 
|  | 6434 |  | 
|  | 6435 | #undef FILL_IN_MESH_PARAM_IF_SET | 
|  | 6436 | } | 
|  | 6437 |  | 
|  | 6438 | static int nl80211_parse_mesh_setup(struct genl_info *info, | 
|  | 6439 | struct mesh_setup *setup) | 
|  | 6440 | { | 
|  | 6441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 6442 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | 
|  | 6443 |  | 
|  | 6444 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | 
|  | 6445 | return -EINVAL; | 
|  | 6446 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | 
|  | 6447 | info->attrs[NL80211_ATTR_MESH_SETUP], | 
|  | 6448 | nl80211_mesh_setup_params_policy, info->extack)) | 
|  | 6449 | return -EINVAL; | 
|  | 6450 |  | 
|  | 6451 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) | 
|  | 6452 | setup->sync_method = | 
|  | 6453 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | 
|  | 6454 | IEEE80211_SYNC_METHOD_VENDOR : | 
|  | 6455 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | 
|  | 6456 |  | 
|  | 6457 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) | 
|  | 6458 | setup->path_sel_proto = | 
|  | 6459 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | 
|  | 6460 | IEEE80211_PATH_PROTOCOL_VENDOR : | 
|  | 6461 | IEEE80211_PATH_PROTOCOL_HWMP; | 
|  | 6462 |  | 
|  | 6463 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | 
|  | 6464 | setup->path_metric = | 
|  | 6465 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | 
|  | 6466 | IEEE80211_PATH_METRIC_VENDOR : | 
|  | 6467 | IEEE80211_PATH_METRIC_AIRTIME; | 
|  | 6468 |  | 
|  | 6469 | if (tb[NL80211_MESH_SETUP_IE]) { | 
|  | 6470 | struct nlattr *ieattr = | 
|  | 6471 | tb[NL80211_MESH_SETUP_IE]; | 
|  | 6472 | if (!is_valid_ie_attr(ieattr)) | 
|  | 6473 | return -EINVAL; | 
|  | 6474 | setup->ie = nla_data(ieattr); | 
|  | 6475 | setup->ie_len = nla_len(ieattr); | 
|  | 6476 | } | 
|  | 6477 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && | 
|  | 6478 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | 
|  | 6479 | return -EINVAL; | 
|  | 6480 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | 
|  | 6481 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); | 
|  | 6482 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | 
|  | 6483 | if (setup->is_secure) | 
|  | 6484 | setup->user_mpm = true; | 
|  | 6485 |  | 
|  | 6486 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { | 
|  | 6487 | if (!setup->user_mpm) | 
|  | 6488 | return -EINVAL; | 
|  | 6489 | setup->auth_id = | 
|  | 6490 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | 
|  | 6491 | } | 
|  | 6492 |  | 
|  | 6493 | return 0; | 
|  | 6494 | } | 
|  | 6495 |  | 
|  | 6496 | static int nl80211_update_mesh_config(struct sk_buff *skb, | 
|  | 6497 | struct genl_info *info) | 
|  | 6498 | { | 
|  | 6499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 6500 | struct net_device *dev = info->user_ptr[1]; | 
|  | 6501 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 6502 | struct mesh_config cfg; | 
|  | 6503 | u32 mask; | 
|  | 6504 | int err; | 
|  | 6505 |  | 
|  | 6506 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | 
|  | 6507 | return -EOPNOTSUPP; | 
|  | 6508 |  | 
|  | 6509 | if (!rdev->ops->update_mesh_config) | 
|  | 6510 | return -EOPNOTSUPP; | 
|  | 6511 |  | 
|  | 6512 | err = nl80211_parse_mesh_config(info, &cfg, &mask); | 
|  | 6513 | if (err) | 
|  | 6514 | return err; | 
|  | 6515 |  | 
|  | 6516 | wdev_lock(wdev); | 
|  | 6517 | if (!wdev->mesh_id_len) | 
|  | 6518 | err = -ENOLINK; | 
|  | 6519 |  | 
|  | 6520 | if (!err) | 
|  | 6521 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); | 
|  | 6522 |  | 
|  | 6523 | wdev_unlock(wdev); | 
|  | 6524 |  | 
|  | 6525 | return err; | 
|  | 6526 | } | 
|  | 6527 |  | 
|  | 6528 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, | 
|  | 6529 | struct sk_buff *msg) | 
|  | 6530 | { | 
|  | 6531 | struct nlattr *nl_reg_rules; | 
|  | 6532 | unsigned int i; | 
|  | 6533 |  | 
|  | 6534 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | 
|  | 6535 | (regdom->dfs_region && | 
|  | 6536 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | 
|  | 6537 | goto nla_put_failure; | 
|  | 6538 |  | 
|  | 6539 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | 
|  | 6540 | if (!nl_reg_rules) | 
|  | 6541 | goto nla_put_failure; | 
|  | 6542 |  | 
|  | 6543 | for (i = 0; i < regdom->n_reg_rules; i++) { | 
|  | 6544 | struct nlattr *nl_reg_rule; | 
|  | 6545 | const struct ieee80211_reg_rule *reg_rule; | 
|  | 6546 | const struct ieee80211_freq_range *freq_range; | 
|  | 6547 | const struct ieee80211_power_rule *power_rule; | 
|  | 6548 | unsigned int max_bandwidth_khz; | 
|  | 6549 |  | 
|  | 6550 | reg_rule = ®dom->reg_rules[i]; | 
|  | 6551 | freq_range = ®_rule->freq_range; | 
|  | 6552 | power_rule = ®_rule->power_rule; | 
|  | 6553 |  | 
|  | 6554 | nl_reg_rule = nla_nest_start(msg, i); | 
|  | 6555 | if (!nl_reg_rule) | 
|  | 6556 | goto nla_put_failure; | 
|  | 6557 |  | 
|  | 6558 | max_bandwidth_khz = freq_range->max_bandwidth_khz; | 
|  | 6559 | if (!max_bandwidth_khz) | 
|  | 6560 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | 
|  | 6561 | reg_rule); | 
|  | 6562 |  | 
|  | 6563 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, | 
|  | 6564 | reg_rule->flags) || | 
|  | 6565 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | 
|  | 6566 | freq_range->start_freq_khz) || | 
|  | 6567 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | 
|  | 6568 | freq_range->end_freq_khz) || | 
|  | 6569 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | 
|  | 6570 | max_bandwidth_khz) || | 
|  | 6571 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | 
|  | 6572 | power_rule->max_antenna_gain) || | 
|  | 6573 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | 
|  | 6574 | power_rule->max_eirp) || | 
|  | 6575 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | 
|  | 6576 | reg_rule->dfs_cac_ms)) | 
|  | 6577 | goto nla_put_failure; | 
|  | 6578 |  | 
|  | 6579 | nla_nest_end(msg, nl_reg_rule); | 
|  | 6580 | } | 
|  | 6581 |  | 
|  | 6582 | nla_nest_end(msg, nl_reg_rules); | 
|  | 6583 | return 0; | 
|  | 6584 |  | 
|  | 6585 | nla_put_failure: | 
|  | 6586 | return -EMSGSIZE; | 
|  | 6587 | } | 
|  | 6588 |  | 
|  | 6589 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | 
|  | 6590 | { | 
|  | 6591 | const struct ieee80211_regdomain *regdom = NULL; | 
|  | 6592 | struct cfg80211_registered_device *rdev; | 
|  | 6593 | struct wiphy *wiphy = NULL; | 
|  | 6594 | struct sk_buff *msg; | 
|  | 6595 | void *hdr; | 
|  | 6596 |  | 
|  | 6597 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 6598 | if (!msg) | 
|  | 6599 | return -ENOBUFS; | 
|  | 6600 |  | 
|  | 6601 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 6602 | NL80211_CMD_GET_REG); | 
|  | 6603 | if (!hdr) | 
|  | 6604 | goto put_failure; | 
|  | 6605 |  | 
|  | 6606 | if (info->attrs[NL80211_ATTR_WIPHY]) { | 
|  | 6607 | bool self_managed; | 
|  | 6608 |  | 
|  | 6609 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); | 
|  | 6610 | if (IS_ERR(rdev)) { | 
|  | 6611 | nlmsg_free(msg); | 
|  | 6612 | return PTR_ERR(rdev); | 
|  | 6613 | } | 
|  | 6614 |  | 
|  | 6615 | wiphy = &rdev->wiphy; | 
|  | 6616 | self_managed = wiphy->regulatory_flags & | 
|  | 6617 | REGULATORY_WIPHY_SELF_MANAGED; | 
|  | 6618 | regdom = get_wiphy_regdom(wiphy); | 
|  | 6619 |  | 
|  | 6620 | /* a self-managed-reg device must have a private regdom */ | 
|  | 6621 | if (WARN_ON(!regdom && self_managed)) { | 
|  | 6622 | nlmsg_free(msg); | 
|  | 6623 | return -EINVAL; | 
|  | 6624 | } | 
|  | 6625 |  | 
|  | 6626 | if (regdom && | 
|  | 6627 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | 
|  | 6628 | goto nla_put_failure; | 
|  | 6629 | } | 
|  | 6630 |  | 
|  | 6631 | if (!wiphy && reg_last_request_cell_base() && | 
|  | 6632 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | 
|  | 6633 | NL80211_USER_REG_HINT_CELL_BASE)) | 
|  | 6634 | goto nla_put_failure; | 
|  | 6635 |  | 
|  | 6636 | rcu_read_lock(); | 
|  | 6637 |  | 
|  | 6638 | if (!regdom) | 
|  | 6639 | regdom = rcu_dereference(cfg80211_regdomain); | 
|  | 6640 |  | 
|  | 6641 | if (nl80211_put_regdom(regdom, msg)) | 
|  | 6642 | goto nla_put_failure_rcu; | 
|  | 6643 |  | 
|  | 6644 | rcu_read_unlock(); | 
|  | 6645 |  | 
|  | 6646 | genlmsg_end(msg, hdr); | 
|  | 6647 | return genlmsg_reply(msg, info); | 
|  | 6648 |  | 
|  | 6649 | nla_put_failure_rcu: | 
|  | 6650 | rcu_read_unlock(); | 
|  | 6651 | nla_put_failure: | 
|  | 6652 | put_failure: | 
|  | 6653 | nlmsg_free(msg); | 
|  | 6654 | return -EMSGSIZE; | 
|  | 6655 | } | 
|  | 6656 |  | 
|  | 6657 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, | 
|  | 6658 | u32 seq, int flags, struct wiphy *wiphy, | 
|  | 6659 | const struct ieee80211_regdomain *regdom) | 
|  | 6660 | { | 
|  | 6661 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | 
|  | 6662 | NL80211_CMD_GET_REG); | 
|  | 6663 |  | 
|  | 6664 | if (!hdr) | 
|  | 6665 | return -1; | 
|  | 6666 |  | 
|  | 6667 | genl_dump_check_consistent(cb, hdr); | 
|  | 6668 |  | 
|  | 6669 | if (nl80211_put_regdom(regdom, msg)) | 
|  | 6670 | goto nla_put_failure; | 
|  | 6671 |  | 
|  | 6672 | if (!wiphy && reg_last_request_cell_base() && | 
|  | 6673 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | 
|  | 6674 | NL80211_USER_REG_HINT_CELL_BASE)) | 
|  | 6675 | goto nla_put_failure; | 
|  | 6676 |  | 
|  | 6677 | if (wiphy && | 
|  | 6678 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | 
|  | 6679 | goto nla_put_failure; | 
|  | 6680 |  | 
|  | 6681 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | 
|  | 6682 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | 
|  | 6683 | goto nla_put_failure; | 
|  | 6684 |  | 
|  | 6685 | genlmsg_end(msg, hdr); | 
|  | 6686 | return 0; | 
|  | 6687 |  | 
|  | 6688 | nla_put_failure: | 
|  | 6689 | genlmsg_cancel(msg, hdr); | 
|  | 6690 | return -EMSGSIZE; | 
|  | 6691 | } | 
|  | 6692 |  | 
|  | 6693 | static int nl80211_get_reg_dump(struct sk_buff *skb, | 
|  | 6694 | struct netlink_callback *cb) | 
|  | 6695 | { | 
|  | 6696 | const struct ieee80211_regdomain *regdom = NULL; | 
|  | 6697 | struct cfg80211_registered_device *rdev; | 
|  | 6698 | int err, reg_idx, start = cb->args[2]; | 
|  | 6699 |  | 
|  | 6700 | rtnl_lock(); | 
|  | 6701 |  | 
|  | 6702 | if (cfg80211_regdomain && start == 0) { | 
|  | 6703 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | 
|  | 6704 | NLM_F_MULTI, NULL, | 
|  | 6705 | rtnl_dereference(cfg80211_regdomain)); | 
|  | 6706 | if (err < 0) | 
|  | 6707 | goto out_err; | 
|  | 6708 | } | 
|  | 6709 |  | 
|  | 6710 | /* the global regdom is idx 0 */ | 
|  | 6711 | reg_idx = 1; | 
|  | 6712 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
|  | 6713 | regdom = get_wiphy_regdom(&rdev->wiphy); | 
|  | 6714 | if (!regdom) | 
|  | 6715 | continue; | 
|  | 6716 |  | 
|  | 6717 | if (++reg_idx <= start) | 
|  | 6718 | continue; | 
|  | 6719 |  | 
|  | 6720 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | 
|  | 6721 | NLM_F_MULTI, &rdev->wiphy, regdom); | 
|  | 6722 | if (err < 0) { | 
|  | 6723 | reg_idx--; | 
|  | 6724 | break; | 
|  | 6725 | } | 
|  | 6726 | } | 
|  | 6727 |  | 
|  | 6728 | cb->args[2] = reg_idx; | 
|  | 6729 | err = skb->len; | 
|  | 6730 | out_err: | 
|  | 6731 | rtnl_unlock(); | 
|  | 6732 | return err; | 
|  | 6733 | } | 
|  | 6734 |  | 
|  | 6735 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT | 
|  | 6736 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | 
|  | 6737 | [NL80211_ATTR_REG_RULE_FLAGS]		= { .type = NLA_U32 }, | 
|  | 6738 | [NL80211_ATTR_FREQ_RANGE_START]		= { .type = NLA_U32 }, | 
|  | 6739 | [NL80211_ATTR_FREQ_RANGE_END]		= { .type = NLA_U32 }, | 
|  | 6740 | [NL80211_ATTR_FREQ_RANGE_MAX_BW]	= { .type = NLA_U32 }, | 
|  | 6741 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]	= { .type = NLA_U32 }, | 
|  | 6742 | [NL80211_ATTR_POWER_RULE_MAX_EIRP]	= { .type = NLA_U32 }, | 
|  | 6743 | [NL80211_ATTR_DFS_CAC_TIME]		= { .type = NLA_U32 }, | 
|  | 6744 | }; | 
|  | 6745 |  | 
|  | 6746 | static int parse_reg_rule(struct nlattr *tb[], | 
|  | 6747 | struct ieee80211_reg_rule *reg_rule) | 
|  | 6748 | { | 
|  | 6749 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | 
|  | 6750 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | 
|  | 6751 |  | 
|  | 6752 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | 
|  | 6753 | return -EINVAL; | 
|  | 6754 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | 
|  | 6755 | return -EINVAL; | 
|  | 6756 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | 
|  | 6757 | return -EINVAL; | 
|  | 6758 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | 
|  | 6759 | return -EINVAL; | 
|  | 6760 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | 
|  | 6761 | return -EINVAL; | 
|  | 6762 |  | 
|  | 6763 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | 
|  | 6764 |  | 
|  | 6765 | freq_range->start_freq_khz = | 
|  | 6766 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | 
|  | 6767 | freq_range->end_freq_khz = | 
|  | 6768 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | 
|  | 6769 | freq_range->max_bandwidth_khz = | 
|  | 6770 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | 
|  | 6771 |  | 
|  | 6772 | power_rule->max_eirp = | 
|  | 6773 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | 
|  | 6774 |  | 
|  | 6775 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | 
|  | 6776 | power_rule->max_antenna_gain = | 
|  | 6777 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | 
|  | 6778 |  | 
|  | 6779 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | 
|  | 6780 | reg_rule->dfs_cac_ms = | 
|  | 6781 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | 
|  | 6782 |  | 
|  | 6783 | return 0; | 
|  | 6784 | } | 
|  | 6785 |  | 
|  | 6786 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) | 
|  | 6787 | { | 
|  | 6788 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | 
|  | 6789 | struct nlattr *nl_reg_rule; | 
|  | 6790 | char *alpha2; | 
|  | 6791 | int rem_reg_rules, r; | 
|  | 6792 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | 
|  | 6793 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; | 
|  | 6794 | struct ieee80211_regdomain *rd; | 
|  | 6795 |  | 
|  | 6796 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | 
|  | 6797 | return -EINVAL; | 
|  | 6798 |  | 
|  | 6799 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | 
|  | 6800 | return -EINVAL; | 
|  | 6801 |  | 
|  | 6802 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | 
|  | 6803 |  | 
|  | 6804 | if (info->attrs[NL80211_ATTR_DFS_REGION]) | 
|  | 6805 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | 
|  | 6806 |  | 
|  | 6807 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | 
|  | 6808 | rem_reg_rules) { | 
|  | 6809 | num_rules++; | 
|  | 6810 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | 
|  | 6811 | return -EINVAL; | 
|  | 6812 | } | 
|  | 6813 |  | 
|  | 6814 | if (!reg_is_valid_request(alpha2)) | 
|  | 6815 | return -EINVAL; | 
|  | 6816 |  | 
|  | 6817 | size_of_regd = sizeof(struct ieee80211_regdomain) + | 
|  | 6818 | num_rules * sizeof(struct ieee80211_reg_rule); | 
|  | 6819 |  | 
|  | 6820 | rd = kzalloc(size_of_regd, GFP_KERNEL); | 
|  | 6821 | if (!rd) | 
|  | 6822 | return -ENOMEM; | 
|  | 6823 |  | 
|  | 6824 | rd->n_reg_rules = num_rules; | 
|  | 6825 | rd->alpha2[0] = alpha2[0]; | 
|  | 6826 | rd->alpha2[1] = alpha2[1]; | 
|  | 6827 |  | 
|  | 6828 | /* | 
|  | 6829 | * Disable DFS master mode if the DFS region was | 
|  | 6830 | * not supported or known on this kernel. | 
|  | 6831 | */ | 
|  | 6832 | if (reg_supported_dfs_region(dfs_region)) | 
|  | 6833 | rd->dfs_region = dfs_region; | 
|  | 6834 |  | 
|  | 6835 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | 
|  | 6836 | rem_reg_rules) { | 
|  | 6837 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, | 
|  | 6838 | nl_reg_rule, reg_rule_policy, | 
|  | 6839 | info->extack); | 
|  | 6840 | if (r) | 
|  | 6841 | goto bad_reg; | 
|  | 6842 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | 
|  | 6843 | if (r) | 
|  | 6844 | goto bad_reg; | 
|  | 6845 |  | 
|  | 6846 | rule_idx++; | 
|  | 6847 |  | 
|  | 6848 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { | 
|  | 6849 | r = -EINVAL; | 
|  | 6850 | goto bad_reg; | 
|  | 6851 | } | 
|  | 6852 | } | 
|  | 6853 |  | 
|  | 6854 | /* set_regdom takes ownership of rd */ | 
|  | 6855 | return set_regdom(rd, REGD_SOURCE_CRDA); | 
|  | 6856 | bad_reg: | 
|  | 6857 | kfree(rd); | 
|  | 6858 | return r; | 
|  | 6859 | } | 
|  | 6860 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ | 
|  | 6861 |  | 
|  | 6862 | static int validate_scan_freqs(struct nlattr *freqs) | 
|  | 6863 | { | 
|  | 6864 | struct nlattr *attr1, *attr2; | 
|  | 6865 | int n_channels = 0, tmp1, tmp2; | 
|  | 6866 |  | 
|  | 6867 | nla_for_each_nested(attr1, freqs, tmp1) | 
|  | 6868 | if (nla_len(attr1) != sizeof(u32)) | 
|  | 6869 | return 0; | 
|  | 6870 |  | 
|  | 6871 | nla_for_each_nested(attr1, freqs, tmp1) { | 
|  | 6872 | n_channels++; | 
|  | 6873 | /* | 
|  | 6874 | * Some hardware has a limited channel list for | 
|  | 6875 | * scanning, and it is pretty much nonsensical | 
|  | 6876 | * to scan for a channel twice, so disallow that | 
|  | 6877 | * and don't require drivers to check that the | 
|  | 6878 | * channel list they get isn't longer than what | 
|  | 6879 | * they can scan, as long as they can scan all | 
|  | 6880 | * the channels they registered at once. | 
|  | 6881 | */ | 
|  | 6882 | nla_for_each_nested(attr2, freqs, tmp2) | 
|  | 6883 | if (attr1 != attr2 && | 
|  | 6884 | nla_get_u32(attr1) == nla_get_u32(attr2)) | 
|  | 6885 | return 0; | 
|  | 6886 | } | 
|  | 6887 |  | 
|  | 6888 | return n_channels; | 
|  | 6889 | } | 
|  | 6890 |  | 
|  | 6891 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) | 
|  | 6892 | { | 
|  | 6893 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; | 
|  | 6894 | } | 
|  | 6895 |  | 
|  | 6896 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | 
|  | 6897 | struct cfg80211_bss_selection *bss_select) | 
|  | 6898 | { | 
|  | 6899 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | 
|  | 6900 | struct nlattr *nest; | 
|  | 6901 | int err; | 
|  | 6902 | bool found = false; | 
|  | 6903 | int i; | 
|  | 6904 |  | 
|  | 6905 | /* only process one nested attribute */ | 
|  | 6906 | nest = nla_data(nla); | 
|  | 6907 | if (!nla_ok(nest, nla_len(nest))) | 
|  | 6908 | return -EINVAL; | 
|  | 6909 |  | 
|  | 6910 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, | 
|  | 6911 | nl80211_bss_select_policy, NULL); | 
|  | 6912 | if (err) | 
|  | 6913 | return err; | 
|  | 6914 |  | 
|  | 6915 | /* only one attribute may be given */ | 
|  | 6916 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | 
|  | 6917 | if (attr[i]) { | 
|  | 6918 | if (found) | 
|  | 6919 | return -EINVAL; | 
|  | 6920 | found = true; | 
|  | 6921 | } | 
|  | 6922 | } | 
|  | 6923 |  | 
|  | 6924 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | 
|  | 6925 |  | 
|  | 6926 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | 
|  | 6927 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | 
|  | 6928 |  | 
|  | 6929 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | 
|  | 6930 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | 
|  | 6931 | bss_select->param.band_pref = | 
|  | 6932 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | 
|  | 6933 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | 
|  | 6934 | return -EINVAL; | 
|  | 6935 | } | 
|  | 6936 |  | 
|  | 6937 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | 
|  | 6938 | struct nl80211_bss_select_rssi_adjust *adj_param; | 
|  | 6939 |  | 
|  | 6940 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | 
|  | 6941 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | 
|  | 6942 | bss_select->param.adjust.band = adj_param->band; | 
|  | 6943 | bss_select->param.adjust.delta = adj_param->delta; | 
|  | 6944 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | 
|  | 6945 | return -EINVAL; | 
|  | 6946 | } | 
|  | 6947 |  | 
|  | 6948 | /* user-space did not provide behaviour attribute */ | 
|  | 6949 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | 
|  | 6950 | return -EINVAL; | 
|  | 6951 |  | 
|  | 6952 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | 
|  | 6953 | return -EINVAL; | 
|  | 6954 |  | 
|  | 6955 | return 0; | 
|  | 6956 | } | 
|  | 6957 |  | 
|  | 6958 | static int nl80211_parse_random_mac(struct nlattr **attrs, | 
|  | 6959 | u8 *mac_addr, u8 *mac_addr_mask) | 
|  | 6960 | { | 
|  | 6961 | int i; | 
|  | 6962 |  | 
|  | 6963 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | 
|  | 6964 | eth_zero_addr(mac_addr); | 
|  | 6965 | eth_zero_addr(mac_addr_mask); | 
|  | 6966 | mac_addr[0] = 0x2; | 
|  | 6967 | mac_addr_mask[0] = 0x3; | 
|  | 6968 |  | 
|  | 6969 | return 0; | 
|  | 6970 | } | 
|  | 6971 |  | 
|  | 6972 | /* need both or none */ | 
|  | 6973 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | 
|  | 6974 | return -EINVAL; | 
|  | 6975 |  | 
|  | 6976 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | 
|  | 6977 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | 
|  | 6978 |  | 
|  | 6979 | /* don't allow or configure an mcast address */ | 
|  | 6980 | if (!is_multicast_ether_addr(mac_addr_mask) || | 
|  | 6981 | is_multicast_ether_addr(mac_addr)) | 
|  | 6982 | return -EINVAL; | 
|  | 6983 |  | 
|  | 6984 | /* | 
|  | 6985 | * allow users to pass a MAC address that has bits set outside | 
|  | 6986 | * of the mask, but don't bother drivers with having to deal | 
|  | 6987 | * with such bits | 
|  | 6988 | */ | 
|  | 6989 | for (i = 0; i < ETH_ALEN; i++) | 
|  | 6990 | mac_addr[i] &= mac_addr_mask[i]; | 
|  | 6991 |  | 
|  | 6992 | return 0; | 
|  | 6993 | } | 
|  | 6994 |  | 
|  | 6995 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) | 
|  | 6996 | { | 
|  | 6997 | ASSERT_WDEV_LOCK(wdev); | 
|  | 6998 |  | 
|  | 6999 | if (!cfg80211_beaconing_iface_active(wdev)) | 
|  | 7000 | return true; | 
|  | 7001 |  | 
|  | 7002 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) | 
|  | 7003 | return true; | 
|  | 7004 |  | 
|  | 7005 | return regulatory_pre_cac_allowed(wdev->wiphy); | 
|  | 7006 | } | 
|  | 7007 |  | 
|  | 7008 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, | 
|  | 7009 | enum nl80211_ext_feature_index feat) | 
|  | 7010 | { | 
|  | 7011 | if (!(flags & flag)) | 
|  | 7012 | return true; | 
|  | 7013 | if (wiphy_ext_feature_isset(wiphy, feat)) | 
|  | 7014 | return true; | 
|  | 7015 | return false; | 
|  | 7016 | } | 
|  | 7017 |  | 
|  | 7018 | static int | 
|  | 7019 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, | 
|  | 7020 | void *request, struct nlattr **attrs, | 
|  | 7021 | bool is_sched_scan) | 
|  | 7022 | { | 
|  | 7023 | u8 *mac_addr, *mac_addr_mask; | 
|  | 7024 | u32 *flags; | 
|  | 7025 | enum nl80211_feature_flags randomness_flag; | 
|  | 7026 |  | 
|  | 7027 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) | 
|  | 7028 | return 0; | 
|  | 7029 |  | 
|  | 7030 | if (is_sched_scan) { | 
|  | 7031 | struct cfg80211_sched_scan_request *req = request; | 
|  | 7032 |  | 
|  | 7033 | randomness_flag = wdev ? | 
|  | 7034 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : | 
|  | 7035 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | 
|  | 7036 | flags = &req->flags; | 
|  | 7037 | mac_addr = req->mac_addr; | 
|  | 7038 | mac_addr_mask = req->mac_addr_mask; | 
|  | 7039 | } else { | 
|  | 7040 | struct cfg80211_scan_request *req = request; | 
|  | 7041 |  | 
|  | 7042 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; | 
|  | 7043 | flags = &req->flags; | 
|  | 7044 | mac_addr = req->mac_addr; | 
|  | 7045 | mac_addr_mask = req->mac_addr_mask; | 
|  | 7046 | } | 
|  | 7047 |  | 
|  | 7048 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); | 
|  | 7049 |  | 
|  | 7050 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && | 
|  | 7051 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || | 
|  | 7052 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7053 | NL80211_SCAN_FLAG_LOW_SPAN, | 
|  | 7054 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || | 
|  | 7055 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7056 | NL80211_SCAN_FLAG_LOW_POWER, | 
|  | 7057 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || | 
|  | 7058 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7059 | NL80211_SCAN_FLAG_HIGH_ACCURACY, | 
|  | 7060 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || | 
|  | 7061 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7062 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, | 
|  | 7063 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || | 
|  | 7064 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7065 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, | 
|  | 7066 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || | 
|  | 7067 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7068 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, | 
|  | 7069 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || | 
|  | 7070 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7071 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, | 
|  | 7072 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || | 
|  | 7073 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7074 | NL80211_SCAN_FLAG_RANDOM_SN, | 
|  | 7075 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || | 
|  | 7076 | !nl80211_check_scan_feat(wiphy, *flags, | 
|  | 7077 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, | 
|  | 7078 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) | 
|  | 7079 | return -EOPNOTSUPP; | 
|  | 7080 |  | 
|  | 7081 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | 
|  | 7082 | int err; | 
|  | 7083 |  | 
|  | 7084 | if (!(wiphy->features & randomness_flag) || | 
|  | 7085 | (wdev && wdev->current_bss)) | 
|  | 7086 | return -EOPNOTSUPP; | 
|  | 7087 |  | 
|  | 7088 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); | 
|  | 7089 | if (err) | 
|  | 7090 | return err; | 
|  | 7091 | } | 
|  | 7092 |  | 
|  | 7093 | return 0; | 
|  | 7094 | } | 
|  | 7095 |  | 
|  | 7096 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | 
|  | 7097 | { | 
|  | 7098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 7099 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 7100 | struct cfg80211_scan_request *request; | 
|  | 7101 | struct nlattr *attr; | 
|  | 7102 | struct wiphy *wiphy; | 
|  | 7103 | int err, tmp, n_ssids = 0, n_channels, i; | 
|  | 7104 | size_t ie_len; | 
|  | 7105 |  | 
|  | 7106 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 7107 | return -EINVAL; | 
|  | 7108 |  | 
|  | 7109 | wiphy = &rdev->wiphy; | 
|  | 7110 |  | 
|  | 7111 | if (wdev->iftype == NL80211_IFTYPE_NAN) | 
|  | 7112 | return -EOPNOTSUPP; | 
|  | 7113 |  | 
|  | 7114 | if (!rdev->ops->scan) | 
|  | 7115 | return -EOPNOTSUPP; | 
|  | 7116 |  | 
|  | 7117 | if (rdev->scan_req || rdev->scan_msg) { | 
|  | 7118 | err = -EBUSY; | 
|  | 7119 | goto unlock; | 
|  | 7120 | } | 
|  | 7121 |  | 
|  | 7122 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
|  | 7123 | n_channels = validate_scan_freqs( | 
|  | 7124 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | 
|  | 7125 | if (!n_channels) { | 
|  | 7126 | err = -EINVAL; | 
|  | 7127 | goto unlock; | 
|  | 7128 | } | 
|  | 7129 | } else { | 
|  | 7130 | n_channels = ieee80211_get_num_supported_channels(wiphy); | 
|  | 7131 | } | 
|  | 7132 |  | 
|  | 7133 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | 
|  | 7134 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | 
|  | 7135 | n_ssids++; | 
|  | 7136 |  | 
|  | 7137 | if (n_ssids > wiphy->max_scan_ssids) { | 
|  | 7138 | err = -EINVAL; | 
|  | 7139 | goto unlock; | 
|  | 7140 | } | 
|  | 7141 |  | 
|  | 7142 | if (info->attrs[NL80211_ATTR_IE]) | 
|  | 7143 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 7144 | else | 
|  | 7145 | ie_len = 0; | 
|  | 7146 |  | 
|  | 7147 | if (ie_len > wiphy->max_scan_ie_len) { | 
|  | 7148 | err = -EINVAL; | 
|  | 7149 | goto unlock; | 
|  | 7150 | } | 
|  | 7151 |  | 
|  | 7152 | request = kzalloc(sizeof(*request) | 
|  | 7153 | + sizeof(*request->ssids) * n_ssids | 
|  | 7154 | + sizeof(*request->channels) * n_channels | 
|  | 7155 | + ie_len, GFP_KERNEL); | 
|  | 7156 | if (!request) { | 
|  | 7157 | err = -ENOMEM; | 
|  | 7158 | goto unlock; | 
|  | 7159 | } | 
|  | 7160 |  | 
|  | 7161 | if (n_ssids) | 
|  | 7162 | request->ssids = (void *)&request->channels[n_channels]; | 
|  | 7163 | request->n_ssids = n_ssids; | 
|  | 7164 | if (ie_len) { | 
|  | 7165 | if (n_ssids) | 
|  | 7166 | request->ie = (void *)(request->ssids + n_ssids); | 
|  | 7167 | else | 
|  | 7168 | request->ie = (void *)(request->channels + n_channels); | 
|  | 7169 | } | 
|  | 7170 |  | 
|  | 7171 | i = 0; | 
|  | 7172 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
|  | 7173 | /* user specified, bail out if channel not found */ | 
|  | 7174 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { | 
|  | 7175 | struct ieee80211_channel *chan; | 
|  | 7176 |  | 
|  | 7177 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | 
|  | 7178 |  | 
|  | 7179 | if (!chan) { | 
|  | 7180 | err = -EINVAL; | 
|  | 7181 | goto out_free; | 
|  | 7182 | } | 
|  | 7183 |  | 
|  | 7184 | /* ignore disabled channels */ | 
|  | 7185 | if (chan->flags & IEEE80211_CHAN_DISABLED) | 
|  | 7186 | continue; | 
|  | 7187 |  | 
|  | 7188 | request->channels[i] = chan; | 
|  | 7189 | i++; | 
|  | 7190 | } | 
|  | 7191 | } else { | 
|  | 7192 | enum nl80211_band band; | 
|  | 7193 |  | 
|  | 7194 | /* all channels */ | 
|  | 7195 | for (band = 0; band < NUM_NL80211_BANDS; band++) { | 
|  | 7196 | int j; | 
|  | 7197 |  | 
|  | 7198 | if (!wiphy->bands[band]) | 
|  | 7199 | continue; | 
|  | 7200 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | 
|  | 7201 | struct ieee80211_channel *chan; | 
|  | 7202 |  | 
|  | 7203 | chan = &wiphy->bands[band]->channels[j]; | 
|  | 7204 |  | 
|  | 7205 | if (chan->flags & IEEE80211_CHAN_DISABLED) | 
|  | 7206 | continue; | 
|  | 7207 |  | 
|  | 7208 | request->channels[i] = chan; | 
|  | 7209 | i++; | 
|  | 7210 | } | 
|  | 7211 | } | 
|  | 7212 | } | 
|  | 7213 |  | 
|  | 7214 | if (!i) { | 
|  | 7215 | err = -EINVAL; | 
|  | 7216 | goto out_free; | 
|  | 7217 | } | 
|  | 7218 |  | 
|  | 7219 | request->n_channels = i; | 
|  | 7220 |  | 
|  | 7221 | wdev_lock(wdev); | 
|  | 7222 | if (!cfg80211_off_channel_oper_allowed(wdev)) { | 
|  | 7223 | struct ieee80211_channel *chan; | 
|  | 7224 |  | 
|  | 7225 | if (request->n_channels != 1) { | 
|  | 7226 | wdev_unlock(wdev); | 
|  | 7227 | err = -EBUSY; | 
|  | 7228 | goto out_free; | 
|  | 7229 | } | 
|  | 7230 |  | 
|  | 7231 | chan = request->channels[0]; | 
|  | 7232 | if (chan->center_freq != wdev->chandef.chan->center_freq) { | 
|  | 7233 | wdev_unlock(wdev); | 
|  | 7234 | err = -EBUSY; | 
|  | 7235 | goto out_free; | 
|  | 7236 | } | 
|  | 7237 | } | 
|  | 7238 | wdev_unlock(wdev); | 
|  | 7239 |  | 
|  | 7240 | i = 0; | 
|  | 7241 | if (n_ssids) { | 
|  | 7242 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | 
|  | 7243 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { | 
|  | 7244 | err = -EINVAL; | 
|  | 7245 | goto out_free; | 
|  | 7246 | } | 
|  | 7247 | request->ssids[i].ssid_len = nla_len(attr); | 
|  | 7248 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | 
|  | 7249 | i++; | 
|  | 7250 | } | 
|  | 7251 | } | 
|  | 7252 |  | 
|  | 7253 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 7254 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 7255 | memcpy((void *)request->ie, | 
|  | 7256 | nla_data(info->attrs[NL80211_ATTR_IE]), | 
|  | 7257 | request->ie_len); | 
|  | 7258 | } | 
|  | 7259 |  | 
|  | 7260 | for (i = 0; i < NUM_NL80211_BANDS; i++) | 
|  | 7261 | if (wiphy->bands[i]) | 
|  | 7262 | request->rates[i] = | 
|  | 7263 | (1 << wiphy->bands[i]->n_bitrates) - 1; | 
|  | 7264 |  | 
|  | 7265 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | 
|  | 7266 | nla_for_each_nested(attr, | 
|  | 7267 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | 
|  | 7268 | tmp) { | 
|  | 7269 | enum nl80211_band band = nla_type(attr); | 
|  | 7270 |  | 
|  | 7271 | if (band < 0 || band >= NUM_NL80211_BANDS) { | 
|  | 7272 | err = -EINVAL; | 
|  | 7273 | goto out_free; | 
|  | 7274 | } | 
|  | 7275 |  | 
|  | 7276 | if (!wiphy->bands[band]) | 
|  | 7277 | continue; | 
|  | 7278 |  | 
|  | 7279 | err = ieee80211_get_ratemask(wiphy->bands[band], | 
|  | 7280 | nla_data(attr), | 
|  | 7281 | nla_len(attr), | 
|  | 7282 | &request->rates[band]); | 
|  | 7283 | if (err) | 
|  | 7284 | goto out_free; | 
|  | 7285 | } | 
|  | 7286 | } | 
|  | 7287 |  | 
|  | 7288 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { | 
|  | 7289 | if (!wiphy_ext_feature_isset(wiphy, | 
|  | 7290 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { | 
|  | 7291 | err = -EOPNOTSUPP; | 
|  | 7292 | goto out_free; | 
|  | 7293 | } | 
|  | 7294 |  | 
|  | 7295 | request->duration = | 
|  | 7296 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | 
|  | 7297 | request->duration_mandatory = | 
|  | 7298 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | 
|  | 7299 | } | 
|  | 7300 |  | 
|  | 7301 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, | 
|  | 7302 | false); | 
|  | 7303 | if (err) | 
|  | 7304 | goto out_free; | 
|  | 7305 |  | 
|  | 7306 | request->no_cck = | 
|  | 7307 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | 
|  | 7308 |  | 
|  | 7309 | /* Initial implementation used NL80211_ATTR_MAC to set the specific | 
|  | 7310 | * BSSID to scan for. This was problematic because that same attribute | 
|  | 7311 | * was already used for another purpose (local random MAC address). The | 
|  | 7312 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards | 
|  | 7313 | * compatibility with older userspace components, also use the | 
|  | 7314 | * NL80211_ATTR_MAC value here if it can be determined to be used for | 
|  | 7315 | * the specific BSSID use case instead of the random MAC address | 
|  | 7316 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). | 
|  | 7317 | */ | 
|  | 7318 | if (info->attrs[NL80211_ATTR_BSSID]) | 
|  | 7319 | memcpy(request->bssid, | 
|  | 7320 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); | 
|  | 7321 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && | 
|  | 7322 | info->attrs[NL80211_ATTR_MAC]) | 
|  | 7323 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), | 
|  | 7324 | ETH_ALEN); | 
|  | 7325 | else | 
|  | 7326 | eth_broadcast_addr(request->bssid); | 
|  | 7327 |  | 
|  | 7328 | request->wdev = wdev; | 
|  | 7329 | request->wiphy = &rdev->wiphy; | 
|  | 7330 | request->scan_start = jiffies; | 
|  | 7331 |  | 
|  | 7332 | rdev->scan_req = request; | 
|  | 7333 | err = rdev_scan(rdev, request); | 
|  | 7334 |  | 
|  | 7335 | if (!err) { | 
|  | 7336 | nl80211_send_scan_start(rdev, wdev); | 
|  | 7337 | if (wdev->netdev) | 
|  | 7338 | dev_hold(wdev->netdev); | 
|  | 7339 | } else { | 
|  | 7340 | out_free: | 
|  | 7341 | rdev->scan_req = NULL; | 
|  | 7342 | kfree(request); | 
|  | 7343 | } | 
|  | 7344 |  | 
|  | 7345 | unlock: | 
|  | 7346 | return err; | 
|  | 7347 | } | 
|  | 7348 |  | 
|  | 7349 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) | 
|  | 7350 | { | 
|  | 7351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 7352 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 7353 |  | 
|  | 7354 | if (!rdev->ops->abort_scan) | 
|  | 7355 | return -EOPNOTSUPP; | 
|  | 7356 |  | 
|  | 7357 | if (rdev->scan_msg) | 
|  | 7358 | return 0; | 
|  | 7359 |  | 
|  | 7360 | if (!rdev->scan_req) | 
|  | 7361 | return -ENOENT; | 
|  | 7362 |  | 
|  | 7363 | rdev_abort_scan(rdev, wdev); | 
|  | 7364 | return 0; | 
|  | 7365 | } | 
|  | 7366 |  | 
|  | 7367 | static int | 
|  | 7368 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | 
|  | 7369 | struct cfg80211_sched_scan_request *request, | 
|  | 7370 | struct nlattr **attrs) | 
|  | 7371 | { | 
|  | 7372 | int tmp, err, i = 0; | 
|  | 7373 | struct nlattr *attr; | 
|  | 7374 |  | 
|  | 7375 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | 
|  | 7376 | u32 interval; | 
|  | 7377 |  | 
|  | 7378 | /* | 
|  | 7379 | * If scan plans are not specified, | 
|  | 7380 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this | 
|  | 7381 | * case one scan plan will be set with the specified scan | 
|  | 7382 | * interval and infinite number of iterations. | 
|  | 7383 | */ | 
|  | 7384 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | 
|  | 7385 | if (!interval) | 
|  | 7386 | return -EINVAL; | 
|  | 7387 |  | 
|  | 7388 | request->scan_plans[0].interval = | 
|  | 7389 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | 
|  | 7390 | if (!request->scan_plans[0].interval) | 
|  | 7391 | return -EINVAL; | 
|  | 7392 |  | 
|  | 7393 | if (request->scan_plans[0].interval > | 
|  | 7394 | wiphy->max_sched_scan_plan_interval) | 
|  | 7395 | request->scan_plans[0].interval = | 
|  | 7396 | wiphy->max_sched_scan_plan_interval; | 
|  | 7397 |  | 
|  | 7398 | return 0; | 
|  | 7399 | } | 
|  | 7400 |  | 
|  | 7401 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | 
|  | 7402 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | 
|  | 7403 |  | 
|  | 7404 | if (WARN_ON(i >= n_plans)) | 
|  | 7405 | return -EINVAL; | 
|  | 7406 |  | 
|  | 7407 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, | 
|  | 7408 | attr, nl80211_plan_policy, NULL); | 
|  | 7409 | if (err) | 
|  | 7410 | return err; | 
|  | 7411 |  | 
|  | 7412 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | 
|  | 7413 | return -EINVAL; | 
|  | 7414 |  | 
|  | 7415 | request->scan_plans[i].interval = | 
|  | 7416 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | 
|  | 7417 | if (!request->scan_plans[i].interval || | 
|  | 7418 | request->scan_plans[i].interval > | 
|  | 7419 | wiphy->max_sched_scan_plan_interval) | 
|  | 7420 | return -EINVAL; | 
|  | 7421 |  | 
|  | 7422 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | 
|  | 7423 | request->scan_plans[i].iterations = | 
|  | 7424 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | 
|  | 7425 | if (!request->scan_plans[i].iterations || | 
|  | 7426 | (request->scan_plans[i].iterations > | 
|  | 7427 | wiphy->max_sched_scan_plan_iterations)) | 
|  | 7428 | return -EINVAL; | 
|  | 7429 | } else if (i < n_plans - 1) { | 
|  | 7430 | /* | 
|  | 7431 | * All scan plans but the last one must specify | 
|  | 7432 | * a finite number of iterations | 
|  | 7433 | */ | 
|  | 7434 | return -EINVAL; | 
|  | 7435 | } | 
|  | 7436 |  | 
|  | 7437 | i++; | 
|  | 7438 | } | 
|  | 7439 |  | 
|  | 7440 | /* | 
|  | 7441 | * The last scan plan must not specify the number of | 
|  | 7442 | * iterations, it is supposed to run infinitely | 
|  | 7443 | */ | 
|  | 7444 | if (request->scan_plans[n_plans - 1].iterations) | 
|  | 7445 | return  -EINVAL; | 
|  | 7446 |  | 
|  | 7447 | return 0; | 
|  | 7448 | } | 
|  | 7449 |  | 
|  | 7450 | static struct cfg80211_sched_scan_request * | 
|  | 7451 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, | 
|  | 7452 | struct nlattr **attrs, int max_match_sets) | 
|  | 7453 | { | 
|  | 7454 | struct cfg80211_sched_scan_request *request; | 
|  | 7455 | struct nlattr *attr; | 
|  | 7456 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; | 
|  | 7457 | enum nl80211_band band; | 
|  | 7458 | size_t ie_len; | 
|  | 7459 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; | 
|  | 7460 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; | 
|  | 7461 |  | 
|  | 7462 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) | 
|  | 7463 | return ERR_PTR(-EINVAL); | 
|  | 7464 |  | 
|  | 7465 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
|  | 7466 | n_channels = validate_scan_freqs( | 
|  | 7467 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | 
|  | 7468 | if (!n_channels) | 
|  | 7469 | return ERR_PTR(-EINVAL); | 
|  | 7470 | } else { | 
|  | 7471 | n_channels = ieee80211_get_num_supported_channels(wiphy); | 
|  | 7472 | } | 
|  | 7473 |  | 
|  | 7474 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) | 
|  | 7475 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | 
|  | 7476 | tmp) | 
|  | 7477 | n_ssids++; | 
|  | 7478 |  | 
|  | 7479 | if (n_ssids > wiphy->max_sched_scan_ssids) | 
|  | 7480 | return ERR_PTR(-EINVAL); | 
|  | 7481 |  | 
|  | 7482 | /* | 
|  | 7483 | * First, count the number of 'real' matchsets. Due to an issue with | 
|  | 7484 | * the old implementation, matchsets containing only the RSSI attribute | 
|  | 7485 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | 
|  | 7486 | * RSSI for all matchsets, rather than their own matchset for reporting | 
|  | 7487 | * all APs with a strong RSSI. This is needed to be compatible with | 
|  | 7488 | * older userspace that treated a matchset with only the RSSI as the | 
|  | 7489 | * global RSSI for all other matchsets - if there are other matchsets. | 
|  | 7490 | */ | 
|  | 7491 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | 
|  | 7492 | nla_for_each_nested(attr, | 
|  | 7493 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | 
|  | 7494 | tmp) { | 
|  | 7495 | struct nlattr *rssi; | 
|  | 7496 |  | 
|  | 7497 | err = nla_parse_nested(tb, | 
|  | 7498 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | 
|  | 7499 | attr, nl80211_match_policy, | 
|  | 7500 | NULL); | 
|  | 7501 | if (err) | 
|  | 7502 | return ERR_PTR(err); | 
|  | 7503 |  | 
|  | 7504 | /* SSID and BSSID are mutually exclusive */ | 
|  | 7505 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && | 
|  | 7506 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) | 
|  | 7507 | return ERR_PTR(-EINVAL); | 
|  | 7508 |  | 
|  | 7509 | /* add other standalone attributes here */ | 
|  | 7510 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || | 
|  | 7511 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { | 
|  | 7512 | n_match_sets++; | 
|  | 7513 | continue; | 
|  | 7514 | } | 
|  | 7515 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | 
|  | 7516 | if (rssi) | 
|  | 7517 | default_match_rssi = nla_get_s32(rssi); | 
|  | 7518 | } | 
|  | 7519 | } | 
|  | 7520 |  | 
|  | 7521 | /* However, if there's no other matchset, add the RSSI one */ | 
|  | 7522 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | 
|  | 7523 | n_match_sets = 1; | 
|  | 7524 |  | 
|  | 7525 | if (n_match_sets > max_match_sets) | 
|  | 7526 | return ERR_PTR(-EINVAL); | 
|  | 7527 |  | 
|  | 7528 | if (attrs[NL80211_ATTR_IE]) | 
|  | 7529 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | 
|  | 7530 | else | 
|  | 7531 | ie_len = 0; | 
|  | 7532 |  | 
|  | 7533 | if (ie_len > wiphy->max_sched_scan_ie_len) | 
|  | 7534 | return ERR_PTR(-EINVAL); | 
|  | 7535 |  | 
|  | 7536 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | 
|  | 7537 | /* | 
|  | 7538 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | 
|  | 7539 | * each scan plan already specifies its own interval | 
|  | 7540 | */ | 
|  | 7541 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | 
|  | 7542 | return ERR_PTR(-EINVAL); | 
|  | 7543 |  | 
|  | 7544 | nla_for_each_nested(attr, | 
|  | 7545 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | 
|  | 7546 | n_plans++; | 
|  | 7547 | } else { | 
|  | 7548 | /* | 
|  | 7549 | * The scan interval attribute is kept for backward | 
|  | 7550 | * compatibility. If no scan plans are specified and sched scan | 
|  | 7551 | * interval is specified, one scan plan will be set with this | 
|  | 7552 | * scan interval and infinite number of iterations. | 
|  | 7553 | */ | 
|  | 7554 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | 
|  | 7555 | return ERR_PTR(-EINVAL); | 
|  | 7556 |  | 
|  | 7557 | n_plans = 1; | 
|  | 7558 | } | 
|  | 7559 |  | 
|  | 7560 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | 
|  | 7561 | return ERR_PTR(-EINVAL); | 
|  | 7562 |  | 
|  | 7563 | if (!wiphy_ext_feature_isset( | 
|  | 7564 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && | 
|  | 7565 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || | 
|  | 7566 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) | 
|  | 7567 | return ERR_PTR(-EINVAL); | 
|  | 7568 |  | 
|  | 7569 | request = kzalloc(sizeof(*request) | 
|  | 7570 | + sizeof(*request->ssids) * n_ssids | 
|  | 7571 | + sizeof(*request->match_sets) * n_match_sets | 
|  | 7572 | + sizeof(*request->scan_plans) * n_plans | 
|  | 7573 | + sizeof(*request->channels) * n_channels | 
|  | 7574 | + ie_len, GFP_KERNEL); | 
|  | 7575 | if (!request) | 
|  | 7576 | return ERR_PTR(-ENOMEM); | 
|  | 7577 |  | 
|  | 7578 | if (n_ssids) | 
|  | 7579 | request->ssids = (void *)&request->channels[n_channels]; | 
|  | 7580 | request->n_ssids = n_ssids; | 
|  | 7581 | if (ie_len) { | 
|  | 7582 | if (n_ssids) | 
|  | 7583 | request->ie = (void *)(request->ssids + n_ssids); | 
|  | 7584 | else | 
|  | 7585 | request->ie = (void *)(request->channels + n_channels); | 
|  | 7586 | } | 
|  | 7587 |  | 
|  | 7588 | if (n_match_sets) { | 
|  | 7589 | if (request->ie) | 
|  | 7590 | request->match_sets = (void *)(request->ie + ie_len); | 
|  | 7591 | else if (n_ssids) | 
|  | 7592 | request->match_sets = | 
|  | 7593 | (void *)(request->ssids + n_ssids); | 
|  | 7594 | else | 
|  | 7595 | request->match_sets = | 
|  | 7596 | (void *)(request->channels + n_channels); | 
|  | 7597 | } | 
|  | 7598 | request->n_match_sets = n_match_sets; | 
|  | 7599 |  | 
|  | 7600 | if (n_match_sets) | 
|  | 7601 | request->scan_plans = (void *)(request->match_sets + | 
|  | 7602 | n_match_sets); | 
|  | 7603 | else if (request->ie) | 
|  | 7604 | request->scan_plans = (void *)(request->ie + ie_len); | 
|  | 7605 | else if (n_ssids) | 
|  | 7606 | request->scan_plans = (void *)(request->ssids + n_ssids); | 
|  | 7607 | else | 
|  | 7608 | request->scan_plans = (void *)(request->channels + n_channels); | 
|  | 7609 |  | 
|  | 7610 | request->n_scan_plans = n_plans; | 
|  | 7611 |  | 
|  | 7612 | i = 0; | 
|  | 7613 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
|  | 7614 | /* user specified, bail out if channel not found */ | 
|  | 7615 | nla_for_each_nested(attr, | 
|  | 7616 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], | 
|  | 7617 | tmp) { | 
|  | 7618 | struct ieee80211_channel *chan; | 
|  | 7619 |  | 
|  | 7620 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | 
|  | 7621 |  | 
|  | 7622 | if (!chan) { | 
|  | 7623 | err = -EINVAL; | 
|  | 7624 | goto out_free; | 
|  | 7625 | } | 
|  | 7626 |  | 
|  | 7627 | /* ignore disabled channels */ | 
|  | 7628 | if (chan->flags & IEEE80211_CHAN_DISABLED) | 
|  | 7629 | continue; | 
|  | 7630 |  | 
|  | 7631 | request->channels[i] = chan; | 
|  | 7632 | i++; | 
|  | 7633 | } | 
|  | 7634 | } else { | 
|  | 7635 | /* all channels */ | 
|  | 7636 | for (band = 0; band < NUM_NL80211_BANDS; band++) { | 
|  | 7637 | int j; | 
|  | 7638 |  | 
|  | 7639 | if (!wiphy->bands[band]) | 
|  | 7640 | continue; | 
|  | 7641 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | 
|  | 7642 | struct ieee80211_channel *chan; | 
|  | 7643 |  | 
|  | 7644 | chan = &wiphy->bands[band]->channels[j]; | 
|  | 7645 |  | 
|  | 7646 | if (chan->flags & IEEE80211_CHAN_DISABLED) | 
|  | 7647 | continue; | 
|  | 7648 |  | 
|  | 7649 | request->channels[i] = chan; | 
|  | 7650 | i++; | 
|  | 7651 | } | 
|  | 7652 | } | 
|  | 7653 | } | 
|  | 7654 |  | 
|  | 7655 | if (!i) { | 
|  | 7656 | err = -EINVAL; | 
|  | 7657 | goto out_free; | 
|  | 7658 | } | 
|  | 7659 |  | 
|  | 7660 | request->n_channels = i; | 
|  | 7661 |  | 
|  | 7662 | i = 0; | 
|  | 7663 | if (n_ssids) { | 
|  | 7664 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | 
|  | 7665 | tmp) { | 
|  | 7666 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { | 
|  | 7667 | err = -EINVAL; | 
|  | 7668 | goto out_free; | 
|  | 7669 | } | 
|  | 7670 | request->ssids[i].ssid_len = nla_len(attr); | 
|  | 7671 | memcpy(request->ssids[i].ssid, nla_data(attr), | 
|  | 7672 | nla_len(attr)); | 
|  | 7673 | i++; | 
|  | 7674 | } | 
|  | 7675 | } | 
|  | 7676 |  | 
|  | 7677 | i = 0; | 
|  | 7678 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | 
|  | 7679 | nla_for_each_nested(attr, | 
|  | 7680 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | 
|  | 7681 | tmp) { | 
|  | 7682 | struct nlattr *ssid, *bssid, *rssi; | 
|  | 7683 |  | 
|  | 7684 | err = nla_parse_nested(tb, | 
|  | 7685 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | 
|  | 7686 | attr, nl80211_match_policy, | 
|  | 7687 | NULL); | 
|  | 7688 | if (err) | 
|  | 7689 | goto out_free; | 
|  | 7690 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; | 
|  | 7691 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; | 
|  | 7692 | if (ssid || bssid) { | 
|  | 7693 | if (WARN_ON(i >= n_match_sets)) { | 
|  | 7694 | /* this indicates a programming error, | 
|  | 7695 | * the loop above should have verified | 
|  | 7696 | * things properly | 
|  | 7697 | */ | 
|  | 7698 | err = -EINVAL; | 
|  | 7699 | goto out_free; | 
|  | 7700 | } | 
|  | 7701 |  | 
|  | 7702 | if (ssid) { | 
|  | 7703 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | 
|  | 7704 | err = -EINVAL; | 
|  | 7705 | goto out_free; | 
|  | 7706 | } | 
|  | 7707 | memcpy(request->match_sets[i].ssid.ssid, | 
|  | 7708 | nla_data(ssid), nla_len(ssid)); | 
|  | 7709 | request->match_sets[i].ssid.ssid_len = | 
|  | 7710 | nla_len(ssid); | 
|  | 7711 | } | 
|  | 7712 | if (bssid) { | 
|  | 7713 | if (nla_len(bssid) != ETH_ALEN) { | 
|  | 7714 | err = -EINVAL; | 
|  | 7715 | goto out_free; | 
|  | 7716 | } | 
|  | 7717 | memcpy(request->match_sets[i].bssid, | 
|  | 7718 | nla_data(bssid), ETH_ALEN); | 
|  | 7719 | } | 
|  | 7720 |  | 
|  | 7721 | /* special attribute - old implementation w/a */ | 
|  | 7722 | request->match_sets[i].rssi_thold = | 
|  | 7723 | default_match_rssi; | 
|  | 7724 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | 
|  | 7725 | if (rssi) | 
|  | 7726 | request->match_sets[i].rssi_thold = | 
|  | 7727 | nla_get_s32(rssi); | 
|  | 7728 | } | 
|  | 7729 | i++; | 
|  | 7730 | } | 
|  | 7731 |  | 
|  | 7732 | /* there was no other matchset, so the RSSI one is alone */ | 
|  | 7733 | if (i == 0 && n_match_sets) | 
|  | 7734 | request->match_sets[0].rssi_thold = default_match_rssi; | 
|  | 7735 |  | 
|  | 7736 | request->min_rssi_thold = INT_MAX; | 
|  | 7737 | for (i = 0; i < n_match_sets; i++) | 
|  | 7738 | request->min_rssi_thold = | 
|  | 7739 | min(request->match_sets[i].rssi_thold, | 
|  | 7740 | request->min_rssi_thold); | 
|  | 7741 | } else { | 
|  | 7742 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | 
|  | 7743 | } | 
|  | 7744 |  | 
|  | 7745 | if (ie_len) { | 
|  | 7746 | request->ie_len = ie_len; | 
|  | 7747 | memcpy((void *)request->ie, | 
|  | 7748 | nla_data(attrs[NL80211_ATTR_IE]), | 
|  | 7749 | request->ie_len); | 
|  | 7750 | } | 
|  | 7751 |  | 
|  | 7752 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); | 
|  | 7753 | if (err) | 
|  | 7754 | goto out_free; | 
|  | 7755 |  | 
|  | 7756 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) | 
|  | 7757 | request->delay = | 
|  | 7758 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | 
|  | 7759 |  | 
|  | 7760 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { | 
|  | 7761 | request->relative_rssi = nla_get_s8( | 
|  | 7762 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); | 
|  | 7763 | request->relative_rssi_set = true; | 
|  | 7764 | } | 
|  | 7765 |  | 
|  | 7766 | if (request->relative_rssi_set && | 
|  | 7767 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { | 
|  | 7768 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; | 
|  | 7769 |  | 
|  | 7770 | rssi_adjust = nla_data( | 
|  | 7771 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); | 
|  | 7772 | request->rssi_adjust.band = rssi_adjust->band; | 
|  | 7773 | request->rssi_adjust.delta = rssi_adjust->delta; | 
|  | 7774 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { | 
|  | 7775 | err = -EINVAL; | 
|  | 7776 | goto out_free; | 
|  | 7777 | } | 
|  | 7778 | } | 
|  | 7779 |  | 
|  | 7780 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); | 
|  | 7781 | if (err) | 
|  | 7782 | goto out_free; | 
|  | 7783 |  | 
|  | 7784 | request->scan_start = jiffies; | 
|  | 7785 |  | 
|  | 7786 | return request; | 
|  | 7787 |  | 
|  | 7788 | out_free: | 
|  | 7789 | kfree(request); | 
|  | 7790 | return ERR_PTR(err); | 
|  | 7791 | } | 
|  | 7792 |  | 
|  | 7793 | static int nl80211_start_sched_scan(struct sk_buff *skb, | 
|  | 7794 | struct genl_info *info) | 
|  | 7795 | { | 
|  | 7796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 7797 | struct net_device *dev = info->user_ptr[1]; | 
|  | 7798 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 7799 | struct cfg80211_sched_scan_request *sched_scan_req; | 
|  | 7800 | bool want_multi; | 
|  | 7801 | int err; | 
|  | 7802 |  | 
|  | 7803 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) | 
|  | 7804 | return -EOPNOTSUPP; | 
|  | 7805 |  | 
|  | 7806 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; | 
|  | 7807 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); | 
|  | 7808 | if (err) | 
|  | 7809 | return err; | 
|  | 7810 |  | 
|  | 7811 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, | 
|  | 7812 | info->attrs, | 
|  | 7813 | rdev->wiphy.max_match_sets); | 
|  | 7814 |  | 
|  | 7815 | err = PTR_ERR_OR_ZERO(sched_scan_req); | 
|  | 7816 | if (err) | 
|  | 7817 | goto out_err; | 
|  | 7818 |  | 
|  | 7819 | /* leave request id zero for legacy request | 
|  | 7820 | * or if driver does not support multi-scheduled scan | 
|  | 7821 | */ | 
|  | 7822 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { | 
|  | 7823 | while (!sched_scan_req->reqid) | 
|  | 7824 | sched_scan_req->reqid = rdev->wiphy.cookie_counter++; | 
|  | 7825 | } | 
|  | 7826 |  | 
|  | 7827 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); | 
|  | 7828 | if (err) | 
|  | 7829 | goto out_free; | 
|  | 7830 |  | 
|  | 7831 | sched_scan_req->dev = dev; | 
|  | 7832 | sched_scan_req->wiphy = &rdev->wiphy; | 
|  | 7833 |  | 
|  | 7834 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
|  | 7835 | sched_scan_req->owner_nlportid = info->snd_portid; | 
|  | 7836 |  | 
|  | 7837 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); | 
|  | 7838 |  | 
|  | 7839 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); | 
|  | 7840 | return 0; | 
|  | 7841 |  | 
|  | 7842 | out_free: | 
|  | 7843 | kfree(sched_scan_req); | 
|  | 7844 | out_err: | 
|  | 7845 | return err; | 
|  | 7846 | } | 
|  | 7847 |  | 
|  | 7848 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | 
|  | 7849 | struct genl_info *info) | 
|  | 7850 | { | 
|  | 7851 | struct cfg80211_sched_scan_request *req; | 
|  | 7852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 7853 | u64 cookie; | 
|  | 7854 |  | 
|  | 7855 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) | 
|  | 7856 | return -EOPNOTSUPP; | 
|  | 7857 |  | 
|  | 7858 | if (info->attrs[NL80211_ATTR_COOKIE]) { | 
|  | 7859 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 
|  | 7860 | return __cfg80211_stop_sched_scan(rdev, cookie, false); | 
|  | 7861 | } | 
|  | 7862 |  | 
|  | 7863 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, | 
|  | 7864 | struct cfg80211_sched_scan_request, | 
|  | 7865 | list); | 
|  | 7866 | if (!req || req->reqid || | 
|  | 7867 | (req->owner_nlportid && | 
|  | 7868 | req->owner_nlportid != info->snd_portid)) | 
|  | 7869 | return -ENOENT; | 
|  | 7870 |  | 
|  | 7871 | return cfg80211_stop_sched_scan_req(rdev, req, false); | 
|  | 7872 | } | 
|  | 7873 |  | 
|  | 7874 | static int nl80211_start_radar_detection(struct sk_buff *skb, | 
|  | 7875 | struct genl_info *info) | 
|  | 7876 | { | 
|  | 7877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 7878 | struct net_device *dev = info->user_ptr[1]; | 
|  | 7879 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 7880 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 7881 | struct cfg80211_chan_def chandef; | 
|  | 7882 | enum nl80211_dfs_regions dfs_region; | 
|  | 7883 | unsigned int cac_time_ms; | 
|  | 7884 | int err; | 
|  | 7885 |  | 
|  | 7886 | dfs_region = reg_get_dfs_region(wiphy); | 
|  | 7887 | if (dfs_region == NL80211_DFS_UNSET) | 
|  | 7888 | return -EINVAL; | 
|  | 7889 |  | 
|  | 7890 | err = nl80211_parse_chandef(rdev, info, &chandef); | 
|  | 7891 | if (err) | 
|  | 7892 | return err; | 
|  | 7893 |  | 
|  | 7894 | if (netif_carrier_ok(dev)) | 
|  | 7895 | return -EBUSY; | 
|  | 7896 |  | 
|  | 7897 | if (wdev->cac_started) | 
|  | 7898 | return -EBUSY; | 
|  | 7899 |  | 
|  | 7900 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); | 
|  | 7901 | if (err < 0) | 
|  | 7902 | return err; | 
|  | 7903 |  | 
|  | 7904 | if (err == 0) | 
|  | 7905 | return -EINVAL; | 
|  | 7906 |  | 
|  | 7907 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) | 
|  | 7908 | return -EINVAL; | 
|  | 7909 |  | 
|  | 7910 | /* CAC start is offloaded to HW and can't be started manually */ | 
|  | 7911 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) | 
|  | 7912 | return -EOPNOTSUPP; | 
|  | 7913 |  | 
|  | 7914 | if (!rdev->ops->start_radar_detection) | 
|  | 7915 | return -EOPNOTSUPP; | 
|  | 7916 |  | 
|  | 7917 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); | 
|  | 7918 | if (WARN_ON(!cac_time_ms)) | 
|  | 7919 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | 
|  | 7920 |  | 
|  | 7921 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); | 
|  | 7922 | if (!err) { | 
|  | 7923 | wdev->chandef = chandef; | 
|  | 7924 | wdev->cac_started = true; | 
|  | 7925 | wdev->cac_start_time = jiffies; | 
|  | 7926 | wdev->cac_time_ms = cac_time_ms; | 
|  | 7927 | } | 
|  | 7928 | return err; | 
|  | 7929 | } | 
|  | 7930 |  | 
|  | 7931 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) | 
|  | 7932 | { | 
|  | 7933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 7934 | struct net_device *dev = info->user_ptr[1]; | 
|  | 7935 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 7936 | struct cfg80211_csa_settings params; | 
|  | 7937 | /* csa_attrs is defined static to avoid waste of stack size - this | 
|  | 7938 | * function is called under RTNL lock, so this should not be a problem. | 
|  | 7939 | */ | 
|  | 7940 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | 
|  | 7941 | int err; | 
|  | 7942 | bool need_new_beacon = false; | 
|  | 7943 | bool need_handle_dfs_flag = true; | 
|  | 7944 | int len, i; | 
|  | 7945 | u32 cs_count; | 
|  | 7946 |  | 
|  | 7947 | if (!rdev->ops->channel_switch || | 
|  | 7948 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | 
|  | 7949 | return -EOPNOTSUPP; | 
|  | 7950 |  | 
|  | 7951 | switch (dev->ieee80211_ptr->iftype) { | 
|  | 7952 | case NL80211_IFTYPE_AP: | 
|  | 7953 | case NL80211_IFTYPE_P2P_GO: | 
|  | 7954 | need_new_beacon = true; | 
|  | 7955 | /* For all modes except AP the handle_dfs flag needs to be | 
|  | 7956 | * supplied to tell the kernel that userspace will handle radar | 
|  | 7957 | * events when they happen. Otherwise a switch to a channel | 
|  | 7958 | * requiring DFS will be rejected. | 
|  | 7959 | */ | 
|  | 7960 | need_handle_dfs_flag = false; | 
|  | 7961 |  | 
|  | 7962 | /* useless if AP is not running */ | 
|  | 7963 | if (!wdev->beacon_interval) | 
|  | 7964 | return -ENOTCONN; | 
|  | 7965 | break; | 
|  | 7966 | case NL80211_IFTYPE_ADHOC: | 
|  | 7967 | if (!wdev->ssid_len) | 
|  | 7968 | return -ENOTCONN; | 
|  | 7969 | break; | 
|  | 7970 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 7971 | if (!wdev->mesh_id_len) | 
|  | 7972 | return -ENOTCONN; | 
|  | 7973 | break; | 
|  | 7974 | default: | 
|  | 7975 | return -EOPNOTSUPP; | 
|  | 7976 | } | 
|  | 7977 |  | 
|  | 7978 | memset(¶ms, 0, sizeof(params)); | 
|  | 7979 |  | 
|  | 7980 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | 
|  | 7981 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | 
|  | 7982 | return -EINVAL; | 
|  | 7983 |  | 
|  | 7984 | /* only important for AP, IBSS and mesh create IEs internally */ | 
|  | 7985 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) | 
|  | 7986 | return -EINVAL; | 
|  | 7987 |  | 
|  | 7988 | /* Even though the attribute is u32, the specification says | 
|  | 7989 | * u8, so let's make sure we don't overflow. | 
|  | 7990 | */ | 
|  | 7991 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | 
|  | 7992 | if (cs_count > 255) | 
|  | 7993 | return -EINVAL; | 
|  | 7994 |  | 
|  | 7995 | params.count = cs_count; | 
|  | 7996 |  | 
|  | 7997 | if (!need_new_beacon) | 
|  | 7998 | goto skip_beacons; | 
|  | 7999 |  | 
|  | 8000 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); | 
|  | 8001 | if (err) | 
|  | 8002 | return err; | 
|  | 8003 |  | 
|  | 8004 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | 
|  | 8005 | info->attrs[NL80211_ATTR_CSA_IES], | 
|  | 8006 | nl80211_policy, info->extack); | 
|  | 8007 | if (err) | 
|  | 8008 | return err; | 
|  | 8009 |  | 
|  | 8010 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | 
|  | 8011 | if (err) | 
|  | 8012 | return err; | 
|  | 8013 |  | 
|  | 8014 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | 
|  | 8015 | return -EINVAL; | 
|  | 8016 |  | 
|  | 8017 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | 
|  | 8018 | if (!len || (len % sizeof(u16))) | 
|  | 8019 | return -EINVAL; | 
|  | 8020 |  | 
|  | 8021 | params.n_counter_offsets_beacon = len / sizeof(u16); | 
|  | 8022 | if (rdev->wiphy.max_num_csa_counters && | 
|  | 8023 | (params.n_counter_offsets_beacon > | 
|  | 8024 | rdev->wiphy.max_num_csa_counters)) | 
|  | 8025 | return -EINVAL; | 
|  | 8026 |  | 
|  | 8027 | params.counter_offsets_beacon = | 
|  | 8028 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | 
|  | 8029 |  | 
|  | 8030 | /* sanity checks - counters should fit and be the same */ | 
|  | 8031 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | 
|  | 8032 | u16 offset = params.counter_offsets_beacon[i]; | 
|  | 8033 |  | 
|  | 8034 | if (offset >= params.beacon_csa.tail_len) | 
|  | 8035 | return -EINVAL; | 
|  | 8036 |  | 
|  | 8037 | if (params.beacon_csa.tail[offset] != params.count) | 
|  | 8038 | return -EINVAL; | 
|  | 8039 | } | 
|  | 8040 |  | 
|  | 8041 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | 
|  | 8042 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | 
|  | 8043 | if (!len || (len % sizeof(u16))) | 
|  | 8044 | return -EINVAL; | 
|  | 8045 |  | 
|  | 8046 | params.n_counter_offsets_presp = len / sizeof(u16); | 
|  | 8047 | if (rdev->wiphy.max_num_csa_counters && | 
|  | 8048 | (params.n_counter_offsets_presp > | 
|  | 8049 | rdev->wiphy.max_num_csa_counters)) | 
|  | 8050 | return -EINVAL; | 
|  | 8051 |  | 
|  | 8052 | params.counter_offsets_presp = | 
|  | 8053 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | 
|  | 8054 |  | 
|  | 8055 | /* sanity checks - counters should fit and be the same */ | 
|  | 8056 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | 
|  | 8057 | u16 offset = params.counter_offsets_presp[i]; | 
|  | 8058 |  | 
|  | 8059 | if (offset >= params.beacon_csa.probe_resp_len) | 
|  | 8060 | return -EINVAL; | 
|  | 8061 |  | 
|  | 8062 | if (params.beacon_csa.probe_resp[offset] != | 
|  | 8063 | params.count) | 
|  | 8064 | return -EINVAL; | 
|  | 8065 | } | 
|  | 8066 | } | 
|  | 8067 |  | 
|  | 8068 | skip_beacons: | 
|  | 8069 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); | 
|  | 8070 | if (err) | 
|  | 8071 | return err; | 
|  | 8072 |  | 
|  | 8073 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, | 
|  | 8074 | wdev->iftype)) | 
|  | 8075 | return -EINVAL; | 
|  | 8076 |  | 
|  | 8077 | err = cfg80211_chandef_dfs_required(wdev->wiphy, | 
|  | 8078 | ¶ms.chandef, | 
|  | 8079 | wdev->iftype); | 
|  | 8080 | if (err < 0) | 
|  | 8081 | return err; | 
|  | 8082 |  | 
|  | 8083 | if (err > 0) { | 
|  | 8084 | params.radar_required = true; | 
|  | 8085 | if (need_handle_dfs_flag && | 
|  | 8086 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { | 
|  | 8087 | return -EINVAL; | 
|  | 8088 | } | 
|  | 8089 | } | 
|  | 8090 |  | 
|  | 8091 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | 
|  | 8092 | params.block_tx = true; | 
|  | 8093 |  | 
|  | 8094 | wdev_lock(wdev); | 
|  | 8095 | err = rdev_channel_switch(rdev, dev, ¶ms); | 
|  | 8096 | wdev_unlock(wdev); | 
|  | 8097 |  | 
|  | 8098 | return err; | 
|  | 8099 | } | 
|  | 8100 |  | 
|  | 8101 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, | 
|  | 8102 | u32 seq, int flags, | 
|  | 8103 | struct cfg80211_registered_device *rdev, | 
|  | 8104 | struct wireless_dev *wdev, | 
|  | 8105 | struct cfg80211_internal_bss *intbss) | 
|  | 8106 | { | 
|  | 8107 | struct cfg80211_bss *res = &intbss->pub; | 
|  | 8108 | const struct cfg80211_bss_ies *ies; | 
|  | 8109 | void *hdr; | 
|  | 8110 | struct nlattr *bss; | 
|  | 8111 |  | 
|  | 8112 | ASSERT_WDEV_LOCK(wdev); | 
|  | 8113 |  | 
|  | 8114 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | 
|  | 8115 | NL80211_CMD_NEW_SCAN_RESULTS); | 
|  | 8116 | if (!hdr) | 
|  | 8117 | return -1; | 
|  | 8118 |  | 
|  | 8119 | genl_dump_check_consistent(cb, hdr); | 
|  | 8120 |  | 
|  | 8121 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) | 
|  | 8122 | goto nla_put_failure; | 
|  | 8123 | if (wdev->netdev && | 
|  | 8124 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | 
|  | 8125 | goto nla_put_failure; | 
|  | 8126 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 8127 | NL80211_ATTR_PAD)) | 
|  | 8128 | goto nla_put_failure; | 
|  | 8129 |  | 
|  | 8130 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | 
|  | 8131 | if (!bss) | 
|  | 8132 | goto nla_put_failure; | 
|  | 8133 | if ((!is_zero_ether_addr(res->bssid) && | 
|  | 8134 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) | 
|  | 8135 | goto nla_put_failure; | 
|  | 8136 |  | 
|  | 8137 | rcu_read_lock(); | 
|  | 8138 | /* indicate whether we have probe response data or not */ | 
|  | 8139 | if (rcu_access_pointer(res->proberesp_ies) && | 
|  | 8140 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | 
|  | 8141 | goto fail_unlock_rcu; | 
|  | 8142 |  | 
|  | 8143 | /* this pointer prefers to be pointed to probe response data | 
|  | 8144 | * but is always valid | 
|  | 8145 | */ | 
|  | 8146 | ies = rcu_dereference(res->ies); | 
|  | 8147 | if (ies) { | 
|  | 8148 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, | 
|  | 8149 | NL80211_BSS_PAD)) | 
|  | 8150 | goto fail_unlock_rcu; | 
|  | 8151 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | 
|  | 8152 | ies->len, ies->data)) | 
|  | 8153 | goto fail_unlock_rcu; | 
|  | 8154 | } | 
|  | 8155 |  | 
|  | 8156 | /* and this pointer is always (unless driver didn't know) beacon data */ | 
|  | 8157 | ies = rcu_dereference(res->beacon_ies); | 
|  | 8158 | if (ies && ies->from_beacon) { | 
|  | 8159 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, | 
|  | 8160 | NL80211_BSS_PAD)) | 
|  | 8161 | goto fail_unlock_rcu; | 
|  | 8162 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | 
|  | 8163 | ies->len, ies->data)) | 
|  | 8164 | goto fail_unlock_rcu; | 
|  | 8165 | } | 
|  | 8166 | rcu_read_unlock(); | 
|  | 8167 |  | 
|  | 8168 | if (res->beacon_interval && | 
|  | 8169 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | 
|  | 8170 | goto nla_put_failure; | 
|  | 8171 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | 
|  | 8172 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | 
|  | 8173 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || | 
|  | 8174 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | 
|  | 8175 | jiffies_to_msecs(jiffies - intbss->ts))) | 
|  | 8176 | goto nla_put_failure; | 
|  | 8177 |  | 
|  | 8178 | if (intbss->parent_tsf && | 
|  | 8179 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | 
|  | 8180 | intbss->parent_tsf, NL80211_BSS_PAD) || | 
|  | 8181 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | 
|  | 8182 | intbss->parent_bssid))) | 
|  | 8183 | goto nla_put_failure; | 
|  | 8184 |  | 
|  | 8185 | if (intbss->ts_boottime && | 
|  | 8186 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, | 
|  | 8187 | intbss->ts_boottime, NL80211_BSS_PAD)) | 
|  | 8188 | goto nla_put_failure; | 
|  | 8189 |  | 
|  | 8190 | if (!nl80211_put_signal(msg, intbss->pub.chains, | 
|  | 8191 | intbss->pub.chain_signal, | 
|  | 8192 | NL80211_BSS_CHAIN_SIGNAL)) | 
|  | 8193 | goto nla_put_failure; | 
|  | 8194 |  | 
|  | 8195 | switch (rdev->wiphy.signal_type) { | 
|  | 8196 | case CFG80211_SIGNAL_TYPE_MBM: | 
|  | 8197 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) | 
|  | 8198 | goto nla_put_failure; | 
|  | 8199 | break; | 
|  | 8200 | case CFG80211_SIGNAL_TYPE_UNSPEC: | 
|  | 8201 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) | 
|  | 8202 | goto nla_put_failure; | 
|  | 8203 | break; | 
|  | 8204 | default: | 
|  | 8205 | break; | 
|  | 8206 | } | 
|  | 8207 |  | 
|  | 8208 | switch (wdev->iftype) { | 
|  | 8209 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 8210 | case NL80211_IFTYPE_STATION: | 
|  | 8211 | if (intbss == wdev->current_bss && | 
|  | 8212 | nla_put_u32(msg, NL80211_BSS_STATUS, | 
|  | 8213 | NL80211_BSS_STATUS_ASSOCIATED)) | 
|  | 8214 | goto nla_put_failure; | 
|  | 8215 | break; | 
|  | 8216 | case NL80211_IFTYPE_ADHOC: | 
|  | 8217 | if (intbss == wdev->current_bss && | 
|  | 8218 | nla_put_u32(msg, NL80211_BSS_STATUS, | 
|  | 8219 | NL80211_BSS_STATUS_IBSS_JOINED)) | 
|  | 8220 | goto nla_put_failure; | 
|  | 8221 | break; | 
|  | 8222 | default: | 
|  | 8223 | break; | 
|  | 8224 | } | 
|  | 8225 |  | 
|  | 8226 | nla_nest_end(msg, bss); | 
|  | 8227 |  | 
|  | 8228 | genlmsg_end(msg, hdr); | 
|  | 8229 | return 0; | 
|  | 8230 |  | 
|  | 8231 | fail_unlock_rcu: | 
|  | 8232 | rcu_read_unlock(); | 
|  | 8233 | nla_put_failure: | 
|  | 8234 | genlmsg_cancel(msg, hdr); | 
|  | 8235 | return -EMSGSIZE; | 
|  | 8236 | } | 
|  | 8237 |  | 
|  | 8238 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) | 
|  | 8239 | { | 
|  | 8240 | struct cfg80211_registered_device *rdev; | 
|  | 8241 | struct cfg80211_internal_bss *scan; | 
|  | 8242 | struct wireless_dev *wdev; | 
|  | 8243 | int start = cb->args[2], idx = 0; | 
|  | 8244 | int err; | 
|  | 8245 |  | 
|  | 8246 | rtnl_lock(); | 
|  | 8247 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
|  | 8248 | if (err) { | 
|  | 8249 | rtnl_unlock(); | 
|  | 8250 | return err; | 
|  | 8251 | } | 
|  | 8252 |  | 
|  | 8253 | wdev_lock(wdev); | 
|  | 8254 | spin_lock_bh(&rdev->bss_lock); | 
|  | 8255 |  | 
|  | 8256 | /* | 
|  | 8257 | * dump_scan will be called multiple times to break up the scan results | 
|  | 8258 | * into multiple messages.  It is unlikely that any more bss-es will be | 
|  | 8259 | * expired after the first call, so only call only call this on the | 
|  | 8260 | * first dump_scan invocation. | 
|  | 8261 | */ | 
|  | 8262 | if (start == 0) | 
|  | 8263 | cfg80211_bss_expire(rdev); | 
|  | 8264 |  | 
|  | 8265 | cb->seq = rdev->bss_generation; | 
|  | 8266 |  | 
|  | 8267 | list_for_each_entry(scan, &rdev->bss_list, list) { | 
|  | 8268 | if (++idx <= start) | 
|  | 8269 | continue; | 
|  | 8270 | if (nl80211_send_bss(skb, cb, | 
|  | 8271 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 8272 | rdev, wdev, scan) < 0) { | 
|  | 8273 | idx--; | 
|  | 8274 | break; | 
|  | 8275 | } | 
|  | 8276 | } | 
|  | 8277 |  | 
|  | 8278 | spin_unlock_bh(&rdev->bss_lock); | 
|  | 8279 | wdev_unlock(wdev); | 
|  | 8280 |  | 
|  | 8281 | cb->args[2] = idx; | 
|  | 8282 | rtnl_unlock(); | 
|  | 8283 |  | 
|  | 8284 | return skb->len; | 
|  | 8285 | } | 
|  | 8286 |  | 
|  | 8287 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, | 
|  | 8288 | int flags, struct net_device *dev, | 
|  | 8289 | bool allow_radio_stats, | 
|  | 8290 | struct survey_info *survey) | 
|  | 8291 | { | 
|  | 8292 | void *hdr; | 
|  | 8293 | struct nlattr *infoattr; | 
|  | 8294 |  | 
|  | 8295 | /* skip radio stats if userspace didn't request them */ | 
|  | 8296 | if (!survey->channel && !allow_radio_stats) | 
|  | 8297 | return 0; | 
|  | 8298 |  | 
|  | 8299 | hdr = nl80211hdr_put(msg, portid, seq, flags, | 
|  | 8300 | NL80211_CMD_NEW_SURVEY_RESULTS); | 
|  | 8301 | if (!hdr) | 
|  | 8302 | return -ENOMEM; | 
|  | 8303 |  | 
|  | 8304 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | 
|  | 8305 | goto nla_put_failure; | 
|  | 8306 |  | 
|  | 8307 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | 
|  | 8308 | if (!infoattr) | 
|  | 8309 | goto nla_put_failure; | 
|  | 8310 |  | 
|  | 8311 | if (survey->channel && | 
|  | 8312 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | 
|  | 8313 | survey->channel->center_freq)) | 
|  | 8314 | goto nla_put_failure; | 
|  | 8315 |  | 
|  | 8316 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | 
|  | 8317 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | 
|  | 8318 | goto nla_put_failure; | 
|  | 8319 | if ((survey->filled & SURVEY_INFO_IN_USE) && | 
|  | 8320 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | 
|  | 8321 | goto nla_put_failure; | 
|  | 8322 | if ((survey->filled & SURVEY_INFO_TIME) && | 
|  | 8323 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, | 
|  | 8324 | survey->time, NL80211_SURVEY_INFO_PAD)) | 
|  | 8325 | goto nla_put_failure; | 
|  | 8326 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && | 
|  | 8327 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, | 
|  | 8328 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | 
|  | 8329 | goto nla_put_failure; | 
|  | 8330 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && | 
|  | 8331 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | 
|  | 8332 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | 
|  | 8333 | goto nla_put_failure; | 
|  | 8334 | if ((survey->filled & SURVEY_INFO_TIME_RX) && | 
|  | 8335 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, | 
|  | 8336 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | 
|  | 8337 | goto nla_put_failure; | 
|  | 8338 | if ((survey->filled & SURVEY_INFO_TIME_TX) && | 
|  | 8339 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, | 
|  | 8340 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | 
|  | 8341 | goto nla_put_failure; | 
|  | 8342 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && | 
|  | 8343 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, | 
|  | 8344 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | 
|  | 8345 | goto nla_put_failure; | 
|  | 8346 |  | 
|  | 8347 | nla_nest_end(msg, infoattr); | 
|  | 8348 |  | 
|  | 8349 | genlmsg_end(msg, hdr); | 
|  | 8350 | return 0; | 
|  | 8351 |  | 
|  | 8352 | nla_put_failure: | 
|  | 8353 | genlmsg_cancel(msg, hdr); | 
|  | 8354 | return -EMSGSIZE; | 
|  | 8355 | } | 
|  | 8356 |  | 
|  | 8357 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) | 
|  | 8358 | { | 
|  | 8359 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); | 
|  | 8360 | struct survey_info survey; | 
|  | 8361 | struct cfg80211_registered_device *rdev; | 
|  | 8362 | struct wireless_dev *wdev; | 
|  | 8363 | int survey_idx = cb->args[2]; | 
|  | 8364 | int res; | 
|  | 8365 | bool radio_stats; | 
|  | 8366 |  | 
|  | 8367 | rtnl_lock(); | 
|  | 8368 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
|  | 8369 | if (res) | 
|  | 8370 | goto out_err; | 
|  | 8371 |  | 
|  | 8372 | /* prepare_wdev_dump parsed the attributes */ | 
|  | 8373 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | 
|  | 8374 |  | 
|  | 8375 | if (!wdev->netdev) { | 
|  | 8376 | res = -EINVAL; | 
|  | 8377 | goto out_err; | 
|  | 8378 | } | 
|  | 8379 |  | 
|  | 8380 | if (!rdev->ops->dump_survey) { | 
|  | 8381 | res = -EOPNOTSUPP; | 
|  | 8382 | goto out_err; | 
|  | 8383 | } | 
|  | 8384 |  | 
|  | 8385 | while (1) { | 
|  | 8386 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); | 
|  | 8387 | if (res == -ENOENT) | 
|  | 8388 | break; | 
|  | 8389 | if (res) | 
|  | 8390 | goto out_err; | 
|  | 8391 |  | 
|  | 8392 | /* don't send disabled channels, but do send non-channel data */ | 
|  | 8393 | if (survey.channel && | 
|  | 8394 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | 
|  | 8395 | survey_idx++; | 
|  | 8396 | continue; | 
|  | 8397 | } | 
|  | 8398 |  | 
|  | 8399 | if (nl80211_send_survey(skb, | 
|  | 8400 | NETLINK_CB(cb->skb).portid, | 
|  | 8401 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 8402 | wdev->netdev, radio_stats, &survey) < 0) | 
|  | 8403 | goto out; | 
|  | 8404 | survey_idx++; | 
|  | 8405 | } | 
|  | 8406 |  | 
|  | 8407 | out: | 
|  | 8408 | cb->args[2] = survey_idx; | 
|  | 8409 | res = skb->len; | 
|  | 8410 | out_err: | 
|  | 8411 | rtnl_unlock(); | 
|  | 8412 | return res; | 
|  | 8413 | } | 
|  | 8414 |  | 
|  | 8415 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | 
|  | 8416 | { | 
|  | 8417 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | 
|  | 8418 | NL80211_WPA_VERSION_2)); | 
|  | 8419 | } | 
|  | 8420 |  | 
|  | 8421 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) | 
|  | 8422 | { | 
|  | 8423 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 8424 | struct net_device *dev = info->user_ptr[1]; | 
|  | 8425 | struct ieee80211_channel *chan; | 
|  | 8426 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; | 
|  | 8427 | int err, ssid_len, ie_len = 0, auth_data_len = 0; | 
|  | 8428 | enum nl80211_auth_type auth_type; | 
|  | 8429 | struct key_parse key; | 
|  | 8430 | bool local_state_change; | 
|  | 8431 |  | 
|  | 8432 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 8433 | return -EINVAL; | 
|  | 8434 |  | 
|  | 8435 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 8436 | return -EINVAL; | 
|  | 8437 |  | 
|  | 8438 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) | 
|  | 8439 | return -EINVAL; | 
|  | 8440 |  | 
|  | 8441 | if (!info->attrs[NL80211_ATTR_SSID]) | 
|  | 8442 | return -EINVAL; | 
|  | 8443 |  | 
|  | 8444 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
|  | 8445 | return -EINVAL; | 
|  | 8446 |  | 
|  | 8447 | err = nl80211_parse_key(info, &key); | 
|  | 8448 | if (err) | 
|  | 8449 | return err; | 
|  | 8450 |  | 
|  | 8451 | if (key.idx >= 0) { | 
|  | 8452 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) | 
|  | 8453 | return -EINVAL; | 
|  | 8454 | if (!key.p.key || !key.p.key_len) | 
|  | 8455 | return -EINVAL; | 
|  | 8456 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | 
|  | 8457 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | 
|  | 8458 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | 
|  | 8459 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | 
|  | 8460 | return -EINVAL; | 
|  | 8461 | if (key.idx > 3) | 
|  | 8462 | return -EINVAL; | 
|  | 8463 | } else { | 
|  | 8464 | key.p.key_len = 0; | 
|  | 8465 | key.p.key = NULL; | 
|  | 8466 | } | 
|  | 8467 |  | 
|  | 8468 | if (key.idx >= 0) { | 
|  | 8469 | int i; | 
|  | 8470 | bool ok = false; | 
|  | 8471 |  | 
|  | 8472 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | 
|  | 8473 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | 
|  | 8474 | ok = true; | 
|  | 8475 | break; | 
|  | 8476 | } | 
|  | 8477 | } | 
|  | 8478 | if (!ok) | 
|  | 8479 | return -EINVAL; | 
|  | 8480 | } | 
|  | 8481 |  | 
|  | 8482 | if (!rdev->ops->auth) | 
|  | 8483 | return -EOPNOTSUPP; | 
|  | 8484 |  | 
|  | 8485 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 8486 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 8487 | return -EOPNOTSUPP; | 
|  | 8488 |  | 
|  | 8489 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 8490 | chan = nl80211_get_valid_chan(&rdev->wiphy, | 
|  | 8491 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
|  | 8492 | if (!chan) | 
|  | 8493 | return -EINVAL; | 
|  | 8494 |  | 
|  | 8495 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
|  | 8496 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 8497 |  | 
|  | 8498 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 8499 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 8500 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 8501 | } | 
|  | 8502 |  | 
|  | 8503 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
|  | 8504 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) | 
|  | 8505 | return -EINVAL; | 
|  | 8506 |  | 
|  | 8507 | if ((auth_type == NL80211_AUTHTYPE_SAE || | 
|  | 8508 | auth_type == NL80211_AUTHTYPE_FILS_SK || | 
|  | 8509 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | 
|  | 8510 | auth_type == NL80211_AUTHTYPE_FILS_PK) && | 
|  | 8511 | !info->attrs[NL80211_ATTR_AUTH_DATA]) | 
|  | 8512 | return -EINVAL; | 
|  | 8513 |  | 
|  | 8514 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { | 
|  | 8515 | if (auth_type != NL80211_AUTHTYPE_SAE && | 
|  | 8516 | auth_type != NL80211_AUTHTYPE_FILS_SK && | 
|  | 8517 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && | 
|  | 8518 | auth_type != NL80211_AUTHTYPE_FILS_PK) | 
|  | 8519 | return -EINVAL; | 
|  | 8520 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); | 
|  | 8521 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); | 
|  | 8522 | /* need to include at least Auth Transaction and Status Code */ | 
|  | 8523 | if (auth_data_len < 4) | 
|  | 8524 | return -EINVAL; | 
|  | 8525 | } | 
|  | 8526 |  | 
|  | 8527 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 
|  | 8528 |  | 
|  | 8529 | /* | 
|  | 8530 | * Since we no longer track auth state, ignore | 
|  | 8531 | * requests to only change local state. | 
|  | 8532 | */ | 
|  | 8533 | if (local_state_change) | 
|  | 8534 | return 0; | 
|  | 8535 |  | 
|  | 8536 | wdev_lock(dev->ieee80211_ptr); | 
|  | 8537 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | 
|  | 8538 | ssid, ssid_len, ie, ie_len, | 
|  | 8539 | key.p.key, key.p.key_len, key.idx, | 
|  | 8540 | auth_data, auth_data_len); | 
|  | 8541 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 8542 | return err; | 
|  | 8543 | } | 
|  | 8544 |  | 
|  | 8545 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, | 
|  | 8546 | struct genl_info *info) | 
|  | 8547 | { | 
|  | 8548 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | 
|  | 8549 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); | 
|  | 8550 | return -EINVAL; | 
|  | 8551 | } | 
|  | 8552 |  | 
|  | 8553 | if (!rdev->ops->tx_control_port || | 
|  | 8554 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 8555 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) | 
|  | 8556 | return -EOPNOTSUPP; | 
|  | 8557 |  | 
|  | 8558 | return 0; | 
|  | 8559 | } | 
|  | 8560 |  | 
|  | 8561 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, | 
|  | 8562 | struct genl_info *info, | 
|  | 8563 | struct cfg80211_crypto_settings *settings, | 
|  | 8564 | int cipher_limit) | 
|  | 8565 | { | 
|  | 8566 | memset(settings, 0, sizeof(*settings)); | 
|  | 8567 |  | 
|  | 8568 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; | 
|  | 8569 |  | 
|  | 8570 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { | 
|  | 8571 | u16 proto; | 
|  | 8572 |  | 
|  | 8573 | proto = nla_get_u16( | 
|  | 8574 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | 
|  | 8575 | settings->control_port_ethertype = cpu_to_be16(proto); | 
|  | 8576 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | 
|  | 8577 | proto != ETH_P_PAE) | 
|  | 8578 | return -EINVAL; | 
|  | 8579 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | 
|  | 8580 | settings->control_port_no_encrypt = true; | 
|  | 8581 | } else | 
|  | 8582 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | 
|  | 8583 |  | 
|  | 8584 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { | 
|  | 8585 | int r = validate_pae_over_nl80211(rdev, info); | 
|  | 8586 |  | 
|  | 8587 | if (r < 0) | 
|  | 8588 | return r; | 
|  | 8589 |  | 
|  | 8590 | settings->control_port_over_nl80211 = true; | 
|  | 8591 | } | 
|  | 8592 |  | 
|  | 8593 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { | 
|  | 8594 | void *data; | 
|  | 8595 | int len, i; | 
|  | 8596 |  | 
|  | 8597 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | 
|  | 8598 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | 
|  | 8599 | settings->n_ciphers_pairwise = len / sizeof(u32); | 
|  | 8600 |  | 
|  | 8601 | if (len % sizeof(u32)) | 
|  | 8602 | return -EINVAL; | 
|  | 8603 |  | 
|  | 8604 | if (settings->n_ciphers_pairwise > cipher_limit) | 
|  | 8605 | return -EINVAL; | 
|  | 8606 |  | 
|  | 8607 | memcpy(settings->ciphers_pairwise, data, len); | 
|  | 8608 |  | 
|  | 8609 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | 
|  | 8610 | if (!cfg80211_supported_cipher_suite( | 
|  | 8611 | &rdev->wiphy, | 
|  | 8612 | settings->ciphers_pairwise[i])) | 
|  | 8613 | return -EINVAL; | 
|  | 8614 | } | 
|  | 8615 |  | 
|  | 8616 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | 
|  | 8617 | settings->cipher_group = | 
|  | 8618 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | 
|  | 8619 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, | 
|  | 8620 | settings->cipher_group)) | 
|  | 8621 | return -EINVAL; | 
|  | 8622 | } | 
|  | 8623 |  | 
|  | 8624 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | 
|  | 8625 | settings->wpa_versions = | 
|  | 8626 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | 
|  | 8627 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | 
|  | 8628 | return -EINVAL; | 
|  | 8629 | } | 
|  | 8630 |  | 
|  | 8631 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | 
|  | 8632 | void *data; | 
|  | 8633 | int len; | 
|  | 8634 |  | 
|  | 8635 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | 
|  | 8636 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | 
|  | 8637 | settings->n_akm_suites = len / sizeof(u32); | 
|  | 8638 |  | 
|  | 8639 | if (len % sizeof(u32)) | 
|  | 8640 | return -EINVAL; | 
|  | 8641 |  | 
|  | 8642 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) | 
|  | 8643 | return -EINVAL; | 
|  | 8644 |  | 
|  | 8645 | memcpy(settings->akm_suites, data, len); | 
|  | 8646 | } | 
|  | 8647 |  | 
|  | 8648 | if (info->attrs[NL80211_ATTR_PMK]) { | 
|  | 8649 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) | 
|  | 8650 | return -EINVAL; | 
|  | 8651 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 8652 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) | 
|  | 8653 | return -EINVAL; | 
|  | 8654 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); | 
|  | 8655 | } | 
|  | 8656 |  | 
|  | 8657 | return 0; | 
|  | 8658 | } | 
|  | 8659 |  | 
|  | 8660 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) | 
|  | 8661 | { | 
|  | 8662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 8663 | struct net_device *dev = info->user_ptr[1]; | 
|  | 8664 | struct ieee80211_channel *chan; | 
|  | 8665 | struct cfg80211_assoc_request req = {}; | 
|  | 8666 | const u8 *bssid, *ssid; | 
|  | 8667 | int err, ssid_len = 0; | 
|  | 8668 |  | 
|  | 8669 | if (dev->ieee80211_ptr->conn_owner_nlportid && | 
|  | 8670 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | 
|  | 8671 | return -EPERM; | 
|  | 8672 |  | 
|  | 8673 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 8674 | return -EINVAL; | 
|  | 8675 |  | 
|  | 8676 | if (!info->attrs[NL80211_ATTR_MAC] || | 
|  | 8677 | !info->attrs[NL80211_ATTR_SSID] || | 
|  | 8678 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
|  | 8679 | return -EINVAL; | 
|  | 8680 |  | 
|  | 8681 | if (!rdev->ops->assoc) | 
|  | 8682 | return -EOPNOTSUPP; | 
|  | 8683 |  | 
|  | 8684 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 8685 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 8686 | return -EOPNOTSUPP; | 
|  | 8687 |  | 
|  | 8688 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 8689 |  | 
|  | 8690 | chan = nl80211_get_valid_chan(&rdev->wiphy, | 
|  | 8691 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
|  | 8692 | if (!chan) | 
|  | 8693 | return -EINVAL; | 
|  | 8694 |  | 
|  | 8695 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
|  | 8696 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 8697 |  | 
|  | 8698 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 8699 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 8700 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 8701 | } | 
|  | 8702 |  | 
|  | 8703 | if (info->attrs[NL80211_ATTR_USE_MFP]) { | 
|  | 8704 | enum nl80211_mfp mfp = | 
|  | 8705 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | 
|  | 8706 | if (mfp == NL80211_MFP_REQUIRED) | 
|  | 8707 | req.use_mfp = true; | 
|  | 8708 | else if (mfp != NL80211_MFP_NO) | 
|  | 8709 | return -EINVAL; | 
|  | 8710 | } | 
|  | 8711 |  | 
|  | 8712 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) | 
|  | 8713 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | 
|  | 8714 |  | 
|  | 8715 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) | 
|  | 8716 | req.flags |= ASSOC_REQ_DISABLE_HT; | 
|  | 8717 |  | 
|  | 8718 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
|  | 8719 | memcpy(&req.ht_capa_mask, | 
|  | 8720 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | 
|  | 8721 | sizeof(req.ht_capa_mask)); | 
|  | 8722 |  | 
|  | 8723 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | 
|  | 8724 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
|  | 8725 | return -EINVAL; | 
|  | 8726 | memcpy(&req.ht_capa, | 
|  | 8727 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | 
|  | 8728 | sizeof(req.ht_capa)); | 
|  | 8729 | } | 
|  | 8730 |  | 
|  | 8731 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) | 
|  | 8732 | req.flags |= ASSOC_REQ_DISABLE_VHT; | 
|  | 8733 |  | 
|  | 8734 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | 
|  | 8735 | memcpy(&req.vht_capa_mask, | 
|  | 8736 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | 
|  | 8737 | sizeof(req.vht_capa_mask)); | 
|  | 8738 |  | 
|  | 8739 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | 
|  | 8740 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | 
|  | 8741 | return -EINVAL; | 
|  | 8742 | memcpy(&req.vht_capa, | 
|  | 8743 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | 
|  | 8744 | sizeof(req.vht_capa)); | 
|  | 8745 | } | 
|  | 8746 |  | 
|  | 8747 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { | 
|  | 8748 | if (!((rdev->wiphy.features & | 
|  | 8749 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | 
|  | 8750 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | 
|  | 8751 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 8752 | NL80211_EXT_FEATURE_RRM)) | 
|  | 8753 | return -EINVAL; | 
|  | 8754 | req.flags |= ASSOC_REQ_USE_RRM; | 
|  | 8755 | } | 
|  | 8756 |  | 
|  | 8757 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { | 
|  | 8758 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); | 
|  | 8759 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); | 
|  | 8760 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) | 
|  | 8761 | return -EINVAL; | 
|  | 8762 | req.fils_nonces = | 
|  | 8763 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); | 
|  | 8764 | } | 
|  | 8765 |  | 
|  | 8766 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); | 
|  | 8767 | if (!err) { | 
|  | 8768 | wdev_lock(dev->ieee80211_ptr); | 
|  | 8769 |  | 
|  | 8770 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, | 
|  | 8771 | ssid, ssid_len, &req); | 
|  | 8772 |  | 
|  | 8773 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | 
|  | 8774 | dev->ieee80211_ptr->conn_owner_nlportid = | 
|  | 8775 | info->snd_portid; | 
|  | 8776 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | 
|  | 8777 | bssid, ETH_ALEN); | 
|  | 8778 | } | 
|  | 8779 |  | 
|  | 8780 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 8781 | } | 
|  | 8782 |  | 
|  | 8783 | return err; | 
|  | 8784 | } | 
|  | 8785 |  | 
|  | 8786 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | 
|  | 8787 | { | 
|  | 8788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 8789 | struct net_device *dev = info->user_ptr[1]; | 
|  | 8790 | const u8 *ie = NULL, *bssid; | 
|  | 8791 | int ie_len = 0, err; | 
|  | 8792 | u16 reason_code; | 
|  | 8793 | bool local_state_change; | 
|  | 8794 |  | 
|  | 8795 | if (dev->ieee80211_ptr->conn_owner_nlportid && | 
|  | 8796 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | 
|  | 8797 | return -EPERM; | 
|  | 8798 |  | 
|  | 8799 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 8800 | return -EINVAL; | 
|  | 8801 |  | 
|  | 8802 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 8803 | return -EINVAL; | 
|  | 8804 |  | 
|  | 8805 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 
|  | 8806 | return -EINVAL; | 
|  | 8807 |  | 
|  | 8808 | if (!rdev->ops->deauth) | 
|  | 8809 | return -EOPNOTSUPP; | 
|  | 8810 |  | 
|  | 8811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 8812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 8813 | return -EOPNOTSUPP; | 
|  | 8814 |  | 
|  | 8815 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 8816 |  | 
|  | 8817 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
|  | 8818 | if (reason_code == 0) { | 
|  | 8819 | /* Reason Code 0 is reserved */ | 
|  | 8820 | return -EINVAL; | 
|  | 8821 | } | 
|  | 8822 |  | 
|  | 8823 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 8824 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 8825 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 8826 | } | 
|  | 8827 |  | 
|  | 8828 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 
|  | 8829 |  | 
|  | 8830 | wdev_lock(dev->ieee80211_ptr); | 
|  | 8831 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | 
|  | 8832 | local_state_change); | 
|  | 8833 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 8834 | return err; | 
|  | 8835 | } | 
|  | 8836 |  | 
|  | 8837 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | 
|  | 8838 | { | 
|  | 8839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 8840 | struct net_device *dev = info->user_ptr[1]; | 
|  | 8841 | const u8 *ie = NULL, *bssid; | 
|  | 8842 | int ie_len = 0, err; | 
|  | 8843 | u16 reason_code; | 
|  | 8844 | bool local_state_change; | 
|  | 8845 |  | 
|  | 8846 | if (dev->ieee80211_ptr->conn_owner_nlportid && | 
|  | 8847 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | 
|  | 8848 | return -EPERM; | 
|  | 8849 |  | 
|  | 8850 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 8851 | return -EINVAL; | 
|  | 8852 |  | 
|  | 8853 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 8854 | return -EINVAL; | 
|  | 8855 |  | 
|  | 8856 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 
|  | 8857 | return -EINVAL; | 
|  | 8858 |  | 
|  | 8859 | if (!rdev->ops->disassoc) | 
|  | 8860 | return -EOPNOTSUPP; | 
|  | 8861 |  | 
|  | 8862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 8863 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 8864 | return -EOPNOTSUPP; | 
|  | 8865 |  | 
|  | 8866 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 8867 |  | 
|  | 8868 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
|  | 8869 | if (reason_code == 0) { | 
|  | 8870 | /* Reason Code 0 is reserved */ | 
|  | 8871 | return -EINVAL; | 
|  | 8872 | } | 
|  | 8873 |  | 
|  | 8874 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 8875 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 8876 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 8877 | } | 
|  | 8878 |  | 
|  | 8879 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 
|  | 8880 |  | 
|  | 8881 | wdev_lock(dev->ieee80211_ptr); | 
|  | 8882 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | 
|  | 8883 | local_state_change); | 
|  | 8884 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 8885 | return err; | 
|  | 8886 | } | 
|  | 8887 |  | 
|  | 8888 | static bool | 
|  | 8889 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | 
|  | 8890 | int mcast_rate[NUM_NL80211_BANDS], | 
|  | 8891 | int rateval) | 
|  | 8892 | { | 
|  | 8893 | struct wiphy *wiphy = &rdev->wiphy; | 
|  | 8894 | bool found = false; | 
|  | 8895 | int band, i; | 
|  | 8896 |  | 
|  | 8897 | for (band = 0; band < NUM_NL80211_BANDS; band++) { | 
|  | 8898 | struct ieee80211_supported_band *sband; | 
|  | 8899 |  | 
|  | 8900 | sband = wiphy->bands[band]; | 
|  | 8901 | if (!sband) | 
|  | 8902 | continue; | 
|  | 8903 |  | 
|  | 8904 | for (i = 0; i < sband->n_bitrates; i++) { | 
|  | 8905 | if (sband->bitrates[i].bitrate == rateval) { | 
|  | 8906 | mcast_rate[band] = i + 1; | 
|  | 8907 | found = true; | 
|  | 8908 | break; | 
|  | 8909 | } | 
|  | 8910 | } | 
|  | 8911 | } | 
|  | 8912 |  | 
|  | 8913 | return found; | 
|  | 8914 | } | 
|  | 8915 |  | 
|  | 8916 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | 
|  | 8917 | { | 
|  | 8918 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 8919 | struct net_device *dev = info->user_ptr[1]; | 
|  | 8920 | struct cfg80211_ibss_params ibss; | 
|  | 8921 | struct wiphy *wiphy; | 
|  | 8922 | struct cfg80211_cached_keys *connkeys = NULL; | 
|  | 8923 | int err; | 
|  | 8924 |  | 
|  | 8925 | memset(&ibss, 0, sizeof(ibss)); | 
|  | 8926 |  | 
|  | 8927 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 8928 | return -EINVAL; | 
|  | 8929 |  | 
|  | 8930 | if (!info->attrs[NL80211_ATTR_SSID] || | 
|  | 8931 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | 
|  | 8932 | return -EINVAL; | 
|  | 8933 |  | 
|  | 8934 | ibss.beacon_interval = 100; | 
|  | 8935 |  | 
|  | 8936 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) | 
|  | 8937 | ibss.beacon_interval = | 
|  | 8938 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | 
|  | 8939 |  | 
|  | 8940 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, | 
|  | 8941 | ibss.beacon_interval); | 
|  | 8942 | if (err) | 
|  | 8943 | return err; | 
|  | 8944 |  | 
|  | 8945 | if (!rdev->ops->join_ibss) | 
|  | 8946 | return -EOPNOTSUPP; | 
|  | 8947 |  | 
|  | 8948 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) | 
|  | 8949 | return -EOPNOTSUPP; | 
|  | 8950 |  | 
|  | 8951 | wiphy = &rdev->wiphy; | 
|  | 8952 |  | 
|  | 8953 | if (info->attrs[NL80211_ATTR_MAC]) { | 
|  | 8954 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 8955 |  | 
|  | 8956 | if (!is_valid_ether_addr(ibss.bssid)) | 
|  | 8957 | return -EINVAL; | 
|  | 8958 | } | 
|  | 8959 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
|  | 8960 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 8961 |  | 
|  | 8962 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 8963 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 8964 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 8965 | } | 
|  | 8966 |  | 
|  | 8967 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); | 
|  | 8968 | if (err) | 
|  | 8969 | return err; | 
|  | 8970 |  | 
|  | 8971 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, | 
|  | 8972 | NL80211_IFTYPE_ADHOC)) | 
|  | 8973 | return -EINVAL; | 
|  | 8974 |  | 
|  | 8975 | switch (ibss.chandef.width) { | 
|  | 8976 | case NL80211_CHAN_WIDTH_5: | 
|  | 8977 | case NL80211_CHAN_WIDTH_10: | 
|  | 8978 | case NL80211_CHAN_WIDTH_20_NOHT: | 
|  | 8979 | break; | 
|  | 8980 | case NL80211_CHAN_WIDTH_20: | 
|  | 8981 | case NL80211_CHAN_WIDTH_40: | 
|  | 8982 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | 
|  | 8983 | return -EINVAL; | 
|  | 8984 | break; | 
|  | 8985 | case NL80211_CHAN_WIDTH_80: | 
|  | 8986 | case NL80211_CHAN_WIDTH_80P80: | 
|  | 8987 | case NL80211_CHAN_WIDTH_160: | 
|  | 8988 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | 
|  | 8989 | return -EINVAL; | 
|  | 8990 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 8991 | NL80211_EXT_FEATURE_VHT_IBSS)) | 
|  | 8992 | return -EINVAL; | 
|  | 8993 | break; | 
|  | 8994 | default: | 
|  | 8995 | return -EINVAL; | 
|  | 8996 | } | 
|  | 8997 |  | 
|  | 8998 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | 
|  | 8999 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | 
|  | 9000 |  | 
|  | 9001 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 
|  | 9002 | u8 *rates = | 
|  | 9003 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
|  | 9004 | int n_rates = | 
|  | 9005 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
|  | 9006 | struct ieee80211_supported_band *sband = | 
|  | 9007 | wiphy->bands[ibss.chandef.chan->band]; | 
|  | 9008 |  | 
|  | 9009 | err = ieee80211_get_ratemask(sband, rates, n_rates, | 
|  | 9010 | &ibss.basic_rates); | 
|  | 9011 | if (err) | 
|  | 9012 | return err; | 
|  | 9013 | } | 
|  | 9014 |  | 
|  | 9015 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
|  | 9016 | memcpy(&ibss.ht_capa_mask, | 
|  | 9017 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | 
|  | 9018 | sizeof(ibss.ht_capa_mask)); | 
|  | 9019 |  | 
|  | 9020 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | 
|  | 9021 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
|  | 9022 | return -EINVAL; | 
|  | 9023 | memcpy(&ibss.ht_capa, | 
|  | 9024 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | 
|  | 9025 | sizeof(ibss.ht_capa)); | 
|  | 9026 | } | 
|  | 9027 |  | 
|  | 9028 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | 
|  | 9029 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | 
|  | 9030 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | 
|  | 9031 | return -EINVAL; | 
|  | 9032 |  | 
|  | 9033 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { | 
|  | 9034 | bool no_ht = false; | 
|  | 9035 |  | 
|  | 9036 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); | 
|  | 9037 | if (IS_ERR(connkeys)) | 
|  | 9038 | return PTR_ERR(connkeys); | 
|  | 9039 |  | 
|  | 9040 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && | 
|  | 9041 | no_ht) { | 
|  | 9042 | kzfree(connkeys); | 
|  | 9043 | return -EINVAL; | 
|  | 9044 | } | 
|  | 9045 | } | 
|  | 9046 |  | 
|  | 9047 | ibss.control_port = | 
|  | 9048 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | 
|  | 9049 |  | 
|  | 9050 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { | 
|  | 9051 | int r = validate_pae_over_nl80211(rdev, info); | 
|  | 9052 |  | 
|  | 9053 | if (r < 0) { | 
|  | 9054 | kzfree(connkeys); | 
|  | 9055 | return r; | 
|  | 9056 | } | 
|  | 9057 |  | 
|  | 9058 | ibss.control_port_over_nl80211 = true; | 
|  | 9059 | } | 
|  | 9060 |  | 
|  | 9061 | ibss.userspace_handles_dfs = | 
|  | 9062 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | 
|  | 9063 |  | 
|  | 9064 | wdev_lock(dev->ieee80211_ptr); | 
|  | 9065 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); | 
|  | 9066 | if (err) | 
|  | 9067 | kzfree(connkeys); | 
|  | 9068 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
|  | 9069 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | 
|  | 9070 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 9071 |  | 
|  | 9072 | return err; | 
|  | 9073 | } | 
|  | 9074 |  | 
|  | 9075 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | 
|  | 9076 | { | 
|  | 9077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9078 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9079 |  | 
|  | 9080 | if (!rdev->ops->leave_ibss) | 
|  | 9081 | return -EOPNOTSUPP; | 
|  | 9082 |  | 
|  | 9083 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) | 
|  | 9084 | return -EOPNOTSUPP; | 
|  | 9085 |  | 
|  | 9086 | return cfg80211_leave_ibss(rdev, dev, false); | 
|  | 9087 | } | 
|  | 9088 |  | 
|  | 9089 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) | 
|  | 9090 | { | 
|  | 9091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9092 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9093 | int mcast_rate[NUM_NL80211_BANDS]; | 
|  | 9094 | u32 nla_rate; | 
|  | 9095 | int err; | 
|  | 9096 |  | 
|  | 9097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | 
|  | 9098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && | 
|  | 9099 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | 
|  | 9100 | return -EOPNOTSUPP; | 
|  | 9101 |  | 
|  | 9102 | if (!rdev->ops->set_mcast_rate) | 
|  | 9103 | return -EOPNOTSUPP; | 
|  | 9104 |  | 
|  | 9105 | memset(mcast_rate, 0, sizeof(mcast_rate)); | 
|  | 9106 |  | 
|  | 9107 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | 
|  | 9108 | return -EINVAL; | 
|  | 9109 |  | 
|  | 9110 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | 
|  | 9111 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | 
|  | 9112 | return -EINVAL; | 
|  | 9113 |  | 
|  | 9114 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); | 
|  | 9115 |  | 
|  | 9116 | return err; | 
|  | 9117 | } | 
|  | 9118 |  | 
|  | 9119 | static struct sk_buff * | 
|  | 9120 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | 
|  | 9121 | struct wireless_dev *wdev, int approxlen, | 
|  | 9122 | u32 portid, u32 seq, enum nl80211_commands cmd, | 
|  | 9123 | enum nl80211_attrs attr, | 
|  | 9124 | const struct nl80211_vendor_cmd_info *info, | 
|  | 9125 | gfp_t gfp) | 
|  | 9126 | { | 
|  | 9127 | struct sk_buff *skb; | 
|  | 9128 | void *hdr; | 
|  | 9129 | struct nlattr *data; | 
|  | 9130 |  | 
|  | 9131 | skb = nlmsg_new(approxlen + 100, gfp); | 
|  | 9132 | if (!skb) | 
|  | 9133 | return NULL; | 
|  | 9134 |  | 
|  | 9135 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | 
|  | 9136 | if (!hdr) { | 
|  | 9137 | kfree_skb(skb); | 
|  | 9138 | return NULL; | 
|  | 9139 | } | 
|  | 9140 |  | 
|  | 9141 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | 
|  | 9142 | goto nla_put_failure; | 
|  | 9143 |  | 
|  | 9144 | if (info) { | 
|  | 9145 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | 
|  | 9146 | info->vendor_id)) | 
|  | 9147 | goto nla_put_failure; | 
|  | 9148 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 9149 | info->subcmd)) | 
|  | 9150 | goto nla_put_failure; | 
|  | 9151 | } | 
|  | 9152 |  | 
|  | 9153 | if (wdev) { | 
|  | 9154 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, | 
|  | 9155 | wdev_id(wdev), NL80211_ATTR_PAD)) | 
|  | 9156 | goto nla_put_failure; | 
|  | 9157 | if (wdev->netdev && | 
|  | 9158 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | 
|  | 9159 | wdev->netdev->ifindex)) | 
|  | 9160 | goto nla_put_failure; | 
|  | 9161 | } | 
|  | 9162 |  | 
|  | 9163 | data = nla_nest_start(skb, attr); | 
|  | 9164 | if (!data) | 
|  | 9165 | goto nla_put_failure; | 
|  | 9166 |  | 
|  | 9167 | ((void **)skb->cb)[0] = rdev; | 
|  | 9168 | ((void **)skb->cb)[1] = hdr; | 
|  | 9169 | ((void **)skb->cb)[2] = data; | 
|  | 9170 |  | 
|  | 9171 | return skb; | 
|  | 9172 |  | 
|  | 9173 | nla_put_failure: | 
|  | 9174 | kfree_skb(skb); | 
|  | 9175 | return NULL; | 
|  | 9176 | } | 
|  | 9177 |  | 
|  | 9178 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, | 
|  | 9179 | struct wireless_dev *wdev, | 
|  | 9180 | enum nl80211_commands cmd, | 
|  | 9181 | enum nl80211_attrs attr, | 
|  | 9182 | int vendor_event_idx, | 
|  | 9183 | int approxlen, gfp_t gfp) | 
|  | 9184 | { | 
|  | 9185 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 9186 | const struct nl80211_vendor_cmd_info *info; | 
|  | 9187 |  | 
|  | 9188 | switch (cmd) { | 
|  | 9189 | case NL80211_CMD_TESTMODE: | 
|  | 9190 | if (WARN_ON(vendor_event_idx != -1)) | 
|  | 9191 | return NULL; | 
|  | 9192 | info = NULL; | 
|  | 9193 | break; | 
|  | 9194 | case NL80211_CMD_VENDOR: | 
|  | 9195 | if (WARN_ON(vendor_event_idx < 0 || | 
|  | 9196 | vendor_event_idx >= wiphy->n_vendor_events)) | 
|  | 9197 | return NULL; | 
|  | 9198 | info = &wiphy->vendor_events[vendor_event_idx]; | 
|  | 9199 | break; | 
|  | 9200 | default: | 
|  | 9201 | WARN_ON(1); | 
|  | 9202 | return NULL; | 
|  | 9203 | } | 
|  | 9204 |  | 
|  | 9205 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, | 
|  | 9206 | cmd, attr, info, gfp); | 
|  | 9207 | } | 
|  | 9208 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | 
|  | 9209 |  | 
|  | 9210 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | 
|  | 9211 | { | 
|  | 9212 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | 
|  | 9213 | void *hdr = ((void **)skb->cb)[1]; | 
|  | 9214 | struct nlattr *data = ((void **)skb->cb)[2]; | 
|  | 9215 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | 
|  | 9216 |  | 
|  | 9217 | /* clear CB data for netlink core to own from now on */ | 
|  | 9218 | memset(skb->cb, 0, sizeof(skb->cb)); | 
|  | 9219 |  | 
|  | 9220 | nla_nest_end(skb, data); | 
|  | 9221 | genlmsg_end(skb, hdr); | 
|  | 9222 |  | 
|  | 9223 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | 
|  | 9224 | mcgrp = NL80211_MCGRP_VENDOR; | 
|  | 9225 |  | 
|  | 9226 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | 
|  | 9227 | mcgrp, gfp); | 
|  | 9228 | } | 
|  | 9229 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | 
|  | 9230 |  | 
|  | 9231 | #ifdef CONFIG_NL80211_TESTMODE | 
|  | 9232 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | 
|  | 9233 | { | 
|  | 9234 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9235 | struct wireless_dev *wdev = | 
|  | 9236 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | 
|  | 9237 | int err; | 
|  | 9238 |  | 
|  | 9239 | if (!rdev->ops->testmode_cmd) | 
|  | 9240 | return -EOPNOTSUPP; | 
|  | 9241 |  | 
|  | 9242 | if (IS_ERR(wdev)) { | 
|  | 9243 | err = PTR_ERR(wdev); | 
|  | 9244 | if (err != -EINVAL) | 
|  | 9245 | return err; | 
|  | 9246 | wdev = NULL; | 
|  | 9247 | } else if (wdev->wiphy != &rdev->wiphy) { | 
|  | 9248 | return -EINVAL; | 
|  | 9249 | } | 
|  | 9250 |  | 
|  | 9251 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | 
|  | 9252 | return -EINVAL; | 
|  | 9253 |  | 
|  | 9254 | rdev->cur_cmd_info = info; | 
|  | 9255 | err = rdev_testmode_cmd(rdev, wdev, | 
|  | 9256 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | 
|  | 9257 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | 
|  | 9258 | rdev->cur_cmd_info = NULL; | 
|  | 9259 |  | 
|  | 9260 | return err; | 
|  | 9261 | } | 
|  | 9262 |  | 
|  | 9263 | static int nl80211_testmode_dump(struct sk_buff *skb, | 
|  | 9264 | struct netlink_callback *cb) | 
|  | 9265 | { | 
|  | 9266 | struct cfg80211_registered_device *rdev; | 
|  | 9267 | int err; | 
|  | 9268 | long phy_idx; | 
|  | 9269 | void *data = NULL; | 
|  | 9270 | int data_len = 0; | 
|  | 9271 |  | 
|  | 9272 | rtnl_lock(); | 
|  | 9273 |  | 
|  | 9274 | if (cb->args[0]) { | 
|  | 9275 | /* | 
|  | 9276 | * 0 is a valid index, but not valid for args[0], | 
|  | 9277 | * so we need to offset by 1. | 
|  | 9278 | */ | 
|  | 9279 | phy_idx = cb->args[0] - 1; | 
|  | 9280 |  | 
|  | 9281 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); | 
|  | 9282 | if (!rdev) { | 
|  | 9283 | err = -ENOENT; | 
|  | 9284 | goto out_err; | 
|  | 9285 | } | 
|  | 9286 | } else { | 
|  | 9287 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); | 
|  | 9288 |  | 
|  | 9289 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | 
|  | 9290 | attrbuf, nl80211_fam.maxattr, | 
|  | 9291 | nl80211_policy, NULL); | 
|  | 9292 | if (err) | 
|  | 9293 | goto out_err; | 
|  | 9294 |  | 
|  | 9295 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); | 
|  | 9296 | if (IS_ERR(rdev)) { | 
|  | 9297 | err = PTR_ERR(rdev); | 
|  | 9298 | goto out_err; | 
|  | 9299 | } | 
|  | 9300 | phy_idx = rdev->wiphy_idx; | 
|  | 9301 |  | 
|  | 9302 | if (attrbuf[NL80211_ATTR_TESTDATA]) | 
|  | 9303 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; | 
|  | 9304 | } | 
|  | 9305 |  | 
|  | 9306 | if (cb->args[1]) { | 
|  | 9307 | data = nla_data((void *)cb->args[1]); | 
|  | 9308 | data_len = nla_len((void *)cb->args[1]); | 
|  | 9309 | } | 
|  | 9310 |  | 
|  | 9311 | if (!rdev->ops->testmode_dump) { | 
|  | 9312 | err = -EOPNOTSUPP; | 
|  | 9313 | goto out_err; | 
|  | 9314 | } | 
|  | 9315 |  | 
|  | 9316 | while (1) { | 
|  | 9317 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | 
|  | 9318 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 9319 | NL80211_CMD_TESTMODE); | 
|  | 9320 | struct nlattr *tmdata; | 
|  | 9321 |  | 
|  | 9322 | if (!hdr) | 
|  | 9323 | break; | 
|  | 9324 |  | 
|  | 9325 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { | 
|  | 9326 | genlmsg_cancel(skb, hdr); | 
|  | 9327 | break; | 
|  | 9328 | } | 
|  | 9329 |  | 
|  | 9330 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | 
|  | 9331 | if (!tmdata) { | 
|  | 9332 | genlmsg_cancel(skb, hdr); | 
|  | 9333 | break; | 
|  | 9334 | } | 
|  | 9335 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); | 
|  | 9336 | nla_nest_end(skb, tmdata); | 
|  | 9337 |  | 
|  | 9338 | if (err == -ENOBUFS || err == -ENOENT) { | 
|  | 9339 | genlmsg_cancel(skb, hdr); | 
|  | 9340 | break; | 
|  | 9341 | } else if (err) { | 
|  | 9342 | genlmsg_cancel(skb, hdr); | 
|  | 9343 | goto out_err; | 
|  | 9344 | } | 
|  | 9345 |  | 
|  | 9346 | genlmsg_end(skb, hdr); | 
|  | 9347 | } | 
|  | 9348 |  | 
|  | 9349 | err = skb->len; | 
|  | 9350 | /* see above */ | 
|  | 9351 | cb->args[0] = phy_idx + 1; | 
|  | 9352 | out_err: | 
|  | 9353 | rtnl_unlock(); | 
|  | 9354 | return err; | 
|  | 9355 | } | 
|  | 9356 | #endif | 
|  | 9357 |  | 
|  | 9358 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) | 
|  | 9359 | { | 
|  | 9360 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9361 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9362 | struct cfg80211_connect_params connect; | 
|  | 9363 | struct wiphy *wiphy; | 
|  | 9364 | struct cfg80211_cached_keys *connkeys = NULL; | 
|  | 9365 | int err; | 
|  | 9366 |  | 
|  | 9367 | memset(&connect, 0, sizeof(connect)); | 
|  | 9368 |  | 
|  | 9369 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 9370 | return -EINVAL; | 
|  | 9371 |  | 
|  | 9372 | if (!info->attrs[NL80211_ATTR_SSID] || | 
|  | 9373 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | 
|  | 9374 | return -EINVAL; | 
|  | 9375 |  | 
|  | 9376 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | 
|  | 9377 | connect.auth_type = | 
|  | 9378 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
|  | 9379 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, | 
|  | 9380 | NL80211_CMD_CONNECT)) | 
|  | 9381 | return -EINVAL; | 
|  | 9382 | } else | 
|  | 9383 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | 
|  | 9384 |  | 
|  | 9385 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | 
|  | 9386 |  | 
|  | 9387 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && | 
|  | 9388 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 9389 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | 
|  | 9390 | return -EINVAL; | 
|  | 9391 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; | 
|  | 9392 |  | 
|  | 9393 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, | 
|  | 9394 | NL80211_MAX_NR_CIPHER_SUITES); | 
|  | 9395 | if (err) | 
|  | 9396 | return err; | 
|  | 9397 |  | 
|  | 9398 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 9399 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 9400 | return -EOPNOTSUPP; | 
|  | 9401 |  | 
|  | 9402 | wiphy = &rdev->wiphy; | 
|  | 9403 |  | 
|  | 9404 | connect.bg_scan_period = -1; | 
|  | 9405 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | 
|  | 9406 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | 
|  | 9407 | connect.bg_scan_period = | 
|  | 9408 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | 
|  | 9409 | } | 
|  | 9410 |  | 
|  | 9411 | if (info->attrs[NL80211_ATTR_MAC]) | 
|  | 9412 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 9413 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) | 
|  | 9414 | connect.bssid_hint = | 
|  | 9415 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | 
|  | 9416 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
|  | 9417 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 9418 |  | 
|  | 9419 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 9420 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 9421 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 9422 | } | 
|  | 9423 |  | 
|  | 9424 | if (info->attrs[NL80211_ATTR_USE_MFP]) { | 
|  | 9425 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | 
|  | 9426 | if (connect.mfp == NL80211_MFP_OPTIONAL && | 
|  | 9427 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 9428 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) | 
|  | 9429 | return -EOPNOTSUPP; | 
|  | 9430 |  | 
|  | 9431 | if (connect.mfp != NL80211_MFP_REQUIRED && | 
|  | 9432 | connect.mfp != NL80211_MFP_NO && | 
|  | 9433 | connect.mfp != NL80211_MFP_OPTIONAL) | 
|  | 9434 | return -EINVAL; | 
|  | 9435 | } else { | 
|  | 9436 | connect.mfp = NL80211_MFP_NO; | 
|  | 9437 | } | 
|  | 9438 |  | 
|  | 9439 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) | 
|  | 9440 | connect.prev_bssid = | 
|  | 9441 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | 
|  | 9442 |  | 
|  | 9443 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
|  | 9444 | connect.channel = nl80211_get_valid_chan( | 
|  | 9445 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
|  | 9446 | if (!connect.channel) | 
|  | 9447 | return -EINVAL; | 
|  | 9448 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | 
|  | 9449 | connect.channel_hint = nl80211_get_valid_chan( | 
|  | 9450 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | 
|  | 9451 | if (!connect.channel_hint) | 
|  | 9452 | return -EINVAL; | 
|  | 9453 | } | 
|  | 9454 |  | 
|  | 9455 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { | 
|  | 9456 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); | 
|  | 9457 | if (IS_ERR(connkeys)) | 
|  | 9458 | return PTR_ERR(connkeys); | 
|  | 9459 | } | 
|  | 9460 |  | 
|  | 9461 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) | 
|  | 9462 | connect.flags |= ASSOC_REQ_DISABLE_HT; | 
|  | 9463 |  | 
|  | 9464 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
|  | 9465 | memcpy(&connect.ht_capa_mask, | 
|  | 9466 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | 
|  | 9467 | sizeof(connect.ht_capa_mask)); | 
|  | 9468 |  | 
|  | 9469 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | 
|  | 9470 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { | 
|  | 9471 | kzfree(connkeys); | 
|  | 9472 | return -EINVAL; | 
|  | 9473 | } | 
|  | 9474 | memcpy(&connect.ht_capa, | 
|  | 9475 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | 
|  | 9476 | sizeof(connect.ht_capa)); | 
|  | 9477 | } | 
|  | 9478 |  | 
|  | 9479 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) | 
|  | 9480 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | 
|  | 9481 |  | 
|  | 9482 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | 
|  | 9483 | memcpy(&connect.vht_capa_mask, | 
|  | 9484 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | 
|  | 9485 | sizeof(connect.vht_capa_mask)); | 
|  | 9486 |  | 
|  | 9487 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | 
|  | 9488 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | 
|  | 9489 | kzfree(connkeys); | 
|  | 9490 | return -EINVAL; | 
|  | 9491 | } | 
|  | 9492 | memcpy(&connect.vht_capa, | 
|  | 9493 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | 
|  | 9494 | sizeof(connect.vht_capa)); | 
|  | 9495 | } | 
|  | 9496 |  | 
|  | 9497 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { | 
|  | 9498 | if (!((rdev->wiphy.features & | 
|  | 9499 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | 
|  | 9500 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | 
|  | 9501 | !wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 9502 | NL80211_EXT_FEATURE_RRM)) { | 
|  | 9503 | kzfree(connkeys); | 
|  | 9504 | return -EINVAL; | 
|  | 9505 | } | 
|  | 9506 | connect.flags |= ASSOC_REQ_USE_RRM; | 
|  | 9507 | } | 
|  | 9508 |  | 
|  | 9509 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); | 
|  | 9510 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { | 
|  | 9511 | kzfree(connkeys); | 
|  | 9512 | return -EOPNOTSUPP; | 
|  | 9513 | } | 
|  | 9514 |  | 
|  | 9515 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { | 
|  | 9516 | /* bss selection makes no sense if bssid is set */ | 
|  | 9517 | if (connect.bssid) { | 
|  | 9518 | kzfree(connkeys); | 
|  | 9519 | return -EINVAL; | 
|  | 9520 | } | 
|  | 9521 |  | 
|  | 9522 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | 
|  | 9523 | wiphy, &connect.bss_select); | 
|  | 9524 | if (err) { | 
|  | 9525 | kzfree(connkeys); | 
|  | 9526 | return err; | 
|  | 9527 | } | 
|  | 9528 | } | 
|  | 9529 |  | 
|  | 9530 | if (wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 9531 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | 
|  | 9532 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | 
|  | 9533 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | 
|  | 9534 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | 
|  | 9535 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | 
|  | 9536 | connect.fils_erp_username = | 
|  | 9537 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | 
|  | 9538 | connect.fils_erp_username_len = | 
|  | 9539 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | 
|  | 9540 | connect.fils_erp_realm = | 
|  | 9541 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | 
|  | 9542 | connect.fils_erp_realm_len = | 
|  | 9543 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | 
|  | 9544 | connect.fils_erp_next_seq_num = | 
|  | 9545 | nla_get_u16( | 
|  | 9546 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | 
|  | 9547 | connect.fils_erp_rrk = | 
|  | 9548 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | 
|  | 9549 | connect.fils_erp_rrk_len = | 
|  | 9550 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | 
|  | 9551 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | 
|  | 9552 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | 
|  | 9553 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | 
|  | 9554 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | 
|  | 9555 | kzfree(connkeys); | 
|  | 9556 | return -EINVAL; | 
|  | 9557 | } | 
|  | 9558 |  | 
|  | 9559 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { | 
|  | 9560 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | 
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 9561 | GENL_SET_ERR_MSG(info, | 
|  | 9562 | "external auth requires connection ownership"); | 
|  | 9563 | return -EINVAL; | 
|  | 9564 | } | 
|  | 9565 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; | 
|  | 9566 | } | 
|  | 9567 |  | 
|  | 9568 | wdev_lock(dev->ieee80211_ptr); | 
|  | 9569 |  | 
|  | 9570 | err = cfg80211_connect(rdev, dev, &connect, connkeys, | 
|  | 9571 | connect.prev_bssid); | 
|  | 9572 | if (err) | 
|  | 9573 | kzfree(connkeys); | 
|  | 9574 |  | 
|  | 9575 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | 
|  | 9576 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | 
|  | 9577 | if (connect.bssid) | 
|  | 9578 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | 
|  | 9579 | connect.bssid, ETH_ALEN); | 
|  | 9580 | else | 
|  | 9581 | memset(dev->ieee80211_ptr->disconnect_bssid, | 
|  | 9582 | 0, ETH_ALEN); | 
|  | 9583 | } | 
|  | 9584 |  | 
|  | 9585 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 9586 |  | 
|  | 9587 | return err; | 
|  | 9588 | } | 
|  | 9589 |  | 
|  | 9590 | static int nl80211_update_connect_params(struct sk_buff *skb, | 
|  | 9591 | struct genl_info *info) | 
|  | 9592 | { | 
|  | 9593 | struct cfg80211_connect_params connect = {}; | 
|  | 9594 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9595 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9596 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 9597 | bool fils_sk_offload; | 
|  | 9598 | u32 auth_type; | 
|  | 9599 | u32 changed = 0; | 
|  | 9600 | int ret; | 
|  | 9601 |  | 
|  | 9602 | if (!rdev->ops->update_connect_params) | 
|  | 9603 | return -EOPNOTSUPP; | 
|  | 9604 |  | 
|  | 9605 | if (info->attrs[NL80211_ATTR_IE]) { | 
|  | 9606 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 9607 | return -EINVAL; | 
|  | 9608 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 9609 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 9610 | changed |= UPDATE_ASSOC_IES; | 
|  | 9611 | } | 
|  | 9612 |  | 
|  | 9613 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 9614 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); | 
|  | 9615 |  | 
|  | 9616 | /* | 
|  | 9617 | * when driver supports fils-sk offload all attributes must be | 
|  | 9618 | * provided. So the else covers "fils-sk-not-all" and | 
|  | 9619 | * "no-fils-sk-any". | 
|  | 9620 | */ | 
|  | 9621 | if (fils_sk_offload && | 
|  | 9622 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | 
|  | 9623 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | 
|  | 9624 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | 
|  | 9625 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | 
|  | 9626 | connect.fils_erp_username = | 
|  | 9627 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | 
|  | 9628 | connect.fils_erp_username_len = | 
|  | 9629 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | 
|  | 9630 | connect.fils_erp_realm = | 
|  | 9631 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | 
|  | 9632 | connect.fils_erp_realm_len = | 
|  | 9633 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | 
|  | 9634 | connect.fils_erp_next_seq_num = | 
|  | 9635 | nla_get_u16( | 
|  | 9636 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | 
|  | 9637 | connect.fils_erp_rrk = | 
|  | 9638 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | 
|  | 9639 | connect.fils_erp_rrk_len = | 
|  | 9640 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | 
|  | 9641 | changed |= UPDATE_FILS_ERP_INFO; | 
|  | 9642 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | 
|  | 9643 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | 
|  | 9644 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | 
|  | 9645 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | 
|  | 9646 | return -EINVAL; | 
|  | 9647 | } | 
|  | 9648 |  | 
|  | 9649 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | 
|  | 9650 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
|  | 9651 | if (!nl80211_valid_auth_type(rdev, auth_type, | 
|  | 9652 | NL80211_CMD_CONNECT)) | 
|  | 9653 | return -EINVAL; | 
|  | 9654 |  | 
|  | 9655 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && | 
|  | 9656 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) | 
|  | 9657 | return -EINVAL; | 
|  | 9658 |  | 
|  | 9659 | connect.auth_type = auth_type; | 
|  | 9660 | changed |= UPDATE_AUTH_TYPE; | 
|  | 9661 | } | 
|  | 9662 |  | 
|  | 9663 | wdev_lock(dev->ieee80211_ptr); | 
|  | 9664 | if (!wdev->current_bss) | 
|  | 9665 | ret = -ENOLINK; | 
|  | 9666 | else | 
|  | 9667 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); | 
|  | 9668 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 9669 |  | 
|  | 9670 | return ret; | 
|  | 9671 | } | 
|  | 9672 |  | 
|  | 9673 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | 
|  | 9674 | { | 
|  | 9675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9676 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9677 | u16 reason; | 
|  | 9678 | int ret; | 
|  | 9679 |  | 
|  | 9680 | if (dev->ieee80211_ptr->conn_owner_nlportid && | 
|  | 9681 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) | 
|  | 9682 | return -EPERM; | 
|  | 9683 |  | 
|  | 9684 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 
|  | 9685 | reason = WLAN_REASON_DEAUTH_LEAVING; | 
|  | 9686 | else | 
|  | 9687 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
|  | 9688 |  | 
|  | 9689 | if (reason == 0) | 
|  | 9690 | return -EINVAL; | 
|  | 9691 |  | 
|  | 9692 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 9693 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 9694 | return -EOPNOTSUPP; | 
|  | 9695 |  | 
|  | 9696 | wdev_lock(dev->ieee80211_ptr); | 
|  | 9697 | ret = cfg80211_disconnect(rdev, dev, reason, true); | 
|  | 9698 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 9699 | return ret; | 
|  | 9700 | } | 
|  | 9701 |  | 
|  | 9702 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) | 
|  | 9703 | { | 
|  | 9704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9705 | struct net *net; | 
|  | 9706 | int err; | 
|  | 9707 |  | 
|  | 9708 | if (info->attrs[NL80211_ATTR_PID]) { | 
|  | 9709 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | 
|  | 9710 |  | 
|  | 9711 | net = get_net_ns_by_pid(pid); | 
|  | 9712 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | 
|  | 9713 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | 
|  | 9714 |  | 
|  | 9715 | net = get_net_ns_by_fd(fd); | 
|  | 9716 | } else { | 
|  | 9717 | return -EINVAL; | 
|  | 9718 | } | 
|  | 9719 |  | 
|  | 9720 | if (IS_ERR(net)) | 
|  | 9721 | return PTR_ERR(net); | 
|  | 9722 |  | 
|  | 9723 | err = 0; | 
|  | 9724 |  | 
|  | 9725 | /* check if anything to do */ | 
|  | 9726 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) | 
|  | 9727 | err = cfg80211_switch_netns(rdev, net); | 
|  | 9728 |  | 
|  | 9729 | put_net(net); | 
|  | 9730 | return err; | 
|  | 9731 | } | 
|  | 9732 |  | 
|  | 9733 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) | 
|  | 9734 | { | 
|  | 9735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9736 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, | 
|  | 9737 | struct cfg80211_pmksa *pmksa) = NULL; | 
|  | 9738 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9739 | struct cfg80211_pmksa pmksa; | 
|  | 9740 |  | 
|  | 9741 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | 
|  | 9742 |  | 
|  | 9743 | if (!info->attrs[NL80211_ATTR_PMKID]) | 
|  | 9744 | return -EINVAL; | 
|  | 9745 |  | 
|  | 9746 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | 
|  | 9747 |  | 
|  | 9748 | if (info->attrs[NL80211_ATTR_MAC]) { | 
|  | 9749 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 9750 | } else if (info->attrs[NL80211_ATTR_SSID] && | 
|  | 9751 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && | 
|  | 9752 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || | 
|  | 9753 | info->attrs[NL80211_ATTR_PMK])) { | 
|  | 9754 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
|  | 9755 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 9756 | pmksa.cache_id = | 
|  | 9757 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); | 
|  | 9758 | } else { | 
|  | 9759 | return -EINVAL; | 
|  | 9760 | } | 
|  | 9761 | if (info->attrs[NL80211_ATTR_PMK]) { | 
|  | 9762 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | 
|  | 9763 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | 
|  | 9764 | } | 
|  | 9765 |  | 
|  | 9766 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 9767 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 9768 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && | 
|  | 9769 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && | 
|  | 9770 | wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 9771 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) | 
|  | 9772 | return -EOPNOTSUPP; | 
|  | 9773 | //tianyan@2021.7.27 modify for add wifi6 module end | 
|  | 9774 |  | 
|  | 9775 | switch (info->genlhdr->cmd) { | 
|  | 9776 | case NL80211_CMD_SET_PMKSA: | 
|  | 9777 | rdev_ops = rdev->ops->set_pmksa; | 
|  | 9778 | break; | 
|  | 9779 | case NL80211_CMD_DEL_PMKSA: | 
|  | 9780 | rdev_ops = rdev->ops->del_pmksa; | 
|  | 9781 | break; | 
|  | 9782 | default: | 
|  | 9783 | WARN_ON(1); | 
|  | 9784 | break; | 
|  | 9785 | } | 
|  | 9786 |  | 
|  | 9787 | if (!rdev_ops) | 
|  | 9788 | return -EOPNOTSUPP; | 
|  | 9789 |  | 
|  | 9790 | return rdev_ops(&rdev->wiphy, dev, &pmksa); | 
|  | 9791 | } | 
|  | 9792 |  | 
|  | 9793 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | 
|  | 9794 | { | 
|  | 9795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9796 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9797 |  | 
|  | 9798 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
|  | 9799 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 9800 | return -EOPNOTSUPP; | 
|  | 9801 |  | 
|  | 9802 | if (!rdev->ops->flush_pmksa) | 
|  | 9803 | return -EOPNOTSUPP; | 
|  | 9804 |  | 
|  | 9805 | return rdev_flush_pmksa(rdev, dev); | 
|  | 9806 | } | 
|  | 9807 |  | 
|  | 9808 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) | 
|  | 9809 | { | 
|  | 9810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9811 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9812 | u8 action_code, dialog_token; | 
|  | 9813 | u32 peer_capability = 0; | 
|  | 9814 | u16 status_code; | 
|  | 9815 | u8 *peer; | 
|  | 9816 | bool initiator; | 
|  | 9817 |  | 
|  | 9818 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | 
|  | 9819 | !rdev->ops->tdls_mgmt) | 
|  | 9820 | return -EOPNOTSUPP; | 
|  | 9821 |  | 
|  | 9822 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | 
|  | 9823 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | 
|  | 9824 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | 
|  | 9825 | !info->attrs[NL80211_ATTR_IE] || | 
|  | 9826 | !info->attrs[NL80211_ATTR_MAC]) | 
|  | 9827 | return -EINVAL; | 
|  | 9828 |  | 
|  | 9829 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 9830 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | 
|  | 9831 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | 
|  | 9832 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | 
|  | 9833 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); | 
|  | 9834 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) | 
|  | 9835 | peer_capability = | 
|  | 9836 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | 
|  | 9837 |  | 
|  | 9838 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, | 
|  | 9839 | dialog_token, status_code, peer_capability, | 
|  | 9840 | initiator, | 
|  | 9841 | nla_data(info->attrs[NL80211_ATTR_IE]), | 
|  | 9842 | nla_len(info->attrs[NL80211_ATTR_IE])); | 
|  | 9843 | } | 
|  | 9844 |  | 
|  | 9845 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | 
|  | 9846 | { | 
|  | 9847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9848 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9849 | enum nl80211_tdls_operation operation; | 
|  | 9850 | u8 *peer; | 
|  | 9851 |  | 
|  | 9852 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | 
|  | 9853 | !rdev->ops->tdls_oper) | 
|  | 9854 | return -EOPNOTSUPP; | 
|  | 9855 |  | 
|  | 9856 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | 
|  | 9857 | !info->attrs[NL80211_ATTR_MAC]) | 
|  | 9858 | return -EINVAL; | 
|  | 9859 |  | 
|  | 9860 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | 
|  | 9861 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 9862 |  | 
|  | 9863 | return rdev_tdls_oper(rdev, dev, peer, operation); | 
|  | 9864 | } | 
|  | 9865 |  | 
|  | 9866 | static int nl80211_remain_on_channel(struct sk_buff *skb, | 
|  | 9867 | struct genl_info *info) | 
|  | 9868 | { | 
|  | 9869 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9870 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 9871 | struct cfg80211_chan_def chandef; | 
|  | 9872 | const struct cfg80211_chan_def *compat_chandef; | 
|  | 9873 | struct sk_buff *msg; | 
|  | 9874 | void *hdr; | 
|  | 9875 | u64 cookie; | 
|  | 9876 | u32 duration; | 
|  | 9877 | int err; | 
|  | 9878 |  | 
|  | 9879 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | 
|  | 9880 | !info->attrs[NL80211_ATTR_DURATION]) | 
|  | 9881 | return -EINVAL; | 
|  | 9882 |  | 
|  | 9883 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | 
|  | 9884 |  | 
|  | 9885 | if (!rdev->ops->remain_on_channel || | 
|  | 9886 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | 
|  | 9887 | return -EOPNOTSUPP; | 
|  | 9888 |  | 
|  | 9889 | /* | 
|  | 9890 | * We should be on that channel for at least a minimum amount of | 
|  | 9891 | * time (10ms) but no longer than the driver supports. | 
|  | 9892 | */ | 
|  | 9893 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | 
|  | 9894 | duration > rdev->wiphy.max_remain_on_channel_duration) | 
|  | 9895 | return -EINVAL; | 
|  | 9896 |  | 
|  | 9897 | err = nl80211_parse_chandef(rdev, info, &chandef); | 
|  | 9898 | if (err) | 
|  | 9899 | return err; | 
|  | 9900 |  | 
|  | 9901 | wdev_lock(wdev); | 
|  | 9902 | if (!cfg80211_off_channel_oper_allowed(wdev) && | 
|  | 9903 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { | 
|  | 9904 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, | 
|  | 9905 | &chandef); | 
|  | 9906 | if (compat_chandef != &chandef) { | 
|  | 9907 | wdev_unlock(wdev); | 
|  | 9908 | return -EBUSY; | 
|  | 9909 | } | 
|  | 9910 | } | 
|  | 9911 | wdev_unlock(wdev); | 
|  | 9912 |  | 
|  | 9913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 9914 | if (!msg) | 
|  | 9915 | return -ENOMEM; | 
|  | 9916 |  | 
|  | 9917 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 9918 | NL80211_CMD_REMAIN_ON_CHANNEL); | 
|  | 9919 | if (!hdr) { | 
|  | 9920 | err = -ENOBUFS; | 
|  | 9921 | goto free_msg; | 
|  | 9922 | } | 
|  | 9923 |  | 
|  | 9924 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, | 
|  | 9925 | duration, &cookie); | 
|  | 9926 |  | 
|  | 9927 | if (err) | 
|  | 9928 | goto free_msg; | 
|  | 9929 |  | 
|  | 9930 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 9931 | NL80211_ATTR_PAD)) | 
|  | 9932 | goto nla_put_failure; | 
|  | 9933 |  | 
|  | 9934 | genlmsg_end(msg, hdr); | 
|  | 9935 |  | 
|  | 9936 | return genlmsg_reply(msg, info); | 
|  | 9937 |  | 
|  | 9938 | nla_put_failure: | 
|  | 9939 | err = -ENOBUFS; | 
|  | 9940 | free_msg: | 
|  | 9941 | nlmsg_free(msg); | 
|  | 9942 | return err; | 
|  | 9943 | } | 
|  | 9944 |  | 
|  | 9945 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | 
|  | 9946 | struct genl_info *info) | 
|  | 9947 | { | 
|  | 9948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9949 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 9950 | u64 cookie; | 
|  | 9951 |  | 
|  | 9952 | if (!info->attrs[NL80211_ATTR_COOKIE]) | 
|  | 9953 | return -EINVAL; | 
|  | 9954 |  | 
|  | 9955 | if (!rdev->ops->cancel_remain_on_channel) | 
|  | 9956 | return -EOPNOTSUPP; | 
|  | 9957 |  | 
|  | 9958 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 
|  | 9959 |  | 
|  | 9960 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); | 
|  | 9961 | } | 
|  | 9962 |  | 
|  | 9963 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | 
|  | 9964 | struct genl_info *info) | 
|  | 9965 | { | 
|  | 9966 | struct cfg80211_bitrate_mask mask; | 
|  | 9967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9968 | struct net_device *dev = info->user_ptr[1]; | 
|  | 9969 | int err; | 
|  | 9970 |  | 
|  | 9971 | if (!rdev->ops->set_bitrate_mask) | 
|  | 9972 | return -EOPNOTSUPP; | 
|  | 9973 |  | 
|  | 9974 | err = nl80211_parse_tx_bitrate_mask(info, &mask); | 
|  | 9975 | if (err) | 
|  | 9976 | return err; | 
|  | 9977 |  | 
|  | 9978 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); | 
|  | 9979 | } | 
|  | 9980 |  | 
|  | 9981 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) | 
|  | 9982 | { | 
|  | 9983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 9984 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 9985 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; | 
|  | 9986 |  | 
|  | 9987 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | 
|  | 9988 | return -EINVAL; | 
|  | 9989 |  | 
|  | 9990 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) | 
|  | 9991 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | 
|  | 9992 |  | 
|  | 9993 | switch (wdev->iftype) { | 
|  | 9994 | case NL80211_IFTYPE_STATION: | 
|  | 9995 | case NL80211_IFTYPE_ADHOC: | 
|  | 9996 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 9997 | case NL80211_IFTYPE_AP: | 
|  | 9998 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 9999 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 10000 | case NL80211_IFTYPE_P2P_GO: | 
|  | 10001 | case NL80211_IFTYPE_P2P_DEVICE: | 
|  | 10002 | break; | 
|  | 10003 | case NL80211_IFTYPE_NAN: | 
|  | 10004 | default: | 
|  | 10005 | return -EOPNOTSUPP; | 
|  | 10006 | } | 
|  | 10007 |  | 
|  | 10008 | /* not much point in registering if we can't reply */ | 
|  | 10009 | if (!rdev->ops->mgmt_tx) | 
|  | 10010 | return -EOPNOTSUPP; | 
|  | 10011 |  | 
|  | 10012 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, | 
|  | 10013 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), | 
|  | 10014 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | 
|  | 10015 | } | 
|  | 10016 |  | 
|  | 10017 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) | 
|  | 10018 | { | 
|  | 10019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10020 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 10021 | struct cfg80211_chan_def chandef; | 
|  | 10022 | int err; | 
|  | 10023 | void *hdr = NULL; | 
|  | 10024 | u64 cookie; | 
|  | 10025 | struct sk_buff *msg = NULL; | 
|  | 10026 | struct cfg80211_mgmt_tx_params params = { | 
|  | 10027 | .dont_wait_for_ack = | 
|  | 10028 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | 
|  | 10029 | }; | 
|  | 10030 |  | 
|  | 10031 | if (!info->attrs[NL80211_ATTR_FRAME]) | 
|  | 10032 | return -EINVAL; | 
|  | 10033 |  | 
|  | 10034 | if (!rdev->ops->mgmt_tx) | 
|  | 10035 | return -EOPNOTSUPP; | 
|  | 10036 |  | 
|  | 10037 | switch (wdev->iftype) { | 
|  | 10038 | case NL80211_IFTYPE_P2P_DEVICE: | 
|  | 10039 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
|  | 10040 | return -EINVAL; | 
|  | 10041 | case NL80211_IFTYPE_STATION: | 
|  | 10042 | case NL80211_IFTYPE_ADHOC: | 
|  | 10043 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 10044 | case NL80211_IFTYPE_AP: | 
|  | 10045 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 10046 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 10047 | case NL80211_IFTYPE_P2P_GO: | 
|  | 10048 | break; | 
|  | 10049 | case NL80211_IFTYPE_NAN: | 
|  | 10050 | default: | 
|  | 10051 | return -EOPNOTSUPP; | 
|  | 10052 | } | 
|  | 10053 |  | 
|  | 10054 | if (info->attrs[NL80211_ATTR_DURATION]) { | 
|  | 10055 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) | 
|  | 10056 | return -EINVAL; | 
|  | 10057 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | 
|  | 10058 |  | 
|  | 10059 | /* | 
|  | 10060 | * We should wait on the channel for at least a minimum amount | 
|  | 10061 | * of time (10ms) but no longer than the driver supports. | 
|  | 10062 | */ | 
|  | 10063 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | 
|  | 10064 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | 
|  | 10065 | return -EINVAL; | 
|  | 10066 | } | 
|  | 10067 |  | 
|  | 10068 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; | 
|  | 10069 |  | 
|  | 10070 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) | 
|  | 10071 | return -EINVAL; | 
|  | 10072 |  | 
|  | 10073 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | 
|  | 10074 |  | 
|  | 10075 | /* get the channel if any has been specified, otherwise pass NULL to | 
|  | 10076 | * the driver. The latter will use the current one | 
|  | 10077 | */ | 
|  | 10078 | chandef.chan = NULL; | 
|  | 10079 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
|  | 10080 | err = nl80211_parse_chandef(rdev, info, &chandef); | 
|  | 10081 | if (err) | 
|  | 10082 | return err; | 
|  | 10083 | } | 
|  | 10084 |  | 
|  | 10085 | if (!chandef.chan && params.offchan) | 
|  | 10086 | return -EINVAL; | 
|  | 10087 |  | 
|  | 10088 | wdev_lock(wdev); | 
|  | 10089 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { | 
|  | 10090 | wdev_unlock(wdev); | 
|  | 10091 | return -EBUSY; | 
|  | 10092 | } | 
|  | 10093 | wdev_unlock(wdev); | 
|  | 10094 |  | 
|  | 10095 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | 
|  | 10096 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | 
|  | 10097 |  | 
|  | 10098 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | 
|  | 10099 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | 
|  | 10100 | int i; | 
|  | 10101 |  | 
|  | 10102 | if (len % sizeof(u16)) | 
|  | 10103 | return -EINVAL; | 
|  | 10104 |  | 
|  | 10105 | params.n_csa_offsets = len / sizeof(u16); | 
|  | 10106 | params.csa_offsets = | 
|  | 10107 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | 
|  | 10108 |  | 
|  | 10109 | /* check that all the offsets fit the frame */ | 
|  | 10110 | for (i = 0; i < params.n_csa_offsets; i++) { | 
|  | 10111 | if (params.csa_offsets[i] >= params.len) | 
|  | 10112 | return -EINVAL; | 
|  | 10113 | } | 
|  | 10114 | } | 
|  | 10115 |  | 
|  | 10116 | if (!params.dont_wait_for_ack) { | 
|  | 10117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 10118 | if (!msg) | 
|  | 10119 | return -ENOMEM; | 
|  | 10120 |  | 
|  | 10121 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 10122 | NL80211_CMD_FRAME); | 
|  | 10123 | if (!hdr) { | 
|  | 10124 | err = -ENOBUFS; | 
|  | 10125 | goto free_msg; | 
|  | 10126 | } | 
|  | 10127 | } | 
|  | 10128 |  | 
|  | 10129 | params.chan = chandef.chan; | 
|  | 10130 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | 
|  | 10131 | if (err) | 
|  | 10132 | goto free_msg; | 
|  | 10133 |  | 
|  | 10134 | if (msg) { | 
|  | 10135 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 10136 | NL80211_ATTR_PAD)) | 
|  | 10137 | goto nla_put_failure; | 
|  | 10138 |  | 
|  | 10139 | genlmsg_end(msg, hdr); | 
|  | 10140 | return genlmsg_reply(msg, info); | 
|  | 10141 | } | 
|  | 10142 |  | 
|  | 10143 | return 0; | 
|  | 10144 |  | 
|  | 10145 | nla_put_failure: | 
|  | 10146 | err = -ENOBUFS; | 
|  | 10147 | free_msg: | 
|  | 10148 | nlmsg_free(msg); | 
|  | 10149 | return err; | 
|  | 10150 | } | 
|  | 10151 |  | 
|  | 10152 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) | 
|  | 10153 | { | 
|  | 10154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10155 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 10156 | u64 cookie; | 
|  | 10157 |  | 
|  | 10158 | if (!info->attrs[NL80211_ATTR_COOKIE]) | 
|  | 10159 | return -EINVAL; | 
|  | 10160 |  | 
|  | 10161 | if (!rdev->ops->mgmt_tx_cancel_wait) | 
|  | 10162 | return -EOPNOTSUPP; | 
|  | 10163 |  | 
|  | 10164 | switch (wdev->iftype) { | 
|  | 10165 | case NL80211_IFTYPE_STATION: | 
|  | 10166 | case NL80211_IFTYPE_ADHOC: | 
|  | 10167 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 10168 | case NL80211_IFTYPE_AP: | 
|  | 10169 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 10170 | case NL80211_IFTYPE_P2P_GO: | 
|  | 10171 | case NL80211_IFTYPE_P2P_DEVICE: | 
|  | 10172 | break; | 
|  | 10173 | case NL80211_IFTYPE_NAN: | 
|  | 10174 | default: | 
|  | 10175 | return -EOPNOTSUPP; | 
|  | 10176 | } | 
|  | 10177 |  | 
|  | 10178 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 
|  | 10179 |  | 
|  | 10180 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); | 
|  | 10181 | } | 
|  | 10182 |  | 
|  | 10183 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) | 
|  | 10184 | { | 
|  | 10185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10186 | struct wireless_dev *wdev; | 
|  | 10187 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10188 | u8 ps_state; | 
|  | 10189 | bool state; | 
|  | 10190 | int err; | 
|  | 10191 |  | 
|  | 10192 | if (!info->attrs[NL80211_ATTR_PS_STATE]) | 
|  | 10193 | return -EINVAL; | 
|  | 10194 |  | 
|  | 10195 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | 
|  | 10196 |  | 
|  | 10197 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) | 
|  | 10198 | return -EINVAL; | 
|  | 10199 |  | 
|  | 10200 | wdev = dev->ieee80211_ptr; | 
|  | 10201 |  | 
|  | 10202 | if (!rdev->ops->set_power_mgmt) | 
|  | 10203 | return -EOPNOTSUPP; | 
|  | 10204 |  | 
|  | 10205 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | 
|  | 10206 |  | 
|  | 10207 | if (state == wdev->ps) | 
|  | 10208 | return 0; | 
|  | 10209 |  | 
|  | 10210 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); | 
|  | 10211 | if (!err) | 
|  | 10212 | wdev->ps = state; | 
|  | 10213 | return err; | 
|  | 10214 | } | 
|  | 10215 |  | 
|  | 10216 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | 
|  | 10217 | { | 
|  | 10218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10219 | enum nl80211_ps_state ps_state; | 
|  | 10220 | struct wireless_dev *wdev; | 
|  | 10221 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10222 | struct sk_buff *msg; | 
|  | 10223 | void *hdr; | 
|  | 10224 | int err; | 
|  | 10225 |  | 
|  | 10226 | wdev = dev->ieee80211_ptr; | 
|  | 10227 |  | 
|  | 10228 | if (!rdev->ops->set_power_mgmt) | 
|  | 10229 | return -EOPNOTSUPP; | 
|  | 10230 |  | 
|  | 10231 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 10232 | if (!msg) | 
|  | 10233 | return -ENOMEM; | 
|  | 10234 |  | 
|  | 10235 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 10236 | NL80211_CMD_GET_POWER_SAVE); | 
|  | 10237 | if (!hdr) { | 
|  | 10238 | err = -ENOBUFS; | 
|  | 10239 | goto free_msg; | 
|  | 10240 | } | 
|  | 10241 |  | 
|  | 10242 | if (wdev->ps) | 
|  | 10243 | ps_state = NL80211_PS_ENABLED; | 
|  | 10244 | else | 
|  | 10245 | ps_state = NL80211_PS_DISABLED; | 
|  | 10246 |  | 
|  | 10247 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) | 
|  | 10248 | goto nla_put_failure; | 
|  | 10249 |  | 
|  | 10250 | genlmsg_end(msg, hdr); | 
|  | 10251 | return genlmsg_reply(msg, info); | 
|  | 10252 |  | 
|  | 10253 | nla_put_failure: | 
|  | 10254 | err = -ENOBUFS; | 
|  | 10255 | free_msg: | 
|  | 10256 | nlmsg_free(msg); | 
|  | 10257 | return err; | 
|  | 10258 | } | 
|  | 10259 |  | 
|  | 10260 | static const struct nla_policy | 
|  | 10261 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | 
|  | 10262 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, | 
|  | 10263 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | 
|  | 10264 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | 
|  | 10265 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, | 
|  | 10266 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | 
|  | 10267 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | 
|  | 10268 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, | 
|  | 10269 | }; | 
|  | 10270 |  | 
|  | 10271 | static int nl80211_set_cqm_txe(struct genl_info *info, | 
|  | 10272 | u32 rate, u32 pkts, u32 intvl) | 
|  | 10273 | { | 
|  | 10274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10275 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10276 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 10277 |  | 
|  | 10278 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) | 
|  | 10279 | return -EINVAL; | 
|  | 10280 |  | 
|  | 10281 | if (!rdev->ops->set_cqm_txe_config) | 
|  | 10282 | return -EOPNOTSUPP; | 
|  | 10283 |  | 
|  | 10284 | if (wdev->iftype != NL80211_IFTYPE_STATION && | 
|  | 10285 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 10286 | return -EOPNOTSUPP; | 
|  | 10287 |  | 
|  | 10288 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); | 
|  | 10289 | } | 
|  | 10290 |  | 
|  | 10291 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, | 
|  | 10292 | struct net_device *dev) | 
|  | 10293 | { | 
|  | 10294 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 10295 | s32 last, low, high; | 
|  | 10296 | u32 hyst; | 
|  | 10297 | int i, n, low_index; | 
|  | 10298 | int err; | 
|  | 10299 |  | 
|  | 10300 | /* RSSI reporting disabled? */ | 
|  | 10301 | if (!wdev->cqm_config) | 
|  | 10302 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); | 
|  | 10303 |  | 
|  | 10304 | /* | 
|  | 10305 | * Obtain current RSSI value if possible, if not and no RSSI threshold | 
|  | 10306 | * event has been received yet, we should receive an event after a | 
|  | 10307 | * connection is established and enough beacons received to calculate | 
|  | 10308 | * the average. | 
|  | 10309 | */ | 
|  | 10310 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && | 
|  | 10311 | rdev->ops->get_station) { | 
|  | 10312 | struct station_info sinfo = {}; | 
|  | 10313 | u8 *mac_addr; | 
|  | 10314 |  | 
|  | 10315 | mac_addr = wdev->current_bss->pub.bssid; | 
|  | 10316 |  | 
|  | 10317 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); | 
|  | 10318 | if (err) | 
|  | 10319 | return err; | 
|  | 10320 |  | 
|  | 10321 | cfg80211_sinfo_release_content(&sinfo); | 
|  | 10322 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) | 
|  | 10323 | wdev->cqm_config->last_rssi_event_value = | 
|  | 10324 | (s8) sinfo.rx_beacon_signal_avg; | 
|  | 10325 | } | 
|  | 10326 |  | 
|  | 10327 | last = wdev->cqm_config->last_rssi_event_value; | 
|  | 10328 | hyst = wdev->cqm_config->rssi_hyst; | 
|  | 10329 | n = wdev->cqm_config->n_rssi_thresholds; | 
|  | 10330 |  | 
|  | 10331 | for (i = 0; i < n; i++) { | 
|  | 10332 | i = array_index_nospec(i, n); | 
|  | 10333 | if (last < wdev->cqm_config->rssi_thresholds[i]) | 
|  | 10334 | break; | 
|  | 10335 | } | 
|  | 10336 |  | 
|  | 10337 | low_index = i - 1; | 
|  | 10338 | if (low_index >= 0) { | 
|  | 10339 | low_index = array_index_nospec(low_index, n); | 
|  | 10340 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; | 
|  | 10341 | } else { | 
|  | 10342 | low = S32_MIN; | 
|  | 10343 | } | 
|  | 10344 | if (i < n) { | 
|  | 10345 | i = array_index_nospec(i, n); | 
|  | 10346 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; | 
|  | 10347 | } else { | 
|  | 10348 | high = S32_MAX; | 
|  | 10349 | } | 
|  | 10350 |  | 
|  | 10351 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); | 
|  | 10352 | } | 
|  | 10353 |  | 
|  | 10354 | static int nl80211_set_cqm_rssi(struct genl_info *info, | 
|  | 10355 | const s32 *thresholds, int n_thresholds, | 
|  | 10356 | u32 hysteresis) | 
|  | 10357 | { | 
|  | 10358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10359 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10360 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 10361 | int i, err; | 
|  | 10362 | s32 prev = S32_MIN; | 
|  | 10363 |  | 
|  | 10364 | /* Check all values negative and sorted */ | 
|  | 10365 | for (i = 0; i < n_thresholds; i++) { | 
|  | 10366 | if (thresholds[i] > 0 || thresholds[i] <= prev) | 
|  | 10367 | return -EINVAL; | 
|  | 10368 |  | 
|  | 10369 | prev = thresholds[i]; | 
|  | 10370 | } | 
|  | 10371 |  | 
|  | 10372 | if (wdev->iftype != NL80211_IFTYPE_STATION && | 
|  | 10373 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 10374 | return -EOPNOTSUPP; | 
|  | 10375 |  | 
|  | 10376 | wdev_lock(wdev); | 
|  | 10377 | cfg80211_cqm_config_free(wdev); | 
|  | 10378 | wdev_unlock(wdev); | 
|  | 10379 |  | 
|  | 10380 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { | 
|  | 10381 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ | 
|  | 10382 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); | 
|  | 10383 |  | 
|  | 10384 | return rdev_set_cqm_rssi_config(rdev, dev, | 
|  | 10385 | thresholds[0], hysteresis); | 
|  | 10386 | } | 
|  | 10387 |  | 
|  | 10388 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 10389 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) | 
|  | 10390 | return -EOPNOTSUPP; | 
|  | 10391 |  | 
|  | 10392 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ | 
|  | 10393 | n_thresholds = 0; | 
|  | 10394 |  | 
|  | 10395 | wdev_lock(wdev); | 
|  | 10396 | if (n_thresholds) { | 
|  | 10397 | struct cfg80211_cqm_config *cqm_config; | 
|  | 10398 |  | 
|  | 10399 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + | 
|  | 10400 | n_thresholds * sizeof(s32), GFP_KERNEL); | 
|  | 10401 | if (!cqm_config) { | 
|  | 10402 | err = -ENOMEM; | 
|  | 10403 | goto unlock; | 
|  | 10404 | } | 
|  | 10405 |  | 
|  | 10406 | cqm_config->rssi_hyst = hysteresis; | 
|  | 10407 | cqm_config->n_rssi_thresholds = n_thresholds; | 
|  | 10408 | memcpy(cqm_config->rssi_thresholds, thresholds, | 
|  | 10409 | n_thresholds * sizeof(s32)); | 
|  | 10410 |  | 
|  | 10411 | wdev->cqm_config = cqm_config; | 
|  | 10412 | } | 
|  | 10413 |  | 
|  | 10414 | err = cfg80211_cqm_rssi_update(rdev, dev); | 
|  | 10415 |  | 
|  | 10416 | unlock: | 
|  | 10417 | wdev_unlock(wdev); | 
|  | 10418 |  | 
|  | 10419 | return err; | 
|  | 10420 | } | 
|  | 10421 |  | 
|  | 10422 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | 
|  | 10423 | { | 
|  | 10424 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | 
|  | 10425 | struct nlattr *cqm; | 
|  | 10426 | int err; | 
|  | 10427 |  | 
|  | 10428 | cqm = info->attrs[NL80211_ATTR_CQM]; | 
|  | 10429 | if (!cqm) | 
|  | 10430 | return -EINVAL; | 
|  | 10431 |  | 
|  | 10432 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | 
|  | 10433 | nl80211_attr_cqm_policy, info->extack); | 
|  | 10434 | if (err) | 
|  | 10435 | return err; | 
|  | 10436 |  | 
|  | 10437 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | 
|  | 10438 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | 
|  | 10439 | const s32 *thresholds = | 
|  | 10440 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | 
|  | 10441 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | 
|  | 10442 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | 
|  | 10443 |  | 
|  | 10444 | if (len % 4) | 
|  | 10445 | return -EINVAL; | 
|  | 10446 |  | 
|  | 10447 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, | 
|  | 10448 | hysteresis); | 
|  | 10449 | } | 
|  | 10450 |  | 
|  | 10451 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | 
|  | 10452 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | 
|  | 10453 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | 
|  | 10454 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | 
|  | 10455 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | 
|  | 10456 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | 
|  | 10457 |  | 
|  | 10458 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | 
|  | 10459 | } | 
|  | 10460 |  | 
|  | 10461 | return -EINVAL; | 
|  | 10462 | } | 
|  | 10463 |  | 
|  | 10464 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) | 
|  | 10465 | { | 
|  | 10466 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10467 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10468 | struct ocb_setup setup = {}; | 
|  | 10469 | int err; | 
|  | 10470 |  | 
|  | 10471 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | 
|  | 10472 | if (err) | 
|  | 10473 | return err; | 
|  | 10474 |  | 
|  | 10475 | return cfg80211_join_ocb(rdev, dev, &setup); | 
|  | 10476 | } | 
|  | 10477 |  | 
|  | 10478 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | 
|  | 10479 | { | 
|  | 10480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10481 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10482 |  | 
|  | 10483 | return cfg80211_leave_ocb(rdev, dev); | 
|  | 10484 | } | 
|  | 10485 |  | 
|  | 10486 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) | 
|  | 10487 | { | 
|  | 10488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10489 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10490 | struct mesh_config cfg; | 
|  | 10491 | struct mesh_setup setup; | 
|  | 10492 | int err; | 
|  | 10493 |  | 
|  | 10494 | /* start with default */ | 
|  | 10495 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | 
|  | 10496 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); | 
|  | 10497 |  | 
|  | 10498 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { | 
|  | 10499 | /* and parse parameters if given */ | 
|  | 10500 | err = nl80211_parse_mesh_config(info, &cfg, NULL); | 
|  | 10501 | if (err) | 
|  | 10502 | return err; | 
|  | 10503 | } | 
|  | 10504 |  | 
|  | 10505 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | 
|  | 10506 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | 
|  | 10507 | return -EINVAL; | 
|  | 10508 |  | 
|  | 10509 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | 
|  | 10510 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 
|  | 10511 |  | 
|  | 10512 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | 
|  | 10513 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | 
|  | 10514 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | 
|  | 10515 | return -EINVAL; | 
|  | 10516 |  | 
|  | 10517 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | 
|  | 10518 | setup.beacon_interval = | 
|  | 10519 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | 
|  | 10520 |  | 
|  | 10521 | err = cfg80211_validate_beacon_int(rdev, | 
|  | 10522 | NL80211_IFTYPE_MESH_POINT, | 
|  | 10523 | setup.beacon_interval); | 
|  | 10524 | if (err) | 
|  | 10525 | return err; | 
|  | 10526 | } | 
|  | 10527 |  | 
|  | 10528 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | 
|  | 10529 | setup.dtim_period = | 
|  | 10530 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | 
|  | 10531 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | 
|  | 10532 | return -EINVAL; | 
|  | 10533 | } | 
|  | 10534 |  | 
|  | 10535 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { | 
|  | 10536 | /* parse additional setup parameters if given */ | 
|  | 10537 | err = nl80211_parse_mesh_setup(info, &setup); | 
|  | 10538 | if (err) | 
|  | 10539 | return err; | 
|  | 10540 | } | 
|  | 10541 |  | 
|  | 10542 | if (setup.user_mpm) | 
|  | 10543 | cfg.auto_open_plinks = false; | 
|  | 10544 |  | 
|  | 10545 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
|  | 10546 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | 
|  | 10547 | if (err) | 
|  | 10548 | return err; | 
|  | 10549 | } else { | 
|  | 10550 | /* __cfg80211_join_mesh() will sort it out */ | 
|  | 10551 | setup.chandef.chan = NULL; | 
|  | 10552 | } | 
|  | 10553 |  | 
|  | 10554 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 
|  | 10555 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
|  | 10556 | int n_rates = | 
|  | 10557 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
|  | 10558 | struct ieee80211_supported_band *sband; | 
|  | 10559 |  | 
|  | 10560 | if (!setup.chandef.chan) | 
|  | 10561 | return -EINVAL; | 
|  | 10562 |  | 
|  | 10563 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | 
|  | 10564 |  | 
|  | 10565 | err = ieee80211_get_ratemask(sband, rates, n_rates, | 
|  | 10566 | &setup.basic_rates); | 
|  | 10567 | if (err) | 
|  | 10568 | return err; | 
|  | 10569 | } | 
|  | 10570 |  | 
|  | 10571 | if (info->attrs[NL80211_ATTR_TX_RATES]) { | 
|  | 10572 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); | 
|  | 10573 | if (err) | 
|  | 10574 | return err; | 
|  | 10575 |  | 
|  | 10576 | if (!setup.chandef.chan) | 
|  | 10577 | return -EINVAL; | 
|  | 10578 |  | 
|  | 10579 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, | 
|  | 10580 | &setup.beacon_rate); | 
|  | 10581 | if (err) | 
|  | 10582 | return err; | 
|  | 10583 | } | 
|  | 10584 |  | 
|  | 10585 | setup.userspace_handles_dfs = | 
|  | 10586 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | 
|  | 10587 |  | 
|  | 10588 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { | 
|  | 10589 | int r = validate_pae_over_nl80211(rdev, info); | 
|  | 10590 |  | 
|  | 10591 | if (r < 0) | 
|  | 10592 | return r; | 
|  | 10593 |  | 
|  | 10594 | setup.control_port_over_nl80211 = true; | 
|  | 10595 | } | 
|  | 10596 |  | 
|  | 10597 | wdev_lock(dev->ieee80211_ptr); | 
|  | 10598 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); | 
|  | 10599 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
|  | 10600 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | 
|  | 10601 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 10602 |  | 
|  | 10603 | return err; | 
|  | 10604 | } | 
|  | 10605 |  | 
|  | 10606 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | 
|  | 10607 | { | 
|  | 10608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10609 | struct net_device *dev = info->user_ptr[1]; | 
|  | 10610 |  | 
|  | 10611 | return cfg80211_leave_mesh(rdev, dev); | 
|  | 10612 | } | 
|  | 10613 |  | 
|  | 10614 | #ifdef CONFIG_PM | 
|  | 10615 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, | 
|  | 10616 | struct cfg80211_registered_device *rdev) | 
|  | 10617 | { | 
|  | 10618 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; | 
|  | 10619 | struct nlattr *nl_pats, *nl_pat; | 
|  | 10620 | int i, pat_len; | 
|  | 10621 |  | 
|  | 10622 | if (!wowlan->n_patterns) | 
|  | 10623 | return 0; | 
|  | 10624 |  | 
|  | 10625 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | 
|  | 10626 | if (!nl_pats) | 
|  | 10627 | return -ENOBUFS; | 
|  | 10628 |  | 
|  | 10629 | for (i = 0; i < wowlan->n_patterns; i++) { | 
|  | 10630 | nl_pat = nla_nest_start(msg, i + 1); | 
|  | 10631 | if (!nl_pat) | 
|  | 10632 | return -ENOBUFS; | 
|  | 10633 | pat_len = wowlan->patterns[i].pattern_len; | 
|  | 10634 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), | 
|  | 10635 | wowlan->patterns[i].mask) || | 
|  | 10636 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | 
|  | 10637 | wowlan->patterns[i].pattern) || | 
|  | 10638 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | 
|  | 10639 | wowlan->patterns[i].pkt_offset)) | 
|  | 10640 | return -ENOBUFS; | 
|  | 10641 | nla_nest_end(msg, nl_pat); | 
|  | 10642 | } | 
|  | 10643 | nla_nest_end(msg, nl_pats); | 
|  | 10644 |  | 
|  | 10645 | return 0; | 
|  | 10646 | } | 
|  | 10647 |  | 
|  | 10648 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, | 
|  | 10649 | struct cfg80211_wowlan_tcp *tcp) | 
|  | 10650 | { | 
|  | 10651 | struct nlattr *nl_tcp; | 
|  | 10652 |  | 
|  | 10653 | if (!tcp) | 
|  | 10654 | return 0; | 
|  | 10655 |  | 
|  | 10656 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | 
|  | 10657 | if (!nl_tcp) | 
|  | 10658 | return -ENOBUFS; | 
|  | 10659 |  | 
|  | 10660 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | 
|  | 10661 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | 
|  | 10662 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | 
|  | 10663 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | 
|  | 10664 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | 
|  | 10665 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | 
|  | 10666 | tcp->payload_len, tcp->payload) || | 
|  | 10667 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | 
|  | 10668 | tcp->data_interval) || | 
|  | 10669 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | 
|  | 10670 | tcp->wake_len, tcp->wake_data) || | 
|  | 10671 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | 
|  | 10672 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | 
|  | 10673 | return -ENOBUFS; | 
|  | 10674 |  | 
|  | 10675 | if (tcp->payload_seq.len && | 
|  | 10676 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | 
|  | 10677 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | 
|  | 10678 | return -ENOBUFS; | 
|  | 10679 |  | 
|  | 10680 | if (tcp->payload_tok.len && | 
|  | 10681 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | 
|  | 10682 | sizeof(tcp->payload_tok) + tcp->tokens_size, | 
|  | 10683 | &tcp->payload_tok)) | 
|  | 10684 | return -ENOBUFS; | 
|  | 10685 |  | 
|  | 10686 | nla_nest_end(msg, nl_tcp); | 
|  | 10687 |  | 
|  | 10688 | return 0; | 
|  | 10689 | } | 
|  | 10690 |  | 
|  | 10691 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, | 
|  | 10692 | struct cfg80211_sched_scan_request *req) | 
|  | 10693 | { | 
|  | 10694 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; | 
|  | 10695 | int i; | 
|  | 10696 |  | 
|  | 10697 | if (!req) | 
|  | 10698 | return 0; | 
|  | 10699 |  | 
|  | 10700 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | 
|  | 10701 | if (!nd) | 
|  | 10702 | return -ENOBUFS; | 
|  | 10703 |  | 
|  | 10704 | if (req->n_scan_plans == 1 && | 
|  | 10705 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | 
|  | 10706 | req->scan_plans[0].interval * 1000)) | 
|  | 10707 | return -ENOBUFS; | 
|  | 10708 |  | 
|  | 10709 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) | 
|  | 10710 | return -ENOBUFS; | 
|  | 10711 |  | 
|  | 10712 | if (req->relative_rssi_set) { | 
|  | 10713 | struct nl80211_bss_select_rssi_adjust rssi_adjust; | 
|  | 10714 |  | 
|  | 10715 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, | 
|  | 10716 | req->relative_rssi)) | 
|  | 10717 | return -ENOBUFS; | 
|  | 10718 |  | 
|  | 10719 | rssi_adjust.band = req->rssi_adjust.band; | 
|  | 10720 | rssi_adjust.delta = req->rssi_adjust.delta; | 
|  | 10721 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, | 
|  | 10722 | sizeof(rssi_adjust), &rssi_adjust)) | 
|  | 10723 | return -ENOBUFS; | 
|  | 10724 | } | 
|  | 10725 |  | 
|  | 10726 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | 
|  | 10727 | if (!freqs) | 
|  | 10728 | return -ENOBUFS; | 
|  | 10729 |  | 
|  | 10730 | for (i = 0; i < req->n_channels; i++) { | 
|  | 10731 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | 
|  | 10732 | return -ENOBUFS; | 
|  | 10733 | } | 
|  | 10734 |  | 
|  | 10735 | nla_nest_end(msg, freqs); | 
|  | 10736 |  | 
|  | 10737 | if (req->n_match_sets) { | 
|  | 10738 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | 
|  | 10739 | if (!matches) | 
|  | 10740 | return -ENOBUFS; | 
|  | 10741 |  | 
|  | 10742 | for (i = 0; i < req->n_match_sets; i++) { | 
|  | 10743 | match = nla_nest_start(msg, i); | 
|  | 10744 | if (!match) | 
|  | 10745 | return -ENOBUFS; | 
|  | 10746 |  | 
|  | 10747 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | 
|  | 10748 | req->match_sets[i].ssid.ssid_len, | 
|  | 10749 | req->match_sets[i].ssid.ssid)) | 
|  | 10750 | return -ENOBUFS; | 
|  | 10751 | nla_nest_end(msg, match); | 
|  | 10752 | } | 
|  | 10753 | nla_nest_end(msg, matches); | 
|  | 10754 | } | 
|  | 10755 |  | 
|  | 10756 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); | 
|  | 10757 | if (!scan_plans) | 
|  | 10758 | return -ENOBUFS; | 
|  | 10759 |  | 
|  | 10760 | for (i = 0; i < req->n_scan_plans; i++) { | 
|  | 10761 | scan_plan = nla_nest_start(msg, i + 1); | 
|  | 10762 | if (!scan_plan) | 
|  | 10763 | return -ENOBUFS; | 
|  | 10764 |  | 
|  | 10765 | if (!scan_plan || | 
|  | 10766 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, | 
|  | 10767 | req->scan_plans[i].interval) || | 
|  | 10768 | (req->scan_plans[i].iterations && | 
|  | 10769 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | 
|  | 10770 | req->scan_plans[i].iterations))) | 
|  | 10771 | return -ENOBUFS; | 
|  | 10772 | nla_nest_end(msg, scan_plan); | 
|  | 10773 | } | 
|  | 10774 | nla_nest_end(msg, scan_plans); | 
|  | 10775 |  | 
|  | 10776 | nla_nest_end(msg, nd); | 
|  | 10777 |  | 
|  | 10778 | return 0; | 
|  | 10779 | } | 
|  | 10780 |  | 
|  | 10781 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) | 
|  | 10782 | { | 
|  | 10783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 10784 | struct sk_buff *msg; | 
|  | 10785 | void *hdr; | 
|  | 10786 | u32 size = NLMSG_DEFAULT_SIZE; | 
|  | 10787 |  | 
|  | 10788 | if (!rdev->wiphy.wowlan) | 
|  | 10789 | return -EOPNOTSUPP; | 
|  | 10790 |  | 
|  | 10791 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { | 
|  | 10792 | /* adjust size to have room for all the data */ | 
|  | 10793 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + | 
|  | 10794 | rdev->wiphy.wowlan_config->tcp->payload_len + | 
|  | 10795 | rdev->wiphy.wowlan_config->tcp->wake_len + | 
|  | 10796 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | 
|  | 10797 | } | 
|  | 10798 |  | 
|  | 10799 | msg = nlmsg_new(size, GFP_KERNEL); | 
|  | 10800 | if (!msg) | 
|  | 10801 | return -ENOMEM; | 
|  | 10802 |  | 
|  | 10803 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 10804 | NL80211_CMD_GET_WOWLAN); | 
|  | 10805 | if (!hdr) | 
|  | 10806 | goto nla_put_failure; | 
|  | 10807 |  | 
|  | 10808 | if (rdev->wiphy.wowlan_config) { | 
|  | 10809 | struct nlattr *nl_wowlan; | 
|  | 10810 |  | 
|  | 10811 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | 
|  | 10812 | if (!nl_wowlan) | 
|  | 10813 | goto nla_put_failure; | 
|  | 10814 |  | 
|  | 10815 | if ((rdev->wiphy.wowlan_config->any && | 
|  | 10816 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | 
|  | 10817 | (rdev->wiphy.wowlan_config->disconnect && | 
|  | 10818 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | 
|  | 10819 | (rdev->wiphy.wowlan_config->magic_pkt && | 
|  | 10820 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | 
|  | 10821 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && | 
|  | 10822 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | 
|  | 10823 | (rdev->wiphy.wowlan_config->eap_identity_req && | 
|  | 10824 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | 
|  | 10825 | (rdev->wiphy.wowlan_config->four_way_handshake && | 
|  | 10826 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | 
|  | 10827 | (rdev->wiphy.wowlan_config->rfkill_release && | 
|  | 10828 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | 
|  | 10829 | goto nla_put_failure; | 
|  | 10830 |  | 
|  | 10831 | if (nl80211_send_wowlan_patterns(msg, rdev)) | 
|  | 10832 | goto nla_put_failure; | 
|  | 10833 |  | 
|  | 10834 | if (nl80211_send_wowlan_tcp(msg, | 
|  | 10835 | rdev->wiphy.wowlan_config->tcp)) | 
|  | 10836 | goto nla_put_failure; | 
|  | 10837 |  | 
|  | 10838 | if (nl80211_send_wowlan_nd( | 
|  | 10839 | msg, | 
|  | 10840 | rdev->wiphy.wowlan_config->nd_config)) | 
|  | 10841 | goto nla_put_failure; | 
|  | 10842 |  | 
|  | 10843 | nla_nest_end(msg, nl_wowlan); | 
|  | 10844 | } | 
|  | 10845 |  | 
|  | 10846 | genlmsg_end(msg, hdr); | 
|  | 10847 | return genlmsg_reply(msg, info); | 
|  | 10848 |  | 
|  | 10849 | nla_put_failure: | 
|  | 10850 | nlmsg_free(msg); | 
|  | 10851 | return -ENOBUFS; | 
|  | 10852 | } | 
|  | 10853 |  | 
|  | 10854 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, | 
|  | 10855 | struct nlattr *attr, | 
|  | 10856 | struct cfg80211_wowlan *trig) | 
|  | 10857 | { | 
|  | 10858 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | 
|  | 10859 | struct cfg80211_wowlan_tcp *cfg; | 
|  | 10860 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | 
|  | 10861 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | 
|  | 10862 | u32 size; | 
|  | 10863 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | 
|  | 10864 | int err, port; | 
|  | 10865 |  | 
|  | 10866 | if (!rdev->wiphy.wowlan->tcp) | 
|  | 10867 | return -EINVAL; | 
|  | 10868 |  | 
|  | 10869 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, | 
|  | 10870 | nl80211_wowlan_tcp_policy, NULL); | 
|  | 10871 | if (err) | 
|  | 10872 | return err; | 
|  | 10873 |  | 
|  | 10874 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | 
|  | 10875 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | 
|  | 10876 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | 
|  | 10877 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | 
|  | 10878 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | 
|  | 10879 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | 
|  | 10880 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | 
|  | 10881 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | 
|  | 10882 | return -EINVAL; | 
|  | 10883 |  | 
|  | 10884 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | 
|  | 10885 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) | 
|  | 10886 | return -EINVAL; | 
|  | 10887 |  | 
|  | 10888 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | 
|  | 10889 | rdev->wiphy.wowlan->tcp->data_interval_max || | 
|  | 10890 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) | 
|  | 10891 | return -EINVAL; | 
|  | 10892 |  | 
|  | 10893 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | 
|  | 10894 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) | 
|  | 10895 | return -EINVAL; | 
|  | 10896 |  | 
|  | 10897 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | 
|  | 10898 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | 
|  | 10899 | return -EINVAL; | 
|  | 10900 |  | 
|  | 10901 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | 
|  | 10902 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | 
|  | 10903 |  | 
|  | 10904 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | 
|  | 10905 | tokens_size = tokln - sizeof(*tok); | 
|  | 10906 |  | 
|  | 10907 | if (!tok->len || tokens_size % tok->len) | 
|  | 10908 | return -EINVAL; | 
|  | 10909 | if (!rdev->wiphy.wowlan->tcp->tok) | 
|  | 10910 | return -EINVAL; | 
|  | 10911 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) | 
|  | 10912 | return -EINVAL; | 
|  | 10913 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) | 
|  | 10914 | return -EINVAL; | 
|  | 10915 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) | 
|  | 10916 | return -EINVAL; | 
|  | 10917 | if (tok->offset + tok->len > data_size) | 
|  | 10918 | return -EINVAL; | 
|  | 10919 | } | 
|  | 10920 |  | 
|  | 10921 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | 
|  | 10922 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | 
|  | 10923 | if (!rdev->wiphy.wowlan->tcp->seq) | 
|  | 10924 | return -EINVAL; | 
|  | 10925 | if (seq->len == 0 || seq->len > 4) | 
|  | 10926 | return -EINVAL; | 
|  | 10927 | if (seq->len + seq->offset > data_size) | 
|  | 10928 | return -EINVAL; | 
|  | 10929 | } | 
|  | 10930 |  | 
|  | 10931 | size = sizeof(*cfg); | 
|  | 10932 | size += data_size; | 
|  | 10933 | size += wake_size + wake_mask_size; | 
|  | 10934 | size += tokens_size; | 
|  | 10935 |  | 
|  | 10936 | cfg = kzalloc(size, GFP_KERNEL); | 
|  | 10937 | if (!cfg) | 
|  | 10938 | return -ENOMEM; | 
|  | 10939 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | 
|  | 10940 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | 
|  | 10941 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | 
|  | 10942 | ETH_ALEN); | 
|  | 10943 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | 
|  | 10944 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | 
|  | 10945 | else | 
|  | 10946 | port = 0; | 
|  | 10947 | #ifdef CONFIG_INET | 
|  | 10948 | /* allocate a socket and port for it and use it */ | 
|  | 10949 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | 
|  | 10950 | IPPROTO_TCP, &cfg->sock, 1); | 
|  | 10951 | if (err) { | 
|  | 10952 | kfree(cfg); | 
|  | 10953 | return err; | 
|  | 10954 | } | 
|  | 10955 | if (inet_csk_get_port(cfg->sock->sk, port)) { | 
|  | 10956 | sock_release(cfg->sock); | 
|  | 10957 | kfree(cfg); | 
|  | 10958 | return -EADDRINUSE; | 
|  | 10959 | } | 
|  | 10960 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | 
|  | 10961 | #else | 
|  | 10962 | if (!port) { | 
|  | 10963 | kfree(cfg); | 
|  | 10964 | return -EINVAL; | 
|  | 10965 | } | 
|  | 10966 | cfg->src_port = port; | 
|  | 10967 | #endif | 
|  | 10968 |  | 
|  | 10969 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | 
|  | 10970 | cfg->payload_len = data_size; | 
|  | 10971 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | 
|  | 10972 | memcpy((void *)cfg->payload, | 
|  | 10973 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | 
|  | 10974 | data_size); | 
|  | 10975 | if (seq) | 
|  | 10976 | cfg->payload_seq = *seq; | 
|  | 10977 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | 
|  | 10978 | cfg->wake_len = wake_size; | 
|  | 10979 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | 
|  | 10980 | memcpy((void *)cfg->wake_data, | 
|  | 10981 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | 
|  | 10982 | wake_size); | 
|  | 10983 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | 
|  | 10984 | data_size + wake_size; | 
|  | 10985 | memcpy((void *)cfg->wake_mask, | 
|  | 10986 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | 
|  | 10987 | wake_mask_size); | 
|  | 10988 | if (tok) { | 
|  | 10989 | cfg->tokens_size = tokens_size; | 
|  | 10990 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | 
|  | 10991 | } | 
|  | 10992 |  | 
|  | 10993 | trig->tcp = cfg; | 
|  | 10994 |  | 
|  | 10995 | return 0; | 
|  | 10996 | } | 
|  | 10997 |  | 
|  | 10998 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, | 
|  | 10999 | const struct wiphy_wowlan_support *wowlan, | 
|  | 11000 | struct nlattr *attr, | 
|  | 11001 | struct cfg80211_wowlan *trig) | 
|  | 11002 | { | 
|  | 11003 | struct nlattr **tb; | 
|  | 11004 | int err; | 
|  | 11005 |  | 
|  | 11006 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); | 
|  | 11007 | if (!tb) | 
|  | 11008 | return -ENOMEM; | 
|  | 11009 |  | 
|  | 11010 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | 
|  | 11011 | err = -EOPNOTSUPP; | 
|  | 11012 | goto out; | 
|  | 11013 | } | 
|  | 11014 |  | 
|  | 11015 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, | 
|  | 11016 | NULL); | 
|  | 11017 | if (err) | 
|  | 11018 | goto out; | 
|  | 11019 |  | 
|  | 11020 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, | 
|  | 11021 | wowlan->max_nd_match_sets); | 
|  | 11022 | err = PTR_ERR_OR_ZERO(trig->nd_config); | 
|  | 11023 | if (err) | 
|  | 11024 | trig->nd_config = NULL; | 
|  | 11025 |  | 
|  | 11026 | out: | 
|  | 11027 | kfree(tb); | 
|  | 11028 | return err; | 
|  | 11029 | } | 
|  | 11030 |  | 
|  | 11031 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | 
|  | 11032 | { | 
|  | 11033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11034 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | 
|  | 11035 | struct cfg80211_wowlan new_triggers = {}; | 
|  | 11036 | struct cfg80211_wowlan *ntrig; | 
|  | 11037 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; | 
|  | 11038 | int err, i; | 
|  | 11039 | bool prev_enabled = rdev->wiphy.wowlan_config; | 
|  | 11040 | bool regular = false; | 
|  | 11041 |  | 
|  | 11042 | if (!wowlan) | 
|  | 11043 | return -EOPNOTSUPP; | 
|  | 11044 |  | 
|  | 11045 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { | 
|  | 11046 | cfg80211_rdev_free_wowlan(rdev); | 
|  | 11047 | rdev->wiphy.wowlan_config = NULL; | 
|  | 11048 | goto set_wakeup; | 
|  | 11049 | } | 
|  | 11050 |  | 
|  | 11051 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, | 
|  | 11052 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], | 
|  | 11053 | nl80211_wowlan_policy, info->extack); | 
|  | 11054 | if (err) | 
|  | 11055 | return err; | 
|  | 11056 |  | 
|  | 11057 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | 
|  | 11058 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | 
|  | 11059 | return -EINVAL; | 
|  | 11060 | new_triggers.any = true; | 
|  | 11061 | } | 
|  | 11062 |  | 
|  | 11063 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | 
|  | 11064 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | 
|  | 11065 | return -EINVAL; | 
|  | 11066 | new_triggers.disconnect = true; | 
|  | 11067 | regular = true; | 
|  | 11068 | } | 
|  | 11069 |  | 
|  | 11070 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | 
|  | 11071 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | 
|  | 11072 | return -EINVAL; | 
|  | 11073 | new_triggers.magic_pkt = true; | 
|  | 11074 | regular = true; | 
|  | 11075 | } | 
|  | 11076 |  | 
|  | 11077 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) | 
|  | 11078 | return -EINVAL; | 
|  | 11079 |  | 
|  | 11080 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | 
|  | 11081 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | 
|  | 11082 | return -EINVAL; | 
|  | 11083 | new_triggers.gtk_rekey_failure = true; | 
|  | 11084 | regular = true; | 
|  | 11085 | } | 
|  | 11086 |  | 
|  | 11087 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | 
|  | 11088 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | 
|  | 11089 | return -EINVAL; | 
|  | 11090 | new_triggers.eap_identity_req = true; | 
|  | 11091 | regular = true; | 
|  | 11092 | } | 
|  | 11093 |  | 
|  | 11094 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | 
|  | 11095 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | 
|  | 11096 | return -EINVAL; | 
|  | 11097 | new_triggers.four_way_handshake = true; | 
|  | 11098 | regular = true; | 
|  | 11099 | } | 
|  | 11100 |  | 
|  | 11101 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | 
|  | 11102 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | 
|  | 11103 | return -EINVAL; | 
|  | 11104 | new_triggers.rfkill_release = true; | 
|  | 11105 | regular = true; | 
|  | 11106 | } | 
|  | 11107 |  | 
|  | 11108 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { | 
|  | 11109 | struct nlattr *pat; | 
|  | 11110 | int n_patterns = 0; | 
|  | 11111 | int rem, pat_len, mask_len, pkt_offset; | 
|  | 11112 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | 
|  | 11113 |  | 
|  | 11114 | regular = true; | 
|  | 11115 |  | 
|  | 11116 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | 
|  | 11117 | rem) | 
|  | 11118 | n_patterns++; | 
|  | 11119 | if (n_patterns > wowlan->n_patterns) | 
|  | 11120 | return -EINVAL; | 
|  | 11121 |  | 
|  | 11122 | new_triggers.patterns = kcalloc(n_patterns, | 
|  | 11123 | sizeof(new_triggers.patterns[0]), | 
|  | 11124 | GFP_KERNEL); | 
|  | 11125 | if (!new_triggers.patterns) | 
|  | 11126 | return -ENOMEM; | 
|  | 11127 |  | 
|  | 11128 | new_triggers.n_patterns = n_patterns; | 
|  | 11129 | i = 0; | 
|  | 11130 |  | 
|  | 11131 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | 
|  | 11132 | rem) { | 
|  | 11133 | u8 *mask_pat; | 
|  | 11134 |  | 
|  | 11135 | err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, | 
|  | 11136 | nl80211_packet_pattern_policy, | 
|  | 11137 | info->extack); | 
|  | 11138 | if (err) | 
|  | 11139 | goto error; | 
|  | 11140 |  | 
|  | 11141 | err = -EINVAL; | 
|  | 11142 | if (!pat_tb[NL80211_PKTPAT_MASK] || | 
|  | 11143 | !pat_tb[NL80211_PKTPAT_PATTERN]) | 
|  | 11144 | goto error; | 
|  | 11145 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | 
|  | 11146 | mask_len = DIV_ROUND_UP(pat_len, 8); | 
|  | 11147 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | 
|  | 11148 | goto error; | 
|  | 11149 | if (pat_len > wowlan->pattern_max_len || | 
|  | 11150 | pat_len < wowlan->pattern_min_len) | 
|  | 11151 | goto error; | 
|  | 11152 |  | 
|  | 11153 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | 
|  | 11154 | pkt_offset = 0; | 
|  | 11155 | else | 
|  | 11156 | pkt_offset = nla_get_u32( | 
|  | 11157 | pat_tb[NL80211_PKTPAT_OFFSET]); | 
|  | 11158 | if (pkt_offset > wowlan->max_pkt_offset) | 
|  | 11159 | goto error; | 
|  | 11160 | new_triggers.patterns[i].pkt_offset = pkt_offset; | 
|  | 11161 |  | 
|  | 11162 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); | 
|  | 11163 | if (!mask_pat) { | 
|  | 11164 | err = -ENOMEM; | 
|  | 11165 | goto error; | 
|  | 11166 | } | 
|  | 11167 | new_triggers.patterns[i].mask = mask_pat; | 
|  | 11168 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | 
|  | 11169 | mask_len); | 
|  | 11170 | mask_pat += mask_len; | 
|  | 11171 | new_triggers.patterns[i].pattern = mask_pat; | 
|  | 11172 | new_triggers.patterns[i].pattern_len = pat_len; | 
|  | 11173 | memcpy(mask_pat, | 
|  | 11174 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), | 
|  | 11175 | pat_len); | 
|  | 11176 | i++; | 
|  | 11177 | } | 
|  | 11178 | } | 
|  | 11179 |  | 
|  | 11180 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { | 
|  | 11181 | regular = true; | 
|  | 11182 | err = nl80211_parse_wowlan_tcp( | 
|  | 11183 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | 
|  | 11184 | &new_triggers); | 
|  | 11185 | if (err) | 
|  | 11186 | goto error; | 
|  | 11187 | } | 
|  | 11188 |  | 
|  | 11189 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { | 
|  | 11190 | regular = true; | 
|  | 11191 | err = nl80211_parse_wowlan_nd( | 
|  | 11192 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | 
|  | 11193 | &new_triggers); | 
|  | 11194 | if (err) | 
|  | 11195 | goto error; | 
|  | 11196 | } | 
|  | 11197 |  | 
|  | 11198 | /* The 'any' trigger means the device continues operating more or less | 
|  | 11199 | * as in its normal operation mode and wakes up the host on most of the | 
|  | 11200 | * normal interrupts (like packet RX, ...) | 
|  | 11201 | * It therefore makes little sense to combine with the more constrained | 
|  | 11202 | * wakeup trigger modes. | 
|  | 11203 | */ | 
|  | 11204 | if (new_triggers.any && regular) { | 
|  | 11205 | err = -EINVAL; | 
|  | 11206 | goto error; | 
|  | 11207 | } | 
|  | 11208 |  | 
|  | 11209 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); | 
|  | 11210 | if (!ntrig) { | 
|  | 11211 | err = -ENOMEM; | 
|  | 11212 | goto error; | 
|  | 11213 | } | 
|  | 11214 | cfg80211_rdev_free_wowlan(rdev); | 
|  | 11215 | rdev->wiphy.wowlan_config = ntrig; | 
|  | 11216 |  | 
|  | 11217 | set_wakeup: | 
|  | 11218 | if (rdev->ops->set_wakeup && | 
|  | 11219 | prev_enabled != !!rdev->wiphy.wowlan_config) | 
|  | 11220 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | 
|  | 11221 |  | 
|  | 11222 | return 0; | 
|  | 11223 | error: | 
|  | 11224 | for (i = 0; i < new_triggers.n_patterns; i++) | 
|  | 11225 | kfree(new_triggers.patterns[i].mask); | 
|  | 11226 | kfree(new_triggers.patterns); | 
|  | 11227 | if (new_triggers.tcp && new_triggers.tcp->sock) | 
|  | 11228 | sock_release(new_triggers.tcp->sock); | 
|  | 11229 | kfree(new_triggers.tcp); | 
|  | 11230 | kfree(new_triggers.nd_config); | 
|  | 11231 | return err; | 
|  | 11232 | } | 
|  | 11233 | #endif | 
|  | 11234 |  | 
|  | 11235 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, | 
|  | 11236 | struct cfg80211_registered_device *rdev) | 
|  | 11237 | { | 
|  | 11238 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | 
|  | 11239 | int i, j, pat_len; | 
|  | 11240 | struct cfg80211_coalesce_rules *rule; | 
|  | 11241 |  | 
|  | 11242 | if (!rdev->coalesce->n_rules) | 
|  | 11243 | return 0; | 
|  | 11244 |  | 
|  | 11245 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | 
|  | 11246 | if (!nl_rules) | 
|  | 11247 | return -ENOBUFS; | 
|  | 11248 |  | 
|  | 11249 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | 
|  | 11250 | nl_rule = nla_nest_start(msg, i + 1); | 
|  | 11251 | if (!nl_rule) | 
|  | 11252 | return -ENOBUFS; | 
|  | 11253 |  | 
|  | 11254 | rule = &rdev->coalesce->rules[i]; | 
|  | 11255 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | 
|  | 11256 | rule->delay)) | 
|  | 11257 | return -ENOBUFS; | 
|  | 11258 |  | 
|  | 11259 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | 
|  | 11260 | rule->condition)) | 
|  | 11261 | return -ENOBUFS; | 
|  | 11262 |  | 
|  | 11263 | nl_pats = nla_nest_start(msg, | 
|  | 11264 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | 
|  | 11265 | if (!nl_pats) | 
|  | 11266 | return -ENOBUFS; | 
|  | 11267 |  | 
|  | 11268 | for (j = 0; j < rule->n_patterns; j++) { | 
|  | 11269 | nl_pat = nla_nest_start(msg, j + 1); | 
|  | 11270 | if (!nl_pat) | 
|  | 11271 | return -ENOBUFS; | 
|  | 11272 | pat_len = rule->patterns[j].pattern_len; | 
|  | 11273 | if (nla_put(msg, NL80211_PKTPAT_MASK, | 
|  | 11274 | DIV_ROUND_UP(pat_len, 8), | 
|  | 11275 | rule->patterns[j].mask) || | 
|  | 11276 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | 
|  | 11277 | rule->patterns[j].pattern) || | 
|  | 11278 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | 
|  | 11279 | rule->patterns[j].pkt_offset)) | 
|  | 11280 | return -ENOBUFS; | 
|  | 11281 | nla_nest_end(msg, nl_pat); | 
|  | 11282 | } | 
|  | 11283 | nla_nest_end(msg, nl_pats); | 
|  | 11284 | nla_nest_end(msg, nl_rule); | 
|  | 11285 | } | 
|  | 11286 | nla_nest_end(msg, nl_rules); | 
|  | 11287 |  | 
|  | 11288 | return 0; | 
|  | 11289 | } | 
|  | 11290 |  | 
|  | 11291 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | 
|  | 11292 | { | 
|  | 11293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11294 | struct sk_buff *msg; | 
|  | 11295 | void *hdr; | 
|  | 11296 |  | 
|  | 11297 | if (!rdev->wiphy.coalesce) | 
|  | 11298 | return -EOPNOTSUPP; | 
|  | 11299 |  | 
|  | 11300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 11301 | if (!msg) | 
|  | 11302 | return -ENOMEM; | 
|  | 11303 |  | 
|  | 11304 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 11305 | NL80211_CMD_GET_COALESCE); | 
|  | 11306 | if (!hdr) | 
|  | 11307 | goto nla_put_failure; | 
|  | 11308 |  | 
|  | 11309 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | 
|  | 11310 | goto nla_put_failure; | 
|  | 11311 |  | 
|  | 11312 | genlmsg_end(msg, hdr); | 
|  | 11313 | return genlmsg_reply(msg, info); | 
|  | 11314 |  | 
|  | 11315 | nla_put_failure: | 
|  | 11316 | nlmsg_free(msg); | 
|  | 11317 | return -ENOBUFS; | 
|  | 11318 | } | 
|  | 11319 |  | 
|  | 11320 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | 
|  | 11321 | { | 
|  | 11322 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | 
|  | 11323 | int i, j; | 
|  | 11324 | struct cfg80211_coalesce_rules *rule; | 
|  | 11325 |  | 
|  | 11326 | if (!coalesce) | 
|  | 11327 | return; | 
|  | 11328 |  | 
|  | 11329 | for (i = 0; i < coalesce->n_rules; i++) { | 
|  | 11330 | rule = &coalesce->rules[i]; | 
|  | 11331 | for (j = 0; j < rule->n_patterns; j++) | 
|  | 11332 | kfree(rule->patterns[j].mask); | 
|  | 11333 | kfree(rule->patterns); | 
|  | 11334 | } | 
|  | 11335 | kfree(coalesce->rules); | 
|  | 11336 | kfree(coalesce); | 
|  | 11337 | rdev->coalesce = NULL; | 
|  | 11338 | } | 
|  | 11339 |  | 
|  | 11340 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | 
|  | 11341 | struct nlattr *rule, | 
|  | 11342 | struct cfg80211_coalesce_rules *new_rule) | 
|  | 11343 | { | 
|  | 11344 | int err, i; | 
|  | 11345 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | 
|  | 11346 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | 
|  | 11347 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | 
|  | 11348 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | 
|  | 11349 |  | 
|  | 11350 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, | 
|  | 11351 | nl80211_coalesce_policy, NULL); | 
|  | 11352 | if (err) | 
|  | 11353 | return err; | 
|  | 11354 |  | 
|  | 11355 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | 
|  | 11356 | new_rule->delay = | 
|  | 11357 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | 
|  | 11358 | if (new_rule->delay > coalesce->max_delay) | 
|  | 11359 | return -EINVAL; | 
|  | 11360 |  | 
|  | 11361 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | 
|  | 11362 | new_rule->condition = | 
|  | 11363 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | 
|  | 11364 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | 
|  | 11365 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | 
|  | 11366 | return -EINVAL; | 
|  | 11367 |  | 
|  | 11368 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | 
|  | 11369 | return -EINVAL; | 
|  | 11370 |  | 
|  | 11371 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | 
|  | 11372 | rem) | 
|  | 11373 | n_patterns++; | 
|  | 11374 | if (n_patterns > coalesce->n_patterns) | 
|  | 11375 | return -EINVAL; | 
|  | 11376 |  | 
|  | 11377 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | 
|  | 11378 | GFP_KERNEL); | 
|  | 11379 | if (!new_rule->patterns) | 
|  | 11380 | return -ENOMEM; | 
|  | 11381 |  | 
|  | 11382 | new_rule->n_patterns = n_patterns; | 
|  | 11383 | i = 0; | 
|  | 11384 |  | 
|  | 11385 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | 
|  | 11386 | rem) { | 
|  | 11387 | u8 *mask_pat; | 
|  | 11388 |  | 
|  | 11389 | err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, | 
|  | 11390 | nl80211_packet_pattern_policy, NULL); | 
|  | 11391 | if (err) | 
|  | 11392 | return err; | 
|  | 11393 |  | 
|  | 11394 | if (!pat_tb[NL80211_PKTPAT_MASK] || | 
|  | 11395 | !pat_tb[NL80211_PKTPAT_PATTERN]) | 
|  | 11396 | return -EINVAL; | 
|  | 11397 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | 
|  | 11398 | mask_len = DIV_ROUND_UP(pat_len, 8); | 
|  | 11399 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | 
|  | 11400 | return -EINVAL; | 
|  | 11401 | if (pat_len > coalesce->pattern_max_len || | 
|  | 11402 | pat_len < coalesce->pattern_min_len) | 
|  | 11403 | return -EINVAL; | 
|  | 11404 |  | 
|  | 11405 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | 
|  | 11406 | pkt_offset = 0; | 
|  | 11407 | else | 
|  | 11408 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | 
|  | 11409 | if (pkt_offset > coalesce->max_pkt_offset) | 
|  | 11410 | return -EINVAL; | 
|  | 11411 | new_rule->patterns[i].pkt_offset = pkt_offset; | 
|  | 11412 |  | 
|  | 11413 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); | 
|  | 11414 | if (!mask_pat) | 
|  | 11415 | return -ENOMEM; | 
|  | 11416 |  | 
|  | 11417 | new_rule->patterns[i].mask = mask_pat; | 
|  | 11418 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | 
|  | 11419 | mask_len); | 
|  | 11420 |  | 
|  | 11421 | mask_pat += mask_len; | 
|  | 11422 | new_rule->patterns[i].pattern = mask_pat; | 
|  | 11423 | new_rule->patterns[i].pattern_len = pat_len; | 
|  | 11424 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), | 
|  | 11425 | pat_len); | 
|  | 11426 | i++; | 
|  | 11427 | } | 
|  | 11428 |  | 
|  | 11429 | return 0; | 
|  | 11430 | } | 
|  | 11431 |  | 
|  | 11432 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | 
|  | 11433 | { | 
|  | 11434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11435 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | 
|  | 11436 | struct cfg80211_coalesce new_coalesce = {}; | 
|  | 11437 | struct cfg80211_coalesce *n_coalesce; | 
|  | 11438 | int err, rem_rule, n_rules = 0, i, j; | 
|  | 11439 | struct nlattr *rule; | 
|  | 11440 | struct cfg80211_coalesce_rules *tmp_rule; | 
|  | 11441 |  | 
|  | 11442 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | 
|  | 11443 | return -EOPNOTSUPP; | 
|  | 11444 |  | 
|  | 11445 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | 
|  | 11446 | cfg80211_rdev_free_coalesce(rdev); | 
|  | 11447 | rdev_set_coalesce(rdev, NULL); | 
|  | 11448 | return 0; | 
|  | 11449 | } | 
|  | 11450 |  | 
|  | 11451 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | 
|  | 11452 | rem_rule) | 
|  | 11453 | n_rules++; | 
|  | 11454 | if (n_rules > coalesce->n_rules) | 
|  | 11455 | return -EINVAL; | 
|  | 11456 |  | 
|  | 11457 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | 
|  | 11458 | GFP_KERNEL); | 
|  | 11459 | if (!new_coalesce.rules) | 
|  | 11460 | return -ENOMEM; | 
|  | 11461 |  | 
|  | 11462 | new_coalesce.n_rules = n_rules; | 
|  | 11463 | i = 0; | 
|  | 11464 |  | 
|  | 11465 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | 
|  | 11466 | rem_rule) { | 
|  | 11467 | err = nl80211_parse_coalesce_rule(rdev, rule, | 
|  | 11468 | &new_coalesce.rules[i]); | 
|  | 11469 | if (err) | 
|  | 11470 | goto error; | 
|  | 11471 |  | 
|  | 11472 | i++; | 
|  | 11473 | } | 
|  | 11474 |  | 
|  | 11475 | err = rdev_set_coalesce(rdev, &new_coalesce); | 
|  | 11476 | if (err) | 
|  | 11477 | goto error; | 
|  | 11478 |  | 
|  | 11479 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | 
|  | 11480 | if (!n_coalesce) { | 
|  | 11481 | err = -ENOMEM; | 
|  | 11482 | goto error; | 
|  | 11483 | } | 
|  | 11484 | cfg80211_rdev_free_coalesce(rdev); | 
|  | 11485 | rdev->coalesce = n_coalesce; | 
|  | 11486 |  | 
|  | 11487 | return 0; | 
|  | 11488 | error: | 
|  | 11489 | for (i = 0; i < new_coalesce.n_rules; i++) { | 
|  | 11490 | tmp_rule = &new_coalesce.rules[i]; | 
|  | 11491 | for (j = 0; j < tmp_rule->n_patterns; j++) | 
|  | 11492 | kfree(tmp_rule->patterns[j].mask); | 
|  | 11493 | kfree(tmp_rule->patterns); | 
|  | 11494 | } | 
|  | 11495 | kfree(new_coalesce.rules); | 
|  | 11496 |  | 
|  | 11497 | return err; | 
|  | 11498 | } | 
|  | 11499 |  | 
|  | 11500 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) | 
|  | 11501 | { | 
|  | 11502 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11503 | struct net_device *dev = info->user_ptr[1]; | 
|  | 11504 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 11505 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | 
|  | 11506 | struct cfg80211_gtk_rekey_data rekey_data; | 
|  | 11507 | int err; | 
|  | 11508 |  | 
|  | 11509 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | 
|  | 11510 | return -EINVAL; | 
|  | 11511 |  | 
|  | 11512 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, | 
|  | 11513 | info->attrs[NL80211_ATTR_REKEY_DATA], | 
|  | 11514 | nl80211_rekey_policy, info->extack); | 
|  | 11515 | if (err) | 
|  | 11516 | return err; | 
|  | 11517 |  | 
|  | 11518 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || | 
|  | 11519 | !tb[NL80211_REKEY_DATA_KCK]) | 
|  | 11520 | return -EINVAL; | 
|  | 11521 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | 
|  | 11522 | return -ERANGE; | 
|  | 11523 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | 
|  | 11524 | return -ERANGE; | 
|  | 11525 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | 
|  | 11526 | return -ERANGE; | 
|  | 11527 |  | 
|  | 11528 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); | 
|  | 11529 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | 
|  | 11530 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | 
|  | 11531 |  | 
|  | 11532 | wdev_lock(wdev); | 
|  | 11533 | if (!wdev->current_bss) { | 
|  | 11534 | err = -ENOTCONN; | 
|  | 11535 | goto out; | 
|  | 11536 | } | 
|  | 11537 |  | 
|  | 11538 | if (!rdev->ops->set_rekey_data) { | 
|  | 11539 | err = -EOPNOTSUPP; | 
|  | 11540 | goto out; | 
|  | 11541 | } | 
|  | 11542 |  | 
|  | 11543 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); | 
|  | 11544 | out: | 
|  | 11545 | wdev_unlock(wdev); | 
|  | 11546 | return err; | 
|  | 11547 | } | 
|  | 11548 |  | 
|  | 11549 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, | 
|  | 11550 | struct genl_info *info) | 
|  | 11551 | { | 
|  | 11552 | struct net_device *dev = info->user_ptr[1]; | 
|  | 11553 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 11554 |  | 
|  | 11555 | if (wdev->iftype != NL80211_IFTYPE_AP && | 
|  | 11556 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 11557 | return -EINVAL; | 
|  | 11558 |  | 
|  | 11559 | if (wdev->ap_unexpected_nlportid) | 
|  | 11560 | return -EBUSY; | 
|  | 11561 |  | 
|  | 11562 | wdev->ap_unexpected_nlportid = info->snd_portid; | 
|  | 11563 | return 0; | 
|  | 11564 | } | 
|  | 11565 |  | 
|  | 11566 | static int nl80211_probe_client(struct sk_buff *skb, | 
|  | 11567 | struct genl_info *info) | 
|  | 11568 | { | 
|  | 11569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11570 | struct net_device *dev = info->user_ptr[1]; | 
|  | 11571 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 11572 | struct sk_buff *msg; | 
|  | 11573 | void *hdr; | 
|  | 11574 | const u8 *addr; | 
|  | 11575 | u64 cookie; | 
|  | 11576 | int err; | 
|  | 11577 |  | 
|  | 11578 | if (wdev->iftype != NL80211_IFTYPE_AP && | 
|  | 11579 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 11580 | return -EOPNOTSUPP; | 
|  | 11581 |  | 
|  | 11582 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 11583 | return -EINVAL; | 
|  | 11584 |  | 
|  | 11585 | if (!rdev->ops->probe_client) | 
|  | 11586 | return -EOPNOTSUPP; | 
|  | 11587 |  | 
|  | 11588 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 11589 | if (!msg) | 
|  | 11590 | return -ENOMEM; | 
|  | 11591 |  | 
|  | 11592 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 11593 | NL80211_CMD_PROBE_CLIENT); | 
|  | 11594 | if (!hdr) { | 
|  | 11595 | err = -ENOBUFS; | 
|  | 11596 | goto free_msg; | 
|  | 11597 | } | 
|  | 11598 |  | 
|  | 11599 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 11600 |  | 
|  | 11601 | err = rdev_probe_client(rdev, dev, addr, &cookie); | 
|  | 11602 | if (err) | 
|  | 11603 | goto free_msg; | 
|  | 11604 |  | 
|  | 11605 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 11606 | NL80211_ATTR_PAD)) | 
|  | 11607 | goto nla_put_failure; | 
|  | 11608 |  | 
|  | 11609 | genlmsg_end(msg, hdr); | 
|  | 11610 |  | 
|  | 11611 | return genlmsg_reply(msg, info); | 
|  | 11612 |  | 
|  | 11613 | nla_put_failure: | 
|  | 11614 | err = -ENOBUFS; | 
|  | 11615 | free_msg: | 
|  | 11616 | nlmsg_free(msg); | 
|  | 11617 | return err; | 
|  | 11618 | } | 
|  | 11619 |  | 
|  | 11620 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) | 
|  | 11621 | { | 
|  | 11622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11623 | struct cfg80211_beacon_registration *reg, *nreg; | 
|  | 11624 | int rv; | 
|  | 11625 |  | 
|  | 11626 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | 
|  | 11627 | return -EOPNOTSUPP; | 
|  | 11628 |  | 
|  | 11629 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); | 
|  | 11630 | if (!nreg) | 
|  | 11631 | return -ENOMEM; | 
|  | 11632 |  | 
|  | 11633 | /* First, check if already registered. */ | 
|  | 11634 | spin_lock_bh(&rdev->beacon_registrations_lock); | 
|  | 11635 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | 
|  | 11636 | if (reg->nlportid == info->snd_portid) { | 
|  | 11637 | rv = -EALREADY; | 
|  | 11638 | goto out_err; | 
|  | 11639 | } | 
|  | 11640 | } | 
|  | 11641 | /* Add it to the list */ | 
|  | 11642 | nreg->nlportid = info->snd_portid; | 
|  | 11643 | list_add(&nreg->list, &rdev->beacon_registrations); | 
|  | 11644 |  | 
|  | 11645 | spin_unlock_bh(&rdev->beacon_registrations_lock); | 
|  | 11646 |  | 
|  | 11647 | return 0; | 
|  | 11648 | out_err: | 
|  | 11649 | spin_unlock_bh(&rdev->beacon_registrations_lock); | 
|  | 11650 | kfree(nreg); | 
|  | 11651 | return rv; | 
|  | 11652 | } | 
|  | 11653 |  | 
|  | 11654 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) | 
|  | 11655 | { | 
|  | 11656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11657 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 11658 | int err; | 
|  | 11659 |  | 
|  | 11660 | if (!rdev->ops->start_p2p_device) | 
|  | 11661 | return -EOPNOTSUPP; | 
|  | 11662 |  | 
|  | 11663 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | 
|  | 11664 | return -EOPNOTSUPP; | 
|  | 11665 |  | 
|  | 11666 | if (wdev_running(wdev)) | 
|  | 11667 | return 0; | 
|  | 11668 |  | 
|  | 11669 | if (rfkill_blocked(rdev->rfkill)) | 
|  | 11670 | return -ERFKILL; | 
|  | 11671 |  | 
|  | 11672 | err = rdev_start_p2p_device(rdev, wdev); | 
|  | 11673 | if (err) | 
|  | 11674 | return err; | 
|  | 11675 |  | 
|  | 11676 | wdev->is_running = true; | 
|  | 11677 | rdev->opencount++; | 
|  | 11678 |  | 
|  | 11679 | return 0; | 
|  | 11680 | } | 
|  | 11681 |  | 
|  | 11682 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | 
|  | 11683 | { | 
|  | 11684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11685 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 11686 |  | 
|  | 11687 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | 
|  | 11688 | return -EOPNOTSUPP; | 
|  | 11689 |  | 
|  | 11690 | if (!rdev->ops->stop_p2p_device) | 
|  | 11691 | return -EOPNOTSUPP; | 
|  | 11692 |  | 
|  | 11693 | cfg80211_stop_p2p_device(rdev, wdev); | 
|  | 11694 |  | 
|  | 11695 | return 0; | 
|  | 11696 | } | 
|  | 11697 |  | 
|  | 11698 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) | 
|  | 11699 | { | 
|  | 11700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11701 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 11702 | struct cfg80211_nan_conf conf = {}; | 
|  | 11703 | int err; | 
|  | 11704 |  | 
|  | 11705 | if (wdev->iftype != NL80211_IFTYPE_NAN) | 
|  | 11706 | return -EOPNOTSUPP; | 
|  | 11707 |  | 
|  | 11708 | if (wdev_running(wdev)) | 
|  | 11709 | return -EEXIST; | 
|  | 11710 |  | 
|  | 11711 | if (rfkill_blocked(rdev->rfkill)) | 
|  | 11712 | return -ERFKILL; | 
|  | 11713 |  | 
|  | 11714 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) | 
|  | 11715 | return -EINVAL; | 
|  | 11716 |  | 
|  | 11717 | conf.master_pref = | 
|  | 11718 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | 
|  | 11719 | if (!conf.master_pref) | 
|  | 11720 | return -EINVAL; | 
|  | 11721 |  | 
|  | 11722 | if (info->attrs[NL80211_ATTR_BANDS]) { | 
|  | 11723 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | 
|  | 11724 |  | 
|  | 11725 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | 
|  | 11726 | return -EOPNOTSUPP; | 
|  | 11727 |  | 
|  | 11728 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | 
|  | 11729 | return -EINVAL; | 
|  | 11730 |  | 
|  | 11731 | conf.bands = bands; | 
|  | 11732 | } | 
|  | 11733 |  | 
|  | 11734 | err = rdev_start_nan(rdev, wdev, &conf); | 
|  | 11735 | if (err) | 
|  | 11736 | return err; | 
|  | 11737 |  | 
|  | 11738 | wdev->is_running = true; | 
|  | 11739 | rdev->opencount++; | 
|  | 11740 |  | 
|  | 11741 | return 0; | 
|  | 11742 | } | 
|  | 11743 |  | 
|  | 11744 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) | 
|  | 11745 | { | 
|  | 11746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11747 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 11748 |  | 
|  | 11749 | if (wdev->iftype != NL80211_IFTYPE_NAN) | 
|  | 11750 | return -EOPNOTSUPP; | 
|  | 11751 |  | 
|  | 11752 | cfg80211_stop_nan(rdev, wdev); | 
|  | 11753 |  | 
|  | 11754 | return 0; | 
|  | 11755 | } | 
|  | 11756 |  | 
|  | 11757 | static int validate_nan_filter(struct nlattr *filter_attr) | 
|  | 11758 | { | 
|  | 11759 | struct nlattr *attr; | 
|  | 11760 | int len = 0, n_entries = 0, rem; | 
|  | 11761 |  | 
|  | 11762 | nla_for_each_nested(attr, filter_attr, rem) { | 
|  | 11763 | len += nla_len(attr); | 
|  | 11764 | n_entries++; | 
|  | 11765 | } | 
|  | 11766 |  | 
|  | 11767 | if (len >= U8_MAX) | 
|  | 11768 | return -EINVAL; | 
|  | 11769 |  | 
|  | 11770 | return n_entries; | 
|  | 11771 | } | 
|  | 11772 |  | 
|  | 11773 | static int handle_nan_filter(struct nlattr *attr_filter, | 
|  | 11774 | struct cfg80211_nan_func *func, | 
|  | 11775 | bool tx) | 
|  | 11776 | { | 
|  | 11777 | struct nlattr *attr; | 
|  | 11778 | int n_entries, rem, i; | 
|  | 11779 | struct cfg80211_nan_func_filter *filter; | 
|  | 11780 |  | 
|  | 11781 | n_entries = validate_nan_filter(attr_filter); | 
|  | 11782 | if (n_entries < 0) | 
|  | 11783 | return n_entries; | 
|  | 11784 |  | 
|  | 11785 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); | 
|  | 11786 |  | 
|  | 11787 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); | 
|  | 11788 | if (!filter) | 
|  | 11789 | return -ENOMEM; | 
|  | 11790 |  | 
|  | 11791 | i = 0; | 
|  | 11792 | nla_for_each_nested(attr, attr_filter, rem) { | 
|  | 11793 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); | 
|  | 11794 | filter[i].len = nla_len(attr); | 
|  | 11795 | i++; | 
|  | 11796 | } | 
|  | 11797 | if (tx) { | 
|  | 11798 | func->num_tx_filters = n_entries; | 
|  | 11799 | func->tx_filters = filter; | 
|  | 11800 | } else { | 
|  | 11801 | func->num_rx_filters = n_entries; | 
|  | 11802 | func->rx_filters = filter; | 
|  | 11803 | } | 
|  | 11804 |  | 
|  | 11805 | return 0; | 
|  | 11806 | } | 
|  | 11807 |  | 
|  | 11808 | static int nl80211_nan_add_func(struct sk_buff *skb, | 
|  | 11809 | struct genl_info *info) | 
|  | 11810 | { | 
|  | 11811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 11812 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 11813 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; | 
|  | 11814 | struct cfg80211_nan_func *func; | 
|  | 11815 | struct sk_buff *msg = NULL; | 
|  | 11816 | void *hdr = NULL; | 
|  | 11817 | int err = 0; | 
|  | 11818 |  | 
|  | 11819 | if (wdev->iftype != NL80211_IFTYPE_NAN) | 
|  | 11820 | return -EOPNOTSUPP; | 
|  | 11821 |  | 
|  | 11822 | if (!wdev_running(wdev)) | 
|  | 11823 | return -ENOTCONN; | 
|  | 11824 |  | 
|  | 11825 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) | 
|  | 11826 | return -EINVAL; | 
|  | 11827 |  | 
|  | 11828 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, | 
|  | 11829 | info->attrs[NL80211_ATTR_NAN_FUNC], | 
|  | 11830 | nl80211_nan_func_policy, info->extack); | 
|  | 11831 | if (err) | 
|  | 11832 | return err; | 
|  | 11833 |  | 
|  | 11834 | func = kzalloc(sizeof(*func), GFP_KERNEL); | 
|  | 11835 | if (!func) | 
|  | 11836 | return -ENOMEM; | 
|  | 11837 |  | 
|  | 11838 | func->cookie = wdev->wiphy->cookie_counter++; | 
|  | 11839 |  | 
|  | 11840 | if (!tb[NL80211_NAN_FUNC_TYPE] || | 
|  | 11841 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { | 
|  | 11842 | err = -EINVAL; | 
|  | 11843 | goto out; | 
|  | 11844 | } | 
|  | 11845 |  | 
|  | 11846 |  | 
|  | 11847 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); | 
|  | 11848 |  | 
|  | 11849 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { | 
|  | 11850 | err = -EINVAL; | 
|  | 11851 | goto out; | 
|  | 11852 | } | 
|  | 11853 |  | 
|  | 11854 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), | 
|  | 11855 | sizeof(func->service_id)); | 
|  | 11856 |  | 
|  | 11857 | func->close_range = | 
|  | 11858 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); | 
|  | 11859 |  | 
|  | 11860 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { | 
|  | 11861 | func->serv_spec_info_len = | 
|  | 11862 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); | 
|  | 11863 | func->serv_spec_info = | 
|  | 11864 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), | 
|  | 11865 | func->serv_spec_info_len, | 
|  | 11866 | GFP_KERNEL); | 
|  | 11867 | if (!func->serv_spec_info) { | 
|  | 11868 | err = -ENOMEM; | 
|  | 11869 | goto out; | 
|  | 11870 | } | 
|  | 11871 | } | 
|  | 11872 |  | 
|  | 11873 | if (tb[NL80211_NAN_FUNC_TTL]) | 
|  | 11874 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); | 
|  | 11875 |  | 
|  | 11876 | switch (func->type) { | 
|  | 11877 | case NL80211_NAN_FUNC_PUBLISH: | 
|  | 11878 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { | 
|  | 11879 | err = -EINVAL; | 
|  | 11880 | goto out; | 
|  | 11881 | } | 
|  | 11882 |  | 
|  | 11883 | func->publish_type = | 
|  | 11884 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); | 
|  | 11885 | func->publish_bcast = | 
|  | 11886 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); | 
|  | 11887 |  | 
|  | 11888 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && | 
|  | 11889 | func->publish_bcast) { | 
|  | 11890 | err = -EINVAL; | 
|  | 11891 | goto out; | 
|  | 11892 | } | 
|  | 11893 | break; | 
|  | 11894 | case NL80211_NAN_FUNC_SUBSCRIBE: | 
|  | 11895 | func->subscribe_active = | 
|  | 11896 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); | 
|  | 11897 | break; | 
|  | 11898 | case NL80211_NAN_FUNC_FOLLOW_UP: | 
|  | 11899 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || | 
|  | 11900 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || | 
|  | 11901 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { | 
|  | 11902 | err = -EINVAL; | 
|  | 11903 | goto out; | 
|  | 11904 | } | 
|  | 11905 |  | 
|  | 11906 | func->followup_id = | 
|  | 11907 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); | 
|  | 11908 | func->followup_reqid = | 
|  | 11909 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); | 
|  | 11910 | memcpy(func->followup_dest.addr, | 
|  | 11911 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), | 
|  | 11912 | sizeof(func->followup_dest.addr)); | 
|  | 11913 | if (func->ttl) { | 
|  | 11914 | err = -EINVAL; | 
|  | 11915 | goto out; | 
|  | 11916 | } | 
|  | 11917 | break; | 
|  | 11918 | default: | 
|  | 11919 | err = -EINVAL; | 
|  | 11920 | goto out; | 
|  | 11921 | } | 
|  | 11922 |  | 
|  | 11923 | if (tb[NL80211_NAN_FUNC_SRF]) { | 
|  | 11924 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; | 
|  | 11925 |  | 
|  | 11926 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, | 
|  | 11927 | tb[NL80211_NAN_FUNC_SRF], | 
|  | 11928 | nl80211_nan_srf_policy, info->extack); | 
|  | 11929 | if (err) | 
|  | 11930 | goto out; | 
|  | 11931 |  | 
|  | 11932 | func->srf_include = | 
|  | 11933 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); | 
|  | 11934 |  | 
|  | 11935 | if (srf_tb[NL80211_NAN_SRF_BF]) { | 
|  | 11936 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || | 
|  | 11937 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { | 
|  | 11938 | err = -EINVAL; | 
|  | 11939 | goto out; | 
|  | 11940 | } | 
|  | 11941 |  | 
|  | 11942 | func->srf_bf_len = | 
|  | 11943 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); | 
|  | 11944 | func->srf_bf = | 
|  | 11945 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), | 
|  | 11946 | func->srf_bf_len, GFP_KERNEL); | 
|  | 11947 | if (!func->srf_bf) { | 
|  | 11948 | err = -ENOMEM; | 
|  | 11949 | goto out; | 
|  | 11950 | } | 
|  | 11951 |  | 
|  | 11952 | func->srf_bf_idx = | 
|  | 11953 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); | 
|  | 11954 | } else { | 
|  | 11955 | struct nlattr *attr, *mac_attr = | 
|  | 11956 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; | 
|  | 11957 | int n_entries, rem, i = 0; | 
|  | 11958 |  | 
|  | 11959 | if (!mac_attr) { | 
|  | 11960 | err = -EINVAL; | 
|  | 11961 | goto out; | 
|  | 11962 | } | 
|  | 11963 |  | 
|  | 11964 | n_entries = validate_acl_mac_addrs(mac_attr); | 
|  | 11965 | if (n_entries <= 0) { | 
|  | 11966 | err = -EINVAL; | 
|  | 11967 | goto out; | 
|  | 11968 | } | 
|  | 11969 |  | 
|  | 11970 | func->srf_num_macs = n_entries; | 
|  | 11971 | func->srf_macs = | 
|  | 11972 | kcalloc(n_entries, sizeof(*func->srf_macs), | 
|  | 11973 | GFP_KERNEL); | 
|  | 11974 | if (!func->srf_macs) { | 
|  | 11975 | err = -ENOMEM; | 
|  | 11976 | goto out; | 
|  | 11977 | } | 
|  | 11978 |  | 
|  | 11979 | nla_for_each_nested(attr, mac_attr, rem) | 
|  | 11980 | memcpy(func->srf_macs[i++].addr, nla_data(attr), | 
|  | 11981 | sizeof(*func->srf_macs)); | 
|  | 11982 | } | 
|  | 11983 | } | 
|  | 11984 |  | 
|  | 11985 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { | 
|  | 11986 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], | 
|  | 11987 | func, true); | 
|  | 11988 | if (err) | 
|  | 11989 | goto out; | 
|  | 11990 | } | 
|  | 11991 |  | 
|  | 11992 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { | 
|  | 11993 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], | 
|  | 11994 | func, false); | 
|  | 11995 | if (err) | 
|  | 11996 | goto out; | 
|  | 11997 | } | 
|  | 11998 |  | 
|  | 11999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 12000 | if (!msg) { | 
|  | 12001 | err = -ENOMEM; | 
|  | 12002 | goto out; | 
|  | 12003 | } | 
|  | 12004 |  | 
|  | 12005 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 12006 | NL80211_CMD_ADD_NAN_FUNCTION); | 
|  | 12007 | /* This can't really happen - we just allocated 4KB */ | 
|  | 12008 | if (WARN_ON(!hdr)) { | 
|  | 12009 | err = -ENOMEM; | 
|  | 12010 | goto out; | 
|  | 12011 | } | 
|  | 12012 |  | 
|  | 12013 | err = rdev_add_nan_func(rdev, wdev, func); | 
|  | 12014 | out: | 
|  | 12015 | if (err < 0) { | 
|  | 12016 | cfg80211_free_nan_func(func); | 
|  | 12017 | nlmsg_free(msg); | 
|  | 12018 | return err; | 
|  | 12019 | } | 
|  | 12020 |  | 
|  | 12021 | /* propagate the instance id and cookie to userspace  */ | 
|  | 12022 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, | 
|  | 12023 | NL80211_ATTR_PAD)) | 
|  | 12024 | goto nla_put_failure; | 
|  | 12025 |  | 
|  | 12026 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); | 
|  | 12027 | if (!func_attr) | 
|  | 12028 | goto nla_put_failure; | 
|  | 12029 |  | 
|  | 12030 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, | 
|  | 12031 | func->instance_id)) | 
|  | 12032 | goto nla_put_failure; | 
|  | 12033 |  | 
|  | 12034 | nla_nest_end(msg, func_attr); | 
|  | 12035 |  | 
|  | 12036 | genlmsg_end(msg, hdr); | 
|  | 12037 | return genlmsg_reply(msg, info); | 
|  | 12038 |  | 
|  | 12039 | nla_put_failure: | 
|  | 12040 | nlmsg_free(msg); | 
|  | 12041 | return -ENOBUFS; | 
|  | 12042 | } | 
|  | 12043 |  | 
|  | 12044 | static int nl80211_nan_del_func(struct sk_buff *skb, | 
|  | 12045 | struct genl_info *info) | 
|  | 12046 | { | 
|  | 12047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12048 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 12049 | u64 cookie; | 
|  | 12050 |  | 
|  | 12051 | if (wdev->iftype != NL80211_IFTYPE_NAN) | 
|  | 12052 | return -EOPNOTSUPP; | 
|  | 12053 |  | 
|  | 12054 | if (!wdev_running(wdev)) | 
|  | 12055 | return -ENOTCONN; | 
|  | 12056 |  | 
|  | 12057 | if (!info->attrs[NL80211_ATTR_COOKIE]) | 
|  | 12058 | return -EINVAL; | 
|  | 12059 |  | 
|  | 12060 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 
|  | 12061 |  | 
|  | 12062 | rdev_del_nan_func(rdev, wdev, cookie); | 
|  | 12063 |  | 
|  | 12064 | return 0; | 
|  | 12065 | } | 
|  | 12066 |  | 
|  | 12067 | static int nl80211_nan_change_config(struct sk_buff *skb, | 
|  | 12068 | struct genl_info *info) | 
|  | 12069 | { | 
|  | 12070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12071 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 12072 | struct cfg80211_nan_conf conf = {}; | 
|  | 12073 | u32 changed = 0; | 
|  | 12074 |  | 
|  | 12075 | if (wdev->iftype != NL80211_IFTYPE_NAN) | 
|  | 12076 | return -EOPNOTSUPP; | 
|  | 12077 |  | 
|  | 12078 | if (!wdev_running(wdev)) | 
|  | 12079 | return -ENOTCONN; | 
|  | 12080 |  | 
|  | 12081 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { | 
|  | 12082 | conf.master_pref = | 
|  | 12083 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | 
|  | 12084 | if (conf.master_pref <= 1 || conf.master_pref == 255) | 
|  | 12085 | return -EINVAL; | 
|  | 12086 |  | 
|  | 12087 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; | 
|  | 12088 | } | 
|  | 12089 |  | 
|  | 12090 | if (info->attrs[NL80211_ATTR_BANDS]) { | 
|  | 12091 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | 
|  | 12092 |  | 
|  | 12093 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | 
|  | 12094 | return -EOPNOTSUPP; | 
|  | 12095 |  | 
|  | 12096 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | 
|  | 12097 | return -EINVAL; | 
|  | 12098 |  | 
|  | 12099 | conf.bands = bands; | 
|  | 12100 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; | 
|  | 12101 | } | 
|  | 12102 |  | 
|  | 12103 | if (!changed) | 
|  | 12104 | return -EINVAL; | 
|  | 12105 |  | 
|  | 12106 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); | 
|  | 12107 | } | 
|  | 12108 |  | 
|  | 12109 | void cfg80211_nan_match(struct wireless_dev *wdev, | 
|  | 12110 | struct cfg80211_nan_match_params *match, gfp_t gfp) | 
|  | 12111 | { | 
|  | 12112 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 12113 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 12114 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; | 
|  | 12115 | struct sk_buff *msg; | 
|  | 12116 | void *hdr; | 
|  | 12117 |  | 
|  | 12118 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) | 
|  | 12119 | return; | 
|  | 12120 |  | 
|  | 12121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 12122 | if (!msg) | 
|  | 12123 | return; | 
|  | 12124 |  | 
|  | 12125 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); | 
|  | 12126 | if (!hdr) { | 
|  | 12127 | nlmsg_free(msg); | 
|  | 12128 | return; | 
|  | 12129 | } | 
|  | 12130 |  | 
|  | 12131 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 12132 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 12133 | wdev->netdev->ifindex)) || | 
|  | 12134 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 12135 | NL80211_ATTR_PAD)) | 
|  | 12136 | goto nla_put_failure; | 
|  | 12137 |  | 
|  | 12138 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, | 
|  | 12139 | NL80211_ATTR_PAD) || | 
|  | 12140 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) | 
|  | 12141 | goto nla_put_failure; | 
|  | 12142 |  | 
|  | 12143 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); | 
|  | 12144 | if (!match_attr) | 
|  | 12145 | goto nla_put_failure; | 
|  | 12146 |  | 
|  | 12147 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); | 
|  | 12148 | if (!local_func_attr) | 
|  | 12149 | goto nla_put_failure; | 
|  | 12150 |  | 
|  | 12151 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) | 
|  | 12152 | goto nla_put_failure; | 
|  | 12153 |  | 
|  | 12154 | nla_nest_end(msg, local_func_attr); | 
|  | 12155 |  | 
|  | 12156 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); | 
|  | 12157 | if (!peer_func_attr) | 
|  | 12158 | goto nla_put_failure; | 
|  | 12159 |  | 
|  | 12160 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || | 
|  | 12161 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) | 
|  | 12162 | goto nla_put_failure; | 
|  | 12163 |  | 
|  | 12164 | if (match->info && match->info_len && | 
|  | 12165 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, | 
|  | 12166 | match->info)) | 
|  | 12167 | goto nla_put_failure; | 
|  | 12168 |  | 
|  | 12169 | nla_nest_end(msg, peer_func_attr); | 
|  | 12170 | nla_nest_end(msg, match_attr); | 
|  | 12171 | genlmsg_end(msg, hdr); | 
|  | 12172 |  | 
|  | 12173 | if (!wdev->owner_nlportid) | 
|  | 12174 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | 
|  | 12175 | msg, 0, NL80211_MCGRP_NAN, gfp); | 
|  | 12176 | else | 
|  | 12177 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | 
|  | 12178 | wdev->owner_nlportid); | 
|  | 12179 |  | 
|  | 12180 | return; | 
|  | 12181 |  | 
|  | 12182 | nla_put_failure: | 
|  | 12183 | nlmsg_free(msg); | 
|  | 12184 | } | 
|  | 12185 | EXPORT_SYMBOL(cfg80211_nan_match); | 
|  | 12186 |  | 
|  | 12187 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, | 
|  | 12188 | u8 inst_id, | 
|  | 12189 | enum nl80211_nan_func_term_reason reason, | 
|  | 12190 | u64 cookie, gfp_t gfp) | 
|  | 12191 | { | 
|  | 12192 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 12193 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 12194 | struct sk_buff *msg; | 
|  | 12195 | struct nlattr *func_attr; | 
|  | 12196 | void *hdr; | 
|  | 12197 |  | 
|  | 12198 | if (WARN_ON(!inst_id)) | 
|  | 12199 | return; | 
|  | 12200 |  | 
|  | 12201 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 12202 | if (!msg) | 
|  | 12203 | return; | 
|  | 12204 |  | 
|  | 12205 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); | 
|  | 12206 | if (!hdr) { | 
|  | 12207 | nlmsg_free(msg); | 
|  | 12208 | return; | 
|  | 12209 | } | 
|  | 12210 |  | 
|  | 12211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 12212 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 12213 | wdev->netdev->ifindex)) || | 
|  | 12214 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 12215 | NL80211_ATTR_PAD)) | 
|  | 12216 | goto nla_put_failure; | 
|  | 12217 |  | 
|  | 12218 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 12219 | NL80211_ATTR_PAD)) | 
|  | 12220 | goto nla_put_failure; | 
|  | 12221 |  | 
|  | 12222 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); | 
|  | 12223 | if (!func_attr) | 
|  | 12224 | goto nla_put_failure; | 
|  | 12225 |  | 
|  | 12226 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || | 
|  | 12227 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) | 
|  | 12228 | goto nla_put_failure; | 
|  | 12229 |  | 
|  | 12230 | nla_nest_end(msg, func_attr); | 
|  | 12231 | genlmsg_end(msg, hdr); | 
|  | 12232 |  | 
|  | 12233 | if (!wdev->owner_nlportid) | 
|  | 12234 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | 
|  | 12235 | msg, 0, NL80211_MCGRP_NAN, gfp); | 
|  | 12236 | else | 
|  | 12237 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | 
|  | 12238 | wdev->owner_nlportid); | 
|  | 12239 |  | 
|  | 12240 | return; | 
|  | 12241 |  | 
|  | 12242 | nla_put_failure: | 
|  | 12243 | nlmsg_free(msg); | 
|  | 12244 | } | 
|  | 12245 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); | 
|  | 12246 |  | 
|  | 12247 | static int nl80211_get_protocol_features(struct sk_buff *skb, | 
|  | 12248 | struct genl_info *info) | 
|  | 12249 | { | 
|  | 12250 | void *hdr; | 
|  | 12251 | struct sk_buff *msg; | 
|  | 12252 |  | 
|  | 12253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 12254 | if (!msg) | 
|  | 12255 | return -ENOMEM; | 
|  | 12256 |  | 
|  | 12257 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
|  | 12258 | NL80211_CMD_GET_PROTOCOL_FEATURES); | 
|  | 12259 | if (!hdr) | 
|  | 12260 | goto nla_put_failure; | 
|  | 12261 |  | 
|  | 12262 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | 
|  | 12263 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | 
|  | 12264 | goto nla_put_failure; | 
|  | 12265 |  | 
|  | 12266 | genlmsg_end(msg, hdr); | 
|  | 12267 | return genlmsg_reply(msg, info); | 
|  | 12268 |  | 
|  | 12269 | nla_put_failure: | 
|  | 12270 | kfree_skb(msg); | 
|  | 12271 | return -ENOBUFS; | 
|  | 12272 | } | 
|  | 12273 |  | 
|  | 12274 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) | 
|  | 12275 | { | 
|  | 12276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12277 | struct cfg80211_update_ft_ies_params ft_params; | 
|  | 12278 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12279 |  | 
|  | 12280 | if (!rdev->ops->update_ft_ies) | 
|  | 12281 | return -EOPNOTSUPP; | 
|  | 12282 |  | 
|  | 12283 | if (!info->attrs[NL80211_ATTR_MDID] || | 
|  | 12284 | !info->attrs[NL80211_ATTR_IE] || | 
|  | 12285 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
|  | 12286 | return -EINVAL; | 
|  | 12287 |  | 
|  | 12288 | memset(&ft_params, 0, sizeof(ft_params)); | 
|  | 12289 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | 
|  | 12290 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
|  | 12291 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
|  | 12292 |  | 
|  | 12293 | return rdev_update_ft_ies(rdev, dev, &ft_params); | 
|  | 12294 | } | 
|  | 12295 |  | 
|  | 12296 | static int nl80211_crit_protocol_start(struct sk_buff *skb, | 
|  | 12297 | struct genl_info *info) | 
|  | 12298 | { | 
|  | 12299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12300 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 12301 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | 
|  | 12302 | u16 duration; | 
|  | 12303 | int ret; | 
|  | 12304 |  | 
|  | 12305 | if (!rdev->ops->crit_proto_start) | 
|  | 12306 | return -EOPNOTSUPP; | 
|  | 12307 |  | 
|  | 12308 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | 
|  | 12309 | return -EINVAL; | 
|  | 12310 |  | 
|  | 12311 | if (rdev->crit_proto_nlportid) | 
|  | 12312 | return -EBUSY; | 
|  | 12313 |  | 
|  | 12314 | /* determine protocol if provided */ | 
|  | 12315 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | 
|  | 12316 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | 
|  | 12317 |  | 
|  | 12318 | if (proto >= NUM_NL80211_CRIT_PROTO) | 
|  | 12319 | return -EINVAL; | 
|  | 12320 |  | 
|  | 12321 | /* timeout must be provided */ | 
|  | 12322 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | 
|  | 12323 | return -EINVAL; | 
|  | 12324 |  | 
|  | 12325 | duration = | 
|  | 12326 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | 
|  | 12327 |  | 
|  | 12328 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | 
|  | 12329 | return -ERANGE; | 
|  | 12330 |  | 
|  | 12331 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | 
|  | 12332 | if (!ret) | 
|  | 12333 | rdev->crit_proto_nlportid = info->snd_portid; | 
|  | 12334 |  | 
|  | 12335 | return ret; | 
|  | 12336 | } | 
|  | 12337 |  | 
|  | 12338 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | 
|  | 12339 | struct genl_info *info) | 
|  | 12340 | { | 
|  | 12341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12342 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 12343 |  | 
|  | 12344 | if (!rdev->ops->crit_proto_stop) | 
|  | 12345 | return -EOPNOTSUPP; | 
|  | 12346 |  | 
|  | 12347 | if (rdev->crit_proto_nlportid) { | 
|  | 12348 | rdev->crit_proto_nlportid = 0; | 
|  | 12349 | rdev_crit_proto_stop(rdev, wdev); | 
|  | 12350 | } | 
|  | 12351 | return 0; | 
|  | 12352 | } | 
|  | 12353 |  | 
|  | 12354 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) | 
|  | 12355 | { | 
|  | 12356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12357 | struct wireless_dev *wdev = | 
|  | 12358 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | 
|  | 12359 | int i, err; | 
|  | 12360 | u32 vid, subcmd; | 
|  | 12361 |  | 
|  | 12362 | if (!rdev->wiphy.vendor_commands) | 
|  | 12363 | return -EOPNOTSUPP; | 
|  | 12364 |  | 
|  | 12365 | if (IS_ERR(wdev)) { | 
|  | 12366 | err = PTR_ERR(wdev); | 
|  | 12367 | if (err != -EINVAL) | 
|  | 12368 | return err; | 
|  | 12369 | wdev = NULL; | 
|  | 12370 | } else if (wdev->wiphy != &rdev->wiphy) { | 
|  | 12371 | return -EINVAL; | 
|  | 12372 | } | 
|  | 12373 |  | 
|  | 12374 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | 
|  | 12375 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | 
|  | 12376 | return -EINVAL; | 
|  | 12377 |  | 
|  | 12378 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | 
|  | 12379 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | 
|  | 12380 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | 
|  | 12381 | const struct wiphy_vendor_command *vcmd; | 
|  | 12382 | void *data = NULL; | 
|  | 12383 | int len = 0; | 
|  | 12384 |  | 
|  | 12385 | vcmd = &rdev->wiphy.vendor_commands[i]; | 
|  | 12386 |  | 
|  | 12387 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | 
|  | 12388 | continue; | 
|  | 12389 |  | 
|  | 12390 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | 
|  | 12391 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | 
|  | 12392 | if (!wdev) | 
|  | 12393 | return -EINVAL; | 
|  | 12394 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | 
|  | 12395 | !wdev->netdev) | 
|  | 12396 | return -EINVAL; | 
|  | 12397 |  | 
|  | 12398 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | 
|  | 12399 | if (!wdev_running(wdev)) | 
|  | 12400 | return -ENETDOWN; | 
|  | 12401 | } | 
|  | 12402 |  | 
|  | 12403 | if (!vcmd->doit) | 
|  | 12404 | return -EOPNOTSUPP; | 
|  | 12405 | } else { | 
|  | 12406 | wdev = NULL; | 
|  | 12407 | } | 
|  | 12408 |  | 
|  | 12409 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | 
|  | 12410 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | 
|  | 12411 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | 
|  | 12412 | } | 
|  | 12413 |  | 
|  | 12414 | rdev->cur_cmd_info = info; | 
|  | 12415 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | 
|  | 12416 | data, len); | 
|  | 12417 | rdev->cur_cmd_info = NULL; | 
|  | 12418 | return err; | 
|  | 12419 | } | 
|  | 12420 |  | 
|  | 12421 | return -EOPNOTSUPP; | 
|  | 12422 | } | 
|  | 12423 |  | 
|  | 12424 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, | 
|  | 12425 | struct netlink_callback *cb, | 
|  | 12426 | struct cfg80211_registered_device **rdev, | 
|  | 12427 | struct wireless_dev **wdev) | 
|  | 12428 | { | 
|  | 12429 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); | 
|  | 12430 | u32 vid, subcmd; | 
|  | 12431 | unsigned int i; | 
|  | 12432 | int vcmd_idx = -1; | 
|  | 12433 | int err; | 
|  | 12434 | void *data = NULL; | 
|  | 12435 | unsigned int data_len = 0; | 
|  | 12436 |  | 
|  | 12437 | if (cb->args[0]) { | 
|  | 12438 | /* subtract the 1 again here */ | 
|  | 12439 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | 
|  | 12440 | struct wireless_dev *tmp; | 
|  | 12441 |  | 
|  | 12442 | if (!wiphy) | 
|  | 12443 | return -ENODEV; | 
|  | 12444 | *rdev = wiphy_to_rdev(wiphy); | 
|  | 12445 | *wdev = NULL; | 
|  | 12446 |  | 
|  | 12447 | if (cb->args[1]) { | 
|  | 12448 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { | 
|  | 12449 | if (tmp->identifier == cb->args[1] - 1) { | 
|  | 12450 | *wdev = tmp; | 
|  | 12451 | break; | 
|  | 12452 | } | 
|  | 12453 | } | 
|  | 12454 | } | 
|  | 12455 |  | 
|  | 12456 | /* keep rtnl locked in successful case */ | 
|  | 12457 | return 0; | 
|  | 12458 | } | 
|  | 12459 |  | 
|  | 12460 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, | 
|  | 12461 | nl80211_fam.maxattr, nl80211_policy, NULL); | 
|  | 12462 | if (err) | 
|  | 12463 | return err; | 
|  | 12464 |  | 
|  | 12465 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || | 
|  | 12466 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) | 
|  | 12467 | return -EINVAL; | 
|  | 12468 |  | 
|  | 12469 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); | 
|  | 12470 | if (IS_ERR(*wdev)) | 
|  | 12471 | *wdev = NULL; | 
|  | 12472 |  | 
|  | 12473 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); | 
|  | 12474 | if (IS_ERR(*rdev)) | 
|  | 12475 | return PTR_ERR(*rdev); | 
|  | 12476 |  | 
|  | 12477 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); | 
|  | 12478 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | 
|  | 12479 |  | 
|  | 12480 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | 
|  | 12481 | const struct wiphy_vendor_command *vcmd; | 
|  | 12482 |  | 
|  | 12483 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | 
|  | 12484 |  | 
|  | 12485 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | 
|  | 12486 | continue; | 
|  | 12487 |  | 
|  | 12488 | if (!vcmd->dumpit) | 
|  | 12489 | return -EOPNOTSUPP; | 
|  | 12490 |  | 
|  | 12491 | vcmd_idx = i; | 
|  | 12492 | break; | 
|  | 12493 | } | 
|  | 12494 |  | 
|  | 12495 | if (vcmd_idx < 0) | 
|  | 12496 | return -EOPNOTSUPP; | 
|  | 12497 |  | 
|  | 12498 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { | 
|  | 12499 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); | 
|  | 12500 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); | 
|  | 12501 | } | 
|  | 12502 |  | 
|  | 12503 | /* 0 is the first index - add 1 to parse only once */ | 
|  | 12504 | cb->args[0] = (*rdev)->wiphy_idx + 1; | 
|  | 12505 | /* add 1 to know if it was NULL */ | 
|  | 12506 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | 
|  | 12507 | cb->args[2] = vcmd_idx; | 
|  | 12508 | cb->args[3] = (unsigned long)data; | 
|  | 12509 | cb->args[4] = data_len; | 
|  | 12510 |  | 
|  | 12511 | /* keep rtnl locked in successful case */ | 
|  | 12512 | return 0; | 
|  | 12513 | } | 
|  | 12514 |  | 
|  | 12515 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | 
|  | 12516 | struct netlink_callback *cb) | 
|  | 12517 | { | 
|  | 12518 | struct cfg80211_registered_device *rdev; | 
|  | 12519 | struct wireless_dev *wdev; | 
|  | 12520 | unsigned int vcmd_idx; | 
|  | 12521 | const struct wiphy_vendor_command *vcmd; | 
|  | 12522 | void *data; | 
|  | 12523 | int data_len; | 
|  | 12524 | int err; | 
|  | 12525 | struct nlattr *vendor_data; | 
|  | 12526 |  | 
|  | 12527 | rtnl_lock(); | 
|  | 12528 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); | 
|  | 12529 | if (err) | 
|  | 12530 | goto out; | 
|  | 12531 |  | 
|  | 12532 | vcmd_idx = cb->args[2]; | 
|  | 12533 | data = (void *)cb->args[3]; | 
|  | 12534 | data_len = cb->args[4]; | 
|  | 12535 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | 
|  | 12536 |  | 
|  | 12537 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | 
|  | 12538 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | 
|  | 12539 | if (!wdev) { | 
|  | 12540 | err = -EINVAL; | 
|  | 12541 | goto out; | 
|  | 12542 | } | 
|  | 12543 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | 
|  | 12544 | !wdev->netdev) { | 
|  | 12545 | err = -EINVAL; | 
|  | 12546 | goto out; | 
|  | 12547 | } | 
|  | 12548 |  | 
|  | 12549 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | 
|  | 12550 | if (!wdev_running(wdev)) { | 
|  | 12551 | err = -ENETDOWN; | 
|  | 12552 | goto out; | 
|  | 12553 | } | 
|  | 12554 | } | 
|  | 12555 | } | 
|  | 12556 |  | 
|  | 12557 | while (1) { | 
|  | 12558 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | 
|  | 12559 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
|  | 12560 | NL80211_CMD_VENDOR); | 
|  | 12561 | if (!hdr) | 
|  | 12562 | break; | 
|  | 12563 |  | 
|  | 12564 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 12565 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, | 
|  | 12566 | wdev_id(wdev), | 
|  | 12567 | NL80211_ATTR_PAD))) { | 
|  | 12568 | genlmsg_cancel(skb, hdr); | 
|  | 12569 | break; | 
|  | 12570 | } | 
|  | 12571 |  | 
|  | 12572 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); | 
|  | 12573 | if (!vendor_data) { | 
|  | 12574 | genlmsg_cancel(skb, hdr); | 
|  | 12575 | break; | 
|  | 12576 | } | 
|  | 12577 |  | 
|  | 12578 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | 
|  | 12579 | (unsigned long *)&cb->args[5]); | 
|  | 12580 | nla_nest_end(skb, vendor_data); | 
|  | 12581 |  | 
|  | 12582 | if (err == -ENOBUFS || err == -ENOENT) { | 
|  | 12583 | genlmsg_cancel(skb, hdr); | 
|  | 12584 | break; | 
|  | 12585 | } else if (err) { | 
|  | 12586 | genlmsg_cancel(skb, hdr); | 
|  | 12587 | goto out; | 
|  | 12588 | } | 
|  | 12589 |  | 
|  | 12590 | genlmsg_end(skb, hdr); | 
|  | 12591 | } | 
|  | 12592 |  | 
|  | 12593 | err = skb->len; | 
|  | 12594 | out: | 
|  | 12595 | rtnl_unlock(); | 
|  | 12596 | return err; | 
|  | 12597 | } | 
|  | 12598 |  | 
|  | 12599 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | 
|  | 12600 | enum nl80211_commands cmd, | 
|  | 12601 | enum nl80211_attrs attr, | 
|  | 12602 | int approxlen) | 
|  | 12603 | { | 
|  | 12604 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 12605 |  | 
|  | 12606 | if (WARN_ON(!rdev->cur_cmd_info)) | 
|  | 12607 | return NULL; | 
|  | 12608 |  | 
|  | 12609 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, | 
|  | 12610 | rdev->cur_cmd_info->snd_portid, | 
|  | 12611 | rdev->cur_cmd_info->snd_seq, | 
|  | 12612 | cmd, attr, NULL, GFP_KERNEL); | 
|  | 12613 | } | 
|  | 12614 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | 
|  | 12615 |  | 
|  | 12616 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | 
|  | 12617 | { | 
|  | 12618 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | 
|  | 12619 | void *hdr = ((void **)skb->cb)[1]; | 
|  | 12620 | struct nlattr *data = ((void **)skb->cb)[2]; | 
|  | 12621 |  | 
|  | 12622 | /* clear CB data for netlink core to own from now on */ | 
|  | 12623 | memset(skb->cb, 0, sizeof(skb->cb)); | 
|  | 12624 |  | 
|  | 12625 | if (WARN_ON(!rdev->cur_cmd_info)) { | 
|  | 12626 | kfree_skb(skb); | 
|  | 12627 | return -EINVAL; | 
|  | 12628 | } | 
|  | 12629 |  | 
|  | 12630 | nla_nest_end(skb, data); | 
|  | 12631 | genlmsg_end(skb, hdr); | 
|  | 12632 | return genlmsg_reply(skb, rdev->cur_cmd_info); | 
|  | 12633 | } | 
|  | 12634 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | 
|  | 12635 |  | 
|  | 12636 | static int nl80211_set_qos_map(struct sk_buff *skb, | 
|  | 12637 | struct genl_info *info) | 
|  | 12638 | { | 
|  | 12639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12640 | struct cfg80211_qos_map *qos_map = NULL; | 
|  | 12641 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12642 | u8 *pos, len, num_des, des_len, des; | 
|  | 12643 | int ret; | 
|  | 12644 |  | 
|  | 12645 | if (!rdev->ops->set_qos_map) | 
|  | 12646 | return -EOPNOTSUPP; | 
|  | 12647 |  | 
|  | 12648 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | 
|  | 12649 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | 
|  | 12650 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | 
|  | 12651 |  | 
|  | 12652 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | 
|  | 12653 | len > IEEE80211_QOS_MAP_LEN_MAX) | 
|  | 12654 | return -EINVAL; | 
|  | 12655 |  | 
|  | 12656 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | 
|  | 12657 | if (!qos_map) | 
|  | 12658 | return -ENOMEM; | 
|  | 12659 |  | 
|  | 12660 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | 
|  | 12661 | if (num_des) { | 
|  | 12662 | des_len = num_des * | 
|  | 12663 | sizeof(struct cfg80211_dscp_exception); | 
|  | 12664 | memcpy(qos_map->dscp_exception, pos, des_len); | 
|  | 12665 | qos_map->num_des = num_des; | 
|  | 12666 | for (des = 0; des < num_des; des++) { | 
|  | 12667 | if (qos_map->dscp_exception[des].up > 7) { | 
|  | 12668 | kfree(qos_map); | 
|  | 12669 | return -EINVAL; | 
|  | 12670 | } | 
|  | 12671 | } | 
|  | 12672 | pos += des_len; | 
|  | 12673 | } | 
|  | 12674 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | 
|  | 12675 | } | 
|  | 12676 |  | 
|  | 12677 | wdev_lock(dev->ieee80211_ptr); | 
|  | 12678 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | 
|  | 12679 | if (!ret) | 
|  | 12680 | ret = rdev_set_qos_map(rdev, dev, qos_map); | 
|  | 12681 | wdev_unlock(dev->ieee80211_ptr); | 
|  | 12682 |  | 
|  | 12683 | kfree(qos_map); | 
|  | 12684 | return ret; | 
|  | 12685 | } | 
|  | 12686 |  | 
|  | 12687 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) | 
|  | 12688 | { | 
|  | 12689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12690 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12691 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12692 | const u8 *peer; | 
|  | 12693 | u8 tsid, up; | 
|  | 12694 | u16 admitted_time = 0; | 
|  | 12695 | int err; | 
|  | 12696 |  | 
|  | 12697 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) | 
|  | 12698 | return -EOPNOTSUPP; | 
|  | 12699 |  | 
|  | 12700 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | 
|  | 12701 | !info->attrs[NL80211_ATTR_USER_PRIO]) | 
|  | 12702 | return -EINVAL; | 
|  | 12703 |  | 
|  | 12704 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | 
|  | 12705 | if (tsid >= IEEE80211_NUM_TIDS) | 
|  | 12706 | return -EINVAL; | 
|  | 12707 |  | 
|  | 12708 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | 
|  | 12709 | if (up >= IEEE80211_NUM_UPS) | 
|  | 12710 | return -EINVAL; | 
|  | 12711 |  | 
|  | 12712 | /* WMM uses TIDs 0-7 even for TSPEC */ | 
|  | 12713 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { | 
|  | 12714 | /* TODO: handle 802.11 TSPEC/admission control | 
|  | 12715 | * need more attributes for that (e.g. BA session requirement); | 
|  | 12716 | * change the WMM adminssion test above to allow both then | 
|  | 12717 | */ | 
|  | 12718 | return -EINVAL; | 
|  | 12719 | } | 
|  | 12720 |  | 
|  | 12721 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 12722 |  | 
|  | 12723 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | 
|  | 12724 | admitted_time = | 
|  | 12725 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | 
|  | 12726 | if (!admitted_time) | 
|  | 12727 | return -EINVAL; | 
|  | 12728 | } | 
|  | 12729 |  | 
|  | 12730 | wdev_lock(wdev); | 
|  | 12731 | switch (wdev->iftype) { | 
|  | 12732 | case NL80211_IFTYPE_STATION: | 
|  | 12733 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 12734 | if (wdev->current_bss) | 
|  | 12735 | break; | 
|  | 12736 | err = -ENOTCONN; | 
|  | 12737 | goto out; | 
|  | 12738 | default: | 
|  | 12739 | err = -EOPNOTSUPP; | 
|  | 12740 | goto out; | 
|  | 12741 | } | 
|  | 12742 |  | 
|  | 12743 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | 
|  | 12744 |  | 
|  | 12745 | out: | 
|  | 12746 | wdev_unlock(wdev); | 
|  | 12747 | return err; | 
|  | 12748 | } | 
|  | 12749 |  | 
|  | 12750 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | 
|  | 12751 | { | 
|  | 12752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12753 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12754 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12755 | const u8 *peer; | 
|  | 12756 | u8 tsid; | 
|  | 12757 | int err; | 
|  | 12758 |  | 
|  | 12759 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | 
|  | 12760 | return -EINVAL; | 
|  | 12761 |  | 
|  | 12762 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | 
|  | 12763 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 12764 |  | 
|  | 12765 | wdev_lock(wdev); | 
|  | 12766 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | 
|  | 12767 | wdev_unlock(wdev); | 
|  | 12768 |  | 
|  | 12769 | return err; | 
|  | 12770 | } | 
|  | 12771 |  | 
|  | 12772 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, | 
|  | 12773 | struct genl_info *info) | 
|  | 12774 | { | 
|  | 12775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12776 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12777 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12778 | struct cfg80211_chan_def chandef = {}; | 
|  | 12779 | const u8 *addr; | 
|  | 12780 | u8 oper_class; | 
|  | 12781 | int err; | 
|  | 12782 |  | 
|  | 12783 | if (!rdev->ops->tdls_channel_switch || | 
|  | 12784 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | 
|  | 12785 | return -EOPNOTSUPP; | 
|  | 12786 |  | 
|  | 12787 | switch (dev->ieee80211_ptr->iftype) { | 
|  | 12788 | case NL80211_IFTYPE_STATION: | 
|  | 12789 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 12790 | break; | 
|  | 12791 | default: | 
|  | 12792 | return -EOPNOTSUPP; | 
|  | 12793 | } | 
|  | 12794 |  | 
|  | 12795 | if (!info->attrs[NL80211_ATTR_MAC] || | 
|  | 12796 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | 
|  | 12797 | return -EINVAL; | 
|  | 12798 |  | 
|  | 12799 | err = nl80211_parse_chandef(rdev, info, &chandef); | 
|  | 12800 | if (err) | 
|  | 12801 | return err; | 
|  | 12802 |  | 
|  | 12803 | /* | 
|  | 12804 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | 
|  | 12805 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | 
|  | 12806 | * specification is not defined for them. | 
|  | 12807 | */ | 
|  | 12808 | if (chandef.chan->band == NL80211_BAND_2GHZ && | 
|  | 12809 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | 
|  | 12810 | chandef.width != NL80211_CHAN_WIDTH_20) | 
|  | 12811 | return -EINVAL; | 
|  | 12812 |  | 
|  | 12813 | /* we will be active on the TDLS link */ | 
|  | 12814 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, | 
|  | 12815 | wdev->iftype)) | 
|  | 12816 | return -EINVAL; | 
|  | 12817 |  | 
|  | 12818 | /* don't allow switching to DFS channels */ | 
|  | 12819 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | 
|  | 12820 | return -EINVAL; | 
|  | 12821 |  | 
|  | 12822 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 12823 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | 
|  | 12824 |  | 
|  | 12825 | wdev_lock(wdev); | 
|  | 12826 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | 
|  | 12827 | wdev_unlock(wdev); | 
|  | 12828 |  | 
|  | 12829 | return err; | 
|  | 12830 | } | 
|  | 12831 |  | 
|  | 12832 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | 
|  | 12833 | struct genl_info *info) | 
|  | 12834 | { | 
|  | 12835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12836 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12837 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12838 | const u8 *addr; | 
|  | 12839 |  | 
|  | 12840 | if (!rdev->ops->tdls_channel_switch || | 
|  | 12841 | !rdev->ops->tdls_cancel_channel_switch || | 
|  | 12842 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | 
|  | 12843 | return -EOPNOTSUPP; | 
|  | 12844 |  | 
|  | 12845 | switch (dev->ieee80211_ptr->iftype) { | 
|  | 12846 | case NL80211_IFTYPE_STATION: | 
|  | 12847 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 12848 | break; | 
|  | 12849 | default: | 
|  | 12850 | return -EOPNOTSUPP; | 
|  | 12851 | } | 
|  | 12852 |  | 
|  | 12853 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 12854 | return -EINVAL; | 
|  | 12855 |  | 
|  | 12856 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 12857 |  | 
|  | 12858 | wdev_lock(wdev); | 
|  | 12859 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | 
|  | 12860 | wdev_unlock(wdev); | 
|  | 12861 |  | 
|  | 12862 | return 0; | 
|  | 12863 | } | 
|  | 12864 |  | 
|  | 12865 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, | 
|  | 12866 | struct genl_info *info) | 
|  | 12867 | { | 
|  | 12868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12869 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12870 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12871 | const struct nlattr *nla; | 
|  | 12872 | bool enabled; | 
|  | 12873 |  | 
|  | 12874 | if (!rdev->ops->set_multicast_to_unicast) | 
|  | 12875 | return -EOPNOTSUPP; | 
|  | 12876 |  | 
|  | 12877 | if (wdev->iftype != NL80211_IFTYPE_AP && | 
|  | 12878 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 12879 | return -EOPNOTSUPP; | 
|  | 12880 |  | 
|  | 12881 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; | 
|  | 12882 | enabled = nla_get_flag(nla); | 
|  | 12883 |  | 
|  | 12884 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); | 
|  | 12885 | } | 
|  | 12886 |  | 
|  | 12887 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) | 
|  | 12888 | { | 
|  | 12889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12890 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12891 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12892 | struct cfg80211_pmk_conf pmk_conf = {}; | 
|  | 12893 | int ret; | 
|  | 12894 |  | 
|  | 12895 | if (wdev->iftype != NL80211_IFTYPE_STATION && | 
|  | 12896 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 12897 | return -EOPNOTSUPP; | 
|  | 12898 |  | 
|  | 12899 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 12900 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | 
|  | 12901 | return -EOPNOTSUPP; | 
|  | 12902 |  | 
|  | 12903 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) | 
|  | 12904 | return -EINVAL; | 
|  | 12905 |  | 
|  | 12906 | wdev_lock(wdev); | 
|  | 12907 | if (!wdev->current_bss) { | 
|  | 12908 | ret = -ENOTCONN; | 
|  | 12909 | goto out; | 
|  | 12910 | } | 
|  | 12911 |  | 
|  | 12912 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 12913 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { | 
|  | 12914 | ret = -EINVAL; | 
|  | 12915 | goto out; | 
|  | 12916 | } | 
|  | 12917 |  | 
|  | 12918 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | 
|  | 12919 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | 
|  | 12920 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && | 
|  | 12921 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { | 
|  | 12922 | ret = -EINVAL; | 
|  | 12923 | goto out; | 
|  | 12924 | } | 
|  | 12925 |  | 
|  | 12926 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { | 
|  | 12927 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); | 
|  | 12928 |  | 
|  | 12929 | if (r0_name_len != WLAN_PMK_NAME_LEN) { | 
|  | 12930 | ret = -EINVAL; | 
|  | 12931 | goto out; | 
|  | 12932 | } | 
|  | 12933 |  | 
|  | 12934 | pmk_conf.pmk_r0_name = | 
|  | 12935 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); | 
|  | 12936 | } | 
|  | 12937 |  | 
|  | 12938 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); | 
|  | 12939 | out: | 
|  | 12940 | wdev_unlock(wdev); | 
|  | 12941 | return ret; | 
|  | 12942 | } | 
|  | 12943 |  | 
|  | 12944 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) | 
|  | 12945 | { | 
|  | 12946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12947 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12948 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 12949 | const u8 *aa; | 
|  | 12950 | int ret; | 
|  | 12951 |  | 
|  | 12952 | if (wdev->iftype != NL80211_IFTYPE_STATION && | 
|  | 12953 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 12954 | return -EOPNOTSUPP; | 
|  | 12955 |  | 
|  | 12956 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 12957 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | 
|  | 12958 | return -EOPNOTSUPP; | 
|  | 12959 |  | 
|  | 12960 | if (!info->attrs[NL80211_ATTR_MAC]) | 
|  | 12961 | return -EINVAL; | 
|  | 12962 |  | 
|  | 12963 | wdev_lock(wdev); | 
|  | 12964 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 12965 | ret = rdev_del_pmk(rdev, dev, aa); | 
|  | 12966 | wdev_unlock(wdev); | 
|  | 12967 |  | 
|  | 12968 | return ret; | 
|  | 12969 | } | 
|  | 12970 |  | 
|  | 12971 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) | 
|  | 12972 | { | 
|  | 12973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 12974 | struct net_device *dev = info->user_ptr[1]; | 
|  | 12975 | struct cfg80211_external_auth_params params; | 
|  | 12976 |  | 
|  | 12977 | if (!rdev->ops->external_auth) | 
|  | 12978 | return -EOPNOTSUPP; | 
|  | 12979 |  | 
|  | 12980 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 12981 | if (!info->attrs[NL80211_ATTR_SSID] && | 
|  | 12982 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
|  | 12983 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
|  | 12984 | return -EINVAL; | 
|  | 12985 | //tianyan@2021.7.27 modify for add wifi6 module end | 
|  | 12986 |  | 
|  | 12987 | if (!info->attrs[NL80211_ATTR_BSSID]) | 
|  | 12988 | return -EINVAL; | 
|  | 12989 |  | 
|  | 12990 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) | 
|  | 12991 | return -EINVAL; | 
|  | 12992 |  | 
|  | 12993 | memset(¶ms, 0, sizeof(params)); | 
|  | 12994 |  | 
|  | 12995 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 12996 | if (info->attrs[NL80211_ATTR_SSID]) { | 
|  | 12997 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
|  | 12998 | if (params.ssid.ssid_len == 0 || | 
|  | 12999 | params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) | 
|  | 13000 | return -EINVAL; | 
|  | 13001 | memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]), | 
|  | 13002 | params.ssid.ssid_len); | 
|  | 13003 | } | 
|  | 13004 | //tianyan@2021.7.27 modify for add wifi6 module end | 
|  | 13005 |  | 
|  | 13006 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), | 
|  | 13007 | ETH_ALEN); | 
|  | 13008 |  | 
|  | 13009 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | 
|  | 13010 |  | 
|  | 13011 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 13012 | if (info->attrs[NL80211_ATTR_PMKID]) | 
|  | 13013 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | 
|  | 13014 | //tianyan@2021.7.27 modify for add wifi6 module start | 
|  | 13015 |  | 
|  | 13016 | return rdev_external_auth(rdev, dev, ¶ms); | 
|  | 13017 | } | 
|  | 13018 |  | 
|  | 13019 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) | 
|  | 13020 | { | 
|  | 13021 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
|  | 13022 | struct net_device *dev = info->user_ptr[1]; | 
|  | 13023 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 13024 | const u8 *buf; | 
|  | 13025 | size_t len; | 
|  | 13026 | u8 *dest; | 
|  | 13027 | u16 proto; | 
|  | 13028 | bool noencrypt; | 
|  | 13029 | int err; | 
|  | 13030 |  | 
|  | 13031 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | 
|  | 13032 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) | 
|  | 13033 | return -EOPNOTSUPP; | 
|  | 13034 |  | 
|  | 13035 | if (!rdev->ops->tx_control_port) | 
|  | 13036 | return -EOPNOTSUPP; | 
|  | 13037 |  | 
|  | 13038 | if (!info->attrs[NL80211_ATTR_FRAME] || | 
|  | 13039 | !info->attrs[NL80211_ATTR_MAC] || | 
|  | 13040 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { | 
|  | 13041 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); | 
|  | 13042 | return -EINVAL; | 
|  | 13043 | } | 
|  | 13044 |  | 
|  | 13045 | wdev_lock(wdev); | 
|  | 13046 |  | 
|  | 13047 | switch (wdev->iftype) { | 
|  | 13048 | case NL80211_IFTYPE_AP: | 
|  | 13049 | case NL80211_IFTYPE_P2P_GO: | 
|  | 13050 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 13051 | break; | 
|  | 13052 | case NL80211_IFTYPE_ADHOC: | 
|  | 13053 | case NL80211_IFTYPE_STATION: | 
|  | 13054 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 13055 | if (wdev->current_bss) | 
|  | 13056 | break; | 
|  | 13057 | err = -ENOTCONN; | 
|  | 13058 | goto out; | 
|  | 13059 | default: | 
|  | 13060 | err = -EOPNOTSUPP; | 
|  | 13061 | goto out; | 
|  | 13062 | } | 
|  | 13063 |  | 
|  | 13064 | wdev_unlock(wdev); | 
|  | 13065 |  | 
|  | 13066 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | 
|  | 13067 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | 
|  | 13068 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
|  | 13069 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | 
|  | 13070 | noencrypt = | 
|  | 13071 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); | 
|  | 13072 |  | 
|  | 13073 | return rdev_tx_control_port(rdev, dev, buf, len, | 
|  | 13074 | dest, cpu_to_be16(proto), noencrypt); | 
|  | 13075 |  | 
|  | 13076 | out: | 
|  | 13077 | wdev_unlock(wdev); | 
|  | 13078 | return err; | 
|  | 13079 | } | 
|  | 13080 |  | 
|  | 13081 | #define NL80211_FLAG_NEED_WIPHY		0x01 | 
|  | 13082 | #define NL80211_FLAG_NEED_NETDEV	0x02 | 
|  | 13083 | #define NL80211_FLAG_NEED_RTNL		0x04 | 
|  | 13084 | #define NL80211_FLAG_CHECK_NETDEV_UP	0x08 | 
|  | 13085 | #define NL80211_FLAG_NEED_NETDEV_UP	(NL80211_FLAG_NEED_NETDEV |\ | 
|  | 13086 | NL80211_FLAG_CHECK_NETDEV_UP) | 
|  | 13087 | #define NL80211_FLAG_NEED_WDEV		0x10 | 
|  | 13088 | /* If a netdev is associated, it must be UP, P2P must be started */ | 
|  | 13089 | #define NL80211_FLAG_NEED_WDEV_UP	(NL80211_FLAG_NEED_WDEV |\ | 
|  | 13090 | NL80211_FLAG_CHECK_NETDEV_UP) | 
|  | 13091 | #define NL80211_FLAG_CLEAR_SKB		0x20 | 
|  | 13092 |  | 
|  | 13093 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, | 
|  | 13094 | struct genl_info *info) | 
|  | 13095 | { | 
|  | 13096 | struct cfg80211_registered_device *rdev; | 
|  | 13097 | struct wireless_dev *wdev; | 
|  | 13098 | struct net_device *dev; | 
|  | 13099 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | 
|  | 13100 |  | 
|  | 13101 | if (rtnl) | 
|  | 13102 | rtnl_lock(); | 
|  | 13103 |  | 
|  | 13104 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | 
|  | 13105 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); | 
|  | 13106 | if (IS_ERR(rdev)) { | 
|  | 13107 | if (rtnl) | 
|  | 13108 | rtnl_unlock(); | 
|  | 13109 | return PTR_ERR(rdev); | 
|  | 13110 | } | 
|  | 13111 | info->user_ptr[0] = rdev; | 
|  | 13112 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || | 
|  | 13113 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | 
|  | 13114 | ASSERT_RTNL(); | 
|  | 13115 |  | 
|  | 13116 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | 
|  | 13117 | info->attrs); | 
|  | 13118 | if (IS_ERR(wdev)) { | 
|  | 13119 | if (rtnl) | 
|  | 13120 | rtnl_unlock(); | 
|  | 13121 | return PTR_ERR(wdev); | 
|  | 13122 | } | 
|  | 13123 |  | 
|  | 13124 | dev = wdev->netdev; | 
|  | 13125 | rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 13126 |  | 
|  | 13127 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | 
|  | 13128 | if (!dev) { | 
|  | 13129 | if (rtnl) | 
|  | 13130 | rtnl_unlock(); | 
|  | 13131 | return -EINVAL; | 
|  | 13132 | } | 
|  | 13133 |  | 
|  | 13134 | info->user_ptr[1] = dev; | 
|  | 13135 | } else { | 
|  | 13136 | info->user_ptr[1] = wdev; | 
|  | 13137 | } | 
|  | 13138 |  | 
|  | 13139 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | 
|  | 13140 | !wdev_running(wdev)) { | 
|  | 13141 | if (rtnl) | 
|  | 13142 | rtnl_unlock(); | 
|  | 13143 | return -ENETDOWN; | 
|  | 13144 | } | 
|  | 13145 |  | 
|  | 13146 | if (dev) | 
|  | 13147 | dev_hold(dev); | 
|  | 13148 |  | 
|  | 13149 | info->user_ptr[0] = rdev; | 
|  | 13150 | } | 
|  | 13151 |  | 
|  | 13152 | return 0; | 
|  | 13153 | } | 
|  | 13154 |  | 
|  | 13155 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, | 
|  | 13156 | struct genl_info *info) | 
|  | 13157 | { | 
|  | 13158 | if (info->user_ptr[1]) { | 
|  | 13159 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | 
|  | 13160 | struct wireless_dev *wdev = info->user_ptr[1]; | 
|  | 13161 |  | 
|  | 13162 | if (wdev->netdev) | 
|  | 13163 | dev_put(wdev->netdev); | 
|  | 13164 | } else { | 
|  | 13165 | dev_put(info->user_ptr[1]); | 
|  | 13166 | } | 
|  | 13167 | } | 
|  | 13168 |  | 
|  | 13169 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | 
|  | 13170 | rtnl_unlock(); | 
|  | 13171 |  | 
|  | 13172 | /* If needed, clear the netlink message payload from the SKB | 
|  | 13173 | * as it might contain key data that shouldn't stick around on | 
|  | 13174 | * the heap after the SKB is freed. The netlink message header | 
|  | 13175 | * is still needed for further processing, so leave it intact. | 
|  | 13176 | */ | 
|  | 13177 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | 
|  | 13178 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | 
|  | 13179 |  | 
|  | 13180 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | 
|  | 13181 | } | 
|  | 13182 | } | 
|  | 13183 |  | 
|  | 13184 | static const struct genl_ops nl80211_ops[] = { | 
|  | 13185 | { | 
|  | 13186 | .cmd = NL80211_CMD_GET_WIPHY, | 
|  | 13187 | .doit = nl80211_get_wiphy, | 
|  | 13188 | .dumpit = nl80211_dump_wiphy, | 
|  | 13189 | .done = nl80211_dump_wiphy_done, | 
|  | 13190 | .policy = nl80211_policy, | 
|  | 13191 | /* can be retrieved by unprivileged users */ | 
|  | 13192 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13193 | NL80211_FLAG_NEED_RTNL, | 
|  | 13194 | }, | 
|  | 13195 | { | 
|  | 13196 | .cmd = NL80211_CMD_SET_WIPHY, | 
|  | 13197 | .doit = nl80211_set_wiphy, | 
|  | 13198 | .policy = nl80211_policy, | 
|  | 13199 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13200 | .internal_flags = NL80211_FLAG_NEED_RTNL, | 
|  | 13201 | }, | 
|  | 13202 | { | 
|  | 13203 | .cmd = NL80211_CMD_GET_INTERFACE, | 
|  | 13204 | .doit = nl80211_get_interface, | 
|  | 13205 | .dumpit = nl80211_dump_interface, | 
|  | 13206 | .policy = nl80211_policy, | 
|  | 13207 | /* can be retrieved by unprivileged users */ | 
|  | 13208 | .internal_flags = NL80211_FLAG_NEED_WDEV | | 
|  | 13209 | NL80211_FLAG_NEED_RTNL, | 
|  | 13210 | }, | 
|  | 13211 | { | 
|  | 13212 | .cmd = NL80211_CMD_SET_INTERFACE, | 
|  | 13213 | .doit = nl80211_set_interface, | 
|  | 13214 | .policy = nl80211_policy, | 
|  | 13215 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13216 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13217 | NL80211_FLAG_NEED_RTNL, | 
|  | 13218 | }, | 
|  | 13219 | { | 
|  | 13220 | .cmd = NL80211_CMD_NEW_INTERFACE, | 
|  | 13221 | .doit = nl80211_new_interface, | 
|  | 13222 | .policy = nl80211_policy, | 
|  | 13223 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13224 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13225 | NL80211_FLAG_NEED_RTNL, | 
|  | 13226 | }, | 
|  | 13227 | { | 
|  | 13228 | .cmd = NL80211_CMD_DEL_INTERFACE, | 
|  | 13229 | .doit = nl80211_del_interface, | 
|  | 13230 | .policy = nl80211_policy, | 
|  | 13231 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13232 | .internal_flags = NL80211_FLAG_NEED_WDEV | | 
|  | 13233 | NL80211_FLAG_NEED_RTNL, | 
|  | 13234 | }, | 
|  | 13235 | { | 
|  | 13236 | .cmd = NL80211_CMD_GET_KEY, | 
|  | 13237 | .doit = nl80211_get_key, | 
|  | 13238 | .policy = nl80211_policy, | 
|  | 13239 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13240 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13241 | NL80211_FLAG_NEED_RTNL, | 
|  | 13242 | }, | 
|  | 13243 | { | 
|  | 13244 | .cmd = NL80211_CMD_SET_KEY, | 
|  | 13245 | .doit = nl80211_set_key, | 
|  | 13246 | .policy = nl80211_policy, | 
|  | 13247 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13248 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13249 | NL80211_FLAG_NEED_RTNL | | 
|  | 13250 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13251 | }, | 
|  | 13252 | { | 
|  | 13253 | .cmd = NL80211_CMD_NEW_KEY, | 
|  | 13254 | .doit = nl80211_new_key, | 
|  | 13255 | .policy = nl80211_policy, | 
|  | 13256 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13258 | NL80211_FLAG_NEED_RTNL | | 
|  | 13259 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13260 | }, | 
|  | 13261 | { | 
|  | 13262 | .cmd = NL80211_CMD_DEL_KEY, | 
|  | 13263 | .doit = nl80211_del_key, | 
|  | 13264 | .policy = nl80211_policy, | 
|  | 13265 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13266 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13267 | NL80211_FLAG_NEED_RTNL, | 
|  | 13268 | }, | 
|  | 13269 | { | 
|  | 13270 | .cmd = NL80211_CMD_SET_BEACON, | 
|  | 13271 | .policy = nl80211_policy, | 
|  | 13272 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13273 | .doit = nl80211_set_beacon, | 
|  | 13274 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13275 | NL80211_FLAG_NEED_RTNL, | 
|  | 13276 | }, | 
|  | 13277 | { | 
|  | 13278 | .cmd = NL80211_CMD_START_AP, | 
|  | 13279 | .policy = nl80211_policy, | 
|  | 13280 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13281 | .doit = nl80211_start_ap, | 
|  | 13282 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13283 | NL80211_FLAG_NEED_RTNL, | 
|  | 13284 | }, | 
|  | 13285 | { | 
|  | 13286 | .cmd = NL80211_CMD_STOP_AP, | 
|  | 13287 | .policy = nl80211_policy, | 
|  | 13288 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13289 | .doit = nl80211_stop_ap, | 
|  | 13290 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13291 | NL80211_FLAG_NEED_RTNL, | 
|  | 13292 | }, | 
|  | 13293 | { | 
|  | 13294 | .cmd = NL80211_CMD_GET_STATION, | 
|  | 13295 | .doit = nl80211_get_station, | 
|  | 13296 | .dumpit = nl80211_dump_station, | 
|  | 13297 | .policy = nl80211_policy, | 
|  | 13298 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13299 | NL80211_FLAG_NEED_RTNL, | 
|  | 13300 | }, | 
|  | 13301 | { | 
|  | 13302 | .cmd = NL80211_CMD_SET_STATION, | 
|  | 13303 | .doit = nl80211_set_station, | 
|  | 13304 | .policy = nl80211_policy, | 
|  | 13305 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13307 | NL80211_FLAG_NEED_RTNL, | 
|  | 13308 | }, | 
|  | 13309 | { | 
|  | 13310 | .cmd = NL80211_CMD_NEW_STATION, | 
|  | 13311 | .doit = nl80211_new_station, | 
|  | 13312 | .policy = nl80211_policy, | 
|  | 13313 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13315 | NL80211_FLAG_NEED_RTNL, | 
|  | 13316 | }, | 
|  | 13317 | { | 
|  | 13318 | .cmd = NL80211_CMD_DEL_STATION, | 
|  | 13319 | .doit = nl80211_del_station, | 
|  | 13320 | .policy = nl80211_policy, | 
|  | 13321 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13322 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13323 | NL80211_FLAG_NEED_RTNL, | 
|  | 13324 | }, | 
|  | 13325 | { | 
|  | 13326 | .cmd = NL80211_CMD_GET_MPATH, | 
|  | 13327 | .doit = nl80211_get_mpath, | 
|  | 13328 | .dumpit = nl80211_dump_mpath, | 
|  | 13329 | .policy = nl80211_policy, | 
|  | 13330 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13331 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13332 | NL80211_FLAG_NEED_RTNL, | 
|  | 13333 | }, | 
|  | 13334 | { | 
|  | 13335 | .cmd = NL80211_CMD_GET_MPP, | 
|  | 13336 | .doit = nl80211_get_mpp, | 
|  | 13337 | .dumpit = nl80211_dump_mpp, | 
|  | 13338 | .policy = nl80211_policy, | 
|  | 13339 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13340 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13341 | NL80211_FLAG_NEED_RTNL, | 
|  | 13342 | }, | 
|  | 13343 | { | 
|  | 13344 | .cmd = NL80211_CMD_SET_MPATH, | 
|  | 13345 | .doit = nl80211_set_mpath, | 
|  | 13346 | .policy = nl80211_policy, | 
|  | 13347 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13348 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13349 | NL80211_FLAG_NEED_RTNL, | 
|  | 13350 | }, | 
|  | 13351 | { | 
|  | 13352 | .cmd = NL80211_CMD_NEW_MPATH, | 
|  | 13353 | .doit = nl80211_new_mpath, | 
|  | 13354 | .policy = nl80211_policy, | 
|  | 13355 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13356 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13357 | NL80211_FLAG_NEED_RTNL, | 
|  | 13358 | }, | 
|  | 13359 | { | 
|  | 13360 | .cmd = NL80211_CMD_DEL_MPATH, | 
|  | 13361 | .doit = nl80211_del_mpath, | 
|  | 13362 | .policy = nl80211_policy, | 
|  | 13363 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13364 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13365 | NL80211_FLAG_NEED_RTNL, | 
|  | 13366 | }, | 
|  | 13367 | { | 
|  | 13368 | .cmd = NL80211_CMD_SET_BSS, | 
|  | 13369 | .doit = nl80211_set_bss, | 
|  | 13370 | .policy = nl80211_policy, | 
|  | 13371 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13372 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13373 | NL80211_FLAG_NEED_RTNL, | 
|  | 13374 | }, | 
|  | 13375 | { | 
|  | 13376 | .cmd = NL80211_CMD_GET_REG, | 
|  | 13377 | .doit = nl80211_get_reg_do, | 
|  | 13378 | .dumpit = nl80211_get_reg_dump, | 
|  | 13379 | .policy = nl80211_policy, | 
|  | 13380 | .internal_flags = NL80211_FLAG_NEED_RTNL, | 
|  | 13381 | /* can be retrieved by unprivileged users */ | 
|  | 13382 | }, | 
|  | 13383 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT | 
|  | 13384 | { | 
|  | 13385 | .cmd = NL80211_CMD_SET_REG, | 
|  | 13386 | .doit = nl80211_set_reg, | 
|  | 13387 | .policy = nl80211_policy, | 
|  | 13388 | .flags = GENL_ADMIN_PERM, | 
|  | 13389 | .internal_flags = NL80211_FLAG_NEED_RTNL, | 
|  | 13390 | }, | 
|  | 13391 | #endif | 
|  | 13392 | { | 
|  | 13393 | .cmd = NL80211_CMD_REQ_SET_REG, | 
|  | 13394 | .doit = nl80211_req_set_reg, | 
|  | 13395 | .policy = nl80211_policy, | 
|  | 13396 | .flags = GENL_ADMIN_PERM, | 
|  | 13397 | }, | 
|  | 13398 | { | 
|  | 13399 | .cmd = NL80211_CMD_RELOAD_REGDB, | 
|  | 13400 | .doit = nl80211_reload_regdb, | 
|  | 13401 | .policy = nl80211_policy, | 
|  | 13402 | .flags = GENL_ADMIN_PERM, | 
|  | 13403 | }, | 
|  | 13404 | { | 
|  | 13405 | .cmd = NL80211_CMD_GET_MESH_CONFIG, | 
|  | 13406 | .doit = nl80211_get_mesh_config, | 
|  | 13407 | .policy = nl80211_policy, | 
|  | 13408 | /* can be retrieved by unprivileged users */ | 
|  | 13409 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13410 | NL80211_FLAG_NEED_RTNL, | 
|  | 13411 | }, | 
|  | 13412 | { | 
|  | 13413 | .cmd = NL80211_CMD_SET_MESH_CONFIG, | 
|  | 13414 | .doit = nl80211_update_mesh_config, | 
|  | 13415 | .policy = nl80211_policy, | 
|  | 13416 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13417 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13418 | NL80211_FLAG_NEED_RTNL, | 
|  | 13419 | }, | 
|  | 13420 | { | 
|  | 13421 | .cmd = NL80211_CMD_TRIGGER_SCAN, | 
|  | 13422 | .doit = nl80211_trigger_scan, | 
|  | 13423 | .policy = nl80211_policy, | 
|  | 13424 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13425 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13426 | NL80211_FLAG_NEED_RTNL, | 
|  | 13427 | }, | 
|  | 13428 | { | 
|  | 13429 | .cmd = NL80211_CMD_ABORT_SCAN, | 
|  | 13430 | .doit = nl80211_abort_scan, | 
|  | 13431 | .policy = nl80211_policy, | 
|  | 13432 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13433 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13434 | NL80211_FLAG_NEED_RTNL, | 
|  | 13435 | }, | 
|  | 13436 | { | 
|  | 13437 | .cmd = NL80211_CMD_GET_SCAN, | 
|  | 13438 | .policy = nl80211_policy, | 
|  | 13439 | .dumpit = nl80211_dump_scan, | 
|  | 13440 | }, | 
|  | 13441 | { | 
|  | 13442 | .cmd = NL80211_CMD_START_SCHED_SCAN, | 
|  | 13443 | .doit = nl80211_start_sched_scan, | 
|  | 13444 | .policy = nl80211_policy, | 
|  | 13445 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13446 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13447 | NL80211_FLAG_NEED_RTNL, | 
|  | 13448 | }, | 
|  | 13449 | { | 
|  | 13450 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | 
|  | 13451 | .doit = nl80211_stop_sched_scan, | 
|  | 13452 | .policy = nl80211_policy, | 
|  | 13453 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13454 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13455 | NL80211_FLAG_NEED_RTNL, | 
|  | 13456 | }, | 
|  | 13457 | { | 
|  | 13458 | .cmd = NL80211_CMD_AUTHENTICATE, | 
|  | 13459 | .doit = nl80211_authenticate, | 
|  | 13460 | .policy = nl80211_policy, | 
|  | 13461 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13462 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13463 | NL80211_FLAG_NEED_RTNL | | 
|  | 13464 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13465 | }, | 
|  | 13466 | { | 
|  | 13467 | .cmd = NL80211_CMD_ASSOCIATE, | 
|  | 13468 | .doit = nl80211_associate, | 
|  | 13469 | .policy = nl80211_policy, | 
|  | 13470 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13472 | NL80211_FLAG_NEED_RTNL | | 
|  | 13473 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13474 | }, | 
|  | 13475 | { | 
|  | 13476 | .cmd = NL80211_CMD_DEAUTHENTICATE, | 
|  | 13477 | .doit = nl80211_deauthenticate, | 
|  | 13478 | .policy = nl80211_policy, | 
|  | 13479 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13481 | NL80211_FLAG_NEED_RTNL, | 
|  | 13482 | }, | 
|  | 13483 | { | 
|  | 13484 | .cmd = NL80211_CMD_DISASSOCIATE, | 
|  | 13485 | .doit = nl80211_disassociate, | 
|  | 13486 | .policy = nl80211_policy, | 
|  | 13487 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13489 | NL80211_FLAG_NEED_RTNL, | 
|  | 13490 | }, | 
|  | 13491 | { | 
|  | 13492 | .cmd = NL80211_CMD_JOIN_IBSS, | 
|  | 13493 | .doit = nl80211_join_ibss, | 
|  | 13494 | .policy = nl80211_policy, | 
|  | 13495 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13496 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13497 | NL80211_FLAG_NEED_RTNL, | 
|  | 13498 | }, | 
|  | 13499 | { | 
|  | 13500 | .cmd = NL80211_CMD_LEAVE_IBSS, | 
|  | 13501 | .doit = nl80211_leave_ibss, | 
|  | 13502 | .policy = nl80211_policy, | 
|  | 13503 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13504 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13505 | NL80211_FLAG_NEED_RTNL, | 
|  | 13506 | }, | 
|  | 13507 | #ifdef CONFIG_NL80211_TESTMODE | 
|  | 13508 | { | 
|  | 13509 | .cmd = NL80211_CMD_TESTMODE, | 
|  | 13510 | .doit = nl80211_testmode_do, | 
|  | 13511 | .dumpit = nl80211_testmode_dump, | 
|  | 13512 | .policy = nl80211_policy, | 
|  | 13513 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13514 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13515 | NL80211_FLAG_NEED_RTNL, | 
|  | 13516 | }, | 
|  | 13517 | #endif | 
|  | 13518 | { | 
|  | 13519 | .cmd = NL80211_CMD_CONNECT, | 
|  | 13520 | .doit = nl80211_connect, | 
|  | 13521 | .policy = nl80211_policy, | 
|  | 13522 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13524 | NL80211_FLAG_NEED_RTNL | | 
|  | 13525 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13526 | }, | 
|  | 13527 | { | 
|  | 13528 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, | 
|  | 13529 | .doit = nl80211_update_connect_params, | 
|  | 13530 | .policy = nl80211_policy, | 
|  | 13531 | .flags = GENL_ADMIN_PERM, | 
|  | 13532 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13533 | NL80211_FLAG_NEED_RTNL | | 
|  | 13534 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13535 | }, | 
|  | 13536 | { | 
|  | 13537 | .cmd = NL80211_CMD_DISCONNECT, | 
|  | 13538 | .doit = nl80211_disconnect, | 
|  | 13539 | .policy = nl80211_policy, | 
|  | 13540 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13542 | NL80211_FLAG_NEED_RTNL, | 
|  | 13543 | }, | 
|  | 13544 | { | 
|  | 13545 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | 
|  | 13546 | .doit = nl80211_wiphy_netns, | 
|  | 13547 | .policy = nl80211_policy, | 
|  | 13548 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13549 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13550 | NL80211_FLAG_NEED_RTNL, | 
|  | 13551 | }, | 
|  | 13552 | { | 
|  | 13553 | .cmd = NL80211_CMD_GET_SURVEY, | 
|  | 13554 | .policy = nl80211_policy, | 
|  | 13555 | .dumpit = nl80211_dump_survey, | 
|  | 13556 | }, | 
|  | 13557 | { | 
|  | 13558 | .cmd = NL80211_CMD_SET_PMKSA, | 
|  | 13559 | .doit = nl80211_setdel_pmksa, | 
|  | 13560 | .policy = nl80211_policy, | 
|  | 13561 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13563 | NL80211_FLAG_NEED_RTNL | | 
|  | 13564 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13565 | }, | 
|  | 13566 | { | 
|  | 13567 | .cmd = NL80211_CMD_DEL_PMKSA, | 
|  | 13568 | .doit = nl80211_setdel_pmksa, | 
|  | 13569 | .policy = nl80211_policy, | 
|  | 13570 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13571 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13572 | NL80211_FLAG_NEED_RTNL, | 
|  | 13573 | }, | 
|  | 13574 | { | 
|  | 13575 | .cmd = NL80211_CMD_FLUSH_PMKSA, | 
|  | 13576 | .doit = nl80211_flush_pmksa, | 
|  | 13577 | .policy = nl80211_policy, | 
|  | 13578 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13580 | NL80211_FLAG_NEED_RTNL, | 
|  | 13581 | }, | 
|  | 13582 | { | 
|  | 13583 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | 
|  | 13584 | .doit = nl80211_remain_on_channel, | 
|  | 13585 | .policy = nl80211_policy, | 
|  | 13586 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13587 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13588 | NL80211_FLAG_NEED_RTNL, | 
|  | 13589 | }, | 
|  | 13590 | { | 
|  | 13591 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | 
|  | 13592 | .doit = nl80211_cancel_remain_on_channel, | 
|  | 13593 | .policy = nl80211_policy, | 
|  | 13594 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13595 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13596 | NL80211_FLAG_NEED_RTNL, | 
|  | 13597 | }, | 
|  | 13598 | { | 
|  | 13599 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | 
|  | 13600 | .doit = nl80211_set_tx_bitrate_mask, | 
|  | 13601 | .policy = nl80211_policy, | 
|  | 13602 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13603 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13604 | NL80211_FLAG_NEED_RTNL, | 
|  | 13605 | }, | 
|  | 13606 | { | 
|  | 13607 | .cmd = NL80211_CMD_REGISTER_FRAME, | 
|  | 13608 | .doit = nl80211_register_mgmt, | 
|  | 13609 | .policy = nl80211_policy, | 
|  | 13610 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13611 | .internal_flags = NL80211_FLAG_NEED_WDEV | | 
|  | 13612 | NL80211_FLAG_NEED_RTNL, | 
|  | 13613 | }, | 
|  | 13614 | { | 
|  | 13615 | .cmd = NL80211_CMD_FRAME, | 
|  | 13616 | .doit = nl80211_tx_mgmt, | 
|  | 13617 | .policy = nl80211_policy, | 
|  | 13618 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13619 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13620 | NL80211_FLAG_NEED_RTNL, | 
|  | 13621 | }, | 
|  | 13622 | { | 
|  | 13623 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | 
|  | 13624 | .doit = nl80211_tx_mgmt_cancel_wait, | 
|  | 13625 | .policy = nl80211_policy, | 
|  | 13626 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13627 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13628 | NL80211_FLAG_NEED_RTNL, | 
|  | 13629 | }, | 
|  | 13630 | { | 
|  | 13631 | .cmd = NL80211_CMD_SET_POWER_SAVE, | 
|  | 13632 | .doit = nl80211_set_power_save, | 
|  | 13633 | .policy = nl80211_policy, | 
|  | 13634 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13635 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13636 | NL80211_FLAG_NEED_RTNL, | 
|  | 13637 | }, | 
|  | 13638 | { | 
|  | 13639 | .cmd = NL80211_CMD_GET_POWER_SAVE, | 
|  | 13640 | .doit = nl80211_get_power_save, | 
|  | 13641 | .policy = nl80211_policy, | 
|  | 13642 | /* can be retrieved by unprivileged users */ | 
|  | 13643 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13644 | NL80211_FLAG_NEED_RTNL, | 
|  | 13645 | }, | 
|  | 13646 | { | 
|  | 13647 | .cmd = NL80211_CMD_SET_CQM, | 
|  | 13648 | .doit = nl80211_set_cqm, | 
|  | 13649 | .policy = nl80211_policy, | 
|  | 13650 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13651 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13652 | NL80211_FLAG_NEED_RTNL, | 
|  | 13653 | }, | 
|  | 13654 | { | 
|  | 13655 | .cmd = NL80211_CMD_SET_CHANNEL, | 
|  | 13656 | .doit = nl80211_set_channel, | 
|  | 13657 | .policy = nl80211_policy, | 
|  | 13658 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13659 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13660 | NL80211_FLAG_NEED_RTNL, | 
|  | 13661 | }, | 
|  | 13662 | { | 
|  | 13663 | .cmd = NL80211_CMD_SET_WDS_PEER, | 
|  | 13664 | .doit = nl80211_set_wds_peer, | 
|  | 13665 | .policy = nl80211_policy, | 
|  | 13666 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13667 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13668 | NL80211_FLAG_NEED_RTNL, | 
|  | 13669 | }, | 
|  | 13670 | { | 
|  | 13671 | .cmd = NL80211_CMD_JOIN_MESH, | 
|  | 13672 | .doit = nl80211_join_mesh, | 
|  | 13673 | .policy = nl80211_policy, | 
|  | 13674 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13675 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13676 | NL80211_FLAG_NEED_RTNL, | 
|  | 13677 | }, | 
|  | 13678 | { | 
|  | 13679 | .cmd = NL80211_CMD_LEAVE_MESH, | 
|  | 13680 | .doit = nl80211_leave_mesh, | 
|  | 13681 | .policy = nl80211_policy, | 
|  | 13682 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13683 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13684 | NL80211_FLAG_NEED_RTNL, | 
|  | 13685 | }, | 
|  | 13686 | { | 
|  | 13687 | .cmd = NL80211_CMD_JOIN_OCB, | 
|  | 13688 | .doit = nl80211_join_ocb, | 
|  | 13689 | .policy = nl80211_policy, | 
|  | 13690 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13692 | NL80211_FLAG_NEED_RTNL, | 
|  | 13693 | }, | 
|  | 13694 | { | 
|  | 13695 | .cmd = NL80211_CMD_LEAVE_OCB, | 
|  | 13696 | .doit = nl80211_leave_ocb, | 
|  | 13697 | .policy = nl80211_policy, | 
|  | 13698 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13699 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13700 | NL80211_FLAG_NEED_RTNL, | 
|  | 13701 | }, | 
|  | 13702 | #ifdef CONFIG_PM | 
|  | 13703 | { | 
|  | 13704 | .cmd = NL80211_CMD_GET_WOWLAN, | 
|  | 13705 | .doit = nl80211_get_wowlan, | 
|  | 13706 | .policy = nl80211_policy, | 
|  | 13707 | /* can be retrieved by unprivileged users */ | 
|  | 13708 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13709 | NL80211_FLAG_NEED_RTNL, | 
|  | 13710 | }, | 
|  | 13711 | { | 
|  | 13712 | .cmd = NL80211_CMD_SET_WOWLAN, | 
|  | 13713 | .doit = nl80211_set_wowlan, | 
|  | 13714 | .policy = nl80211_policy, | 
|  | 13715 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13716 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13717 | NL80211_FLAG_NEED_RTNL, | 
|  | 13718 | }, | 
|  | 13719 | #endif | 
|  | 13720 | { | 
|  | 13721 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | 
|  | 13722 | .doit = nl80211_set_rekey_data, | 
|  | 13723 | .policy = nl80211_policy, | 
|  | 13724 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13725 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13726 | NL80211_FLAG_NEED_RTNL | | 
|  | 13727 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13728 | }, | 
|  | 13729 | { | 
|  | 13730 | .cmd = NL80211_CMD_TDLS_MGMT, | 
|  | 13731 | .doit = nl80211_tdls_mgmt, | 
|  | 13732 | .policy = nl80211_policy, | 
|  | 13733 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13734 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13735 | NL80211_FLAG_NEED_RTNL, | 
|  | 13736 | }, | 
|  | 13737 | { | 
|  | 13738 | .cmd = NL80211_CMD_TDLS_OPER, | 
|  | 13739 | .doit = nl80211_tdls_oper, | 
|  | 13740 | .policy = nl80211_policy, | 
|  | 13741 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13742 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13743 | NL80211_FLAG_NEED_RTNL, | 
|  | 13744 | }, | 
|  | 13745 | { | 
|  | 13746 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | 
|  | 13747 | .doit = nl80211_register_unexpected_frame, | 
|  | 13748 | .policy = nl80211_policy, | 
|  | 13749 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13751 | NL80211_FLAG_NEED_RTNL, | 
|  | 13752 | }, | 
|  | 13753 | { | 
|  | 13754 | .cmd = NL80211_CMD_PROBE_CLIENT, | 
|  | 13755 | .doit = nl80211_probe_client, | 
|  | 13756 | .policy = nl80211_policy, | 
|  | 13757 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13759 | NL80211_FLAG_NEED_RTNL, | 
|  | 13760 | }, | 
|  | 13761 | { | 
|  | 13762 | .cmd = NL80211_CMD_REGISTER_BEACONS, | 
|  | 13763 | .doit = nl80211_register_beacons, | 
|  | 13764 | .policy = nl80211_policy, | 
|  | 13765 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13766 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13767 | NL80211_FLAG_NEED_RTNL, | 
|  | 13768 | }, | 
|  | 13769 | { | 
|  | 13770 | .cmd = NL80211_CMD_SET_NOACK_MAP, | 
|  | 13771 | .doit = nl80211_set_noack_map, | 
|  | 13772 | .policy = nl80211_policy, | 
|  | 13773 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13774 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13775 | NL80211_FLAG_NEED_RTNL, | 
|  | 13776 | }, | 
|  | 13777 | { | 
|  | 13778 | .cmd = NL80211_CMD_START_P2P_DEVICE, | 
|  | 13779 | .doit = nl80211_start_p2p_device, | 
|  | 13780 | .policy = nl80211_policy, | 
|  | 13781 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13782 | .internal_flags = NL80211_FLAG_NEED_WDEV | | 
|  | 13783 | NL80211_FLAG_NEED_RTNL, | 
|  | 13784 | }, | 
|  | 13785 | { | 
|  | 13786 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | 
|  | 13787 | .doit = nl80211_stop_p2p_device, | 
|  | 13788 | .policy = nl80211_policy, | 
|  | 13789 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13790 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13791 | NL80211_FLAG_NEED_RTNL, | 
|  | 13792 | }, | 
|  | 13793 | { | 
|  | 13794 | .cmd = NL80211_CMD_START_NAN, | 
|  | 13795 | .doit = nl80211_start_nan, | 
|  | 13796 | .policy = nl80211_policy, | 
|  | 13797 | .flags = GENL_ADMIN_PERM, | 
|  | 13798 | .internal_flags = NL80211_FLAG_NEED_WDEV | | 
|  | 13799 | NL80211_FLAG_NEED_RTNL, | 
|  | 13800 | }, | 
|  | 13801 | { | 
|  | 13802 | .cmd = NL80211_CMD_STOP_NAN, | 
|  | 13803 | .doit = nl80211_stop_nan, | 
|  | 13804 | .policy = nl80211_policy, | 
|  | 13805 | .flags = GENL_ADMIN_PERM, | 
|  | 13806 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13807 | NL80211_FLAG_NEED_RTNL, | 
|  | 13808 | }, | 
|  | 13809 | { | 
|  | 13810 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, | 
|  | 13811 | .doit = nl80211_nan_add_func, | 
|  | 13812 | .policy = nl80211_policy, | 
|  | 13813 | .flags = GENL_ADMIN_PERM, | 
|  | 13814 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13815 | NL80211_FLAG_NEED_RTNL, | 
|  | 13816 | }, | 
|  | 13817 | { | 
|  | 13818 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, | 
|  | 13819 | .doit = nl80211_nan_del_func, | 
|  | 13820 | .policy = nl80211_policy, | 
|  | 13821 | .flags = GENL_ADMIN_PERM, | 
|  | 13822 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13823 | NL80211_FLAG_NEED_RTNL, | 
|  | 13824 | }, | 
|  | 13825 | { | 
|  | 13826 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, | 
|  | 13827 | .doit = nl80211_nan_change_config, | 
|  | 13828 | .policy = nl80211_policy, | 
|  | 13829 | .flags = GENL_ADMIN_PERM, | 
|  | 13830 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13831 | NL80211_FLAG_NEED_RTNL, | 
|  | 13832 | }, | 
|  | 13833 | { | 
|  | 13834 | .cmd = NL80211_CMD_SET_MCAST_RATE, | 
|  | 13835 | .doit = nl80211_set_mcast_rate, | 
|  | 13836 | .policy = nl80211_policy, | 
|  | 13837 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13838 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13839 | NL80211_FLAG_NEED_RTNL, | 
|  | 13840 | }, | 
|  | 13841 | { | 
|  | 13842 | .cmd = NL80211_CMD_SET_MAC_ACL, | 
|  | 13843 | .doit = nl80211_set_mac_acl, | 
|  | 13844 | .policy = nl80211_policy, | 
|  | 13845 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13846 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13847 | NL80211_FLAG_NEED_RTNL, | 
|  | 13848 | }, | 
|  | 13849 | { | 
|  | 13850 | .cmd = NL80211_CMD_RADAR_DETECT, | 
|  | 13851 | .doit = nl80211_start_radar_detection, | 
|  | 13852 | .policy = nl80211_policy, | 
|  | 13853 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13854 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13855 | NL80211_FLAG_NEED_RTNL, | 
|  | 13856 | }, | 
|  | 13857 | { | 
|  | 13858 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | 
|  | 13859 | .doit = nl80211_get_protocol_features, | 
|  | 13860 | .policy = nl80211_policy, | 
|  | 13861 | }, | 
|  | 13862 | { | 
|  | 13863 | .cmd = NL80211_CMD_UPDATE_FT_IES, | 
|  | 13864 | .doit = nl80211_update_ft_ies, | 
|  | 13865 | .policy = nl80211_policy, | 
|  | 13866 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13867 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13868 | NL80211_FLAG_NEED_RTNL, | 
|  | 13869 | }, | 
|  | 13870 | { | 
|  | 13871 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | 
|  | 13872 | .doit = nl80211_crit_protocol_start, | 
|  | 13873 | .policy = nl80211_policy, | 
|  | 13874 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13875 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13876 | NL80211_FLAG_NEED_RTNL, | 
|  | 13877 | }, | 
|  | 13878 | { | 
|  | 13879 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | 
|  | 13880 | .doit = nl80211_crit_protocol_stop, | 
|  | 13881 | .policy = nl80211_policy, | 
|  | 13882 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13883 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
|  | 13884 | NL80211_FLAG_NEED_RTNL, | 
|  | 13885 | }, | 
|  | 13886 | { | 
|  | 13887 | .cmd = NL80211_CMD_GET_COALESCE, | 
|  | 13888 | .doit = nl80211_get_coalesce, | 
|  | 13889 | .policy = nl80211_policy, | 
|  | 13890 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13891 | NL80211_FLAG_NEED_RTNL, | 
|  | 13892 | }, | 
|  | 13893 | { | 
|  | 13894 | .cmd = NL80211_CMD_SET_COALESCE, | 
|  | 13895 | .doit = nl80211_set_coalesce, | 
|  | 13896 | .policy = nl80211_policy, | 
|  | 13897 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13898 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13899 | NL80211_FLAG_NEED_RTNL, | 
|  | 13900 | }, | 
|  | 13901 | { | 
|  | 13902 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | 
|  | 13903 | .doit = nl80211_channel_switch, | 
|  | 13904 | .policy = nl80211_policy, | 
|  | 13905 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13906 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13907 | NL80211_FLAG_NEED_RTNL, | 
|  | 13908 | }, | 
|  | 13909 | { | 
|  | 13910 | .cmd = NL80211_CMD_VENDOR, | 
|  | 13911 | .doit = nl80211_vendor_cmd, | 
|  | 13912 | .dumpit = nl80211_vendor_cmd_dump, | 
|  | 13913 | .policy = nl80211_policy, | 
|  | 13914 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13915 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | 
|  | 13916 | NL80211_FLAG_NEED_RTNL | | 
|  | 13917 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13918 | }, | 
|  | 13919 | { | 
|  | 13920 | .cmd = NL80211_CMD_SET_QOS_MAP, | 
|  | 13921 | .doit = nl80211_set_qos_map, | 
|  | 13922 | .policy = nl80211_policy, | 
|  | 13923 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13925 | NL80211_FLAG_NEED_RTNL, | 
|  | 13926 | }, | 
|  | 13927 | { | 
|  | 13928 | .cmd = NL80211_CMD_ADD_TX_TS, | 
|  | 13929 | .doit = nl80211_add_tx_ts, | 
|  | 13930 | .policy = nl80211_policy, | 
|  | 13931 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13932 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13933 | NL80211_FLAG_NEED_RTNL, | 
|  | 13934 | }, | 
|  | 13935 | { | 
|  | 13936 | .cmd = NL80211_CMD_DEL_TX_TS, | 
|  | 13937 | .doit = nl80211_del_tx_ts, | 
|  | 13938 | .policy = nl80211_policy, | 
|  | 13939 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13940 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13941 | NL80211_FLAG_NEED_RTNL, | 
|  | 13942 | }, | 
|  | 13943 | { | 
|  | 13944 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | 
|  | 13945 | .doit = nl80211_tdls_channel_switch, | 
|  | 13946 | .policy = nl80211_policy, | 
|  | 13947 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13949 | NL80211_FLAG_NEED_RTNL, | 
|  | 13950 | }, | 
|  | 13951 | { | 
|  | 13952 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | 
|  | 13953 | .doit = nl80211_tdls_cancel_channel_switch, | 
|  | 13954 | .policy = nl80211_policy, | 
|  | 13955 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13956 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13957 | NL80211_FLAG_NEED_RTNL, | 
|  | 13958 | }, | 
|  | 13959 | { | 
|  | 13960 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, | 
|  | 13961 | .doit = nl80211_set_multicast_to_unicast, | 
|  | 13962 | .policy = nl80211_policy, | 
|  | 13963 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13964 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | 
|  | 13965 | NL80211_FLAG_NEED_RTNL, | 
|  | 13966 | }, | 
|  | 13967 | { | 
|  | 13968 | .cmd = NL80211_CMD_SET_PMK, | 
|  | 13969 | .doit = nl80211_set_pmk, | 
|  | 13970 | .policy = nl80211_policy, | 
|  | 13971 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13972 | NL80211_FLAG_NEED_RTNL | | 
|  | 13973 | NL80211_FLAG_CLEAR_SKB, | 
|  | 13974 | }, | 
|  | 13975 | { | 
|  | 13976 | .cmd = NL80211_CMD_DEL_PMK, | 
|  | 13977 | .doit = nl80211_del_pmk, | 
|  | 13978 | .policy = nl80211_policy, | 
|  | 13979 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13980 | NL80211_FLAG_NEED_RTNL, | 
|  | 13981 | }, | 
|  | 13982 | { | 
|  | 13983 | .cmd = NL80211_CMD_EXTERNAL_AUTH, | 
|  | 13984 | .doit = nl80211_external_auth, | 
|  | 13985 | .policy = nl80211_policy, | 
|  | 13986 | .flags = GENL_ADMIN_PERM, | 
|  | 13987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13988 | NL80211_FLAG_NEED_RTNL, | 
|  | 13989 | }, | 
|  | 13990 | { | 
|  | 13991 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, | 
|  | 13992 | .doit = nl80211_tx_control_port, | 
|  | 13993 | .policy = nl80211_policy, | 
|  | 13994 | .flags = GENL_UNS_ADMIN_PERM, | 
|  | 13995 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
|  | 13996 | NL80211_FLAG_NEED_RTNL, | 
|  | 13997 | }, | 
|  | 13998 | }; | 
|  | 13999 |  | 
|  | 14000 | static struct genl_family nl80211_fam __ro_after_init = { | 
|  | 14001 | .name = NL80211_GENL_NAME,	/* have users key off the name instead */ | 
|  | 14002 | .hdrsize = 0,			/* no private header */ | 
|  | 14003 | .version = 1,			/* no particular meaning now */ | 
|  | 14004 | .maxattr = NL80211_ATTR_MAX, | 
|  | 14005 | .netnsok = true, | 
|  | 14006 | .pre_doit = nl80211_pre_doit, | 
|  | 14007 | .post_doit = nl80211_post_doit, | 
|  | 14008 | .module = THIS_MODULE, | 
|  | 14009 | .ops = nl80211_ops, | 
|  | 14010 | .n_ops = ARRAY_SIZE(nl80211_ops), | 
|  | 14011 | .mcgrps = nl80211_mcgrps, | 
|  | 14012 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), | 
|  | 14013 | }; | 
|  | 14014 |  | 
|  | 14015 | /* notification functions */ | 
|  | 14016 |  | 
|  | 14017 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, | 
|  | 14018 | enum nl80211_commands cmd) | 
|  | 14019 | { | 
|  | 14020 | struct sk_buff *msg; | 
|  | 14021 | struct nl80211_dump_wiphy_state state = {}; | 
|  | 14022 |  | 
|  | 14023 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && | 
|  | 14024 | cmd != NL80211_CMD_DEL_WIPHY); | 
|  | 14025 |  | 
|  | 14026 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14027 | if (!msg) | 
|  | 14028 | return; | 
|  | 14029 |  | 
|  | 14030 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { | 
|  | 14031 | nlmsg_free(msg); | 
|  | 14032 | return; | 
|  | 14033 | } | 
|  | 14034 |  | 
|  | 14035 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14036 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | 
|  | 14037 | } | 
|  | 14038 |  | 
|  | 14039 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, | 
|  | 14040 | struct wireless_dev *wdev, | 
|  | 14041 | enum nl80211_commands cmd) | 
|  | 14042 | { | 
|  | 14043 | struct sk_buff *msg; | 
|  | 14044 |  | 
|  | 14045 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && | 
|  | 14046 | cmd != NL80211_CMD_DEL_INTERFACE); | 
|  | 14047 |  | 
|  | 14048 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14049 | if (!msg) | 
|  | 14050 | return; | 
|  | 14051 |  | 
|  | 14052 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, | 
|  | 14053 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { | 
|  | 14054 | nlmsg_free(msg); | 
|  | 14055 | return; | 
|  | 14056 | } | 
|  | 14057 |  | 
|  | 14058 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14059 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | 
|  | 14060 | } | 
|  | 14061 |  | 
|  | 14062 | static int nl80211_add_scan_req(struct sk_buff *msg, | 
|  | 14063 | struct cfg80211_registered_device *rdev) | 
|  | 14064 | { | 
|  | 14065 | struct cfg80211_scan_request *req = rdev->scan_req; | 
|  | 14066 | struct nlattr *nest; | 
|  | 14067 | int i; | 
|  | 14068 |  | 
|  | 14069 | if (WARN_ON(!req)) | 
|  | 14070 | return 0; | 
|  | 14071 |  | 
|  | 14072 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | 
|  | 14073 | if (!nest) | 
|  | 14074 | goto nla_put_failure; | 
|  | 14075 | for (i = 0; i < req->n_ssids; i++) { | 
|  | 14076 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | 
|  | 14077 | goto nla_put_failure; | 
|  | 14078 | } | 
|  | 14079 | nla_nest_end(msg, nest); | 
|  | 14080 |  | 
|  | 14081 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | 
|  | 14082 | if (!nest) | 
|  | 14083 | goto nla_put_failure; | 
|  | 14084 | for (i = 0; i < req->n_channels; i++) { | 
|  | 14085 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | 
|  | 14086 | goto nla_put_failure; | 
|  | 14087 | } | 
|  | 14088 | nla_nest_end(msg, nest); | 
|  | 14089 |  | 
|  | 14090 | if (req->ie && | 
|  | 14091 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | 
|  | 14092 | goto nla_put_failure; | 
|  | 14093 |  | 
|  | 14094 | if (req->flags && | 
|  | 14095 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | 
|  | 14096 | goto nla_put_failure; | 
|  | 14097 |  | 
|  | 14098 | if (req->info.scan_start_tsf && | 
|  | 14099 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, | 
|  | 14100 | req->info.scan_start_tsf, NL80211_BSS_PAD) || | 
|  | 14101 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, | 
|  | 14102 | req->info.tsf_bssid))) | 
|  | 14103 | goto nla_put_failure; | 
|  | 14104 |  | 
|  | 14105 | return 0; | 
|  | 14106 | nla_put_failure: | 
|  | 14107 | return -ENOBUFS; | 
|  | 14108 | } | 
|  | 14109 |  | 
|  | 14110 | static int nl80211_prep_scan_msg(struct sk_buff *msg, | 
|  | 14111 | struct cfg80211_registered_device *rdev, | 
|  | 14112 | struct wireless_dev *wdev, | 
|  | 14113 | u32 portid, u32 seq, int flags, | 
|  | 14114 | u32 cmd) | 
|  | 14115 | { | 
|  | 14116 | void *hdr; | 
|  | 14117 |  | 
|  | 14118 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
|  | 14119 | if (!hdr) | 
|  | 14120 | return -1; | 
|  | 14121 |  | 
|  | 14122 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14123 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 14124 | wdev->netdev->ifindex)) || | 
|  | 14125 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 14126 | NL80211_ATTR_PAD)) | 
|  | 14127 | goto nla_put_failure; | 
|  | 14128 |  | 
|  | 14129 | /* ignore errors and send incomplete event anyway */ | 
|  | 14130 | nl80211_add_scan_req(msg, rdev); | 
|  | 14131 |  | 
|  | 14132 | genlmsg_end(msg, hdr); | 
|  | 14133 | return 0; | 
|  | 14134 |  | 
|  | 14135 | nla_put_failure: | 
|  | 14136 | genlmsg_cancel(msg, hdr); | 
|  | 14137 | return -EMSGSIZE; | 
|  | 14138 | } | 
|  | 14139 |  | 
|  | 14140 | static int | 
|  | 14141 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, | 
|  | 14142 | struct cfg80211_sched_scan_request *req, u32 cmd) | 
|  | 14143 | { | 
|  | 14144 | void *hdr; | 
|  | 14145 |  | 
|  | 14146 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
|  | 14147 | if (!hdr) | 
|  | 14148 | return -1; | 
|  | 14149 |  | 
|  | 14150 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, | 
|  | 14151 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || | 
|  | 14152 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || | 
|  | 14153 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, | 
|  | 14154 | NL80211_ATTR_PAD)) | 
|  | 14155 | goto nla_put_failure; | 
|  | 14156 |  | 
|  | 14157 | genlmsg_end(msg, hdr); | 
|  | 14158 | return 0; | 
|  | 14159 |  | 
|  | 14160 | nla_put_failure: | 
|  | 14161 | genlmsg_cancel(msg, hdr); | 
|  | 14162 | return -EMSGSIZE; | 
|  | 14163 | } | 
|  | 14164 |  | 
|  | 14165 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, | 
|  | 14166 | struct wireless_dev *wdev) | 
|  | 14167 | { | 
|  | 14168 | struct sk_buff *msg; | 
|  | 14169 |  | 
|  | 14170 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14171 | if (!msg) | 
|  | 14172 | return; | 
|  | 14173 |  | 
|  | 14174 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, | 
|  | 14175 | NL80211_CMD_TRIGGER_SCAN) < 0) { | 
|  | 14176 | nlmsg_free(msg); | 
|  | 14177 | return; | 
|  | 14178 | } | 
|  | 14179 |  | 
|  | 14180 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14181 | NL80211_MCGRP_SCAN, GFP_KERNEL); | 
|  | 14182 | } | 
|  | 14183 |  | 
|  | 14184 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, | 
|  | 14185 | struct wireless_dev *wdev, bool aborted) | 
|  | 14186 | { | 
|  | 14187 | struct sk_buff *msg; | 
|  | 14188 |  | 
|  | 14189 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14190 | if (!msg) | 
|  | 14191 | return NULL; | 
|  | 14192 |  | 
|  | 14193 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, | 
|  | 14194 | aborted ? NL80211_CMD_SCAN_ABORTED : | 
|  | 14195 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | 
|  | 14196 | nlmsg_free(msg); | 
|  | 14197 | return NULL; | 
|  | 14198 | } | 
|  | 14199 |  | 
|  | 14200 | return msg; | 
|  | 14201 | } | 
|  | 14202 |  | 
|  | 14203 | /* send message created by nl80211_build_scan_msg() */ | 
|  | 14204 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, | 
|  | 14205 | struct sk_buff *msg) | 
|  | 14206 | { | 
|  | 14207 | if (!msg) | 
|  | 14208 | return; | 
|  | 14209 |  | 
|  | 14210 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14211 | NL80211_MCGRP_SCAN, GFP_KERNEL); | 
|  | 14212 | } | 
|  | 14213 |  | 
|  | 14214 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) | 
|  | 14215 | { | 
|  | 14216 | struct sk_buff *msg; | 
|  | 14217 |  | 
|  | 14218 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14219 | if (!msg) | 
|  | 14220 | return; | 
|  | 14221 |  | 
|  | 14222 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { | 
|  | 14223 | nlmsg_free(msg); | 
|  | 14224 | return; | 
|  | 14225 | } | 
|  | 14226 |  | 
|  | 14227 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, | 
|  | 14228 | NL80211_MCGRP_SCAN, GFP_KERNEL); | 
|  | 14229 | } | 
|  | 14230 |  | 
|  | 14231 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, | 
|  | 14232 | struct regulatory_request *request) | 
|  | 14233 | { | 
|  | 14234 | /* Userspace can always count this one always being set */ | 
|  | 14235 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) | 
|  | 14236 | goto nla_put_failure; | 
|  | 14237 |  | 
|  | 14238 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | 
|  | 14239 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
|  | 14240 | NL80211_REGDOM_TYPE_WORLD)) | 
|  | 14241 | goto nla_put_failure; | 
|  | 14242 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | 
|  | 14243 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
|  | 14244 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | 
|  | 14245 | goto nla_put_failure; | 
|  | 14246 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | 
|  | 14247 | request->intersect) { | 
|  | 14248 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
|  | 14249 | NL80211_REGDOM_TYPE_INTERSECTION)) | 
|  | 14250 | goto nla_put_failure; | 
|  | 14251 | } else { | 
|  | 14252 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
|  | 14253 | NL80211_REGDOM_TYPE_COUNTRY) || | 
|  | 14254 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | 
|  | 14255 | request->alpha2)) | 
|  | 14256 | goto nla_put_failure; | 
|  | 14257 | } | 
|  | 14258 |  | 
|  | 14259 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { | 
|  | 14260 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | 
|  | 14261 |  | 
|  | 14262 | if (wiphy && | 
|  | 14263 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | 
|  | 14264 | goto nla_put_failure; | 
|  | 14265 |  | 
|  | 14266 | if (wiphy && | 
|  | 14267 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | 
|  | 14268 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | 
|  | 14269 | goto nla_put_failure; | 
|  | 14270 | } | 
|  | 14271 |  | 
|  | 14272 | return true; | 
|  | 14273 |  | 
|  | 14274 | nla_put_failure: | 
|  | 14275 | return false; | 
|  | 14276 | } | 
|  | 14277 |  | 
|  | 14278 | /* | 
|  | 14279 | * This can happen on global regulatory changes or device specific settings | 
|  | 14280 | * based on custom regulatory domains. | 
|  | 14281 | */ | 
|  | 14282 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | 
|  | 14283 | struct regulatory_request *request) | 
|  | 14284 | { | 
|  | 14285 | struct sk_buff *msg; | 
|  | 14286 | void *hdr; | 
|  | 14287 |  | 
|  | 14288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14289 | if (!msg) | 
|  | 14290 | return; | 
|  | 14291 |  | 
|  | 14292 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | 
|  | 14293 | if (!hdr) { | 
|  | 14294 | nlmsg_free(msg); | 
|  | 14295 | return; | 
|  | 14296 | } | 
|  | 14297 |  | 
|  | 14298 | if (nl80211_reg_change_event_fill(msg, request) == false) | 
|  | 14299 | goto nla_put_failure; | 
|  | 14300 |  | 
|  | 14301 | genlmsg_end(msg, hdr); | 
|  | 14302 |  | 
|  | 14303 | rcu_read_lock(); | 
|  | 14304 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, | 
|  | 14305 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); | 
|  | 14306 | rcu_read_unlock(); | 
|  | 14307 |  | 
|  | 14308 | return; | 
|  | 14309 |  | 
|  | 14310 | nla_put_failure: | 
|  | 14311 | nlmsg_free(msg); | 
|  | 14312 | } | 
|  | 14313 |  | 
|  | 14314 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, | 
|  | 14315 | struct net_device *netdev, | 
|  | 14316 | const u8 *buf, size_t len, | 
|  | 14317 | enum nl80211_commands cmd, gfp_t gfp, | 
|  | 14318 | int uapsd_queues) | 
|  | 14319 | { | 
|  | 14320 | struct sk_buff *msg; | 
|  | 14321 | void *hdr; | 
|  | 14322 |  | 
|  | 14323 | msg = nlmsg_new(100 + len, gfp); | 
|  | 14324 | if (!msg) | 
|  | 14325 | return; | 
|  | 14326 |  | 
|  | 14327 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
|  | 14328 | if (!hdr) { | 
|  | 14329 | nlmsg_free(msg); | 
|  | 14330 | return; | 
|  | 14331 | } | 
|  | 14332 |  | 
|  | 14333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14334 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14335 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | 
|  | 14336 | goto nla_put_failure; | 
|  | 14337 |  | 
|  | 14338 | if (uapsd_queues >= 0) { | 
|  | 14339 | struct nlattr *nla_wmm = | 
|  | 14340 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | 
|  | 14341 | if (!nla_wmm) | 
|  | 14342 | goto nla_put_failure; | 
|  | 14343 |  | 
|  | 14344 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | 
|  | 14345 | uapsd_queues)) | 
|  | 14346 | goto nla_put_failure; | 
|  | 14347 |  | 
|  | 14348 | nla_nest_end(msg, nla_wmm); | 
|  | 14349 | } | 
|  | 14350 |  | 
|  | 14351 | genlmsg_end(msg, hdr); | 
|  | 14352 |  | 
|  | 14353 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14354 | NL80211_MCGRP_MLME, gfp); | 
|  | 14355 | return; | 
|  | 14356 |  | 
|  | 14357 | nla_put_failure: | 
|  | 14358 | nlmsg_free(msg); | 
|  | 14359 | } | 
|  | 14360 |  | 
|  | 14361 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | 
|  | 14362 | struct net_device *netdev, const u8 *buf, | 
|  | 14363 | size_t len, gfp_t gfp) | 
|  | 14364 | { | 
|  | 14365 | nl80211_send_mlme_event(rdev, netdev, buf, len, | 
|  | 14366 | NL80211_CMD_AUTHENTICATE, gfp, -1); | 
|  | 14367 | } | 
|  | 14368 |  | 
|  | 14369 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | 
|  | 14370 | struct net_device *netdev, const u8 *buf, | 
|  | 14371 | size_t len, gfp_t gfp, int uapsd_queues) | 
|  | 14372 | { | 
|  | 14373 | nl80211_send_mlme_event(rdev, netdev, buf, len, | 
|  | 14374 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); | 
|  | 14375 | } | 
|  | 14376 |  | 
|  | 14377 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, | 
|  | 14378 | struct net_device *netdev, const u8 *buf, | 
|  | 14379 | size_t len, gfp_t gfp) | 
|  | 14380 | { | 
|  | 14381 | nl80211_send_mlme_event(rdev, netdev, buf, len, | 
|  | 14382 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); | 
|  | 14383 | } | 
|  | 14384 |  | 
|  | 14385 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, | 
|  | 14386 | struct net_device *netdev, const u8 *buf, | 
|  | 14387 | size_t len, gfp_t gfp) | 
|  | 14388 | { | 
|  | 14389 | nl80211_send_mlme_event(rdev, netdev, buf, len, | 
|  | 14390 | NL80211_CMD_DISASSOCIATE, gfp, -1); | 
|  | 14391 | } | 
|  | 14392 |  | 
|  | 14393 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, | 
|  | 14394 | size_t len) | 
|  | 14395 | { | 
|  | 14396 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 14397 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 14398 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 14399 | const struct ieee80211_mgmt *mgmt = (void *)buf; | 
|  | 14400 | u32 cmd; | 
|  | 14401 |  | 
|  | 14402 | if (WARN_ON(len < 2)) | 
|  | 14403 | return; | 
|  | 14404 |  | 
|  | 14405 | if (ieee80211_is_deauth(mgmt->frame_control)) | 
|  | 14406 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | 
|  | 14407 | else | 
|  | 14408 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | 
|  | 14409 |  | 
|  | 14410 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); | 
|  | 14411 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); | 
|  | 14412 | } | 
|  | 14413 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); | 
|  | 14414 |  | 
|  | 14415 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, | 
|  | 14416 | struct net_device *netdev, int cmd, | 
|  | 14417 | const u8 *addr, gfp_t gfp) | 
|  | 14418 | { | 
|  | 14419 | struct sk_buff *msg; | 
|  | 14420 | void *hdr; | 
|  | 14421 |  | 
|  | 14422 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 14423 | if (!msg) | 
|  | 14424 | return; | 
|  | 14425 |  | 
|  | 14426 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
|  | 14427 | if (!hdr) { | 
|  | 14428 | nlmsg_free(msg); | 
|  | 14429 | return; | 
|  | 14430 | } | 
|  | 14431 |  | 
|  | 14432 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14433 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14434 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | 
|  | 14435 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | 
|  | 14436 | goto nla_put_failure; | 
|  | 14437 |  | 
|  | 14438 | genlmsg_end(msg, hdr); | 
|  | 14439 |  | 
|  | 14440 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14441 | NL80211_MCGRP_MLME, gfp); | 
|  | 14442 | return; | 
|  | 14443 |  | 
|  | 14444 | nla_put_failure: | 
|  | 14445 | nlmsg_free(msg); | 
|  | 14446 | } | 
|  | 14447 |  | 
|  | 14448 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | 
|  | 14449 | struct net_device *netdev, const u8 *addr, | 
|  | 14450 | gfp_t gfp) | 
|  | 14451 | { | 
|  | 14452 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | 
|  | 14453 | addr, gfp); | 
|  | 14454 | } | 
|  | 14455 |  | 
|  | 14456 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | 
|  | 14457 | struct net_device *netdev, const u8 *addr, | 
|  | 14458 | gfp_t gfp) | 
|  | 14459 | { | 
|  | 14460 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, | 
|  | 14461 | addr, gfp); | 
|  | 14462 | } | 
|  | 14463 |  | 
|  | 14464 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, | 
|  | 14465 | struct net_device *netdev, | 
|  | 14466 | struct cfg80211_connect_resp_params *cr, | 
|  | 14467 | gfp_t gfp) | 
|  | 14468 | { | 
|  | 14469 | struct sk_buff *msg; | 
|  | 14470 | void *hdr; | 
|  | 14471 |  | 
|  | 14472 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + | 
|  | 14473 | cr->fils.kek_len + cr->fils.pmk_len + | 
|  | 14474 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); | 
|  | 14475 | if (!msg) | 
|  | 14476 | return; | 
|  | 14477 |  | 
|  | 14478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | 
|  | 14479 | if (!hdr) { | 
|  | 14480 | nlmsg_free(msg); | 
|  | 14481 | return; | 
|  | 14482 | } | 
|  | 14483 |  | 
|  | 14484 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14485 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14486 | (cr->bssid && | 
|  | 14487 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || | 
|  | 14488 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, | 
|  | 14489 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : | 
|  | 14490 | cr->status) || | 
|  | 14491 | (cr->status < 0 && | 
|  | 14492 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | 
|  | 14493 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, | 
|  | 14494 | cr->timeout_reason))) || | 
|  | 14495 | (cr->req_ie && | 
|  | 14496 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || | 
|  | 14497 | (cr->resp_ie && | 
|  | 14498 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, | 
|  | 14499 | cr->resp_ie)) || | 
|  | 14500 | (cr->fils.update_erp_next_seq_num && | 
|  | 14501 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | 
|  | 14502 | cr->fils.erp_next_seq_num)) || | 
|  | 14503 | (cr->status == WLAN_STATUS_SUCCESS && | 
|  | 14504 | ((cr->fils.kek && | 
|  | 14505 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, | 
|  | 14506 | cr->fils.kek)) || | 
|  | 14507 | (cr->fils.pmk && | 
|  | 14508 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || | 
|  | 14509 | (cr->fils.pmkid && | 
|  | 14510 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) | 
|  | 14511 | goto nla_put_failure; | 
|  | 14512 |  | 
|  | 14513 | genlmsg_end(msg, hdr); | 
|  | 14514 |  | 
|  | 14515 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14516 | NL80211_MCGRP_MLME, gfp); | 
|  | 14517 | return; | 
|  | 14518 |  | 
|  | 14519 | nla_put_failure: | 
|  | 14520 | nlmsg_free(msg); | 
|  | 14521 | } | 
|  | 14522 |  | 
|  | 14523 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | 
|  | 14524 | struct net_device *netdev, | 
|  | 14525 | struct cfg80211_roam_info *info, gfp_t gfp) | 
|  | 14526 | { | 
|  | 14527 | struct sk_buff *msg; | 
|  | 14528 | void *hdr; | 
|  | 14529 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; | 
|  | 14530 |  | 
|  | 14531 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + | 
|  | 14532 | info->fils.kek_len + info->fils.pmk_len + | 
|  | 14533 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); | 
|  | 14534 | if (!msg) | 
|  | 14535 | return; | 
|  | 14536 |  | 
|  | 14537 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | 
|  | 14538 | if (!hdr) { | 
|  | 14539 | nlmsg_free(msg); | 
|  | 14540 | return; | 
|  | 14541 | } | 
|  | 14542 |  | 
|  | 14543 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14544 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14545 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | 
|  | 14546 | (info->req_ie && | 
|  | 14547 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, | 
|  | 14548 | info->req_ie)) || | 
|  | 14549 | (info->resp_ie && | 
|  | 14550 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, | 
|  | 14551 | info->resp_ie)) || | 
|  | 14552 | (info->fils.update_erp_next_seq_num && | 
|  | 14553 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | 
|  | 14554 | info->fils.erp_next_seq_num)) || | 
|  | 14555 | (info->fils.kek && | 
|  | 14556 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, | 
|  | 14557 | info->fils.kek)) || | 
|  | 14558 | (info->fils.pmk && | 
|  | 14559 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || | 
|  | 14560 | (info->fils.pmkid && | 
|  | 14561 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) | 
|  | 14562 | goto nla_put_failure; | 
|  | 14563 |  | 
|  | 14564 | genlmsg_end(msg, hdr); | 
|  | 14565 |  | 
|  | 14566 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14567 | NL80211_MCGRP_MLME, gfp); | 
|  | 14568 | return; | 
|  | 14569 |  | 
|  | 14570 | nla_put_failure: | 
|  | 14571 | nlmsg_free(msg); | 
|  | 14572 | } | 
|  | 14573 |  | 
|  | 14574 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, | 
|  | 14575 | struct net_device *netdev, const u8 *bssid) | 
|  | 14576 | { | 
|  | 14577 | struct sk_buff *msg; | 
|  | 14578 | void *hdr; | 
|  | 14579 |  | 
|  | 14580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 14581 | if (!msg) | 
|  | 14582 | return; | 
|  | 14583 |  | 
|  | 14584 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); | 
|  | 14585 | if (!hdr) { | 
|  | 14586 | nlmsg_free(msg); | 
|  | 14587 | return; | 
|  | 14588 | } | 
|  | 14589 |  | 
|  | 14590 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | 
|  | 14591 | goto nla_put_failure; | 
|  | 14592 |  | 
|  | 14593 | genlmsg_end(msg, hdr); | 
|  | 14594 |  | 
|  | 14595 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14596 | NL80211_MCGRP_MLME, GFP_KERNEL); | 
|  | 14597 | return; | 
|  | 14598 |  | 
|  | 14599 | nla_put_failure: | 
|  | 14600 | nlmsg_free(msg); | 
|  | 14601 | } | 
|  | 14602 |  | 
|  | 14603 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | 
|  | 14604 | struct net_device *netdev, u16 reason, | 
|  | 14605 | const u8 *ie, size_t ie_len, bool from_ap) | 
|  | 14606 | { | 
|  | 14607 | struct sk_buff *msg; | 
|  | 14608 | void *hdr; | 
|  | 14609 |  | 
|  | 14610 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); | 
|  | 14611 | if (!msg) | 
|  | 14612 | return; | 
|  | 14613 |  | 
|  | 14614 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | 
|  | 14615 | if (!hdr) { | 
|  | 14616 | nlmsg_free(msg); | 
|  | 14617 | return; | 
|  | 14618 | } | 
|  | 14619 |  | 
|  | 14620 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14621 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14622 | (reason && | 
|  | 14623 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | 
|  | 14624 | (from_ap && | 
|  | 14625 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | 
|  | 14626 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | 
|  | 14627 | goto nla_put_failure; | 
|  | 14628 |  | 
|  | 14629 | genlmsg_end(msg, hdr); | 
|  | 14630 |  | 
|  | 14631 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14632 | NL80211_MCGRP_MLME, GFP_KERNEL); | 
|  | 14633 | return; | 
|  | 14634 |  | 
|  | 14635 | nla_put_failure: | 
|  | 14636 | nlmsg_free(msg); | 
|  | 14637 | } | 
|  | 14638 |  | 
|  | 14639 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, | 
|  | 14640 | struct net_device *netdev, const u8 *bssid, | 
|  | 14641 | gfp_t gfp) | 
|  | 14642 | { | 
|  | 14643 | struct sk_buff *msg; | 
|  | 14644 | void *hdr; | 
|  | 14645 |  | 
|  | 14646 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 14647 | if (!msg) | 
|  | 14648 | return; | 
|  | 14649 |  | 
|  | 14650 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | 
|  | 14651 | if (!hdr) { | 
|  | 14652 | nlmsg_free(msg); | 
|  | 14653 | return; | 
|  | 14654 | } | 
|  | 14655 |  | 
|  | 14656 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14657 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14658 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | 
|  | 14659 | goto nla_put_failure; | 
|  | 14660 |  | 
|  | 14661 | genlmsg_end(msg, hdr); | 
|  | 14662 |  | 
|  | 14663 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14664 | NL80211_MCGRP_MLME, gfp); | 
|  | 14665 | return; | 
|  | 14666 |  | 
|  | 14667 | nla_put_failure: | 
|  | 14668 | nlmsg_free(msg); | 
|  | 14669 | } | 
|  | 14670 |  | 
|  | 14671 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, | 
|  | 14672 | const u8* ie, u8 ie_len, gfp_t gfp) | 
|  | 14673 | { | 
|  | 14674 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 14675 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 14676 | struct sk_buff *msg; | 
|  | 14677 | void *hdr; | 
|  | 14678 |  | 
|  | 14679 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | 
|  | 14680 | return; | 
|  | 14681 |  | 
|  | 14682 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | 
|  | 14683 |  | 
|  | 14684 | msg = nlmsg_new(100 + ie_len, gfp); | 
|  | 14685 | if (!msg) | 
|  | 14686 | return; | 
|  | 14687 |  | 
|  | 14688 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | 
|  | 14689 | if (!hdr) { | 
|  | 14690 | nlmsg_free(msg); | 
|  | 14691 | return; | 
|  | 14692 | } | 
|  | 14693 |  | 
|  | 14694 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14695 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 14696 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 14697 | (ie_len && ie && | 
|  | 14698 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | 
|  | 14699 | goto nla_put_failure; | 
|  | 14700 |  | 
|  | 14701 | genlmsg_end(msg, hdr); | 
|  | 14702 |  | 
|  | 14703 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14704 | NL80211_MCGRP_MLME, gfp); | 
|  | 14705 | return; | 
|  | 14706 |  | 
|  | 14707 | nla_put_failure: | 
|  | 14708 | nlmsg_free(msg); | 
|  | 14709 | } | 
|  | 14710 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); | 
|  | 14711 |  | 
|  | 14712 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, | 
|  | 14713 | struct net_device *netdev, const u8 *addr, | 
|  | 14714 | enum nl80211_key_type key_type, int key_id, | 
|  | 14715 | const u8 *tsc, gfp_t gfp) | 
|  | 14716 | { | 
|  | 14717 | struct sk_buff *msg; | 
|  | 14718 | void *hdr; | 
|  | 14719 |  | 
|  | 14720 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 14721 | if (!msg) | 
|  | 14722 | return; | 
|  | 14723 |  | 
|  | 14724 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | 
|  | 14725 | if (!hdr) { | 
|  | 14726 | nlmsg_free(msg); | 
|  | 14727 | return; | 
|  | 14728 | } | 
|  | 14729 |  | 
|  | 14730 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14731 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 14732 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | 
|  | 14733 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | 
|  | 14734 | (key_id != -1 && | 
|  | 14735 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | 
|  | 14736 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | 
|  | 14737 | goto nla_put_failure; | 
|  | 14738 |  | 
|  | 14739 | genlmsg_end(msg, hdr); | 
|  | 14740 |  | 
|  | 14741 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14742 | NL80211_MCGRP_MLME, gfp); | 
|  | 14743 | return; | 
|  | 14744 |  | 
|  | 14745 | nla_put_failure: | 
|  | 14746 | nlmsg_free(msg); | 
|  | 14747 | } | 
|  | 14748 |  | 
|  | 14749 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, | 
|  | 14750 | struct ieee80211_channel *channel_before, | 
|  | 14751 | struct ieee80211_channel *channel_after) | 
|  | 14752 | { | 
|  | 14753 | struct sk_buff *msg; | 
|  | 14754 | void *hdr; | 
|  | 14755 | struct nlattr *nl_freq; | 
|  | 14756 |  | 
|  | 14757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); | 
|  | 14758 | if (!msg) | 
|  | 14759 | return; | 
|  | 14760 |  | 
|  | 14761 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | 
|  | 14762 | if (!hdr) { | 
|  | 14763 | nlmsg_free(msg); | 
|  | 14764 | return; | 
|  | 14765 | } | 
|  | 14766 |  | 
|  | 14767 | /* | 
|  | 14768 | * Since we are applying the beacon hint to a wiphy we know its | 
|  | 14769 | * wiphy_idx is valid | 
|  | 14770 | */ | 
|  | 14771 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | 
|  | 14772 | goto nla_put_failure; | 
|  | 14773 |  | 
|  | 14774 | /* Before */ | 
|  | 14775 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | 
|  | 14776 | if (!nl_freq) | 
|  | 14777 | goto nla_put_failure; | 
|  | 14778 |  | 
|  | 14779 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) | 
|  | 14780 | goto nla_put_failure; | 
|  | 14781 | nla_nest_end(msg, nl_freq); | 
|  | 14782 |  | 
|  | 14783 | /* After */ | 
|  | 14784 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | 
|  | 14785 | if (!nl_freq) | 
|  | 14786 | goto nla_put_failure; | 
|  | 14787 |  | 
|  | 14788 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) | 
|  | 14789 | goto nla_put_failure; | 
|  | 14790 | nla_nest_end(msg, nl_freq); | 
|  | 14791 |  | 
|  | 14792 | genlmsg_end(msg, hdr); | 
|  | 14793 |  | 
|  | 14794 | rcu_read_lock(); | 
|  | 14795 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, | 
|  | 14796 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); | 
|  | 14797 | rcu_read_unlock(); | 
|  | 14798 |  | 
|  | 14799 | return; | 
|  | 14800 |  | 
|  | 14801 | nla_put_failure: | 
|  | 14802 | nlmsg_free(msg); | 
|  | 14803 | } | 
|  | 14804 |  | 
|  | 14805 | static void nl80211_send_remain_on_chan_event( | 
|  | 14806 | int cmd, struct cfg80211_registered_device *rdev, | 
|  | 14807 | struct wireless_dev *wdev, u64 cookie, | 
|  | 14808 | struct ieee80211_channel *chan, | 
|  | 14809 | unsigned int duration, gfp_t gfp) | 
|  | 14810 | { | 
|  | 14811 | struct sk_buff *msg; | 
|  | 14812 | void *hdr; | 
|  | 14813 |  | 
|  | 14814 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 14815 | if (!msg) | 
|  | 14816 | return; | 
|  | 14817 |  | 
|  | 14818 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
|  | 14819 | if (!hdr) { | 
|  | 14820 | nlmsg_free(msg); | 
|  | 14821 | return; | 
|  | 14822 | } | 
|  | 14823 |  | 
|  | 14824 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14825 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 14826 | wdev->netdev->ifindex)) || | 
|  | 14827 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 14828 | NL80211_ATTR_PAD) || | 
|  | 14829 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || | 
|  | 14830 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | 
|  | 14831 | NL80211_CHAN_NO_HT) || | 
|  | 14832 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 14833 | NL80211_ATTR_PAD)) | 
|  | 14834 | goto nla_put_failure; | 
|  | 14835 |  | 
|  | 14836 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && | 
|  | 14837 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | 
|  | 14838 | goto nla_put_failure; | 
|  | 14839 |  | 
|  | 14840 | genlmsg_end(msg, hdr); | 
|  | 14841 |  | 
|  | 14842 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14843 | NL80211_MCGRP_MLME, gfp); | 
|  | 14844 | return; | 
|  | 14845 |  | 
|  | 14846 | nla_put_failure: | 
|  | 14847 | nlmsg_free(msg); | 
|  | 14848 | } | 
|  | 14849 |  | 
|  | 14850 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, | 
|  | 14851 | struct ieee80211_channel *chan, | 
|  | 14852 | unsigned int duration, gfp_t gfp) | 
|  | 14853 | { | 
|  | 14854 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 14855 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 14856 |  | 
|  | 14857 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | 
|  | 14858 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | 
|  | 14859 | rdev, wdev, cookie, chan, | 
|  | 14860 | duration, gfp); | 
|  | 14861 | } | 
|  | 14862 | EXPORT_SYMBOL(cfg80211_ready_on_channel); | 
|  | 14863 |  | 
|  | 14864 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, | 
|  | 14865 | struct ieee80211_channel *chan, | 
|  | 14866 | gfp_t gfp) | 
|  | 14867 | { | 
|  | 14868 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 14869 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 14870 |  | 
|  | 14871 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | 
|  | 14872 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | 
|  | 14873 | rdev, wdev, cookie, chan, 0, gfp); | 
|  | 14874 | } | 
|  | 14875 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); | 
|  | 14876 |  | 
|  | 14877 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, | 
|  | 14878 | struct station_info *sinfo, gfp_t gfp) | 
|  | 14879 | { | 
|  | 14880 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | 
|  | 14881 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 14882 | struct sk_buff *msg; | 
|  | 14883 |  | 
|  | 14884 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); | 
|  | 14885 |  | 
|  | 14886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 14887 | if (!msg) | 
|  | 14888 | return; | 
|  | 14889 |  | 
|  | 14890 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, | 
|  | 14891 | rdev, dev, mac_addr, sinfo) < 0) { | 
|  | 14892 | nlmsg_free(msg); | 
|  | 14893 | return; | 
|  | 14894 | } | 
|  | 14895 |  | 
|  | 14896 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14897 | NL80211_MCGRP_MLME, gfp); | 
|  | 14898 | } | 
|  | 14899 | EXPORT_SYMBOL(cfg80211_new_sta); | 
|  | 14900 |  | 
|  | 14901 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, | 
|  | 14902 | struct station_info *sinfo, gfp_t gfp) | 
|  | 14903 | { | 
|  | 14904 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | 
|  | 14905 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 14906 | struct sk_buff *msg; | 
|  | 14907 | struct station_info empty_sinfo = {}; | 
|  | 14908 |  | 
|  | 14909 | if (!sinfo) | 
|  | 14910 | sinfo = &empty_sinfo; | 
|  | 14911 |  | 
|  | 14912 | trace_cfg80211_del_sta(dev, mac_addr); | 
|  | 14913 |  | 
|  | 14914 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 14915 | if (!msg) { | 
|  | 14916 | cfg80211_sinfo_release_content(sinfo); | 
|  | 14917 | return; | 
|  | 14918 | } | 
|  | 14919 |  | 
|  | 14920 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, | 
|  | 14921 | rdev, dev, mac_addr, sinfo) < 0) { | 
|  | 14922 | nlmsg_free(msg); | 
|  | 14923 | return; | 
|  | 14924 | } | 
|  | 14925 |  | 
|  | 14926 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14927 | NL80211_MCGRP_MLME, gfp); | 
|  | 14928 | } | 
|  | 14929 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); | 
|  | 14930 |  | 
|  | 14931 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, | 
|  | 14932 | enum nl80211_connect_failed_reason reason, | 
|  | 14933 | gfp_t gfp) | 
|  | 14934 | { | 
|  | 14935 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | 
|  | 14936 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 14937 | struct sk_buff *msg; | 
|  | 14938 | void *hdr; | 
|  | 14939 |  | 
|  | 14940 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | 
|  | 14941 | if (!msg) | 
|  | 14942 | return; | 
|  | 14943 |  | 
|  | 14944 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | 
|  | 14945 | if (!hdr) { | 
|  | 14946 | nlmsg_free(msg); | 
|  | 14947 | return; | 
|  | 14948 | } | 
|  | 14949 |  | 
|  | 14950 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 14951 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | 
|  | 14952 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | 
|  | 14953 | goto nla_put_failure; | 
|  | 14954 |  | 
|  | 14955 | genlmsg_end(msg, hdr); | 
|  | 14956 |  | 
|  | 14957 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 14958 | NL80211_MCGRP_MLME, gfp); | 
|  | 14959 | return; | 
|  | 14960 |  | 
|  | 14961 | nla_put_failure: | 
|  | 14962 | nlmsg_free(msg); | 
|  | 14963 | } | 
|  | 14964 | EXPORT_SYMBOL(cfg80211_conn_failed); | 
|  | 14965 |  | 
|  | 14966 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, | 
|  | 14967 | const u8 *addr, gfp_t gfp) | 
|  | 14968 | { | 
|  | 14969 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 14970 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 14971 | struct sk_buff *msg; | 
|  | 14972 | void *hdr; | 
|  | 14973 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); | 
|  | 14974 |  | 
|  | 14975 | if (!nlportid) | 
|  | 14976 | return false; | 
|  | 14977 |  | 
|  | 14978 | msg = nlmsg_new(100, gfp); | 
|  | 14979 | if (!msg) | 
|  | 14980 | return true; | 
|  | 14981 |  | 
|  | 14982 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
|  | 14983 | if (!hdr) { | 
|  | 14984 | nlmsg_free(msg); | 
|  | 14985 | return true; | 
|  | 14986 | } | 
|  | 14987 |  | 
|  | 14988 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 14989 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 14990 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | 
|  | 14991 | goto nla_put_failure; | 
|  | 14992 |  | 
|  | 14993 | genlmsg_end(msg, hdr); | 
|  | 14994 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
|  | 14995 | return true; | 
|  | 14996 |  | 
|  | 14997 | nla_put_failure: | 
|  | 14998 | nlmsg_free(msg); | 
|  | 14999 | return true; | 
|  | 15000 | } | 
|  | 15001 |  | 
|  | 15002 | bool cfg80211_rx_spurious_frame(struct net_device *dev, | 
|  | 15003 | const u8 *addr, gfp_t gfp) | 
|  | 15004 | { | 
|  | 15005 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15006 | bool ret; | 
|  | 15007 |  | 
|  | 15008 | trace_cfg80211_rx_spurious_frame(dev, addr); | 
|  | 15009 |  | 
|  | 15010 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | 
|  | 15011 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | 
|  | 15012 | trace_cfg80211_return_bool(false); | 
|  | 15013 | return false; | 
|  | 15014 | } | 
|  | 15015 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | 
|  | 15016 | addr, gfp); | 
|  | 15017 | trace_cfg80211_return_bool(ret); | 
|  | 15018 | return ret; | 
|  | 15019 | } | 
|  | 15020 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); | 
|  | 15021 |  | 
|  | 15022 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, | 
|  | 15023 | const u8 *addr, gfp_t gfp) | 
|  | 15024 | { | 
|  | 15025 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15026 | bool ret; | 
|  | 15027 |  | 
|  | 15028 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | 
|  | 15029 |  | 
|  | 15030 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | 
|  | 15031 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | 
|  | 15032 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | 
|  | 15033 | trace_cfg80211_return_bool(false); | 
|  | 15034 | return false; | 
|  | 15035 | } | 
|  | 15036 | ret = __nl80211_unexpected_frame(dev, | 
|  | 15037 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | 
|  | 15038 | addr, gfp); | 
|  | 15039 | trace_cfg80211_return_bool(ret); | 
|  | 15040 | return ret; | 
|  | 15041 | } | 
|  | 15042 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); | 
|  | 15043 |  | 
|  | 15044 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, | 
|  | 15045 | struct wireless_dev *wdev, u32 nlportid, | 
|  | 15046 | int freq, int sig_dbm, | 
|  | 15047 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) | 
|  | 15048 | { | 
|  | 15049 | struct net_device *netdev = wdev->netdev; | 
|  | 15050 | struct sk_buff *msg; | 
|  | 15051 | void *hdr; | 
|  | 15052 |  | 
|  | 15053 | msg = nlmsg_new(100 + len, gfp); | 
|  | 15054 | if (!msg) | 
|  | 15055 | return -ENOMEM; | 
|  | 15056 |  | 
|  | 15057 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | 
|  | 15058 | if (!hdr) { | 
|  | 15059 | nlmsg_free(msg); | 
|  | 15060 | return -ENOMEM; | 
|  | 15061 | } | 
|  | 15062 |  | 
|  | 15063 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15064 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 15065 | netdev->ifindex)) || | 
|  | 15066 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 15067 | NL80211_ATTR_PAD) || | 
|  | 15068 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | 
|  | 15069 | (sig_dbm && | 
|  | 15070 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | 
|  | 15071 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | 
|  | 15072 | (flags && | 
|  | 15073 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | 
|  | 15074 | goto nla_put_failure; | 
|  | 15075 |  | 
|  | 15076 | genlmsg_end(msg, hdr); | 
|  | 15077 |  | 
|  | 15078 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
|  | 15079 |  | 
|  | 15080 | nla_put_failure: | 
|  | 15081 | nlmsg_free(msg); | 
|  | 15082 | return -ENOBUFS; | 
|  | 15083 | } | 
|  | 15084 |  | 
|  | 15085 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, | 
|  | 15086 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | 
|  | 15087 | { | 
|  | 15088 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 15089 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 15090 | struct net_device *netdev = wdev->netdev; | 
|  | 15091 | struct sk_buff *msg; | 
|  | 15092 | void *hdr; | 
|  | 15093 |  | 
|  | 15094 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); | 
|  | 15095 |  | 
|  | 15096 | msg = nlmsg_new(100 + len, gfp); | 
|  | 15097 | if (!msg) | 
|  | 15098 | return; | 
|  | 15099 |  | 
|  | 15100 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); | 
|  | 15101 | if (!hdr) { | 
|  | 15102 | nlmsg_free(msg); | 
|  | 15103 | return; | 
|  | 15104 | } | 
|  | 15105 |  | 
|  | 15106 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15107 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 15108 | netdev->ifindex)) || | 
|  | 15109 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 15110 | NL80211_ATTR_PAD) || | 
|  | 15111 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | 
|  | 15112 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 15113 | NL80211_ATTR_PAD) || | 
|  | 15114 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | 
|  | 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 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); | 
|  | 15127 |  | 
|  | 15128 | static int __nl80211_rx_control_port(struct net_device *dev, | 
|  | 15129 | struct sk_buff *skb, | 
|  | 15130 | bool unencrypted, gfp_t gfp) | 
|  | 15131 | { | 
|  | 15132 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15133 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15134 | struct ethhdr *ehdr = eth_hdr(skb); | 
|  | 15135 | const u8 *addr = ehdr->h_source; | 
|  | 15136 | u16 proto = be16_to_cpu(skb->protocol); | 
|  | 15137 | struct sk_buff *msg; | 
|  | 15138 | void *hdr; | 
|  | 15139 | struct nlattr *frame; | 
|  | 15140 |  | 
|  | 15141 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); | 
|  | 15142 |  | 
|  | 15143 | if (!nlportid) | 
|  | 15144 | return -ENOENT; | 
|  | 15145 |  | 
|  | 15146 | msg = nlmsg_new(100 + skb->len, gfp); | 
|  | 15147 | if (!msg) | 
|  | 15148 | return -ENOMEM; | 
|  | 15149 |  | 
|  | 15150 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); | 
|  | 15151 | if (!hdr) { | 
|  | 15152 | nlmsg_free(msg); | 
|  | 15153 | return -ENOBUFS; | 
|  | 15154 | } | 
|  | 15155 |  | 
|  | 15156 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15157 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 15158 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 15159 | NL80211_ATTR_PAD) || | 
|  | 15160 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 15161 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || | 
|  | 15162 | (unencrypted && nla_put_flag(msg, | 
|  | 15163 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | 
|  | 15164 | goto nla_put_failure; | 
|  | 15165 |  | 
|  | 15166 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); | 
|  | 15167 | if (!frame) | 
|  | 15168 | goto nla_put_failure; | 
|  | 15169 |  | 
|  | 15170 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); | 
|  | 15171 | genlmsg_end(msg, hdr); | 
|  | 15172 |  | 
|  | 15173 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
|  | 15174 |  | 
|  | 15175 | nla_put_failure: | 
|  | 15176 | nlmsg_free(msg); | 
|  | 15177 | return -ENOBUFS; | 
|  | 15178 | } | 
|  | 15179 |  | 
|  | 15180 | bool cfg80211_rx_control_port(struct net_device *dev, | 
|  | 15181 | struct sk_buff *skb, bool unencrypted) | 
|  | 15182 | { | 
|  | 15183 | int ret; | 
|  | 15184 |  | 
|  | 15185 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); | 
|  | 15186 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); | 
|  | 15187 | trace_cfg80211_return_bool(ret == 0); | 
|  | 15188 | return ret == 0; | 
|  | 15189 | } | 
|  | 15190 | EXPORT_SYMBOL(cfg80211_rx_control_port); | 
|  | 15191 |  | 
|  | 15192 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, | 
|  | 15193 | const char *mac, gfp_t gfp) | 
|  | 15194 | { | 
|  | 15195 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15196 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15197 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15198 | void **cb; | 
|  | 15199 |  | 
|  | 15200 | if (!msg) | 
|  | 15201 | return NULL; | 
|  | 15202 |  | 
|  | 15203 | cb = (void **)msg->cb; | 
|  | 15204 |  | 
|  | 15205 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | 
|  | 15206 | if (!cb[0]) { | 
|  | 15207 | nlmsg_free(msg); | 
|  | 15208 | return NULL; | 
|  | 15209 | } | 
|  | 15210 |  | 
|  | 15211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15212 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | 
|  | 15213 | goto nla_put_failure; | 
|  | 15214 |  | 
|  | 15215 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) | 
|  | 15216 | goto nla_put_failure; | 
|  | 15217 |  | 
|  | 15218 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); | 
|  | 15219 | if (!cb[1]) | 
|  | 15220 | goto nla_put_failure; | 
|  | 15221 |  | 
|  | 15222 | cb[2] = rdev; | 
|  | 15223 |  | 
|  | 15224 | return msg; | 
|  | 15225 | nla_put_failure: | 
|  | 15226 | nlmsg_free(msg); | 
|  | 15227 | return NULL; | 
|  | 15228 | } | 
|  | 15229 |  | 
|  | 15230 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | 
|  | 15231 | { | 
|  | 15232 | void **cb = (void **)msg->cb; | 
|  | 15233 | struct cfg80211_registered_device *rdev = cb[2]; | 
|  | 15234 |  | 
|  | 15235 | nla_nest_end(msg, cb[1]); | 
|  | 15236 | genlmsg_end(msg, cb[0]); | 
|  | 15237 |  | 
|  | 15238 | memset(msg->cb, 0, sizeof(msg->cb)); | 
|  | 15239 |  | 
|  | 15240 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15241 | NL80211_MCGRP_MLME, gfp); | 
|  | 15242 | } | 
|  | 15243 |  | 
|  | 15244 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | 
|  | 15245 | enum nl80211_cqm_rssi_threshold_event rssi_event, | 
|  | 15246 | s32 rssi_level, gfp_t gfp) | 
|  | 15247 | { | 
|  | 15248 | struct sk_buff *msg; | 
|  | 15249 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15250 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15251 |  | 
|  | 15252 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); | 
|  | 15253 |  | 
|  | 15254 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && | 
|  | 15255 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | 
|  | 15256 | return; | 
|  | 15257 |  | 
|  | 15258 | if (wdev->cqm_config) { | 
|  | 15259 | wdev->cqm_config->last_rssi_event_value = rssi_level; | 
|  | 15260 |  | 
|  | 15261 | cfg80211_cqm_rssi_update(rdev, dev); | 
|  | 15262 |  | 
|  | 15263 | if (rssi_level == 0) | 
|  | 15264 | rssi_level = wdev->cqm_config->last_rssi_event_value; | 
|  | 15265 | } | 
|  | 15266 |  | 
|  | 15267 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | 
|  | 15268 | if (!msg) | 
|  | 15269 | return; | 
|  | 15270 |  | 
|  | 15271 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | 
|  | 15272 | rssi_event)) | 
|  | 15273 | goto nla_put_failure; | 
|  | 15274 |  | 
|  | 15275 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, | 
|  | 15276 | rssi_level)) | 
|  | 15277 | goto nla_put_failure; | 
|  | 15278 |  | 
|  | 15279 | cfg80211_send_cqm(msg, gfp); | 
|  | 15280 |  | 
|  | 15281 | return; | 
|  | 15282 |  | 
|  | 15283 | nla_put_failure: | 
|  | 15284 | nlmsg_free(msg); | 
|  | 15285 | } | 
|  | 15286 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); | 
|  | 15287 |  | 
|  | 15288 | void cfg80211_cqm_txe_notify(struct net_device *dev, | 
|  | 15289 | const u8 *peer, u32 num_packets, | 
|  | 15290 | u32 rate, u32 intvl, gfp_t gfp) | 
|  | 15291 | { | 
|  | 15292 | struct sk_buff *msg; | 
|  | 15293 |  | 
|  | 15294 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | 
|  | 15295 | if (!msg) | 
|  | 15296 | return; | 
|  | 15297 |  | 
|  | 15298 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | 
|  | 15299 | goto nla_put_failure; | 
|  | 15300 |  | 
|  | 15301 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | 
|  | 15302 | goto nla_put_failure; | 
|  | 15303 |  | 
|  | 15304 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | 
|  | 15305 | goto nla_put_failure; | 
|  | 15306 |  | 
|  | 15307 | cfg80211_send_cqm(msg, gfp); | 
|  | 15308 | return; | 
|  | 15309 |  | 
|  | 15310 | nla_put_failure: | 
|  | 15311 | nlmsg_free(msg); | 
|  | 15312 | } | 
|  | 15313 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | 
|  | 15314 |  | 
|  | 15315 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | 
|  | 15316 | const u8 *peer, u32 num_packets, gfp_t gfp) | 
|  | 15317 | { | 
|  | 15318 | struct sk_buff *msg; | 
|  | 15319 |  | 
|  | 15320 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | 
|  | 15321 |  | 
|  | 15322 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | 
|  | 15323 | if (!msg) | 
|  | 15324 | return; | 
|  | 15325 |  | 
|  | 15326 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | 
|  | 15327 | goto nla_put_failure; | 
|  | 15328 |  | 
|  | 15329 | cfg80211_send_cqm(msg, gfp); | 
|  | 15330 | return; | 
|  | 15331 |  | 
|  | 15332 | nla_put_failure: | 
|  | 15333 | nlmsg_free(msg); | 
|  | 15334 | } | 
|  | 15335 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | 
|  | 15336 |  | 
|  | 15337 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) | 
|  | 15338 | { | 
|  | 15339 | struct sk_buff *msg; | 
|  | 15340 |  | 
|  | 15341 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | 
|  | 15342 | if (!msg) | 
|  | 15343 | return; | 
|  | 15344 |  | 
|  | 15345 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | 
|  | 15346 | goto nla_put_failure; | 
|  | 15347 |  | 
|  | 15348 | cfg80211_send_cqm(msg, gfp); | 
|  | 15349 | return; | 
|  | 15350 |  | 
|  | 15351 | nla_put_failure: | 
|  | 15352 | nlmsg_free(msg); | 
|  | 15353 | } | 
|  | 15354 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | 
|  | 15355 |  | 
|  | 15356 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, | 
|  | 15357 | struct net_device *netdev, const u8 *bssid, | 
|  | 15358 | const u8 *replay_ctr, gfp_t gfp) | 
|  | 15359 | { | 
|  | 15360 | struct sk_buff *msg; | 
|  | 15361 | struct nlattr *rekey_attr; | 
|  | 15362 | void *hdr; | 
|  | 15363 |  | 
|  | 15364 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15365 | if (!msg) | 
|  | 15366 | return; | 
|  | 15367 |  | 
|  | 15368 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | 
|  | 15369 | if (!hdr) { | 
|  | 15370 | nlmsg_free(msg); | 
|  | 15371 | return; | 
|  | 15372 | } | 
|  | 15373 |  | 
|  | 15374 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15375 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 15376 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | 
|  | 15377 | goto nla_put_failure; | 
|  | 15378 |  | 
|  | 15379 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | 
|  | 15380 | if (!rekey_attr) | 
|  | 15381 | goto nla_put_failure; | 
|  | 15382 |  | 
|  | 15383 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, | 
|  | 15384 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | 
|  | 15385 | goto nla_put_failure; | 
|  | 15386 |  | 
|  | 15387 | nla_nest_end(msg, rekey_attr); | 
|  | 15388 |  | 
|  | 15389 | genlmsg_end(msg, hdr); | 
|  | 15390 |  | 
|  | 15391 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15392 | NL80211_MCGRP_MLME, gfp); | 
|  | 15393 | return; | 
|  | 15394 |  | 
|  | 15395 | nla_put_failure: | 
|  | 15396 | nlmsg_free(msg); | 
|  | 15397 | } | 
|  | 15398 |  | 
|  | 15399 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, | 
|  | 15400 | const u8 *replay_ctr, gfp_t gfp) | 
|  | 15401 | { | 
|  | 15402 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15403 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 15404 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 15405 |  | 
|  | 15406 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | 
|  | 15407 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | 
|  | 15408 | } | 
|  | 15409 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | 
|  | 15410 |  | 
|  | 15411 | static void | 
|  | 15412 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | 
|  | 15413 | struct net_device *netdev, int index, | 
|  | 15414 | const u8 *bssid, bool preauth, gfp_t gfp) | 
|  | 15415 | { | 
|  | 15416 | struct sk_buff *msg; | 
|  | 15417 | struct nlattr *attr; | 
|  | 15418 | void *hdr; | 
|  | 15419 |  | 
|  | 15420 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15421 | if (!msg) | 
|  | 15422 | return; | 
|  | 15423 |  | 
|  | 15424 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | 
|  | 15425 | if (!hdr) { | 
|  | 15426 | nlmsg_free(msg); | 
|  | 15427 | return; | 
|  | 15428 | } | 
|  | 15429 |  | 
|  | 15430 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15431 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | 
|  | 15432 | goto nla_put_failure; | 
|  | 15433 |  | 
|  | 15434 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | 
|  | 15435 | if (!attr) | 
|  | 15436 | goto nla_put_failure; | 
|  | 15437 |  | 
|  | 15438 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || | 
|  | 15439 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | 
|  | 15440 | (preauth && | 
|  | 15441 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | 
|  | 15442 | goto nla_put_failure; | 
|  | 15443 |  | 
|  | 15444 | nla_nest_end(msg, attr); | 
|  | 15445 |  | 
|  | 15446 | genlmsg_end(msg, hdr); | 
|  | 15447 |  | 
|  | 15448 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15449 | NL80211_MCGRP_MLME, gfp); | 
|  | 15450 | return; | 
|  | 15451 |  | 
|  | 15452 | nla_put_failure: | 
|  | 15453 | nlmsg_free(msg); | 
|  | 15454 | } | 
|  | 15455 |  | 
|  | 15456 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, | 
|  | 15457 | const u8 *bssid, bool preauth, gfp_t gfp) | 
|  | 15458 | { | 
|  | 15459 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15460 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 15461 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 15462 |  | 
|  | 15463 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | 
|  | 15464 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | 
|  | 15465 | } | 
|  | 15466 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | 
|  | 15467 |  | 
|  | 15468 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | 
|  | 15469 | struct net_device *netdev, | 
|  | 15470 | struct cfg80211_chan_def *chandef, | 
|  | 15471 | gfp_t gfp, | 
|  | 15472 | enum nl80211_commands notif, | 
|  | 15473 | u8 count) | 
|  | 15474 | { | 
|  | 15475 | struct sk_buff *msg; | 
|  | 15476 | void *hdr; | 
|  | 15477 |  | 
|  | 15478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15479 | if (!msg) | 
|  | 15480 | return; | 
|  | 15481 |  | 
|  | 15482 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); | 
|  | 15483 | if (!hdr) { | 
|  | 15484 | nlmsg_free(msg); | 
|  | 15485 | return; | 
|  | 15486 | } | 
|  | 15487 |  | 
|  | 15488 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | 
|  | 15489 | goto nla_put_failure; | 
|  | 15490 |  | 
|  | 15491 | if (nl80211_send_chandef(msg, chandef)) | 
|  | 15492 | goto nla_put_failure; | 
|  | 15493 |  | 
|  | 15494 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && | 
|  | 15495 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | 
|  | 15496 | goto nla_put_failure; | 
|  | 15497 |  | 
|  | 15498 | genlmsg_end(msg, hdr); | 
|  | 15499 |  | 
|  | 15500 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15501 | NL80211_MCGRP_MLME, gfp); | 
|  | 15502 | return; | 
|  | 15503 |  | 
|  | 15504 | nla_put_failure: | 
|  | 15505 | nlmsg_free(msg); | 
|  | 15506 | } | 
|  | 15507 |  | 
|  | 15508 | void cfg80211_ch_switch_notify(struct net_device *dev, | 
|  | 15509 | struct cfg80211_chan_def *chandef) | 
|  | 15510 | { | 
|  | 15511 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15512 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 15513 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 15514 |  | 
|  | 15515 | ASSERT_WDEV_LOCK(wdev); | 
|  | 15516 |  | 
|  | 15517 | trace_cfg80211_ch_switch_notify(dev, chandef); | 
|  | 15518 |  | 
|  | 15519 | wdev->chandef = *chandef; | 
|  | 15520 | wdev->preset_chandef = *chandef; | 
|  | 15521 |  | 
|  | 15522 | if (wdev->iftype == NL80211_IFTYPE_STATION && | 
|  | 15523 | !WARN_ON(!wdev->current_bss)) | 
|  | 15524 | wdev->current_bss->pub.channel = chandef->chan; | 
|  | 15525 |  | 
|  | 15526 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | 
|  | 15527 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | 
|  | 15528 | } | 
|  | 15529 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | 
|  | 15530 |  | 
|  | 15531 | void cfg80211_ch_switch_started_notify(struct net_device *dev, | 
|  | 15532 | struct cfg80211_chan_def *chandef, | 
|  | 15533 | u8 count) | 
|  | 15534 | { | 
|  | 15535 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15536 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 15537 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 15538 |  | 
|  | 15539 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | 
|  | 15540 |  | 
|  | 15541 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | 
|  | 15542 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | 
|  | 15543 | } | 
|  | 15544 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | 
|  | 15545 |  | 
|  | 15546 | void | 
|  | 15547 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | 
|  | 15548 | const struct cfg80211_chan_def *chandef, | 
|  | 15549 | enum nl80211_radar_event event, | 
|  | 15550 | struct net_device *netdev, gfp_t gfp) | 
|  | 15551 | { | 
|  | 15552 | struct sk_buff *msg; | 
|  | 15553 | void *hdr; | 
|  | 15554 |  | 
|  | 15555 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15556 | if (!msg) | 
|  | 15557 | return; | 
|  | 15558 |  | 
|  | 15559 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | 
|  | 15560 | if (!hdr) { | 
|  | 15561 | nlmsg_free(msg); | 
|  | 15562 | return; | 
|  | 15563 | } | 
|  | 15564 |  | 
|  | 15565 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | 
|  | 15566 | goto nla_put_failure; | 
|  | 15567 |  | 
|  | 15568 | /* NOP and radar events don't need a netdev parameter */ | 
|  | 15569 | if (netdev) { | 
|  | 15570 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | 
|  | 15571 |  | 
|  | 15572 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 15573 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 15574 | NL80211_ATTR_PAD)) | 
|  | 15575 | goto nla_put_failure; | 
|  | 15576 | } | 
|  | 15577 |  | 
|  | 15578 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | 
|  | 15579 | goto nla_put_failure; | 
|  | 15580 |  | 
|  | 15581 | if (nl80211_send_chandef(msg, chandef)) | 
|  | 15582 | goto nla_put_failure; | 
|  | 15583 |  | 
|  | 15584 | genlmsg_end(msg, hdr); | 
|  | 15585 |  | 
|  | 15586 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15587 | NL80211_MCGRP_MLME, gfp); | 
|  | 15588 | return; | 
|  | 15589 |  | 
|  | 15590 | nla_put_failure: | 
|  | 15591 | nlmsg_free(msg); | 
|  | 15592 | } | 
|  | 15593 |  | 
|  | 15594 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, | 
|  | 15595 | struct sta_opmode_info *sta_opmode, | 
|  | 15596 | gfp_t gfp) | 
|  | 15597 | { | 
|  | 15598 | struct sk_buff *msg; | 
|  | 15599 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15600 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15601 | void *hdr; | 
|  | 15602 |  | 
|  | 15603 | if (WARN_ON(!mac)) | 
|  | 15604 | return; | 
|  | 15605 |  | 
|  | 15606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15607 | if (!msg) | 
|  | 15608 | return; | 
|  | 15609 |  | 
|  | 15610 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); | 
|  | 15611 | if (!hdr) { | 
|  | 15612 | nlmsg_free(msg); | 
|  | 15613 | return; | 
|  | 15614 | } | 
|  | 15615 |  | 
|  | 15616 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | 
|  | 15617 | goto nla_put_failure; | 
|  | 15618 |  | 
|  | 15619 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | 
|  | 15620 | goto nla_put_failure; | 
|  | 15621 |  | 
|  | 15622 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) | 
|  | 15623 | goto nla_put_failure; | 
|  | 15624 |  | 
|  | 15625 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && | 
|  | 15626 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) | 
|  | 15627 | goto nla_put_failure; | 
|  | 15628 |  | 
|  | 15629 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && | 
|  | 15630 | nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) | 
|  | 15631 | goto nla_put_failure; | 
|  | 15632 |  | 
|  | 15633 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && | 
|  | 15634 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) | 
|  | 15635 | goto nla_put_failure; | 
|  | 15636 |  | 
|  | 15637 | genlmsg_end(msg, hdr); | 
|  | 15638 |  | 
|  | 15639 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15640 | NL80211_MCGRP_MLME, gfp); | 
|  | 15641 |  | 
|  | 15642 | return; | 
|  | 15643 |  | 
|  | 15644 | nla_put_failure: | 
|  | 15645 | nlmsg_free(msg); | 
|  | 15646 | } | 
|  | 15647 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); | 
|  | 15648 |  | 
|  | 15649 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, | 
|  | 15650 | u64 cookie, bool acked, s32 ack_signal, | 
|  | 15651 | bool is_valid_ack_signal, gfp_t gfp) | 
|  | 15652 | { | 
|  | 15653 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15654 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15655 | struct sk_buff *msg; | 
|  | 15656 | void *hdr; | 
|  | 15657 |  | 
|  | 15658 | trace_cfg80211_probe_status(dev, addr, cookie, acked); | 
|  | 15659 |  | 
|  | 15660 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15661 |  | 
|  | 15662 | if (!msg) | 
|  | 15663 | return; | 
|  | 15664 |  | 
|  | 15665 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | 
|  | 15666 | if (!hdr) { | 
|  | 15667 | nlmsg_free(msg); | 
|  | 15668 | return; | 
|  | 15669 | } | 
|  | 15670 |  | 
|  | 15671 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15672 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 15673 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 15674 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | 
|  | 15675 | NL80211_ATTR_PAD) || | 
|  | 15676 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || | 
|  | 15677 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, | 
|  | 15678 | ack_signal))) | 
|  | 15679 | goto nla_put_failure; | 
|  | 15680 |  | 
|  | 15681 | genlmsg_end(msg, hdr); | 
|  | 15682 |  | 
|  | 15683 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15684 | NL80211_MCGRP_MLME, gfp); | 
|  | 15685 | return; | 
|  | 15686 |  | 
|  | 15687 | nla_put_failure: | 
|  | 15688 | nlmsg_free(msg); | 
|  | 15689 | } | 
|  | 15690 | EXPORT_SYMBOL(cfg80211_probe_status); | 
|  | 15691 |  | 
|  | 15692 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, | 
|  | 15693 | const u8 *frame, size_t len, | 
|  | 15694 | int freq, int sig_dbm) | 
|  | 15695 | { | 
|  | 15696 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 15697 | struct sk_buff *msg; | 
|  | 15698 | void *hdr; | 
|  | 15699 | struct cfg80211_beacon_registration *reg; | 
|  | 15700 |  | 
|  | 15701 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); | 
|  | 15702 |  | 
|  | 15703 | spin_lock_bh(&rdev->beacon_registrations_lock); | 
|  | 15704 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | 
|  | 15705 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | 
|  | 15706 | if (!msg) { | 
|  | 15707 | spin_unlock_bh(&rdev->beacon_registrations_lock); | 
|  | 15708 | return; | 
|  | 15709 | } | 
|  | 15710 |  | 
|  | 15711 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | 
|  | 15712 | if (!hdr) | 
|  | 15713 | goto nla_put_failure; | 
|  | 15714 |  | 
|  | 15715 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15716 | (freq && | 
|  | 15717 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | 
|  | 15718 | (sig_dbm && | 
|  | 15719 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | 
|  | 15720 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | 
|  | 15721 | goto nla_put_failure; | 
|  | 15722 |  | 
|  | 15723 | genlmsg_end(msg, hdr); | 
|  | 15724 |  | 
|  | 15725 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); | 
|  | 15726 | } | 
|  | 15727 | spin_unlock_bh(&rdev->beacon_registrations_lock); | 
|  | 15728 | return; | 
|  | 15729 |  | 
|  | 15730 | nla_put_failure: | 
|  | 15731 | spin_unlock_bh(&rdev->beacon_registrations_lock); | 
|  | 15732 | nlmsg_free(msg); | 
|  | 15733 | } | 
|  | 15734 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | 
|  | 15735 |  | 
|  | 15736 | #ifdef CONFIG_PM | 
|  | 15737 | static int cfg80211_net_detect_results(struct sk_buff *msg, | 
|  | 15738 | struct cfg80211_wowlan_wakeup *wakeup) | 
|  | 15739 | { | 
|  | 15740 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | 
|  | 15741 | struct nlattr *nl_results, *nl_match, *nl_freqs; | 
|  | 15742 | int i, j; | 
|  | 15743 |  | 
|  | 15744 | nl_results = nla_nest_start( | 
|  | 15745 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | 
|  | 15746 | if (!nl_results) | 
|  | 15747 | return -EMSGSIZE; | 
|  | 15748 |  | 
|  | 15749 | for (i = 0; i < nd->n_matches; i++) { | 
|  | 15750 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | 
|  | 15751 |  | 
|  | 15752 | nl_match = nla_nest_start(msg, i); | 
|  | 15753 | if (!nl_match) | 
|  | 15754 | break; | 
|  | 15755 |  | 
|  | 15756 | /* The SSID attribute is optional in nl80211, but for | 
|  | 15757 | * simplicity reasons it's always present in the | 
|  | 15758 | * cfg80211 structure.  If a driver can't pass the | 
|  | 15759 | * SSID, that needs to be changed.  A zero length SSID | 
|  | 15760 | * is still a valid SSID (wildcard), so it cannot be | 
|  | 15761 | * used for this purpose. | 
|  | 15762 | */ | 
|  | 15763 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | 
|  | 15764 | match->ssid.ssid)) { | 
|  | 15765 | nla_nest_cancel(msg, nl_match); | 
|  | 15766 | goto out; | 
|  | 15767 | } | 
|  | 15768 |  | 
|  | 15769 | if (match->n_channels) { | 
|  | 15770 | nl_freqs = nla_nest_start( | 
|  | 15771 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | 
|  | 15772 | if (!nl_freqs) { | 
|  | 15773 | nla_nest_cancel(msg, nl_match); | 
|  | 15774 | goto out; | 
|  | 15775 | } | 
|  | 15776 |  | 
|  | 15777 | for (j = 0; j < match->n_channels; j++) { | 
|  | 15778 | if (nla_put_u32(msg, j, match->channels[j])) { | 
|  | 15779 | nla_nest_cancel(msg, nl_freqs); | 
|  | 15780 | nla_nest_cancel(msg, nl_match); | 
|  | 15781 | goto out; | 
|  | 15782 | } | 
|  | 15783 | } | 
|  | 15784 |  | 
|  | 15785 | nla_nest_end(msg, nl_freqs); | 
|  | 15786 | } | 
|  | 15787 |  | 
|  | 15788 | nla_nest_end(msg, nl_match); | 
|  | 15789 | } | 
|  | 15790 |  | 
|  | 15791 | out: | 
|  | 15792 | nla_nest_end(msg, nl_results); | 
|  | 15793 | return 0; | 
|  | 15794 | } | 
|  | 15795 |  | 
|  | 15796 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | 
|  | 15797 | struct cfg80211_wowlan_wakeup *wakeup, | 
|  | 15798 | gfp_t gfp) | 
|  | 15799 | { | 
|  | 15800 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15801 | struct sk_buff *msg; | 
|  | 15802 | void *hdr; | 
|  | 15803 | int size = 200; | 
|  | 15804 |  | 
|  | 15805 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | 
|  | 15806 |  | 
|  | 15807 | if (wakeup) | 
|  | 15808 | size += wakeup->packet_present_len; | 
|  | 15809 |  | 
|  | 15810 | msg = nlmsg_new(size, gfp); | 
|  | 15811 | if (!msg) | 
|  | 15812 | return; | 
|  | 15813 |  | 
|  | 15814 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | 
|  | 15815 | if (!hdr) | 
|  | 15816 | goto free_msg; | 
|  | 15817 |  | 
|  | 15818 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15819 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 15820 | NL80211_ATTR_PAD)) | 
|  | 15821 | goto free_msg; | 
|  | 15822 |  | 
|  | 15823 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
|  | 15824 | wdev->netdev->ifindex)) | 
|  | 15825 | goto free_msg; | 
|  | 15826 |  | 
|  | 15827 | if (wakeup) { | 
|  | 15828 | struct nlattr *reasons; | 
|  | 15829 |  | 
|  | 15830 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | 
|  | 15831 | if (!reasons) | 
|  | 15832 | goto free_msg; | 
|  | 15833 |  | 
|  | 15834 | if (wakeup->disconnect && | 
|  | 15835 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | 
|  | 15836 | goto free_msg; | 
|  | 15837 | if (wakeup->magic_pkt && | 
|  | 15838 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | 
|  | 15839 | goto free_msg; | 
|  | 15840 | if (wakeup->gtk_rekey_failure && | 
|  | 15841 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | 
|  | 15842 | goto free_msg; | 
|  | 15843 | if (wakeup->eap_identity_req && | 
|  | 15844 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | 
|  | 15845 | goto free_msg; | 
|  | 15846 | if (wakeup->four_way_handshake && | 
|  | 15847 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | 
|  | 15848 | goto free_msg; | 
|  | 15849 | if (wakeup->rfkill_release && | 
|  | 15850 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | 
|  | 15851 | goto free_msg; | 
|  | 15852 |  | 
|  | 15853 | if (wakeup->pattern_idx >= 0 && | 
|  | 15854 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | 
|  | 15855 | wakeup->pattern_idx)) | 
|  | 15856 | goto free_msg; | 
|  | 15857 |  | 
|  | 15858 | if (wakeup->tcp_match && | 
|  | 15859 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | 
|  | 15860 | goto free_msg; | 
|  | 15861 |  | 
|  | 15862 | if (wakeup->tcp_connlost && | 
|  | 15863 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | 
|  | 15864 | goto free_msg; | 
|  | 15865 |  | 
|  | 15866 | if (wakeup->tcp_nomoretokens && | 
|  | 15867 | nla_put_flag(msg, | 
|  | 15868 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | 
|  | 15869 | goto free_msg; | 
|  | 15870 |  | 
|  | 15871 | if (wakeup->packet) { | 
|  | 15872 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | 
|  | 15873 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | 
|  | 15874 |  | 
|  | 15875 | if (!wakeup->packet_80211) { | 
|  | 15876 | pkt_attr = | 
|  | 15877 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | 
|  | 15878 | len_attr = | 
|  | 15879 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | 
|  | 15880 | } | 
|  | 15881 |  | 
|  | 15882 | if (wakeup->packet_len && | 
|  | 15883 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | 
|  | 15884 | goto free_msg; | 
|  | 15885 |  | 
|  | 15886 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | 
|  | 15887 | wakeup->packet)) | 
|  | 15888 | goto free_msg; | 
|  | 15889 | } | 
|  | 15890 |  | 
|  | 15891 | if (wakeup->net_detect && | 
|  | 15892 | cfg80211_net_detect_results(msg, wakeup)) | 
|  | 15893 | goto free_msg; | 
|  | 15894 |  | 
|  | 15895 | nla_nest_end(msg, reasons); | 
|  | 15896 | } | 
|  | 15897 |  | 
|  | 15898 | genlmsg_end(msg, hdr); | 
|  | 15899 |  | 
|  | 15900 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15901 | NL80211_MCGRP_MLME, gfp); | 
|  | 15902 | return; | 
|  | 15903 |  | 
|  | 15904 | free_msg: | 
|  | 15905 | nlmsg_free(msg); | 
|  | 15906 | } | 
|  | 15907 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | 
|  | 15908 | #endif | 
|  | 15909 |  | 
|  | 15910 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, | 
|  | 15911 | enum nl80211_tdls_operation oper, | 
|  | 15912 | u16 reason_code, gfp_t gfp) | 
|  | 15913 | { | 
|  | 15914 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 15915 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 15916 | struct sk_buff *msg; | 
|  | 15917 | void *hdr; | 
|  | 15918 |  | 
|  | 15919 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | 
|  | 15920 | reason_code); | 
|  | 15921 |  | 
|  | 15922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 15923 | if (!msg) | 
|  | 15924 | return; | 
|  | 15925 |  | 
|  | 15926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | 
|  | 15927 | if (!hdr) { | 
|  | 15928 | nlmsg_free(msg); | 
|  | 15929 | return; | 
|  | 15930 | } | 
|  | 15931 |  | 
|  | 15932 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 15933 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 15934 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | 
|  | 15935 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | 
|  | 15936 | (reason_code > 0 && | 
|  | 15937 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | 
|  | 15938 | goto nla_put_failure; | 
|  | 15939 |  | 
|  | 15940 | genlmsg_end(msg, hdr); | 
|  | 15941 |  | 
|  | 15942 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 15943 | NL80211_MCGRP_MLME, gfp); | 
|  | 15944 | return; | 
|  | 15945 |  | 
|  | 15946 | nla_put_failure: | 
|  | 15947 | nlmsg_free(msg); | 
|  | 15948 | } | 
|  | 15949 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | 
|  | 15950 |  | 
|  | 15951 | static int nl80211_netlink_notify(struct notifier_block * nb, | 
|  | 15952 | unsigned long state, | 
|  | 15953 | void *_notify) | 
|  | 15954 | { | 
|  | 15955 | struct netlink_notify *notify = _notify; | 
|  | 15956 | struct cfg80211_registered_device *rdev; | 
|  | 15957 | struct wireless_dev *wdev; | 
|  | 15958 | struct cfg80211_beacon_registration *reg, *tmp; | 
|  | 15959 |  | 
|  | 15960 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) | 
|  | 15961 | return NOTIFY_DONE; | 
|  | 15962 |  | 
|  | 15963 | rcu_read_lock(); | 
|  | 15964 |  | 
|  | 15965 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { | 
|  | 15966 | struct cfg80211_sched_scan_request *sched_scan_req; | 
|  | 15967 |  | 
|  | 15968 | list_for_each_entry_rcu(sched_scan_req, | 
|  | 15969 | &rdev->sched_scan_req_list, | 
|  | 15970 | list) { | 
|  | 15971 | if (sched_scan_req->owner_nlportid == notify->portid) { | 
|  | 15972 | sched_scan_req->nl_owner_dead = true; | 
|  | 15973 | schedule_work(&rdev->sched_scan_stop_wk); | 
|  | 15974 | } | 
|  | 15975 | } | 
|  | 15976 |  | 
|  | 15977 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { | 
|  | 15978 | cfg80211_mlme_unregister_socket(wdev, notify->portid); | 
|  | 15979 |  | 
|  | 15980 | if (wdev->owner_nlportid == notify->portid) { | 
|  | 15981 | wdev->nl_owner_dead = true; | 
|  | 15982 | schedule_work(&rdev->destroy_work); | 
|  | 15983 | } else if (wdev->conn_owner_nlportid == notify->portid) { | 
|  | 15984 | schedule_work(&wdev->disconnect_wk); | 
|  | 15985 | } | 
|  | 15986 | } | 
|  | 15987 |  | 
|  | 15988 | spin_lock_bh(&rdev->beacon_registrations_lock); | 
|  | 15989 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | 
|  | 15990 | list) { | 
|  | 15991 | if (reg->nlportid == notify->portid) { | 
|  | 15992 | list_del(®->list); | 
|  | 15993 | kfree(reg); | 
|  | 15994 | break; | 
|  | 15995 | } | 
|  | 15996 | } | 
|  | 15997 | spin_unlock_bh(&rdev->beacon_registrations_lock); | 
|  | 15998 | } | 
|  | 15999 |  | 
|  | 16000 | rcu_read_unlock(); | 
|  | 16001 |  | 
|  | 16002 | /* | 
|  | 16003 | * It is possible that the user space process that is controlling the | 
|  | 16004 | * indoor setting disappeared, so notify the regulatory core. | 
|  | 16005 | */ | 
|  | 16006 | regulatory_netlink_notify(notify->portid); | 
|  | 16007 | return NOTIFY_OK; | 
|  | 16008 | } | 
|  | 16009 |  | 
|  | 16010 | static struct notifier_block nl80211_netlink_notifier = { | 
|  | 16011 | .notifier_call = nl80211_netlink_notify, | 
|  | 16012 | }; | 
|  | 16013 |  | 
|  | 16014 | void cfg80211_ft_event(struct net_device *netdev, | 
|  | 16015 | struct cfg80211_ft_event_params *ft_event) | 
|  | 16016 | { | 
|  | 16017 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | 
|  | 16018 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 16019 | struct sk_buff *msg; | 
|  | 16020 | void *hdr; | 
|  | 16021 |  | 
|  | 16022 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | 
|  | 16023 |  | 
|  | 16024 | if (!ft_event->target_ap) | 
|  | 16025 | return; | 
|  | 16026 |  | 
|  | 16027 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, | 
|  | 16028 | GFP_KERNEL); | 
|  | 16029 | if (!msg) | 
|  | 16030 | return; | 
|  | 16031 |  | 
|  | 16032 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | 
|  | 16033 | if (!hdr) | 
|  | 16034 | goto out; | 
|  | 16035 |  | 
|  | 16036 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 16037 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
|  | 16038 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | 
|  | 16039 | goto out; | 
|  | 16040 |  | 
|  | 16041 | if (ft_event->ies && | 
|  | 16042 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | 
|  | 16043 | goto out; | 
|  | 16044 | if (ft_event->ric_ies && | 
|  | 16045 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | 
|  | 16046 | ft_event->ric_ies)) | 
|  | 16047 | goto out; | 
|  | 16048 |  | 
|  | 16049 | genlmsg_end(msg, hdr); | 
|  | 16050 |  | 
|  | 16051 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
|  | 16052 | NL80211_MCGRP_MLME, GFP_KERNEL); | 
|  | 16053 | return; | 
|  | 16054 | out: | 
|  | 16055 | nlmsg_free(msg); | 
|  | 16056 | } | 
|  | 16057 | EXPORT_SYMBOL(cfg80211_ft_event); | 
|  | 16058 |  | 
|  | 16059 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) | 
|  | 16060 | { | 
|  | 16061 | struct cfg80211_registered_device *rdev; | 
|  | 16062 | struct sk_buff *msg; | 
|  | 16063 | void *hdr; | 
|  | 16064 | u32 nlportid; | 
|  | 16065 |  | 
|  | 16066 | rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 16067 | if (!rdev->crit_proto_nlportid) | 
|  | 16068 | return; | 
|  | 16069 |  | 
|  | 16070 | nlportid = rdev->crit_proto_nlportid; | 
|  | 16071 | rdev->crit_proto_nlportid = 0; | 
|  | 16072 |  | 
|  | 16073 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 16074 | if (!msg) | 
|  | 16075 | return; | 
|  | 16076 |  | 
|  | 16077 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | 
|  | 16078 | if (!hdr) | 
|  | 16079 | goto nla_put_failure; | 
|  | 16080 |  | 
|  | 16081 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 16082 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 16083 | NL80211_ATTR_PAD)) | 
|  | 16084 | goto nla_put_failure; | 
|  | 16085 |  | 
|  | 16086 | genlmsg_end(msg, hdr); | 
|  | 16087 |  | 
|  | 16088 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
|  | 16089 | return; | 
|  | 16090 |  | 
|  | 16091 | nla_put_failure: | 
|  | 16092 | nlmsg_free(msg); | 
|  | 16093 | } | 
|  | 16094 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | 
|  | 16095 |  | 
|  | 16096 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) | 
|  | 16097 | { | 
|  | 16098 | struct wiphy *wiphy = wdev->wiphy; | 
|  | 16099 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
|  | 16100 | struct sk_buff *msg; | 
|  | 16101 | void *hdr; | 
|  | 16102 |  | 
|  | 16103 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
|  | 16104 | if (!msg) | 
|  | 16105 | return; | 
|  | 16106 |  | 
|  | 16107 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | 
|  | 16108 | if (!hdr) | 
|  | 16109 | goto out; | 
|  | 16110 |  | 
|  | 16111 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 16112 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | 
|  | 16113 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | 
|  | 16114 | NL80211_ATTR_PAD)) | 
|  | 16115 | goto out; | 
|  | 16116 |  | 
|  | 16117 | genlmsg_end(msg, hdr); | 
|  | 16118 |  | 
|  | 16119 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | 
|  | 16120 | NL80211_MCGRP_MLME, GFP_KERNEL); | 
|  | 16121 | return; | 
|  | 16122 | out: | 
|  | 16123 | nlmsg_free(msg); | 
|  | 16124 | } | 
|  | 16125 |  | 
|  | 16126 | int cfg80211_external_auth_request(struct net_device *dev, | 
|  | 16127 | struct cfg80211_external_auth_params *params, | 
|  | 16128 | gfp_t gfp) | 
|  | 16129 | { | 
|  | 16130 | struct wireless_dev *wdev = dev->ieee80211_ptr; | 
|  | 16131 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
|  | 16132 | struct sk_buff *msg; | 
|  | 16133 | void *hdr; | 
|  | 16134 |  | 
|  | 16135 | if (!wdev->conn_owner_nlportid) | 
|  | 16136 | return -EINVAL; | 
|  | 16137 |  | 
|  | 16138 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
|  | 16139 | if (!msg) | 
|  | 16140 | return -ENOMEM; | 
|  | 16141 |  | 
|  | 16142 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); | 
|  | 16143 | if (!hdr) | 
|  | 16144 | goto nla_put_failure; | 
|  | 16145 |  | 
|  | 16146 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
|  | 16147 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
|  | 16148 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || | 
|  | 16149 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, | 
|  | 16150 | params->action) || | 
|  | 16151 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || | 
|  | 16152 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, | 
|  | 16153 | params->ssid.ssid)) | 
|  | 16154 | goto nla_put_failure; | 
|  | 16155 |  | 
|  | 16156 | genlmsg_end(msg, hdr); | 
|  | 16157 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | 
|  | 16158 | wdev->conn_owner_nlportid); | 
|  | 16159 | return 0; | 
|  | 16160 |  | 
|  | 16161 | nla_put_failure: | 
|  | 16162 | nlmsg_free(msg); | 
|  | 16163 | return -ENOBUFS; | 
|  | 16164 | } | 
|  | 16165 | EXPORT_SYMBOL(cfg80211_external_auth_request); | 
|  | 16166 |  | 
|  | 16167 | /* initialisation/exit functions */ | 
|  | 16168 |  | 
|  | 16169 | int __init nl80211_init(void) | 
|  | 16170 | { | 
|  | 16171 | int err; | 
|  | 16172 |  | 
|  | 16173 | err = genl_register_family(&nl80211_fam); | 
|  | 16174 | if (err) | 
|  | 16175 | return err; | 
|  | 16176 |  | 
|  | 16177 | err = netlink_register_notifier(&nl80211_netlink_notifier); | 
|  | 16178 | if (err) | 
|  | 16179 | goto err_out; | 
|  | 16180 |  | 
|  | 16181 | return 0; | 
|  | 16182 | err_out: | 
|  | 16183 | genl_unregister_family(&nl80211_fam); | 
|  | 16184 | return err; | 
|  | 16185 | } | 
|  | 16186 |  | 
|  | 16187 | void nl80211_exit(void) | 
|  | 16188 | { | 
|  | 16189 | netlink_unregister_notifier(&nl80211_netlink_notifier); | 
|  | 16190 | genl_unregister_family(&nl80211_fam); | 
|  | 16191 | } |