Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 33 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 34 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 50 | /* multicast groups */ |
| 51 | enum nl80211_multicast_groups { |
| 52 | NL80211_MCGRP_CONFIG, |
| 53 | NL80211_MCGRP_SCAN, |
| 54 | NL80211_MCGRP_REGULATORY, |
| 55 | NL80211_MCGRP_MLME, |
| 56 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 57 | }; |
| 58 | |
| 59 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 60 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 61 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 62 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 63 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
| 64 | #ifdef CONFIG_NL80211_TESTMODE |
| 65 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 66 | #endif |
| 67 | }; |
| 68 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 69 | /* returns ERR_PTR values */ |
| 70 | static struct wireless_dev * |
| 71 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | struct cfg80211_registered_device *rdev; |
| 74 | struct wireless_dev *result = NULL; |
| 75 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 76 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 77 | u64 wdev_id; |
| 78 | int wiphy_idx = -1; |
| 79 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 80 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 81 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 83 | if (!have_ifidx && !have_wdev_id) |
| 84 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 86 | if (have_ifidx) |
| 87 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 88 | if (have_wdev_id) { |
| 89 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 90 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 93 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 94 | struct wireless_dev *wdev; |
| 95 | |
| 96 | if (wiphy_net(&rdev->wiphy) != netns) |
| 97 | continue; |
| 98 | |
| 99 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 100 | continue; |
| 101 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 102 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 103 | if (have_ifidx && wdev->netdev && |
| 104 | wdev->netdev->ifindex == ifidx) { |
| 105 | result = wdev; |
| 106 | break; |
| 107 | } |
| 108 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 109 | result = wdev; |
| 110 | break; |
| 111 | } |
| 112 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | |
| 114 | if (result) |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | if (result) |
| 119 | return result; |
| 120 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 123 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 124 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 126 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 127 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 128 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 129 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 131 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 132 | !attrs[NL80211_ATTR_IFINDEX] && |
| 133 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 134 | return ERR_PTR(-EINVAL); |
| 135 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 136 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 137 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 139 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 140 | if (attrs[NL80211_ATTR_WDEV]) { |
| 141 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 142 | struct wireless_dev *wdev; |
| 143 | bool found = false; |
| 144 | |
| 145 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 146 | if (tmp) { |
| 147 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 148 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 149 | if (wdev->identifier != (u32)wdev_id) |
| 150 | continue; |
| 151 | found = true; |
| 152 | break; |
| 153 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 154 | |
| 155 | if (!found) |
| 156 | tmp = NULL; |
| 157 | |
| 158 | if (rdev && tmp != rdev) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | rdev = tmp; |
| 161 | } |
| 162 | } |
| 163 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 164 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 165 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 166 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 167 | if (netdev) { |
| 168 | if (netdev->ieee80211_ptr) |
| 169 | tmp = wiphy_to_dev( |
| 170 | netdev->ieee80211_ptr->wiphy); |
| 171 | else |
| 172 | tmp = NULL; |
| 173 | |
| 174 | dev_put(netdev); |
| 175 | |
| 176 | /* not wireless device -- return error */ |
| 177 | if (!tmp) |
| 178 | return ERR_PTR(-EINVAL); |
| 179 | |
| 180 | /* mismatch -- return error */ |
| 181 | if (rdev && tmp != rdev) |
| 182 | return ERR_PTR(-EINVAL); |
| 183 | |
| 184 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 188 | if (!rdev) |
| 189 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (netns != wiphy_net(&rdev->wiphy)) |
| 192 | return ERR_PTR(-ENODEV); |
| 193 | |
| 194 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function returns a pointer to the driver |
| 199 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | * |
| 201 | * The result of this can be a PTR_ERR and hence must |
| 202 | * be checked with IS_ERR() for errors. |
| 203 | */ |
| 204 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 210 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 214 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 228 | |
| 229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 232 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 238 | .len = WLAN_MAX_KEY_LEN }, |
| 239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 244 | |
| 245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 248 | .len = IEEE80211_MAX_DATA_LEN }, |
| 249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 255 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 265 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 270 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 379 | }; |
| 380 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 381 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 382 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 383 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 384 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 385 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 386 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 387 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 388 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 389 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 390 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 391 | }; |
| 392 | |
| 393 | /* policy for the key default flags */ |
| 394 | static const struct nla_policy |
| 395 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 396 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 397 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 398 | }; |
| 399 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 400 | /* policy for WoWLAN attributes */ |
| 401 | static const struct nla_policy |
| 402 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 403 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 404 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 405 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 406 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 407 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 408 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 409 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 410 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 411 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 412 | }; |
| 413 | |
| 414 | static const struct nla_policy |
| 415 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 416 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 417 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 418 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 419 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 420 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 421 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 422 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 423 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 424 | }, |
| 425 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 426 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 427 | }, |
| 428 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 429 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 430 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 431 | }; |
| 432 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 433 | /* policy for coalesce rule attributes */ |
| 434 | static const struct nla_policy |
| 435 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 436 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 437 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 438 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 439 | }; |
| 440 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 441 | /* policy for GTK rekey offload attributes */ |
| 442 | static const struct nla_policy |
| 443 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 444 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 445 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 446 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 447 | }; |
| 448 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 449 | static const struct nla_policy |
| 450 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 451 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 452 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 453 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 454 | }; |
| 455 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 456 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 457 | struct netlink_callback *cb, |
| 458 | struct cfg80211_registered_device **rdev, |
| 459 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 460 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 461 | int err; |
| 462 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 463 | rtnl_lock(); |
| 464 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 465 | if (!cb->args[0]) { |
| 466 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 467 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 468 | nl80211_policy); |
| 469 | if (err) |
| 470 | goto out_unlock; |
| 471 | |
| 472 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 473 | nl80211_fam.attrbuf); |
| 474 | if (IS_ERR(*wdev)) { |
| 475 | err = PTR_ERR(*wdev); |
| 476 | goto out_unlock; |
| 477 | } |
| 478 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 479 | /* 0 is the first index - add 1 to parse only once */ |
| 480 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 481 | cb->args[1] = (*wdev)->identifier; |
| 482 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 483 | /* subtract the 1 again here */ |
| 484 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 485 | struct wireless_dev *tmp; |
| 486 | |
| 487 | if (!wiphy) { |
| 488 | err = -ENODEV; |
| 489 | goto out_unlock; |
| 490 | } |
| 491 | *rdev = wiphy_to_dev(wiphy); |
| 492 | *wdev = NULL; |
| 493 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 494 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 495 | if (tmp->identifier == cb->args[1]) { |
| 496 | *wdev = tmp; |
| 497 | break; |
| 498 | } |
| 499 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 500 | |
| 501 | if (!*wdev) { |
| 502 | err = -ENODEV; |
| 503 | goto out_unlock; |
| 504 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 507 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 508 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 509 | rtnl_unlock(); |
| 510 | return err; |
| 511 | } |
| 512 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 513 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 514 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 515 | rtnl_unlock(); |
| 516 | } |
| 517 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 518 | /* IE validation */ |
| 519 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 520 | { |
| 521 | const u8 *pos; |
| 522 | int len; |
| 523 | |
| 524 | if (!attr) |
| 525 | return true; |
| 526 | |
| 527 | pos = nla_data(attr); |
| 528 | len = nla_len(attr); |
| 529 | |
| 530 | while (len) { |
| 531 | u8 elemlen; |
| 532 | |
| 533 | if (len < 2) |
| 534 | return false; |
| 535 | len -= 2; |
| 536 | |
| 537 | elemlen = pos[1]; |
| 538 | if (elemlen > len) |
| 539 | return false; |
| 540 | |
| 541 | len -= elemlen; |
| 542 | pos += 2 + elemlen; |
| 543 | } |
| 544 | |
| 545 | return true; |
| 546 | } |
| 547 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 548 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 549 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 550 | int flags, u8 cmd) |
| 551 | { |
| 552 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 553 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 556 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 557 | struct ieee80211_channel *chan, |
| 558 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 559 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 560 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 561 | chan->center_freq)) |
| 562 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 563 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 564 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 565 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 566 | goto nla_put_failure; |
| 567 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 569 | goto nla_put_failure; |
| 570 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 572 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 573 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 574 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 575 | goto nla_put_failure; |
| 576 | if (large) { |
| 577 | u32 time; |
| 578 | |
| 579 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 580 | |
| 581 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 582 | chan->dfs_state)) |
| 583 | goto nla_put_failure; |
| 584 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 585 | time)) |
| 586 | goto nla_put_failure; |
| 587 | } |
| 588 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 590 | if (large) { |
| 591 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 592 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 593 | goto nla_put_failure; |
| 594 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 595 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 596 | goto nla_put_failure; |
| 597 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 598 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 599 | goto nla_put_failure; |
| 600 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 601 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 602 | goto nla_put_failure; |
| 603 | } |
| 604 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 605 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 606 | DBM_TO_MBM(chan->max_power))) |
| 607 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | |
| 611 | nla_put_failure: |
| 612 | return -ENOBUFS; |
| 613 | } |
| 614 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 615 | /* netlink command implementations */ |
| 616 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 617 | struct key_parse { |
| 618 | struct key_params p; |
| 619 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 620 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 621 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 622 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 623 | }; |
| 624 | |
| 625 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 626 | { |
| 627 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 628 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 629 | nl80211_key_policy); |
| 630 | if (err) |
| 631 | return err; |
| 632 | |
| 633 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 634 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 635 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 636 | if (k->def) { |
| 637 | k->def_uni = true; |
| 638 | k->def_multi = true; |
| 639 | } |
| 640 | if (k->defmgmt) |
| 641 | k->def_multi = true; |
| 642 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 643 | if (tb[NL80211_KEY_IDX]) |
| 644 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 645 | |
| 646 | if (tb[NL80211_KEY_DATA]) { |
| 647 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 648 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 649 | } |
| 650 | |
| 651 | if (tb[NL80211_KEY_SEQ]) { |
| 652 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 653 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 654 | } |
| 655 | |
| 656 | if (tb[NL80211_KEY_CIPHER]) |
| 657 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 658 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 659 | if (tb[NL80211_KEY_TYPE]) { |
| 660 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 661 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 662 | return -EINVAL; |
| 663 | } |
| 664 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 665 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 666 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 667 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 668 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 669 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 670 | if (err) |
| 671 | return err; |
| 672 | |
| 673 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 674 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 675 | } |
| 676 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 681 | { |
| 682 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 683 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 684 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 685 | } |
| 686 | |
| 687 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 688 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 689 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 690 | } |
| 691 | |
| 692 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 693 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 694 | |
| 695 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 696 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 697 | |
| 698 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 699 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 700 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 701 | if (k->def) { |
| 702 | k->def_uni = true; |
| 703 | k->def_multi = true; |
| 704 | } |
| 705 | if (k->defmgmt) |
| 706 | k->def_multi = true; |
| 707 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 708 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 709 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 710 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 714 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 715 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 716 | int err = nla_parse_nested( |
| 717 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 718 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 719 | nl80211_key_default_policy); |
| 720 | if (err) |
| 721 | return err; |
| 722 | |
| 723 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 724 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 725 | } |
| 726 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 731 | { |
| 732 | int err; |
| 733 | |
| 734 | memset(k, 0, sizeof(*k)); |
| 735 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 736 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 737 | |
| 738 | if (info->attrs[NL80211_ATTR_KEY]) |
| 739 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 740 | else |
| 741 | err = nl80211_parse_key_old(info, k); |
| 742 | |
| 743 | if (err) |
| 744 | return err; |
| 745 | |
| 746 | if (k->def && k->defmgmt) |
| 747 | return -EINVAL; |
| 748 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 749 | if (k->defmgmt) { |
| 750 | if (k->def_uni || !k->def_multi) |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 754 | if (k->idx != -1) { |
| 755 | if (k->defmgmt) { |
| 756 | if (k->idx < 4 || k->idx > 5) |
| 757 | return -EINVAL; |
| 758 | } else if (k->def) { |
| 759 | if (k->idx < 0 || k->idx > 3) |
| 760 | return -EINVAL; |
| 761 | } else { |
| 762 | if (k->idx < 0 || k->idx > 5) |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 770 | static struct cfg80211_cached_keys * |
| 771 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 772 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 773 | { |
| 774 | struct key_parse parse; |
| 775 | struct nlattr *key; |
| 776 | struct cfg80211_cached_keys *result; |
| 777 | int rem, err, def = 0; |
| 778 | |
| 779 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 780 | if (!result) |
| 781 | return ERR_PTR(-ENOMEM); |
| 782 | |
| 783 | result->def = -1; |
| 784 | result->defmgmt = -1; |
| 785 | |
| 786 | nla_for_each_nested(key, keys, rem) { |
| 787 | memset(&parse, 0, sizeof(parse)); |
| 788 | parse.idx = -1; |
| 789 | |
| 790 | err = nl80211_parse_key_new(key, &parse); |
| 791 | if (err) |
| 792 | goto error; |
| 793 | err = -EINVAL; |
| 794 | if (!parse.p.key) |
| 795 | goto error; |
| 796 | if (parse.idx < 0 || parse.idx > 4) |
| 797 | goto error; |
| 798 | if (parse.def) { |
| 799 | if (def) |
| 800 | goto error; |
| 801 | def = 1; |
| 802 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 803 | if (!parse.def_uni || !parse.def_multi) |
| 804 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 805 | } else if (parse.defmgmt) |
| 806 | goto error; |
| 807 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 808 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 809 | if (err) |
| 810 | goto error; |
| 811 | result->params[parse.idx].cipher = parse.p.cipher; |
| 812 | result->params[parse.idx].key_len = parse.p.key_len; |
| 813 | result->params[parse.idx].key = result->data[parse.idx]; |
| 814 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 815 | |
| 816 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 817 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 818 | if (no_ht) |
| 819 | *no_ht = true; |
| 820 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | return result; |
| 824 | error: |
| 825 | kfree(result); |
| 826 | return ERR_PTR(err); |
| 827 | } |
| 828 | |
| 829 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 830 | { |
| 831 | ASSERT_WDEV_LOCK(wdev); |
| 832 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 833 | switch (wdev->iftype) { |
| 834 | case NL80211_IFTYPE_AP: |
| 835 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 836 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 837 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 838 | break; |
| 839 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 840 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 841 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 842 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 843 | return -ENOLINK; |
| 844 | break; |
| 845 | default: |
| 846 | return -EINVAL; |
| 847 | } |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 852 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 853 | { |
| 854 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 855 | int i; |
| 856 | |
| 857 | if (!nl_modes) |
| 858 | goto nla_put_failure; |
| 859 | |
| 860 | i = 0; |
| 861 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 862 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 863 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 864 | ifmodes >>= 1; |
| 865 | i++; |
| 866 | } |
| 867 | |
| 868 | nla_nest_end(msg, nl_modes); |
| 869 | return 0; |
| 870 | |
| 871 | nla_put_failure: |
| 872 | return -ENOBUFS; |
| 873 | } |
| 874 | |
| 875 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 876 | struct sk_buff *msg, |
| 877 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 878 | { |
| 879 | struct nlattr *nl_combis; |
| 880 | int i, j; |
| 881 | |
| 882 | nl_combis = nla_nest_start(msg, |
| 883 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 884 | if (!nl_combis) |
| 885 | goto nla_put_failure; |
| 886 | |
| 887 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 888 | const struct ieee80211_iface_combination *c; |
| 889 | struct nlattr *nl_combi, *nl_limits; |
| 890 | |
| 891 | c = &wiphy->iface_combinations[i]; |
| 892 | |
| 893 | nl_combi = nla_nest_start(msg, i + 1); |
| 894 | if (!nl_combi) |
| 895 | goto nla_put_failure; |
| 896 | |
| 897 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 898 | if (!nl_limits) |
| 899 | goto nla_put_failure; |
| 900 | |
| 901 | for (j = 0; j < c->n_limits; j++) { |
| 902 | struct nlattr *nl_limit; |
| 903 | |
| 904 | nl_limit = nla_nest_start(msg, j + 1); |
| 905 | if (!nl_limit) |
| 906 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 907 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 908 | c->limits[j].max)) |
| 909 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 910 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 911 | c->limits[j].types)) |
| 912 | goto nla_put_failure; |
| 913 | nla_nest_end(msg, nl_limit); |
| 914 | } |
| 915 | |
| 916 | nla_nest_end(msg, nl_limits); |
| 917 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 918 | if (c->beacon_int_infra_match && |
| 919 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 920 | goto nla_put_failure; |
| 921 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 922 | c->num_different_channels) || |
| 923 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 924 | c->max_interfaces)) |
| 925 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 926 | if (large && |
| 927 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 928 | c->radar_detect_widths)) |
| 929 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 930 | |
| 931 | nla_nest_end(msg, nl_combi); |
| 932 | } |
| 933 | |
| 934 | nla_nest_end(msg, nl_combis); |
| 935 | |
| 936 | return 0; |
| 937 | nla_put_failure: |
| 938 | return -ENOBUFS; |
| 939 | } |
| 940 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 941 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 942 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 943 | struct sk_buff *msg) |
| 944 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 945 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 946 | struct nlattr *nl_tcp; |
| 947 | |
| 948 | if (!tcp) |
| 949 | return 0; |
| 950 | |
| 951 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 952 | if (!nl_tcp) |
| 953 | return -ENOBUFS; |
| 954 | |
| 955 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 956 | tcp->data_payload_max)) |
| 957 | return -ENOBUFS; |
| 958 | |
| 959 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 960 | tcp->data_payload_max)) |
| 961 | return -ENOBUFS; |
| 962 | |
| 963 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 964 | return -ENOBUFS; |
| 965 | |
| 966 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 967 | sizeof(*tcp->tok), tcp->tok)) |
| 968 | return -ENOBUFS; |
| 969 | |
| 970 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 971 | tcp->data_interval_max)) |
| 972 | return -ENOBUFS; |
| 973 | |
| 974 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 975 | tcp->wake_payload_max)) |
| 976 | return -ENOBUFS; |
| 977 | |
| 978 | nla_nest_end(msg, nl_tcp); |
| 979 | return 0; |
| 980 | } |
| 981 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 983 | struct cfg80211_registered_device *dev, |
| 984 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 985 | { |
| 986 | struct nlattr *nl_wowlan; |
| 987 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 988 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 989 | return 0; |
| 990 | |
| 991 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 992 | if (!nl_wowlan) |
| 993 | return -ENOBUFS; |
| 994 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 995 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 996 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 997 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 998 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 999 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1000 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1001 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1003 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1005 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1007 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1009 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1011 | return -ENOBUFS; |
| 1012 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1013 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1014 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1015 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1016 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1017 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1018 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1019 | }; |
| 1020 | |
| 1021 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1022 | sizeof(pat), &pat)) |
| 1023 | return -ENOBUFS; |
| 1024 | } |
| 1025 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1026 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1027 | return -ENOBUFS; |
| 1028 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1029 | nla_nest_end(msg, nl_wowlan); |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | #endif |
| 1034 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1035 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1036 | struct cfg80211_registered_device *dev) |
| 1037 | { |
| 1038 | struct nl80211_coalesce_rule_support rule; |
| 1039 | |
| 1040 | if (!dev->wiphy.coalesce) |
| 1041 | return 0; |
| 1042 | |
| 1043 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1044 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1045 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1046 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1047 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1048 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1049 | |
| 1050 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1051 | return -ENOBUFS; |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1056 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1057 | struct ieee80211_supported_band *sband) |
| 1058 | { |
| 1059 | struct nlattr *nl_rates, *nl_rate; |
| 1060 | struct ieee80211_rate *rate; |
| 1061 | int i; |
| 1062 | |
| 1063 | /* add HT info */ |
| 1064 | if (sband->ht_cap.ht_supported && |
| 1065 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1066 | sizeof(sband->ht_cap.mcs), |
| 1067 | &sband->ht_cap.mcs) || |
| 1068 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1069 | sband->ht_cap.cap) || |
| 1070 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1071 | sband->ht_cap.ampdu_factor) || |
| 1072 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1073 | sband->ht_cap.ampdu_density))) |
| 1074 | return -ENOBUFS; |
| 1075 | |
| 1076 | /* add VHT info */ |
| 1077 | if (sband->vht_cap.vht_supported && |
| 1078 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1079 | sizeof(sband->vht_cap.vht_mcs), |
| 1080 | &sband->vht_cap.vht_mcs) || |
| 1081 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1082 | sband->vht_cap.cap))) |
| 1083 | return -ENOBUFS; |
| 1084 | |
| 1085 | /* add bitrates */ |
| 1086 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1087 | if (!nl_rates) |
| 1088 | return -ENOBUFS; |
| 1089 | |
| 1090 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1091 | nl_rate = nla_nest_start(msg, i); |
| 1092 | if (!nl_rate) |
| 1093 | return -ENOBUFS; |
| 1094 | |
| 1095 | rate = &sband->bitrates[i]; |
| 1096 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1097 | rate->bitrate)) |
| 1098 | return -ENOBUFS; |
| 1099 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1100 | nla_put_flag(msg, |
| 1101 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1102 | return -ENOBUFS; |
| 1103 | |
| 1104 | nla_nest_end(msg, nl_rate); |
| 1105 | } |
| 1106 | |
| 1107 | nla_nest_end(msg, nl_rates); |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | static int |
| 1113 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1114 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1115 | { |
| 1116 | u16 stypes; |
| 1117 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1118 | enum nl80211_iftype ift; |
| 1119 | int i; |
| 1120 | |
| 1121 | if (!mgmt_stypes) |
| 1122 | return 0; |
| 1123 | |
| 1124 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1125 | if (!nl_ifs) |
| 1126 | return -ENOBUFS; |
| 1127 | |
| 1128 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1129 | nl_ftypes = nla_nest_start(msg, ift); |
| 1130 | if (!nl_ftypes) |
| 1131 | return -ENOBUFS; |
| 1132 | i = 0; |
| 1133 | stypes = mgmt_stypes[ift].tx; |
| 1134 | while (stypes) { |
| 1135 | if ((stypes & 1) && |
| 1136 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1137 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1138 | return -ENOBUFS; |
| 1139 | stypes >>= 1; |
| 1140 | i++; |
| 1141 | } |
| 1142 | nla_nest_end(msg, nl_ftypes); |
| 1143 | } |
| 1144 | |
| 1145 | nla_nest_end(msg, nl_ifs); |
| 1146 | |
| 1147 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1148 | if (!nl_ifs) |
| 1149 | return -ENOBUFS; |
| 1150 | |
| 1151 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1152 | nl_ftypes = nla_nest_start(msg, ift); |
| 1153 | if (!nl_ftypes) |
| 1154 | return -ENOBUFS; |
| 1155 | i = 0; |
| 1156 | stypes = mgmt_stypes[ift].rx; |
| 1157 | while (stypes) { |
| 1158 | if ((stypes & 1) && |
| 1159 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1160 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1161 | return -ENOBUFS; |
| 1162 | stypes >>= 1; |
| 1163 | i++; |
| 1164 | } |
| 1165 | nla_nest_end(msg, nl_ftypes); |
| 1166 | } |
| 1167 | nla_nest_end(msg, nl_ifs); |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1172 | struct nl80211_dump_wiphy_state { |
| 1173 | s64 filter_wiphy; |
| 1174 | long start; |
| 1175 | long split_start, band_start, chan_start; |
| 1176 | bool split; |
| 1177 | }; |
| 1178 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1179 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1180 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1181 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1182 | { |
| 1183 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1184 | struct nlattr *nl_bands, *nl_band; |
| 1185 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1186 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1187 | enum ieee80211_band band; |
| 1188 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1189 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1190 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1191 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1192 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1193 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1194 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1195 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1196 | return -ENOBUFS; |
| 1197 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1198 | if (WARN_ON(!state)) |
| 1199 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1200 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1201 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1202 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1203 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1204 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1205 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1206 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1207 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1208 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1209 | case 0: |
| 1210 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1211 | dev->wiphy.retry_short) || |
| 1212 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1213 | dev->wiphy.retry_long) || |
| 1214 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1215 | dev->wiphy.frag_threshold) || |
| 1216 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1217 | dev->wiphy.rts_threshold) || |
| 1218 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1219 | dev->wiphy.coverage_class) || |
| 1220 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1221 | dev->wiphy.max_scan_ssids) || |
| 1222 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1223 | dev->wiphy.max_sched_scan_ssids) || |
| 1224 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1225 | dev->wiphy.max_scan_ie_len) || |
| 1226 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1227 | dev->wiphy.max_sched_scan_ie_len) || |
| 1228 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1229 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1230 | goto nla_put_failure; |
| 1231 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1232 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1233 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1234 | goto nla_put_failure; |
| 1235 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1236 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1237 | goto nla_put_failure; |
| 1238 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1239 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1240 | goto nla_put_failure; |
| 1241 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1242 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1243 | goto nla_put_failure; |
| 1244 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1245 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1246 | goto nla_put_failure; |
| 1247 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1248 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1249 | goto nla_put_failure; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1250 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1251 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1252 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1253 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1254 | state->split_start++; |
| 1255 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1256 | break; |
| 1257 | case 1: |
| 1258 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1259 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1260 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1261 | goto nla_put_failure; |
| 1262 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1263 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1264 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1265 | goto nla_put_failure; |
| 1266 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1267 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1268 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1269 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1270 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1271 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1272 | dev->wiphy.available_antennas_tx) || |
| 1273 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1274 | dev->wiphy.available_antennas_rx)) |
| 1275 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1276 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1278 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1279 | dev->wiphy.probe_resp_offload)) |
| 1280 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1281 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | if ((dev->wiphy.available_antennas_tx || |
| 1283 | dev->wiphy.available_antennas_rx) && |
| 1284 | dev->ops->get_antenna) { |
| 1285 | u32 tx_ant = 0, rx_ant = 0; |
| 1286 | int res; |
| 1287 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1288 | if (!res) { |
| 1289 | if (nla_put_u32(msg, |
| 1290 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1291 | tx_ant) || |
| 1292 | nla_put_u32(msg, |
| 1293 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1294 | rx_ant)) |
| 1295 | goto nla_put_failure; |
| 1296 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1297 | } |
| 1298 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1299 | state->split_start++; |
| 1300 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1301 | break; |
| 1302 | case 2: |
| 1303 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1304 | dev->wiphy.interface_modes)) |
| 1305 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1306 | state->split_start++; |
| 1307 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1308 | break; |
| 1309 | case 3: |
| 1310 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1311 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1312 | goto nla_put_failure; |
| 1313 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1314 | for (band = state->band_start; |
| 1315 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | struct ieee80211_supported_band *sband; |
| 1317 | |
| 1318 | sband = dev->wiphy.bands[band]; |
| 1319 | |
| 1320 | if (!sband) |
| 1321 | continue; |
| 1322 | |
| 1323 | nl_band = nla_nest_start(msg, band); |
| 1324 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1325 | goto nla_put_failure; |
| 1326 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1327 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | case 0: |
| 1329 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1330 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1331 | state->chan_start++; |
| 1332 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | break; |
| 1334 | default: |
| 1335 | /* add frequencies */ |
| 1336 | nl_freqs = nla_nest_start( |
| 1337 | msg, NL80211_BAND_ATTR_FREQS); |
| 1338 | if (!nl_freqs) |
| 1339 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1340 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1341 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | i < sband->n_channels; |
| 1343 | i++) { |
| 1344 | nl_freq = nla_nest_start(msg, i); |
| 1345 | if (!nl_freq) |
| 1346 | goto nla_put_failure; |
| 1347 | |
| 1348 | chan = &sband->channels[i]; |
| 1349 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1350 | if (nl80211_msg_put_channel( |
| 1351 | msg, chan, |
| 1352 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | goto nla_put_failure; |
| 1354 | |
| 1355 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1356 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | break; |
| 1358 | } |
| 1359 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1360 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1362 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | nla_nest_end(msg, nl_freqs); |
| 1364 | } |
| 1365 | |
| 1366 | nla_nest_end(msg, nl_band); |
| 1367 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1368 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1369 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1370 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1371 | band--; |
| 1372 | break; |
| 1373 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1374 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1376 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1377 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1378 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1379 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1380 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1381 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1382 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1383 | if (state->band_start == 0 && state->chan_start == 0) |
| 1384 | state->split_start++; |
| 1385 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1386 | break; |
| 1387 | case 4: |
| 1388 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1389 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1390 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1391 | |
| 1392 | i = 0; |
| 1393 | #define CMD(op, n) \ |
| 1394 | do { \ |
| 1395 | if (dev->ops->op) { \ |
| 1396 | i++; \ |
| 1397 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1398 | goto nla_put_failure; \ |
| 1399 | } \ |
| 1400 | } while (0) |
| 1401 | |
| 1402 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1403 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1404 | CMD(add_key, NEW_KEY); |
| 1405 | CMD(start_ap, START_AP); |
| 1406 | CMD(add_station, NEW_STATION); |
| 1407 | CMD(add_mpath, NEW_MPATH); |
| 1408 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1409 | CMD(change_bss, SET_BSS); |
| 1410 | CMD(auth, AUTHENTICATE); |
| 1411 | CMD(assoc, ASSOCIATE); |
| 1412 | CMD(deauth, DEAUTHENTICATE); |
| 1413 | CMD(disassoc, DISASSOCIATE); |
| 1414 | CMD(join_ibss, JOIN_IBSS); |
| 1415 | CMD(join_mesh, JOIN_MESH); |
| 1416 | CMD(set_pmksa, SET_PMKSA); |
| 1417 | CMD(del_pmksa, DEL_PMKSA); |
| 1418 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1419 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1420 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1421 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1422 | CMD(mgmt_tx, FRAME); |
| 1423 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1424 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1425 | i++; |
| 1426 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1427 | goto nla_put_failure; |
| 1428 | } |
| 1429 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1430 | dev->ops->join_mesh) { |
| 1431 | i++; |
| 1432 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1433 | goto nla_put_failure; |
| 1434 | } |
| 1435 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1436 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1437 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1438 | CMD(tdls_oper, TDLS_OPER); |
| 1439 | } |
| 1440 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1441 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1442 | CMD(probe_client, PROBE_CLIENT); |
| 1443 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1444 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1445 | i++; |
| 1446 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1447 | goto nla_put_failure; |
| 1448 | } |
| 1449 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1450 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1451 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1452 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1453 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1454 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1455 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1456 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1457 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1458 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1459 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1460 | #endif |
| 1461 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1462 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1463 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1464 | if (dev->ops->connect || dev->ops->auth) { |
| 1465 | i++; |
| 1466 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1467 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1468 | } |
| 1469 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1471 | i++; |
| 1472 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1473 | goto nla_put_failure; |
| 1474 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1475 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1477 | state->split_start++; |
| 1478 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1479 | break; |
| 1480 | case 5: |
| 1481 | if (dev->ops->remain_on_channel && |
| 1482 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1483 | nla_put_u32(msg, |
| 1484 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1485 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1486 | goto nla_put_failure; |
| 1487 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1488 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1489 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1490 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1491 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1492 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1493 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1494 | state->split_start++; |
| 1495 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | break; |
| 1497 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1498 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1499 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1500 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1501 | state->split_start++; |
| 1502 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | break; |
| 1504 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1505 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | #endif |
| 1507 | case 7: |
| 1508 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1509 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1510 | goto nla_put_failure; |
| 1511 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1512 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1513 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1514 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1515 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1516 | state->split_start++; |
| 1517 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | break; |
| 1519 | case 8: |
| 1520 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1521 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1522 | dev->wiphy.ap_sme_capa)) |
| 1523 | goto nla_put_failure; |
| 1524 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1525 | features = dev->wiphy.features; |
| 1526 | /* |
| 1527 | * We can only add the per-channel limit information if the |
| 1528 | * dump is split, otherwise it makes it too big. Therefore |
| 1529 | * only advertise it in that case. |
| 1530 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1531 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1532 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1533 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1534 | goto nla_put_failure; |
| 1535 | |
| 1536 | if (dev->wiphy.ht_capa_mod_mask && |
| 1537 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1538 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1539 | dev->wiphy.ht_capa_mod_mask)) |
| 1540 | goto nla_put_failure; |
| 1541 | |
| 1542 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1543 | dev->wiphy.max_acl_mac_addrs && |
| 1544 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1545 | dev->wiphy.max_acl_mac_addrs)) |
| 1546 | goto nla_put_failure; |
| 1547 | |
| 1548 | /* |
| 1549 | * Any information below this point is only available to |
| 1550 | * applications that can deal with it being split. This |
| 1551 | * helps ensure that newly added capabilities don't break |
| 1552 | * older tools by overrunning their buffers. |
| 1553 | * |
| 1554 | * We still increment split_start so that in the split |
| 1555 | * case we'll continue with more data in the next round, |
| 1556 | * but break unconditionally so unsplit data stops here. |
| 1557 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1558 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1559 | break; |
| 1560 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1561 | if (dev->wiphy.extended_capabilities && |
| 1562 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1563 | dev->wiphy.extended_capabilities_len, |
| 1564 | dev->wiphy.extended_capabilities) || |
| 1565 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1566 | dev->wiphy.extended_capabilities_len, |
| 1567 | dev->wiphy.extended_capabilities_mask))) |
| 1568 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1569 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1570 | if (dev->wiphy.vht_capa_mod_mask && |
| 1571 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1572 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1573 | dev->wiphy.vht_capa_mod_mask)) |
| 1574 | goto nla_put_failure; |
| 1575 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1576 | state->split_start++; |
| 1577 | break; |
| 1578 | case 10: |
| 1579 | if (nl80211_send_coalesce(msg, dev)) |
| 1580 | goto nla_put_failure; |
| 1581 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1583 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1585 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1586 | return genlmsg_end(msg, hdr); |
| 1587 | |
| 1588 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1589 | genlmsg_cancel(msg, hdr); |
| 1590 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1593 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1594 | struct netlink_callback *cb, |
| 1595 | struct nl80211_dump_wiphy_state *state) |
| 1596 | { |
| 1597 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1598 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1599 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1600 | /* ignore parse errors for backward compatibility */ |
| 1601 | if (ret) |
| 1602 | return 0; |
| 1603 | |
| 1604 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1605 | if (tb[NL80211_ATTR_WIPHY]) |
| 1606 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1607 | if (tb[NL80211_ATTR_WDEV]) |
| 1608 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1609 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1610 | struct net_device *netdev; |
| 1611 | struct cfg80211_registered_device *rdev; |
| 1612 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1613 | |
| 1614 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1615 | if (!netdev) |
| 1616 | return -ENODEV; |
| 1617 | if (netdev->ieee80211_ptr) { |
| 1618 | rdev = wiphy_to_dev( |
| 1619 | netdev->ieee80211_ptr->wiphy); |
| 1620 | state->filter_wiphy = rdev->wiphy_idx; |
| 1621 | } |
| 1622 | dev_put(netdev); |
| 1623 | } |
| 1624 | |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1628 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1629 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1630 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1631 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1632 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1633 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1634 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1635 | if (!state) { |
| 1636 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1637 | if (!state) { |
| 1638 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1639 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1640 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1641 | state->filter_wiphy = -1; |
| 1642 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1643 | if (ret) { |
| 1644 | kfree(state); |
| 1645 | rtnl_unlock(); |
| 1646 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1647 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1648 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1649 | } |
| 1650 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1651 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1652 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1653 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1654 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1655 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1656 | if (state->filter_wiphy != -1 && |
| 1657 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | continue; |
| 1659 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1660 | do { |
| 1661 | ret = nl80211_send_wiphy(dev, skb, |
| 1662 | NETLINK_CB(cb->skb).portid, |
| 1663 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1664 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1665 | if (ret < 0) { |
| 1666 | /* |
| 1667 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1668 | * or EMSGSIZE returned), this SKB is still |
| 1669 | * empty (so it's not too big because another |
| 1670 | * wiphy dataset is already in the skb) and |
| 1671 | * we've not tried to adjust the dump allocation |
| 1672 | * yet ... then adjust the alloc size to be |
| 1673 | * bigger, and return 1 but with the empty skb. |
| 1674 | * This results in an empty message being RX'ed |
| 1675 | * in userspace, but that is ignored. |
| 1676 | * |
| 1677 | * We can then retry with the larger buffer. |
| 1678 | */ |
| 1679 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1680 | !skb->len && |
| 1681 | cb->min_dump_alloc < 4096) { |
| 1682 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1683 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1684 | return 1; |
| 1685 | } |
| 1686 | idx--; |
| 1687 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1688 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1689 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1690 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1691 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1692 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1694 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | |
| 1696 | return skb->len; |
| 1697 | } |
| 1698 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1699 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1700 | { |
| 1701 | kfree((void *)cb->args[0]); |
| 1702 | return 0; |
| 1703 | } |
| 1704 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1705 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1706 | { |
| 1707 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1708 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1709 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1710 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1711 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1712 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1713 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1714 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1715 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1716 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1717 | nlmsg_free(msg); |
| 1718 | return -ENOBUFS; |
| 1719 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1720 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1721 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1724 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1725 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1726 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1727 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1728 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1729 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1730 | }; |
| 1731 | |
| 1732 | static int parse_txq_params(struct nlattr *tb[], |
| 1733 | struct ieee80211_txq_params *txq_params) |
| 1734 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1735 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1736 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1737 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1738 | return -EINVAL; |
| 1739 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1740 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1741 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1742 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1743 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1744 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1745 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1746 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1747 | return -EINVAL; |
| 1748 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1749 | return 0; |
| 1750 | } |
| 1751 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1752 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1753 | { |
| 1754 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1755 | * You can only set the channel explicitly for WDS interfaces, |
| 1756 | * all others have their channel managed via their respective |
| 1757 | * "establish a connection" command (connect, join, ...) |
| 1758 | * |
| 1759 | * For AP/GO and mesh mode, the channel can be set with the |
| 1760 | * channel userspace API, but is only stored and passed to the |
| 1761 | * low-level driver when the AP starts or the mesh is joined. |
| 1762 | * This is for backward compatibility, userspace can also give |
| 1763 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1764 | * |
| 1765 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1766 | * whatever else is going on, so they have their own special |
| 1767 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1768 | */ |
| 1769 | return !wdev || |
| 1770 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1771 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1772 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1773 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1776 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1777 | struct genl_info *info, |
| 1778 | struct cfg80211_chan_def *chandef) |
| 1779 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1780 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1781 | |
| 1782 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1783 | return -EINVAL; |
| 1784 | |
| 1785 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1786 | |
| 1787 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1788 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1789 | chandef->center_freq1 = control_freq; |
| 1790 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1791 | |
| 1792 | /* Primary channel not allowed */ |
| 1793 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1794 | return -EINVAL; |
| 1795 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1796 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1797 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1798 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1799 | chantype = nla_get_u32( |
| 1800 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1801 | |
| 1802 | switch (chantype) { |
| 1803 | case NL80211_CHAN_NO_HT: |
| 1804 | case NL80211_CHAN_HT20: |
| 1805 | case NL80211_CHAN_HT40PLUS: |
| 1806 | case NL80211_CHAN_HT40MINUS: |
| 1807 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1808 | chantype); |
| 1809 | break; |
| 1810 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1811 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1812 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1813 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1814 | chandef->width = |
| 1815 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1816 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1817 | chandef->center_freq1 = |
| 1818 | nla_get_u32( |
| 1819 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1820 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1821 | chandef->center_freq2 = |
| 1822 | nla_get_u32( |
| 1823 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1824 | } |
| 1825 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1826 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1827 | return -EINVAL; |
| 1828 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1829 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1830 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1831 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1832 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1833 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1834 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1835 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1838 | return 0; |
| 1839 | } |
| 1840 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1841 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1842 | struct wireless_dev *wdev, |
| 1843 | struct genl_info *info) |
| 1844 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1845 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1846 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1847 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1848 | |
| 1849 | if (wdev) |
| 1850 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1851 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1852 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1853 | return -EOPNOTSUPP; |
| 1854 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1855 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1856 | if (result) |
| 1857 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1858 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1859 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1860 | case NL80211_IFTYPE_AP: |
| 1861 | case NL80211_IFTYPE_P2P_GO: |
| 1862 | if (wdev->beacon_interval) { |
| 1863 | result = -EBUSY; |
| 1864 | break; |
| 1865 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1866 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1867 | result = -EINVAL; |
| 1868 | break; |
| 1869 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1870 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1871 | result = 0; |
| 1872 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1873 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1874 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1875 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1876 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1877 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1878 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1879 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1880 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1881 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1882 | |
| 1883 | return result; |
| 1884 | } |
| 1885 | |
| 1886 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1887 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1888 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1889 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1890 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1891 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | } |
| 1893 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1894 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1895 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1897 | struct net_device *dev = info->user_ptr[1]; |
| 1898 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1899 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1900 | |
| 1901 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1902 | return -EINVAL; |
| 1903 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1904 | if (netif_running(dev)) |
| 1905 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1906 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1907 | if (!rdev->ops->set_wds_peer) |
| 1908 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1909 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1910 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1911 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1912 | |
| 1913 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1914 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1918 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1919 | { |
| 1920 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1921 | struct net_device *netdev = NULL; |
| 1922 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1923 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1924 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1925 | u32 changed; |
| 1926 | u8 retry_short = 0, retry_long = 0; |
| 1927 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1928 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1929 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1930 | ASSERT_RTNL(); |
| 1931 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1932 | /* |
| 1933 | * Try to find the wiphy and netdev. Normally this |
| 1934 | * function shouldn't need the netdev, but this is |
| 1935 | * done for backward compatibility -- previously |
| 1936 | * setting the channel was done per wiphy, but now |
| 1937 | * it is per netdev. Previous userland like hostapd |
| 1938 | * also passed a netdev to set_wiphy, so that it is |
| 1939 | * possible to let that go to the right netdev! |
| 1940 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1941 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1942 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1943 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1944 | |
| 1945 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1946 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1947 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1948 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1949 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1952 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1953 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1954 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1955 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1956 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1957 | wdev = NULL; |
| 1958 | netdev = NULL; |
| 1959 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1960 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1961 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1962 | |
| 1963 | /* |
| 1964 | * end workaround code, by now the rdev is available |
| 1965 | * and locked, and wdev may or may not be NULL. |
| 1966 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1967 | |
| 1968 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1969 | result = cfg80211_dev_rename( |
| 1970 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1971 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1972 | if (result) |
| 1973 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1974 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1975 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1976 | struct ieee80211_txq_params txq_params; |
| 1977 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1978 | |
| 1979 | if (!rdev->ops->set_txq_params) { |
| 1980 | result = -EOPNOTSUPP; |
| 1981 | goto bad_res; |
| 1982 | } |
| 1983 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1984 | if (!netdev) { |
| 1985 | result = -EINVAL; |
| 1986 | goto bad_res; |
| 1987 | } |
| 1988 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1989 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1990 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1991 | result = -EINVAL; |
| 1992 | goto bad_res; |
| 1993 | } |
| 1994 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1995 | if (!netif_running(netdev)) { |
| 1996 | result = -ENETDOWN; |
| 1997 | goto bad_res; |
| 1998 | } |
| 1999 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2000 | nla_for_each_nested(nl_txq_params, |
| 2001 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2002 | rem_txq_params) { |
| 2003 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2004 | nla_data(nl_txq_params), |
| 2005 | nla_len(nl_txq_params), |
| 2006 | txq_params_policy); |
| 2007 | result = parse_txq_params(tb, &txq_params); |
| 2008 | if (result) |
| 2009 | goto bad_res; |
| 2010 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2011 | result = rdev_set_txq_params(rdev, netdev, |
| 2012 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2013 | if (result) |
| 2014 | goto bad_res; |
| 2015 | } |
| 2016 | } |
| 2017 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2018 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2019 | result = __nl80211_set_channel(rdev, |
| 2020 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2021 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2022 | if (result) |
| 2023 | goto bad_res; |
| 2024 | } |
| 2025 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2026 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2027 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2028 | enum nl80211_tx_power_setting type; |
| 2029 | int idx, mbm = 0; |
| 2030 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2031 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2032 | txp_wdev = NULL; |
| 2033 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2034 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2035 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2036 | goto bad_res; |
| 2037 | } |
| 2038 | |
| 2039 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2040 | type = nla_get_u32(info->attrs[idx]); |
| 2041 | |
| 2042 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2043 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2044 | result = -EINVAL; |
| 2045 | goto bad_res; |
| 2046 | } |
| 2047 | |
| 2048 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2049 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2050 | mbm = nla_get_u32(info->attrs[idx]); |
| 2051 | } |
| 2052 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2053 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2054 | if (result) |
| 2055 | goto bad_res; |
| 2056 | } |
| 2057 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2058 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2059 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2060 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2061 | if ((!rdev->wiphy.available_antennas_tx && |
| 2062 | !rdev->wiphy.available_antennas_rx) || |
| 2063 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2064 | result = -EOPNOTSUPP; |
| 2065 | goto bad_res; |
| 2066 | } |
| 2067 | |
| 2068 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2069 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2070 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2071 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2072 | * available antenna masks, except for the "all" mask */ |
| 2073 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2074 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2075 | result = -EINVAL; |
| 2076 | goto bad_res; |
| 2077 | } |
| 2078 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2079 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2080 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2081 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2082 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2083 | if (result) |
| 2084 | goto bad_res; |
| 2085 | } |
| 2086 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2087 | changed = 0; |
| 2088 | |
| 2089 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2090 | retry_short = nla_get_u8( |
| 2091 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2092 | if (retry_short == 0) { |
| 2093 | result = -EINVAL; |
| 2094 | goto bad_res; |
| 2095 | } |
| 2096 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2097 | } |
| 2098 | |
| 2099 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2100 | retry_long = nla_get_u8( |
| 2101 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2102 | if (retry_long == 0) { |
| 2103 | result = -EINVAL; |
| 2104 | goto bad_res; |
| 2105 | } |
| 2106 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2107 | } |
| 2108 | |
| 2109 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2110 | frag_threshold = nla_get_u32( |
| 2111 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2112 | if (frag_threshold < 256) { |
| 2113 | result = -EINVAL; |
| 2114 | goto bad_res; |
| 2115 | } |
| 2116 | if (frag_threshold != (u32) -1) { |
| 2117 | /* |
| 2118 | * Fragments (apart from the last one) are required to |
| 2119 | * have even length. Make the fragmentation code |
| 2120 | * simpler by stripping LSB should someone try to use |
| 2121 | * odd threshold value. |
| 2122 | */ |
| 2123 | frag_threshold &= ~0x1; |
| 2124 | } |
| 2125 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2126 | } |
| 2127 | |
| 2128 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2129 | rts_threshold = nla_get_u32( |
| 2130 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2131 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2132 | } |
| 2133 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2134 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2135 | coverage_class = nla_get_u8( |
| 2136 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2137 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2138 | } |
| 2139 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2140 | if (changed) { |
| 2141 | u8 old_retry_short, old_retry_long; |
| 2142 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2143 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2144 | |
| 2145 | if (!rdev->ops->set_wiphy_params) { |
| 2146 | result = -EOPNOTSUPP; |
| 2147 | goto bad_res; |
| 2148 | } |
| 2149 | |
| 2150 | old_retry_short = rdev->wiphy.retry_short; |
| 2151 | old_retry_long = rdev->wiphy.retry_long; |
| 2152 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2153 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2154 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2155 | |
| 2156 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2157 | rdev->wiphy.retry_short = retry_short; |
| 2158 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2159 | rdev->wiphy.retry_long = retry_long; |
| 2160 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2161 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2162 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2163 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2164 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2165 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2166 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2167 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2168 | if (result) { |
| 2169 | rdev->wiphy.retry_short = old_retry_short; |
| 2170 | rdev->wiphy.retry_long = old_retry_long; |
| 2171 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2172 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2173 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2174 | } |
| 2175 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2176 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2177 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2178 | if (netdev) |
| 2179 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2180 | return result; |
| 2181 | } |
| 2182 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2183 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2184 | { |
| 2185 | return (u64)wdev->identifier | |
| 2186 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2187 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2188 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2189 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2190 | struct cfg80211_chan_def *chandef) |
| 2191 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2192 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2193 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2194 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2195 | chandef->chan->center_freq)) |
| 2196 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2197 | switch (chandef->width) { |
| 2198 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2199 | case NL80211_CHAN_WIDTH_20: |
| 2200 | case NL80211_CHAN_WIDTH_40: |
| 2201 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2202 | cfg80211_get_chandef_type(chandef))) |
| 2203 | return -ENOBUFS; |
| 2204 | break; |
| 2205 | default: |
| 2206 | break; |
| 2207 | } |
| 2208 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2209 | return -ENOBUFS; |
| 2210 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2211 | return -ENOBUFS; |
| 2212 | if (chandef->center_freq2 && |
| 2213 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2214 | return -ENOBUFS; |
| 2215 | return 0; |
| 2216 | } |
| 2217 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2218 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 2219 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2220 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2221 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2222 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2223 | void *hdr; |
| 2224 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2225 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2226 | if (!hdr) |
| 2227 | return -1; |
| 2228 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2229 | if (dev && |
| 2230 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2231 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2232 | goto nla_put_failure; |
| 2233 | |
| 2234 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2235 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2236 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2237 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2238 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2239 | rdev->devlist_generation ^ |
| 2240 | (cfg80211_rdev_list_generation << 2))) |
| 2241 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2242 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2243 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2244 | int ret; |
| 2245 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2246 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2247 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2248 | if (ret == 0) { |
| 2249 | if (nl80211_send_chandef(msg, &chandef)) |
| 2250 | goto nla_put_failure; |
| 2251 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2252 | } |
| 2253 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2254 | if (wdev->ssid_len) { |
| 2255 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2256 | goto nla_put_failure; |
| 2257 | } |
| 2258 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2259 | return genlmsg_end(msg, hdr); |
| 2260 | |
| 2261 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2262 | genlmsg_cancel(msg, hdr); |
| 2263 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2267 | { |
| 2268 | int wp_idx = 0; |
| 2269 | int if_idx = 0; |
| 2270 | int wp_start = cb->args[0]; |
| 2271 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2272 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2273 | struct wireless_dev *wdev; |
| 2274 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2275 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2276 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2277 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2278 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2279 | if (wp_idx < wp_start) { |
| 2280 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2281 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2282 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2283 | if_idx = 0; |
| 2284 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2285 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2286 | if (if_idx < if_start) { |
| 2287 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2288 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2289 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2290 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2291 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2292 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2293 | goto out; |
| 2294 | } |
| 2295 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2296 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2297 | |
| 2298 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2300 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2301 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2302 | |
| 2303 | cb->args[0] = wp_idx; |
| 2304 | cb->args[1] = if_idx; |
| 2305 | |
| 2306 | return skb->len; |
| 2307 | } |
| 2308 | |
| 2309 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2310 | { |
| 2311 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2312 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2313 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2314 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2316 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2317 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2318 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2319 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2320 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2321 | nlmsg_free(msg); |
| 2322 | return -ENOBUFS; |
| 2323 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2324 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2325 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2326 | } |
| 2327 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2328 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2329 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2330 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2331 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2332 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2333 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2334 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2335 | }; |
| 2336 | |
| 2337 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2338 | { |
| 2339 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2340 | int flag; |
| 2341 | |
| 2342 | *mntrflags = 0; |
| 2343 | |
| 2344 | if (!nla) |
| 2345 | return -EINVAL; |
| 2346 | |
| 2347 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2348 | nla, mntr_flags_policy)) |
| 2349 | return -EINVAL; |
| 2350 | |
| 2351 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2352 | if (flags[flag]) |
| 2353 | *mntrflags |= (1<<flag); |
| 2354 | |
| 2355 | return 0; |
| 2356 | } |
| 2357 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2358 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2359 | struct net_device *netdev, u8 use_4addr, |
| 2360 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2361 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2362 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2363 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2364 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2365 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2366 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2367 | |
| 2368 | switch (iftype) { |
| 2369 | case NL80211_IFTYPE_AP_VLAN: |
| 2370 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2371 | return 0; |
| 2372 | break; |
| 2373 | case NL80211_IFTYPE_STATION: |
| 2374 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2375 | return 0; |
| 2376 | break; |
| 2377 | default: |
| 2378 | break; |
| 2379 | } |
| 2380 | |
| 2381 | return -EOPNOTSUPP; |
| 2382 | } |
| 2383 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2384 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2388 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2389 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2391 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2392 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2393 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | memset(¶ms, 0, sizeof(params)); |
| 2395 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2396 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2398 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2399 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2400 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2401 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2402 | if (ntype > NL80211_IFTYPE_MAX) |
| 2403 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2404 | } |
| 2405 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2406 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2407 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2408 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2409 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2410 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2411 | if (netif_running(dev)) |
| 2412 | return -EBUSY; |
| 2413 | |
| 2414 | wdev_lock(wdev); |
| 2415 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2416 | IEEE80211_MAX_MESH_ID_LEN); |
| 2417 | wdev->mesh_id_up_len = |
| 2418 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2419 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2420 | wdev->mesh_id_up_len); |
| 2421 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2424 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2425 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2426 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2427 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2428 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2430 | } else { |
| 2431 | params.use_4addr = -1; |
| 2432 | } |
| 2433 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2434 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2435 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2436 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2437 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2438 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2439 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2441 | |
| 2442 | flags = &_flags; |
| 2443 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2444 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2445 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2446 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2447 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2448 | return -EOPNOTSUPP; |
| 2449 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2450 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2451 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2452 | else |
| 2453 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2454 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2455 | if (!err && params.use_4addr != -1) |
| 2456 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2457 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2458 | return err; |
| 2459 | } |
| 2460 | |
| 2461 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2462 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2464 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2465 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2466 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 | int err; |
| 2468 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2469 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2470 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2471 | memset(¶ms, 0, sizeof(params)); |
| 2472 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2473 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2474 | return -EINVAL; |
| 2475 | |
| 2476 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2477 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2478 | if (type > NL80211_IFTYPE_MAX) |
| 2479 | return -EINVAL; |
| 2480 | } |
| 2481 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2482 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2483 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2484 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2485 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2486 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2487 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2488 | ETH_ALEN); |
| 2489 | if (!is_valid_ether_addr(params.macaddr)) |
| 2490 | return -EADDRNOTAVAIL; |
| 2491 | } |
| 2492 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2493 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2494 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2495 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2496 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2497 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2498 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2499 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2500 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2501 | if (!msg) |
| 2502 | return -ENOMEM; |
| 2503 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2504 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2505 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2506 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2507 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2508 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2509 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2510 | return -EOPNOTSUPP; |
| 2511 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2512 | wdev = rdev_add_virtual_intf(rdev, |
| 2513 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2514 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2515 | if (IS_ERR(wdev)) { |
| 2516 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2517 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2518 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2519 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2520 | switch (type) { |
| 2521 | case NL80211_IFTYPE_MESH_POINT: |
| 2522 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2523 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2524 | wdev_lock(wdev); |
| 2525 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2526 | IEEE80211_MAX_MESH_ID_LEN); |
| 2527 | wdev->mesh_id_up_len = |
| 2528 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2529 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2530 | wdev->mesh_id_up_len); |
| 2531 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2532 | break; |
| 2533 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2534 | /* |
| 2535 | * P2P Device doesn't have a netdev, so doesn't go |
| 2536 | * through the netdev notifier and must be added here |
| 2537 | */ |
| 2538 | mutex_init(&wdev->mtx); |
| 2539 | INIT_LIST_HEAD(&wdev->event_list); |
| 2540 | spin_lock_init(&wdev->event_lock); |
| 2541 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2542 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2543 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2544 | wdev->identifier = ++rdev->wdev_id; |
| 2545 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2546 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2547 | break; |
| 2548 | default: |
| 2549 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2550 | } |
| 2551 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2552 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2553 | rdev, wdev) < 0) { |
| 2554 | nlmsg_free(msg); |
| 2555 | return -ENOBUFS; |
| 2556 | } |
| 2557 | |
| 2558 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2562 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2564 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | if (!rdev->ops->del_virtual_intf) |
| 2567 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2568 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2569 | /* |
| 2570 | * If we remove a wireless device without a netdev then clear |
| 2571 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2572 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2573 | * since the wdev has been freed, unlike with a netdev where |
| 2574 | * we need the dev_put() for the netdev to really be freed. |
| 2575 | */ |
| 2576 | if (!wdev->netdev) |
| 2577 | info->user_ptr[1] = NULL; |
| 2578 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2579 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2580 | } |
| 2581 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2582 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2583 | { |
| 2584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2585 | struct net_device *dev = info->user_ptr[1]; |
| 2586 | u16 noack_map; |
| 2587 | |
| 2588 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2589 | return -EINVAL; |
| 2590 | |
| 2591 | if (!rdev->ops->set_noack_map) |
| 2592 | return -EOPNOTSUPP; |
| 2593 | |
| 2594 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2595 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2596 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2597 | } |
| 2598 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2599 | struct get_key_cookie { |
| 2600 | struct sk_buff *msg; |
| 2601 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2602 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2603 | }; |
| 2604 | |
| 2605 | static void get_key_callback(void *c, struct key_params *params) |
| 2606 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2607 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2608 | struct get_key_cookie *cookie = c; |
| 2609 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2610 | if ((params->key && |
| 2611 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2612 | params->key_len, params->key)) || |
| 2613 | (params->seq && |
| 2614 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2615 | params->seq_len, params->seq)) || |
| 2616 | (params->cipher && |
| 2617 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2618 | params->cipher))) |
| 2619 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2620 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2621 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2622 | if (!key) |
| 2623 | goto nla_put_failure; |
| 2624 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2625 | if ((params->key && |
| 2626 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2627 | params->key_len, params->key)) || |
| 2628 | (params->seq && |
| 2629 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2630 | params->seq_len, params->seq)) || |
| 2631 | (params->cipher && |
| 2632 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2633 | params->cipher))) |
| 2634 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2635 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2636 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2637 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2638 | |
| 2639 | nla_nest_end(cookie->msg, key); |
| 2640 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2641 | return; |
| 2642 | nla_put_failure: |
| 2643 | cookie->error = 1; |
| 2644 | } |
| 2645 | |
| 2646 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2647 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2649 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2650 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2651 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2652 | const u8 *mac_addr = NULL; |
| 2653 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2654 | struct get_key_cookie cookie = { |
| 2655 | .error = 0, |
| 2656 | }; |
| 2657 | void *hdr; |
| 2658 | struct sk_buff *msg; |
| 2659 | |
| 2660 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2661 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2662 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2663 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2664 | return -EINVAL; |
| 2665 | |
| 2666 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2667 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2668 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2669 | pairwise = !!mac_addr; |
| 2670 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2671 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2672 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2673 | return -EINVAL; |
| 2674 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2675 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2676 | return -EINVAL; |
| 2677 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2678 | } |
| 2679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2680 | if (!rdev->ops->get_key) |
| 2681 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2682 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2684 | if (!msg) |
| 2685 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2686 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2687 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2688 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2689 | if (!hdr) |
| 2690 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2691 | |
| 2692 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2693 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2695 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2696 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2697 | goto nla_put_failure; |
| 2698 | if (mac_addr && |
| 2699 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2700 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2701 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2702 | if (pairwise && mac_addr && |
| 2703 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2704 | return -ENOENT; |
| 2705 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2706 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2707 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2708 | |
| 2709 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2710 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2711 | |
| 2712 | if (cookie.error) |
| 2713 | goto nla_put_failure; |
| 2714 | |
| 2715 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2716 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2717 | |
| 2718 | nla_put_failure: |
| 2719 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2720 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2721 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2722 | return err; |
| 2723 | } |
| 2724 | |
| 2725 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2726 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2728 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2729 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2731 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2732 | err = nl80211_parse_key(info, &key); |
| 2733 | if (err) |
| 2734 | return err; |
| 2735 | |
| 2736 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2737 | return -EINVAL; |
| 2738 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2739 | /* only support setting default key */ |
| 2740 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | return -EINVAL; |
| 2742 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2743 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2744 | |
| 2745 | if (key.def) { |
| 2746 | if (!rdev->ops->set_default_key) { |
| 2747 | err = -EOPNOTSUPP; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
| 2751 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2752 | if (err) |
| 2753 | goto out; |
| 2754 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2755 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2756 | key.def_uni, key.def_multi); |
| 2757 | |
| 2758 | if (err) |
| 2759 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2760 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2761 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2762 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2763 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2764 | } else { |
| 2765 | if (key.def_uni || !key.def_multi) { |
| 2766 | err = -EINVAL; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | |
| 2770 | if (!rdev->ops->set_default_mgmt_key) { |
| 2771 | err = -EOPNOTSUPP; |
| 2772 | goto out; |
| 2773 | } |
| 2774 | |
| 2775 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2776 | if (err) |
| 2777 | goto out; |
| 2778 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2779 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2780 | if (err) |
| 2781 | goto out; |
| 2782 | |
| 2783 | #ifdef CONFIG_CFG80211_WEXT |
| 2784 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2785 | #endif |
| 2786 | } |
| 2787 | |
| 2788 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2789 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2791 | return err; |
| 2792 | } |
| 2793 | |
| 2794 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2795 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2797 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2798 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2799 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2800 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2801 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2802 | err = nl80211_parse_key(info, &key); |
| 2803 | if (err) |
| 2804 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2805 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2806 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2807 | return -EINVAL; |
| 2808 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2809 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2810 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2811 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2812 | if (key.type == -1) { |
| 2813 | if (mac_addr) |
| 2814 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2815 | else |
| 2816 | key.type = NL80211_KEYTYPE_GROUP; |
| 2817 | } |
| 2818 | |
| 2819 | /* for now */ |
| 2820 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2821 | key.type != NL80211_KEYTYPE_GROUP) |
| 2822 | return -EINVAL; |
| 2823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2824 | if (!rdev->ops->add_key) |
| 2825 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2826 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2827 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2828 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2829 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2830 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2831 | |
| 2832 | wdev_lock(dev->ieee80211_ptr); |
| 2833 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2834 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2835 | err = rdev_add_key(rdev, dev, key.idx, |
| 2836 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2837 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2838 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2839 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2840 | return err; |
| 2841 | } |
| 2842 | |
| 2843 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2844 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2847 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2848 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2849 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2850 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2851 | err = nl80211_parse_key(info, &key); |
| 2852 | if (err) |
| 2853 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2854 | |
| 2855 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2856 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2857 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2858 | if (key.type == -1) { |
| 2859 | if (mac_addr) |
| 2860 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2861 | else |
| 2862 | key.type = NL80211_KEYTYPE_GROUP; |
| 2863 | } |
| 2864 | |
| 2865 | /* for now */ |
| 2866 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2867 | key.type != NL80211_KEYTYPE_GROUP) |
| 2868 | return -EINVAL; |
| 2869 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2870 | if (!rdev->ops->del_key) |
| 2871 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2872 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2873 | wdev_lock(dev->ieee80211_ptr); |
| 2874 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2875 | |
| 2876 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2877 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2878 | err = -ENOENT; |
| 2879 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2880 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2881 | err = rdev_del_key(rdev, dev, key.idx, |
| 2882 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2883 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2884 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2885 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2886 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2887 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2888 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2889 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2890 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2891 | } |
| 2892 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2893 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2894 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2895 | return err; |
| 2896 | } |
| 2897 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2898 | /* This function returns an error or the number of nested attributes */ |
| 2899 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2900 | { |
| 2901 | struct nlattr *attr; |
| 2902 | int n_entries = 0, tmp; |
| 2903 | |
| 2904 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2905 | if (nla_len(attr) != ETH_ALEN) |
| 2906 | return -EINVAL; |
| 2907 | |
| 2908 | n_entries++; |
| 2909 | } |
| 2910 | |
| 2911 | return n_entries; |
| 2912 | } |
| 2913 | |
| 2914 | /* |
| 2915 | * This function parses ACL information and allocates memory for ACL data. |
| 2916 | * On successful return, the calling function is responsible to free the |
| 2917 | * ACL buffer returned by this function. |
| 2918 | */ |
| 2919 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2920 | struct genl_info *info) |
| 2921 | { |
| 2922 | enum nl80211_acl_policy acl_policy; |
| 2923 | struct nlattr *attr; |
| 2924 | struct cfg80211_acl_data *acl; |
| 2925 | int i = 0, n_entries, tmp; |
| 2926 | |
| 2927 | if (!wiphy->max_acl_mac_addrs) |
| 2928 | return ERR_PTR(-EOPNOTSUPP); |
| 2929 | |
| 2930 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2931 | return ERR_PTR(-EINVAL); |
| 2932 | |
| 2933 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2934 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2935 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2936 | return ERR_PTR(-EINVAL); |
| 2937 | |
| 2938 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2939 | return ERR_PTR(-EINVAL); |
| 2940 | |
| 2941 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2942 | if (n_entries < 0) |
| 2943 | return ERR_PTR(n_entries); |
| 2944 | |
| 2945 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2946 | return ERR_PTR(-ENOTSUPP); |
| 2947 | |
| 2948 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2949 | GFP_KERNEL); |
| 2950 | if (!acl) |
| 2951 | return ERR_PTR(-ENOMEM); |
| 2952 | |
| 2953 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2954 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2955 | i++; |
| 2956 | } |
| 2957 | |
| 2958 | acl->n_acl_entries = n_entries; |
| 2959 | acl->acl_policy = acl_policy; |
| 2960 | |
| 2961 | return acl; |
| 2962 | } |
| 2963 | |
| 2964 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2965 | { |
| 2966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2967 | struct net_device *dev = info->user_ptr[1]; |
| 2968 | struct cfg80211_acl_data *acl; |
| 2969 | int err; |
| 2970 | |
| 2971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2973 | return -EOPNOTSUPP; |
| 2974 | |
| 2975 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2976 | return -EINVAL; |
| 2977 | |
| 2978 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2979 | if (IS_ERR(acl)) |
| 2980 | return PTR_ERR(acl); |
| 2981 | |
| 2982 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2983 | |
| 2984 | kfree(acl); |
| 2985 | |
| 2986 | return err; |
| 2987 | } |
| 2988 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2989 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2990 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2991 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2992 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2993 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2994 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2995 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2996 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2997 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2998 | return -EINVAL; |
| 2999 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3000 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3001 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3002 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3003 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3004 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3005 | if (!bcn->head_len) |
| 3006 | return -EINVAL; |
| 3007 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3008 | } |
| 3009 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3010 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3011 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3012 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3013 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3014 | } |
| 3015 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3016 | if (!haveinfo) |
| 3017 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3018 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3019 | if (attrs[NL80211_ATTR_IE]) { |
| 3020 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3021 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3022 | } |
| 3023 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3024 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3025 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3026 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3027 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3028 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3029 | } |
| 3030 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3031 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3032 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3033 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3034 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3035 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3036 | } |
| 3037 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3038 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3039 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3040 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3041 | } |
| 3042 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3043 | return 0; |
| 3044 | } |
| 3045 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3046 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3047 | struct cfg80211_ap_settings *params) |
| 3048 | { |
| 3049 | struct wireless_dev *wdev; |
| 3050 | bool ret = false; |
| 3051 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3052 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3053 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3054 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3055 | continue; |
| 3056 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3057 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3058 | continue; |
| 3059 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3060 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3061 | ret = true; |
| 3062 | break; |
| 3063 | } |
| 3064 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3065 | return ret; |
| 3066 | } |
| 3067 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3068 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3069 | enum nl80211_auth_type auth_type, |
| 3070 | enum nl80211_commands cmd) |
| 3071 | { |
| 3072 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3073 | return false; |
| 3074 | |
| 3075 | switch (cmd) { |
| 3076 | case NL80211_CMD_AUTHENTICATE: |
| 3077 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3078 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3079 | return false; |
| 3080 | return true; |
| 3081 | case NL80211_CMD_CONNECT: |
| 3082 | case NL80211_CMD_START_AP: |
| 3083 | /* SAE not supported yet */ |
| 3084 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3085 | return false; |
| 3086 | return true; |
| 3087 | default: |
| 3088 | return false; |
| 3089 | } |
| 3090 | } |
| 3091 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3092 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3093 | { |
| 3094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3095 | struct net_device *dev = info->user_ptr[1]; |
| 3096 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3097 | struct cfg80211_ap_settings params; |
| 3098 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3099 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3100 | |
| 3101 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3103 | return -EOPNOTSUPP; |
| 3104 | |
| 3105 | if (!rdev->ops->start_ap) |
| 3106 | return -EOPNOTSUPP; |
| 3107 | |
| 3108 | if (wdev->beacon_interval) |
| 3109 | return -EALREADY; |
| 3110 | |
| 3111 | memset(¶ms, 0, sizeof(params)); |
| 3112 | |
| 3113 | /* these are required for START_AP */ |
| 3114 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3115 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3116 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3117 | return -EINVAL; |
| 3118 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3119 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3120 | if (err) |
| 3121 | return err; |
| 3122 | |
| 3123 | params.beacon_interval = |
| 3124 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3125 | params.dtim_period = |
| 3126 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3127 | |
| 3128 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3129 | if (err) |
| 3130 | return err; |
| 3131 | |
| 3132 | /* |
| 3133 | * In theory, some of these attributes should be required here |
| 3134 | * but since they were not used when the command was originally |
| 3135 | * added, keep them optional for old user space programs to let |
| 3136 | * them continue to work with drivers that do not need the |
| 3137 | * additional information -- drivers must check! |
| 3138 | */ |
| 3139 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3140 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3141 | params.ssid_len = |
| 3142 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3143 | if (params.ssid_len == 0 || |
| 3144 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3145 | return -EINVAL; |
| 3146 | } |
| 3147 | |
| 3148 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3149 | params.hidden_ssid = nla_get_u32( |
| 3150 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3151 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3152 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3153 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3154 | return -EINVAL; |
| 3155 | } |
| 3156 | |
| 3157 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3158 | |
| 3159 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3160 | params.auth_type = nla_get_u32( |
| 3161 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3162 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3163 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3164 | return -EINVAL; |
| 3165 | } else |
| 3166 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3167 | |
| 3168 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3169 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3170 | if (err) |
| 3171 | return err; |
| 3172 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3173 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3174 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3175 | return -EOPNOTSUPP; |
| 3176 | params.inactivity_timeout = nla_get_u16( |
| 3177 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3178 | } |
| 3179 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3180 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3182 | return -EINVAL; |
| 3183 | params.p2p_ctwindow = |
| 3184 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3185 | if (params.p2p_ctwindow > 127) |
| 3186 | return -EINVAL; |
| 3187 | if (params.p2p_ctwindow != 0 && |
| 3188 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3189 | return -EINVAL; |
| 3190 | } |
| 3191 | |
| 3192 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3193 | u8 tmp; |
| 3194 | |
| 3195 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3196 | return -EINVAL; |
| 3197 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3198 | if (tmp > 1) |
| 3199 | return -EINVAL; |
| 3200 | params.p2p_opp_ps = tmp; |
| 3201 | if (params.p2p_opp_ps != 0 && |
| 3202 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3203 | return -EINVAL; |
| 3204 | } |
| 3205 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3206 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3207 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3208 | if (err) |
| 3209 | return err; |
| 3210 | } else if (wdev->preset_chandef.chan) { |
| 3211 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3212 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3213 | return -EINVAL; |
| 3214 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3215 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3216 | return -EINVAL; |
| 3217 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3218 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3219 | if (err < 0) |
| 3220 | return err; |
| 3221 | if (err) { |
| 3222 | radar_detect_width = BIT(params.chandef.width); |
| 3223 | params.radar_required = true; |
| 3224 | } |
| 3225 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3226 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3227 | params.chandef.chan, |
| 3228 | CHAN_MODE_SHARED, |
| 3229 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3230 | if (err) |
| 3231 | return err; |
| 3232 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3233 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3234 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3235 | if (IS_ERR(params.acl)) |
| 3236 | return PTR_ERR(params.acl); |
| 3237 | } |
| 3238 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3239 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3240 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3241 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3242 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3243 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3244 | wdev->ssid_len = params.ssid_len; |
| 3245 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3246 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3247 | |
| 3248 | kfree(params.acl); |
| 3249 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3250 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3251 | } |
| 3252 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3253 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3254 | { |
| 3255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3256 | struct net_device *dev = info->user_ptr[1]; |
| 3257 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3258 | struct cfg80211_beacon_data params; |
| 3259 | int err; |
| 3260 | |
| 3261 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3262 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3263 | return -EOPNOTSUPP; |
| 3264 | |
| 3265 | if (!rdev->ops->change_beacon) |
| 3266 | return -EOPNOTSUPP; |
| 3267 | |
| 3268 | if (!wdev->beacon_interval) |
| 3269 | return -EINVAL; |
| 3270 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3271 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3272 | if (err) |
| 3273 | return err; |
| 3274 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3275 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3281 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3282 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3283 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3284 | } |
| 3285 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3286 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3287 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3288 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3289 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3290 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3291 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3292 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3293 | }; |
| 3294 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3295 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3296 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3297 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3298 | { |
| 3299 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3300 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3301 | int flag; |
| 3302 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3303 | /* |
| 3304 | * Try parsing the new attribute first so userspace |
| 3305 | * can specify both for older kernels. |
| 3306 | */ |
| 3307 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3308 | if (nla) { |
| 3309 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3310 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3311 | sta_flags = nla_data(nla); |
| 3312 | params->sta_flags_mask = sta_flags->mask; |
| 3313 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3314 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3315 | if ((params->sta_flags_mask | |
| 3316 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3317 | return -EINVAL; |
| 3318 | return 0; |
| 3319 | } |
| 3320 | |
| 3321 | /* if present, parse the old attribute */ |
| 3322 | |
| 3323 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3324 | if (!nla) |
| 3325 | return 0; |
| 3326 | |
| 3327 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3328 | nla, sta_flags_policy)) |
| 3329 | return -EINVAL; |
| 3330 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3331 | /* |
| 3332 | * Only allow certain flags for interface types so that |
| 3333 | * other attributes are silently ignored. Remember that |
| 3334 | * this is backward compatibility code with old userspace |
| 3335 | * and shouldn't be hit in other cases anyway. |
| 3336 | */ |
| 3337 | switch (iftype) { |
| 3338 | case NL80211_IFTYPE_AP: |
| 3339 | case NL80211_IFTYPE_AP_VLAN: |
| 3340 | case NL80211_IFTYPE_P2P_GO: |
| 3341 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3342 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3343 | BIT(NL80211_STA_FLAG_WME) | |
| 3344 | BIT(NL80211_STA_FLAG_MFP); |
| 3345 | break; |
| 3346 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3347 | case NL80211_IFTYPE_STATION: |
| 3348 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3349 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3350 | break; |
| 3351 | case NL80211_IFTYPE_MESH_POINT: |
| 3352 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3353 | BIT(NL80211_STA_FLAG_MFP) | |
| 3354 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3355 | default: |
| 3356 | return -EINVAL; |
| 3357 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3358 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3359 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3360 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3361 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3362 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3363 | /* no longer support new API additions in old API */ |
| 3364 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3365 | return -EINVAL; |
| 3366 | } |
| 3367 | } |
| 3368 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3369 | return 0; |
| 3370 | } |
| 3371 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3372 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3373 | int attr) |
| 3374 | { |
| 3375 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3376 | u32 bitrate; |
| 3377 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3378 | |
| 3379 | rate = nla_nest_start(msg, attr); |
| 3380 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3381 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3382 | |
| 3383 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3384 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3385 | /* report 16-bit bitrate only if we can */ |
| 3386 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3387 | if (bitrate > 0 && |
| 3388 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3389 | return false; |
| 3390 | if (bitrate_compat > 0 && |
| 3391 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3392 | return false; |
| 3393 | |
| 3394 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3395 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3396 | return false; |
| 3397 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3398 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3399 | return false; |
| 3400 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3401 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3402 | return false; |
| 3403 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3404 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3405 | return false; |
| 3406 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3407 | return false; |
| 3408 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3409 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3410 | return false; |
| 3411 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3412 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3413 | return false; |
| 3414 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3415 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3416 | return false; |
| 3417 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3418 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3419 | return false; |
| 3420 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3421 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3422 | return false; |
| 3423 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3424 | |
| 3425 | nla_nest_end(msg, rate); |
| 3426 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3427 | } |
| 3428 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3429 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3430 | int id) |
| 3431 | { |
| 3432 | void *attr; |
| 3433 | int i = 0; |
| 3434 | |
| 3435 | if (!mask) |
| 3436 | return true; |
| 3437 | |
| 3438 | attr = nla_nest_start(msg, id); |
| 3439 | if (!attr) |
| 3440 | return false; |
| 3441 | |
| 3442 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3443 | if (!(mask & BIT(i))) |
| 3444 | continue; |
| 3445 | |
| 3446 | if (nla_put_u8(msg, i, signal[i])) |
| 3447 | return false; |
| 3448 | } |
| 3449 | |
| 3450 | nla_nest_end(msg, attr); |
| 3451 | |
| 3452 | return true; |
| 3453 | } |
| 3454 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3455 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3456 | int flags, |
| 3457 | struct cfg80211_registered_device *rdev, |
| 3458 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3459 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3460 | { |
| 3461 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3462 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3463 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3464 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3465 | if (!hdr) |
| 3466 | return -1; |
| 3467 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3468 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3469 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3470 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3471 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3472 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3473 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3474 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3475 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3476 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3477 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3478 | sinfo->connected_time)) |
| 3479 | goto nla_put_failure; |
| 3480 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3481 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3482 | sinfo->inactive_time)) |
| 3483 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3484 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3485 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3486 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3487 | (u32)sinfo->rx_bytes)) |
| 3488 | goto nla_put_failure; |
| 3489 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3490 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3491 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3492 | (u32)sinfo->tx_bytes)) |
| 3493 | goto nla_put_failure; |
| 3494 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3495 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3496 | sinfo->rx_bytes)) |
| 3497 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3498 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3499 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3500 | sinfo->tx_bytes)) |
| 3501 | goto nla_put_failure; |
| 3502 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3503 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3504 | goto nla_put_failure; |
| 3505 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3506 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3507 | goto nla_put_failure; |
| 3508 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3509 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3510 | sinfo->plink_state)) |
| 3511 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3512 | switch (rdev->wiphy.signal_type) { |
| 3513 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3514 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3515 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3516 | sinfo->signal)) |
| 3517 | goto nla_put_failure; |
| 3518 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3519 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3520 | sinfo->signal_avg)) |
| 3521 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3522 | break; |
| 3523 | default: |
| 3524 | break; |
| 3525 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3526 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3527 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3528 | sinfo->chain_signal, |
| 3529 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3530 | goto nla_put_failure; |
| 3531 | } |
| 3532 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3533 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3534 | sinfo->chain_signal_avg, |
| 3535 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3536 | goto nla_put_failure; |
| 3537 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3538 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3539 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3540 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3541 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3542 | } |
| 3543 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3544 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3545 | NL80211_STA_INFO_RX_BITRATE)) |
| 3546 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3547 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3548 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3549 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3550 | sinfo->rx_packets)) |
| 3551 | goto nla_put_failure; |
| 3552 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3553 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3554 | sinfo->tx_packets)) |
| 3555 | goto nla_put_failure; |
| 3556 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3557 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3558 | sinfo->tx_retries)) |
| 3559 | goto nla_put_failure; |
| 3560 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3561 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3562 | sinfo->tx_failed)) |
| 3563 | goto nla_put_failure; |
| 3564 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3565 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3566 | sinfo->beacon_loss_count)) |
| 3567 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3568 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3569 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3570 | sinfo->local_pm)) |
| 3571 | goto nla_put_failure; |
| 3572 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3573 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3574 | sinfo->peer_pm)) |
| 3575 | goto nla_put_failure; |
| 3576 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3577 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3578 | sinfo->nonpeer_pm)) |
| 3579 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3580 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3581 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3582 | if (!bss_param) |
| 3583 | goto nla_put_failure; |
| 3584 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3585 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3586 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3587 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3588 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3589 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3590 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3591 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3592 | sinfo->bss_param.dtim_period) || |
| 3593 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3594 | sinfo->bss_param.beacon_interval)) |
| 3595 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3596 | |
| 3597 | nla_nest_end(msg, bss_param); |
| 3598 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3599 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3600 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3601 | sizeof(struct nl80211_sta_flag_update), |
| 3602 | &sinfo->sta_flags)) |
| 3603 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3604 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3605 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3606 | sinfo->t_offset)) |
| 3607 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3608 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3609 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3610 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3611 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3612 | sinfo->assoc_req_ies)) |
| 3613 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3614 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3615 | return genlmsg_end(msg, hdr); |
| 3616 | |
| 3617 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3618 | genlmsg_cancel(msg, hdr); |
| 3619 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3622 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3623 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3624 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3625 | struct station_info sinfo; |
| 3626 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3627 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3628 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3629 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3630 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3631 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3632 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3633 | if (err) |
| 3634 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3635 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3636 | if (!wdev->netdev) { |
| 3637 | err = -EINVAL; |
| 3638 | goto out_err; |
| 3639 | } |
| 3640 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3641 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3642 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3643 | goto out_err; |
| 3644 | } |
| 3645 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3646 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3647 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3648 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3649 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3650 | if (err == -ENOENT) |
| 3651 | break; |
| 3652 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3653 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3654 | |
| 3655 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3656 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3657 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3658 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3659 | &sinfo) < 0) |
| 3660 | goto out; |
| 3661 | |
| 3662 | sta_idx++; |
| 3663 | } |
| 3664 | |
| 3665 | |
| 3666 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3667 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3668 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3669 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3670 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3671 | |
| 3672 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3673 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3674 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3675 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3676 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3678 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3679 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3680 | struct sk_buff *msg; |
| 3681 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3682 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3683 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3684 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3685 | |
| 3686 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3687 | return -EINVAL; |
| 3688 | |
| 3689 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3691 | if (!rdev->ops->get_station) |
| 3692 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3693 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3694 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3695 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3696 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3697 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3699 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3700 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3701 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3702 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3703 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3704 | nlmsg_free(msg); |
| 3705 | return -ENOBUFS; |
| 3706 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3708 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3709 | } |
| 3710 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3711 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3712 | struct station_parameters *params, |
| 3713 | enum cfg80211_station_type statype) |
| 3714 | { |
| 3715 | if (params->listen_interval != -1) |
| 3716 | return -EINVAL; |
| 3717 | if (params->aid) |
| 3718 | return -EINVAL; |
| 3719 | |
| 3720 | /* When you run into this, adjust the code below for the new flag */ |
| 3721 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3722 | |
| 3723 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3724 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3725 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3726 | /* |
| 3727 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3728 | * code doesn't have the bug of including TDLS in the |
| 3729 | * mask everywhere. |
| 3730 | */ |
| 3731 | if (params->sta_flags_mask & |
| 3732 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3733 | BIT(NL80211_STA_FLAG_MFP) | |
| 3734 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3735 | return -EINVAL; |
| 3736 | break; |
| 3737 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3738 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3739 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3740 | return -EINVAL; |
| 3741 | /* ignore since it can't change */ |
| 3742 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3743 | break; |
| 3744 | default: |
| 3745 | /* disallow mesh-specific things */ |
| 3746 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3747 | return -EINVAL; |
| 3748 | if (params->local_pm) |
| 3749 | return -EINVAL; |
| 3750 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3751 | return -EINVAL; |
| 3752 | } |
| 3753 | |
| 3754 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3755 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3756 | /* TDLS can't be set, ... */ |
| 3757 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3758 | return -EINVAL; |
| 3759 | /* |
| 3760 | * ... but don't bother the driver with it. This works around |
| 3761 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3762 | * TLDS_PEER flag in the mask even for AP mode. |
| 3763 | */ |
| 3764 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3765 | } |
| 3766 | |
| 3767 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3768 | /* reject other things that can't change */ |
| 3769 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3770 | return -EINVAL; |
| 3771 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3772 | return -EINVAL; |
| 3773 | if (params->supported_rates) |
| 3774 | return -EINVAL; |
| 3775 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3776 | return -EINVAL; |
| 3777 | } |
| 3778 | |
| 3779 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3780 | if (params->vlan) |
| 3781 | return -EINVAL; |
| 3782 | } |
| 3783 | |
| 3784 | switch (statype) { |
| 3785 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3786 | /* Use this only for authorizing/unauthorizing a station */ |
| 3787 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3788 | return -EOPNOTSUPP; |
| 3789 | break; |
| 3790 | case CFG80211_STA_AP_CLIENT: |
| 3791 | /* accept only the listed bits */ |
| 3792 | if (params->sta_flags_mask & |
| 3793 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3794 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3795 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3796 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3797 | BIT(NL80211_STA_FLAG_WME) | |
| 3798 | BIT(NL80211_STA_FLAG_MFP))) |
| 3799 | return -EINVAL; |
| 3800 | |
| 3801 | /* but authenticated/associated only if driver handles it */ |
| 3802 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3803 | params->sta_flags_mask & |
| 3804 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3805 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3806 | return -EINVAL; |
| 3807 | break; |
| 3808 | case CFG80211_STA_IBSS: |
| 3809 | case CFG80211_STA_AP_STA: |
| 3810 | /* reject any changes other than AUTHORIZED */ |
| 3811 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3812 | return -EINVAL; |
| 3813 | break; |
| 3814 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3815 | /* reject any changes other than AUTHORIZED or WME */ |
| 3816 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3817 | BIT(NL80211_STA_FLAG_WME))) |
| 3818 | return -EINVAL; |
| 3819 | /* force (at least) rates when authorizing */ |
| 3820 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3821 | !params->supported_rates) |
| 3822 | return -EINVAL; |
| 3823 | break; |
| 3824 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3825 | /* reject any changes */ |
| 3826 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3827 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3828 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3829 | return -EINVAL; |
| 3830 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3831 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3832 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3833 | return -EINVAL; |
| 3834 | break; |
| 3835 | } |
| 3836 | |
| 3837 | return 0; |
| 3838 | } |
| 3839 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3840 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3841 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3842 | * Get vlan interface making sure it is running and on the right wiphy. |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3843 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3844 | static struct net_device *get_vlan(struct genl_info *info, |
| 3845 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3846 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3847 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3848 | struct net_device *v; |
| 3849 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3850 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3851 | if (!vlanattr) |
| 3852 | return NULL; |
| 3853 | |
| 3854 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3855 | if (!v) |
| 3856 | return ERR_PTR(-ENODEV); |
| 3857 | |
| 3858 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3859 | ret = -EINVAL; |
| 3860 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3861 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3862 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3863 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3864 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3865 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3866 | ret = -EINVAL; |
| 3867 | goto error; |
| 3868 | } |
| 3869 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3870 | if (!netif_running(v)) { |
| 3871 | ret = -ENETDOWN; |
| 3872 | goto error; |
| 3873 | } |
| 3874 | |
| 3875 | return v; |
| 3876 | error: |
| 3877 | dev_put(v); |
| 3878 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3879 | } |
| 3880 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3881 | static struct nla_policy |
| 3882 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3883 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3884 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3885 | }; |
| 3886 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3887 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3888 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3889 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3890 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3891 | struct nlattr *nla; |
| 3892 | int err; |
| 3893 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3894 | /* parse WME attributes if present */ |
| 3895 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3896 | return 0; |
| 3897 | |
| 3898 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3899 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3900 | nl80211_sta_wme_policy); |
| 3901 | if (err) |
| 3902 | return err; |
| 3903 | |
| 3904 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3905 | params->uapsd_queues = nla_get_u8( |
| 3906 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3907 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3908 | return -EINVAL; |
| 3909 | |
| 3910 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3911 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3912 | |
| 3913 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3914 | return -EINVAL; |
| 3915 | |
| 3916 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3917 | |
| 3918 | return 0; |
| 3919 | } |
| 3920 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3921 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3922 | struct station_parameters *params) |
| 3923 | { |
| 3924 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3925 | params->supported_channels = |
| 3926 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3927 | params->supported_channels_len = |
| 3928 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3929 | /* |
| 3930 | * Need to include at least one (first channel, number of |
| 3931 | * channels) tuple for each subband, and must have proper |
| 3932 | * tuples for the rest of the data as well. |
| 3933 | */ |
| 3934 | if (params->supported_channels_len < 2) |
| 3935 | return -EINVAL; |
| 3936 | if (params->supported_channels_len % 2) |
| 3937 | return -EINVAL; |
| 3938 | } |
| 3939 | |
| 3940 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3941 | params->supported_oper_classes = |
| 3942 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3943 | params->supported_oper_classes_len = |
| 3944 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3945 | /* |
| 3946 | * The value of the Length field of the Supported Operating |
| 3947 | * Classes element is between 2 and 253. |
| 3948 | */ |
| 3949 | if (params->supported_oper_classes_len < 2 || |
| 3950 | params->supported_oper_classes_len > 253) |
| 3951 | return -EINVAL; |
| 3952 | } |
| 3953 | return 0; |
| 3954 | } |
| 3955 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3956 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3957 | struct station_parameters *params) |
| 3958 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3959 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3960 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3961 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3962 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3963 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3964 | params->ht_capa = |
| 3965 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3966 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3967 | params->vht_capa = |
| 3968 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3969 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3970 | err = nl80211_parse_sta_channel_info(info, params); |
| 3971 | if (err) |
| 3972 | return err; |
| 3973 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3974 | return nl80211_parse_sta_wme(info, params); |
| 3975 | } |
| 3976 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3977 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3978 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3980 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3981 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3982 | u8 *mac_addr; |
| 3983 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3984 | |
| 3985 | memset(¶ms, 0, sizeof(params)); |
| 3986 | |
| 3987 | params.listen_interval = -1; |
| 3988 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3989 | if (!rdev->ops->change_station) |
| 3990 | return -EOPNOTSUPP; |
| 3991 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3992 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3993 | return -EINVAL; |
| 3994 | |
| 3995 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3996 | return -EINVAL; |
| 3997 | |
| 3998 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3999 | |
| 4000 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4001 | params.supported_rates = |
| 4002 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4003 | params.supported_rates_len = |
| 4004 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4005 | } |
| 4006 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4007 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4008 | params.capability = |
| 4009 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4010 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4011 | } |
| 4012 | |
| 4013 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4014 | params.ext_capab = |
| 4015 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4016 | params.ext_capab_len = |
| 4017 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4018 | } |
| 4019 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4020 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4021 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4022 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4023 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4024 | return -EINVAL; |
| 4025 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4026 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4027 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4028 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4029 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4030 | return -EINVAL; |
| 4031 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4032 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4033 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4034 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4035 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4036 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4037 | return -EINVAL; |
| 4038 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4039 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4040 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4041 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4042 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4043 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4044 | |
| 4045 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4046 | pm > NL80211_MESH_POWER_MAX) |
| 4047 | return -EINVAL; |
| 4048 | |
| 4049 | params.local_pm = pm; |
| 4050 | } |
| 4051 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4052 | /* Include parameters for TDLS peer (will check later) */ |
| 4053 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4054 | if (err) |
| 4055 | return err; |
| 4056 | |
| 4057 | params.vlan = get_vlan(info, rdev); |
| 4058 | if (IS_ERR(params.vlan)) |
| 4059 | return PTR_ERR(params.vlan); |
| 4060 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4061 | switch (dev->ieee80211_ptr->iftype) { |
| 4062 | case NL80211_IFTYPE_AP: |
| 4063 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4064 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4065 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4066 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4067 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4068 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4069 | break; |
| 4070 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4071 | err = -EOPNOTSUPP; |
| 4072 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4073 | } |
| 4074 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4075 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4076 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4077 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4078 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4079 | if (params.vlan) |
| 4080 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4081 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4082 | return err; |
| 4083 | } |
| 4084 | |
| 4085 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4086 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4088 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4089 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4090 | struct station_parameters params; |
| 4091 | u8 *mac_addr = NULL; |
| 4092 | |
| 4093 | memset(¶ms, 0, sizeof(params)); |
| 4094 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4095 | if (!rdev->ops->add_station) |
| 4096 | return -EOPNOTSUPP; |
| 4097 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4098 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4099 | return -EINVAL; |
| 4100 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4101 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4102 | return -EINVAL; |
| 4103 | |
| 4104 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4105 | return -EINVAL; |
| 4106 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4107 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4108 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4109 | return -EINVAL; |
| 4110 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4111 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4112 | params.supported_rates = |
| 4113 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4114 | params.supported_rates_len = |
| 4115 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4116 | params.listen_interval = |
| 4117 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4118 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4119 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4120 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4121 | else |
| 4122 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4123 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4124 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4125 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4126 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4127 | params.capability = |
| 4128 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4129 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4130 | } |
| 4131 | |
| 4132 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4133 | params.ext_capab = |
| 4134 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4135 | params.ext_capab_len = |
| 4136 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4137 | } |
| 4138 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4139 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4140 | params.ht_capa = |
| 4141 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4142 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4143 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4144 | params.vht_capa = |
| 4145 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4146 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4147 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4148 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4149 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4150 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4151 | return -EINVAL; |
| 4152 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4153 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4154 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4155 | if (err) |
| 4156 | return err; |
| 4157 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4158 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4159 | if (err) |
| 4160 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4161 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4162 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4163 | return -EINVAL; |
| 4164 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4165 | /* When you run into this, adjust the code below for the new flag */ |
| 4166 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4167 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4168 | switch (dev->ieee80211_ptr->iftype) { |
| 4169 | case NL80211_IFTYPE_AP: |
| 4170 | case NL80211_IFTYPE_AP_VLAN: |
| 4171 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4172 | /* ignore WME attributes if iface/sta is not capable */ |
| 4173 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4174 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4175 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4176 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4177 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4178 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4179 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4180 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4181 | /* but don't bother the driver with it */ |
| 4182 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4183 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4184 | /* allow authenticated/associated only if driver handles it */ |
| 4185 | if (!(rdev->wiphy.features & |
| 4186 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4187 | params.sta_flags_mask & |
| 4188 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4189 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4190 | return -EINVAL; |
| 4191 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4192 | /* must be last in here for error handling */ |
| 4193 | params.vlan = get_vlan(info, rdev); |
| 4194 | if (IS_ERR(params.vlan)) |
| 4195 | return PTR_ERR(params.vlan); |
| 4196 | break; |
| 4197 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4198 | /* ignore uAPSD data */ |
| 4199 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4200 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4201 | /* associated is disallowed */ |
| 4202 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4203 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4204 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4205 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4206 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4207 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4208 | break; |
| 4209 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4210 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4211 | /* ignore uAPSD data */ |
| 4212 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4213 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4214 | /* these are disallowed */ |
| 4215 | if (params.sta_flags_mask & |
| 4216 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4217 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4218 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4219 | /* Only TDLS peers can be added */ |
| 4220 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4221 | return -EINVAL; |
| 4222 | /* Can only add if TDLS ... */ |
| 4223 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4224 | return -EOPNOTSUPP; |
| 4225 | /* ... with external setup is supported */ |
| 4226 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4227 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4228 | /* |
| 4229 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4230 | * as authorized, but it shouldn't yet be. |
| 4231 | */ |
| 4232 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4233 | break; |
| 4234 | default: |
| 4235 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4236 | } |
| 4237 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4238 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4239 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4240 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4241 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4242 | if (params.vlan) |
| 4243 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4244 | return err; |
| 4245 | } |
| 4246 | |
| 4247 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4248 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4249 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4250 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4251 | u8 *mac_addr = NULL; |
| 4252 | |
| 4253 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4254 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4255 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4256 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4257 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4258 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4259 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4260 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4261 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4262 | if (!rdev->ops->del_station) |
| 4263 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4264 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4265 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4268 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4269 | int flags, struct net_device *dev, |
| 4270 | u8 *dst, u8 *next_hop, |
| 4271 | struct mpath_info *pinfo) |
| 4272 | { |
| 4273 | void *hdr; |
| 4274 | struct nlattr *pinfoattr; |
| 4275 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4276 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4277 | if (!hdr) |
| 4278 | return -1; |
| 4279 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4280 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4281 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4282 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4283 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4284 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4285 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4286 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4287 | if (!pinfoattr) |
| 4288 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4289 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4290 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4291 | pinfo->frame_qlen)) |
| 4292 | goto nla_put_failure; |
| 4293 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4294 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4295 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4296 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4297 | pinfo->metric)) || |
| 4298 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4299 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4300 | pinfo->exptime)) || |
| 4301 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4302 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4303 | pinfo->flags)) || |
| 4304 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4305 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4306 | pinfo->discovery_timeout)) || |
| 4307 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4308 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4309 | pinfo->discovery_retries))) |
| 4310 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4311 | |
| 4312 | nla_nest_end(msg, pinfoattr); |
| 4313 | |
| 4314 | return genlmsg_end(msg, hdr); |
| 4315 | |
| 4316 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4317 | genlmsg_cancel(msg, hdr); |
| 4318 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4322 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4323 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4324 | struct mpath_info pinfo; |
| 4325 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4326 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4327 | u8 dst[ETH_ALEN]; |
| 4328 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4329 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4330 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4331 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4332 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4333 | if (err) |
| 4334 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4335 | |
| 4336 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4337 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4338 | goto out_err; |
| 4339 | } |
| 4340 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4341 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4342 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4343 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4344 | } |
| 4345 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4346 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4347 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4348 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4349 | if (err == -ENOENT) |
| 4350 | break; |
| 4351 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4352 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4353 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4354 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4355 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4356 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4357 | &pinfo) < 0) |
| 4358 | goto out; |
| 4359 | |
| 4360 | path_idx++; |
| 4361 | } |
| 4362 | |
| 4363 | |
| 4364 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4365 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4366 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4367 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4368 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4369 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4373 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4375 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4376 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4377 | struct mpath_info pinfo; |
| 4378 | struct sk_buff *msg; |
| 4379 | u8 *dst = NULL; |
| 4380 | u8 next_hop[ETH_ALEN]; |
| 4381 | |
| 4382 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4383 | |
| 4384 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4385 | return -EINVAL; |
| 4386 | |
| 4387 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4389 | if (!rdev->ops->get_mpath) |
| 4390 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4392 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4393 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4394 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4395 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4396 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4398 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4399 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4400 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4401 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4402 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4403 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4404 | dev, dst, next_hop, &pinfo) < 0) { |
| 4405 | nlmsg_free(msg); |
| 4406 | return -ENOBUFS; |
| 4407 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4408 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4409 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4413 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4415 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4416 | u8 *dst = NULL; |
| 4417 | u8 *next_hop = NULL; |
| 4418 | |
| 4419 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4420 | return -EINVAL; |
| 4421 | |
| 4422 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4423 | return -EINVAL; |
| 4424 | |
| 4425 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4426 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4427 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4428 | if (!rdev->ops->change_mpath) |
| 4429 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4430 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4432 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4433 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4434 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4435 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4436 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4437 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4438 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4440 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4441 | u8 *dst = NULL; |
| 4442 | u8 *next_hop = NULL; |
| 4443 | |
| 4444 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4445 | return -EINVAL; |
| 4446 | |
| 4447 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4448 | return -EINVAL; |
| 4449 | |
| 4450 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4451 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4452 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4453 | if (!rdev->ops->add_mpath) |
| 4454 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4455 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4456 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4457 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4458 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4459 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4463 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4465 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4466 | u8 *dst = NULL; |
| 4467 | |
| 4468 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4469 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4470 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4471 | if (!rdev->ops->del_mpath) |
| 4472 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4473 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4474 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4475 | } |
| 4476 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4477 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4478 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4480 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4481 | struct bss_parameters params; |
| 4482 | |
| 4483 | memset(¶ms, 0, sizeof(params)); |
| 4484 | /* default to not changing parameters */ |
| 4485 | params.use_cts_prot = -1; |
| 4486 | params.use_short_preamble = -1; |
| 4487 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4488 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4489 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4490 | params.p2p_ctwindow = -1; |
| 4491 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4492 | |
| 4493 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4494 | params.use_cts_prot = |
| 4495 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4496 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4497 | params.use_short_preamble = |
| 4498 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4499 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4500 | params.use_short_slot_time = |
| 4501 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4502 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4503 | params.basic_rates = |
| 4504 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4505 | params.basic_rates_len = |
| 4506 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4507 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4508 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4509 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4510 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4511 | params.ht_opmode = |
| 4512 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4513 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4514 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4515 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4516 | return -EINVAL; |
| 4517 | params.p2p_ctwindow = |
| 4518 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4519 | if (params.p2p_ctwindow < 0) |
| 4520 | return -EINVAL; |
| 4521 | if (params.p2p_ctwindow != 0 && |
| 4522 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4523 | return -EINVAL; |
| 4524 | } |
| 4525 | |
| 4526 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4527 | u8 tmp; |
| 4528 | |
| 4529 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4530 | return -EINVAL; |
| 4531 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4532 | if (tmp > 1) |
| 4533 | return -EINVAL; |
| 4534 | params.p2p_opp_ps = tmp; |
| 4535 | if (params.p2p_opp_ps && |
| 4536 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4537 | return -EINVAL; |
| 4538 | } |
| 4539 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4540 | if (!rdev->ops->change_bss) |
| 4541 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4542 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4543 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4544 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4545 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4546 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4547 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4548 | } |
| 4549 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4550 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4551 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4552 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4553 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4554 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4555 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4556 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4557 | }; |
| 4558 | |
| 4559 | static int parse_reg_rule(struct nlattr *tb[], |
| 4560 | struct ieee80211_reg_rule *reg_rule) |
| 4561 | { |
| 4562 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4563 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4564 | |
| 4565 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4566 | return -EINVAL; |
| 4567 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4568 | return -EINVAL; |
| 4569 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4570 | return -EINVAL; |
| 4571 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4572 | return -EINVAL; |
| 4573 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4574 | return -EINVAL; |
| 4575 | |
| 4576 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4577 | |
| 4578 | freq_range->start_freq_khz = |
| 4579 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4580 | freq_range->end_freq_khz = |
| 4581 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4582 | freq_range->max_bandwidth_khz = |
| 4583 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4584 | |
| 4585 | power_rule->max_eirp = |
| 4586 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4587 | |
| 4588 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4589 | power_rule->max_antenna_gain = |
| 4590 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4591 | |
| 4592 | return 0; |
| 4593 | } |
| 4594 | |
| 4595 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4596 | { |
| 4597 | int r; |
| 4598 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4599 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4600 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4601 | /* |
| 4602 | * You should only get this when cfg80211 hasn't yet initialized |
| 4603 | * completely when built-in to the kernel right between the time |
| 4604 | * window between nl80211_init() and regulatory_init(), if that is |
| 4605 | * even possible. |
| 4606 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4607 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4608 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4609 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4610 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4611 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4612 | |
| 4613 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4614 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4615 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4616 | user_reg_hint_type = |
| 4617 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4618 | else |
| 4619 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4620 | |
| 4621 | switch (user_reg_hint_type) { |
| 4622 | case NL80211_USER_REG_HINT_USER: |
| 4623 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4624 | break; |
| 4625 | default: |
| 4626 | return -EINVAL; |
| 4627 | } |
| 4628 | |
| 4629 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4630 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4631 | return r; |
| 4632 | } |
| 4633 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4634 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4635 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4636 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4638 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4639 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4640 | struct mesh_config cur_params; |
| 4641 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4642 | void *hdr; |
| 4643 | struct nlattr *pinfoattr; |
| 4644 | struct sk_buff *msg; |
| 4645 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4646 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4647 | return -EOPNOTSUPP; |
| 4648 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4649 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4650 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4651 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4652 | wdev_lock(wdev); |
| 4653 | /* If not connected, get default parameters */ |
| 4654 | if (!wdev->mesh_id_len) |
| 4655 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4656 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4657 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4658 | wdev_unlock(wdev); |
| 4659 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4660 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4661 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4662 | |
| 4663 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4665 | if (!msg) |
| 4666 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4667 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4668 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4669 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4670 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4671 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4672 | if (!pinfoattr) |
| 4673 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4674 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4675 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4676 | cur_params.dot11MeshRetryTimeout) || |
| 4677 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4678 | cur_params.dot11MeshConfirmTimeout) || |
| 4679 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4680 | cur_params.dot11MeshHoldingTimeout) || |
| 4681 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4682 | cur_params.dot11MeshMaxPeerLinks) || |
| 4683 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4684 | cur_params.dot11MeshMaxRetries) || |
| 4685 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4686 | cur_params.dot11MeshTTL) || |
| 4687 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4688 | cur_params.element_ttl) || |
| 4689 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4690 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4691 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4692 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4693 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4694 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4695 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4696 | cur_params.path_refresh_time) || |
| 4697 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4698 | cur_params.min_discovery_timeout) || |
| 4699 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4700 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4701 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4702 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4703 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4704 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4705 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4706 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4707 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4708 | cur_params.dot11MeshHWMPRootMode) || |
| 4709 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4710 | cur_params.dot11MeshHWMPRannInterval) || |
| 4711 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4712 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4713 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4714 | cur_params.dot11MeshForwarding) || |
| 4715 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4716 | cur_params.rssi_threshold) || |
| 4717 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4718 | cur_params.ht_opmode) || |
| 4719 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4720 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4721 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4722 | cur_params.dot11MeshHWMProotInterval) || |
| 4723 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4724 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4725 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4726 | cur_params.power_mode) || |
| 4727 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4728 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4729 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4730 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4731 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4732 | nla_nest_end(msg, pinfoattr); |
| 4733 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4734 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4735 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4736 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4737 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4738 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4739 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4740 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4741 | } |
| 4742 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4743 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4744 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4745 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4746 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4747 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4748 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4749 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4750 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4751 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4752 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4753 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4754 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4755 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4756 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4757 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4758 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4759 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4760 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4761 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4762 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4763 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4764 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4765 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4766 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4767 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4768 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4769 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4770 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4771 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4772 | }; |
| 4773 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4774 | static const struct nla_policy |
| 4775 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4776 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4777 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4778 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4779 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4780 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4781 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4782 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4783 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4784 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4785 | }; |
| 4786 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4787 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4788 | struct mesh_config *cfg, |
| 4789 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4790 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4791 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4792 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4793 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4794 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4795 | do { \ |
| 4796 | if (tb[attr]) { \ |
| 4797 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4798 | return -EINVAL; \ |
| 4799 | cfg->param = fn(tb[attr]); \ |
| 4800 | mask |= (1 << (attr - 1)); \ |
| 4801 | } \ |
| 4802 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4803 | |
| 4804 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4805 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4806 | return -EINVAL; |
| 4807 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4808 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4809 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4810 | return -EINVAL; |
| 4811 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4812 | /* This makes sure that there aren't more than 32 mesh config |
| 4813 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4814 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4815 | |
| 4816 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4817 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4818 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4819 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4820 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4821 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4822 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4823 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4824 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4825 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4826 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4827 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4828 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4829 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4830 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4831 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4832 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4833 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4834 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4835 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4836 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4837 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4838 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4839 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4840 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4841 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4842 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4843 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4844 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4845 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4846 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4847 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4848 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4849 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4851 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4852 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4854 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4855 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4856 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4857 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4858 | 1, 65535, mask, |
| 4859 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4860 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4861 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4862 | 1, 65535, mask, |
| 4863 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4864 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4866 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4867 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4868 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4869 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4870 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4871 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4872 | nla_get_u8); |
| 4873 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4874 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4875 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4876 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4877 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4878 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4879 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4880 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4881 | mask, NL80211_MESHCONF_FORWARDING, |
| 4882 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4883 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4884 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4885 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4886 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4887 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4888 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4889 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4890 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4891 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4892 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4893 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4894 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4895 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4896 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4897 | dot11MeshHWMPconfirmationInterval, |
| 4898 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4899 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4900 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4901 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4902 | NL80211_MESH_POWER_ACTIVE, |
| 4903 | NL80211_MESH_POWER_MAX, |
| 4904 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4905 | nla_get_u32); |
| 4906 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4907 | 0, 65535, mask, |
| 4908 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4909 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4910 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4911 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4912 | if (mask_out) |
| 4913 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4914 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4915 | return 0; |
| 4916 | |
| 4917 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4918 | } |
| 4919 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4920 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4921 | struct mesh_setup *setup) |
| 4922 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4924 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4925 | |
| 4926 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4927 | return -EINVAL; |
| 4928 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4929 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4930 | nl80211_mesh_setup_params_policy)) |
| 4931 | return -EINVAL; |
| 4932 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4933 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4934 | setup->sync_method = |
| 4935 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4936 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4937 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4938 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4939 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4940 | setup->path_sel_proto = |
| 4941 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4942 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4943 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4944 | |
| 4945 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4946 | setup->path_metric = |
| 4947 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4948 | IEEE80211_PATH_METRIC_VENDOR : |
| 4949 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4950 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4951 | |
| 4952 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4953 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4954 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4955 | if (!is_valid_ie_attr(ieattr)) |
| 4956 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4957 | setup->ie = nla_data(ieattr); |
| 4958 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4959 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4960 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4961 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4962 | return -EINVAL; |
| 4963 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4964 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4965 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4966 | if (setup->is_secure) |
| 4967 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4968 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4969 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4970 | if (!setup->user_mpm) |
| 4971 | return -EINVAL; |
| 4972 | setup->auth_id = |
| 4973 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4974 | } |
| 4975 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4976 | return 0; |
| 4977 | } |
| 4978 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4979 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4980 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4981 | { |
| 4982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4983 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4984 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4985 | struct mesh_config cfg; |
| 4986 | u32 mask; |
| 4987 | int err; |
| 4988 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4989 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4990 | return -EOPNOTSUPP; |
| 4991 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4992 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4993 | return -EOPNOTSUPP; |
| 4994 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4995 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4996 | if (err) |
| 4997 | return err; |
| 4998 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4999 | wdev_lock(wdev); |
| 5000 | if (!wdev->mesh_id_len) |
| 5001 | err = -ENOLINK; |
| 5002 | |
| 5003 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5004 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5005 | |
| 5006 | wdev_unlock(wdev); |
| 5007 | |
| 5008 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5011 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5012 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5013 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5014 | struct sk_buff *msg; |
| 5015 | void *hdr = NULL; |
| 5016 | struct nlattr *nl_reg_rules; |
| 5017 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5018 | |
| 5019 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5020 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5021 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5022 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5023 | if (!msg) |
| 5024 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5025 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5026 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5027 | NL80211_CMD_GET_REG); |
| 5028 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5029 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5030 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5031 | if (reg_last_request_cell_base() && |
| 5032 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5033 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5034 | goto nla_put_failure; |
| 5035 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5036 | rcu_read_lock(); |
| 5037 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5038 | |
| 5039 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5040 | (regdom->dfs_region && |
| 5041 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5042 | goto nla_put_failure_rcu; |
| 5043 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5044 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5045 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5046 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5047 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5048 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5049 | struct nlattr *nl_reg_rule; |
| 5050 | const struct ieee80211_reg_rule *reg_rule; |
| 5051 | const struct ieee80211_freq_range *freq_range; |
| 5052 | const struct ieee80211_power_rule *power_rule; |
| 5053 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5054 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5055 | freq_range = ®_rule->freq_range; |
| 5056 | power_rule = ®_rule->power_rule; |
| 5057 | |
| 5058 | nl_reg_rule = nla_nest_start(msg, i); |
| 5059 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5060 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5061 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5062 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5063 | reg_rule->flags) || |
| 5064 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5065 | freq_range->start_freq_khz) || |
| 5066 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5067 | freq_range->end_freq_khz) || |
| 5068 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5069 | freq_range->max_bandwidth_khz) || |
| 5070 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5071 | power_rule->max_antenna_gain) || |
| 5072 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5073 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5074 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5075 | |
| 5076 | nla_nest_end(msg, nl_reg_rule); |
| 5077 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5078 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5079 | |
| 5080 | nla_nest_end(msg, nl_reg_rules); |
| 5081 | |
| 5082 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5083 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5084 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5085 | nla_put_failure_rcu: |
| 5086 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5087 | nla_put_failure: |
| 5088 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5089 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5090 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5091 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5092 | } |
| 5093 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5094 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5095 | { |
| 5096 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5097 | struct nlattr *nl_reg_rule; |
| 5098 | char *alpha2 = NULL; |
| 5099 | int rem_reg_rules = 0, r = 0; |
| 5100 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5101 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5102 | struct ieee80211_regdomain *rd = NULL; |
| 5103 | |
| 5104 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5105 | return -EINVAL; |
| 5106 | |
| 5107 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5108 | return -EINVAL; |
| 5109 | |
| 5110 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5111 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5112 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5113 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5114 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5115 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5116 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5117 | num_rules++; |
| 5118 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5119 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5122 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5123 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5124 | |
| 5125 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5126 | if (!rd) |
| 5127 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5128 | |
| 5129 | rd->n_reg_rules = num_rules; |
| 5130 | rd->alpha2[0] = alpha2[0]; |
| 5131 | rd->alpha2[1] = alpha2[1]; |
| 5132 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5133 | /* |
| 5134 | * Disable DFS master mode if the DFS region was |
| 5135 | * not supported or known on this kernel. |
| 5136 | */ |
| 5137 | if (reg_supported_dfs_region(dfs_region)) |
| 5138 | rd->dfs_region = dfs_region; |
| 5139 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5140 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5141 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5142 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5143 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5144 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5145 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5146 | if (r) |
| 5147 | goto bad_reg; |
| 5148 | |
| 5149 | rule_idx++; |
| 5150 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5151 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5152 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5153 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5154 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5155 | } |
| 5156 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5157 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5158 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5159 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5160 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5161 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5162 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5163 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5166 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5167 | { |
| 5168 | struct nlattr *attr1, *attr2; |
| 5169 | int n_channels = 0, tmp1, tmp2; |
| 5170 | |
| 5171 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5172 | n_channels++; |
| 5173 | /* |
| 5174 | * Some hardware has a limited channel list for |
| 5175 | * scanning, and it is pretty much nonsensical |
| 5176 | * to scan for a channel twice, so disallow that |
| 5177 | * and don't require drivers to check that the |
| 5178 | * channel list they get isn't longer than what |
| 5179 | * they can scan, as long as they can scan all |
| 5180 | * the channels they registered at once. |
| 5181 | */ |
| 5182 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5183 | if (attr1 != attr2 && |
| 5184 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5185 | return 0; |
| 5186 | } |
| 5187 | |
| 5188 | return n_channels; |
| 5189 | } |
| 5190 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5191 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5192 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5194 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5195 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5196 | struct nlattr *attr; |
| 5197 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5198 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5199 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5200 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5201 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5202 | return -EINVAL; |
| 5203 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5204 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5206 | if (!rdev->ops->scan) |
| 5207 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5208 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5209 | if (rdev->scan_req) { |
| 5210 | err = -EBUSY; |
| 5211 | goto unlock; |
| 5212 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5213 | |
| 5214 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5215 | n_channels = validate_scan_freqs( |
| 5216 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5217 | if (!n_channels) { |
| 5218 | err = -EINVAL; |
| 5219 | goto unlock; |
| 5220 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5221 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5222 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5223 | n_channels = 0; |
| 5224 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5225 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5226 | if (wiphy->bands[band]) |
| 5227 | n_channels += wiphy->bands[band]->n_channels; |
| 5228 | } |
| 5229 | |
| 5230 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5231 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5232 | n_ssids++; |
| 5233 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5234 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5235 | err = -EINVAL; |
| 5236 | goto unlock; |
| 5237 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5238 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5239 | if (info->attrs[NL80211_ATTR_IE]) |
| 5240 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5241 | else |
| 5242 | ie_len = 0; |
| 5243 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5244 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5245 | err = -EINVAL; |
| 5246 | goto unlock; |
| 5247 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5248 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5249 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5250 | + sizeof(*request->ssids) * n_ssids |
| 5251 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5252 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5253 | if (!request) { |
| 5254 | err = -ENOMEM; |
| 5255 | goto unlock; |
| 5256 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5257 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5258 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5259 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5260 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5261 | if (ie_len) { |
| 5262 | if (request->ssids) |
| 5263 | request->ie = (void *)(request->ssids + n_ssids); |
| 5264 | else |
| 5265 | request->ie = (void *)(request->channels + n_channels); |
| 5266 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5267 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5268 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5269 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5270 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5272 | struct ieee80211_channel *chan; |
| 5273 | |
| 5274 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5275 | |
| 5276 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5277 | err = -EINVAL; |
| 5278 | goto out_free; |
| 5279 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5280 | |
| 5281 | /* ignore disabled channels */ |
| 5282 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5283 | continue; |
| 5284 | |
| 5285 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5286 | i++; |
| 5287 | } |
| 5288 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5289 | enum ieee80211_band band; |
| 5290 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5291 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5292 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5293 | int j; |
| 5294 | if (!wiphy->bands[band]) |
| 5295 | continue; |
| 5296 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5297 | struct ieee80211_channel *chan; |
| 5298 | |
| 5299 | chan = &wiphy->bands[band]->channels[j]; |
| 5300 | |
| 5301 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5302 | continue; |
| 5303 | |
| 5304 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5305 | i++; |
| 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5310 | if (!i) { |
| 5311 | err = -EINVAL; |
| 5312 | goto out_free; |
| 5313 | } |
| 5314 | |
| 5315 | request->n_channels = i; |
| 5316 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5317 | i = 0; |
| 5318 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5319 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5320 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5321 | err = -EINVAL; |
| 5322 | goto out_free; |
| 5323 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5324 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | i++; |
| 5327 | } |
| 5328 | } |
| 5329 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5330 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5331 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5332 | memcpy((void *)request->ie, |
| 5333 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5334 | request->ie_len); |
| 5335 | } |
| 5336 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5337 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5338 | if (wiphy->bands[i]) |
| 5339 | request->rates[i] = |
| 5340 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5341 | |
| 5342 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5343 | nla_for_each_nested(attr, |
| 5344 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5345 | tmp) { |
| 5346 | enum ieee80211_band band = nla_type(attr); |
| 5347 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5348 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5349 | err = -EINVAL; |
| 5350 | goto out_free; |
| 5351 | } |
| 5352 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5353 | nla_data(attr), |
| 5354 | nla_len(attr), |
| 5355 | &request->rates[band]); |
| 5356 | if (err) |
| 5357 | goto out_free; |
| 5358 | } |
| 5359 | } |
| 5360 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5361 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5362 | request->flags = nla_get_u32( |
| 5363 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5364 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5365 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5366 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5367 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5368 | err = -EOPNOTSUPP; |
| 5369 | goto out_free; |
| 5370 | } |
| 5371 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5372 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5373 | request->no_cck = |
| 5374 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5375 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5376 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5377 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5378 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5379 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5380 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5381 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5382 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5383 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5384 | nl80211_send_scan_start(rdev, wdev); |
| 5385 | if (wdev->netdev) |
| 5386 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5387 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5388 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5389 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5390 | kfree(request); |
| 5391 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5392 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5393 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5394 | return err; |
| 5395 | } |
| 5396 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5397 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5398 | struct genl_info *info) |
| 5399 | { |
| 5400 | struct cfg80211_sched_scan_request *request; |
| 5401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5402 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5403 | struct nlattr *attr; |
| 5404 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5405 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5406 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5407 | enum ieee80211_band band; |
| 5408 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5409 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5410 | |
| 5411 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5412 | !rdev->ops->sched_scan_start) |
| 5413 | return -EOPNOTSUPP; |
| 5414 | |
| 5415 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5416 | return -EINVAL; |
| 5417 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5418 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5419 | return -EINVAL; |
| 5420 | |
| 5421 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5422 | if (interval == 0) |
| 5423 | return -EINVAL; |
| 5424 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5425 | wiphy = &rdev->wiphy; |
| 5426 | |
| 5427 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5428 | n_channels = validate_scan_freqs( |
| 5429 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5430 | if (!n_channels) |
| 5431 | return -EINVAL; |
| 5432 | } else { |
| 5433 | n_channels = 0; |
| 5434 | |
| 5435 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5436 | if (wiphy->bands[band]) |
| 5437 | n_channels += wiphy->bands[band]->n_channels; |
| 5438 | } |
| 5439 | |
| 5440 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5441 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5442 | tmp) |
| 5443 | n_ssids++; |
| 5444 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5445 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5446 | return -EINVAL; |
| 5447 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5448 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5449 | nla_for_each_nested(attr, |
| 5450 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5451 | tmp) |
| 5452 | n_match_sets++; |
| 5453 | |
| 5454 | if (n_match_sets > wiphy->max_match_sets) |
| 5455 | return -EINVAL; |
| 5456 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5457 | if (info->attrs[NL80211_ATTR_IE]) |
| 5458 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5459 | else |
| 5460 | ie_len = 0; |
| 5461 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5462 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5463 | return -EINVAL; |
| 5464 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5465 | if (rdev->sched_scan_req) { |
| 5466 | err = -EINPROGRESS; |
| 5467 | goto out; |
| 5468 | } |
| 5469 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5470 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5471 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5472 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5473 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5474 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5475 | if (!request) { |
| 5476 | err = -ENOMEM; |
| 5477 | goto out; |
| 5478 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5479 | |
| 5480 | if (n_ssids) |
| 5481 | request->ssids = (void *)&request->channels[n_channels]; |
| 5482 | request->n_ssids = n_ssids; |
| 5483 | if (ie_len) { |
| 5484 | if (request->ssids) |
| 5485 | request->ie = (void *)(request->ssids + n_ssids); |
| 5486 | else |
| 5487 | request->ie = (void *)(request->channels + n_channels); |
| 5488 | } |
| 5489 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5490 | if (n_match_sets) { |
| 5491 | if (request->ie) |
| 5492 | request->match_sets = (void *)(request->ie + ie_len); |
| 5493 | else if (request->ssids) |
| 5494 | request->match_sets = |
| 5495 | (void *)(request->ssids + n_ssids); |
| 5496 | else |
| 5497 | request->match_sets = |
| 5498 | (void *)(request->channels + n_channels); |
| 5499 | } |
| 5500 | request->n_match_sets = n_match_sets; |
| 5501 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5502 | i = 0; |
| 5503 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5504 | /* user specified, bail out if channel not found */ |
| 5505 | nla_for_each_nested(attr, |
| 5506 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5507 | tmp) { |
| 5508 | struct ieee80211_channel *chan; |
| 5509 | |
| 5510 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5511 | |
| 5512 | if (!chan) { |
| 5513 | err = -EINVAL; |
| 5514 | goto out_free; |
| 5515 | } |
| 5516 | |
| 5517 | /* ignore disabled channels */ |
| 5518 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5519 | continue; |
| 5520 | |
| 5521 | request->channels[i] = chan; |
| 5522 | i++; |
| 5523 | } |
| 5524 | } else { |
| 5525 | /* all channels */ |
| 5526 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5527 | int j; |
| 5528 | if (!wiphy->bands[band]) |
| 5529 | continue; |
| 5530 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5531 | struct ieee80211_channel *chan; |
| 5532 | |
| 5533 | chan = &wiphy->bands[band]->channels[j]; |
| 5534 | |
| 5535 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5536 | continue; |
| 5537 | |
| 5538 | request->channels[i] = chan; |
| 5539 | i++; |
| 5540 | } |
| 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | if (!i) { |
| 5545 | err = -EINVAL; |
| 5546 | goto out_free; |
| 5547 | } |
| 5548 | |
| 5549 | request->n_channels = i; |
| 5550 | |
| 5551 | i = 0; |
| 5552 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5553 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5554 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5555 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5556 | err = -EINVAL; |
| 5557 | goto out_free; |
| 5558 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5559 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5560 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5561 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5562 | i++; |
| 5563 | } |
| 5564 | } |
| 5565 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5566 | i = 0; |
| 5567 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5568 | nla_for_each_nested(attr, |
| 5569 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5570 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5571 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5572 | |
| 5573 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5574 | nla_data(attr), nla_len(attr), |
| 5575 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5576 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5577 | if (ssid) { |
| 5578 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5579 | err = -EINVAL; |
| 5580 | goto out_free; |
| 5581 | } |
| 5582 | memcpy(request->match_sets[i].ssid.ssid, |
| 5583 | nla_data(ssid), nla_len(ssid)); |
| 5584 | request->match_sets[i].ssid.ssid_len = |
| 5585 | nla_len(ssid); |
| 5586 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5587 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5588 | if (rssi) |
| 5589 | request->rssi_thold = nla_get_u32(rssi); |
| 5590 | else |
| 5591 | request->rssi_thold = |
| 5592 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5593 | i++; |
| 5594 | } |
| 5595 | } |
| 5596 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5597 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5598 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5599 | memcpy((void *)request->ie, |
| 5600 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5601 | request->ie_len); |
| 5602 | } |
| 5603 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5604 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5605 | request->flags = nla_get_u32( |
| 5606 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5607 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5608 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5609 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5610 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5611 | err = -EOPNOTSUPP; |
| 5612 | goto out_free; |
| 5613 | } |
| 5614 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5615 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5616 | request->dev = dev; |
| 5617 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5618 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5619 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5620 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5621 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5622 | if (!err) { |
| 5623 | rdev->sched_scan_req = request; |
| 5624 | nl80211_send_sched_scan(rdev, dev, |
| 5625 | NL80211_CMD_START_SCHED_SCAN); |
| 5626 | goto out; |
| 5627 | } |
| 5628 | |
| 5629 | out_free: |
| 5630 | kfree(request); |
| 5631 | out: |
| 5632 | return err; |
| 5633 | } |
| 5634 | |
| 5635 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5636 | struct genl_info *info) |
| 5637 | { |
| 5638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5639 | |
| 5640 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5641 | !rdev->ops->sched_scan_stop) |
| 5642 | return -EOPNOTSUPP; |
| 5643 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5644 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5645 | } |
| 5646 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5647 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5648 | struct genl_info *info) |
| 5649 | { |
| 5650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5651 | struct net_device *dev = info->user_ptr[1]; |
| 5652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5653 | struct cfg80211_chan_def chandef; |
| 5654 | int err; |
| 5655 | |
| 5656 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5657 | if (err) |
| 5658 | return err; |
| 5659 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5660 | if (netif_carrier_ok(dev)) |
| 5661 | return -EBUSY; |
| 5662 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5663 | if (wdev->cac_started) |
| 5664 | return -EBUSY; |
| 5665 | |
| 5666 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5667 | if (err < 0) |
| 5668 | return err; |
| 5669 | |
| 5670 | if (err == 0) |
| 5671 | return -EINVAL; |
| 5672 | |
| 5673 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5674 | return -EINVAL; |
| 5675 | |
| 5676 | if (!rdev->ops->start_radar_detection) |
| 5677 | return -EOPNOTSUPP; |
| 5678 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5679 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5680 | chandef.chan, CHAN_MODE_SHARED, |
| 5681 | BIT(chandef.width)); |
| 5682 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5683 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5684 | |
| 5685 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5686 | if (!err) { |
| 5687 | wdev->channel = chandef.chan; |
| 5688 | wdev->cac_started = true; |
| 5689 | wdev->cac_start_time = jiffies; |
| 5690 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5691 | return err; |
| 5692 | } |
| 5693 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5694 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5695 | { |
| 5696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5697 | struct net_device *dev = info->user_ptr[1]; |
| 5698 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5699 | struct cfg80211_csa_settings params; |
| 5700 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5701 | * function is called under RTNL lock, so this should not be a problem. |
| 5702 | */ |
| 5703 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5704 | u8 radar_detect_width = 0; |
| 5705 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5706 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5707 | |
| 5708 | if (!rdev->ops->channel_switch || |
| 5709 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5710 | return -EOPNOTSUPP; |
| 5711 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5712 | switch (dev->ieee80211_ptr->iftype) { |
| 5713 | case NL80211_IFTYPE_AP: |
| 5714 | case NL80211_IFTYPE_P2P_GO: |
| 5715 | need_new_beacon = true; |
| 5716 | |
| 5717 | /* useless if AP is not running */ |
| 5718 | if (!wdev->beacon_interval) |
| 5719 | return -EINVAL; |
| 5720 | break; |
| 5721 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5722 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5723 | break; |
| 5724 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5725 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5726 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5727 | |
| 5728 | memset(¶ms, 0, sizeof(params)); |
| 5729 | |
| 5730 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5731 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5732 | return -EINVAL; |
| 5733 | |
| 5734 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5735 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5736 | return -EINVAL; |
| 5737 | |
| 5738 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5739 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5740 | if (!need_new_beacon) |
| 5741 | goto skip_beacons; |
| 5742 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5743 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5744 | if (err) |
| 5745 | return err; |
| 5746 | |
| 5747 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5748 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5749 | nl80211_policy); |
| 5750 | if (err) |
| 5751 | return err; |
| 5752 | |
| 5753 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5754 | if (err) |
| 5755 | return err; |
| 5756 | |
| 5757 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5758 | return -EINVAL; |
| 5759 | |
| 5760 | params.counter_offset_beacon = |
| 5761 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5762 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5763 | return -EINVAL; |
| 5764 | |
| 5765 | /* sanity check - counters should be the same */ |
| 5766 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5767 | params.count) |
| 5768 | return -EINVAL; |
| 5769 | |
| 5770 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5771 | params.counter_offset_presp = |
| 5772 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5773 | if (params.counter_offset_presp >= |
| 5774 | params.beacon_csa.probe_resp_len) |
| 5775 | return -EINVAL; |
| 5776 | |
| 5777 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5778 | params.count) |
| 5779 | return -EINVAL; |
| 5780 | } |
| 5781 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5782 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5783 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5784 | if (err) |
| 5785 | return err; |
| 5786 | |
| 5787 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5788 | return -EINVAL; |
| 5789 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5790 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5791 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5792 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5793 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5794 | ¶ms.chandef); |
| 5795 | if (err < 0) { |
| 5796 | return err; |
| 5797 | } else if (err) { |
| 5798 | radar_detect_width = BIT(params.chandef.width); |
| 5799 | params.radar_required = true; |
| 5800 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5804 | params.chandef.chan, |
| 5805 | CHAN_MODE_SHARED, |
| 5806 | radar_detect_width); |
| 5807 | if (err) |
| 5808 | return err; |
| 5809 | |
| 5810 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5811 | params.block_tx = true; |
| 5812 | |
| 5813 | return rdev_channel_switch(rdev, dev, ¶ms); |
| 5814 | } |
| 5815 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5816 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5817 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5818 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5819 | struct wireless_dev *wdev, |
| 5820 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5821 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5822 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5823 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5824 | void *hdr; |
| 5825 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5826 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5827 | |
| 5828 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5829 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5830 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5831 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5832 | if (!hdr) |
| 5833 | return -1; |
| 5834 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5835 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5836 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5837 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5838 | goto nla_put_failure; |
| 5839 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5840 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5841 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5842 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5843 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5844 | |
| 5845 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5846 | if (!bss) |
| 5847 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5848 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5849 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5850 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5851 | |
| 5852 | rcu_read_lock(); |
| 5853 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5854 | if (ies) { |
| 5855 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5856 | goto fail_unlock_rcu; |
| 5857 | tsf = true; |
| 5858 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5859 | ies->len, ies->data)) |
| 5860 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5861 | } |
| 5862 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5863 | if (ies) { |
| 5864 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5865 | goto fail_unlock_rcu; |
| 5866 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5867 | ies->len, ies->data)) |
| 5868 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5869 | } |
| 5870 | rcu_read_unlock(); |
| 5871 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5872 | if (res->beacon_interval && |
| 5873 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5874 | goto nla_put_failure; |
| 5875 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5876 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5877 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5878 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5879 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5880 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5881 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5882 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5883 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5884 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5885 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5886 | break; |
| 5887 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5888 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5889 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5890 | break; |
| 5891 | default: |
| 5892 | break; |
| 5893 | } |
| 5894 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5895 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5896 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5897 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5898 | if (intbss == wdev->current_bss && |
| 5899 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5900 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5901 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5902 | break; |
| 5903 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5904 | if (intbss == wdev->current_bss && |
| 5905 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5906 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5907 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5908 | break; |
| 5909 | default: |
| 5910 | break; |
| 5911 | } |
| 5912 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5913 | nla_nest_end(msg, bss); |
| 5914 | |
| 5915 | return genlmsg_end(msg, hdr); |
| 5916 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5917 | fail_unlock_rcu: |
| 5918 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5919 | nla_put_failure: |
| 5920 | genlmsg_cancel(msg, hdr); |
| 5921 | return -EMSGSIZE; |
| 5922 | } |
| 5923 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5924 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5925 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5926 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5927 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5928 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5929 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5930 | int err; |
| 5931 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5932 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5933 | if (err) |
| 5934 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5935 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5936 | wdev_lock(wdev); |
| 5937 | spin_lock_bh(&rdev->bss_lock); |
| 5938 | cfg80211_bss_expire(rdev); |
| 5939 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5940 | cb->seq = rdev->bss_generation; |
| 5941 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5942 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5943 | if (++idx <= start) |
| 5944 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5945 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5946 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5947 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5948 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5949 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5950 | } |
| 5951 | } |
| 5952 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5953 | spin_unlock_bh(&rdev->bss_lock); |
| 5954 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5955 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5956 | cb->args[2] = idx; |
| 5957 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5958 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5959 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5960 | } |
| 5961 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5962 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5963 | int flags, struct net_device *dev, |
| 5964 | struct survey_info *survey) |
| 5965 | { |
| 5966 | void *hdr; |
| 5967 | struct nlattr *infoattr; |
| 5968 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5969 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5970 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5971 | if (!hdr) |
| 5972 | return -ENOMEM; |
| 5973 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5974 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5975 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5976 | |
| 5977 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5978 | if (!infoattr) |
| 5979 | goto nla_put_failure; |
| 5980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5981 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5982 | survey->channel->center_freq)) |
| 5983 | goto nla_put_failure; |
| 5984 | |
| 5985 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5986 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5987 | goto nla_put_failure; |
| 5988 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5989 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5990 | goto nla_put_failure; |
| 5991 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5992 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5993 | survey->channel_time)) |
| 5994 | goto nla_put_failure; |
| 5995 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5996 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5997 | survey->channel_time_busy)) |
| 5998 | goto nla_put_failure; |
| 5999 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6000 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6001 | survey->channel_time_ext_busy)) |
| 6002 | goto nla_put_failure; |
| 6003 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6004 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6005 | survey->channel_time_rx)) |
| 6006 | goto nla_put_failure; |
| 6007 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6008 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6009 | survey->channel_time_tx)) |
| 6010 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6011 | |
| 6012 | nla_nest_end(msg, infoattr); |
| 6013 | |
| 6014 | return genlmsg_end(msg, hdr); |
| 6015 | |
| 6016 | nla_put_failure: |
| 6017 | genlmsg_cancel(msg, hdr); |
| 6018 | return -EMSGSIZE; |
| 6019 | } |
| 6020 | |
| 6021 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6022 | struct netlink_callback *cb) |
| 6023 | { |
| 6024 | struct survey_info survey; |
| 6025 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6026 | struct wireless_dev *wdev; |
| 6027 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6028 | int res; |
| 6029 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6030 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6031 | if (res) |
| 6032 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6033 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6034 | if (!wdev->netdev) { |
| 6035 | res = -EINVAL; |
| 6036 | goto out_err; |
| 6037 | } |
| 6038 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6039 | if (!dev->ops->dump_survey) { |
| 6040 | res = -EOPNOTSUPP; |
| 6041 | goto out_err; |
| 6042 | } |
| 6043 | |
| 6044 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6045 | struct ieee80211_channel *chan; |
| 6046 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6047 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6048 | if (res == -ENOENT) |
| 6049 | break; |
| 6050 | if (res) |
| 6051 | goto out_err; |
| 6052 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6053 | /* Survey without a channel doesn't make sense */ |
| 6054 | if (!survey.channel) { |
| 6055 | res = -EINVAL; |
| 6056 | goto out; |
| 6057 | } |
| 6058 | |
| 6059 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6060 | survey.channel->center_freq); |
| 6061 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6062 | survey_idx++; |
| 6063 | continue; |
| 6064 | } |
| 6065 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6066 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6067 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6068 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6069 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6070 | goto out; |
| 6071 | survey_idx++; |
| 6072 | } |
| 6073 | |
| 6074 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6075 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6076 | res = skb->len; |
| 6077 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6078 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6079 | return res; |
| 6080 | } |
| 6081 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6082 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6083 | { |
| 6084 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6085 | NL80211_WPA_VERSION_2)); |
| 6086 | } |
| 6087 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6088 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6089 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6091 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6092 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6093 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6094 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6095 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6096 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6097 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6098 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6099 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6100 | return -EINVAL; |
| 6101 | |
| 6102 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6103 | return -EINVAL; |
| 6104 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6105 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6106 | return -EINVAL; |
| 6107 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6108 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6109 | return -EINVAL; |
| 6110 | |
| 6111 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6112 | return -EINVAL; |
| 6113 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6114 | err = nl80211_parse_key(info, &key); |
| 6115 | if (err) |
| 6116 | return err; |
| 6117 | |
| 6118 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6119 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6120 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6121 | if (!key.p.key || !key.p.key_len) |
| 6122 | return -EINVAL; |
| 6123 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6124 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6125 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6126 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6127 | return -EINVAL; |
| 6128 | if (key.idx > 4) |
| 6129 | return -EINVAL; |
| 6130 | } else { |
| 6131 | key.p.key_len = 0; |
| 6132 | key.p.key = NULL; |
| 6133 | } |
| 6134 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6135 | if (key.idx >= 0) { |
| 6136 | int i; |
| 6137 | bool ok = false; |
| 6138 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6139 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6140 | ok = true; |
| 6141 | break; |
| 6142 | } |
| 6143 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6144 | if (!ok) |
| 6145 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6146 | } |
| 6147 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6148 | if (!rdev->ops->auth) |
| 6149 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6150 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6151 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6153 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6154 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6155 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6156 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6157 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6158 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6159 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6160 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6161 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6162 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6163 | |
| 6164 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6165 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6166 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6167 | } |
| 6168 | |
| 6169 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6170 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6171 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6172 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6173 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6174 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6175 | return -EINVAL; |
| 6176 | |
| 6177 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6178 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6179 | return -EINVAL; |
| 6180 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6181 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6182 | /* need to include at least Auth Transaction and Status Code */ |
| 6183 | if (sae_data_len < 4) |
| 6184 | return -EINVAL; |
| 6185 | } |
| 6186 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6187 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6188 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6189 | /* |
| 6190 | * Since we no longer track auth state, ignore |
| 6191 | * requests to only change local state. |
| 6192 | */ |
| 6193 | if (local_state_change) |
| 6194 | return 0; |
| 6195 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6196 | wdev_lock(dev->ieee80211_ptr); |
| 6197 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6198 | ssid, ssid_len, ie, ie_len, |
| 6199 | key.p.key, key.p.key_len, key.idx, |
| 6200 | sae_data, sae_data_len); |
| 6201 | wdev_unlock(dev->ieee80211_ptr); |
| 6202 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6203 | } |
| 6204 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6205 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6206 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6207 | struct cfg80211_crypto_settings *settings, |
| 6208 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6209 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6210 | memset(settings, 0, sizeof(*settings)); |
| 6211 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6212 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6213 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6214 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6215 | u16 proto; |
| 6216 | proto = nla_get_u16( |
| 6217 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6218 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6219 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6220 | proto != ETH_P_PAE) |
| 6221 | return -EINVAL; |
| 6222 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6223 | settings->control_port_no_encrypt = true; |
| 6224 | } else |
| 6225 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6226 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6227 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6228 | void *data; |
| 6229 | int len, i; |
| 6230 | |
| 6231 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6232 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6233 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6234 | |
| 6235 | if (len % sizeof(u32)) |
| 6236 | return -EINVAL; |
| 6237 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6238 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6239 | return -EINVAL; |
| 6240 | |
| 6241 | memcpy(settings->ciphers_pairwise, data, len); |
| 6242 | |
| 6243 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6244 | if (!cfg80211_supported_cipher_suite( |
| 6245 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6246 | settings->ciphers_pairwise[i])) |
| 6247 | return -EINVAL; |
| 6248 | } |
| 6249 | |
| 6250 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6251 | settings->cipher_group = |
| 6252 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6253 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6254 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6255 | return -EINVAL; |
| 6256 | } |
| 6257 | |
| 6258 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6259 | settings->wpa_versions = |
| 6260 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6261 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6262 | return -EINVAL; |
| 6263 | } |
| 6264 | |
| 6265 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6266 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6267 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6268 | |
| 6269 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6270 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6271 | settings->n_akm_suites = len / sizeof(u32); |
| 6272 | |
| 6273 | if (len % sizeof(u32)) |
| 6274 | return -EINVAL; |
| 6275 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6276 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6277 | return -EINVAL; |
| 6278 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6279 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | return 0; |
| 6283 | } |
| 6284 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6285 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6286 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6288 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6289 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6290 | struct cfg80211_assoc_request req = {}; |
| 6291 | const u8 *bssid, *ssid; |
| 6292 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6293 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6294 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6295 | return -EINVAL; |
| 6296 | |
| 6297 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6298 | !info->attrs[NL80211_ATTR_SSID] || |
| 6299 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6300 | return -EINVAL; |
| 6301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6302 | if (!rdev->ops->assoc) |
| 6303 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6304 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6305 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6306 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6307 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6308 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6309 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6310 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6311 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6312 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6313 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6314 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6315 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6316 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6317 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6318 | |
| 6319 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6320 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6321 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6322 | } |
| 6323 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6324 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6325 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6326 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6327 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6328 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6329 | else if (mfp != NL80211_MFP_NO) |
| 6330 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6331 | } |
| 6332 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6333 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6334 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6335 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6336 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6337 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6338 | |
| 6339 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6340 | memcpy(&req.ht_capa_mask, |
| 6341 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6342 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6343 | |
| 6344 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6345 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6346 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6347 | memcpy(&req.ht_capa, |
| 6348 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6349 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6350 | } |
| 6351 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6352 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6353 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6354 | |
| 6355 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6356 | memcpy(&req.vht_capa_mask, |
| 6357 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6358 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6359 | |
| 6360 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6361 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6362 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6363 | memcpy(&req.vht_capa, |
| 6364 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6365 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6366 | } |
| 6367 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6368 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6369 | if (!err) { |
| 6370 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6371 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6372 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6373 | wdev_unlock(dev->ieee80211_ptr); |
| 6374 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6375 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6376 | return err; |
| 6377 | } |
| 6378 | |
| 6379 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6380 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6382 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6383 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6384 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6385 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6386 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6387 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6388 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6389 | return -EINVAL; |
| 6390 | |
| 6391 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6392 | return -EINVAL; |
| 6393 | |
| 6394 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6395 | return -EINVAL; |
| 6396 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6397 | if (!rdev->ops->deauth) |
| 6398 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6399 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6400 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6401 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6402 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6403 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6404 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6405 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6406 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6407 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6408 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6409 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6410 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6411 | |
| 6412 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6413 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6414 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6415 | } |
| 6416 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6417 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6418 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6419 | wdev_lock(dev->ieee80211_ptr); |
| 6420 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6421 | local_state_change); |
| 6422 | wdev_unlock(dev->ieee80211_ptr); |
| 6423 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6427 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6429 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6430 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6431 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6432 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6433 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6434 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6435 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6436 | return -EINVAL; |
| 6437 | |
| 6438 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6439 | return -EINVAL; |
| 6440 | |
| 6441 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6442 | return -EINVAL; |
| 6443 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6444 | if (!rdev->ops->disassoc) |
| 6445 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6446 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6447 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6448 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6449 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6450 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6451 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6452 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6453 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6454 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6455 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6456 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6457 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6458 | |
| 6459 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6460 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6461 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6462 | } |
| 6463 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6464 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6465 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6466 | wdev_lock(dev->ieee80211_ptr); |
| 6467 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6468 | local_state_change); |
| 6469 | wdev_unlock(dev->ieee80211_ptr); |
| 6470 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6471 | } |
| 6472 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6473 | static bool |
| 6474 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6475 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6476 | int rateval) |
| 6477 | { |
| 6478 | struct wiphy *wiphy = &rdev->wiphy; |
| 6479 | bool found = false; |
| 6480 | int band, i; |
| 6481 | |
| 6482 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6483 | struct ieee80211_supported_band *sband; |
| 6484 | |
| 6485 | sband = wiphy->bands[band]; |
| 6486 | if (!sband) |
| 6487 | continue; |
| 6488 | |
| 6489 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6490 | if (sband->bitrates[i].bitrate == rateval) { |
| 6491 | mcast_rate[band] = i + 1; |
| 6492 | found = true; |
| 6493 | break; |
| 6494 | } |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | return found; |
| 6499 | } |
| 6500 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6501 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6502 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6504 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6505 | struct cfg80211_ibss_params ibss; |
| 6506 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6507 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6508 | int err; |
| 6509 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6510 | memset(&ibss, 0, sizeof(ibss)); |
| 6511 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6512 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6513 | return -EINVAL; |
| 6514 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6515 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6516 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6517 | return -EINVAL; |
| 6518 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6519 | ibss.beacon_interval = 100; |
| 6520 | |
| 6521 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6522 | ibss.beacon_interval = |
| 6523 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6524 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6525 | return -EINVAL; |
| 6526 | } |
| 6527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6528 | if (!rdev->ops->join_ibss) |
| 6529 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6530 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6531 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6532 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6533 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6534 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6535 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6536 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6537 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6538 | |
| 6539 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6540 | return -EINVAL; |
| 6541 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6542 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6543 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6544 | |
| 6545 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6546 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6547 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6548 | } |
| 6549 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6550 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6551 | if (err) |
| 6552 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6553 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6554 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6555 | return -EINVAL; |
| 6556 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6557 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6558 | case NL80211_CHAN_WIDTH_5: |
| 6559 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6560 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6561 | break; |
| 6562 | case NL80211_CHAN_WIDTH_20: |
| 6563 | case NL80211_CHAN_WIDTH_40: |
| 6564 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6565 | break; |
| 6566 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6567 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6568 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6569 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6570 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6571 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6572 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6573 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6574 | u8 *rates = |
| 6575 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6576 | int n_rates = |
| 6577 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6578 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6579 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6580 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6581 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6582 | &ibss.basic_rates); |
| 6583 | if (err) |
| 6584 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6585 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6586 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6587 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6588 | memcpy(&ibss.ht_capa_mask, |
| 6589 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6590 | sizeof(ibss.ht_capa_mask)); |
| 6591 | |
| 6592 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6593 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6594 | return -EINVAL; |
| 6595 | memcpy(&ibss.ht_capa, |
| 6596 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6597 | sizeof(ibss.ht_capa)); |
| 6598 | } |
| 6599 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6600 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6601 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6602 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6603 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6604 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6605 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6606 | bool no_ht = false; |
| 6607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6608 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6609 | info->attrs[NL80211_ATTR_KEYS], |
| 6610 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6611 | if (IS_ERR(connkeys)) |
| 6612 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6613 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6614 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6615 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6616 | kfree(connkeys); |
| 6617 | return -EINVAL; |
| 6618 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6619 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6620 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6621 | ibss.control_port = |
| 6622 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6623 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6624 | ibss.userspace_handles_dfs = |
| 6625 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6626 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6627 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6628 | if (err) |
| 6629 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6630 | return err; |
| 6631 | } |
| 6632 | |
| 6633 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6634 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6635 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6636 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6638 | if (!rdev->ops->leave_ibss) |
| 6639 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6640 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6641 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6642 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6643 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6644 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6645 | } |
| 6646 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6647 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6648 | { |
| 6649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6650 | struct net_device *dev = info->user_ptr[1]; |
| 6651 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6652 | u32 nla_rate; |
| 6653 | int err; |
| 6654 | |
| 6655 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6656 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6657 | return -EOPNOTSUPP; |
| 6658 | |
| 6659 | if (!rdev->ops->set_mcast_rate) |
| 6660 | return -EOPNOTSUPP; |
| 6661 | |
| 6662 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6663 | |
| 6664 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6665 | return -EINVAL; |
| 6666 | |
| 6667 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6668 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6669 | return -EINVAL; |
| 6670 | |
| 6671 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6672 | |
| 6673 | return err; |
| 6674 | } |
| 6675 | |
| 6676 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6677 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6678 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6679 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6681 | struct wireless_dev *wdev = |
| 6682 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6683 | int err; |
| 6684 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6685 | if (!rdev->ops->testmode_cmd) |
| 6686 | return -EOPNOTSUPP; |
| 6687 | |
| 6688 | if (IS_ERR(wdev)) { |
| 6689 | err = PTR_ERR(wdev); |
| 6690 | if (err != -EINVAL) |
| 6691 | return err; |
| 6692 | wdev = NULL; |
| 6693 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6694 | return -EINVAL; |
| 6695 | } |
| 6696 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6697 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6698 | return -EINVAL; |
| 6699 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6700 | rdev->testmode_info = info; |
| 6701 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6702 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6703 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6704 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6705 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6706 | return err; |
| 6707 | } |
| 6708 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6709 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6710 | struct netlink_callback *cb) |
| 6711 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6712 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6713 | int err; |
| 6714 | long phy_idx; |
| 6715 | void *data = NULL; |
| 6716 | int data_len = 0; |
| 6717 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6718 | rtnl_lock(); |
| 6719 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6720 | if (cb->args[0]) { |
| 6721 | /* |
| 6722 | * 0 is a valid index, but not valid for args[0], |
| 6723 | * so we need to offset by 1. |
| 6724 | */ |
| 6725 | phy_idx = cb->args[0] - 1; |
| 6726 | } else { |
| 6727 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6728 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6729 | nl80211_policy); |
| 6730 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6731 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6732 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6733 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6734 | nl80211_fam.attrbuf); |
| 6735 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6736 | err = PTR_ERR(rdev); |
| 6737 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6738 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6739 | phy_idx = rdev->wiphy_idx; |
| 6740 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6741 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6742 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6743 | cb->args[1] = |
| 6744 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6745 | } |
| 6746 | |
| 6747 | if (cb->args[1]) { |
| 6748 | data = nla_data((void *)cb->args[1]); |
| 6749 | data_len = nla_len((void *)cb->args[1]); |
| 6750 | } |
| 6751 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6752 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6753 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6754 | err = -ENOENT; |
| 6755 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6756 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6757 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6758 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6759 | err = -EOPNOTSUPP; |
| 6760 | goto out_err; |
| 6761 | } |
| 6762 | |
| 6763 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6764 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6765 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6766 | NL80211_CMD_TESTMODE); |
| 6767 | struct nlattr *tmdata; |
| 6768 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6769 | if (!hdr) |
| 6770 | break; |
| 6771 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6772 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6773 | genlmsg_cancel(skb, hdr); |
| 6774 | break; |
| 6775 | } |
| 6776 | |
| 6777 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6778 | if (!tmdata) { |
| 6779 | genlmsg_cancel(skb, hdr); |
| 6780 | break; |
| 6781 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6782 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6783 | nla_nest_end(skb, tmdata); |
| 6784 | |
| 6785 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6786 | genlmsg_cancel(skb, hdr); |
| 6787 | break; |
| 6788 | } else if (err) { |
| 6789 | genlmsg_cancel(skb, hdr); |
| 6790 | goto out_err; |
| 6791 | } |
| 6792 | |
| 6793 | genlmsg_end(skb, hdr); |
| 6794 | } |
| 6795 | |
| 6796 | err = skb->len; |
| 6797 | /* see above */ |
| 6798 | cb->args[0] = phy_idx + 1; |
| 6799 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6800 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6801 | return err; |
| 6802 | } |
| 6803 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6804 | static struct sk_buff * |
| 6805 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6806 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6807 | { |
| 6808 | struct sk_buff *skb; |
| 6809 | void *hdr; |
| 6810 | struct nlattr *data; |
| 6811 | |
| 6812 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6813 | if (!skb) |
| 6814 | return NULL; |
| 6815 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6816 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6817 | if (!hdr) { |
| 6818 | kfree_skb(skb); |
| 6819 | return NULL; |
| 6820 | } |
| 6821 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6822 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6823 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6824 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6825 | |
| 6826 | ((void **)skb->cb)[0] = rdev; |
| 6827 | ((void **)skb->cb)[1] = hdr; |
| 6828 | ((void **)skb->cb)[2] = data; |
| 6829 | |
| 6830 | return skb; |
| 6831 | |
| 6832 | nla_put_failure: |
| 6833 | kfree_skb(skb); |
| 6834 | return NULL; |
| 6835 | } |
| 6836 | |
| 6837 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6838 | int approxlen) |
| 6839 | { |
| 6840 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6841 | |
| 6842 | if (WARN_ON(!rdev->testmode_info)) |
| 6843 | return NULL; |
| 6844 | |
| 6845 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6846 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6847 | rdev->testmode_info->snd_seq, |
| 6848 | GFP_KERNEL); |
| 6849 | } |
| 6850 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6851 | |
| 6852 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6853 | { |
| 6854 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6855 | void *hdr = ((void **)skb->cb)[1]; |
| 6856 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6857 | |
| 6858 | if (WARN_ON(!rdev->testmode_info)) { |
| 6859 | kfree_skb(skb); |
| 6860 | return -EINVAL; |
| 6861 | } |
| 6862 | |
| 6863 | nla_nest_end(skb, data); |
| 6864 | genlmsg_end(skb, hdr); |
| 6865 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6866 | } |
| 6867 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6868 | |
| 6869 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6870 | int approxlen, gfp_t gfp) |
| 6871 | { |
| 6872 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6873 | |
| 6874 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6875 | } |
| 6876 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6877 | |
| 6878 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6879 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6880 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6881 | void *hdr = ((void **)skb->cb)[1]; |
| 6882 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6883 | |
| 6884 | nla_nest_end(skb, data); |
| 6885 | genlmsg_end(skb, hdr); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 6886 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 6887 | NL80211_MCGRP_TESTMODE, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6888 | } |
| 6889 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6890 | #endif |
| 6891 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6892 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6893 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6894 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6895 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6896 | struct cfg80211_connect_params connect; |
| 6897 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6898 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6899 | int err; |
| 6900 | |
| 6901 | memset(&connect, 0, sizeof(connect)); |
| 6902 | |
| 6903 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6904 | return -EINVAL; |
| 6905 | |
| 6906 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6907 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6908 | return -EINVAL; |
| 6909 | |
| 6910 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6911 | connect.auth_type = |
| 6912 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6913 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6914 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6915 | return -EINVAL; |
| 6916 | } else |
| 6917 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6918 | |
| 6919 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6920 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6921 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6922 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6923 | if (err) |
| 6924 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6925 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6926 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6927 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6928 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6929 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6930 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6931 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6932 | connect.bg_scan_period = -1; |
| 6933 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6934 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6935 | connect.bg_scan_period = |
| 6936 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6937 | } |
| 6938 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6939 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6940 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6941 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6942 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6943 | |
| 6944 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6945 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6946 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6947 | } |
| 6948 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6949 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6950 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6951 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6952 | connect.mfp != NL80211_MFP_NO) |
| 6953 | return -EINVAL; |
| 6954 | } else { |
| 6955 | connect.mfp = NL80211_MFP_NO; |
| 6956 | } |
| 6957 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6958 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6959 | connect.channel = |
| 6960 | ieee80211_get_channel(wiphy, |
| 6961 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6962 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6963 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6964 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6965 | } |
| 6966 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6967 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6968 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6969 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6970 | if (IS_ERR(connkeys)) |
| 6971 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6972 | } |
| 6973 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6974 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6975 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6976 | |
| 6977 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6978 | memcpy(&connect.ht_capa_mask, |
| 6979 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6980 | sizeof(connect.ht_capa_mask)); |
| 6981 | |
| 6982 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6983 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6984 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6985 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6986 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6987 | memcpy(&connect.ht_capa, |
| 6988 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6989 | sizeof(connect.ht_capa)); |
| 6990 | } |
| 6991 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6992 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6993 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6994 | |
| 6995 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6996 | memcpy(&connect.vht_capa_mask, |
| 6997 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6998 | sizeof(connect.vht_capa_mask)); |
| 6999 | |
| 7000 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7001 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7002 | kfree(connkeys); |
| 7003 | return -EINVAL; |
| 7004 | } |
| 7005 | memcpy(&connect.vht_capa, |
| 7006 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7007 | sizeof(connect.vht_capa)); |
| 7008 | } |
| 7009 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7010 | wdev_lock(dev->ieee80211_ptr); |
| 7011 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7012 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7013 | if (err) |
| 7014 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7015 | return err; |
| 7016 | } |
| 7017 | |
| 7018 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7019 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7021 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7022 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7023 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7024 | |
| 7025 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7026 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7027 | else |
| 7028 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7029 | |
| 7030 | if (reason == 0) |
| 7031 | return -EINVAL; |
| 7032 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7033 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7034 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7035 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7036 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7037 | wdev_lock(dev->ieee80211_ptr); |
| 7038 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7039 | wdev_unlock(dev->ieee80211_ptr); |
| 7040 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7041 | } |
| 7042 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7043 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7044 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7046 | struct net *net; |
| 7047 | int err; |
| 7048 | u32 pid; |
| 7049 | |
| 7050 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7051 | return -EINVAL; |
| 7052 | |
| 7053 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7054 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7055 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7056 | if (IS_ERR(net)) |
| 7057 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7058 | |
| 7059 | err = 0; |
| 7060 | |
| 7061 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7062 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7063 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7064 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7065 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7066 | return err; |
| 7067 | } |
| 7068 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7069 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7072 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7073 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7074 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7075 | struct cfg80211_pmksa pmksa; |
| 7076 | |
| 7077 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7078 | |
| 7079 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7080 | return -EINVAL; |
| 7081 | |
| 7082 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7083 | return -EINVAL; |
| 7084 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7085 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7086 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7087 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7088 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7089 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7090 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7091 | |
| 7092 | switch (info->genlhdr->cmd) { |
| 7093 | case NL80211_CMD_SET_PMKSA: |
| 7094 | rdev_ops = rdev->ops->set_pmksa; |
| 7095 | break; |
| 7096 | case NL80211_CMD_DEL_PMKSA: |
| 7097 | rdev_ops = rdev->ops->del_pmksa; |
| 7098 | break; |
| 7099 | default: |
| 7100 | WARN_ON(1); |
| 7101 | break; |
| 7102 | } |
| 7103 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7104 | if (!rdev_ops) |
| 7105 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7107 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7111 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7113 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7114 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7115 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7116 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7117 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7118 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7119 | if (!rdev->ops->flush_pmksa) |
| 7120 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7121 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7122 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7123 | } |
| 7124 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7125 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7126 | { |
| 7127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7128 | struct net_device *dev = info->user_ptr[1]; |
| 7129 | u8 action_code, dialog_token; |
| 7130 | u16 status_code; |
| 7131 | u8 *peer; |
| 7132 | |
| 7133 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7134 | !rdev->ops->tdls_mgmt) |
| 7135 | return -EOPNOTSUPP; |
| 7136 | |
| 7137 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7138 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7139 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7140 | !info->attrs[NL80211_ATTR_IE] || |
| 7141 | !info->attrs[NL80211_ATTR_MAC]) |
| 7142 | return -EINVAL; |
| 7143 | |
| 7144 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7145 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7146 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7147 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7148 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7149 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7150 | dialog_token, status_code, |
| 7151 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7152 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7153 | } |
| 7154 | |
| 7155 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7156 | { |
| 7157 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7158 | struct net_device *dev = info->user_ptr[1]; |
| 7159 | enum nl80211_tdls_operation operation; |
| 7160 | u8 *peer; |
| 7161 | |
| 7162 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7163 | !rdev->ops->tdls_oper) |
| 7164 | return -EOPNOTSUPP; |
| 7165 | |
| 7166 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7167 | !info->attrs[NL80211_ATTR_MAC]) |
| 7168 | return -EINVAL; |
| 7169 | |
| 7170 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7171 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7172 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7173 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7174 | } |
| 7175 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7176 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7177 | struct genl_info *info) |
| 7178 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7179 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7180 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7181 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7182 | struct sk_buff *msg; |
| 7183 | void *hdr; |
| 7184 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7185 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7186 | int err; |
| 7187 | |
| 7188 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7189 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7190 | return -EINVAL; |
| 7191 | |
| 7192 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7193 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7194 | if (!rdev->ops->remain_on_channel || |
| 7195 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7196 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7197 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7198 | /* |
| 7199 | * We should be on that channel for at least a minimum amount of |
| 7200 | * time (10ms) but no longer than the driver supports. |
| 7201 | */ |
| 7202 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7203 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7204 | return -EINVAL; |
| 7205 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7206 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7207 | if (err) |
| 7208 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7209 | |
| 7210 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7211 | if (!msg) |
| 7212 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7213 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7214 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7215 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7216 | if (!hdr) { |
| 7217 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7218 | goto free_msg; |
| 7219 | } |
| 7220 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7221 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7222 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7223 | |
| 7224 | if (err) |
| 7225 | goto free_msg; |
| 7226 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7227 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7228 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7229 | |
| 7230 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7231 | |
| 7232 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7233 | |
| 7234 | nla_put_failure: |
| 7235 | err = -ENOBUFS; |
| 7236 | free_msg: |
| 7237 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7238 | return err; |
| 7239 | } |
| 7240 | |
| 7241 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7242 | struct genl_info *info) |
| 7243 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7245 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7246 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7247 | |
| 7248 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7249 | return -EINVAL; |
| 7250 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7251 | if (!rdev->ops->cancel_remain_on_channel) |
| 7252 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7253 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7254 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7255 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7256 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7257 | } |
| 7258 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7259 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7260 | u8 *rates, u8 rates_len) |
| 7261 | { |
| 7262 | u8 i; |
| 7263 | u32 mask = 0; |
| 7264 | |
| 7265 | for (i = 0; i < rates_len; i++) { |
| 7266 | int rate = (rates[i] & 0x7f) * 5; |
| 7267 | int ridx; |
| 7268 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7269 | struct ieee80211_rate *srate = |
| 7270 | &sband->bitrates[ridx]; |
| 7271 | if (rate == srate->bitrate) { |
| 7272 | mask |= 1 << ridx; |
| 7273 | break; |
| 7274 | } |
| 7275 | } |
| 7276 | if (ridx == sband->n_bitrates) |
| 7277 | return 0; /* rate not found */ |
| 7278 | } |
| 7279 | |
| 7280 | return mask; |
| 7281 | } |
| 7282 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7283 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7284 | u8 *rates, u8 rates_len, |
| 7285 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7286 | { |
| 7287 | u8 i; |
| 7288 | |
| 7289 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7290 | |
| 7291 | for (i = 0; i < rates_len; i++) { |
| 7292 | int ridx, rbit; |
| 7293 | |
| 7294 | ridx = rates[i] / 8; |
| 7295 | rbit = BIT(rates[i] % 8); |
| 7296 | |
| 7297 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7298 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7299 | return false; |
| 7300 | |
| 7301 | /* check availability */ |
| 7302 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7303 | mcs[ridx] |= rbit; |
| 7304 | else |
| 7305 | return false; |
| 7306 | } |
| 7307 | |
| 7308 | return true; |
| 7309 | } |
| 7310 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7311 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7312 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7313 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7314 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7315 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7316 | }; |
| 7317 | |
| 7318 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7319 | struct genl_info *info) |
| 7320 | { |
| 7321 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7323 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7324 | int rem, i; |
| 7325 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7326 | struct nlattr *tx_rates; |
| 7327 | struct ieee80211_supported_band *sband; |
| 7328 | |
| 7329 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7330 | return -EINVAL; |
| 7331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7332 | if (!rdev->ops->set_bitrate_mask) |
| 7333 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7334 | |
| 7335 | memset(&mask, 0, sizeof(mask)); |
| 7336 | /* Default to all rates enabled */ |
| 7337 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7338 | sband = rdev->wiphy.bands[i]; |
| 7339 | mask.control[i].legacy = |
| 7340 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7341 | if (sband) |
| 7342 | memcpy(mask.control[i].mcs, |
| 7343 | sband->ht_cap.mcs.rx_mask, |
| 7344 | sizeof(mask.control[i].mcs)); |
| 7345 | else |
| 7346 | memset(mask.control[i].mcs, 0, |
| 7347 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7348 | } |
| 7349 | |
| 7350 | /* |
| 7351 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7352 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7353 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7354 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7355 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7356 | { |
| 7357 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7358 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7359 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7360 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7361 | if (sband == NULL) |
| 7362 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7363 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7364 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7365 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7366 | mask.control[band].legacy = rateset_to_mask( |
| 7367 | sband, |
| 7368 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7369 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7370 | if ((mask.control[band].legacy == 0) && |
| 7371 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7372 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7373 | } |
| 7374 | if (tb[NL80211_TXRATE_MCS]) { |
| 7375 | if (!ht_rateset_to_mask( |
| 7376 | sband, |
| 7377 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7378 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7379 | mask.control[band].mcs)) |
| 7380 | return -EINVAL; |
| 7381 | } |
| 7382 | |
| 7383 | if (mask.control[band].legacy == 0) { |
| 7384 | /* don't allow empty legacy rates if HT |
| 7385 | * is not even supported. */ |
| 7386 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7387 | return -EINVAL; |
| 7388 | |
| 7389 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7390 | if (mask.control[band].mcs[i]) |
| 7391 | break; |
| 7392 | |
| 7393 | /* legacy and mcs rates may not be both empty */ |
| 7394 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7395 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7396 | } |
| 7397 | } |
| 7398 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7399 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7400 | } |
| 7401 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7402 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7403 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7405 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7406 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7407 | |
| 7408 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7409 | return -EINVAL; |
| 7410 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7411 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7412 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7413 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7414 | switch (wdev->iftype) { |
| 7415 | case NL80211_IFTYPE_STATION: |
| 7416 | case NL80211_IFTYPE_ADHOC: |
| 7417 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7418 | case NL80211_IFTYPE_AP: |
| 7419 | case NL80211_IFTYPE_AP_VLAN: |
| 7420 | case NL80211_IFTYPE_MESH_POINT: |
| 7421 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7422 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7423 | break; |
| 7424 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7425 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7426 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7427 | |
| 7428 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7429 | if (!rdev->ops->mgmt_tx) |
| 7430 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7431 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7432 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7433 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7434 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7435 | } |
| 7436 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7437 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7438 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7440 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7441 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7442 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7443 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7444 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7445 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7446 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7447 | bool offchan, no_cck, dont_wait_for_ack; |
| 7448 | |
| 7449 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7450 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7451 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7452 | return -EINVAL; |
| 7453 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7454 | if (!rdev->ops->mgmt_tx) |
| 7455 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7456 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7457 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7458 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7459 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7460 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7461 | case NL80211_IFTYPE_STATION: |
| 7462 | case NL80211_IFTYPE_ADHOC: |
| 7463 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7464 | case NL80211_IFTYPE_AP: |
| 7465 | case NL80211_IFTYPE_AP_VLAN: |
| 7466 | case NL80211_IFTYPE_MESH_POINT: |
| 7467 | case NL80211_IFTYPE_P2P_GO: |
| 7468 | break; |
| 7469 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7470 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7471 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7472 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7473 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7474 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7475 | return -EINVAL; |
| 7476 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7477 | |
| 7478 | /* |
| 7479 | * We should wait on the channel for at least a minimum amount |
| 7480 | * of time (10ms) but no longer than the driver supports. |
| 7481 | */ |
| 7482 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7483 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7484 | return -EINVAL; |
| 7485 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7486 | } |
| 7487 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7488 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7489 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7490 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7491 | return -EINVAL; |
| 7492 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7493 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7494 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7495 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7496 | * the driver. The latter will use the current one |
| 7497 | */ |
| 7498 | chandef.chan = NULL; |
| 7499 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7500 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7501 | if (err) |
| 7502 | return err; |
| 7503 | } |
| 7504 | |
| 7505 | if (!chandef.chan && offchan) |
| 7506 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7507 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7508 | if (!dont_wait_for_ack) { |
| 7509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7510 | if (!msg) |
| 7511 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7512 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7513 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7514 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7515 | if (!hdr) { |
| 7516 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7517 | goto free_msg; |
| 7518 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7519 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7520 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7521 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7522 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7523 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7524 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7525 | if (err) |
| 7526 | goto free_msg; |
| 7527 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7528 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7529 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7530 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7531 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7532 | genlmsg_end(msg, hdr); |
| 7533 | return genlmsg_reply(msg, info); |
| 7534 | } |
| 7535 | |
| 7536 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7537 | |
| 7538 | nla_put_failure: |
| 7539 | err = -ENOBUFS; |
| 7540 | free_msg: |
| 7541 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7542 | return err; |
| 7543 | } |
| 7544 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7545 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7546 | { |
| 7547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7548 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7549 | u64 cookie; |
| 7550 | |
| 7551 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7552 | return -EINVAL; |
| 7553 | |
| 7554 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7555 | return -EOPNOTSUPP; |
| 7556 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7557 | switch (wdev->iftype) { |
| 7558 | case NL80211_IFTYPE_STATION: |
| 7559 | case NL80211_IFTYPE_ADHOC: |
| 7560 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7561 | case NL80211_IFTYPE_AP: |
| 7562 | case NL80211_IFTYPE_AP_VLAN: |
| 7563 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7564 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7565 | break; |
| 7566 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7567 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7568 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7569 | |
| 7570 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7571 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7572 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7573 | } |
| 7574 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7575 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7576 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7578 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7579 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7580 | u8 ps_state; |
| 7581 | bool state; |
| 7582 | int err; |
| 7583 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7584 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7585 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7586 | |
| 7587 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7589 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7590 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7591 | |
| 7592 | wdev = dev->ieee80211_ptr; |
| 7593 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7594 | if (!rdev->ops->set_power_mgmt) |
| 7595 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7596 | |
| 7597 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7598 | |
| 7599 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7600 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7601 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7602 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7603 | if (!err) |
| 7604 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7605 | return err; |
| 7606 | } |
| 7607 | |
| 7608 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7609 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7610 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7611 | enum nl80211_ps_state ps_state; |
| 7612 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7613 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7614 | struct sk_buff *msg; |
| 7615 | void *hdr; |
| 7616 | int err; |
| 7617 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7618 | wdev = dev->ieee80211_ptr; |
| 7619 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7620 | if (!rdev->ops->set_power_mgmt) |
| 7621 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7622 | |
| 7623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7624 | if (!msg) |
| 7625 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7626 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7627 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7628 | NL80211_CMD_GET_POWER_SAVE); |
| 7629 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7630 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7631 | goto free_msg; |
| 7632 | } |
| 7633 | |
| 7634 | if (wdev->ps) |
| 7635 | ps_state = NL80211_PS_ENABLED; |
| 7636 | else |
| 7637 | ps_state = NL80211_PS_DISABLED; |
| 7638 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7639 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7640 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7641 | |
| 7642 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7643 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7644 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7645 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7646 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7647 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7648 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7649 | return err; |
| 7650 | } |
| 7651 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7652 | static struct nla_policy |
| 7653 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7654 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7655 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7656 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7657 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7658 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7659 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7660 | }; |
| 7661 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7662 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7663 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7664 | { |
| 7665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7666 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7667 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7668 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7669 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7670 | return -EINVAL; |
| 7671 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7672 | if (!rdev->ops->set_cqm_txe_config) |
| 7673 | return -EOPNOTSUPP; |
| 7674 | |
| 7675 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7676 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7677 | return -EOPNOTSUPP; |
| 7678 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7679 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7680 | } |
| 7681 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7682 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7683 | s32 threshold, u32 hysteresis) |
| 7684 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7685 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7686 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7687 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7688 | |
| 7689 | if (threshold > 0) |
| 7690 | return -EINVAL; |
| 7691 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7692 | /* disabling - hysteresis should also be zero then */ |
| 7693 | if (threshold == 0) |
| 7694 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7695 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7696 | if (!rdev->ops->set_cqm_rssi_config) |
| 7697 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7698 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7699 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7700 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7701 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7702 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7703 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7704 | } |
| 7705 | |
| 7706 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7707 | { |
| 7708 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7709 | struct nlattr *cqm; |
| 7710 | int err; |
| 7711 | |
| 7712 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7713 | if (!cqm) |
| 7714 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7715 | |
| 7716 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7717 | nl80211_attr_cqm_policy); |
| 7718 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7719 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7720 | |
| 7721 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7722 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7723 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7724 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7725 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7726 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7727 | } |
| 7728 | |
| 7729 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7730 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7731 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7732 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7733 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7734 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7735 | |
| 7736 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7737 | } |
| 7738 | |
| 7739 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7740 | } |
| 7741 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7742 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7743 | { |
| 7744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7745 | struct net_device *dev = info->user_ptr[1]; |
| 7746 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7747 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7748 | int err; |
| 7749 | |
| 7750 | /* start with default */ |
| 7751 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7752 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7753 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7754 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7755 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7756 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7757 | if (err) |
| 7758 | return err; |
| 7759 | } |
| 7760 | |
| 7761 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7762 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7763 | return -EINVAL; |
| 7764 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7765 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7766 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7767 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7768 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7769 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7770 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7771 | return -EINVAL; |
| 7772 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7773 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7774 | setup.beacon_interval = |
| 7775 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7776 | if (setup.beacon_interval < 10 || |
| 7777 | setup.beacon_interval > 10000) |
| 7778 | return -EINVAL; |
| 7779 | } |
| 7780 | |
| 7781 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7782 | setup.dtim_period = |
| 7783 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7784 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7785 | return -EINVAL; |
| 7786 | } |
| 7787 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7788 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7789 | /* parse additional setup parameters if given */ |
| 7790 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7791 | if (err) |
| 7792 | return err; |
| 7793 | } |
| 7794 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7795 | if (setup.user_mpm) |
| 7796 | cfg.auto_open_plinks = false; |
| 7797 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7798 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7799 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7800 | if (err) |
| 7801 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7802 | } else { |
| 7803 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7804 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7805 | } |
| 7806 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7807 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7808 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7809 | int n_rates = |
| 7810 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7811 | struct ieee80211_supported_band *sband; |
| 7812 | |
| 7813 | if (!setup.chandef.chan) |
| 7814 | return -EINVAL; |
| 7815 | |
| 7816 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7817 | |
| 7818 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7819 | &setup.basic_rates); |
| 7820 | if (err) |
| 7821 | return err; |
| 7822 | } |
| 7823 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7824 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7825 | } |
| 7826 | |
| 7827 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7828 | { |
| 7829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7830 | struct net_device *dev = info->user_ptr[1]; |
| 7831 | |
| 7832 | return cfg80211_leave_mesh(rdev, dev); |
| 7833 | } |
| 7834 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7835 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7836 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7837 | struct cfg80211_registered_device *rdev) |
| 7838 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7839 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7840 | struct nlattr *nl_pats, *nl_pat; |
| 7841 | int i, pat_len; |
| 7842 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7843 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7844 | return 0; |
| 7845 | |
| 7846 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7847 | if (!nl_pats) |
| 7848 | return -ENOBUFS; |
| 7849 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7850 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7851 | nl_pat = nla_nest_start(msg, i + 1); |
| 7852 | if (!nl_pat) |
| 7853 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7854 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7855 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7856 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7857 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7858 | wowlan->patterns[i].pattern) || |
| 7859 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7860 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7861 | return -ENOBUFS; |
| 7862 | nla_nest_end(msg, nl_pat); |
| 7863 | } |
| 7864 | nla_nest_end(msg, nl_pats); |
| 7865 | |
| 7866 | return 0; |
| 7867 | } |
| 7868 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7869 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7870 | struct cfg80211_wowlan_tcp *tcp) |
| 7871 | { |
| 7872 | struct nlattr *nl_tcp; |
| 7873 | |
| 7874 | if (!tcp) |
| 7875 | return 0; |
| 7876 | |
| 7877 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7878 | if (!nl_tcp) |
| 7879 | return -ENOBUFS; |
| 7880 | |
| 7881 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7882 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7883 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7884 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7885 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7886 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7887 | tcp->payload_len, tcp->payload) || |
| 7888 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7889 | tcp->data_interval) || |
| 7890 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7891 | tcp->wake_len, tcp->wake_data) || |
| 7892 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7893 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7894 | return -ENOBUFS; |
| 7895 | |
| 7896 | if (tcp->payload_seq.len && |
| 7897 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7898 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7899 | return -ENOBUFS; |
| 7900 | |
| 7901 | if (tcp->payload_tok.len && |
| 7902 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7903 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7904 | &tcp->payload_tok)) |
| 7905 | return -ENOBUFS; |
| 7906 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7907 | nla_nest_end(msg, nl_tcp); |
| 7908 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7909 | return 0; |
| 7910 | } |
| 7911 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7912 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7913 | { |
| 7914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7915 | struct sk_buff *msg; |
| 7916 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7917 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7918 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7919 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7920 | return -EOPNOTSUPP; |
| 7921 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7922 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7923 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7924 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7925 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7926 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7927 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7928 | } |
| 7929 | |
| 7930 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7931 | if (!msg) |
| 7932 | return -ENOMEM; |
| 7933 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7934 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7935 | NL80211_CMD_GET_WOWLAN); |
| 7936 | if (!hdr) |
| 7937 | goto nla_put_failure; |
| 7938 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7939 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7940 | struct nlattr *nl_wowlan; |
| 7941 | |
| 7942 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7943 | if (!nl_wowlan) |
| 7944 | goto nla_put_failure; |
| 7945 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7946 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7947 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7948 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7949 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7950 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7951 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7952 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7953 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7954 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7955 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7956 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7957 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7958 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7960 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7961 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7962 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7963 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7964 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7965 | if (nl80211_send_wowlan_tcp(msg, |
| 7966 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7967 | goto nla_put_failure; |
| 7968 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7969 | nla_nest_end(msg, nl_wowlan); |
| 7970 | } |
| 7971 | |
| 7972 | genlmsg_end(msg, hdr); |
| 7973 | return genlmsg_reply(msg, info); |
| 7974 | |
| 7975 | nla_put_failure: |
| 7976 | nlmsg_free(msg); |
| 7977 | return -ENOBUFS; |
| 7978 | } |
| 7979 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7980 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7981 | struct nlattr *attr, |
| 7982 | struct cfg80211_wowlan *trig) |
| 7983 | { |
| 7984 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7985 | struct cfg80211_wowlan_tcp *cfg; |
| 7986 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7987 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7988 | u32 size; |
| 7989 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7990 | int err, port; |
| 7991 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7992 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7993 | return -EINVAL; |
| 7994 | |
| 7995 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7996 | nla_data(attr), nla_len(attr), |
| 7997 | nl80211_wowlan_tcp_policy); |
| 7998 | if (err) |
| 7999 | return err; |
| 8000 | |
| 8001 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8002 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8003 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8004 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8005 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8006 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8007 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8008 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8009 | return -EINVAL; |
| 8010 | |
| 8011 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8012 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8013 | return -EINVAL; |
| 8014 | |
| 8015 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8016 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8017 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8018 | return -EINVAL; |
| 8019 | |
| 8020 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8021 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8022 | return -EINVAL; |
| 8023 | |
| 8024 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8025 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8026 | return -EINVAL; |
| 8027 | |
| 8028 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8029 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8030 | |
| 8031 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8032 | tokens_size = tokln - sizeof(*tok); |
| 8033 | |
| 8034 | if (!tok->len || tokens_size % tok->len) |
| 8035 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8036 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8037 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8038 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8039 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8040 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8041 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8042 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8043 | return -EINVAL; |
| 8044 | if (tok->offset + tok->len > data_size) |
| 8045 | return -EINVAL; |
| 8046 | } |
| 8047 | |
| 8048 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8049 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8050 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8051 | return -EINVAL; |
| 8052 | if (seq->len == 0 || seq->len > 4) |
| 8053 | return -EINVAL; |
| 8054 | if (seq->len + seq->offset > data_size) |
| 8055 | return -EINVAL; |
| 8056 | } |
| 8057 | |
| 8058 | size = sizeof(*cfg); |
| 8059 | size += data_size; |
| 8060 | size += wake_size + wake_mask_size; |
| 8061 | size += tokens_size; |
| 8062 | |
| 8063 | cfg = kzalloc(size, GFP_KERNEL); |
| 8064 | if (!cfg) |
| 8065 | return -ENOMEM; |
| 8066 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8067 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8068 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8069 | ETH_ALEN); |
| 8070 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8071 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8072 | else |
| 8073 | port = 0; |
| 8074 | #ifdef CONFIG_INET |
| 8075 | /* allocate a socket and port for it and use it */ |
| 8076 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8077 | IPPROTO_TCP, &cfg->sock, 1); |
| 8078 | if (err) { |
| 8079 | kfree(cfg); |
| 8080 | return err; |
| 8081 | } |
| 8082 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8083 | sock_release(cfg->sock); |
| 8084 | kfree(cfg); |
| 8085 | return -EADDRINUSE; |
| 8086 | } |
| 8087 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8088 | #else |
| 8089 | if (!port) { |
| 8090 | kfree(cfg); |
| 8091 | return -EINVAL; |
| 8092 | } |
| 8093 | cfg->src_port = port; |
| 8094 | #endif |
| 8095 | |
| 8096 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8097 | cfg->payload_len = data_size; |
| 8098 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8099 | memcpy((void *)cfg->payload, |
| 8100 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8101 | data_size); |
| 8102 | if (seq) |
| 8103 | cfg->payload_seq = *seq; |
| 8104 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8105 | cfg->wake_len = wake_size; |
| 8106 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8107 | memcpy((void *)cfg->wake_data, |
| 8108 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8109 | wake_size); |
| 8110 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8111 | data_size + wake_size; |
| 8112 | memcpy((void *)cfg->wake_mask, |
| 8113 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8114 | wake_mask_size); |
| 8115 | if (tok) { |
| 8116 | cfg->tokens_size = tokens_size; |
| 8117 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8118 | } |
| 8119 | |
| 8120 | trig->tcp = cfg; |
| 8121 | |
| 8122 | return 0; |
| 8123 | } |
| 8124 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8125 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8126 | { |
| 8127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8128 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8129 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8130 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8131 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8132 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8133 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8134 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8135 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8136 | return -EOPNOTSUPP; |
| 8137 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8138 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8139 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8140 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8141 | goto set_wakeup; |
| 8142 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8143 | |
| 8144 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8145 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8146 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8147 | nl80211_wowlan_policy); |
| 8148 | if (err) |
| 8149 | return err; |
| 8150 | |
| 8151 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8152 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8153 | return -EINVAL; |
| 8154 | new_triggers.any = true; |
| 8155 | } |
| 8156 | |
| 8157 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8158 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8159 | return -EINVAL; |
| 8160 | new_triggers.disconnect = true; |
| 8161 | } |
| 8162 | |
| 8163 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8164 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8165 | return -EINVAL; |
| 8166 | new_triggers.magic_pkt = true; |
| 8167 | } |
| 8168 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8169 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8170 | return -EINVAL; |
| 8171 | |
| 8172 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8173 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8174 | return -EINVAL; |
| 8175 | new_triggers.gtk_rekey_failure = true; |
| 8176 | } |
| 8177 | |
| 8178 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8179 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8180 | return -EINVAL; |
| 8181 | new_triggers.eap_identity_req = true; |
| 8182 | } |
| 8183 | |
| 8184 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8185 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8186 | return -EINVAL; |
| 8187 | new_triggers.four_way_handshake = true; |
| 8188 | } |
| 8189 | |
| 8190 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8191 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8192 | return -EINVAL; |
| 8193 | new_triggers.rfkill_release = true; |
| 8194 | } |
| 8195 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8196 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8197 | struct nlattr *pat; |
| 8198 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8199 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8200 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8201 | |
| 8202 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8203 | rem) |
| 8204 | n_patterns++; |
| 8205 | if (n_patterns > wowlan->n_patterns) |
| 8206 | return -EINVAL; |
| 8207 | |
| 8208 | new_triggers.patterns = kcalloc(n_patterns, |
| 8209 | sizeof(new_triggers.patterns[0]), |
| 8210 | GFP_KERNEL); |
| 8211 | if (!new_triggers.patterns) |
| 8212 | return -ENOMEM; |
| 8213 | |
| 8214 | new_triggers.n_patterns = n_patterns; |
| 8215 | i = 0; |
| 8216 | |
| 8217 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8218 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8219 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8220 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8221 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8222 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8223 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8224 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8225 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8226 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8227 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8228 | goto error; |
| 8229 | if (pat_len > wowlan->pattern_max_len || |
| 8230 | pat_len < wowlan->pattern_min_len) |
| 8231 | goto error; |
| 8232 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8233 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8234 | pkt_offset = 0; |
| 8235 | else |
| 8236 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8237 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8238 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8239 | goto error; |
| 8240 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8241 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8242 | new_triggers.patterns[i].mask = |
| 8243 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8244 | if (!new_triggers.patterns[i].mask) { |
| 8245 | err = -ENOMEM; |
| 8246 | goto error; |
| 8247 | } |
| 8248 | new_triggers.patterns[i].pattern = |
| 8249 | new_triggers.patterns[i].mask + mask_len; |
| 8250 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8251 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8252 | mask_len); |
| 8253 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8254 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8255 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8256 | pat_len); |
| 8257 | i++; |
| 8258 | } |
| 8259 | } |
| 8260 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8261 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8262 | err = nl80211_parse_wowlan_tcp( |
| 8263 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8264 | &new_triggers); |
| 8265 | if (err) |
| 8266 | goto error; |
| 8267 | } |
| 8268 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8269 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8270 | if (!ntrig) { |
| 8271 | err = -ENOMEM; |
| 8272 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8273 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8274 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8275 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8276 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8277 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8278 | if (rdev->ops->set_wakeup && |
| 8279 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8280 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8281 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8282 | return 0; |
| 8283 | error: |
| 8284 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8285 | kfree(new_triggers.patterns[i].mask); |
| 8286 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8287 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8288 | sock_release(new_triggers.tcp->sock); |
| 8289 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8290 | return err; |
| 8291 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8292 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8293 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8294 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8295 | struct cfg80211_registered_device *rdev) |
| 8296 | { |
| 8297 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8298 | int i, j, pat_len; |
| 8299 | struct cfg80211_coalesce_rules *rule; |
| 8300 | |
| 8301 | if (!rdev->coalesce->n_rules) |
| 8302 | return 0; |
| 8303 | |
| 8304 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8305 | if (!nl_rules) |
| 8306 | return -ENOBUFS; |
| 8307 | |
| 8308 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8309 | nl_rule = nla_nest_start(msg, i + 1); |
| 8310 | if (!nl_rule) |
| 8311 | return -ENOBUFS; |
| 8312 | |
| 8313 | rule = &rdev->coalesce->rules[i]; |
| 8314 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8315 | rule->delay)) |
| 8316 | return -ENOBUFS; |
| 8317 | |
| 8318 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8319 | rule->condition)) |
| 8320 | return -ENOBUFS; |
| 8321 | |
| 8322 | nl_pats = nla_nest_start(msg, |
| 8323 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8324 | if (!nl_pats) |
| 8325 | return -ENOBUFS; |
| 8326 | |
| 8327 | for (j = 0; j < rule->n_patterns; j++) { |
| 8328 | nl_pat = nla_nest_start(msg, j + 1); |
| 8329 | if (!nl_pat) |
| 8330 | return -ENOBUFS; |
| 8331 | pat_len = rule->patterns[j].pattern_len; |
| 8332 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8333 | DIV_ROUND_UP(pat_len, 8), |
| 8334 | rule->patterns[j].mask) || |
| 8335 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8336 | rule->patterns[j].pattern) || |
| 8337 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8338 | rule->patterns[j].pkt_offset)) |
| 8339 | return -ENOBUFS; |
| 8340 | nla_nest_end(msg, nl_pat); |
| 8341 | } |
| 8342 | nla_nest_end(msg, nl_pats); |
| 8343 | nla_nest_end(msg, nl_rule); |
| 8344 | } |
| 8345 | nla_nest_end(msg, nl_rules); |
| 8346 | |
| 8347 | return 0; |
| 8348 | } |
| 8349 | |
| 8350 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8351 | { |
| 8352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8353 | struct sk_buff *msg; |
| 8354 | void *hdr; |
| 8355 | |
| 8356 | if (!rdev->wiphy.coalesce) |
| 8357 | return -EOPNOTSUPP; |
| 8358 | |
| 8359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8360 | if (!msg) |
| 8361 | return -ENOMEM; |
| 8362 | |
| 8363 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8364 | NL80211_CMD_GET_COALESCE); |
| 8365 | if (!hdr) |
| 8366 | goto nla_put_failure; |
| 8367 | |
| 8368 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8369 | goto nla_put_failure; |
| 8370 | |
| 8371 | genlmsg_end(msg, hdr); |
| 8372 | return genlmsg_reply(msg, info); |
| 8373 | |
| 8374 | nla_put_failure: |
| 8375 | nlmsg_free(msg); |
| 8376 | return -ENOBUFS; |
| 8377 | } |
| 8378 | |
| 8379 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8380 | { |
| 8381 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8382 | int i, j; |
| 8383 | struct cfg80211_coalesce_rules *rule; |
| 8384 | |
| 8385 | if (!coalesce) |
| 8386 | return; |
| 8387 | |
| 8388 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8389 | rule = &coalesce->rules[i]; |
| 8390 | for (j = 0; j < rule->n_patterns; j++) |
| 8391 | kfree(rule->patterns[j].mask); |
| 8392 | kfree(rule->patterns); |
| 8393 | } |
| 8394 | kfree(coalesce->rules); |
| 8395 | kfree(coalesce); |
| 8396 | rdev->coalesce = NULL; |
| 8397 | } |
| 8398 | |
| 8399 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8400 | struct nlattr *rule, |
| 8401 | struct cfg80211_coalesce_rules *new_rule) |
| 8402 | { |
| 8403 | int err, i; |
| 8404 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8405 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8406 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8407 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8408 | |
| 8409 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8410 | nla_len(rule), nl80211_coalesce_policy); |
| 8411 | if (err) |
| 8412 | return err; |
| 8413 | |
| 8414 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8415 | new_rule->delay = |
| 8416 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8417 | if (new_rule->delay > coalesce->max_delay) |
| 8418 | return -EINVAL; |
| 8419 | |
| 8420 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8421 | new_rule->condition = |
| 8422 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8423 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8424 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8425 | return -EINVAL; |
| 8426 | |
| 8427 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8428 | return -EINVAL; |
| 8429 | |
| 8430 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8431 | rem) |
| 8432 | n_patterns++; |
| 8433 | if (n_patterns > coalesce->n_patterns) |
| 8434 | return -EINVAL; |
| 8435 | |
| 8436 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8437 | GFP_KERNEL); |
| 8438 | if (!new_rule->patterns) |
| 8439 | return -ENOMEM; |
| 8440 | |
| 8441 | new_rule->n_patterns = n_patterns; |
| 8442 | i = 0; |
| 8443 | |
| 8444 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8445 | rem) { |
| 8446 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8447 | nla_len(pat), NULL); |
| 8448 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8449 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8450 | return -EINVAL; |
| 8451 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8452 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8453 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8454 | return -EINVAL; |
| 8455 | if (pat_len > coalesce->pattern_max_len || |
| 8456 | pat_len < coalesce->pattern_min_len) |
| 8457 | return -EINVAL; |
| 8458 | |
| 8459 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8460 | pkt_offset = 0; |
| 8461 | else |
| 8462 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8463 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8464 | return -EINVAL; |
| 8465 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8466 | |
| 8467 | new_rule->patterns[i].mask = |
| 8468 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8469 | if (!new_rule->patterns[i].mask) |
| 8470 | return -ENOMEM; |
| 8471 | new_rule->patterns[i].pattern = |
| 8472 | new_rule->patterns[i].mask + mask_len; |
| 8473 | memcpy(new_rule->patterns[i].mask, |
| 8474 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8475 | new_rule->patterns[i].pattern_len = pat_len; |
| 8476 | memcpy(new_rule->patterns[i].pattern, |
| 8477 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8478 | i++; |
| 8479 | } |
| 8480 | |
| 8481 | return 0; |
| 8482 | } |
| 8483 | |
| 8484 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8485 | { |
| 8486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8487 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8488 | struct cfg80211_coalesce new_coalesce = {}; |
| 8489 | struct cfg80211_coalesce *n_coalesce; |
| 8490 | int err, rem_rule, n_rules = 0, i, j; |
| 8491 | struct nlattr *rule; |
| 8492 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8493 | |
| 8494 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8495 | return -EOPNOTSUPP; |
| 8496 | |
| 8497 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8498 | cfg80211_rdev_free_coalesce(rdev); |
| 8499 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8500 | return 0; |
| 8501 | } |
| 8502 | |
| 8503 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8504 | rem_rule) |
| 8505 | n_rules++; |
| 8506 | if (n_rules > coalesce->n_rules) |
| 8507 | return -EINVAL; |
| 8508 | |
| 8509 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8510 | GFP_KERNEL); |
| 8511 | if (!new_coalesce.rules) |
| 8512 | return -ENOMEM; |
| 8513 | |
| 8514 | new_coalesce.n_rules = n_rules; |
| 8515 | i = 0; |
| 8516 | |
| 8517 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8518 | rem_rule) { |
| 8519 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8520 | &new_coalesce.rules[i]); |
| 8521 | if (err) |
| 8522 | goto error; |
| 8523 | |
| 8524 | i++; |
| 8525 | } |
| 8526 | |
| 8527 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8528 | if (err) |
| 8529 | goto error; |
| 8530 | |
| 8531 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8532 | if (!n_coalesce) { |
| 8533 | err = -ENOMEM; |
| 8534 | goto error; |
| 8535 | } |
| 8536 | cfg80211_rdev_free_coalesce(rdev); |
| 8537 | rdev->coalesce = n_coalesce; |
| 8538 | |
| 8539 | return 0; |
| 8540 | error: |
| 8541 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8542 | tmp_rule = &new_coalesce.rules[i]; |
| 8543 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8544 | kfree(tmp_rule->patterns[j].mask); |
| 8545 | kfree(tmp_rule->patterns); |
| 8546 | } |
| 8547 | kfree(new_coalesce.rules); |
| 8548 | |
| 8549 | return err; |
| 8550 | } |
| 8551 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8552 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8553 | { |
| 8554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8555 | struct net_device *dev = info->user_ptr[1]; |
| 8556 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8557 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8558 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8559 | int err; |
| 8560 | |
| 8561 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8562 | return -EINVAL; |
| 8563 | |
| 8564 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8565 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8566 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8567 | nl80211_rekey_policy); |
| 8568 | if (err) |
| 8569 | return err; |
| 8570 | |
| 8571 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8572 | return -ERANGE; |
| 8573 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8574 | return -ERANGE; |
| 8575 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8576 | return -ERANGE; |
| 8577 | |
| 8578 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8579 | NL80211_KEK_LEN); |
| 8580 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8581 | NL80211_KCK_LEN); |
| 8582 | memcpy(rekey_data.replay_ctr, |
| 8583 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8584 | NL80211_REPLAY_CTR_LEN); |
| 8585 | |
| 8586 | wdev_lock(wdev); |
| 8587 | if (!wdev->current_bss) { |
| 8588 | err = -ENOTCONN; |
| 8589 | goto out; |
| 8590 | } |
| 8591 | |
| 8592 | if (!rdev->ops->set_rekey_data) { |
| 8593 | err = -EOPNOTSUPP; |
| 8594 | goto out; |
| 8595 | } |
| 8596 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8597 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8598 | out: |
| 8599 | wdev_unlock(wdev); |
| 8600 | return err; |
| 8601 | } |
| 8602 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8603 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8604 | struct genl_info *info) |
| 8605 | { |
| 8606 | struct net_device *dev = info->user_ptr[1]; |
| 8607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8608 | |
| 8609 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8610 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8611 | return -EINVAL; |
| 8612 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8613 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8614 | return -EBUSY; |
| 8615 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8616 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8617 | return 0; |
| 8618 | } |
| 8619 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8620 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8621 | struct genl_info *info) |
| 8622 | { |
| 8623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8624 | struct net_device *dev = info->user_ptr[1]; |
| 8625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8626 | struct sk_buff *msg; |
| 8627 | void *hdr; |
| 8628 | const u8 *addr; |
| 8629 | u64 cookie; |
| 8630 | int err; |
| 8631 | |
| 8632 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8633 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8634 | return -EOPNOTSUPP; |
| 8635 | |
| 8636 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8637 | return -EINVAL; |
| 8638 | |
| 8639 | if (!rdev->ops->probe_client) |
| 8640 | return -EOPNOTSUPP; |
| 8641 | |
| 8642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8643 | if (!msg) |
| 8644 | return -ENOMEM; |
| 8645 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8646 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8647 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8648 | if (!hdr) { |
| 8649 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8650 | goto free_msg; |
| 8651 | } |
| 8652 | |
| 8653 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8654 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8655 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8656 | if (err) |
| 8657 | goto free_msg; |
| 8658 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8659 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8660 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8661 | |
| 8662 | genlmsg_end(msg, hdr); |
| 8663 | |
| 8664 | return genlmsg_reply(msg, info); |
| 8665 | |
| 8666 | nla_put_failure: |
| 8667 | err = -ENOBUFS; |
| 8668 | free_msg: |
| 8669 | nlmsg_free(msg); |
| 8670 | return err; |
| 8671 | } |
| 8672 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8673 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8674 | { |
| 8675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8676 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8677 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8678 | |
| 8679 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8680 | return -EOPNOTSUPP; |
| 8681 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8682 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8683 | if (!nreg) |
| 8684 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8685 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8686 | /* First, check if already registered. */ |
| 8687 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8688 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8689 | if (reg->nlportid == info->snd_portid) { |
| 8690 | rv = -EALREADY; |
| 8691 | goto out_err; |
| 8692 | } |
| 8693 | } |
| 8694 | /* Add it to the list */ |
| 8695 | nreg->nlportid = info->snd_portid; |
| 8696 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8697 | |
| 8698 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8699 | |
| 8700 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8701 | out_err: |
| 8702 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8703 | kfree(nreg); |
| 8704 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8705 | } |
| 8706 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8707 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8708 | { |
| 8709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8710 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8711 | int err; |
| 8712 | |
| 8713 | if (!rdev->ops->start_p2p_device) |
| 8714 | return -EOPNOTSUPP; |
| 8715 | |
| 8716 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8717 | return -EOPNOTSUPP; |
| 8718 | |
| 8719 | if (wdev->p2p_started) |
| 8720 | return 0; |
| 8721 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8722 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8723 | if (err) |
| 8724 | return err; |
| 8725 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8726 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8727 | if (err) |
| 8728 | return err; |
| 8729 | |
| 8730 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8731 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8732 | |
| 8733 | return 0; |
| 8734 | } |
| 8735 | |
| 8736 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8737 | { |
| 8738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8739 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8740 | |
| 8741 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8742 | return -EOPNOTSUPP; |
| 8743 | |
| 8744 | if (!rdev->ops->stop_p2p_device) |
| 8745 | return -EOPNOTSUPP; |
| 8746 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8747 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8748 | |
| 8749 | return 0; |
| 8750 | } |
| 8751 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8752 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8753 | struct genl_info *info) |
| 8754 | { |
| 8755 | void *hdr; |
| 8756 | struct sk_buff *msg; |
| 8757 | |
| 8758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8759 | if (!msg) |
| 8760 | return -ENOMEM; |
| 8761 | |
| 8762 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8763 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8764 | if (!hdr) |
| 8765 | goto nla_put_failure; |
| 8766 | |
| 8767 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8768 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8769 | goto nla_put_failure; |
| 8770 | |
| 8771 | genlmsg_end(msg, hdr); |
| 8772 | return genlmsg_reply(msg, info); |
| 8773 | |
| 8774 | nla_put_failure: |
| 8775 | kfree_skb(msg); |
| 8776 | return -ENOBUFS; |
| 8777 | } |
| 8778 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8779 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8780 | { |
| 8781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8782 | struct cfg80211_update_ft_ies_params ft_params; |
| 8783 | struct net_device *dev = info->user_ptr[1]; |
| 8784 | |
| 8785 | if (!rdev->ops->update_ft_ies) |
| 8786 | return -EOPNOTSUPP; |
| 8787 | |
| 8788 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8789 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8790 | return -EINVAL; |
| 8791 | |
| 8792 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8793 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8794 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8795 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8796 | |
| 8797 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8798 | } |
| 8799 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8800 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8801 | struct genl_info *info) |
| 8802 | { |
| 8803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8804 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8805 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8806 | u16 duration; |
| 8807 | int ret; |
| 8808 | |
| 8809 | if (!rdev->ops->crit_proto_start) |
| 8810 | return -EOPNOTSUPP; |
| 8811 | |
| 8812 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8813 | return -EINVAL; |
| 8814 | |
| 8815 | if (rdev->crit_proto_nlportid) |
| 8816 | return -EBUSY; |
| 8817 | |
| 8818 | /* determine protocol if provided */ |
| 8819 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8820 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8821 | |
| 8822 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8823 | return -EINVAL; |
| 8824 | |
| 8825 | /* timeout must be provided */ |
| 8826 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8827 | return -EINVAL; |
| 8828 | |
| 8829 | duration = |
| 8830 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8831 | |
| 8832 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8833 | return -ERANGE; |
| 8834 | |
| 8835 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8836 | if (!ret) |
| 8837 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8838 | |
| 8839 | return ret; |
| 8840 | } |
| 8841 | |
| 8842 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8843 | struct genl_info *info) |
| 8844 | { |
| 8845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8846 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8847 | |
| 8848 | if (!rdev->ops->crit_proto_stop) |
| 8849 | return -EOPNOTSUPP; |
| 8850 | |
| 8851 | if (rdev->crit_proto_nlportid) { |
| 8852 | rdev->crit_proto_nlportid = 0; |
| 8853 | rdev_crit_proto_stop(rdev, wdev); |
| 8854 | } |
| 8855 | return 0; |
| 8856 | } |
| 8857 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8858 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8859 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8860 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8861 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8862 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8863 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8864 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8865 | /* If a netdev is associated, it must be UP, P2P must be started */ |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8866 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8867 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8868 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 8869 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8870 | struct genl_info *info) |
| 8871 | { |
| 8872 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8873 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8874 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8875 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8876 | |
| 8877 | if (rtnl) |
| 8878 | rtnl_lock(); |
| 8879 | |
| 8880 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8881 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8882 | if (IS_ERR(rdev)) { |
| 8883 | if (rtnl) |
| 8884 | rtnl_unlock(); |
| 8885 | return PTR_ERR(rdev); |
| 8886 | } |
| 8887 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8888 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8889 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8890 | ASSERT_RTNL(); |
| 8891 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8892 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8893 | info->attrs); |
| 8894 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8895 | if (rtnl) |
| 8896 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8897 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8898 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8899 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8900 | dev = wdev->netdev; |
| 8901 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8902 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8903 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8904 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8905 | if (rtnl) |
| 8906 | rtnl_unlock(); |
| 8907 | return -EINVAL; |
| 8908 | } |
| 8909 | |
| 8910 | info->user_ptr[1] = dev; |
| 8911 | } else { |
| 8912 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8913 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8914 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8915 | if (dev) { |
| 8916 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8917 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8918 | if (rtnl) |
| 8919 | rtnl_unlock(); |
| 8920 | return -ENETDOWN; |
| 8921 | } |
| 8922 | |
| 8923 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8924 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8925 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8926 | if (rtnl) |
| 8927 | rtnl_unlock(); |
| 8928 | return -ENETDOWN; |
| 8929 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8930 | } |
| 8931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8932 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8933 | } |
| 8934 | |
| 8935 | return 0; |
| 8936 | } |
| 8937 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 8938 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8939 | struct genl_info *info) |
| 8940 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8941 | if (info->user_ptr[1]) { |
| 8942 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8943 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8944 | |
| 8945 | if (wdev->netdev) |
| 8946 | dev_put(wdev->netdev); |
| 8947 | } else { |
| 8948 | dev_put(info->user_ptr[1]); |
| 8949 | } |
| 8950 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8951 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8952 | rtnl_unlock(); |
| 8953 | } |
| 8954 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 8955 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8956 | { |
| 8957 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8958 | .doit = nl80211_get_wiphy, |
| 8959 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8960 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8961 | .policy = nl80211_policy, |
| 8962 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8963 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8964 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8965 | }, |
| 8966 | { |
| 8967 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8968 | .doit = nl80211_set_wiphy, |
| 8969 | .policy = nl80211_policy, |
| 8970 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8971 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8972 | }, |
| 8973 | { |
| 8974 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8975 | .doit = nl80211_get_interface, |
| 8976 | .dumpit = nl80211_dump_interface, |
| 8977 | .policy = nl80211_policy, |
| 8978 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8979 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8980 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8981 | }, |
| 8982 | { |
| 8983 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8984 | .doit = nl80211_set_interface, |
| 8985 | .policy = nl80211_policy, |
| 8986 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8987 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8988 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8989 | }, |
| 8990 | { |
| 8991 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8992 | .doit = nl80211_new_interface, |
| 8993 | .policy = nl80211_policy, |
| 8994 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8995 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8996 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8997 | }, |
| 8998 | { |
| 8999 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9000 | .doit = nl80211_del_interface, |
| 9001 | .policy = nl80211_policy, |
| 9002 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9003 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9004 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9005 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9006 | { |
| 9007 | .cmd = NL80211_CMD_GET_KEY, |
| 9008 | .doit = nl80211_get_key, |
| 9009 | .policy = nl80211_policy, |
| 9010 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9012 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9013 | }, |
| 9014 | { |
| 9015 | .cmd = NL80211_CMD_SET_KEY, |
| 9016 | .doit = nl80211_set_key, |
| 9017 | .policy = nl80211_policy, |
| 9018 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9020 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9021 | }, |
| 9022 | { |
| 9023 | .cmd = NL80211_CMD_NEW_KEY, |
| 9024 | .doit = nl80211_new_key, |
| 9025 | .policy = nl80211_policy, |
| 9026 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9028 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9029 | }, |
| 9030 | { |
| 9031 | .cmd = NL80211_CMD_DEL_KEY, |
| 9032 | .doit = nl80211_del_key, |
| 9033 | .policy = nl80211_policy, |
| 9034 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9036 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9037 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9038 | { |
| 9039 | .cmd = NL80211_CMD_SET_BEACON, |
| 9040 | .policy = nl80211_policy, |
| 9041 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9042 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9043 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9044 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9045 | }, |
| 9046 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9047 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9048 | .policy = nl80211_policy, |
| 9049 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9050 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9051 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9052 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9053 | }, |
| 9054 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9055 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9056 | .policy = nl80211_policy, |
| 9057 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9058 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9060 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9061 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9062 | { |
| 9063 | .cmd = NL80211_CMD_GET_STATION, |
| 9064 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9065 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9066 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9067 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9068 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9069 | }, |
| 9070 | { |
| 9071 | .cmd = NL80211_CMD_SET_STATION, |
| 9072 | .doit = nl80211_set_station, |
| 9073 | .policy = nl80211_policy, |
| 9074 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9075 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9076 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9077 | }, |
| 9078 | { |
| 9079 | .cmd = NL80211_CMD_NEW_STATION, |
| 9080 | .doit = nl80211_new_station, |
| 9081 | .policy = nl80211_policy, |
| 9082 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9083 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9084 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9085 | }, |
| 9086 | { |
| 9087 | .cmd = NL80211_CMD_DEL_STATION, |
| 9088 | .doit = nl80211_del_station, |
| 9089 | .policy = nl80211_policy, |
| 9090 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9091 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9092 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9093 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9094 | { |
| 9095 | .cmd = NL80211_CMD_GET_MPATH, |
| 9096 | .doit = nl80211_get_mpath, |
| 9097 | .dumpit = nl80211_dump_mpath, |
| 9098 | .policy = nl80211_policy, |
| 9099 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9101 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9102 | }, |
| 9103 | { |
| 9104 | .cmd = NL80211_CMD_SET_MPATH, |
| 9105 | .doit = nl80211_set_mpath, |
| 9106 | .policy = nl80211_policy, |
| 9107 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9108 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9109 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9110 | }, |
| 9111 | { |
| 9112 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9113 | .doit = nl80211_new_mpath, |
| 9114 | .policy = nl80211_policy, |
| 9115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9117 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9118 | }, |
| 9119 | { |
| 9120 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9121 | .doit = nl80211_del_mpath, |
| 9122 | .policy = nl80211_policy, |
| 9123 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9124 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9125 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9126 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9127 | { |
| 9128 | .cmd = NL80211_CMD_SET_BSS, |
| 9129 | .doit = nl80211_set_bss, |
| 9130 | .policy = nl80211_policy, |
| 9131 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9132 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9133 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9134 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9135 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9136 | .cmd = NL80211_CMD_GET_REG, |
| 9137 | .doit = nl80211_get_reg, |
| 9138 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9139 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9140 | /* can be retrieved by unprivileged users */ |
| 9141 | }, |
| 9142 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9143 | .cmd = NL80211_CMD_SET_REG, |
| 9144 | .doit = nl80211_set_reg, |
| 9145 | .policy = nl80211_policy, |
| 9146 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9147 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9148 | }, |
| 9149 | { |
| 9150 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9151 | .doit = nl80211_req_set_reg, |
| 9152 | .policy = nl80211_policy, |
| 9153 | .flags = GENL_ADMIN_PERM, |
| 9154 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9155 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9156 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9157 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9158 | .policy = nl80211_policy, |
| 9159 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9160 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9161 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9162 | }, |
| 9163 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9164 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9165 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9166 | .policy = nl80211_policy, |
| 9167 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9168 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9169 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9170 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9171 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9172 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9173 | .doit = nl80211_trigger_scan, |
| 9174 | .policy = nl80211_policy, |
| 9175 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9176 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9177 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9178 | }, |
| 9179 | { |
| 9180 | .cmd = NL80211_CMD_GET_SCAN, |
| 9181 | .policy = nl80211_policy, |
| 9182 | .dumpit = nl80211_dump_scan, |
| 9183 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9184 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9185 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9186 | .doit = nl80211_start_sched_scan, |
| 9187 | .policy = nl80211_policy, |
| 9188 | .flags = GENL_ADMIN_PERM, |
| 9189 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9190 | NL80211_FLAG_NEED_RTNL, |
| 9191 | }, |
| 9192 | { |
| 9193 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9194 | .doit = nl80211_stop_sched_scan, |
| 9195 | .policy = nl80211_policy, |
| 9196 | .flags = GENL_ADMIN_PERM, |
| 9197 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9198 | NL80211_FLAG_NEED_RTNL, |
| 9199 | }, |
| 9200 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9201 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9202 | .doit = nl80211_authenticate, |
| 9203 | .policy = nl80211_policy, |
| 9204 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9205 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9206 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9207 | }, |
| 9208 | { |
| 9209 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9210 | .doit = nl80211_associate, |
| 9211 | .policy = nl80211_policy, |
| 9212 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9213 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9214 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9215 | }, |
| 9216 | { |
| 9217 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9218 | .doit = nl80211_deauthenticate, |
| 9219 | .policy = nl80211_policy, |
| 9220 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9221 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9222 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9223 | }, |
| 9224 | { |
| 9225 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9226 | .doit = nl80211_disassociate, |
| 9227 | .policy = nl80211_policy, |
| 9228 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9229 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9230 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9231 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9232 | { |
| 9233 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9234 | .doit = nl80211_join_ibss, |
| 9235 | .policy = nl80211_policy, |
| 9236 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9237 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9238 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9239 | }, |
| 9240 | { |
| 9241 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9242 | .doit = nl80211_leave_ibss, |
| 9243 | .policy = nl80211_policy, |
| 9244 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9245 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9246 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9247 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9248 | #ifdef CONFIG_NL80211_TESTMODE |
| 9249 | { |
| 9250 | .cmd = NL80211_CMD_TESTMODE, |
| 9251 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9252 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9253 | .policy = nl80211_policy, |
| 9254 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9255 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9256 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9257 | }, |
| 9258 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9259 | { |
| 9260 | .cmd = NL80211_CMD_CONNECT, |
| 9261 | .doit = nl80211_connect, |
| 9262 | .policy = nl80211_policy, |
| 9263 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9264 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9265 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9266 | }, |
| 9267 | { |
| 9268 | .cmd = NL80211_CMD_DISCONNECT, |
| 9269 | .doit = nl80211_disconnect, |
| 9270 | .policy = nl80211_policy, |
| 9271 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9272 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9273 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9274 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9275 | { |
| 9276 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9277 | .doit = nl80211_wiphy_netns, |
| 9278 | .policy = nl80211_policy, |
| 9279 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9280 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9281 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9282 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9283 | { |
| 9284 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9285 | .policy = nl80211_policy, |
| 9286 | .dumpit = nl80211_dump_survey, |
| 9287 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9288 | { |
| 9289 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9290 | .doit = nl80211_setdel_pmksa, |
| 9291 | .policy = nl80211_policy, |
| 9292 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9293 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9294 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9295 | }, |
| 9296 | { |
| 9297 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9298 | .doit = nl80211_setdel_pmksa, |
| 9299 | .policy = nl80211_policy, |
| 9300 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9301 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9302 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9303 | }, |
| 9304 | { |
| 9305 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9306 | .doit = nl80211_flush_pmksa, |
| 9307 | .policy = nl80211_policy, |
| 9308 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9309 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9310 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9311 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9312 | { |
| 9313 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9314 | .doit = nl80211_remain_on_channel, |
| 9315 | .policy = nl80211_policy, |
| 9316 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9317 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9318 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9319 | }, |
| 9320 | { |
| 9321 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9322 | .doit = nl80211_cancel_remain_on_channel, |
| 9323 | .policy = nl80211_policy, |
| 9324 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9325 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9326 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9327 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9328 | { |
| 9329 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9330 | .doit = nl80211_set_tx_bitrate_mask, |
| 9331 | .policy = nl80211_policy, |
| 9332 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9333 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9334 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9335 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9336 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9337 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9338 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9339 | .policy = nl80211_policy, |
| 9340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9341 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9342 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9343 | }, |
| 9344 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9345 | .cmd = NL80211_CMD_FRAME, |
| 9346 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9347 | .policy = nl80211_policy, |
| 9348 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9349 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9350 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9351 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9352 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9353 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9354 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9355 | .policy = nl80211_policy, |
| 9356 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9357 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9358 | NL80211_FLAG_NEED_RTNL, |
| 9359 | }, |
| 9360 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9361 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9362 | .doit = nl80211_set_power_save, |
| 9363 | .policy = nl80211_policy, |
| 9364 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9365 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9366 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9367 | }, |
| 9368 | { |
| 9369 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9370 | .doit = nl80211_get_power_save, |
| 9371 | .policy = nl80211_policy, |
| 9372 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9373 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9374 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9375 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9376 | { |
| 9377 | .cmd = NL80211_CMD_SET_CQM, |
| 9378 | .doit = nl80211_set_cqm, |
| 9379 | .policy = nl80211_policy, |
| 9380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9381 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9382 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9383 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9384 | { |
| 9385 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9386 | .doit = nl80211_set_channel, |
| 9387 | .policy = nl80211_policy, |
| 9388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9389 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9390 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9391 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9392 | { |
| 9393 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9394 | .doit = nl80211_set_wds_peer, |
| 9395 | .policy = nl80211_policy, |
| 9396 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9397 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9398 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9399 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9400 | { |
| 9401 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9402 | .doit = nl80211_join_mesh, |
| 9403 | .policy = nl80211_policy, |
| 9404 | .flags = GENL_ADMIN_PERM, |
| 9405 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9406 | NL80211_FLAG_NEED_RTNL, |
| 9407 | }, |
| 9408 | { |
| 9409 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9410 | .doit = nl80211_leave_mesh, |
| 9411 | .policy = nl80211_policy, |
| 9412 | .flags = GENL_ADMIN_PERM, |
| 9413 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9414 | NL80211_FLAG_NEED_RTNL, |
| 9415 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9416 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9417 | { |
| 9418 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9419 | .doit = nl80211_get_wowlan, |
| 9420 | .policy = nl80211_policy, |
| 9421 | /* can be retrieved by unprivileged users */ |
| 9422 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9423 | NL80211_FLAG_NEED_RTNL, |
| 9424 | }, |
| 9425 | { |
| 9426 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9427 | .doit = nl80211_set_wowlan, |
| 9428 | .policy = nl80211_policy, |
| 9429 | .flags = GENL_ADMIN_PERM, |
| 9430 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9431 | NL80211_FLAG_NEED_RTNL, |
| 9432 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9433 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9434 | { |
| 9435 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9436 | .doit = nl80211_set_rekey_data, |
| 9437 | .policy = nl80211_policy, |
| 9438 | .flags = GENL_ADMIN_PERM, |
| 9439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9440 | NL80211_FLAG_NEED_RTNL, |
| 9441 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9442 | { |
| 9443 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9444 | .doit = nl80211_tdls_mgmt, |
| 9445 | .policy = nl80211_policy, |
| 9446 | .flags = GENL_ADMIN_PERM, |
| 9447 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9448 | NL80211_FLAG_NEED_RTNL, |
| 9449 | }, |
| 9450 | { |
| 9451 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9452 | .doit = nl80211_tdls_oper, |
| 9453 | .policy = nl80211_policy, |
| 9454 | .flags = GENL_ADMIN_PERM, |
| 9455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9456 | NL80211_FLAG_NEED_RTNL, |
| 9457 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9458 | { |
| 9459 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9460 | .doit = nl80211_register_unexpected_frame, |
| 9461 | .policy = nl80211_policy, |
| 9462 | .flags = GENL_ADMIN_PERM, |
| 9463 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9464 | NL80211_FLAG_NEED_RTNL, |
| 9465 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9466 | { |
| 9467 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9468 | .doit = nl80211_probe_client, |
| 9469 | .policy = nl80211_policy, |
| 9470 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9472 | NL80211_FLAG_NEED_RTNL, |
| 9473 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9474 | { |
| 9475 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9476 | .doit = nl80211_register_beacons, |
| 9477 | .policy = nl80211_policy, |
| 9478 | .flags = GENL_ADMIN_PERM, |
| 9479 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9480 | NL80211_FLAG_NEED_RTNL, |
| 9481 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9482 | { |
| 9483 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9484 | .doit = nl80211_set_noack_map, |
| 9485 | .policy = nl80211_policy, |
| 9486 | .flags = GENL_ADMIN_PERM, |
| 9487 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9488 | NL80211_FLAG_NEED_RTNL, |
| 9489 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9490 | { |
| 9491 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9492 | .doit = nl80211_start_p2p_device, |
| 9493 | .policy = nl80211_policy, |
| 9494 | .flags = GENL_ADMIN_PERM, |
| 9495 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9496 | NL80211_FLAG_NEED_RTNL, |
| 9497 | }, |
| 9498 | { |
| 9499 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9500 | .doit = nl80211_stop_p2p_device, |
| 9501 | .policy = nl80211_policy, |
| 9502 | .flags = GENL_ADMIN_PERM, |
| 9503 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9504 | NL80211_FLAG_NEED_RTNL, |
| 9505 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9506 | { |
| 9507 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9508 | .doit = nl80211_set_mcast_rate, |
| 9509 | .policy = nl80211_policy, |
| 9510 | .flags = GENL_ADMIN_PERM, |
| 9511 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9512 | NL80211_FLAG_NEED_RTNL, |
| 9513 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9514 | { |
| 9515 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9516 | .doit = nl80211_set_mac_acl, |
| 9517 | .policy = nl80211_policy, |
| 9518 | .flags = GENL_ADMIN_PERM, |
| 9519 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9520 | NL80211_FLAG_NEED_RTNL, |
| 9521 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9522 | { |
| 9523 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9524 | .doit = nl80211_start_radar_detection, |
| 9525 | .policy = nl80211_policy, |
| 9526 | .flags = GENL_ADMIN_PERM, |
| 9527 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9528 | NL80211_FLAG_NEED_RTNL, |
| 9529 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9530 | { |
| 9531 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9532 | .doit = nl80211_get_protocol_features, |
| 9533 | .policy = nl80211_policy, |
| 9534 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9535 | { |
| 9536 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9537 | .doit = nl80211_update_ft_ies, |
| 9538 | .policy = nl80211_policy, |
| 9539 | .flags = GENL_ADMIN_PERM, |
| 9540 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9541 | NL80211_FLAG_NEED_RTNL, |
| 9542 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9543 | { |
| 9544 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9545 | .doit = nl80211_crit_protocol_start, |
| 9546 | .policy = nl80211_policy, |
| 9547 | .flags = GENL_ADMIN_PERM, |
| 9548 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9549 | NL80211_FLAG_NEED_RTNL, |
| 9550 | }, |
| 9551 | { |
| 9552 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9553 | .doit = nl80211_crit_protocol_stop, |
| 9554 | .policy = nl80211_policy, |
| 9555 | .flags = GENL_ADMIN_PERM, |
| 9556 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9557 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9558 | }, |
| 9559 | { |
| 9560 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9561 | .doit = nl80211_get_coalesce, |
| 9562 | .policy = nl80211_policy, |
| 9563 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9564 | NL80211_FLAG_NEED_RTNL, |
| 9565 | }, |
| 9566 | { |
| 9567 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9568 | .doit = nl80211_set_coalesce, |
| 9569 | .policy = nl80211_policy, |
| 9570 | .flags = GENL_ADMIN_PERM, |
| 9571 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9572 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9573 | }, |
| 9574 | { |
| 9575 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9576 | .doit = nl80211_channel_switch, |
| 9577 | .policy = nl80211_policy, |
| 9578 | .flags = GENL_ADMIN_PERM, |
| 9579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9580 | NL80211_FLAG_NEED_RTNL, |
| 9581 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9582 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9583 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9584 | /* notification functions */ |
| 9585 | |
| 9586 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9587 | { |
| 9588 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9589 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9590 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9592 | if (!msg) |
| 9593 | return; |
| 9594 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9595 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9596 | nlmsg_free(msg); |
| 9597 | return; |
| 9598 | } |
| 9599 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9600 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9601 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9602 | } |
| 9603 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9604 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9605 | struct cfg80211_registered_device *rdev) |
| 9606 | { |
| 9607 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9608 | struct nlattr *nest; |
| 9609 | int i; |
| 9610 | |
| 9611 | if (WARN_ON(!req)) |
| 9612 | return 0; |
| 9613 | |
| 9614 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9615 | if (!nest) |
| 9616 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9617 | for (i = 0; i < req->n_ssids; i++) { |
| 9618 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9619 | goto nla_put_failure; |
| 9620 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9621 | nla_nest_end(msg, nest); |
| 9622 | |
| 9623 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9624 | if (!nest) |
| 9625 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9626 | for (i = 0; i < req->n_channels; i++) { |
| 9627 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9628 | goto nla_put_failure; |
| 9629 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9630 | nla_nest_end(msg, nest); |
| 9631 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9632 | if (req->ie && |
| 9633 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9634 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9635 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9636 | if (req->flags) |
| 9637 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9638 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9639 | return 0; |
| 9640 | nla_put_failure: |
| 9641 | return -ENOBUFS; |
| 9642 | } |
| 9643 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9644 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9645 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9646 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9647 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9648 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9649 | { |
| 9650 | void *hdr; |
| 9651 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9652 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9653 | if (!hdr) |
| 9654 | return -1; |
| 9655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9656 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9657 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9658 | wdev->netdev->ifindex)) || |
| 9659 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9660 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9661 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9662 | /* ignore errors and send incomplete event anyway */ |
| 9663 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9664 | |
| 9665 | return genlmsg_end(msg, hdr); |
| 9666 | |
| 9667 | nla_put_failure: |
| 9668 | genlmsg_cancel(msg, hdr); |
| 9669 | return -EMSGSIZE; |
| 9670 | } |
| 9671 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9672 | static int |
| 9673 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9674 | struct cfg80211_registered_device *rdev, |
| 9675 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9676 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9677 | { |
| 9678 | void *hdr; |
| 9679 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9680 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9681 | if (!hdr) |
| 9682 | return -1; |
| 9683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9685 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9686 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9687 | |
| 9688 | return genlmsg_end(msg, hdr); |
| 9689 | |
| 9690 | nla_put_failure: |
| 9691 | genlmsg_cancel(msg, hdr); |
| 9692 | return -EMSGSIZE; |
| 9693 | } |
| 9694 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9695 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9696 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9697 | { |
| 9698 | struct sk_buff *msg; |
| 9699 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9701 | if (!msg) |
| 9702 | return; |
| 9703 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9704 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9705 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9706 | nlmsg_free(msg); |
| 9707 | return; |
| 9708 | } |
| 9709 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9710 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9711 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9712 | } |
| 9713 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9714 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9715 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9716 | { |
| 9717 | struct sk_buff *msg; |
| 9718 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9719 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9720 | if (!msg) |
| 9721 | return; |
| 9722 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9723 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9724 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9725 | nlmsg_free(msg); |
| 9726 | return; |
| 9727 | } |
| 9728 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9729 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9730 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9731 | } |
| 9732 | |
| 9733 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9734 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9735 | { |
| 9736 | struct sk_buff *msg; |
| 9737 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9738 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9739 | if (!msg) |
| 9740 | return; |
| 9741 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9742 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9743 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9744 | nlmsg_free(msg); |
| 9745 | return; |
| 9746 | } |
| 9747 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9748 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9749 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9750 | } |
| 9751 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9752 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9753 | struct net_device *netdev) |
| 9754 | { |
| 9755 | struct sk_buff *msg; |
| 9756 | |
| 9757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9758 | if (!msg) |
| 9759 | return; |
| 9760 | |
| 9761 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9762 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9763 | nlmsg_free(msg); |
| 9764 | return; |
| 9765 | } |
| 9766 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9767 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9768 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9769 | } |
| 9770 | |
| 9771 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9772 | struct net_device *netdev, u32 cmd) |
| 9773 | { |
| 9774 | struct sk_buff *msg; |
| 9775 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9777 | if (!msg) |
| 9778 | return; |
| 9779 | |
| 9780 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9781 | nlmsg_free(msg); |
| 9782 | return; |
| 9783 | } |
| 9784 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9785 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9786 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9787 | } |
| 9788 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9789 | /* |
| 9790 | * This can happen on global regulatory changes or device specific settings |
| 9791 | * based on custom world regulatory domains. |
| 9792 | */ |
| 9793 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9794 | { |
| 9795 | struct sk_buff *msg; |
| 9796 | void *hdr; |
| 9797 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9799 | if (!msg) |
| 9800 | return; |
| 9801 | |
| 9802 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9803 | if (!hdr) { |
| 9804 | nlmsg_free(msg); |
| 9805 | return; |
| 9806 | } |
| 9807 | |
| 9808 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9809 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9810 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9811 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9812 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9813 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9814 | NL80211_REGDOM_TYPE_WORLD)) |
| 9815 | goto nla_put_failure; |
| 9816 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9817 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9818 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9819 | goto nla_put_failure; |
| 9820 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9821 | request->intersect) { |
| 9822 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9823 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9824 | goto nla_put_failure; |
| 9825 | } else { |
| 9826 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9827 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9828 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9829 | request->alpha2)) |
| 9830 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9831 | } |
| 9832 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9833 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9834 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9835 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9836 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9837 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9838 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9839 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9840 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9841 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9842 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9843 | |
| 9844 | return; |
| 9845 | |
| 9846 | nla_put_failure: |
| 9847 | genlmsg_cancel(msg, hdr); |
| 9848 | nlmsg_free(msg); |
| 9849 | } |
| 9850 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9851 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9852 | struct net_device *netdev, |
| 9853 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9854 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9855 | { |
| 9856 | struct sk_buff *msg; |
| 9857 | void *hdr; |
| 9858 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9860 | if (!msg) |
| 9861 | return; |
| 9862 | |
| 9863 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9864 | if (!hdr) { |
| 9865 | nlmsg_free(msg); |
| 9866 | return; |
| 9867 | } |
| 9868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9870 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9871 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9872 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9873 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9874 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9875 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9876 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9877 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9878 | return; |
| 9879 | |
| 9880 | nla_put_failure: |
| 9881 | genlmsg_cancel(msg, hdr); |
| 9882 | nlmsg_free(msg); |
| 9883 | } |
| 9884 | |
| 9885 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9886 | struct net_device *netdev, const u8 *buf, |
| 9887 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9888 | { |
| 9889 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9890 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9891 | } |
| 9892 | |
| 9893 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9894 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9895 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9896 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9897 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9898 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9899 | } |
| 9900 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9901 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9902 | struct net_device *netdev, const u8 *buf, |
| 9903 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9904 | { |
| 9905 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9906 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9907 | } |
| 9908 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9909 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9910 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9911 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9912 | { |
| 9913 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9914 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9915 | } |
| 9916 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9917 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9918 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9919 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9920 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9921 | struct wiphy *wiphy = wdev->wiphy; |
| 9922 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9923 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9924 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9925 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9926 | if (WARN_ON(len < 2)) |
| 9927 | return; |
| 9928 | |
| 9929 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9930 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9931 | else |
| 9932 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9933 | |
| 9934 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9935 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9936 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9937 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9938 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9939 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9940 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9941 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9942 | { |
| 9943 | struct sk_buff *msg; |
| 9944 | void *hdr; |
| 9945 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9946 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9947 | if (!msg) |
| 9948 | return; |
| 9949 | |
| 9950 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9951 | if (!hdr) { |
| 9952 | nlmsg_free(msg); |
| 9953 | return; |
| 9954 | } |
| 9955 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9956 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9957 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9958 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9959 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9960 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9961 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9962 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9963 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9964 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 9965 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9966 | return; |
| 9967 | |
| 9968 | nla_put_failure: |
| 9969 | genlmsg_cancel(msg, hdr); |
| 9970 | nlmsg_free(msg); |
| 9971 | } |
| 9972 | |
| 9973 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9974 | struct net_device *netdev, const u8 *addr, |
| 9975 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9976 | { |
| 9977 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9978 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9979 | } |
| 9980 | |
| 9981 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9982 | struct net_device *netdev, const u8 *addr, |
| 9983 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9984 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9985 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9986 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9987 | } |
| 9988 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9989 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9990 | struct net_device *netdev, const u8 *bssid, |
| 9991 | const u8 *req_ie, size_t req_ie_len, |
| 9992 | const u8 *resp_ie, size_t resp_ie_len, |
| 9993 | u16 status, gfp_t gfp) |
| 9994 | { |
| 9995 | struct sk_buff *msg; |
| 9996 | void *hdr; |
| 9997 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9999 | if (!msg) |
| 10000 | return; |
| 10001 | |
| 10002 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10003 | if (!hdr) { |
| 10004 | nlmsg_free(msg); |
| 10005 | return; |
| 10006 | } |
| 10007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10008 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10009 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10010 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10011 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10012 | (req_ie && |
| 10013 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10014 | (resp_ie && |
| 10015 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10016 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10017 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10018 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10019 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10020 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10021 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10022 | return; |
| 10023 | |
| 10024 | nla_put_failure: |
| 10025 | genlmsg_cancel(msg, hdr); |
| 10026 | nlmsg_free(msg); |
| 10027 | |
| 10028 | } |
| 10029 | |
| 10030 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10031 | struct net_device *netdev, const u8 *bssid, |
| 10032 | const u8 *req_ie, size_t req_ie_len, |
| 10033 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10034 | { |
| 10035 | struct sk_buff *msg; |
| 10036 | void *hdr; |
| 10037 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10039 | if (!msg) |
| 10040 | return; |
| 10041 | |
| 10042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10043 | if (!hdr) { |
| 10044 | nlmsg_free(msg); |
| 10045 | return; |
| 10046 | } |
| 10047 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10049 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10050 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10051 | (req_ie && |
| 10052 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10053 | (resp_ie && |
| 10054 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10055 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10056 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10057 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10058 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10059 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10060 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10061 | return; |
| 10062 | |
| 10063 | nla_put_failure: |
| 10064 | genlmsg_cancel(msg, hdr); |
| 10065 | nlmsg_free(msg); |
| 10066 | |
| 10067 | } |
| 10068 | |
| 10069 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10070 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10071 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10072 | { |
| 10073 | struct sk_buff *msg; |
| 10074 | void *hdr; |
| 10075 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10077 | if (!msg) |
| 10078 | return; |
| 10079 | |
| 10080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10081 | if (!hdr) { |
| 10082 | nlmsg_free(msg); |
| 10083 | return; |
| 10084 | } |
| 10085 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10087 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10088 | (from_ap && reason && |
| 10089 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10090 | (from_ap && |
| 10091 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10092 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10093 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10094 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10095 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10096 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10097 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10098 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10099 | return; |
| 10100 | |
| 10101 | nla_put_failure: |
| 10102 | genlmsg_cancel(msg, hdr); |
| 10103 | nlmsg_free(msg); |
| 10104 | |
| 10105 | } |
| 10106 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10107 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10108 | struct net_device *netdev, const u8 *bssid, |
| 10109 | gfp_t gfp) |
| 10110 | { |
| 10111 | struct sk_buff *msg; |
| 10112 | void *hdr; |
| 10113 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10115 | if (!msg) |
| 10116 | return; |
| 10117 | |
| 10118 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10119 | if (!hdr) { |
| 10120 | nlmsg_free(msg); |
| 10121 | return; |
| 10122 | } |
| 10123 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10124 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10125 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10126 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10127 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10128 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10129 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10130 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10131 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10132 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10133 | return; |
| 10134 | |
| 10135 | nla_put_failure: |
| 10136 | genlmsg_cancel(msg, hdr); |
| 10137 | nlmsg_free(msg); |
| 10138 | } |
| 10139 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10140 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10141 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10142 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10143 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10144 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10145 | struct sk_buff *msg; |
| 10146 | void *hdr; |
| 10147 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10148 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10149 | return; |
| 10150 | |
| 10151 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10152 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10153 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10154 | if (!msg) |
| 10155 | return; |
| 10156 | |
| 10157 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10158 | if (!hdr) { |
| 10159 | nlmsg_free(msg); |
| 10160 | return; |
| 10161 | } |
| 10162 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10163 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10164 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10165 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10166 | (ie_len && ie && |
| 10167 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10168 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10169 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10170 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10171 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10172 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10173 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10174 | return; |
| 10175 | |
| 10176 | nla_put_failure: |
| 10177 | genlmsg_cancel(msg, hdr); |
| 10178 | nlmsg_free(msg); |
| 10179 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10180 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10181 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10182 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10183 | struct net_device *netdev, const u8 *addr, |
| 10184 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10185 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10186 | { |
| 10187 | struct sk_buff *msg; |
| 10188 | void *hdr; |
| 10189 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10190 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10191 | if (!msg) |
| 10192 | return; |
| 10193 | |
| 10194 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10195 | if (!hdr) { |
| 10196 | nlmsg_free(msg); |
| 10197 | return; |
| 10198 | } |
| 10199 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10200 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10201 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10202 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10203 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10204 | (key_id != -1 && |
| 10205 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10206 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10207 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10208 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10209 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10210 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10211 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10212 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10213 | return; |
| 10214 | |
| 10215 | nla_put_failure: |
| 10216 | genlmsg_cancel(msg, hdr); |
| 10217 | nlmsg_free(msg); |
| 10218 | } |
| 10219 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10220 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10221 | struct ieee80211_channel *channel_before, |
| 10222 | struct ieee80211_channel *channel_after) |
| 10223 | { |
| 10224 | struct sk_buff *msg; |
| 10225 | void *hdr; |
| 10226 | struct nlattr *nl_freq; |
| 10227 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10228 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10229 | if (!msg) |
| 10230 | return; |
| 10231 | |
| 10232 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10233 | if (!hdr) { |
| 10234 | nlmsg_free(msg); |
| 10235 | return; |
| 10236 | } |
| 10237 | |
| 10238 | /* |
| 10239 | * Since we are applying the beacon hint to a wiphy we know its |
| 10240 | * wiphy_idx is valid |
| 10241 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10243 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10244 | |
| 10245 | /* Before */ |
| 10246 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10247 | if (!nl_freq) |
| 10248 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10249 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10250 | goto nla_put_failure; |
| 10251 | nla_nest_end(msg, nl_freq); |
| 10252 | |
| 10253 | /* After */ |
| 10254 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10255 | if (!nl_freq) |
| 10256 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10257 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10258 | goto nla_put_failure; |
| 10259 | nla_nest_end(msg, nl_freq); |
| 10260 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10261 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10262 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10263 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10264 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10265 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10266 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10267 | |
| 10268 | return; |
| 10269 | |
| 10270 | nla_put_failure: |
| 10271 | genlmsg_cancel(msg, hdr); |
| 10272 | nlmsg_free(msg); |
| 10273 | } |
| 10274 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10275 | static void nl80211_send_remain_on_chan_event( |
| 10276 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10277 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10278 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10279 | unsigned int duration, gfp_t gfp) |
| 10280 | { |
| 10281 | struct sk_buff *msg; |
| 10282 | void *hdr; |
| 10283 | |
| 10284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10285 | if (!msg) |
| 10286 | return; |
| 10287 | |
| 10288 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10289 | if (!hdr) { |
| 10290 | nlmsg_free(msg); |
| 10291 | return; |
| 10292 | } |
| 10293 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10295 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10296 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10297 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10298 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10299 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10300 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10301 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10302 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10303 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10304 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10305 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10306 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10307 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10308 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10309 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10310 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10311 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10312 | return; |
| 10313 | |
| 10314 | nla_put_failure: |
| 10315 | genlmsg_cancel(msg, hdr); |
| 10316 | nlmsg_free(msg); |
| 10317 | } |
| 10318 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10319 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10320 | struct ieee80211_channel *chan, |
| 10321 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10322 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10323 | struct wiphy *wiphy = wdev->wiphy; |
| 10324 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10325 | |
| 10326 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10327 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10328 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10329 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10330 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10331 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10332 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10333 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10334 | struct ieee80211_channel *chan, |
| 10335 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10336 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10337 | struct wiphy *wiphy = wdev->wiphy; |
| 10338 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10339 | |
| 10340 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10341 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10342 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10343 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10344 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10345 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10346 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10347 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10348 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10349 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10350 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10351 | struct sk_buff *msg; |
| 10352 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10353 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10354 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10355 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10356 | if (!msg) |
| 10357 | return; |
| 10358 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10359 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10360 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10361 | nlmsg_free(msg); |
| 10362 | return; |
| 10363 | } |
| 10364 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10365 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10366 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10367 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10368 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10369 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10370 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10371 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10372 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10373 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10374 | struct sk_buff *msg; |
| 10375 | void *hdr; |
| 10376 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10377 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10378 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10380 | if (!msg) |
| 10381 | return; |
| 10382 | |
| 10383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10384 | if (!hdr) { |
| 10385 | nlmsg_free(msg); |
| 10386 | return; |
| 10387 | } |
| 10388 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10389 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10390 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10391 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10392 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10393 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10394 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10395 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10396 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10397 | return; |
| 10398 | |
| 10399 | nla_put_failure: |
| 10400 | genlmsg_cancel(msg, hdr); |
| 10401 | nlmsg_free(msg); |
| 10402 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10403 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10404 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10405 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10406 | enum nl80211_connect_failed_reason reason, |
| 10407 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10408 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10409 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10410 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10411 | struct sk_buff *msg; |
| 10412 | void *hdr; |
| 10413 | |
| 10414 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10415 | if (!msg) |
| 10416 | return; |
| 10417 | |
| 10418 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10419 | if (!hdr) { |
| 10420 | nlmsg_free(msg); |
| 10421 | return; |
| 10422 | } |
| 10423 | |
| 10424 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10425 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10426 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10427 | goto nla_put_failure; |
| 10428 | |
| 10429 | genlmsg_end(msg, hdr); |
| 10430 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10431 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10432 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10433 | return; |
| 10434 | |
| 10435 | nla_put_failure: |
| 10436 | genlmsg_cancel(msg, hdr); |
| 10437 | nlmsg_free(msg); |
| 10438 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10439 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10440 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10441 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10442 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10443 | { |
| 10444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10445 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10446 | struct sk_buff *msg; |
| 10447 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10448 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10449 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10450 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10451 | return false; |
| 10452 | |
| 10453 | msg = nlmsg_new(100, gfp); |
| 10454 | if (!msg) |
| 10455 | return true; |
| 10456 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10457 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10458 | if (!hdr) { |
| 10459 | nlmsg_free(msg); |
| 10460 | return true; |
| 10461 | } |
| 10462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10463 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10464 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10465 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10466 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10467 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10468 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10469 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10470 | return true; |
| 10471 | |
| 10472 | nla_put_failure: |
| 10473 | genlmsg_cancel(msg, hdr); |
| 10474 | nlmsg_free(msg); |
| 10475 | return true; |
| 10476 | } |
| 10477 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10478 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10479 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10480 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10481 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10482 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10483 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10484 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10485 | |
| 10486 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10487 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10488 | trace_cfg80211_return_bool(false); |
| 10489 | return false; |
| 10490 | } |
| 10491 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10492 | addr, gfp); |
| 10493 | trace_cfg80211_return_bool(ret); |
| 10494 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10495 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10496 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10497 | |
| 10498 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10499 | const u8 *addr, gfp_t gfp) |
| 10500 | { |
| 10501 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10502 | bool ret; |
| 10503 | |
| 10504 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10505 | |
| 10506 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10507 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10508 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10509 | trace_cfg80211_return_bool(false); |
| 10510 | return false; |
| 10511 | } |
| 10512 | ret = __nl80211_unexpected_frame(dev, |
| 10513 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10514 | addr, gfp); |
| 10515 | trace_cfg80211_return_bool(ret); |
| 10516 | return ret; |
| 10517 | } |
| 10518 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10519 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10520 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10521 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10522 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10523 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10524 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10525 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10526 | struct sk_buff *msg; |
| 10527 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10528 | |
| 10529 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10530 | if (!msg) |
| 10531 | return -ENOMEM; |
| 10532 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10533 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10534 | if (!hdr) { |
| 10535 | nlmsg_free(msg); |
| 10536 | return -ENOMEM; |
| 10537 | } |
| 10538 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10539 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10540 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10541 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10542 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10543 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10544 | (sig_dbm && |
| 10545 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10546 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10547 | (flags && |
| 10548 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10549 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10550 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10551 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10552 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10553 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10554 | |
| 10555 | nla_put_failure: |
| 10556 | genlmsg_cancel(msg, hdr); |
| 10557 | nlmsg_free(msg); |
| 10558 | return -ENOBUFS; |
| 10559 | } |
| 10560 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10561 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10562 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10563 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10564 | struct wiphy *wiphy = wdev->wiphy; |
| 10565 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10566 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10567 | struct sk_buff *msg; |
| 10568 | void *hdr; |
| 10569 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10570 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10571 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10573 | if (!msg) |
| 10574 | return; |
| 10575 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10576 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10577 | if (!hdr) { |
| 10578 | nlmsg_free(msg); |
| 10579 | return; |
| 10580 | } |
| 10581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10582 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10583 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10584 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10585 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10586 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10587 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10588 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10589 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10590 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10591 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10592 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10593 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10594 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10595 | return; |
| 10596 | |
| 10597 | nla_put_failure: |
| 10598 | genlmsg_cancel(msg, hdr); |
| 10599 | nlmsg_free(msg); |
| 10600 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10601 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10602 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10603 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10604 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10605 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10606 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10608 | struct wiphy *wiphy = wdev->wiphy; |
| 10609 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10610 | struct sk_buff *msg; |
| 10611 | struct nlattr *pinfoattr; |
| 10612 | void *hdr; |
| 10613 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10614 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10615 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10617 | if (!msg) |
| 10618 | return; |
| 10619 | |
| 10620 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10621 | if (!hdr) { |
| 10622 | nlmsg_free(msg); |
| 10623 | return; |
| 10624 | } |
| 10625 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10626 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10627 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10628 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10629 | |
| 10630 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10631 | if (!pinfoattr) |
| 10632 | goto nla_put_failure; |
| 10633 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10634 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10635 | rssi_event)) |
| 10636 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10637 | |
| 10638 | nla_nest_end(msg, pinfoattr); |
| 10639 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10640 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10641 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10642 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10643 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10644 | return; |
| 10645 | |
| 10646 | nla_put_failure: |
| 10647 | genlmsg_cancel(msg, hdr); |
| 10648 | nlmsg_free(msg); |
| 10649 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10650 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10651 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10652 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10653 | struct net_device *netdev, const u8 *bssid, |
| 10654 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10655 | { |
| 10656 | struct sk_buff *msg; |
| 10657 | struct nlattr *rekey_attr; |
| 10658 | void *hdr; |
| 10659 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10660 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10661 | if (!msg) |
| 10662 | return; |
| 10663 | |
| 10664 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10665 | if (!hdr) { |
| 10666 | nlmsg_free(msg); |
| 10667 | return; |
| 10668 | } |
| 10669 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10670 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10671 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10672 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10673 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10674 | |
| 10675 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10676 | if (!rekey_attr) |
| 10677 | goto nla_put_failure; |
| 10678 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10679 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10680 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10681 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10682 | |
| 10683 | nla_nest_end(msg, rekey_attr); |
| 10684 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10685 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10686 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10687 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10688 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10689 | return; |
| 10690 | |
| 10691 | nla_put_failure: |
| 10692 | genlmsg_cancel(msg, hdr); |
| 10693 | nlmsg_free(msg); |
| 10694 | } |
| 10695 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10696 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10697 | const u8 *replay_ctr, gfp_t gfp) |
| 10698 | { |
| 10699 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10700 | struct wiphy *wiphy = wdev->wiphy; |
| 10701 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10702 | |
| 10703 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10704 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10705 | } |
| 10706 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10707 | |
| 10708 | static void |
| 10709 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10710 | struct net_device *netdev, int index, |
| 10711 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10712 | { |
| 10713 | struct sk_buff *msg; |
| 10714 | struct nlattr *attr; |
| 10715 | void *hdr; |
| 10716 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10717 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10718 | if (!msg) |
| 10719 | return; |
| 10720 | |
| 10721 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10722 | if (!hdr) { |
| 10723 | nlmsg_free(msg); |
| 10724 | return; |
| 10725 | } |
| 10726 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10727 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10728 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10729 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10730 | |
| 10731 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10732 | if (!attr) |
| 10733 | goto nla_put_failure; |
| 10734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10735 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10736 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10737 | (preauth && |
| 10738 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10739 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10740 | |
| 10741 | nla_nest_end(msg, attr); |
| 10742 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10743 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10744 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10745 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10746 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10747 | return; |
| 10748 | |
| 10749 | nla_put_failure: |
| 10750 | genlmsg_cancel(msg, hdr); |
| 10751 | nlmsg_free(msg); |
| 10752 | } |
| 10753 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10754 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10755 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10756 | { |
| 10757 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10758 | struct wiphy *wiphy = wdev->wiphy; |
| 10759 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10760 | |
| 10761 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10762 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10763 | } |
| 10764 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10765 | |
| 10766 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10767 | struct net_device *netdev, |
| 10768 | struct cfg80211_chan_def *chandef, |
| 10769 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10770 | { |
| 10771 | struct sk_buff *msg; |
| 10772 | void *hdr; |
| 10773 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10775 | if (!msg) |
| 10776 | return; |
| 10777 | |
| 10778 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10779 | if (!hdr) { |
| 10780 | nlmsg_free(msg); |
| 10781 | return; |
| 10782 | } |
| 10783 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10784 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10785 | goto nla_put_failure; |
| 10786 | |
| 10787 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10788 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10789 | |
| 10790 | genlmsg_end(msg, hdr); |
| 10791 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10792 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10793 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10794 | return; |
| 10795 | |
| 10796 | nla_put_failure: |
| 10797 | genlmsg_cancel(msg, hdr); |
| 10798 | nlmsg_free(msg); |
| 10799 | } |
| 10800 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10801 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10802 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10803 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10804 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10805 | struct wiphy *wiphy = wdev->wiphy; |
| 10806 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10807 | |
| 10808 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10809 | |
| 10810 | wdev_lock(wdev); |
| 10811 | |
| 10812 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 10813 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 10814 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 10815 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10816 | goto out; |
| 10817 | |
| 10818 | wdev->channel = chandef->chan; |
| 10819 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10820 | out: |
| 10821 | wdev_unlock(wdev); |
| 10822 | return; |
| 10823 | } |
| 10824 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10825 | |
| 10826 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10827 | const u8 *peer, u32 num_packets, |
| 10828 | u32 rate, u32 intvl, gfp_t gfp) |
| 10829 | { |
| 10830 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10831 | struct wiphy *wiphy = wdev->wiphy; |
| 10832 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10833 | struct sk_buff *msg; |
| 10834 | struct nlattr *pinfoattr; |
| 10835 | void *hdr; |
| 10836 | |
| 10837 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10838 | if (!msg) |
| 10839 | return; |
| 10840 | |
| 10841 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10842 | if (!hdr) { |
| 10843 | nlmsg_free(msg); |
| 10844 | return; |
| 10845 | } |
| 10846 | |
| 10847 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10848 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10849 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10850 | goto nla_put_failure; |
| 10851 | |
| 10852 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10853 | if (!pinfoattr) |
| 10854 | goto nla_put_failure; |
| 10855 | |
| 10856 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10857 | goto nla_put_failure; |
| 10858 | |
| 10859 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10860 | goto nla_put_failure; |
| 10861 | |
| 10862 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10863 | goto nla_put_failure; |
| 10864 | |
| 10865 | nla_nest_end(msg, pinfoattr); |
| 10866 | |
| 10867 | genlmsg_end(msg, hdr); |
| 10868 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10869 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10870 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10871 | return; |
| 10872 | |
| 10873 | nla_put_failure: |
| 10874 | genlmsg_cancel(msg, hdr); |
| 10875 | nlmsg_free(msg); |
| 10876 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10877 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10878 | |
| 10879 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10880 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10881 | struct cfg80211_chan_def *chandef, |
| 10882 | enum nl80211_radar_event event, |
| 10883 | struct net_device *netdev, gfp_t gfp) |
| 10884 | { |
| 10885 | struct sk_buff *msg; |
| 10886 | void *hdr; |
| 10887 | |
| 10888 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10889 | if (!msg) |
| 10890 | return; |
| 10891 | |
| 10892 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10893 | if (!hdr) { |
| 10894 | nlmsg_free(msg); |
| 10895 | return; |
| 10896 | } |
| 10897 | |
| 10898 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10899 | goto nla_put_failure; |
| 10900 | |
| 10901 | /* NOP and radar events don't need a netdev parameter */ |
| 10902 | if (netdev) { |
| 10903 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10904 | |
| 10905 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10906 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10907 | goto nla_put_failure; |
| 10908 | } |
| 10909 | |
| 10910 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10911 | goto nla_put_failure; |
| 10912 | |
| 10913 | if (nl80211_send_chandef(msg, chandef)) |
| 10914 | goto nla_put_failure; |
| 10915 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10916 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10917 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10918 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10919 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10920 | return; |
| 10921 | |
| 10922 | nla_put_failure: |
| 10923 | genlmsg_cancel(msg, hdr); |
| 10924 | nlmsg_free(msg); |
| 10925 | } |
| 10926 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10927 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10928 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10929 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10930 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10931 | struct wiphy *wiphy = wdev->wiphy; |
| 10932 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10933 | struct sk_buff *msg; |
| 10934 | struct nlattr *pinfoattr; |
| 10935 | void *hdr; |
| 10936 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10937 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10938 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10940 | if (!msg) |
| 10941 | return; |
| 10942 | |
| 10943 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10944 | if (!hdr) { |
| 10945 | nlmsg_free(msg); |
| 10946 | return; |
| 10947 | } |
| 10948 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10949 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10950 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10951 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10952 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10953 | |
| 10954 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10955 | if (!pinfoattr) |
| 10956 | goto nla_put_failure; |
| 10957 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10958 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10959 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10960 | |
| 10961 | nla_nest_end(msg, pinfoattr); |
| 10962 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10963 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10964 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10965 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 10966 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10967 | return; |
| 10968 | |
| 10969 | nla_put_failure: |
| 10970 | genlmsg_cancel(msg, hdr); |
| 10971 | nlmsg_free(msg); |
| 10972 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10973 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10974 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10975 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10976 | u64 cookie, bool acked, gfp_t gfp) |
| 10977 | { |
| 10978 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10979 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10980 | struct sk_buff *msg; |
| 10981 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10982 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10983 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10984 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10985 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10986 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10987 | if (!msg) |
| 10988 | return; |
| 10989 | |
| 10990 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10991 | if (!hdr) { |
| 10992 | nlmsg_free(msg); |
| 10993 | return; |
| 10994 | } |
| 10995 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10996 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10997 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10998 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10999 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11000 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11001 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11002 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11003 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11004 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11005 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 11006 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11007 | return; |
| 11008 | |
| 11009 | nla_put_failure: |
| 11010 | genlmsg_cancel(msg, hdr); |
| 11011 | nlmsg_free(msg); |
| 11012 | } |
| 11013 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11014 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11015 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11016 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11017 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11018 | { |
| 11019 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11020 | struct sk_buff *msg; |
| 11021 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11022 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11023 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11024 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11025 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11026 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11027 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11028 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11029 | if (!msg) { |
| 11030 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11031 | return; |
| 11032 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11033 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11034 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11035 | if (!hdr) |
| 11036 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11037 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11039 | (freq && |
| 11040 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11041 | (sig_dbm && |
| 11042 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11043 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11044 | goto nla_put_failure; |
| 11045 | |
| 11046 | genlmsg_end(msg, hdr); |
| 11047 | |
| 11048 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11049 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11050 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11051 | return; |
| 11052 | |
| 11053 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11054 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11055 | if (hdr) |
| 11056 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11057 | nlmsg_free(msg); |
| 11058 | } |
| 11059 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11060 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11061 | #ifdef CONFIG_PM |
| 11062 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11063 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11064 | gfp_t gfp) |
| 11065 | { |
| 11066 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11067 | struct sk_buff *msg; |
| 11068 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11069 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11070 | |
| 11071 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11072 | |
| 11073 | if (wakeup) |
| 11074 | size += wakeup->packet_present_len; |
| 11075 | |
| 11076 | msg = nlmsg_new(size, gfp); |
| 11077 | if (!msg) |
| 11078 | return; |
| 11079 | |
| 11080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11081 | if (!hdr) |
| 11082 | goto free_msg; |
| 11083 | |
| 11084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11085 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11086 | goto free_msg; |
| 11087 | |
| 11088 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11089 | wdev->netdev->ifindex)) |
| 11090 | goto free_msg; |
| 11091 | |
| 11092 | if (wakeup) { |
| 11093 | struct nlattr *reasons; |
| 11094 | |
| 11095 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11096 | |
| 11097 | if (wakeup->disconnect && |
| 11098 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11099 | goto free_msg; |
| 11100 | if (wakeup->magic_pkt && |
| 11101 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11102 | goto free_msg; |
| 11103 | if (wakeup->gtk_rekey_failure && |
| 11104 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11105 | goto free_msg; |
| 11106 | if (wakeup->eap_identity_req && |
| 11107 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11108 | goto free_msg; |
| 11109 | if (wakeup->four_way_handshake && |
| 11110 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11111 | goto free_msg; |
| 11112 | if (wakeup->rfkill_release && |
| 11113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11114 | goto free_msg; |
| 11115 | |
| 11116 | if (wakeup->pattern_idx >= 0 && |
| 11117 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11118 | wakeup->pattern_idx)) |
| 11119 | goto free_msg; |
| 11120 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11121 | if (wakeup->tcp_match) |
| 11122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11123 | |
| 11124 | if (wakeup->tcp_connlost) |
| 11125 | nla_put_flag(msg, |
| 11126 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11127 | |
| 11128 | if (wakeup->tcp_nomoretokens) |
| 11129 | nla_put_flag(msg, |
| 11130 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11131 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11132 | if (wakeup->packet) { |
| 11133 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11134 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11135 | |
| 11136 | if (!wakeup->packet_80211) { |
| 11137 | pkt_attr = |
| 11138 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11139 | len_attr = |
| 11140 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11141 | } |
| 11142 | |
| 11143 | if (wakeup->packet_len && |
| 11144 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11145 | goto free_msg; |
| 11146 | |
| 11147 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11148 | wakeup->packet)) |
| 11149 | goto free_msg; |
| 11150 | } |
| 11151 | |
| 11152 | nla_nest_end(msg, reasons); |
| 11153 | } |
| 11154 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11155 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11156 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11157 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 11158 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11159 | return; |
| 11160 | |
| 11161 | free_msg: |
| 11162 | nlmsg_free(msg); |
| 11163 | } |
| 11164 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11165 | #endif |
| 11166 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11167 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11168 | enum nl80211_tdls_operation oper, |
| 11169 | u16 reason_code, gfp_t gfp) |
| 11170 | { |
| 11171 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11172 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11173 | struct sk_buff *msg; |
| 11174 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11175 | |
| 11176 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11177 | reason_code); |
| 11178 | |
| 11179 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11180 | if (!msg) |
| 11181 | return; |
| 11182 | |
| 11183 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11184 | if (!hdr) { |
| 11185 | nlmsg_free(msg); |
| 11186 | return; |
| 11187 | } |
| 11188 | |
| 11189 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11190 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11191 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11192 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11193 | (reason_code > 0 && |
| 11194 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11195 | goto nla_put_failure; |
| 11196 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11197 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11198 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11199 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 11200 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11201 | return; |
| 11202 | |
| 11203 | nla_put_failure: |
| 11204 | genlmsg_cancel(msg, hdr); |
| 11205 | nlmsg_free(msg); |
| 11206 | } |
| 11207 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11208 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11209 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11210 | unsigned long state, |
| 11211 | void *_notify) |
| 11212 | { |
| 11213 | struct netlink_notify *notify = _notify; |
| 11214 | struct cfg80211_registered_device *rdev; |
| 11215 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11216 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11217 | |
| 11218 | if (state != NETLINK_URELEASE) |
| 11219 | return NOTIFY_DONE; |
| 11220 | |
| 11221 | rcu_read_lock(); |
| 11222 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11223 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11224 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11225 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11226 | |
| 11227 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11228 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11229 | list) { |
| 11230 | if (reg->nlportid == notify->portid) { |
| 11231 | list_del(®->list); |
| 11232 | kfree(reg); |
| 11233 | break; |
| 11234 | } |
| 11235 | } |
| 11236 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11237 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11238 | |
| 11239 | rcu_read_unlock(); |
| 11240 | |
| 11241 | return NOTIFY_DONE; |
| 11242 | } |
| 11243 | |
| 11244 | static struct notifier_block nl80211_netlink_notifier = { |
| 11245 | .notifier_call = nl80211_netlink_notify, |
| 11246 | }; |
| 11247 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11248 | void cfg80211_ft_event(struct net_device *netdev, |
| 11249 | struct cfg80211_ft_event_params *ft_event) |
| 11250 | { |
| 11251 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11252 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11253 | struct sk_buff *msg; |
| 11254 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11255 | |
| 11256 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11257 | |
| 11258 | if (!ft_event->target_ap) |
| 11259 | return; |
| 11260 | |
| 11261 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11262 | if (!msg) |
| 11263 | return; |
| 11264 | |
| 11265 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11266 | if (!hdr) { |
| 11267 | nlmsg_free(msg); |
| 11268 | return; |
| 11269 | } |
| 11270 | |
| 11271 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11272 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11273 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11274 | if (ft_event->ies) |
| 11275 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11276 | if (ft_event->ric_ies) |
| 11277 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11278 | ft_event->ric_ies); |
| 11279 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11280 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11281 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11282 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 11283 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11284 | } |
| 11285 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11286 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11287 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11288 | { |
| 11289 | struct cfg80211_registered_device *rdev; |
| 11290 | struct sk_buff *msg; |
| 11291 | void *hdr; |
| 11292 | u32 nlportid; |
| 11293 | |
| 11294 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11295 | if (!rdev->crit_proto_nlportid) |
| 11296 | return; |
| 11297 | |
| 11298 | nlportid = rdev->crit_proto_nlportid; |
| 11299 | rdev->crit_proto_nlportid = 0; |
| 11300 | |
| 11301 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11302 | if (!msg) |
| 11303 | return; |
| 11304 | |
| 11305 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11306 | if (!hdr) |
| 11307 | goto nla_put_failure; |
| 11308 | |
| 11309 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11310 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11311 | goto nla_put_failure; |
| 11312 | |
| 11313 | genlmsg_end(msg, hdr); |
| 11314 | |
| 11315 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11316 | return; |
| 11317 | |
| 11318 | nla_put_failure: |
| 11319 | if (hdr) |
| 11320 | genlmsg_cancel(msg, hdr); |
| 11321 | nlmsg_free(msg); |
| 11322 | |
| 11323 | } |
| 11324 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11325 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11326 | /* initialisation/exit functions */ |
| 11327 | |
| 11328 | int nl80211_init(void) |
| 11329 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11330 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11331 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame^] | 11332 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11333 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11334 | if (err) |
| 11335 | return err; |
| 11336 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11337 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11338 | if (err) |
| 11339 | goto err_out; |
| 11340 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11341 | return 0; |
| 11342 | err_out: |
| 11343 | genl_unregister_family(&nl80211_fam); |
| 11344 | return err; |
| 11345 | } |
| 11346 | |
| 11347 | void nl80211_exit(void) |
| 11348 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11349 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11350 | genl_unregister_family(&nl80211_fam); |
| 11351 | } |