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 | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 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 = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 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 | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 373 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 374 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 375 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 376 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 377 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 379 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 380 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 381 | }; |
| 382 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 384 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 385 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 386 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 387 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 388 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 389 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 390 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 391 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 392 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 393 | }; |
| 394 | |
| 395 | /* policy for the key default flags */ |
| 396 | static const struct nla_policy |
| 397 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 398 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 399 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 400 | }; |
| 401 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 402 | /* policy for WoWLAN attributes */ |
| 403 | static const struct nla_policy |
| 404 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 405 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 406 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 407 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 408 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 409 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 410 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 411 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 413 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 414 | }; |
| 415 | |
| 416 | static const struct nla_policy |
| 417 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 418 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 419 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 420 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 421 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 422 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 423 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 424 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 425 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 426 | }, |
| 427 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 428 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 429 | }, |
| 430 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 431 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 432 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 433 | }; |
| 434 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 435 | /* policy for GTK rekey offload attributes */ |
| 436 | static const struct nla_policy |
| 437 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 438 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 439 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 440 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 441 | }; |
| 442 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 443 | static const struct nla_policy |
| 444 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 445 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 446 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 447 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 448 | }; |
| 449 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 450 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 451 | struct netlink_callback *cb, |
| 452 | struct cfg80211_registered_device **rdev, |
| 453 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 454 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 455 | int err; |
| 456 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 457 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 458 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 459 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 460 | if (!cb->args[0]) { |
| 461 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 462 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 463 | nl80211_policy); |
| 464 | if (err) |
| 465 | goto out_unlock; |
| 466 | |
| 467 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 468 | nl80211_fam.attrbuf); |
| 469 | if (IS_ERR(*wdev)) { |
| 470 | err = PTR_ERR(*wdev); |
| 471 | goto out_unlock; |
| 472 | } |
| 473 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 474 | cb->args[0] = (*rdev)->wiphy_idx; |
| 475 | cb->args[1] = (*wdev)->identifier; |
| 476 | } else { |
| 477 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 478 | struct wireless_dev *tmp; |
| 479 | |
| 480 | if (!wiphy) { |
| 481 | err = -ENODEV; |
| 482 | goto out_unlock; |
| 483 | } |
| 484 | *rdev = wiphy_to_dev(wiphy); |
| 485 | *wdev = NULL; |
| 486 | |
| 487 | mutex_lock(&(*rdev)->devlist_mtx); |
| 488 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 489 | if (tmp->identifier == cb->args[1]) { |
| 490 | *wdev = tmp; |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | mutex_unlock(&(*rdev)->devlist_mtx); |
| 495 | |
| 496 | if (!*wdev) { |
| 497 | err = -ENODEV; |
| 498 | goto out_unlock; |
| 499 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 500 | } |
| 501 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 502 | cfg80211_lock_rdev(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 503 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 505 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 506 | out_unlock: |
| 507 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 508 | rtnl_unlock(); |
| 509 | return err; |
| 510 | } |
| 511 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 512 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | { |
| 514 | cfg80211_unlock_rdev(rdev); |
| 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: |
| 840 | if (!wdev->current_bss) |
| 841 | return -ENOLINK; |
| 842 | break; |
| 843 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 845 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 846 | return -ENOLINK; |
| 847 | break; |
| 848 | default: |
| 849 | return -EINVAL; |
| 850 | } |
| 851 | |
| 852 | return 0; |
| 853 | } |
| 854 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 855 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 856 | { |
| 857 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 858 | int i; |
| 859 | |
| 860 | if (!nl_modes) |
| 861 | goto nla_put_failure; |
| 862 | |
| 863 | i = 0; |
| 864 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 865 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 866 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 867 | ifmodes >>= 1; |
| 868 | i++; |
| 869 | } |
| 870 | |
| 871 | nla_nest_end(msg, nl_modes); |
| 872 | return 0; |
| 873 | |
| 874 | nla_put_failure: |
| 875 | return -ENOBUFS; |
| 876 | } |
| 877 | |
| 878 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 879 | struct sk_buff *msg, |
| 880 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 881 | { |
| 882 | struct nlattr *nl_combis; |
| 883 | int i, j; |
| 884 | |
| 885 | nl_combis = nla_nest_start(msg, |
| 886 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 887 | if (!nl_combis) |
| 888 | goto nla_put_failure; |
| 889 | |
| 890 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 891 | const struct ieee80211_iface_combination *c; |
| 892 | struct nlattr *nl_combi, *nl_limits; |
| 893 | |
| 894 | c = &wiphy->iface_combinations[i]; |
| 895 | |
| 896 | nl_combi = nla_nest_start(msg, i + 1); |
| 897 | if (!nl_combi) |
| 898 | goto nla_put_failure; |
| 899 | |
| 900 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 901 | if (!nl_limits) |
| 902 | goto nla_put_failure; |
| 903 | |
| 904 | for (j = 0; j < c->n_limits; j++) { |
| 905 | struct nlattr *nl_limit; |
| 906 | |
| 907 | nl_limit = nla_nest_start(msg, j + 1); |
| 908 | if (!nl_limit) |
| 909 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 910 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 911 | c->limits[j].max)) |
| 912 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 913 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 914 | c->limits[j].types)) |
| 915 | goto nla_put_failure; |
| 916 | nla_nest_end(msg, nl_limit); |
| 917 | } |
| 918 | |
| 919 | nla_nest_end(msg, nl_limits); |
| 920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 921 | if (c->beacon_int_infra_match && |
| 922 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 923 | goto nla_put_failure; |
| 924 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 925 | c->num_different_channels) || |
| 926 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 927 | c->max_interfaces)) |
| 928 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 929 | if (large && |
| 930 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 931 | c->radar_detect_widths)) |
| 932 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 933 | |
| 934 | nla_nest_end(msg, nl_combi); |
| 935 | } |
| 936 | |
| 937 | nla_nest_end(msg, nl_combis); |
| 938 | |
| 939 | return 0; |
| 940 | nla_put_failure: |
| 941 | return -ENOBUFS; |
| 942 | } |
| 943 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 944 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 945 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 946 | struct sk_buff *msg) |
| 947 | { |
| 948 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 949 | struct nlattr *nl_tcp; |
| 950 | |
| 951 | if (!tcp) |
| 952 | return 0; |
| 953 | |
| 954 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 955 | if (!nl_tcp) |
| 956 | return -ENOBUFS; |
| 957 | |
| 958 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 959 | tcp->data_payload_max)) |
| 960 | return -ENOBUFS; |
| 961 | |
| 962 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 963 | tcp->data_payload_max)) |
| 964 | return -ENOBUFS; |
| 965 | |
| 966 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 967 | return -ENOBUFS; |
| 968 | |
| 969 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 970 | sizeof(*tcp->tok), tcp->tok)) |
| 971 | return -ENOBUFS; |
| 972 | |
| 973 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 974 | tcp->data_interval_max)) |
| 975 | return -ENOBUFS; |
| 976 | |
| 977 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 978 | tcp->wake_payload_max)) |
| 979 | return -ENOBUFS; |
| 980 | |
| 981 | nla_nest_end(msg, nl_tcp); |
| 982 | return 0; |
| 983 | } |
| 984 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 985 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 986 | struct cfg80211_registered_device *dev, |
| 987 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | { |
| 989 | struct nlattr *nl_wowlan; |
| 990 | |
| 991 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
| 992 | return 0; |
| 993 | |
| 994 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 995 | if (!nl_wowlan) |
| 996 | return -ENOBUFS; |
| 997 | |
| 998 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 999 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1000 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1001 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1002 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1003 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1004 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1005 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1006 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1007 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1008 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1009 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1010 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1011 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1012 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1013 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1014 | return -ENOBUFS; |
| 1015 | |
| 1016 | if (dev->wiphy.wowlan.n_patterns) { |
| 1017 | struct nl80211_wowlan_pattern_support pat = { |
| 1018 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1019 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, |
| 1020 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, |
| 1021 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, |
| 1022 | }; |
| 1023 | |
| 1024 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1025 | sizeof(pat), &pat)) |
| 1026 | return -ENOBUFS; |
| 1027 | } |
| 1028 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1029 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1030 | return -ENOBUFS; |
| 1031 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1032 | nla_nest_end(msg, nl_wowlan); |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | #endif |
| 1037 | |
| 1038 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1039 | struct ieee80211_supported_band *sband) |
| 1040 | { |
| 1041 | struct nlattr *nl_rates, *nl_rate; |
| 1042 | struct ieee80211_rate *rate; |
| 1043 | int i; |
| 1044 | |
| 1045 | /* add HT info */ |
| 1046 | if (sband->ht_cap.ht_supported && |
| 1047 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1048 | sizeof(sband->ht_cap.mcs), |
| 1049 | &sband->ht_cap.mcs) || |
| 1050 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1051 | sband->ht_cap.cap) || |
| 1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1053 | sband->ht_cap.ampdu_factor) || |
| 1054 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1055 | sband->ht_cap.ampdu_density))) |
| 1056 | return -ENOBUFS; |
| 1057 | |
| 1058 | /* add VHT info */ |
| 1059 | if (sband->vht_cap.vht_supported && |
| 1060 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1061 | sizeof(sband->vht_cap.vht_mcs), |
| 1062 | &sband->vht_cap.vht_mcs) || |
| 1063 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1064 | sband->vht_cap.cap))) |
| 1065 | return -ENOBUFS; |
| 1066 | |
| 1067 | /* add bitrates */ |
| 1068 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1069 | if (!nl_rates) |
| 1070 | return -ENOBUFS; |
| 1071 | |
| 1072 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1073 | nl_rate = nla_nest_start(msg, i); |
| 1074 | if (!nl_rate) |
| 1075 | return -ENOBUFS; |
| 1076 | |
| 1077 | rate = &sband->bitrates[i]; |
| 1078 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1079 | rate->bitrate)) |
| 1080 | return -ENOBUFS; |
| 1081 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1082 | nla_put_flag(msg, |
| 1083 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1084 | return -ENOBUFS; |
| 1085 | |
| 1086 | nla_nest_end(msg, nl_rate); |
| 1087 | } |
| 1088 | |
| 1089 | nla_nest_end(msg, nl_rates); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | static int |
| 1095 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1096 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1097 | { |
| 1098 | u16 stypes; |
| 1099 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1100 | enum nl80211_iftype ift; |
| 1101 | int i; |
| 1102 | |
| 1103 | if (!mgmt_stypes) |
| 1104 | return 0; |
| 1105 | |
| 1106 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1107 | if (!nl_ifs) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1111 | nl_ftypes = nla_nest_start(msg, ift); |
| 1112 | if (!nl_ftypes) |
| 1113 | return -ENOBUFS; |
| 1114 | i = 0; |
| 1115 | stypes = mgmt_stypes[ift].tx; |
| 1116 | while (stypes) { |
| 1117 | if ((stypes & 1) && |
| 1118 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1119 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1120 | return -ENOBUFS; |
| 1121 | stypes >>= 1; |
| 1122 | i++; |
| 1123 | } |
| 1124 | nla_nest_end(msg, nl_ftypes); |
| 1125 | } |
| 1126 | |
| 1127 | nla_nest_end(msg, nl_ifs); |
| 1128 | |
| 1129 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1130 | if (!nl_ifs) |
| 1131 | return -ENOBUFS; |
| 1132 | |
| 1133 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1134 | nl_ftypes = nla_nest_start(msg, ift); |
| 1135 | if (!nl_ftypes) |
| 1136 | return -ENOBUFS; |
| 1137 | i = 0; |
| 1138 | stypes = mgmt_stypes[ift].rx; |
| 1139 | while (stypes) { |
| 1140 | if ((stypes & 1) && |
| 1141 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1142 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1143 | return -ENOBUFS; |
| 1144 | stypes >>= 1; |
| 1145 | i++; |
| 1146 | } |
| 1147 | nla_nest_end(msg, nl_ftypes); |
| 1148 | } |
| 1149 | nla_nest_end(msg, nl_ifs); |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1155 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1156 | int flags, bool split, long *split_start, |
| 1157 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1158 | { |
| 1159 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1160 | struct nlattr *nl_bands, *nl_band; |
| 1161 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1162 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1163 | enum ieee80211_band band; |
| 1164 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1165 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1166 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1167 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1168 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1169 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1170 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1171 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1172 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1173 | return -ENOBUFS; |
| 1174 | |
| 1175 | /* allow always using the variables */ |
| 1176 | if (!split) { |
| 1177 | split_start = &start; |
| 1178 | band_start = &start_band; |
| 1179 | chan_start = &start_chan; |
| 1180 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1184 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1185 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1186 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1187 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1188 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1189 | switch (*split_start) { |
| 1190 | case 0: |
| 1191 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1192 | dev->wiphy.retry_short) || |
| 1193 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1194 | dev->wiphy.retry_long) || |
| 1195 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1196 | dev->wiphy.frag_threshold) || |
| 1197 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1198 | dev->wiphy.rts_threshold) || |
| 1199 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1200 | dev->wiphy.coverage_class) || |
| 1201 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1202 | dev->wiphy.max_scan_ssids) || |
| 1203 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1204 | dev->wiphy.max_sched_scan_ssids) || |
| 1205 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1206 | dev->wiphy.max_scan_ie_len) || |
| 1207 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1208 | dev->wiphy.max_sched_scan_ie_len) || |
| 1209 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1210 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1211 | goto nla_put_failure; |
| 1212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1214 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1215 | goto nla_put_failure; |
| 1216 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1217 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1218 | goto nla_put_failure; |
| 1219 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1220 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1221 | goto nla_put_failure; |
| 1222 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1223 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1224 | goto nla_put_failure; |
| 1225 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1226 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1227 | goto nla_put_failure; |
| 1228 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1229 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1230 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1231 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1232 | (*split_start)++; |
| 1233 | if (split) |
| 1234 | break; |
| 1235 | case 1: |
| 1236 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1237 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1238 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1239 | goto nla_put_failure; |
| 1240 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1241 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1242 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1243 | goto nla_put_failure; |
| 1244 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1245 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1246 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1247 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1248 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1250 | dev->wiphy.available_antennas_tx) || |
| 1251 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1252 | dev->wiphy.available_antennas_rx)) |
| 1253 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1254 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1256 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1257 | dev->wiphy.probe_resp_offload)) |
| 1258 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1259 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | if ((dev->wiphy.available_antennas_tx || |
| 1261 | dev->wiphy.available_antennas_rx) && |
| 1262 | dev->ops->get_antenna) { |
| 1263 | u32 tx_ant = 0, rx_ant = 0; |
| 1264 | int res; |
| 1265 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1266 | if (!res) { |
| 1267 | if (nla_put_u32(msg, |
| 1268 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1269 | tx_ant) || |
| 1270 | nla_put_u32(msg, |
| 1271 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1272 | rx_ant)) |
| 1273 | goto nla_put_failure; |
| 1274 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | (*split_start)++; |
| 1278 | if (split) |
| 1279 | break; |
| 1280 | case 2: |
| 1281 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1282 | dev->wiphy.interface_modes)) |
| 1283 | goto nla_put_failure; |
| 1284 | (*split_start)++; |
| 1285 | if (split) |
| 1286 | break; |
| 1287 | case 3: |
| 1288 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1289 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1290 | goto nla_put_failure; |
| 1291 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
| 1293 | struct ieee80211_supported_band *sband; |
| 1294 | |
| 1295 | sband = dev->wiphy.bands[band]; |
| 1296 | |
| 1297 | if (!sband) |
| 1298 | continue; |
| 1299 | |
| 1300 | nl_band = nla_nest_start(msg, band); |
| 1301 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1302 | goto nla_put_failure; |
| 1303 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | switch (*chan_start) { |
| 1305 | case 0: |
| 1306 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1307 | goto nla_put_failure; |
| 1308 | (*chan_start)++; |
| 1309 | if (split) |
| 1310 | break; |
| 1311 | default: |
| 1312 | /* add frequencies */ |
| 1313 | nl_freqs = nla_nest_start( |
| 1314 | msg, NL80211_BAND_ATTR_FREQS); |
| 1315 | if (!nl_freqs) |
| 1316 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1317 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | for (i = *chan_start - 1; |
| 1319 | i < sband->n_channels; |
| 1320 | i++) { |
| 1321 | nl_freq = nla_nest_start(msg, i); |
| 1322 | if (!nl_freq) |
| 1323 | goto nla_put_failure; |
| 1324 | |
| 1325 | chan = &sband->channels[i]; |
| 1326 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1327 | if (nl80211_msg_put_channel(msg, chan, |
| 1328 | split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
| 1330 | |
| 1331 | nla_nest_end(msg, nl_freq); |
| 1332 | if (split) |
| 1333 | break; |
| 1334 | } |
| 1335 | if (i < sband->n_channels) |
| 1336 | *chan_start = i + 2; |
| 1337 | else |
| 1338 | *chan_start = 0; |
| 1339 | nla_nest_end(msg, nl_freqs); |
| 1340 | } |
| 1341 | |
| 1342 | nla_nest_end(msg, nl_band); |
| 1343 | |
| 1344 | if (split) { |
| 1345 | /* start again here */ |
| 1346 | if (*chan_start) |
| 1347 | band--; |
| 1348 | break; |
| 1349 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1350 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1352 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | if (band < IEEE80211_NUM_BANDS) |
| 1354 | *band_start = band + 1; |
| 1355 | else |
| 1356 | *band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | /* if bands & channels are done, continue outside */ |
| 1359 | if (*band_start == 0 && *chan_start == 0) |
| 1360 | (*split_start)++; |
| 1361 | if (split) |
| 1362 | break; |
| 1363 | case 4: |
| 1364 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1365 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1366 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | |
| 1368 | i = 0; |
| 1369 | #define CMD(op, n) \ |
| 1370 | do { \ |
| 1371 | if (dev->ops->op) { \ |
| 1372 | i++; \ |
| 1373 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1374 | goto nla_put_failure; \ |
| 1375 | } \ |
| 1376 | } while (0) |
| 1377 | |
| 1378 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1379 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1380 | CMD(add_key, NEW_KEY); |
| 1381 | CMD(start_ap, START_AP); |
| 1382 | CMD(add_station, NEW_STATION); |
| 1383 | CMD(add_mpath, NEW_MPATH); |
| 1384 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1385 | CMD(change_bss, SET_BSS); |
| 1386 | CMD(auth, AUTHENTICATE); |
| 1387 | CMD(assoc, ASSOCIATE); |
| 1388 | CMD(deauth, DEAUTHENTICATE); |
| 1389 | CMD(disassoc, DISASSOCIATE); |
| 1390 | CMD(join_ibss, JOIN_IBSS); |
| 1391 | CMD(join_mesh, JOIN_MESH); |
| 1392 | CMD(set_pmksa, SET_PMKSA); |
| 1393 | CMD(del_pmksa, DEL_PMKSA); |
| 1394 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1395 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1396 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1397 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1398 | CMD(mgmt_tx, FRAME); |
| 1399 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1400 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1401 | i++; |
| 1402 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1403 | goto nla_put_failure; |
| 1404 | } |
| 1405 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1406 | dev->ops->join_mesh) { |
| 1407 | i++; |
| 1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1409 | goto nla_put_failure; |
| 1410 | } |
| 1411 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1412 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1413 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1414 | CMD(tdls_oper, TDLS_OPER); |
| 1415 | } |
| 1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1417 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1418 | CMD(probe_client, PROBE_CLIENT); |
| 1419 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1420 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1421 | i++; |
| 1422 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1423 | goto nla_put_failure; |
| 1424 | } |
| 1425 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1426 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1427 | if (split) { |
| 1428 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1429 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
| 1430 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1431 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1432 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1434 | #endif |
| 1435 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1436 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1437 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | if (dev->ops->connect || dev->ops->auth) { |
| 1439 | i++; |
| 1440 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1441 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1445 | i++; |
| 1446 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1447 | goto nla_put_failure; |
| 1448 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1449 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | nla_nest_end(msg, nl_cmds); |
| 1451 | (*split_start)++; |
| 1452 | if (split) |
| 1453 | break; |
| 1454 | case 5: |
| 1455 | if (dev->ops->remain_on_channel && |
| 1456 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1457 | nla_put_u32(msg, |
| 1458 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1459 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1460 | goto nla_put_failure; |
| 1461 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1463 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1464 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1465 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1467 | goto nla_put_failure; |
| 1468 | (*split_start)++; |
| 1469 | if (split) |
| 1470 | break; |
| 1471 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1472 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1473 | if (nl80211_send_wowlan(msg, dev, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | goto nla_put_failure; |
| 1475 | (*split_start)++; |
| 1476 | if (split) |
| 1477 | break; |
| 1478 | #else |
| 1479 | (*split_start)++; |
| 1480 | #endif |
| 1481 | case 7: |
| 1482 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1483 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1484 | goto nla_put_failure; |
| 1485 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1486 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1488 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1489 | (*split_start)++; |
| 1490 | if (split) |
| 1491 | break; |
| 1492 | case 8: |
| 1493 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1494 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1495 | dev->wiphy.ap_sme_capa)) |
| 1496 | goto nla_put_failure; |
| 1497 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1498 | features = dev->wiphy.features; |
| 1499 | /* |
| 1500 | * We can only add the per-channel limit information if the |
| 1501 | * dump is split, otherwise it makes it too big. Therefore |
| 1502 | * only advertise it in that case. |
| 1503 | */ |
| 1504 | if (split) |
| 1505 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1506 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | goto nla_put_failure; |
| 1508 | |
| 1509 | if (dev->wiphy.ht_capa_mod_mask && |
| 1510 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1511 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1512 | dev->wiphy.ht_capa_mod_mask)) |
| 1513 | goto nla_put_failure; |
| 1514 | |
| 1515 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1516 | dev->wiphy.max_acl_mac_addrs && |
| 1517 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1518 | dev->wiphy.max_acl_mac_addrs)) |
| 1519 | goto nla_put_failure; |
| 1520 | |
| 1521 | /* |
| 1522 | * Any information below this point is only available to |
| 1523 | * applications that can deal with it being split. This |
| 1524 | * helps ensure that newly added capabilities don't break |
| 1525 | * older tools by overrunning their buffers. |
| 1526 | * |
| 1527 | * We still increment split_start so that in the split |
| 1528 | * case we'll continue with more data in the next round, |
| 1529 | * but break unconditionally so unsplit data stops here. |
| 1530 | */ |
| 1531 | (*split_start)++; |
| 1532 | break; |
| 1533 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1534 | if (dev->wiphy.extended_capabilities && |
| 1535 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1536 | dev->wiphy.extended_capabilities_len, |
| 1537 | dev->wiphy.extended_capabilities) || |
| 1538 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1539 | dev->wiphy.extended_capabilities_len, |
| 1540 | dev->wiphy.extended_capabilities_mask))) |
| 1541 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1542 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1543 | if (dev->wiphy.vht_capa_mod_mask && |
| 1544 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1545 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1546 | dev->wiphy.vht_capa_mod_mask)) |
| 1547 | goto nla_put_failure; |
| 1548 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | /* done */ |
| 1550 | *split_start = 0; |
| 1551 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1552 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1553 | return genlmsg_end(msg, hdr); |
| 1554 | |
| 1555 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1556 | genlmsg_cancel(msg, hdr); |
| 1557 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1561 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1562 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1563 | int start = cb->args[0]; |
| 1564 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | s64 filter_wiphy = -1; |
| 1566 | bool split = false; |
| 1567 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1568 | int res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1569 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1570 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1571 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1572 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1573 | if (res == 0) { |
| 1574 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1575 | if (tb[NL80211_ATTR_WIPHY]) |
| 1576 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1577 | if (tb[NL80211_ATTR_WDEV]) |
| 1578 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1579 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1580 | struct net_device *netdev; |
| 1581 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1582 | |
| 1583 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1584 | if (!netdev) { |
| 1585 | mutex_unlock(&cfg80211_mutex); |
| 1586 | return -ENODEV; |
| 1587 | } |
| 1588 | if (netdev->ieee80211_ptr) { |
| 1589 | dev = wiphy_to_dev( |
| 1590 | netdev->ieee80211_ptr->wiphy); |
| 1591 | filter_wiphy = dev->wiphy_idx; |
| 1592 | } |
| 1593 | dev_put(netdev); |
| 1594 | } |
| 1595 | } |
| 1596 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1597 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1598 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1599 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1600 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1601 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1602 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1603 | continue; |
| 1604 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1605 | do { |
| 1606 | ret = nl80211_send_wiphy(dev, skb, |
| 1607 | NETLINK_CB(cb->skb).portid, |
| 1608 | cb->nlh->nlmsg_seq, |
| 1609 | NLM_F_MULTI, |
| 1610 | split, &cb->args[1], |
| 1611 | &cb->args[2], |
| 1612 | &cb->args[3]); |
| 1613 | if (ret < 0) { |
| 1614 | /* |
| 1615 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1616 | * or EMSGSIZE returned), this SKB is still |
| 1617 | * empty (so it's not too big because another |
| 1618 | * wiphy dataset is already in the skb) and |
| 1619 | * we've not tried to adjust the dump allocation |
| 1620 | * yet ... then adjust the alloc size to be |
| 1621 | * bigger, and return 1 but with the empty skb. |
| 1622 | * This results in an empty message being RX'ed |
| 1623 | * in userspace, but that is ignored. |
| 1624 | * |
| 1625 | * We can then retry with the larger buffer. |
| 1626 | */ |
| 1627 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1628 | !skb->len && |
| 1629 | cb->min_dump_alloc < 4096) { |
| 1630 | cb->min_dump_alloc = 4096; |
| 1631 | mutex_unlock(&cfg80211_mutex); |
| 1632 | return 1; |
| 1633 | } |
| 1634 | idx--; |
| 1635 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1636 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1637 | } while (cb->args[1] > 0); |
| 1638 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1639 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1640 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1641 | |
| 1642 | cb->args[0] = idx; |
| 1643 | |
| 1644 | return skb->len; |
| 1645 | } |
| 1646 | |
| 1647 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1648 | { |
| 1649 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1650 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1651 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1652 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1653 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1654 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1655 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1656 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1657 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1658 | nlmsg_free(msg); |
| 1659 | return -ENOBUFS; |
| 1660 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1661 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1662 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1665 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1666 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1667 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1668 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1669 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1670 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1671 | }; |
| 1672 | |
| 1673 | static int parse_txq_params(struct nlattr *tb[], |
| 1674 | struct ieee80211_txq_params *txq_params) |
| 1675 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1676 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1677 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1678 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1679 | return -EINVAL; |
| 1680 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1681 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1682 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1683 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1684 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1685 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1686 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1687 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1688 | return -EINVAL; |
| 1689 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1690 | return 0; |
| 1691 | } |
| 1692 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1693 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1694 | { |
| 1695 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1696 | * You can only set the channel explicitly for WDS interfaces, |
| 1697 | * all others have their channel managed via their respective |
| 1698 | * "establish a connection" command (connect, join, ...) |
| 1699 | * |
| 1700 | * For AP/GO and mesh mode, the channel can be set with the |
| 1701 | * channel userspace API, but is only stored and passed to the |
| 1702 | * low-level driver when the AP starts or the mesh is joined. |
| 1703 | * This is for backward compatibility, userspace can also give |
| 1704 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1705 | * |
| 1706 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1707 | * whatever else is going on, so they have their own special |
| 1708 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1709 | */ |
| 1710 | return !wdev || |
| 1711 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1712 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1713 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1714 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1715 | } |
| 1716 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1717 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1718 | struct genl_info *info, |
| 1719 | struct cfg80211_chan_def *chandef) |
| 1720 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1721 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1722 | |
| 1723 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1724 | return -EINVAL; |
| 1725 | |
| 1726 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1727 | |
| 1728 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1729 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1730 | chandef->center_freq1 = control_freq; |
| 1731 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1732 | |
| 1733 | /* Primary channel not allowed */ |
| 1734 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1735 | return -EINVAL; |
| 1736 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1737 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1738 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1739 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1740 | chantype = nla_get_u32( |
| 1741 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1742 | |
| 1743 | switch (chantype) { |
| 1744 | case NL80211_CHAN_NO_HT: |
| 1745 | case NL80211_CHAN_HT20: |
| 1746 | case NL80211_CHAN_HT40PLUS: |
| 1747 | case NL80211_CHAN_HT40MINUS: |
| 1748 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1749 | chantype); |
| 1750 | break; |
| 1751 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1752 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1753 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1754 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1755 | chandef->width = |
| 1756 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1757 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1758 | chandef->center_freq1 = |
| 1759 | nla_get_u32( |
| 1760 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1761 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1762 | chandef->center_freq2 = |
| 1763 | nla_get_u32( |
| 1764 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1765 | } |
| 1766 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1767 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1768 | return -EINVAL; |
| 1769 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1770 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1771 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1772 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1773 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1774 | return 0; |
| 1775 | } |
| 1776 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1777 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1778 | struct wireless_dev *wdev, |
| 1779 | struct genl_info *info) |
| 1780 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1781 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1782 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1783 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1784 | |
| 1785 | if (wdev) |
| 1786 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1787 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1788 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1789 | return -EOPNOTSUPP; |
| 1790 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1791 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1792 | if (result) |
| 1793 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1794 | |
| 1795 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1796 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1797 | case NL80211_IFTYPE_AP: |
| 1798 | case NL80211_IFTYPE_P2P_GO: |
| 1799 | if (wdev->beacon_interval) { |
| 1800 | result = -EBUSY; |
| 1801 | break; |
| 1802 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1803 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1804 | result = -EINVAL; |
| 1805 | break; |
| 1806 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1807 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1808 | result = 0; |
| 1809 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1810 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1811 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1812 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1813 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1814 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1815 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1816 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1817 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1818 | } |
| 1819 | mutex_unlock(&rdev->devlist_mtx); |
| 1820 | |
| 1821 | return result; |
| 1822 | } |
| 1823 | |
| 1824 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1825 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1827 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1828 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1829 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1830 | } |
| 1831 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1832 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1833 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1835 | struct net_device *dev = info->user_ptr[1]; |
| 1836 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1837 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1838 | |
| 1839 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1840 | return -EINVAL; |
| 1841 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1842 | if (netif_running(dev)) |
| 1843 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1844 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1845 | if (!rdev->ops->set_wds_peer) |
| 1846 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1847 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1848 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1849 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1850 | |
| 1851 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1852 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1856 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1857 | { |
| 1858 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1859 | struct net_device *netdev = NULL; |
| 1860 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1861 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1862 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1863 | u32 changed; |
| 1864 | u8 retry_short = 0, retry_long = 0; |
| 1865 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1866 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1867 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1868 | /* |
| 1869 | * Try to find the wiphy and netdev. Normally this |
| 1870 | * function shouldn't need the netdev, but this is |
| 1871 | * done for backward compatibility -- previously |
| 1872 | * setting the channel was done per wiphy, but now |
| 1873 | * it is per netdev. Previous userland like hostapd |
| 1874 | * also passed a netdev to set_wiphy, so that it is |
| 1875 | * possible to let that go to the right netdev! |
| 1876 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1877 | mutex_lock(&cfg80211_mutex); |
| 1878 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1879 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1880 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1881 | |
| 1882 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1883 | if (netdev && netdev->ieee80211_ptr) { |
| 1884 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1885 | mutex_lock(&rdev->mtx); |
| 1886 | } else |
| 1887 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1890 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1891 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1892 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1893 | if (IS_ERR(rdev)) { |
| 1894 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1895 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1896 | } |
| 1897 | wdev = NULL; |
| 1898 | netdev = NULL; |
| 1899 | result = 0; |
| 1900 | |
| 1901 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1902 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1903 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1904 | |
| 1905 | /* |
| 1906 | * end workaround code, by now the rdev is available |
| 1907 | * and locked, and wdev may or may not be NULL. |
| 1908 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1909 | |
| 1910 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1911 | result = cfg80211_dev_rename( |
| 1912 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1913 | |
| 1914 | mutex_unlock(&cfg80211_mutex); |
| 1915 | |
| 1916 | if (result) |
| 1917 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1918 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1919 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1920 | struct ieee80211_txq_params txq_params; |
| 1921 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1922 | |
| 1923 | if (!rdev->ops->set_txq_params) { |
| 1924 | result = -EOPNOTSUPP; |
| 1925 | goto bad_res; |
| 1926 | } |
| 1927 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1928 | if (!netdev) { |
| 1929 | result = -EINVAL; |
| 1930 | goto bad_res; |
| 1931 | } |
| 1932 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1933 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1934 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1935 | result = -EINVAL; |
| 1936 | goto bad_res; |
| 1937 | } |
| 1938 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1939 | if (!netif_running(netdev)) { |
| 1940 | result = -ENETDOWN; |
| 1941 | goto bad_res; |
| 1942 | } |
| 1943 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1944 | nla_for_each_nested(nl_txq_params, |
| 1945 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1946 | rem_txq_params) { |
| 1947 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1948 | nla_data(nl_txq_params), |
| 1949 | nla_len(nl_txq_params), |
| 1950 | txq_params_policy); |
| 1951 | result = parse_txq_params(tb, &txq_params); |
| 1952 | if (result) |
| 1953 | goto bad_res; |
| 1954 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1955 | result = rdev_set_txq_params(rdev, netdev, |
| 1956 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1957 | if (result) |
| 1958 | goto bad_res; |
| 1959 | } |
| 1960 | } |
| 1961 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1962 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1963 | result = __nl80211_set_channel(rdev, |
| 1964 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1965 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1966 | if (result) |
| 1967 | goto bad_res; |
| 1968 | } |
| 1969 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1970 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1971 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1972 | enum nl80211_tx_power_setting type; |
| 1973 | int idx, mbm = 0; |
| 1974 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1975 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1976 | txp_wdev = NULL; |
| 1977 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1978 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1979 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1980 | goto bad_res; |
| 1981 | } |
| 1982 | |
| 1983 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1984 | type = nla_get_u32(info->attrs[idx]); |
| 1985 | |
| 1986 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1987 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1988 | result = -EINVAL; |
| 1989 | goto bad_res; |
| 1990 | } |
| 1991 | |
| 1992 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1993 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1994 | mbm = nla_get_u32(info->attrs[idx]); |
| 1995 | } |
| 1996 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1997 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1998 | if (result) |
| 1999 | goto bad_res; |
| 2000 | } |
| 2001 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2002 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2003 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2004 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2005 | if ((!rdev->wiphy.available_antennas_tx && |
| 2006 | !rdev->wiphy.available_antennas_rx) || |
| 2007 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2008 | result = -EOPNOTSUPP; |
| 2009 | goto bad_res; |
| 2010 | } |
| 2011 | |
| 2012 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2013 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2014 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2015 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2016 | * available antenna masks, except for the "all" mask */ |
| 2017 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2018 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2019 | result = -EINVAL; |
| 2020 | goto bad_res; |
| 2021 | } |
| 2022 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2023 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2024 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2026 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2027 | if (result) |
| 2028 | goto bad_res; |
| 2029 | } |
| 2030 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2031 | changed = 0; |
| 2032 | |
| 2033 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2034 | retry_short = nla_get_u8( |
| 2035 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2036 | if (retry_short == 0) { |
| 2037 | result = -EINVAL; |
| 2038 | goto bad_res; |
| 2039 | } |
| 2040 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2041 | } |
| 2042 | |
| 2043 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2044 | retry_long = nla_get_u8( |
| 2045 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2046 | if (retry_long == 0) { |
| 2047 | result = -EINVAL; |
| 2048 | goto bad_res; |
| 2049 | } |
| 2050 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2051 | } |
| 2052 | |
| 2053 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2054 | frag_threshold = nla_get_u32( |
| 2055 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2056 | if (frag_threshold < 256) { |
| 2057 | result = -EINVAL; |
| 2058 | goto bad_res; |
| 2059 | } |
| 2060 | if (frag_threshold != (u32) -1) { |
| 2061 | /* |
| 2062 | * Fragments (apart from the last one) are required to |
| 2063 | * have even length. Make the fragmentation code |
| 2064 | * simpler by stripping LSB should someone try to use |
| 2065 | * odd threshold value. |
| 2066 | */ |
| 2067 | frag_threshold &= ~0x1; |
| 2068 | } |
| 2069 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2070 | } |
| 2071 | |
| 2072 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2073 | rts_threshold = nla_get_u32( |
| 2074 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2075 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2076 | } |
| 2077 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2078 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2079 | coverage_class = nla_get_u8( |
| 2080 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2081 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2082 | } |
| 2083 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2084 | if (changed) { |
| 2085 | u8 old_retry_short, old_retry_long; |
| 2086 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2087 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2088 | |
| 2089 | if (!rdev->ops->set_wiphy_params) { |
| 2090 | result = -EOPNOTSUPP; |
| 2091 | goto bad_res; |
| 2092 | } |
| 2093 | |
| 2094 | old_retry_short = rdev->wiphy.retry_short; |
| 2095 | old_retry_long = rdev->wiphy.retry_long; |
| 2096 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2097 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2098 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2099 | |
| 2100 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2101 | rdev->wiphy.retry_short = retry_short; |
| 2102 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2103 | rdev->wiphy.retry_long = retry_long; |
| 2104 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2105 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2106 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2107 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2108 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2109 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2110 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2111 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2112 | if (result) { |
| 2113 | rdev->wiphy.retry_short = old_retry_short; |
| 2114 | rdev->wiphy.retry_long = old_retry_long; |
| 2115 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2116 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2117 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2118 | } |
| 2119 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2120 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2121 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2122 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2123 | if (netdev) |
| 2124 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2125 | return result; |
| 2126 | } |
| 2127 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2128 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2129 | { |
| 2130 | return (u64)wdev->identifier | |
| 2131 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2132 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2133 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2134 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2135 | struct cfg80211_chan_def *chandef) |
| 2136 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2137 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2138 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2139 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2140 | chandef->chan->center_freq)) |
| 2141 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2142 | switch (chandef->width) { |
| 2143 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2144 | case NL80211_CHAN_WIDTH_20: |
| 2145 | case NL80211_CHAN_WIDTH_40: |
| 2146 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2147 | cfg80211_get_chandef_type(chandef))) |
| 2148 | return -ENOBUFS; |
| 2149 | break; |
| 2150 | default: |
| 2151 | break; |
| 2152 | } |
| 2153 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2154 | return -ENOBUFS; |
| 2155 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2156 | return -ENOBUFS; |
| 2157 | if (chandef->center_freq2 && |
| 2158 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2159 | return -ENOBUFS; |
| 2160 | return 0; |
| 2161 | } |
| 2162 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2163 | 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] | 2164 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2165 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2166 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2167 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2168 | void *hdr; |
| 2169 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2170 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2171 | if (!hdr) |
| 2172 | return -1; |
| 2173 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2174 | if (dev && |
| 2175 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2176 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2177 | goto nla_put_failure; |
| 2178 | |
| 2179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2180 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2181 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2182 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2183 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2184 | rdev->devlist_generation ^ |
| 2185 | (cfg80211_rdev_list_generation << 2))) |
| 2186 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2187 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2188 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2189 | int ret; |
| 2190 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2191 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2192 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2193 | if (ret == 0) { |
| 2194 | if (nl80211_send_chandef(msg, &chandef)) |
| 2195 | goto nla_put_failure; |
| 2196 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2197 | } |
| 2198 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2199 | if (wdev->ssid_len) { |
| 2200 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2201 | goto nla_put_failure; |
| 2202 | } |
| 2203 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2204 | return genlmsg_end(msg, hdr); |
| 2205 | |
| 2206 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2207 | genlmsg_cancel(msg, hdr); |
| 2208 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2212 | { |
| 2213 | int wp_idx = 0; |
| 2214 | int if_idx = 0; |
| 2215 | int wp_start = cb->args[0]; |
| 2216 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2217 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2218 | struct wireless_dev *wdev; |
| 2219 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2220 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2221 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2222 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2223 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2224 | if (wp_idx < wp_start) { |
| 2225 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2226 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2227 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2228 | if_idx = 0; |
| 2229 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2230 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2231 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2232 | if (if_idx < if_start) { |
| 2233 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2234 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2235 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2236 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2237 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2238 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2239 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2240 | goto out; |
| 2241 | } |
| 2242 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2243 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2244 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2245 | |
| 2246 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2247 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2248 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2249 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2250 | |
| 2251 | cb->args[0] = wp_idx; |
| 2252 | cb->args[1] = if_idx; |
| 2253 | |
| 2254 | return skb->len; |
| 2255 | } |
| 2256 | |
| 2257 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2258 | { |
| 2259 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2260 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2261 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2262 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2263 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2265 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2266 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2267 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2268 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2269 | nlmsg_free(msg); |
| 2270 | return -ENOBUFS; |
| 2271 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2272 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2273 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2274 | } |
| 2275 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2276 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2277 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2278 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2279 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2280 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2281 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2282 | }; |
| 2283 | |
| 2284 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2285 | { |
| 2286 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2287 | int flag; |
| 2288 | |
| 2289 | *mntrflags = 0; |
| 2290 | |
| 2291 | if (!nla) |
| 2292 | return -EINVAL; |
| 2293 | |
| 2294 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2295 | nla, mntr_flags_policy)) |
| 2296 | return -EINVAL; |
| 2297 | |
| 2298 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2299 | if (flags[flag]) |
| 2300 | *mntrflags |= (1<<flag); |
| 2301 | |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2305 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2306 | struct net_device *netdev, u8 use_4addr, |
| 2307 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2308 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2309 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2310 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2311 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2312 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2313 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2314 | |
| 2315 | switch (iftype) { |
| 2316 | case NL80211_IFTYPE_AP_VLAN: |
| 2317 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2318 | return 0; |
| 2319 | break; |
| 2320 | case NL80211_IFTYPE_STATION: |
| 2321 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2322 | return 0; |
| 2323 | break; |
| 2324 | default: |
| 2325 | break; |
| 2326 | } |
| 2327 | |
| 2328 | return -EOPNOTSUPP; |
| 2329 | } |
| 2330 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2331 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2332 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2334 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2335 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2336 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2337 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2338 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2339 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2340 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2341 | memset(¶ms, 0, sizeof(params)); |
| 2342 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2343 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2344 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2345 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2346 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2347 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2348 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2349 | if (ntype > NL80211_IFTYPE_MAX) |
| 2350 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2353 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2354 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2355 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2356 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2357 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2358 | if (netif_running(dev)) |
| 2359 | return -EBUSY; |
| 2360 | |
| 2361 | wdev_lock(wdev); |
| 2362 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2363 | IEEE80211_MAX_MESH_ID_LEN); |
| 2364 | wdev->mesh_id_up_len = |
| 2365 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2366 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2367 | wdev->mesh_id_up_len); |
| 2368 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2369 | } |
| 2370 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2371 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2372 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2373 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2374 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2375 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2376 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2377 | } else { |
| 2378 | params.use_4addr = -1; |
| 2379 | } |
| 2380 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2381 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2383 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2384 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2385 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2386 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2387 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2388 | |
| 2389 | flags = &_flags; |
| 2390 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2391 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2392 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2393 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2394 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2395 | else |
| 2396 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2397 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2398 | if (!err && params.use_4addr != -1) |
| 2399 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2400 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2401 | return err; |
| 2402 | } |
| 2403 | |
| 2404 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2405 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2407 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2408 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2409 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2410 | int err; |
| 2411 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2412 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2413 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2414 | memset(¶ms, 0, sizeof(params)); |
| 2415 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2416 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2417 | return -EINVAL; |
| 2418 | |
| 2419 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2420 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2421 | if (type > NL80211_IFTYPE_MAX) |
| 2422 | return -EINVAL; |
| 2423 | } |
| 2424 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2425 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2426 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2427 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2428 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2429 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2430 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2431 | ETH_ALEN); |
| 2432 | if (!is_valid_ether_addr(params.macaddr)) |
| 2433 | return -EADDRNOTAVAIL; |
| 2434 | } |
| 2435 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2436 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2437 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2438 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2439 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2441 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2442 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2443 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2444 | if (!msg) |
| 2445 | return -ENOMEM; |
| 2446 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2447 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2448 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2449 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2450 | wdev = rdev_add_virtual_intf(rdev, |
| 2451 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2452 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2453 | if (IS_ERR(wdev)) { |
| 2454 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2455 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2456 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2457 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2458 | switch (type) { |
| 2459 | case NL80211_IFTYPE_MESH_POINT: |
| 2460 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2461 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2462 | wdev_lock(wdev); |
| 2463 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2464 | IEEE80211_MAX_MESH_ID_LEN); |
| 2465 | wdev->mesh_id_up_len = |
| 2466 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2467 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2468 | wdev->mesh_id_up_len); |
| 2469 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2470 | break; |
| 2471 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2472 | /* |
| 2473 | * P2P Device doesn't have a netdev, so doesn't go |
| 2474 | * through the netdev notifier and must be added here |
| 2475 | */ |
| 2476 | mutex_init(&wdev->mtx); |
| 2477 | INIT_LIST_HEAD(&wdev->event_list); |
| 2478 | spin_lock_init(&wdev->event_lock); |
| 2479 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2480 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2481 | |
| 2482 | mutex_lock(&rdev->devlist_mtx); |
| 2483 | wdev->identifier = ++rdev->wdev_id; |
| 2484 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2485 | rdev->devlist_generation++; |
| 2486 | mutex_unlock(&rdev->devlist_mtx); |
| 2487 | break; |
| 2488 | default: |
| 2489 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2490 | } |
| 2491 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2492 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2493 | rdev, wdev) < 0) { |
| 2494 | nlmsg_free(msg); |
| 2495 | return -ENOBUFS; |
| 2496 | } |
| 2497 | |
| 2498 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2502 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2504 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2505 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2506 | if (!rdev->ops->del_virtual_intf) |
| 2507 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2508 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2509 | /* |
| 2510 | * If we remove a wireless device without a netdev then clear |
| 2511 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2512 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2513 | * since the wdev has been freed, unlike with a netdev where |
| 2514 | * we need the dev_put() for the netdev to really be freed. |
| 2515 | */ |
| 2516 | if (!wdev->netdev) |
| 2517 | info->user_ptr[1] = NULL; |
| 2518 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2519 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2520 | } |
| 2521 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2522 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2523 | { |
| 2524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2525 | struct net_device *dev = info->user_ptr[1]; |
| 2526 | u16 noack_map; |
| 2527 | |
| 2528 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2529 | return -EINVAL; |
| 2530 | |
| 2531 | if (!rdev->ops->set_noack_map) |
| 2532 | return -EOPNOTSUPP; |
| 2533 | |
| 2534 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2535 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2536 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2537 | } |
| 2538 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2539 | struct get_key_cookie { |
| 2540 | struct sk_buff *msg; |
| 2541 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2542 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2543 | }; |
| 2544 | |
| 2545 | static void get_key_callback(void *c, struct key_params *params) |
| 2546 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2547 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2548 | struct get_key_cookie *cookie = c; |
| 2549 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2550 | if ((params->key && |
| 2551 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2552 | params->key_len, params->key)) || |
| 2553 | (params->seq && |
| 2554 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2555 | params->seq_len, params->seq)) || |
| 2556 | (params->cipher && |
| 2557 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2558 | params->cipher))) |
| 2559 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2560 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2561 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2562 | if (!key) |
| 2563 | goto nla_put_failure; |
| 2564 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2565 | if ((params->key && |
| 2566 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2567 | params->key_len, params->key)) || |
| 2568 | (params->seq && |
| 2569 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2570 | params->seq_len, params->seq)) || |
| 2571 | (params->cipher && |
| 2572 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2573 | params->cipher))) |
| 2574 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2575 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2576 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2577 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2578 | |
| 2579 | nla_nest_end(cookie->msg, key); |
| 2580 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2581 | return; |
| 2582 | nla_put_failure: |
| 2583 | cookie->error = 1; |
| 2584 | } |
| 2585 | |
| 2586 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2587 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2589 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2590 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2591 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2592 | const u8 *mac_addr = NULL; |
| 2593 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2594 | struct get_key_cookie cookie = { |
| 2595 | .error = 0, |
| 2596 | }; |
| 2597 | void *hdr; |
| 2598 | struct sk_buff *msg; |
| 2599 | |
| 2600 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2601 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2602 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2603 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2604 | return -EINVAL; |
| 2605 | |
| 2606 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2607 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2608 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2609 | pairwise = !!mac_addr; |
| 2610 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2611 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2612 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2613 | return -EINVAL; |
| 2614 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2615 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2616 | return -EINVAL; |
| 2617 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2618 | } |
| 2619 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2620 | if (!rdev->ops->get_key) |
| 2621 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2624 | if (!msg) |
| 2625 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2626 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2627 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2628 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2629 | if (IS_ERR(hdr)) |
| 2630 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2631 | |
| 2632 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2633 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2634 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2635 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2636 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2637 | goto nla_put_failure; |
| 2638 | if (mac_addr && |
| 2639 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2640 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2641 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2642 | if (pairwise && mac_addr && |
| 2643 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2644 | return -ENOENT; |
| 2645 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2646 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2647 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2648 | |
| 2649 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2650 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2651 | |
| 2652 | if (cookie.error) |
| 2653 | goto nla_put_failure; |
| 2654 | |
| 2655 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2656 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2657 | |
| 2658 | nla_put_failure: |
| 2659 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2660 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2661 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2662 | return err; |
| 2663 | } |
| 2664 | |
| 2665 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2666 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2668 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2669 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2670 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2671 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2672 | err = nl80211_parse_key(info, &key); |
| 2673 | if (err) |
| 2674 | return err; |
| 2675 | |
| 2676 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2677 | return -EINVAL; |
| 2678 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2679 | /* only support setting default key */ |
| 2680 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2681 | return -EINVAL; |
| 2682 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2683 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2684 | |
| 2685 | if (key.def) { |
| 2686 | if (!rdev->ops->set_default_key) { |
| 2687 | err = -EOPNOTSUPP; |
| 2688 | goto out; |
| 2689 | } |
| 2690 | |
| 2691 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2692 | if (err) |
| 2693 | goto out; |
| 2694 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2695 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2696 | key.def_uni, key.def_multi); |
| 2697 | |
| 2698 | if (err) |
| 2699 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2700 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2701 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2702 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2703 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2704 | } else { |
| 2705 | if (key.def_uni || !key.def_multi) { |
| 2706 | err = -EINVAL; |
| 2707 | goto out; |
| 2708 | } |
| 2709 | |
| 2710 | if (!rdev->ops->set_default_mgmt_key) { |
| 2711 | err = -EOPNOTSUPP; |
| 2712 | goto out; |
| 2713 | } |
| 2714 | |
| 2715 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2716 | if (err) |
| 2717 | goto out; |
| 2718 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2719 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2720 | if (err) |
| 2721 | goto out; |
| 2722 | |
| 2723 | #ifdef CONFIG_CFG80211_WEXT |
| 2724 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2725 | #endif |
| 2726 | } |
| 2727 | |
| 2728 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2729 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2730 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2731 | return err; |
| 2732 | } |
| 2733 | |
| 2734 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2735 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2737 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2738 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2739 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2740 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2742 | err = nl80211_parse_key(info, &key); |
| 2743 | if (err) |
| 2744 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2745 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2746 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2747 | return -EINVAL; |
| 2748 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2749 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2750 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2751 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2752 | if (key.type == -1) { |
| 2753 | if (mac_addr) |
| 2754 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2755 | else |
| 2756 | key.type = NL80211_KEYTYPE_GROUP; |
| 2757 | } |
| 2758 | |
| 2759 | /* for now */ |
| 2760 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2761 | key.type != NL80211_KEYTYPE_GROUP) |
| 2762 | return -EINVAL; |
| 2763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2764 | if (!rdev->ops->add_key) |
| 2765 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2766 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2767 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2768 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2769 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2770 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2771 | |
| 2772 | wdev_lock(dev->ieee80211_ptr); |
| 2773 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2774 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2775 | err = rdev_add_key(rdev, dev, key.idx, |
| 2776 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2777 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2778 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2779 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2780 | return err; |
| 2781 | } |
| 2782 | |
| 2783 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2784 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2787 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2789 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2791 | err = nl80211_parse_key(info, &key); |
| 2792 | if (err) |
| 2793 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2794 | |
| 2795 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2796 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2797 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2798 | if (key.type == -1) { |
| 2799 | if (mac_addr) |
| 2800 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2801 | else |
| 2802 | key.type = NL80211_KEYTYPE_GROUP; |
| 2803 | } |
| 2804 | |
| 2805 | /* for now */ |
| 2806 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2807 | key.type != NL80211_KEYTYPE_GROUP) |
| 2808 | return -EINVAL; |
| 2809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2810 | if (!rdev->ops->del_key) |
| 2811 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2812 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2813 | wdev_lock(dev->ieee80211_ptr); |
| 2814 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2815 | |
| 2816 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2817 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2818 | err = -ENOENT; |
| 2819 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2820 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2821 | err = rdev_del_key(rdev, dev, key.idx, |
| 2822 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2823 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2824 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2825 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2826 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2827 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2828 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2829 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2830 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2831 | } |
| 2832 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2833 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2834 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2835 | return err; |
| 2836 | } |
| 2837 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2838 | /* This function returns an error or the number of nested attributes */ |
| 2839 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2840 | { |
| 2841 | struct nlattr *attr; |
| 2842 | int n_entries = 0, tmp; |
| 2843 | |
| 2844 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2845 | if (nla_len(attr) != ETH_ALEN) |
| 2846 | return -EINVAL; |
| 2847 | |
| 2848 | n_entries++; |
| 2849 | } |
| 2850 | |
| 2851 | return n_entries; |
| 2852 | } |
| 2853 | |
| 2854 | /* |
| 2855 | * This function parses ACL information and allocates memory for ACL data. |
| 2856 | * On successful return, the calling function is responsible to free the |
| 2857 | * ACL buffer returned by this function. |
| 2858 | */ |
| 2859 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2860 | struct genl_info *info) |
| 2861 | { |
| 2862 | enum nl80211_acl_policy acl_policy; |
| 2863 | struct nlattr *attr; |
| 2864 | struct cfg80211_acl_data *acl; |
| 2865 | int i = 0, n_entries, tmp; |
| 2866 | |
| 2867 | if (!wiphy->max_acl_mac_addrs) |
| 2868 | return ERR_PTR(-EOPNOTSUPP); |
| 2869 | |
| 2870 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2871 | return ERR_PTR(-EINVAL); |
| 2872 | |
| 2873 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2874 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2875 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2876 | return ERR_PTR(-EINVAL); |
| 2877 | |
| 2878 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2879 | return ERR_PTR(-EINVAL); |
| 2880 | |
| 2881 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2882 | if (n_entries < 0) |
| 2883 | return ERR_PTR(n_entries); |
| 2884 | |
| 2885 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2886 | return ERR_PTR(-ENOTSUPP); |
| 2887 | |
| 2888 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2889 | GFP_KERNEL); |
| 2890 | if (!acl) |
| 2891 | return ERR_PTR(-ENOMEM); |
| 2892 | |
| 2893 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2894 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2895 | i++; |
| 2896 | } |
| 2897 | |
| 2898 | acl->n_acl_entries = n_entries; |
| 2899 | acl->acl_policy = acl_policy; |
| 2900 | |
| 2901 | return acl; |
| 2902 | } |
| 2903 | |
| 2904 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2905 | { |
| 2906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2907 | struct net_device *dev = info->user_ptr[1]; |
| 2908 | struct cfg80211_acl_data *acl; |
| 2909 | int err; |
| 2910 | |
| 2911 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2912 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2913 | return -EOPNOTSUPP; |
| 2914 | |
| 2915 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2916 | return -EINVAL; |
| 2917 | |
| 2918 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2919 | if (IS_ERR(acl)) |
| 2920 | return PTR_ERR(acl); |
| 2921 | |
| 2922 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2923 | |
| 2924 | kfree(acl); |
| 2925 | |
| 2926 | return err; |
| 2927 | } |
| 2928 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2929 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2930 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2931 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2932 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2933 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2934 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2935 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2936 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2937 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2938 | return -EINVAL; |
| 2939 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2940 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2941 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2942 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2943 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2944 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2945 | if (!bcn->head_len) |
| 2946 | return -EINVAL; |
| 2947 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2951 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2952 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2953 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2954 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2955 | } |
| 2956 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2957 | if (!haveinfo) |
| 2958 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2959 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2960 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2961 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2962 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2966 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2967 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2968 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2969 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2970 | } |
| 2971 | |
| 2972 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2973 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2974 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2975 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2976 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2977 | } |
| 2978 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2979 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2980 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2981 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2982 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2983 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2984 | } |
| 2985 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2986 | return 0; |
| 2987 | } |
| 2988 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2989 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2990 | struct cfg80211_ap_settings *params) |
| 2991 | { |
| 2992 | struct wireless_dev *wdev; |
| 2993 | bool ret = false; |
| 2994 | |
| 2995 | mutex_lock(&rdev->devlist_mtx); |
| 2996 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2997 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2998 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2999 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3000 | continue; |
| 3001 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3002 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3003 | continue; |
| 3004 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3005 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3006 | ret = true; |
| 3007 | break; |
| 3008 | } |
| 3009 | |
| 3010 | mutex_unlock(&rdev->devlist_mtx); |
| 3011 | |
| 3012 | return ret; |
| 3013 | } |
| 3014 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3015 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3016 | enum nl80211_auth_type auth_type, |
| 3017 | enum nl80211_commands cmd) |
| 3018 | { |
| 3019 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3020 | return false; |
| 3021 | |
| 3022 | switch (cmd) { |
| 3023 | case NL80211_CMD_AUTHENTICATE: |
| 3024 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3025 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3026 | return false; |
| 3027 | return true; |
| 3028 | case NL80211_CMD_CONNECT: |
| 3029 | case NL80211_CMD_START_AP: |
| 3030 | /* SAE not supported yet */ |
| 3031 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3032 | return false; |
| 3033 | return true; |
| 3034 | default: |
| 3035 | return false; |
| 3036 | } |
| 3037 | } |
| 3038 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3039 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3040 | { |
| 3041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3042 | struct net_device *dev = info->user_ptr[1]; |
| 3043 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3044 | struct cfg80211_ap_settings params; |
| 3045 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3046 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3047 | |
| 3048 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3049 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3050 | return -EOPNOTSUPP; |
| 3051 | |
| 3052 | if (!rdev->ops->start_ap) |
| 3053 | return -EOPNOTSUPP; |
| 3054 | |
| 3055 | if (wdev->beacon_interval) |
| 3056 | return -EALREADY; |
| 3057 | |
| 3058 | memset(¶ms, 0, sizeof(params)); |
| 3059 | |
| 3060 | /* these are required for START_AP */ |
| 3061 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3062 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3063 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3064 | return -EINVAL; |
| 3065 | |
| 3066 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 3067 | if (err) |
| 3068 | return err; |
| 3069 | |
| 3070 | params.beacon_interval = |
| 3071 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3072 | params.dtim_period = |
| 3073 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3074 | |
| 3075 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3076 | if (err) |
| 3077 | return err; |
| 3078 | |
| 3079 | /* |
| 3080 | * In theory, some of these attributes should be required here |
| 3081 | * but since they were not used when the command was originally |
| 3082 | * added, keep them optional for old user space programs to let |
| 3083 | * them continue to work with drivers that do not need the |
| 3084 | * additional information -- drivers must check! |
| 3085 | */ |
| 3086 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3087 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3088 | params.ssid_len = |
| 3089 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3090 | if (params.ssid_len == 0 || |
| 3091 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3092 | return -EINVAL; |
| 3093 | } |
| 3094 | |
| 3095 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3096 | params.hidden_ssid = nla_get_u32( |
| 3097 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3098 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3099 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3100 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3101 | return -EINVAL; |
| 3102 | } |
| 3103 | |
| 3104 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3105 | |
| 3106 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3107 | params.auth_type = nla_get_u32( |
| 3108 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3109 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3110 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3111 | return -EINVAL; |
| 3112 | } else |
| 3113 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3114 | |
| 3115 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3116 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3117 | if (err) |
| 3118 | return err; |
| 3119 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3120 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3121 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3122 | return -EOPNOTSUPP; |
| 3123 | params.inactivity_timeout = nla_get_u16( |
| 3124 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3125 | } |
| 3126 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3127 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3128 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3129 | return -EINVAL; |
| 3130 | params.p2p_ctwindow = |
| 3131 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3132 | if (params.p2p_ctwindow > 127) |
| 3133 | return -EINVAL; |
| 3134 | if (params.p2p_ctwindow != 0 && |
| 3135 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3136 | return -EINVAL; |
| 3137 | } |
| 3138 | |
| 3139 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3140 | u8 tmp; |
| 3141 | |
| 3142 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3143 | return -EINVAL; |
| 3144 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3145 | if (tmp > 1) |
| 3146 | return -EINVAL; |
| 3147 | params.p2p_opp_ps = tmp; |
| 3148 | if (params.p2p_opp_ps != 0 && |
| 3149 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3150 | return -EINVAL; |
| 3151 | } |
| 3152 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3153 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3154 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3155 | if (err) |
| 3156 | return err; |
| 3157 | } else if (wdev->preset_chandef.chan) { |
| 3158 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3159 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3160 | return -EINVAL; |
| 3161 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3162 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3163 | return -EINVAL; |
| 3164 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3165 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3166 | if (err < 0) |
| 3167 | return err; |
| 3168 | if (err) { |
| 3169 | radar_detect_width = BIT(params.chandef.width); |
| 3170 | params.radar_required = true; |
| 3171 | } |
| 3172 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3173 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3174 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3175 | params.chandef.chan, |
| 3176 | CHAN_MODE_SHARED, |
| 3177 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3178 | mutex_unlock(&rdev->devlist_mtx); |
| 3179 | |
| 3180 | if (err) |
| 3181 | return err; |
| 3182 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3183 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3184 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3185 | if (IS_ERR(params.acl)) |
| 3186 | return PTR_ERR(params.acl); |
| 3187 | } |
| 3188 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3189 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3190 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3191 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3192 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3193 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3194 | wdev->ssid_len = params.ssid_len; |
| 3195 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3196 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3197 | |
| 3198 | kfree(params.acl); |
| 3199 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3200 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3201 | } |
| 3202 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3203 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3204 | { |
| 3205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3206 | struct net_device *dev = info->user_ptr[1]; |
| 3207 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3208 | struct cfg80211_beacon_data params; |
| 3209 | int err; |
| 3210 | |
| 3211 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3212 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3213 | return -EOPNOTSUPP; |
| 3214 | |
| 3215 | if (!rdev->ops->change_beacon) |
| 3216 | return -EOPNOTSUPP; |
| 3217 | |
| 3218 | if (!wdev->beacon_interval) |
| 3219 | return -EINVAL; |
| 3220 | |
| 3221 | err = nl80211_parse_beacon(info, ¶ms); |
| 3222 | if (err) |
| 3223 | return err; |
| 3224 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3225 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | 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] | 3229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3231 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3232 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3233 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3234 | } |
| 3235 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3236 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3237 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3238 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3239 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3240 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3241 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3242 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3243 | }; |
| 3244 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3245 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3246 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3247 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3248 | { |
| 3249 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3250 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3251 | int flag; |
| 3252 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3253 | /* |
| 3254 | * Try parsing the new attribute first so userspace |
| 3255 | * can specify both for older kernels. |
| 3256 | */ |
| 3257 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3258 | if (nla) { |
| 3259 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3260 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3261 | sta_flags = nla_data(nla); |
| 3262 | params->sta_flags_mask = sta_flags->mask; |
| 3263 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3264 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3265 | if ((params->sta_flags_mask | |
| 3266 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3267 | return -EINVAL; |
| 3268 | return 0; |
| 3269 | } |
| 3270 | |
| 3271 | /* if present, parse the old attribute */ |
| 3272 | |
| 3273 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3274 | if (!nla) |
| 3275 | return 0; |
| 3276 | |
| 3277 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3278 | nla, sta_flags_policy)) |
| 3279 | return -EINVAL; |
| 3280 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3281 | /* |
| 3282 | * Only allow certain flags for interface types so that |
| 3283 | * other attributes are silently ignored. Remember that |
| 3284 | * this is backward compatibility code with old userspace |
| 3285 | * and shouldn't be hit in other cases anyway. |
| 3286 | */ |
| 3287 | switch (iftype) { |
| 3288 | case NL80211_IFTYPE_AP: |
| 3289 | case NL80211_IFTYPE_AP_VLAN: |
| 3290 | case NL80211_IFTYPE_P2P_GO: |
| 3291 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3292 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3293 | BIT(NL80211_STA_FLAG_WME) | |
| 3294 | BIT(NL80211_STA_FLAG_MFP); |
| 3295 | break; |
| 3296 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3297 | case NL80211_IFTYPE_STATION: |
| 3298 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3299 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3300 | break; |
| 3301 | case NL80211_IFTYPE_MESH_POINT: |
| 3302 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3303 | BIT(NL80211_STA_FLAG_MFP) | |
| 3304 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3305 | default: |
| 3306 | return -EINVAL; |
| 3307 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3308 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3309 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3310 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3311 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3312 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3313 | /* no longer support new API additions in old API */ |
| 3314 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3315 | return -EINVAL; |
| 3316 | } |
| 3317 | } |
| 3318 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3319 | return 0; |
| 3320 | } |
| 3321 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3322 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3323 | int attr) |
| 3324 | { |
| 3325 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3326 | u32 bitrate; |
| 3327 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3328 | |
| 3329 | rate = nla_nest_start(msg, attr); |
| 3330 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3331 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3332 | |
| 3333 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3334 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3335 | /* report 16-bit bitrate only if we can */ |
| 3336 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3337 | if (bitrate > 0 && |
| 3338 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3339 | return false; |
| 3340 | if (bitrate_compat > 0 && |
| 3341 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3342 | return false; |
| 3343 | |
| 3344 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3345 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3346 | return false; |
| 3347 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3348 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3349 | return false; |
| 3350 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3351 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3352 | return false; |
| 3353 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3354 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3355 | return false; |
| 3356 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3357 | return false; |
| 3358 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3359 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3360 | return false; |
| 3361 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3362 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3363 | return false; |
| 3364 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3365 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3366 | return false; |
| 3367 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3368 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3369 | return false; |
| 3370 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3371 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3372 | return false; |
| 3373 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3374 | |
| 3375 | nla_nest_end(msg, rate); |
| 3376 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame^] | 3379 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3380 | int id) |
| 3381 | { |
| 3382 | void *attr; |
| 3383 | int i = 0; |
| 3384 | |
| 3385 | if (!mask) |
| 3386 | return true; |
| 3387 | |
| 3388 | attr = nla_nest_start(msg, id); |
| 3389 | if (!attr) |
| 3390 | return false; |
| 3391 | |
| 3392 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3393 | if (!(mask & BIT(i))) |
| 3394 | continue; |
| 3395 | |
| 3396 | if (nla_put_u8(msg, i, signal[i])) |
| 3397 | return false; |
| 3398 | } |
| 3399 | |
| 3400 | nla_nest_end(msg, attr); |
| 3401 | |
| 3402 | return true; |
| 3403 | } |
| 3404 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3405 | 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] | 3406 | int flags, |
| 3407 | struct cfg80211_registered_device *rdev, |
| 3408 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3409 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3410 | { |
| 3411 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3412 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3413 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3414 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3415 | if (!hdr) |
| 3416 | return -1; |
| 3417 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3418 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3419 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3420 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3421 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3422 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3423 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3424 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3425 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3426 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3427 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3428 | sinfo->connected_time)) |
| 3429 | goto nla_put_failure; |
| 3430 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3431 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3432 | sinfo->inactive_time)) |
| 3433 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3434 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3435 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3436 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3437 | (u32)sinfo->rx_bytes)) |
| 3438 | goto nla_put_failure; |
| 3439 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3440 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3441 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3442 | (u32)sinfo->tx_bytes)) |
| 3443 | goto nla_put_failure; |
| 3444 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3445 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3446 | sinfo->rx_bytes)) |
| 3447 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3448 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3449 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3450 | sinfo->tx_bytes)) |
| 3451 | goto nla_put_failure; |
| 3452 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3453 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3454 | goto nla_put_failure; |
| 3455 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3456 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3457 | goto nla_put_failure; |
| 3458 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3459 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3460 | sinfo->plink_state)) |
| 3461 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3462 | switch (rdev->wiphy.signal_type) { |
| 3463 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3464 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3465 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3466 | sinfo->signal)) |
| 3467 | goto nla_put_failure; |
| 3468 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3469 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3470 | sinfo->signal_avg)) |
| 3471 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3472 | break; |
| 3473 | default: |
| 3474 | break; |
| 3475 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame^] | 3476 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3477 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3478 | sinfo->chain_signal, |
| 3479 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3480 | goto nla_put_failure; |
| 3481 | } |
| 3482 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3483 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3484 | sinfo->chain_signal_avg, |
| 3485 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3486 | goto nla_put_failure; |
| 3487 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3488 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3489 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3490 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3491 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3492 | } |
| 3493 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3494 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3495 | NL80211_STA_INFO_RX_BITRATE)) |
| 3496 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3497 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3498 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3499 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3500 | sinfo->rx_packets)) |
| 3501 | goto nla_put_failure; |
| 3502 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3503 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3504 | sinfo->tx_packets)) |
| 3505 | goto nla_put_failure; |
| 3506 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3507 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3508 | sinfo->tx_retries)) |
| 3509 | goto nla_put_failure; |
| 3510 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3511 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3512 | sinfo->tx_failed)) |
| 3513 | goto nla_put_failure; |
| 3514 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3515 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3516 | sinfo->beacon_loss_count)) |
| 3517 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3518 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3519 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3520 | sinfo->local_pm)) |
| 3521 | goto nla_put_failure; |
| 3522 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3523 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3524 | sinfo->peer_pm)) |
| 3525 | goto nla_put_failure; |
| 3526 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3527 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3528 | sinfo->nonpeer_pm)) |
| 3529 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3530 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3531 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3532 | if (!bss_param) |
| 3533 | goto nla_put_failure; |
| 3534 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3535 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3536 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3537 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3538 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3539 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3540 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3541 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3542 | sinfo->bss_param.dtim_period) || |
| 3543 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3544 | sinfo->bss_param.beacon_interval)) |
| 3545 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3546 | |
| 3547 | nla_nest_end(msg, bss_param); |
| 3548 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3549 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3550 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3551 | sizeof(struct nl80211_sta_flag_update), |
| 3552 | &sinfo->sta_flags)) |
| 3553 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3554 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3555 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3556 | sinfo->t_offset)) |
| 3557 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3558 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3559 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3560 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3561 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3562 | sinfo->assoc_req_ies)) |
| 3563 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3564 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3565 | return genlmsg_end(msg, hdr); |
| 3566 | |
| 3567 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3568 | genlmsg_cancel(msg, hdr); |
| 3569 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3570 | } |
| 3571 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3572 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3573 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3574 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3575 | struct station_info sinfo; |
| 3576 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3577 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3578 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3579 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3580 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3581 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3582 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3583 | if (err) |
| 3584 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3585 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3586 | if (!wdev->netdev) { |
| 3587 | err = -EINVAL; |
| 3588 | goto out_err; |
| 3589 | } |
| 3590 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3591 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3592 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3593 | goto out_err; |
| 3594 | } |
| 3595 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3596 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3597 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3598 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3599 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3600 | if (err == -ENOENT) |
| 3601 | break; |
| 3602 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3603 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3604 | |
| 3605 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3606 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3607 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3608 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3609 | &sinfo) < 0) |
| 3610 | goto out; |
| 3611 | |
| 3612 | sta_idx++; |
| 3613 | } |
| 3614 | |
| 3615 | |
| 3616 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3617 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3618 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3619 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3620 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3621 | |
| 3622 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3623 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3624 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3625 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3626 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3628 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3629 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3630 | struct sk_buff *msg; |
| 3631 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3632 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3633 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3634 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3635 | |
| 3636 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3637 | return -EINVAL; |
| 3638 | |
| 3639 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3640 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3641 | if (!rdev->ops->get_station) |
| 3642 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3643 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3644 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3645 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3646 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3647 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3649 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3650 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3651 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3652 | 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] | 3653 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3654 | nlmsg_free(msg); |
| 3655 | return -ENOBUFS; |
| 3656 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3657 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3658 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3659 | } |
| 3660 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3661 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3662 | struct station_parameters *params, |
| 3663 | enum cfg80211_station_type statype) |
| 3664 | { |
| 3665 | if (params->listen_interval != -1) |
| 3666 | return -EINVAL; |
| 3667 | if (params->aid) |
| 3668 | return -EINVAL; |
| 3669 | |
| 3670 | /* When you run into this, adjust the code below for the new flag */ |
| 3671 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3672 | |
| 3673 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3674 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3675 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3676 | /* |
| 3677 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3678 | * code doesn't have the bug of including TDLS in the |
| 3679 | * mask everywhere. |
| 3680 | */ |
| 3681 | if (params->sta_flags_mask & |
| 3682 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3683 | BIT(NL80211_STA_FLAG_MFP) | |
| 3684 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3685 | return -EINVAL; |
| 3686 | break; |
| 3687 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3688 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3689 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3690 | return -EINVAL; |
| 3691 | /* ignore since it can't change */ |
| 3692 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3693 | break; |
| 3694 | default: |
| 3695 | /* disallow mesh-specific things */ |
| 3696 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3697 | return -EINVAL; |
| 3698 | if (params->local_pm) |
| 3699 | return -EINVAL; |
| 3700 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3701 | return -EINVAL; |
| 3702 | } |
| 3703 | |
| 3704 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3705 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3706 | /* TDLS can't be set, ... */ |
| 3707 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3708 | return -EINVAL; |
| 3709 | /* |
| 3710 | * ... but don't bother the driver with it. This works around |
| 3711 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3712 | * TLDS_PEER flag in the mask even for AP mode. |
| 3713 | */ |
| 3714 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3715 | } |
| 3716 | |
| 3717 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3718 | /* reject other things that can't change */ |
| 3719 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3720 | return -EINVAL; |
| 3721 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3722 | return -EINVAL; |
| 3723 | if (params->supported_rates) |
| 3724 | return -EINVAL; |
| 3725 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3726 | return -EINVAL; |
| 3727 | } |
| 3728 | |
| 3729 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3730 | if (params->vlan) |
| 3731 | return -EINVAL; |
| 3732 | } |
| 3733 | |
| 3734 | switch (statype) { |
| 3735 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3736 | /* Use this only for authorizing/unauthorizing a station */ |
| 3737 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3738 | return -EOPNOTSUPP; |
| 3739 | break; |
| 3740 | case CFG80211_STA_AP_CLIENT: |
| 3741 | /* accept only the listed bits */ |
| 3742 | if (params->sta_flags_mask & |
| 3743 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3744 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3745 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3746 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3747 | BIT(NL80211_STA_FLAG_WME) | |
| 3748 | BIT(NL80211_STA_FLAG_MFP))) |
| 3749 | return -EINVAL; |
| 3750 | |
| 3751 | /* but authenticated/associated only if driver handles it */ |
| 3752 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3753 | params->sta_flags_mask & |
| 3754 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3755 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3756 | return -EINVAL; |
| 3757 | break; |
| 3758 | case CFG80211_STA_IBSS: |
| 3759 | case CFG80211_STA_AP_STA: |
| 3760 | /* reject any changes other than AUTHORIZED */ |
| 3761 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3762 | return -EINVAL; |
| 3763 | break; |
| 3764 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3765 | /* reject any changes other than AUTHORIZED or WME */ |
| 3766 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3767 | BIT(NL80211_STA_FLAG_WME))) |
| 3768 | return -EINVAL; |
| 3769 | /* force (at least) rates when authorizing */ |
| 3770 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3771 | !params->supported_rates) |
| 3772 | return -EINVAL; |
| 3773 | break; |
| 3774 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3775 | /* reject any changes */ |
| 3776 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3777 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3778 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3779 | return -EINVAL; |
| 3780 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3781 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3782 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3783 | return -EINVAL; |
| 3784 | break; |
| 3785 | } |
| 3786 | |
| 3787 | return 0; |
| 3788 | } |
| 3789 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3790 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3791 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3792 | * 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] | 3793 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3794 | static struct net_device *get_vlan(struct genl_info *info, |
| 3795 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3796 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3797 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3798 | struct net_device *v; |
| 3799 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3800 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3801 | if (!vlanattr) |
| 3802 | return NULL; |
| 3803 | |
| 3804 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3805 | if (!v) |
| 3806 | return ERR_PTR(-ENODEV); |
| 3807 | |
| 3808 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3809 | ret = -EINVAL; |
| 3810 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3811 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3812 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3813 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3814 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3815 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3816 | ret = -EINVAL; |
| 3817 | goto error; |
| 3818 | } |
| 3819 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3820 | if (!netif_running(v)) { |
| 3821 | ret = -ENETDOWN; |
| 3822 | goto error; |
| 3823 | } |
| 3824 | |
| 3825 | return v; |
| 3826 | error: |
| 3827 | dev_put(v); |
| 3828 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3829 | } |
| 3830 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3831 | static struct nla_policy |
| 3832 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3833 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3834 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3835 | }; |
| 3836 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3837 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3838 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3839 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3840 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3841 | struct nlattr *nla; |
| 3842 | int err; |
| 3843 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3844 | /* parse WME attributes if present */ |
| 3845 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3846 | return 0; |
| 3847 | |
| 3848 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3849 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3850 | nl80211_sta_wme_policy); |
| 3851 | if (err) |
| 3852 | return err; |
| 3853 | |
| 3854 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3855 | params->uapsd_queues = nla_get_u8( |
| 3856 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3857 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3858 | return -EINVAL; |
| 3859 | |
| 3860 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3861 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3862 | |
| 3863 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3864 | return -EINVAL; |
| 3865 | |
| 3866 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3867 | |
| 3868 | return 0; |
| 3869 | } |
| 3870 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3871 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3872 | struct station_parameters *params) |
| 3873 | { |
| 3874 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3875 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3876 | params->ht_capa = |
| 3877 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3878 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3879 | params->vht_capa = |
| 3880 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3881 | |
| 3882 | return nl80211_parse_sta_wme(info, params); |
| 3883 | } |
| 3884 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3885 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3886 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3888 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3889 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3890 | u8 *mac_addr; |
| 3891 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3892 | |
| 3893 | memset(¶ms, 0, sizeof(params)); |
| 3894 | |
| 3895 | params.listen_interval = -1; |
| 3896 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3897 | if (!rdev->ops->change_station) |
| 3898 | return -EOPNOTSUPP; |
| 3899 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3900 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3901 | return -EINVAL; |
| 3902 | |
| 3903 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3904 | return -EINVAL; |
| 3905 | |
| 3906 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3907 | |
| 3908 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3909 | params.supported_rates = |
| 3910 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3911 | params.supported_rates_len = |
| 3912 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3913 | } |
| 3914 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3915 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3916 | params.capability = |
| 3917 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3918 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3919 | } |
| 3920 | |
| 3921 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3922 | params.ext_capab = |
| 3923 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3924 | params.ext_capab_len = |
| 3925 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3926 | } |
| 3927 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3928 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3929 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3930 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3931 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3932 | return -EINVAL; |
| 3933 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3934 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3935 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3936 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3937 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3938 | return -EINVAL; |
| 3939 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3940 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3941 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3942 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3943 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3944 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3945 | return -EINVAL; |
| 3946 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3947 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3948 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3949 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3950 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3951 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3952 | |
| 3953 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3954 | pm > NL80211_MESH_POWER_MAX) |
| 3955 | return -EINVAL; |
| 3956 | |
| 3957 | params.local_pm = pm; |
| 3958 | } |
| 3959 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3960 | /* Include parameters for TDLS peer (will check later) */ |
| 3961 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3962 | if (err) |
| 3963 | return err; |
| 3964 | |
| 3965 | params.vlan = get_vlan(info, rdev); |
| 3966 | if (IS_ERR(params.vlan)) |
| 3967 | return PTR_ERR(params.vlan); |
| 3968 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3969 | switch (dev->ieee80211_ptr->iftype) { |
| 3970 | case NL80211_IFTYPE_AP: |
| 3971 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3972 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3973 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3974 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3975 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3976 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3977 | break; |
| 3978 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3979 | err = -EOPNOTSUPP; |
| 3980 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3981 | } |
| 3982 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3983 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3984 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3985 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3986 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3987 | if (params.vlan) |
| 3988 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3989 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3990 | return err; |
| 3991 | } |
| 3992 | |
| 3993 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3994 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3996 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3997 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3998 | struct station_parameters params; |
| 3999 | u8 *mac_addr = NULL; |
| 4000 | |
| 4001 | memset(¶ms, 0, sizeof(params)); |
| 4002 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4003 | if (!rdev->ops->add_station) |
| 4004 | return -EOPNOTSUPP; |
| 4005 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4006 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4007 | return -EINVAL; |
| 4008 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4009 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4010 | return -EINVAL; |
| 4011 | |
| 4012 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4013 | return -EINVAL; |
| 4014 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4015 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 4016 | return -EINVAL; |
| 4017 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4018 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4019 | params.supported_rates = |
| 4020 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4021 | params.supported_rates_len = |
| 4022 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4023 | params.listen_interval = |
| 4024 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4025 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4026 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 4027 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4028 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4029 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4030 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4031 | params.capability = |
| 4032 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4033 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4034 | } |
| 4035 | |
| 4036 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4037 | params.ext_capab = |
| 4038 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4039 | params.ext_capab_len = |
| 4040 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4041 | } |
| 4042 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4043 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4044 | params.ht_capa = |
| 4045 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4046 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4047 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4048 | params.vht_capa = |
| 4049 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4050 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4051 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4052 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4053 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4054 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4055 | return -EINVAL; |
| 4056 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4057 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4058 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4059 | if (err) |
| 4060 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4061 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4062 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4063 | return -EINVAL; |
| 4064 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4065 | /* When you run into this, adjust the code below for the new flag */ |
| 4066 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4067 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4068 | switch (dev->ieee80211_ptr->iftype) { |
| 4069 | case NL80211_IFTYPE_AP: |
| 4070 | case NL80211_IFTYPE_AP_VLAN: |
| 4071 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4072 | /* ignore WME attributes if iface/sta is not capable */ |
| 4073 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4074 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4075 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4076 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4077 | /* TDLS peers cannot be added */ |
| 4078 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4079 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4080 | /* but don't bother the driver with it */ |
| 4081 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4082 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4083 | /* allow authenticated/associated only if driver handles it */ |
| 4084 | if (!(rdev->wiphy.features & |
| 4085 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4086 | params.sta_flags_mask & |
| 4087 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4088 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4089 | return -EINVAL; |
| 4090 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4091 | /* must be last in here for error handling */ |
| 4092 | params.vlan = get_vlan(info, rdev); |
| 4093 | if (IS_ERR(params.vlan)) |
| 4094 | return PTR_ERR(params.vlan); |
| 4095 | break; |
| 4096 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4097 | /* ignore uAPSD data */ |
| 4098 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4099 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4100 | /* associated is disallowed */ |
| 4101 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4102 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4103 | /* TDLS peers cannot be added */ |
| 4104 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4105 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4106 | break; |
| 4107 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4108 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4109 | /* ignore uAPSD data */ |
| 4110 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4111 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4112 | /* these are disallowed */ |
| 4113 | if (params.sta_flags_mask & |
| 4114 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4115 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4116 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4117 | /* Only TDLS peers can be added */ |
| 4118 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4119 | return -EINVAL; |
| 4120 | /* Can only add if TDLS ... */ |
| 4121 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4122 | return -EOPNOTSUPP; |
| 4123 | /* ... with external setup is supported */ |
| 4124 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4125 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4126 | /* |
| 4127 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4128 | * as authorized, but it shouldn't yet be. |
| 4129 | */ |
| 4130 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4131 | break; |
| 4132 | default: |
| 4133 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4134 | } |
| 4135 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4136 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4137 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4138 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4139 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4140 | if (params.vlan) |
| 4141 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4142 | return err; |
| 4143 | } |
| 4144 | |
| 4145 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4146 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4148 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4149 | u8 *mac_addr = NULL; |
| 4150 | |
| 4151 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4152 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4153 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4154 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4155 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4156 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4157 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4158 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4159 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4160 | if (!rdev->ops->del_station) |
| 4161 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4162 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4163 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4164 | } |
| 4165 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4166 | 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] | 4167 | int flags, struct net_device *dev, |
| 4168 | u8 *dst, u8 *next_hop, |
| 4169 | struct mpath_info *pinfo) |
| 4170 | { |
| 4171 | void *hdr; |
| 4172 | struct nlattr *pinfoattr; |
| 4173 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4174 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4175 | if (!hdr) |
| 4176 | return -1; |
| 4177 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4178 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4180 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4181 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4182 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4183 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4184 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4185 | if (!pinfoattr) |
| 4186 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4187 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4188 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4189 | pinfo->frame_qlen)) |
| 4190 | goto nla_put_failure; |
| 4191 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4192 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4193 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4194 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4195 | pinfo->metric)) || |
| 4196 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4197 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4198 | pinfo->exptime)) || |
| 4199 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4200 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4201 | pinfo->flags)) || |
| 4202 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4203 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4204 | pinfo->discovery_timeout)) || |
| 4205 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4206 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4207 | pinfo->discovery_retries))) |
| 4208 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4209 | |
| 4210 | nla_nest_end(msg, pinfoattr); |
| 4211 | |
| 4212 | return genlmsg_end(msg, hdr); |
| 4213 | |
| 4214 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4215 | genlmsg_cancel(msg, hdr); |
| 4216 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4220 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4221 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4222 | struct mpath_info pinfo; |
| 4223 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4224 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4225 | u8 dst[ETH_ALEN]; |
| 4226 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4227 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4228 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4229 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4230 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4231 | if (err) |
| 4232 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4233 | |
| 4234 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4235 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4236 | goto out_err; |
| 4237 | } |
| 4238 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4239 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4240 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4241 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4242 | } |
| 4243 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4244 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4245 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4246 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4247 | if (err == -ENOENT) |
| 4248 | break; |
| 4249 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4250 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4251 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4252 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4253 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4254 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4255 | &pinfo) < 0) |
| 4256 | goto out; |
| 4257 | |
| 4258 | path_idx++; |
| 4259 | } |
| 4260 | |
| 4261 | |
| 4262 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4263 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4264 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4265 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4266 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4267 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4271 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4273 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4275 | struct mpath_info pinfo; |
| 4276 | struct sk_buff *msg; |
| 4277 | u8 *dst = NULL; |
| 4278 | u8 next_hop[ETH_ALEN]; |
| 4279 | |
| 4280 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4281 | |
| 4282 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4283 | return -EINVAL; |
| 4284 | |
| 4285 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4287 | if (!rdev->ops->get_mpath) |
| 4288 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4289 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4290 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4291 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4292 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4293 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4294 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4295 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4296 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4298 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4300 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4301 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4302 | dev, dst, next_hop, &pinfo) < 0) { |
| 4303 | nlmsg_free(msg); |
| 4304 | return -ENOBUFS; |
| 4305 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4306 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4307 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4311 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4313 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4314 | u8 *dst = NULL; |
| 4315 | u8 *next_hop = NULL; |
| 4316 | |
| 4317 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4318 | return -EINVAL; |
| 4319 | |
| 4320 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4321 | return -EINVAL; |
| 4322 | |
| 4323 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4324 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4326 | if (!rdev->ops->change_mpath) |
| 4327 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4330 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4331 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4332 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4333 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4334 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4335 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4336 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4338 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4339 | u8 *dst = NULL; |
| 4340 | u8 *next_hop = NULL; |
| 4341 | |
| 4342 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4343 | return -EINVAL; |
| 4344 | |
| 4345 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4346 | return -EINVAL; |
| 4347 | |
| 4348 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4349 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4351 | if (!rdev->ops->add_mpath) |
| 4352 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4354 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4355 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4356 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4357 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4363 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4364 | u8 *dst = NULL; |
| 4365 | |
| 4366 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4367 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | if (!rdev->ops->del_mpath) |
| 4370 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4371 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4372 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4373 | } |
| 4374 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4375 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4376 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4378 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4379 | struct bss_parameters params; |
| 4380 | |
| 4381 | memset(¶ms, 0, sizeof(params)); |
| 4382 | /* default to not changing parameters */ |
| 4383 | params.use_cts_prot = -1; |
| 4384 | params.use_short_preamble = -1; |
| 4385 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4386 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4387 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4388 | params.p2p_ctwindow = -1; |
| 4389 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4390 | |
| 4391 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4392 | params.use_cts_prot = |
| 4393 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4394 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4395 | params.use_short_preamble = |
| 4396 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4397 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4398 | params.use_short_slot_time = |
| 4399 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4400 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4401 | params.basic_rates = |
| 4402 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4403 | params.basic_rates_len = |
| 4404 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4405 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4406 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4407 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4408 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4409 | params.ht_opmode = |
| 4410 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4411 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4412 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4413 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4414 | return -EINVAL; |
| 4415 | params.p2p_ctwindow = |
| 4416 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4417 | if (params.p2p_ctwindow < 0) |
| 4418 | return -EINVAL; |
| 4419 | if (params.p2p_ctwindow != 0 && |
| 4420 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4421 | return -EINVAL; |
| 4422 | } |
| 4423 | |
| 4424 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4425 | u8 tmp; |
| 4426 | |
| 4427 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4428 | return -EINVAL; |
| 4429 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4430 | if (tmp > 1) |
| 4431 | return -EINVAL; |
| 4432 | params.p2p_opp_ps = tmp; |
| 4433 | if (params.p2p_opp_ps && |
| 4434 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4435 | return -EINVAL; |
| 4436 | } |
| 4437 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4438 | if (!rdev->ops->change_bss) |
| 4439 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4440 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4441 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4442 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4443 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4444 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4445 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4446 | } |
| 4447 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4448 | 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] | 4449 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4450 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4451 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4452 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4453 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4454 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4455 | }; |
| 4456 | |
| 4457 | static int parse_reg_rule(struct nlattr *tb[], |
| 4458 | struct ieee80211_reg_rule *reg_rule) |
| 4459 | { |
| 4460 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4461 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4462 | |
| 4463 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4464 | return -EINVAL; |
| 4465 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4466 | return -EINVAL; |
| 4467 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4468 | return -EINVAL; |
| 4469 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4470 | return -EINVAL; |
| 4471 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4472 | return -EINVAL; |
| 4473 | |
| 4474 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4475 | |
| 4476 | freq_range->start_freq_khz = |
| 4477 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4478 | freq_range->end_freq_khz = |
| 4479 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4480 | freq_range->max_bandwidth_khz = |
| 4481 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4482 | |
| 4483 | power_rule->max_eirp = |
| 4484 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4485 | |
| 4486 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4487 | power_rule->max_antenna_gain = |
| 4488 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4489 | |
| 4490 | return 0; |
| 4491 | } |
| 4492 | |
| 4493 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4494 | { |
| 4495 | int r; |
| 4496 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4497 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4498 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4499 | /* |
| 4500 | * You should only get this when cfg80211 hasn't yet initialized |
| 4501 | * completely when built-in to the kernel right between the time |
| 4502 | * window between nl80211_init() and regulatory_init(), if that is |
| 4503 | * even possible. |
| 4504 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4505 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4506 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4507 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4508 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4509 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4510 | |
| 4511 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4512 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4513 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4514 | user_reg_hint_type = |
| 4515 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4516 | else |
| 4517 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4518 | |
| 4519 | switch (user_reg_hint_type) { |
| 4520 | case NL80211_USER_REG_HINT_USER: |
| 4521 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4522 | break; |
| 4523 | default: |
| 4524 | return -EINVAL; |
| 4525 | } |
| 4526 | |
| 4527 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4528 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4529 | return r; |
| 4530 | } |
| 4531 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4532 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4533 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4534 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4536 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4537 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4538 | struct mesh_config cur_params; |
| 4539 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4540 | void *hdr; |
| 4541 | struct nlattr *pinfoattr; |
| 4542 | struct sk_buff *msg; |
| 4543 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4544 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4545 | return -EOPNOTSUPP; |
| 4546 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4547 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4548 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4549 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4550 | wdev_lock(wdev); |
| 4551 | /* If not connected, get default parameters */ |
| 4552 | if (!wdev->mesh_id_len) |
| 4553 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4554 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4555 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4556 | wdev_unlock(wdev); |
| 4557 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4558 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4559 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4560 | |
| 4561 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4562 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4563 | if (!msg) |
| 4564 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4565 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4566 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4567 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4568 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4569 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4570 | if (!pinfoattr) |
| 4571 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4572 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4573 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4574 | cur_params.dot11MeshRetryTimeout) || |
| 4575 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4576 | cur_params.dot11MeshConfirmTimeout) || |
| 4577 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4578 | cur_params.dot11MeshHoldingTimeout) || |
| 4579 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4580 | cur_params.dot11MeshMaxPeerLinks) || |
| 4581 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4582 | cur_params.dot11MeshMaxRetries) || |
| 4583 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4584 | cur_params.dot11MeshTTL) || |
| 4585 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4586 | cur_params.element_ttl) || |
| 4587 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4588 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4589 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4590 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4591 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4592 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4593 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4594 | cur_params.path_refresh_time) || |
| 4595 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4596 | cur_params.min_discovery_timeout) || |
| 4597 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4598 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4599 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4600 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4601 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4602 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4603 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4604 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4605 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4606 | cur_params.dot11MeshHWMPRootMode) || |
| 4607 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4608 | cur_params.dot11MeshHWMPRannInterval) || |
| 4609 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4610 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4611 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4612 | cur_params.dot11MeshForwarding) || |
| 4613 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4614 | cur_params.rssi_threshold) || |
| 4615 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4616 | cur_params.ht_opmode) || |
| 4617 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4618 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4619 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4620 | cur_params.dot11MeshHWMProotInterval) || |
| 4621 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4622 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4623 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4624 | cur_params.power_mode) || |
| 4625 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4626 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4627 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4628 | nla_nest_end(msg, pinfoattr); |
| 4629 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4630 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4631 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4632 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4633 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4634 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4635 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4639 | 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] | 4640 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4641 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4642 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4643 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4644 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4645 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4646 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4647 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4648 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4649 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4650 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4651 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4652 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4653 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4654 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4655 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4656 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4657 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4658 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4659 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4660 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4661 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4662 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4663 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4664 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4665 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4666 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4667 | }; |
| 4668 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4669 | static const struct nla_policy |
| 4670 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4671 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4672 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4673 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4674 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4675 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4676 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4677 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4678 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4679 | }; |
| 4680 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4681 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4682 | struct mesh_config *cfg, |
| 4683 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4684 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4685 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4686 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4687 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4688 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4689 | do { \ |
| 4690 | if (tb[attr]) { \ |
| 4691 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4692 | return -EINVAL; \ |
| 4693 | cfg->param = fn(tb[attr]); \ |
| 4694 | mask |= (1 << (attr - 1)); \ |
| 4695 | } \ |
| 4696 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4697 | |
| 4698 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4699 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4700 | return -EINVAL; |
| 4701 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4702 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4703 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4704 | return -EINVAL; |
| 4705 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4706 | /* This makes sure that there aren't more than 32 mesh config |
| 4707 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4708 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4709 | |
| 4710 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4712 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4713 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4714 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4715 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4716 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4718 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4719 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4720 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4721 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4722 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4723 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4724 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4725 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4726 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4727 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4728 | 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] | 4729 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4730 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4731 | 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] | 4732 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4733 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4734 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4735 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4736 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4737 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4738 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4739 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4740 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4741 | 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] | 4742 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4743 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4744 | 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] | 4745 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4746 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4747 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4748 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4749 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4750 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4751 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4752 | 1, 65535, mask, |
| 4753 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4754 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4756 | 1, 65535, mask, |
| 4757 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4758 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4759 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4760 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4761 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4762 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4763 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4764 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4765 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4766 | nla_get_u8); |
| 4767 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4768 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4769 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4770 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4771 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4772 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4773 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4774 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4775 | mask, NL80211_MESHCONF_FORWARDING, |
| 4776 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4777 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4778 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4779 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4780 | 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] | 4781 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4782 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4783 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4784 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4785 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4786 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4787 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4788 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4789 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4790 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4791 | dot11MeshHWMPconfirmationInterval, |
| 4792 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4793 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4794 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4796 | NL80211_MESH_POWER_ACTIVE, |
| 4797 | NL80211_MESH_POWER_MAX, |
| 4798 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4799 | nla_get_u32); |
| 4800 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4801 | 0, 65535, mask, |
| 4802 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4803 | if (mask_out) |
| 4804 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4805 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4806 | return 0; |
| 4807 | |
| 4808 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4809 | } |
| 4810 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4811 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4812 | struct mesh_setup *setup) |
| 4813 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4815 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4816 | |
| 4817 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4818 | return -EINVAL; |
| 4819 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4820 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4821 | nl80211_mesh_setup_params_policy)) |
| 4822 | return -EINVAL; |
| 4823 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4824 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4825 | setup->sync_method = |
| 4826 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4827 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4828 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4829 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4830 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4831 | setup->path_sel_proto = |
| 4832 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4833 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4834 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4835 | |
| 4836 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4837 | setup->path_metric = |
| 4838 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4839 | IEEE80211_PATH_METRIC_VENDOR : |
| 4840 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4841 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4842 | |
| 4843 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4844 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4845 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4846 | if (!is_valid_ie_attr(ieattr)) |
| 4847 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4848 | setup->ie = nla_data(ieattr); |
| 4849 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4850 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4851 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4852 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4853 | return -EINVAL; |
| 4854 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4855 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4856 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4857 | if (setup->is_secure) |
| 4858 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4859 | |
| 4860 | return 0; |
| 4861 | } |
| 4862 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4863 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4864 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4865 | { |
| 4866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4867 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4868 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4869 | struct mesh_config cfg; |
| 4870 | u32 mask; |
| 4871 | int err; |
| 4872 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4873 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4874 | return -EOPNOTSUPP; |
| 4875 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4876 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4877 | return -EOPNOTSUPP; |
| 4878 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4879 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4880 | if (err) |
| 4881 | return err; |
| 4882 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4883 | wdev_lock(wdev); |
| 4884 | if (!wdev->mesh_id_len) |
| 4885 | err = -ENOLINK; |
| 4886 | |
| 4887 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4888 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4889 | |
| 4890 | wdev_unlock(wdev); |
| 4891 | |
| 4892 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4893 | } |
| 4894 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4895 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4896 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4897 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4898 | struct sk_buff *msg; |
| 4899 | void *hdr = NULL; |
| 4900 | struct nlattr *nl_reg_rules; |
| 4901 | unsigned int i; |
| 4902 | int err = -EINVAL; |
| 4903 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4904 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4905 | |
| 4906 | if (!cfg80211_regdomain) |
| 4907 | goto out; |
| 4908 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4909 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4910 | if (!msg) { |
| 4911 | err = -ENOBUFS; |
| 4912 | goto out; |
| 4913 | } |
| 4914 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4915 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4916 | NL80211_CMD_GET_REG); |
| 4917 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4918 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4919 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4920 | if (reg_last_request_cell_base() && |
| 4921 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4922 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4923 | goto nla_put_failure; |
| 4924 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4925 | rcu_read_lock(); |
| 4926 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4927 | |
| 4928 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4929 | (regdom->dfs_region && |
| 4930 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4931 | goto nla_put_failure_rcu; |
| 4932 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4933 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4934 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4935 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4936 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4937 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4938 | struct nlattr *nl_reg_rule; |
| 4939 | const struct ieee80211_reg_rule *reg_rule; |
| 4940 | const struct ieee80211_freq_range *freq_range; |
| 4941 | const struct ieee80211_power_rule *power_rule; |
| 4942 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4943 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4944 | freq_range = ®_rule->freq_range; |
| 4945 | power_rule = ®_rule->power_rule; |
| 4946 | |
| 4947 | nl_reg_rule = nla_nest_start(msg, i); |
| 4948 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4949 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4951 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4952 | reg_rule->flags) || |
| 4953 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4954 | freq_range->start_freq_khz) || |
| 4955 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4956 | freq_range->end_freq_khz) || |
| 4957 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4958 | freq_range->max_bandwidth_khz) || |
| 4959 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4960 | power_rule->max_antenna_gain) || |
| 4961 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4962 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4963 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4964 | |
| 4965 | nla_nest_end(msg, nl_reg_rule); |
| 4966 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4967 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4968 | |
| 4969 | nla_nest_end(msg, nl_reg_rules); |
| 4970 | |
| 4971 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4972 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4973 | goto out; |
| 4974 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4975 | nla_put_failure_rcu: |
| 4976 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4977 | nla_put_failure: |
| 4978 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4979 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4980 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4981 | err = -EMSGSIZE; |
| 4982 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4983 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4984 | return err; |
| 4985 | } |
| 4986 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4987 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4988 | { |
| 4989 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4990 | struct nlattr *nl_reg_rule; |
| 4991 | char *alpha2 = NULL; |
| 4992 | int rem_reg_rules = 0, r = 0; |
| 4993 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4994 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4995 | struct ieee80211_regdomain *rd = NULL; |
| 4996 | |
| 4997 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4998 | return -EINVAL; |
| 4999 | |
| 5000 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5001 | return -EINVAL; |
| 5002 | |
| 5003 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5004 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5005 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5006 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5007 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5008 | 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] | 5009 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5010 | num_rules++; |
| 5011 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5012 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5013 | } |
| 5014 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5015 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5016 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5017 | |
| 5018 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5019 | if (!rd) |
| 5020 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5021 | |
| 5022 | rd->n_reg_rules = num_rules; |
| 5023 | rd->alpha2[0] = alpha2[0]; |
| 5024 | rd->alpha2[1] = alpha2[1]; |
| 5025 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5026 | /* |
| 5027 | * Disable DFS master mode if the DFS region was |
| 5028 | * not supported or known on this kernel. |
| 5029 | */ |
| 5030 | if (reg_supported_dfs_region(dfs_region)) |
| 5031 | rd->dfs_region = dfs_region; |
| 5032 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5033 | 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] | 5034 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5035 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5036 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5037 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5038 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5039 | if (r) |
| 5040 | goto bad_reg; |
| 5041 | |
| 5042 | rule_idx++; |
| 5043 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5044 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5045 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5046 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5047 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5050 | mutex_lock(&cfg80211_mutex); |
| 5051 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5052 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5053 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5054 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5055 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5056 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5057 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5058 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5059 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5062 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5063 | { |
| 5064 | struct nlattr *attr1, *attr2; |
| 5065 | int n_channels = 0, tmp1, tmp2; |
| 5066 | |
| 5067 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5068 | n_channels++; |
| 5069 | /* |
| 5070 | * Some hardware has a limited channel list for |
| 5071 | * scanning, and it is pretty much nonsensical |
| 5072 | * to scan for a channel twice, so disallow that |
| 5073 | * and don't require drivers to check that the |
| 5074 | * channel list they get isn't longer than what |
| 5075 | * they can scan, as long as they can scan all |
| 5076 | * the channels they registered at once. |
| 5077 | */ |
| 5078 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5079 | if (attr1 != attr2 && |
| 5080 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5081 | return 0; |
| 5082 | } |
| 5083 | |
| 5084 | return n_channels; |
| 5085 | } |
| 5086 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5087 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5088 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5090 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5091 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5092 | struct nlattr *attr; |
| 5093 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5094 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5095 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5096 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5097 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5098 | return -EINVAL; |
| 5099 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5100 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5101 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5102 | if (!rdev->ops->scan) |
| 5103 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5104 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5105 | mutex_lock(&rdev->sched_scan_mtx); |
| 5106 | if (rdev->scan_req) { |
| 5107 | err = -EBUSY; |
| 5108 | goto unlock; |
| 5109 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5110 | |
| 5111 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5112 | n_channels = validate_scan_freqs( |
| 5113 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5114 | if (!n_channels) { |
| 5115 | err = -EINVAL; |
| 5116 | goto unlock; |
| 5117 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5118 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5119 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5120 | n_channels = 0; |
| 5121 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5122 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5123 | if (wiphy->bands[band]) |
| 5124 | n_channels += wiphy->bands[band]->n_channels; |
| 5125 | } |
| 5126 | |
| 5127 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5128 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5129 | n_ssids++; |
| 5130 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5131 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5132 | err = -EINVAL; |
| 5133 | goto unlock; |
| 5134 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5135 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5136 | if (info->attrs[NL80211_ATTR_IE]) |
| 5137 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5138 | else |
| 5139 | ie_len = 0; |
| 5140 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5141 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5142 | err = -EINVAL; |
| 5143 | goto unlock; |
| 5144 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5145 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5146 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5147 | + sizeof(*request->ssids) * n_ssids |
| 5148 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5149 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5150 | if (!request) { |
| 5151 | err = -ENOMEM; |
| 5152 | goto unlock; |
| 5153 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5154 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5155 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5156 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5157 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5158 | if (ie_len) { |
| 5159 | if (request->ssids) |
| 5160 | request->ie = (void *)(request->ssids + n_ssids); |
| 5161 | else |
| 5162 | request->ie = (void *)(request->channels + n_channels); |
| 5163 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5164 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5165 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5166 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5167 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5168 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5169 | struct ieee80211_channel *chan; |
| 5170 | |
| 5171 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5172 | |
| 5173 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5174 | err = -EINVAL; |
| 5175 | goto out_free; |
| 5176 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5177 | |
| 5178 | /* ignore disabled channels */ |
| 5179 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5180 | continue; |
| 5181 | |
| 5182 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5183 | i++; |
| 5184 | } |
| 5185 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5186 | enum ieee80211_band band; |
| 5187 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5188 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5189 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5190 | int j; |
| 5191 | if (!wiphy->bands[band]) |
| 5192 | continue; |
| 5193 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5194 | struct ieee80211_channel *chan; |
| 5195 | |
| 5196 | chan = &wiphy->bands[band]->channels[j]; |
| 5197 | |
| 5198 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5199 | continue; |
| 5200 | |
| 5201 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5202 | i++; |
| 5203 | } |
| 5204 | } |
| 5205 | } |
| 5206 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5207 | if (!i) { |
| 5208 | err = -EINVAL; |
| 5209 | goto out_free; |
| 5210 | } |
| 5211 | |
| 5212 | request->n_channels = i; |
| 5213 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5214 | i = 0; |
| 5215 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5216 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5217 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5218 | err = -EINVAL; |
| 5219 | goto out_free; |
| 5220 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5221 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5222 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5223 | i++; |
| 5224 | } |
| 5225 | } |
| 5226 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5227 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5228 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5229 | memcpy((void *)request->ie, |
| 5230 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5231 | request->ie_len); |
| 5232 | } |
| 5233 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5234 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5235 | if (wiphy->bands[i]) |
| 5236 | request->rates[i] = |
| 5237 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5238 | |
| 5239 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5240 | nla_for_each_nested(attr, |
| 5241 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5242 | tmp) { |
| 5243 | enum ieee80211_band band = nla_type(attr); |
| 5244 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5245 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5246 | err = -EINVAL; |
| 5247 | goto out_free; |
| 5248 | } |
| 5249 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5250 | nla_data(attr), |
| 5251 | nla_len(attr), |
| 5252 | &request->rates[band]); |
| 5253 | if (err) |
| 5254 | goto out_free; |
| 5255 | } |
| 5256 | } |
| 5257 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5258 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5259 | request->flags = nla_get_u32( |
| 5260 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5261 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5262 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5263 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5264 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5265 | err = -EOPNOTSUPP; |
| 5266 | goto out_free; |
| 5267 | } |
| 5268 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5269 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5270 | request->no_cck = |
| 5271 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5272 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5273 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5274 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5275 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5276 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5277 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5278 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5279 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5280 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5281 | nl80211_send_scan_start(rdev, wdev); |
| 5282 | if (wdev->netdev) |
| 5283 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5284 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5285 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5286 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5287 | kfree(request); |
| 5288 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5289 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5290 | unlock: |
| 5291 | mutex_unlock(&rdev->sched_scan_mtx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5292 | return err; |
| 5293 | } |
| 5294 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5295 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5296 | struct genl_info *info) |
| 5297 | { |
| 5298 | struct cfg80211_sched_scan_request *request; |
| 5299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5300 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5301 | struct nlattr *attr; |
| 5302 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5303 | 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] | 5304 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5305 | enum ieee80211_band band; |
| 5306 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5307 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5308 | |
| 5309 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5310 | !rdev->ops->sched_scan_start) |
| 5311 | return -EOPNOTSUPP; |
| 5312 | |
| 5313 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5314 | return -EINVAL; |
| 5315 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5316 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5317 | return -EINVAL; |
| 5318 | |
| 5319 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5320 | if (interval == 0) |
| 5321 | return -EINVAL; |
| 5322 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5323 | wiphy = &rdev->wiphy; |
| 5324 | |
| 5325 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5326 | n_channels = validate_scan_freqs( |
| 5327 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5328 | if (!n_channels) |
| 5329 | return -EINVAL; |
| 5330 | } else { |
| 5331 | n_channels = 0; |
| 5332 | |
| 5333 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5334 | if (wiphy->bands[band]) |
| 5335 | n_channels += wiphy->bands[band]->n_channels; |
| 5336 | } |
| 5337 | |
| 5338 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5339 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5340 | tmp) |
| 5341 | n_ssids++; |
| 5342 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5343 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5344 | return -EINVAL; |
| 5345 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5346 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5347 | nla_for_each_nested(attr, |
| 5348 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5349 | tmp) |
| 5350 | n_match_sets++; |
| 5351 | |
| 5352 | if (n_match_sets > wiphy->max_match_sets) |
| 5353 | return -EINVAL; |
| 5354 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5355 | if (info->attrs[NL80211_ATTR_IE]) |
| 5356 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5357 | else |
| 5358 | ie_len = 0; |
| 5359 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5360 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5361 | return -EINVAL; |
| 5362 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5363 | mutex_lock(&rdev->sched_scan_mtx); |
| 5364 | |
| 5365 | if (rdev->sched_scan_req) { |
| 5366 | err = -EINPROGRESS; |
| 5367 | goto out; |
| 5368 | } |
| 5369 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5370 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5371 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5372 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5373 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5374 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5375 | if (!request) { |
| 5376 | err = -ENOMEM; |
| 5377 | goto out; |
| 5378 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5379 | |
| 5380 | if (n_ssids) |
| 5381 | request->ssids = (void *)&request->channels[n_channels]; |
| 5382 | request->n_ssids = n_ssids; |
| 5383 | if (ie_len) { |
| 5384 | if (request->ssids) |
| 5385 | request->ie = (void *)(request->ssids + n_ssids); |
| 5386 | else |
| 5387 | request->ie = (void *)(request->channels + n_channels); |
| 5388 | } |
| 5389 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5390 | if (n_match_sets) { |
| 5391 | if (request->ie) |
| 5392 | request->match_sets = (void *)(request->ie + ie_len); |
| 5393 | else if (request->ssids) |
| 5394 | request->match_sets = |
| 5395 | (void *)(request->ssids + n_ssids); |
| 5396 | else |
| 5397 | request->match_sets = |
| 5398 | (void *)(request->channels + n_channels); |
| 5399 | } |
| 5400 | request->n_match_sets = n_match_sets; |
| 5401 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5402 | i = 0; |
| 5403 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5404 | /* user specified, bail out if channel not found */ |
| 5405 | nla_for_each_nested(attr, |
| 5406 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5407 | tmp) { |
| 5408 | struct ieee80211_channel *chan; |
| 5409 | |
| 5410 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5411 | |
| 5412 | if (!chan) { |
| 5413 | err = -EINVAL; |
| 5414 | goto out_free; |
| 5415 | } |
| 5416 | |
| 5417 | /* ignore disabled channels */ |
| 5418 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5419 | continue; |
| 5420 | |
| 5421 | request->channels[i] = chan; |
| 5422 | i++; |
| 5423 | } |
| 5424 | } else { |
| 5425 | /* all channels */ |
| 5426 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5427 | int j; |
| 5428 | if (!wiphy->bands[band]) |
| 5429 | continue; |
| 5430 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5431 | struct ieee80211_channel *chan; |
| 5432 | |
| 5433 | chan = &wiphy->bands[band]->channels[j]; |
| 5434 | |
| 5435 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5436 | continue; |
| 5437 | |
| 5438 | request->channels[i] = chan; |
| 5439 | i++; |
| 5440 | } |
| 5441 | } |
| 5442 | } |
| 5443 | |
| 5444 | if (!i) { |
| 5445 | err = -EINVAL; |
| 5446 | goto out_free; |
| 5447 | } |
| 5448 | |
| 5449 | request->n_channels = i; |
| 5450 | |
| 5451 | i = 0; |
| 5452 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5453 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5454 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5455 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5456 | err = -EINVAL; |
| 5457 | goto out_free; |
| 5458 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5459 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5460 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5461 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5462 | i++; |
| 5463 | } |
| 5464 | } |
| 5465 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5466 | i = 0; |
| 5467 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5468 | nla_for_each_nested(attr, |
| 5469 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5470 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5471 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5472 | |
| 5473 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5474 | nla_data(attr), nla_len(attr), |
| 5475 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5476 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5477 | if (ssid) { |
| 5478 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5479 | err = -EINVAL; |
| 5480 | goto out_free; |
| 5481 | } |
| 5482 | memcpy(request->match_sets[i].ssid.ssid, |
| 5483 | nla_data(ssid), nla_len(ssid)); |
| 5484 | request->match_sets[i].ssid.ssid_len = |
| 5485 | nla_len(ssid); |
| 5486 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5487 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5488 | if (rssi) |
| 5489 | request->rssi_thold = nla_get_u32(rssi); |
| 5490 | else |
| 5491 | request->rssi_thold = |
| 5492 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5493 | i++; |
| 5494 | } |
| 5495 | } |
| 5496 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5497 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5498 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5499 | memcpy((void *)request->ie, |
| 5500 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5501 | request->ie_len); |
| 5502 | } |
| 5503 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5504 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5505 | request->flags = nla_get_u32( |
| 5506 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5507 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5508 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5509 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5510 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5511 | err = -EOPNOTSUPP; |
| 5512 | goto out_free; |
| 5513 | } |
| 5514 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5515 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5516 | request->dev = dev; |
| 5517 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5518 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5519 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5520 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5521 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5522 | if (!err) { |
| 5523 | rdev->sched_scan_req = request; |
| 5524 | nl80211_send_sched_scan(rdev, dev, |
| 5525 | NL80211_CMD_START_SCHED_SCAN); |
| 5526 | goto out; |
| 5527 | } |
| 5528 | |
| 5529 | out_free: |
| 5530 | kfree(request); |
| 5531 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5532 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5533 | return err; |
| 5534 | } |
| 5535 | |
| 5536 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5537 | struct genl_info *info) |
| 5538 | { |
| 5539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5540 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5541 | |
| 5542 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5543 | !rdev->ops->sched_scan_stop) |
| 5544 | return -EOPNOTSUPP; |
| 5545 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5546 | mutex_lock(&rdev->sched_scan_mtx); |
| 5547 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5548 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5549 | |
| 5550 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5551 | } |
| 5552 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5553 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5554 | struct genl_info *info) |
| 5555 | { |
| 5556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5557 | struct net_device *dev = info->user_ptr[1]; |
| 5558 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5559 | struct cfg80211_chan_def chandef; |
| 5560 | int err; |
| 5561 | |
| 5562 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5563 | if (err) |
| 5564 | return err; |
| 5565 | |
| 5566 | if (wdev->cac_started) |
| 5567 | return -EBUSY; |
| 5568 | |
| 5569 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5570 | if (err < 0) |
| 5571 | return err; |
| 5572 | |
| 5573 | if (err == 0) |
| 5574 | return -EINVAL; |
| 5575 | |
| 5576 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5577 | return -EINVAL; |
| 5578 | |
| 5579 | if (!rdev->ops->start_radar_detection) |
| 5580 | return -EOPNOTSUPP; |
| 5581 | |
| 5582 | mutex_lock(&rdev->devlist_mtx); |
| 5583 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5584 | chandef.chan, CHAN_MODE_SHARED, |
| 5585 | BIT(chandef.width)); |
| 5586 | if (err) |
| 5587 | goto err_locked; |
| 5588 | |
| 5589 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5590 | if (!err) { |
| 5591 | wdev->channel = chandef.chan; |
| 5592 | wdev->cac_started = true; |
| 5593 | wdev->cac_start_time = jiffies; |
| 5594 | } |
| 5595 | err_locked: |
| 5596 | mutex_unlock(&rdev->devlist_mtx); |
| 5597 | |
| 5598 | return err; |
| 5599 | } |
| 5600 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5601 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5602 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5603 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5604 | struct wireless_dev *wdev, |
| 5605 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5606 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5607 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5608 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5609 | void *hdr; |
| 5610 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5611 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5612 | |
| 5613 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5614 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5615 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5616 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5617 | if (!hdr) |
| 5618 | return -1; |
| 5619 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5620 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5621 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5622 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5623 | goto nla_put_failure; |
| 5624 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5625 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5626 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5627 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5628 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5629 | |
| 5630 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5631 | if (!bss) |
| 5632 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5633 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5634 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5635 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5636 | |
| 5637 | rcu_read_lock(); |
| 5638 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5639 | if (ies) { |
| 5640 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5641 | goto fail_unlock_rcu; |
| 5642 | tsf = true; |
| 5643 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5644 | ies->len, ies->data)) |
| 5645 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5646 | } |
| 5647 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5648 | if (ies) { |
| 5649 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5650 | goto fail_unlock_rcu; |
| 5651 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5652 | ies->len, ies->data)) |
| 5653 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5654 | } |
| 5655 | rcu_read_unlock(); |
| 5656 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5657 | if (res->beacon_interval && |
| 5658 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5659 | goto nla_put_failure; |
| 5660 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5661 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5662 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5663 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5664 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5665 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5666 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5667 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5668 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5669 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5670 | break; |
| 5671 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5672 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5673 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5674 | break; |
| 5675 | default: |
| 5676 | break; |
| 5677 | } |
| 5678 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5679 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5680 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5681 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5682 | if (intbss == wdev->current_bss && |
| 5683 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5684 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5685 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5686 | break; |
| 5687 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5688 | if (intbss == wdev->current_bss && |
| 5689 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5690 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5691 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5692 | break; |
| 5693 | default: |
| 5694 | break; |
| 5695 | } |
| 5696 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5697 | nla_nest_end(msg, bss); |
| 5698 | |
| 5699 | return genlmsg_end(msg, hdr); |
| 5700 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5701 | fail_unlock_rcu: |
| 5702 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5703 | nla_put_failure: |
| 5704 | genlmsg_cancel(msg, hdr); |
| 5705 | return -EMSGSIZE; |
| 5706 | } |
| 5707 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5708 | 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] | 5709 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5710 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5711 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5712 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5713 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5714 | int err; |
| 5715 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5716 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5717 | if (err) |
| 5718 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5719 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5720 | wdev_lock(wdev); |
| 5721 | spin_lock_bh(&rdev->bss_lock); |
| 5722 | cfg80211_bss_expire(rdev); |
| 5723 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5724 | cb->seq = rdev->bss_generation; |
| 5725 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5726 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5727 | if (++idx <= start) |
| 5728 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5729 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5730 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5731 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5732 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5733 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5734 | } |
| 5735 | } |
| 5736 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5737 | spin_unlock_bh(&rdev->bss_lock); |
| 5738 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5739 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5740 | cb->args[2] = idx; |
| 5741 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5742 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5743 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5744 | } |
| 5745 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5746 | 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] | 5747 | int flags, struct net_device *dev, |
| 5748 | struct survey_info *survey) |
| 5749 | { |
| 5750 | void *hdr; |
| 5751 | struct nlattr *infoattr; |
| 5752 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5753 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5754 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5755 | if (!hdr) |
| 5756 | return -ENOMEM; |
| 5757 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5758 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5759 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5760 | |
| 5761 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5762 | if (!infoattr) |
| 5763 | goto nla_put_failure; |
| 5764 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5765 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5766 | survey->channel->center_freq)) |
| 5767 | goto nla_put_failure; |
| 5768 | |
| 5769 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5770 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5771 | goto nla_put_failure; |
| 5772 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5773 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5774 | goto nla_put_failure; |
| 5775 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5776 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5777 | survey->channel_time)) |
| 5778 | goto nla_put_failure; |
| 5779 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5780 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5781 | survey->channel_time_busy)) |
| 5782 | goto nla_put_failure; |
| 5783 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5784 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5785 | survey->channel_time_ext_busy)) |
| 5786 | goto nla_put_failure; |
| 5787 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5788 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5789 | survey->channel_time_rx)) |
| 5790 | goto nla_put_failure; |
| 5791 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5792 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5793 | survey->channel_time_tx)) |
| 5794 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5795 | |
| 5796 | nla_nest_end(msg, infoattr); |
| 5797 | |
| 5798 | return genlmsg_end(msg, hdr); |
| 5799 | |
| 5800 | nla_put_failure: |
| 5801 | genlmsg_cancel(msg, hdr); |
| 5802 | return -EMSGSIZE; |
| 5803 | } |
| 5804 | |
| 5805 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5806 | struct netlink_callback *cb) |
| 5807 | { |
| 5808 | struct survey_info survey; |
| 5809 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5810 | struct wireless_dev *wdev; |
| 5811 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5812 | int res; |
| 5813 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5814 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5815 | if (res) |
| 5816 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5817 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5818 | if (!wdev->netdev) { |
| 5819 | res = -EINVAL; |
| 5820 | goto out_err; |
| 5821 | } |
| 5822 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5823 | if (!dev->ops->dump_survey) { |
| 5824 | res = -EOPNOTSUPP; |
| 5825 | goto out_err; |
| 5826 | } |
| 5827 | |
| 5828 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5829 | struct ieee80211_channel *chan; |
| 5830 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5831 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5832 | if (res == -ENOENT) |
| 5833 | break; |
| 5834 | if (res) |
| 5835 | goto out_err; |
| 5836 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5837 | /* Survey without a channel doesn't make sense */ |
| 5838 | if (!survey.channel) { |
| 5839 | res = -EINVAL; |
| 5840 | goto out; |
| 5841 | } |
| 5842 | |
| 5843 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5844 | survey.channel->center_freq); |
| 5845 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5846 | survey_idx++; |
| 5847 | continue; |
| 5848 | } |
| 5849 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5850 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5851 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5852 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5853 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5854 | goto out; |
| 5855 | survey_idx++; |
| 5856 | } |
| 5857 | |
| 5858 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5859 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5860 | res = skb->len; |
| 5861 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5862 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5863 | return res; |
| 5864 | } |
| 5865 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5866 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5867 | { |
| 5868 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5869 | NL80211_WPA_VERSION_2)); |
| 5870 | } |
| 5871 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5872 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5873 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5875 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5876 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5877 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5878 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5879 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5880 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5881 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5882 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5883 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5884 | return -EINVAL; |
| 5885 | |
| 5886 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5887 | return -EINVAL; |
| 5888 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5889 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5890 | return -EINVAL; |
| 5891 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5892 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5893 | return -EINVAL; |
| 5894 | |
| 5895 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5896 | return -EINVAL; |
| 5897 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5898 | err = nl80211_parse_key(info, &key); |
| 5899 | if (err) |
| 5900 | return err; |
| 5901 | |
| 5902 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5903 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5904 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5905 | if (!key.p.key || !key.p.key_len) |
| 5906 | return -EINVAL; |
| 5907 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5908 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5909 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5910 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5911 | return -EINVAL; |
| 5912 | if (key.idx > 4) |
| 5913 | return -EINVAL; |
| 5914 | } else { |
| 5915 | key.p.key_len = 0; |
| 5916 | key.p.key = NULL; |
| 5917 | } |
| 5918 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5919 | if (key.idx >= 0) { |
| 5920 | int i; |
| 5921 | bool ok = false; |
| 5922 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5923 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5924 | ok = true; |
| 5925 | break; |
| 5926 | } |
| 5927 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5928 | if (!ok) |
| 5929 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5930 | } |
| 5931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5932 | if (!rdev->ops->auth) |
| 5933 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5934 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5935 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5936 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5937 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5938 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5939 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5940 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5941 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5942 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5943 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5944 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5945 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5946 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5947 | |
| 5948 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5949 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5950 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5951 | } |
| 5952 | |
| 5953 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5954 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5955 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5956 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5957 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5958 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5959 | return -EINVAL; |
| 5960 | |
| 5961 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5962 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5963 | return -EINVAL; |
| 5964 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5965 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5966 | /* need to include at least Auth Transaction and Status Code */ |
| 5967 | if (sae_data_len < 4) |
| 5968 | return -EINVAL; |
| 5969 | } |
| 5970 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5971 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5972 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5973 | /* |
| 5974 | * Since we no longer track auth state, ignore |
| 5975 | * requests to only change local state. |
| 5976 | */ |
| 5977 | if (local_state_change) |
| 5978 | return 0; |
| 5979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5980 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5981 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5982 | key.p.key, key.p.key_len, key.idx, |
| 5983 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5984 | } |
| 5985 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5986 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5987 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5988 | struct cfg80211_crypto_settings *settings, |
| 5989 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5990 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5991 | memset(settings, 0, sizeof(*settings)); |
| 5992 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5993 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5994 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5995 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5996 | u16 proto; |
| 5997 | proto = nla_get_u16( |
| 5998 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5999 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6000 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6001 | proto != ETH_P_PAE) |
| 6002 | return -EINVAL; |
| 6003 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6004 | settings->control_port_no_encrypt = true; |
| 6005 | } else |
| 6006 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6007 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6008 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6009 | void *data; |
| 6010 | int len, i; |
| 6011 | |
| 6012 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6013 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6014 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6015 | |
| 6016 | if (len % sizeof(u32)) |
| 6017 | return -EINVAL; |
| 6018 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6019 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6020 | return -EINVAL; |
| 6021 | |
| 6022 | memcpy(settings->ciphers_pairwise, data, len); |
| 6023 | |
| 6024 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6025 | if (!cfg80211_supported_cipher_suite( |
| 6026 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6027 | settings->ciphers_pairwise[i])) |
| 6028 | return -EINVAL; |
| 6029 | } |
| 6030 | |
| 6031 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6032 | settings->cipher_group = |
| 6033 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6034 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6035 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6036 | return -EINVAL; |
| 6037 | } |
| 6038 | |
| 6039 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6040 | settings->wpa_versions = |
| 6041 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6042 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6043 | return -EINVAL; |
| 6044 | } |
| 6045 | |
| 6046 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6047 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6048 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6049 | |
| 6050 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6051 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6052 | settings->n_akm_suites = len / sizeof(u32); |
| 6053 | |
| 6054 | if (len % sizeof(u32)) |
| 6055 | return -EINVAL; |
| 6056 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6057 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6058 | return -EINVAL; |
| 6059 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6060 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | return 0; |
| 6064 | } |
| 6065 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6066 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6067 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6069 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6070 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6071 | struct cfg80211_assoc_request req = {}; |
| 6072 | const u8 *bssid, *ssid; |
| 6073 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6074 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6075 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6076 | return -EINVAL; |
| 6077 | |
| 6078 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6079 | !info->attrs[NL80211_ATTR_SSID] || |
| 6080 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6081 | return -EINVAL; |
| 6082 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6083 | if (!rdev->ops->assoc) |
| 6084 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6085 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6086 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6087 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6088 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6089 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6090 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6091 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6092 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6093 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6094 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6095 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6096 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6097 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6098 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6099 | |
| 6100 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6101 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6102 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6103 | } |
| 6104 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6105 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6106 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6107 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6108 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6109 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6110 | else if (mfp != NL80211_MFP_NO) |
| 6111 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6112 | } |
| 6113 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6114 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6115 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6116 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6117 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6118 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6119 | |
| 6120 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6121 | memcpy(&req.ht_capa_mask, |
| 6122 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6123 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6124 | |
| 6125 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6126 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6127 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6128 | memcpy(&req.ht_capa, |
| 6129 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6130 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6131 | } |
| 6132 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6133 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6134 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6135 | |
| 6136 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6137 | memcpy(&req.vht_capa_mask, |
| 6138 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6139 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6140 | |
| 6141 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6142 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6143 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6144 | memcpy(&req.vht_capa, |
| 6145 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6146 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6147 | } |
| 6148 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6149 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6150 | if (!err) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6151 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6152 | ssid, ssid_len, &req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6153 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6154 | return err; |
| 6155 | } |
| 6156 | |
| 6157 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6158 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6160 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6161 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6162 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6163 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6164 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6165 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6166 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6167 | return -EINVAL; |
| 6168 | |
| 6169 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6170 | return -EINVAL; |
| 6171 | |
| 6172 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6173 | return -EINVAL; |
| 6174 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6175 | if (!rdev->ops->deauth) |
| 6176 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6177 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6178 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6179 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6180 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6181 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6182 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6183 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6184 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6185 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6186 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6187 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6188 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6189 | |
| 6190 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6191 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6192 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6193 | } |
| 6194 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6195 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6198 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6202 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6204 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6205 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6206 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6207 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6208 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6209 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6210 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6211 | return -EINVAL; |
| 6212 | |
| 6213 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6214 | return -EINVAL; |
| 6215 | |
| 6216 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6217 | return -EINVAL; |
| 6218 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6219 | if (!rdev->ops->disassoc) |
| 6220 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6221 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6222 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6223 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6224 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6225 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6226 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6227 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6228 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6229 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6230 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6231 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6232 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6233 | |
| 6234 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6235 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6236 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6237 | } |
| 6238 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6239 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6240 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6241 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6242 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6243 | } |
| 6244 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6245 | static bool |
| 6246 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6247 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6248 | int rateval) |
| 6249 | { |
| 6250 | struct wiphy *wiphy = &rdev->wiphy; |
| 6251 | bool found = false; |
| 6252 | int band, i; |
| 6253 | |
| 6254 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6255 | struct ieee80211_supported_band *sband; |
| 6256 | |
| 6257 | sband = wiphy->bands[band]; |
| 6258 | if (!sband) |
| 6259 | continue; |
| 6260 | |
| 6261 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6262 | if (sband->bitrates[i].bitrate == rateval) { |
| 6263 | mcast_rate[band] = i + 1; |
| 6264 | found = true; |
| 6265 | break; |
| 6266 | } |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | return found; |
| 6271 | } |
| 6272 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6273 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6274 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6276 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6277 | struct cfg80211_ibss_params ibss; |
| 6278 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6279 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6280 | int err; |
| 6281 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6282 | memset(&ibss, 0, sizeof(ibss)); |
| 6283 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6284 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6285 | return -EINVAL; |
| 6286 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6287 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6288 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6289 | return -EINVAL; |
| 6290 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6291 | ibss.beacon_interval = 100; |
| 6292 | |
| 6293 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6294 | ibss.beacon_interval = |
| 6295 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6296 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6297 | return -EINVAL; |
| 6298 | } |
| 6299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6300 | if (!rdev->ops->join_ibss) |
| 6301 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6303 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6304 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6305 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6306 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6307 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6308 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6309 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6310 | |
| 6311 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6312 | return -EINVAL; |
| 6313 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6314 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6315 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6316 | |
| 6317 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6318 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6319 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6320 | } |
| 6321 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6322 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6323 | if (err) |
| 6324 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6325 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6326 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6327 | return -EINVAL; |
| 6328 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6329 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 6330 | return -EINVAL; |
| 6331 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 6332 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 6333 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6334 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6335 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6336 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6337 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6338 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6339 | u8 *rates = |
| 6340 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6341 | int n_rates = |
| 6342 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6343 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6344 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6345 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6346 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6347 | &ibss.basic_rates); |
| 6348 | if (err) |
| 6349 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6350 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6351 | |
| 6352 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6353 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6354 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6355 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6356 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6357 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6358 | bool no_ht = false; |
| 6359 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6360 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6361 | info->attrs[NL80211_ATTR_KEYS], |
| 6362 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6363 | if (IS_ERR(connkeys)) |
| 6364 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6365 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6366 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6367 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6368 | kfree(connkeys); |
| 6369 | return -EINVAL; |
| 6370 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6371 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6372 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6373 | ibss.control_port = |
| 6374 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6376 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6377 | if (err) |
| 6378 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6379 | return err; |
| 6380 | } |
| 6381 | |
| 6382 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6383 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6384 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6385 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6387 | if (!rdev->ops->leave_ibss) |
| 6388 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6390 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6391 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6392 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6393 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6394 | } |
| 6395 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6396 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6397 | { |
| 6398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6399 | struct net_device *dev = info->user_ptr[1]; |
| 6400 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6401 | u32 nla_rate; |
| 6402 | int err; |
| 6403 | |
| 6404 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6405 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6406 | return -EOPNOTSUPP; |
| 6407 | |
| 6408 | if (!rdev->ops->set_mcast_rate) |
| 6409 | return -EOPNOTSUPP; |
| 6410 | |
| 6411 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6412 | |
| 6413 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6414 | return -EINVAL; |
| 6415 | |
| 6416 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6417 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6418 | return -EINVAL; |
| 6419 | |
| 6420 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6421 | |
| 6422 | return err; |
| 6423 | } |
| 6424 | |
| 6425 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6426 | #ifdef CONFIG_NL80211_TESTMODE |
| 6427 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6428 | .name = "testmode", |
| 6429 | }; |
| 6430 | |
| 6431 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6432 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6433 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6434 | int err; |
| 6435 | |
| 6436 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6437 | return -EINVAL; |
| 6438 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6439 | err = -EOPNOTSUPP; |
| 6440 | if (rdev->ops->testmode_cmd) { |
| 6441 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6442 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6443 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6444 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6445 | rdev->testmode_info = NULL; |
| 6446 | } |
| 6447 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6448 | return err; |
| 6449 | } |
| 6450 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6451 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6452 | struct netlink_callback *cb) |
| 6453 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6454 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6455 | int err; |
| 6456 | long phy_idx; |
| 6457 | void *data = NULL; |
| 6458 | int data_len = 0; |
| 6459 | |
| 6460 | if (cb->args[0]) { |
| 6461 | /* |
| 6462 | * 0 is a valid index, but not valid for args[0], |
| 6463 | * so we need to offset by 1. |
| 6464 | */ |
| 6465 | phy_idx = cb->args[0] - 1; |
| 6466 | } else { |
| 6467 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6468 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6469 | nl80211_policy); |
| 6470 | if (err) |
| 6471 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6472 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6473 | mutex_lock(&cfg80211_mutex); |
| 6474 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6475 | nl80211_fam.attrbuf); |
| 6476 | if (IS_ERR(rdev)) { |
| 6477 | mutex_unlock(&cfg80211_mutex); |
| 6478 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6479 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6480 | phy_idx = rdev->wiphy_idx; |
| 6481 | rdev = NULL; |
| 6482 | mutex_unlock(&cfg80211_mutex); |
| 6483 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6484 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6485 | cb->args[1] = |
| 6486 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6487 | } |
| 6488 | |
| 6489 | if (cb->args[1]) { |
| 6490 | data = nla_data((void *)cb->args[1]); |
| 6491 | data_len = nla_len((void *)cb->args[1]); |
| 6492 | } |
| 6493 | |
| 6494 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6495 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6496 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6497 | mutex_unlock(&cfg80211_mutex); |
| 6498 | return -ENOENT; |
| 6499 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6500 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6501 | mutex_unlock(&cfg80211_mutex); |
| 6502 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6503 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6504 | err = -EOPNOTSUPP; |
| 6505 | goto out_err; |
| 6506 | } |
| 6507 | |
| 6508 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6509 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6510 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6511 | NL80211_CMD_TESTMODE); |
| 6512 | struct nlattr *tmdata; |
| 6513 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6514 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6515 | genlmsg_cancel(skb, hdr); |
| 6516 | break; |
| 6517 | } |
| 6518 | |
| 6519 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6520 | if (!tmdata) { |
| 6521 | genlmsg_cancel(skb, hdr); |
| 6522 | break; |
| 6523 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6524 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6525 | nla_nest_end(skb, tmdata); |
| 6526 | |
| 6527 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6528 | genlmsg_cancel(skb, hdr); |
| 6529 | break; |
| 6530 | } else if (err) { |
| 6531 | genlmsg_cancel(skb, hdr); |
| 6532 | goto out_err; |
| 6533 | } |
| 6534 | |
| 6535 | genlmsg_end(skb, hdr); |
| 6536 | } |
| 6537 | |
| 6538 | err = skb->len; |
| 6539 | /* see above */ |
| 6540 | cb->args[0] = phy_idx + 1; |
| 6541 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6542 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6543 | return err; |
| 6544 | } |
| 6545 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6546 | static struct sk_buff * |
| 6547 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6548 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6549 | { |
| 6550 | struct sk_buff *skb; |
| 6551 | void *hdr; |
| 6552 | struct nlattr *data; |
| 6553 | |
| 6554 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6555 | if (!skb) |
| 6556 | return NULL; |
| 6557 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6558 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6559 | if (!hdr) { |
| 6560 | kfree_skb(skb); |
| 6561 | return NULL; |
| 6562 | } |
| 6563 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6564 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6565 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6566 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6567 | |
| 6568 | ((void **)skb->cb)[0] = rdev; |
| 6569 | ((void **)skb->cb)[1] = hdr; |
| 6570 | ((void **)skb->cb)[2] = data; |
| 6571 | |
| 6572 | return skb; |
| 6573 | |
| 6574 | nla_put_failure: |
| 6575 | kfree_skb(skb); |
| 6576 | return NULL; |
| 6577 | } |
| 6578 | |
| 6579 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6580 | int approxlen) |
| 6581 | { |
| 6582 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6583 | |
| 6584 | if (WARN_ON(!rdev->testmode_info)) |
| 6585 | return NULL; |
| 6586 | |
| 6587 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6588 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6589 | rdev->testmode_info->snd_seq, |
| 6590 | GFP_KERNEL); |
| 6591 | } |
| 6592 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6593 | |
| 6594 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6595 | { |
| 6596 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6597 | void *hdr = ((void **)skb->cb)[1]; |
| 6598 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6599 | |
| 6600 | if (WARN_ON(!rdev->testmode_info)) { |
| 6601 | kfree_skb(skb); |
| 6602 | return -EINVAL; |
| 6603 | } |
| 6604 | |
| 6605 | nla_nest_end(skb, data); |
| 6606 | genlmsg_end(skb, hdr); |
| 6607 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6608 | } |
| 6609 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6610 | |
| 6611 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6612 | int approxlen, gfp_t gfp) |
| 6613 | { |
| 6614 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6615 | |
| 6616 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6617 | } |
| 6618 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6619 | |
| 6620 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6621 | { |
| 6622 | void *hdr = ((void **)skb->cb)[1]; |
| 6623 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6624 | |
| 6625 | nla_nest_end(skb, data); |
| 6626 | genlmsg_end(skb, hdr); |
| 6627 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6628 | } |
| 6629 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6630 | #endif |
| 6631 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6632 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6633 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6634 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6635 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6636 | struct cfg80211_connect_params connect; |
| 6637 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6638 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6639 | int err; |
| 6640 | |
| 6641 | memset(&connect, 0, sizeof(connect)); |
| 6642 | |
| 6643 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6644 | return -EINVAL; |
| 6645 | |
| 6646 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6647 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6648 | return -EINVAL; |
| 6649 | |
| 6650 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6651 | connect.auth_type = |
| 6652 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6653 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6654 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6655 | return -EINVAL; |
| 6656 | } else |
| 6657 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6658 | |
| 6659 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6660 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6661 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6662 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6663 | if (err) |
| 6664 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6665 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6666 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6667 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6668 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6669 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6670 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6671 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6672 | connect.bg_scan_period = -1; |
| 6673 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6674 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6675 | connect.bg_scan_period = |
| 6676 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6677 | } |
| 6678 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6679 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6680 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6681 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6682 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6683 | |
| 6684 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6685 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6686 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6687 | } |
| 6688 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6689 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6690 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6691 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6692 | connect.mfp != NL80211_MFP_NO) |
| 6693 | return -EINVAL; |
| 6694 | } else { |
| 6695 | connect.mfp = NL80211_MFP_NO; |
| 6696 | } |
| 6697 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6698 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6699 | connect.channel = |
| 6700 | ieee80211_get_channel(wiphy, |
| 6701 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6702 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6703 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6704 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6705 | } |
| 6706 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6707 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6708 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6709 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6710 | if (IS_ERR(connkeys)) |
| 6711 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6712 | } |
| 6713 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6714 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6715 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6716 | |
| 6717 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6718 | memcpy(&connect.ht_capa_mask, |
| 6719 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6720 | sizeof(connect.ht_capa_mask)); |
| 6721 | |
| 6722 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6723 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6724 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6725 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6726 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6727 | memcpy(&connect.ht_capa, |
| 6728 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6729 | sizeof(connect.ht_capa)); |
| 6730 | } |
| 6731 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6732 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6733 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6734 | |
| 6735 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6736 | memcpy(&connect.vht_capa_mask, |
| 6737 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6738 | sizeof(connect.vht_capa_mask)); |
| 6739 | |
| 6740 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6741 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6742 | kfree(connkeys); |
| 6743 | return -EINVAL; |
| 6744 | } |
| 6745 | memcpy(&connect.vht_capa, |
| 6746 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6747 | sizeof(connect.vht_capa)); |
| 6748 | } |
| 6749 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6750 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6751 | if (err) |
| 6752 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6753 | return err; |
| 6754 | } |
| 6755 | |
| 6756 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6757 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6759 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6760 | u16 reason; |
| 6761 | |
| 6762 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6763 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6764 | else |
| 6765 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6766 | |
| 6767 | if (reason == 0) |
| 6768 | return -EINVAL; |
| 6769 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6770 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6772 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6774 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6775 | } |
| 6776 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6777 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6778 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6780 | struct net *net; |
| 6781 | int err; |
| 6782 | u32 pid; |
| 6783 | |
| 6784 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6785 | return -EINVAL; |
| 6786 | |
| 6787 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6788 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6789 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6790 | if (IS_ERR(net)) |
| 6791 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6792 | |
| 6793 | err = 0; |
| 6794 | |
| 6795 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6796 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6797 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6798 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6799 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6800 | return err; |
| 6801 | } |
| 6802 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6803 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6804 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6806 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6807 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6809 | struct cfg80211_pmksa pmksa; |
| 6810 | |
| 6811 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6812 | |
| 6813 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6814 | return -EINVAL; |
| 6815 | |
| 6816 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6817 | return -EINVAL; |
| 6818 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6819 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6820 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6821 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6822 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6823 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6824 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6825 | |
| 6826 | switch (info->genlhdr->cmd) { |
| 6827 | case NL80211_CMD_SET_PMKSA: |
| 6828 | rdev_ops = rdev->ops->set_pmksa; |
| 6829 | break; |
| 6830 | case NL80211_CMD_DEL_PMKSA: |
| 6831 | rdev_ops = rdev->ops->del_pmksa; |
| 6832 | break; |
| 6833 | default: |
| 6834 | WARN_ON(1); |
| 6835 | break; |
| 6836 | } |
| 6837 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6838 | if (!rdev_ops) |
| 6839 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6840 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6841 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6845 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6847 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6848 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6849 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6850 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6851 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6853 | if (!rdev->ops->flush_pmksa) |
| 6854 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6855 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6856 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6857 | } |
| 6858 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6859 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6860 | { |
| 6861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6862 | struct net_device *dev = info->user_ptr[1]; |
| 6863 | u8 action_code, dialog_token; |
| 6864 | u16 status_code; |
| 6865 | u8 *peer; |
| 6866 | |
| 6867 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6868 | !rdev->ops->tdls_mgmt) |
| 6869 | return -EOPNOTSUPP; |
| 6870 | |
| 6871 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6872 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6873 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6874 | !info->attrs[NL80211_ATTR_IE] || |
| 6875 | !info->attrs[NL80211_ATTR_MAC]) |
| 6876 | return -EINVAL; |
| 6877 | |
| 6878 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6879 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6880 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6881 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6882 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6883 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6884 | dialog_token, status_code, |
| 6885 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6886 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6890 | { |
| 6891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6892 | struct net_device *dev = info->user_ptr[1]; |
| 6893 | enum nl80211_tdls_operation operation; |
| 6894 | u8 *peer; |
| 6895 | |
| 6896 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6897 | !rdev->ops->tdls_oper) |
| 6898 | return -EOPNOTSUPP; |
| 6899 | |
| 6900 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6901 | !info->attrs[NL80211_ATTR_MAC]) |
| 6902 | return -EINVAL; |
| 6903 | |
| 6904 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6905 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6906 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6907 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6908 | } |
| 6909 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6910 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6911 | struct genl_info *info) |
| 6912 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6914 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6915 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6916 | struct sk_buff *msg; |
| 6917 | void *hdr; |
| 6918 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6919 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6920 | int err; |
| 6921 | |
| 6922 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6923 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6924 | return -EINVAL; |
| 6925 | |
| 6926 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6927 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6928 | if (!rdev->ops->remain_on_channel || |
| 6929 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6930 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6931 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6932 | /* |
| 6933 | * We should be on that channel for at least a minimum amount of |
| 6934 | * time (10ms) but no longer than the driver supports. |
| 6935 | */ |
| 6936 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6937 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6938 | return -EINVAL; |
| 6939 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6940 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6941 | if (err) |
| 6942 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6943 | |
| 6944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6945 | if (!msg) |
| 6946 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6947 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6948 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6949 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6950 | |
| 6951 | if (IS_ERR(hdr)) { |
| 6952 | err = PTR_ERR(hdr); |
| 6953 | goto free_msg; |
| 6954 | } |
| 6955 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6956 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6957 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6958 | |
| 6959 | if (err) |
| 6960 | goto free_msg; |
| 6961 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6962 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6963 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6964 | |
| 6965 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6966 | |
| 6967 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6968 | |
| 6969 | nla_put_failure: |
| 6970 | err = -ENOBUFS; |
| 6971 | free_msg: |
| 6972 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6973 | return err; |
| 6974 | } |
| 6975 | |
| 6976 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6977 | struct genl_info *info) |
| 6978 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6980 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6981 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6982 | |
| 6983 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6984 | return -EINVAL; |
| 6985 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6986 | if (!rdev->ops->cancel_remain_on_channel) |
| 6987 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6988 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6989 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6990 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6991 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6992 | } |
| 6993 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6994 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6995 | u8 *rates, u8 rates_len) |
| 6996 | { |
| 6997 | u8 i; |
| 6998 | u32 mask = 0; |
| 6999 | |
| 7000 | for (i = 0; i < rates_len; i++) { |
| 7001 | int rate = (rates[i] & 0x7f) * 5; |
| 7002 | int ridx; |
| 7003 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7004 | struct ieee80211_rate *srate = |
| 7005 | &sband->bitrates[ridx]; |
| 7006 | if (rate == srate->bitrate) { |
| 7007 | mask |= 1 << ridx; |
| 7008 | break; |
| 7009 | } |
| 7010 | } |
| 7011 | if (ridx == sband->n_bitrates) |
| 7012 | return 0; /* rate not found */ |
| 7013 | } |
| 7014 | |
| 7015 | return mask; |
| 7016 | } |
| 7017 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7018 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7019 | u8 *rates, u8 rates_len, |
| 7020 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7021 | { |
| 7022 | u8 i; |
| 7023 | |
| 7024 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7025 | |
| 7026 | for (i = 0; i < rates_len; i++) { |
| 7027 | int ridx, rbit; |
| 7028 | |
| 7029 | ridx = rates[i] / 8; |
| 7030 | rbit = BIT(rates[i] % 8); |
| 7031 | |
| 7032 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7033 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7034 | return false; |
| 7035 | |
| 7036 | /* check availability */ |
| 7037 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7038 | mcs[ridx] |= rbit; |
| 7039 | else |
| 7040 | return false; |
| 7041 | } |
| 7042 | |
| 7043 | return true; |
| 7044 | } |
| 7045 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7046 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7047 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7048 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7049 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7050 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7051 | }; |
| 7052 | |
| 7053 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7054 | struct genl_info *info) |
| 7055 | { |
| 7056 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7058 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7059 | int rem, i; |
| 7060 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7061 | struct nlattr *tx_rates; |
| 7062 | struct ieee80211_supported_band *sband; |
| 7063 | |
| 7064 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7065 | return -EINVAL; |
| 7066 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7067 | if (!rdev->ops->set_bitrate_mask) |
| 7068 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7069 | |
| 7070 | memset(&mask, 0, sizeof(mask)); |
| 7071 | /* Default to all rates enabled */ |
| 7072 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7073 | sband = rdev->wiphy.bands[i]; |
| 7074 | mask.control[i].legacy = |
| 7075 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7076 | if (sband) |
| 7077 | memcpy(mask.control[i].mcs, |
| 7078 | sband->ht_cap.mcs.rx_mask, |
| 7079 | sizeof(mask.control[i].mcs)); |
| 7080 | else |
| 7081 | memset(mask.control[i].mcs, 0, |
| 7082 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | /* |
| 7086 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7087 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7088 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7089 | 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] | 7090 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7091 | { |
| 7092 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7093 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7094 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7095 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7096 | if (sband == NULL) |
| 7097 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7098 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7099 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7100 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7101 | mask.control[band].legacy = rateset_to_mask( |
| 7102 | sband, |
| 7103 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7104 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7105 | if ((mask.control[band].legacy == 0) && |
| 7106 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7107 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7108 | } |
| 7109 | if (tb[NL80211_TXRATE_MCS]) { |
| 7110 | if (!ht_rateset_to_mask( |
| 7111 | sband, |
| 7112 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7113 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7114 | mask.control[band].mcs)) |
| 7115 | return -EINVAL; |
| 7116 | } |
| 7117 | |
| 7118 | if (mask.control[band].legacy == 0) { |
| 7119 | /* don't allow empty legacy rates if HT |
| 7120 | * is not even supported. */ |
| 7121 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7122 | return -EINVAL; |
| 7123 | |
| 7124 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7125 | if (mask.control[band].mcs[i]) |
| 7126 | break; |
| 7127 | |
| 7128 | /* legacy and mcs rates may not be both empty */ |
| 7129 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7130 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7134 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7135 | } |
| 7136 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7137 | 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] | 7138 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7140 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7141 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7142 | |
| 7143 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7144 | return -EINVAL; |
| 7145 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7146 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7147 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7148 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7149 | switch (wdev->iftype) { |
| 7150 | case NL80211_IFTYPE_STATION: |
| 7151 | case NL80211_IFTYPE_ADHOC: |
| 7152 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7153 | case NL80211_IFTYPE_AP: |
| 7154 | case NL80211_IFTYPE_AP_VLAN: |
| 7155 | case NL80211_IFTYPE_MESH_POINT: |
| 7156 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7157 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7158 | break; |
| 7159 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7160 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7161 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7162 | |
| 7163 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7164 | if (!rdev->ops->mgmt_tx) |
| 7165 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7166 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7167 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7168 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7169 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7170 | } |
| 7171 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7172 | 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] | 7173 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7175 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7176 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7177 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7178 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7179 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7180 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7181 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7182 | bool offchan, no_cck, dont_wait_for_ack; |
| 7183 | |
| 7184 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7185 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7186 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7187 | return -EINVAL; |
| 7188 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7189 | if (!rdev->ops->mgmt_tx) |
| 7190 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7191 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7192 | switch (wdev->iftype) { |
| 7193 | case NL80211_IFTYPE_STATION: |
| 7194 | case NL80211_IFTYPE_ADHOC: |
| 7195 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7196 | case NL80211_IFTYPE_AP: |
| 7197 | case NL80211_IFTYPE_AP_VLAN: |
| 7198 | case NL80211_IFTYPE_MESH_POINT: |
| 7199 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7200 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7201 | break; |
| 7202 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7203 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7204 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7205 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7206 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7207 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7208 | return -EINVAL; |
| 7209 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7210 | |
| 7211 | /* |
| 7212 | * We should wait on the channel for at least a minimum amount |
| 7213 | * of time (10ms) but no longer than the driver supports. |
| 7214 | */ |
| 7215 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7216 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7217 | return -EINVAL; |
| 7218 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7219 | } |
| 7220 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7221 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7222 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7223 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7224 | return -EINVAL; |
| 7225 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7226 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7227 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7228 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7229 | if (err) |
| 7230 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7231 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7232 | if (!dont_wait_for_ack) { |
| 7233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7234 | if (!msg) |
| 7235 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7236 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7237 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7238 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7239 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7240 | if (IS_ERR(hdr)) { |
| 7241 | err = PTR_ERR(hdr); |
| 7242 | goto free_msg; |
| 7243 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7244 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7245 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7246 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7247 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7248 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7249 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7250 | if (err) |
| 7251 | goto free_msg; |
| 7252 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7253 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7254 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7255 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7256 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7257 | genlmsg_end(msg, hdr); |
| 7258 | return genlmsg_reply(msg, info); |
| 7259 | } |
| 7260 | |
| 7261 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7262 | |
| 7263 | nla_put_failure: |
| 7264 | err = -ENOBUFS; |
| 7265 | free_msg: |
| 7266 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7267 | return err; |
| 7268 | } |
| 7269 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7270 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7271 | { |
| 7272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7273 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7274 | u64 cookie; |
| 7275 | |
| 7276 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7277 | return -EINVAL; |
| 7278 | |
| 7279 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7280 | return -EOPNOTSUPP; |
| 7281 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7282 | switch (wdev->iftype) { |
| 7283 | case NL80211_IFTYPE_STATION: |
| 7284 | case NL80211_IFTYPE_ADHOC: |
| 7285 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7286 | case NL80211_IFTYPE_AP: |
| 7287 | case NL80211_IFTYPE_AP_VLAN: |
| 7288 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7289 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7290 | break; |
| 7291 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7292 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7293 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7294 | |
| 7295 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7296 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7297 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7298 | } |
| 7299 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7300 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7301 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7303 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7304 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7305 | u8 ps_state; |
| 7306 | bool state; |
| 7307 | int err; |
| 7308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7309 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7310 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | |
| 7312 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7314 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7315 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7316 | |
| 7317 | wdev = dev->ieee80211_ptr; |
| 7318 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7319 | if (!rdev->ops->set_power_mgmt) |
| 7320 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7321 | |
| 7322 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7323 | |
| 7324 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7325 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7326 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7327 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7328 | if (!err) |
| 7329 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7330 | return err; |
| 7331 | } |
| 7332 | |
| 7333 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7334 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7336 | enum nl80211_ps_state ps_state; |
| 7337 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7338 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7339 | struct sk_buff *msg; |
| 7340 | void *hdr; |
| 7341 | int err; |
| 7342 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7343 | wdev = dev->ieee80211_ptr; |
| 7344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7345 | if (!rdev->ops->set_power_mgmt) |
| 7346 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7347 | |
| 7348 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7349 | if (!msg) |
| 7350 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7351 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7352 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7353 | NL80211_CMD_GET_POWER_SAVE); |
| 7354 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7355 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7356 | goto free_msg; |
| 7357 | } |
| 7358 | |
| 7359 | if (wdev->ps) |
| 7360 | ps_state = NL80211_PS_ENABLED; |
| 7361 | else |
| 7362 | ps_state = NL80211_PS_DISABLED; |
| 7363 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7364 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7365 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7366 | |
| 7367 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7368 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7369 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7370 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7371 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7372 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7373 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7374 | return err; |
| 7375 | } |
| 7376 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7377 | static struct nla_policy |
| 7378 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7379 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7380 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7381 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7382 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7383 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7384 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7385 | }; |
| 7386 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7387 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7388 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7389 | { |
| 7390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7391 | struct wireless_dev *wdev; |
| 7392 | struct net_device *dev = info->user_ptr[1]; |
| 7393 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7394 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7395 | return -EINVAL; |
| 7396 | |
| 7397 | wdev = dev->ieee80211_ptr; |
| 7398 | |
| 7399 | if (!rdev->ops->set_cqm_txe_config) |
| 7400 | return -EOPNOTSUPP; |
| 7401 | |
| 7402 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7403 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7404 | return -EOPNOTSUPP; |
| 7405 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7406 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7407 | } |
| 7408 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7409 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7410 | s32 threshold, u32 hysteresis) |
| 7411 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7412 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7413 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7414 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7415 | |
| 7416 | if (threshold > 0) |
| 7417 | return -EINVAL; |
| 7418 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7419 | wdev = dev->ieee80211_ptr; |
| 7420 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7421 | if (!rdev->ops->set_cqm_rssi_config) |
| 7422 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7423 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7424 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7425 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7426 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7427 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7428 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7432 | { |
| 7433 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7434 | struct nlattr *cqm; |
| 7435 | int err; |
| 7436 | |
| 7437 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7438 | if (!cqm) { |
| 7439 | err = -EINVAL; |
| 7440 | goto out; |
| 7441 | } |
| 7442 | |
| 7443 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7444 | nl80211_attr_cqm_policy); |
| 7445 | if (err) |
| 7446 | goto out; |
| 7447 | |
| 7448 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7449 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7450 | s32 threshold; |
| 7451 | u32 hysteresis; |
| 7452 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7453 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7454 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7455 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7456 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7457 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7458 | u32 rate, pkts, intvl; |
| 7459 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7460 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7461 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7462 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7463 | } else |
| 7464 | err = -EINVAL; |
| 7465 | |
| 7466 | out: |
| 7467 | return err; |
| 7468 | } |
| 7469 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7470 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7471 | { |
| 7472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7473 | struct net_device *dev = info->user_ptr[1]; |
| 7474 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7475 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7476 | int err; |
| 7477 | |
| 7478 | /* start with default */ |
| 7479 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7480 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7481 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7482 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7483 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7484 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7485 | if (err) |
| 7486 | return err; |
| 7487 | } |
| 7488 | |
| 7489 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7490 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7491 | return -EINVAL; |
| 7492 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7493 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7494 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7495 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7496 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7497 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7498 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7499 | return -EINVAL; |
| 7500 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7501 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7502 | setup.beacon_interval = |
| 7503 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7504 | if (setup.beacon_interval < 10 || |
| 7505 | setup.beacon_interval > 10000) |
| 7506 | return -EINVAL; |
| 7507 | } |
| 7508 | |
| 7509 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7510 | setup.dtim_period = |
| 7511 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7512 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7513 | return -EINVAL; |
| 7514 | } |
| 7515 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7516 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7517 | /* parse additional setup parameters if given */ |
| 7518 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7519 | if (err) |
| 7520 | return err; |
| 7521 | } |
| 7522 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7523 | if (setup.user_mpm) |
| 7524 | cfg.auto_open_plinks = false; |
| 7525 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7526 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7527 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7528 | if (err) |
| 7529 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7530 | } else { |
| 7531 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7532 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7533 | } |
| 7534 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7535 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7536 | } |
| 7537 | |
| 7538 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7539 | { |
| 7540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7541 | struct net_device *dev = info->user_ptr[1]; |
| 7542 | |
| 7543 | return cfg80211_leave_mesh(rdev, dev); |
| 7544 | } |
| 7545 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7546 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7547 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7548 | struct cfg80211_registered_device *rdev) |
| 7549 | { |
| 7550 | struct nlattr *nl_pats, *nl_pat; |
| 7551 | int i, pat_len; |
| 7552 | |
| 7553 | if (!rdev->wowlan->n_patterns) |
| 7554 | return 0; |
| 7555 | |
| 7556 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7557 | if (!nl_pats) |
| 7558 | return -ENOBUFS; |
| 7559 | |
| 7560 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7561 | nl_pat = nla_nest_start(msg, i + 1); |
| 7562 | if (!nl_pat) |
| 7563 | return -ENOBUFS; |
| 7564 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7565 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7566 | DIV_ROUND_UP(pat_len, 8), |
| 7567 | rdev->wowlan->patterns[i].mask) || |
| 7568 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7569 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7570 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7571 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7572 | return -ENOBUFS; |
| 7573 | nla_nest_end(msg, nl_pat); |
| 7574 | } |
| 7575 | nla_nest_end(msg, nl_pats); |
| 7576 | |
| 7577 | return 0; |
| 7578 | } |
| 7579 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7580 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7581 | struct cfg80211_wowlan_tcp *tcp) |
| 7582 | { |
| 7583 | struct nlattr *nl_tcp; |
| 7584 | |
| 7585 | if (!tcp) |
| 7586 | return 0; |
| 7587 | |
| 7588 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7589 | if (!nl_tcp) |
| 7590 | return -ENOBUFS; |
| 7591 | |
| 7592 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7593 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7594 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7595 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7596 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7597 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7598 | tcp->payload_len, tcp->payload) || |
| 7599 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7600 | tcp->data_interval) || |
| 7601 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7602 | tcp->wake_len, tcp->wake_data) || |
| 7603 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7604 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7605 | return -ENOBUFS; |
| 7606 | |
| 7607 | if (tcp->payload_seq.len && |
| 7608 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7609 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7610 | return -ENOBUFS; |
| 7611 | |
| 7612 | if (tcp->payload_tok.len && |
| 7613 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7614 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7615 | &tcp->payload_tok)) |
| 7616 | return -ENOBUFS; |
| 7617 | |
| 7618 | return 0; |
| 7619 | } |
| 7620 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7621 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7622 | { |
| 7623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7624 | struct sk_buff *msg; |
| 7625 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7626 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7627 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7628 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7629 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7630 | return -EOPNOTSUPP; |
| 7631 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7632 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7633 | /* adjust size to have room for all the data */ |
| 7634 | size += rdev->wowlan->tcp->tokens_size + |
| 7635 | rdev->wowlan->tcp->payload_len + |
| 7636 | rdev->wowlan->tcp->wake_len + |
| 7637 | rdev->wowlan->tcp->wake_len / 8; |
| 7638 | } |
| 7639 | |
| 7640 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7641 | if (!msg) |
| 7642 | return -ENOMEM; |
| 7643 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7644 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7645 | NL80211_CMD_GET_WOWLAN); |
| 7646 | if (!hdr) |
| 7647 | goto nla_put_failure; |
| 7648 | |
| 7649 | if (rdev->wowlan) { |
| 7650 | struct nlattr *nl_wowlan; |
| 7651 | |
| 7652 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7653 | if (!nl_wowlan) |
| 7654 | goto nla_put_failure; |
| 7655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7656 | if ((rdev->wowlan->any && |
| 7657 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7658 | (rdev->wowlan->disconnect && |
| 7659 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7660 | (rdev->wowlan->magic_pkt && |
| 7661 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7662 | (rdev->wowlan->gtk_rekey_failure && |
| 7663 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7664 | (rdev->wowlan->eap_identity_req && |
| 7665 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7666 | (rdev->wowlan->four_way_handshake && |
| 7667 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7668 | (rdev->wowlan->rfkill_release && |
| 7669 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7670 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7671 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7672 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7673 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7674 | |
| 7675 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7676 | goto nla_put_failure; |
| 7677 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7678 | nla_nest_end(msg, nl_wowlan); |
| 7679 | } |
| 7680 | |
| 7681 | genlmsg_end(msg, hdr); |
| 7682 | return genlmsg_reply(msg, info); |
| 7683 | |
| 7684 | nla_put_failure: |
| 7685 | nlmsg_free(msg); |
| 7686 | return -ENOBUFS; |
| 7687 | } |
| 7688 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7689 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7690 | struct nlattr *attr, |
| 7691 | struct cfg80211_wowlan *trig) |
| 7692 | { |
| 7693 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7694 | struct cfg80211_wowlan_tcp *cfg; |
| 7695 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7696 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7697 | u32 size; |
| 7698 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7699 | int err, port; |
| 7700 | |
| 7701 | if (!rdev->wiphy.wowlan.tcp) |
| 7702 | return -EINVAL; |
| 7703 | |
| 7704 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7705 | nla_data(attr), nla_len(attr), |
| 7706 | nl80211_wowlan_tcp_policy); |
| 7707 | if (err) |
| 7708 | return err; |
| 7709 | |
| 7710 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7711 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7712 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7713 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7714 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7715 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7716 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7717 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7718 | return -EINVAL; |
| 7719 | |
| 7720 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7721 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7722 | return -EINVAL; |
| 7723 | |
| 7724 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7725 | rdev->wiphy.wowlan.tcp->data_interval_max || |
| 7726 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7727 | return -EINVAL; |
| 7728 | |
| 7729 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7730 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7731 | return -EINVAL; |
| 7732 | |
| 7733 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7734 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7735 | return -EINVAL; |
| 7736 | |
| 7737 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7738 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7739 | |
| 7740 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7741 | tokens_size = tokln - sizeof(*tok); |
| 7742 | |
| 7743 | if (!tok->len || tokens_size % tok->len) |
| 7744 | return -EINVAL; |
| 7745 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7746 | return -EINVAL; |
| 7747 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7748 | return -EINVAL; |
| 7749 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7750 | return -EINVAL; |
| 7751 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7752 | return -EINVAL; |
| 7753 | if (tok->offset + tok->len > data_size) |
| 7754 | return -EINVAL; |
| 7755 | } |
| 7756 | |
| 7757 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7758 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7759 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7760 | return -EINVAL; |
| 7761 | if (seq->len == 0 || seq->len > 4) |
| 7762 | return -EINVAL; |
| 7763 | if (seq->len + seq->offset > data_size) |
| 7764 | return -EINVAL; |
| 7765 | } |
| 7766 | |
| 7767 | size = sizeof(*cfg); |
| 7768 | size += data_size; |
| 7769 | size += wake_size + wake_mask_size; |
| 7770 | size += tokens_size; |
| 7771 | |
| 7772 | cfg = kzalloc(size, GFP_KERNEL); |
| 7773 | if (!cfg) |
| 7774 | return -ENOMEM; |
| 7775 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7776 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7777 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7778 | ETH_ALEN); |
| 7779 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7780 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7781 | else |
| 7782 | port = 0; |
| 7783 | #ifdef CONFIG_INET |
| 7784 | /* allocate a socket and port for it and use it */ |
| 7785 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7786 | IPPROTO_TCP, &cfg->sock, 1); |
| 7787 | if (err) { |
| 7788 | kfree(cfg); |
| 7789 | return err; |
| 7790 | } |
| 7791 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7792 | sock_release(cfg->sock); |
| 7793 | kfree(cfg); |
| 7794 | return -EADDRINUSE; |
| 7795 | } |
| 7796 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7797 | #else |
| 7798 | if (!port) { |
| 7799 | kfree(cfg); |
| 7800 | return -EINVAL; |
| 7801 | } |
| 7802 | cfg->src_port = port; |
| 7803 | #endif |
| 7804 | |
| 7805 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7806 | cfg->payload_len = data_size; |
| 7807 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7808 | memcpy((void *)cfg->payload, |
| 7809 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7810 | data_size); |
| 7811 | if (seq) |
| 7812 | cfg->payload_seq = *seq; |
| 7813 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7814 | cfg->wake_len = wake_size; |
| 7815 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7816 | memcpy((void *)cfg->wake_data, |
| 7817 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7818 | wake_size); |
| 7819 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7820 | data_size + wake_size; |
| 7821 | memcpy((void *)cfg->wake_mask, |
| 7822 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7823 | wake_mask_size); |
| 7824 | if (tok) { |
| 7825 | cfg->tokens_size = tokens_size; |
| 7826 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7827 | } |
| 7828 | |
| 7829 | trig->tcp = cfg; |
| 7830 | |
| 7831 | return 0; |
| 7832 | } |
| 7833 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7834 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7835 | { |
| 7836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7837 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7838 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7839 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7840 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7841 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7842 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7843 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7844 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7845 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7846 | return -EOPNOTSUPP; |
| 7847 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7848 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7849 | cfg80211_rdev_free_wowlan(rdev); |
| 7850 | rdev->wowlan = NULL; |
| 7851 | goto set_wakeup; |
| 7852 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7853 | |
| 7854 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7855 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7856 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7857 | nl80211_wowlan_policy); |
| 7858 | if (err) |
| 7859 | return err; |
| 7860 | |
| 7861 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7862 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7863 | return -EINVAL; |
| 7864 | new_triggers.any = true; |
| 7865 | } |
| 7866 | |
| 7867 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7868 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7869 | return -EINVAL; |
| 7870 | new_triggers.disconnect = true; |
| 7871 | } |
| 7872 | |
| 7873 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7874 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7875 | return -EINVAL; |
| 7876 | new_triggers.magic_pkt = true; |
| 7877 | } |
| 7878 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7879 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7880 | return -EINVAL; |
| 7881 | |
| 7882 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7883 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7884 | return -EINVAL; |
| 7885 | new_triggers.gtk_rekey_failure = true; |
| 7886 | } |
| 7887 | |
| 7888 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7889 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7890 | return -EINVAL; |
| 7891 | new_triggers.eap_identity_req = true; |
| 7892 | } |
| 7893 | |
| 7894 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7895 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7896 | return -EINVAL; |
| 7897 | new_triggers.four_way_handshake = true; |
| 7898 | } |
| 7899 | |
| 7900 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7901 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7902 | return -EINVAL; |
| 7903 | new_triggers.rfkill_release = true; |
| 7904 | } |
| 7905 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7906 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7907 | struct nlattr *pat; |
| 7908 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7909 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7910 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7911 | |
| 7912 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7913 | rem) |
| 7914 | n_patterns++; |
| 7915 | if (n_patterns > wowlan->n_patterns) |
| 7916 | return -EINVAL; |
| 7917 | |
| 7918 | new_triggers.patterns = kcalloc(n_patterns, |
| 7919 | sizeof(new_triggers.patterns[0]), |
| 7920 | GFP_KERNEL); |
| 7921 | if (!new_triggers.patterns) |
| 7922 | return -ENOMEM; |
| 7923 | |
| 7924 | new_triggers.n_patterns = n_patterns; |
| 7925 | i = 0; |
| 7926 | |
| 7927 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7928 | rem) { |
| 7929 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7930 | nla_data(pat), nla_len(pat), NULL); |
| 7931 | err = -EINVAL; |
| 7932 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7933 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7934 | goto error; |
| 7935 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7936 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7937 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7938 | mask_len) |
| 7939 | goto error; |
| 7940 | if (pat_len > wowlan->pattern_max_len || |
| 7941 | pat_len < wowlan->pattern_min_len) |
| 7942 | goto error; |
| 7943 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7944 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7945 | pkt_offset = 0; |
| 7946 | else |
| 7947 | pkt_offset = nla_get_u32( |
| 7948 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7949 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7950 | goto error; |
| 7951 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7952 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7953 | new_triggers.patterns[i].mask = |
| 7954 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7955 | if (!new_triggers.patterns[i].mask) { |
| 7956 | err = -ENOMEM; |
| 7957 | goto error; |
| 7958 | } |
| 7959 | new_triggers.patterns[i].pattern = |
| 7960 | new_triggers.patterns[i].mask + mask_len; |
| 7961 | memcpy(new_triggers.patterns[i].mask, |
| 7962 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7963 | mask_len); |
| 7964 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7965 | memcpy(new_triggers.patterns[i].pattern, |
| 7966 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7967 | pat_len); |
| 7968 | i++; |
| 7969 | } |
| 7970 | } |
| 7971 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7972 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7973 | err = nl80211_parse_wowlan_tcp( |
| 7974 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7975 | &new_triggers); |
| 7976 | if (err) |
| 7977 | goto error; |
| 7978 | } |
| 7979 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7980 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7981 | if (!ntrig) { |
| 7982 | err = -ENOMEM; |
| 7983 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7984 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7985 | cfg80211_rdev_free_wowlan(rdev); |
| 7986 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7987 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7988 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7989 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7990 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7991 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7992 | return 0; |
| 7993 | error: |
| 7994 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7995 | kfree(new_triggers.patterns[i].mask); |
| 7996 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7997 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7998 | sock_release(new_triggers.tcp->sock); |
| 7999 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8000 | return err; |
| 8001 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8002 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8003 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8004 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8005 | { |
| 8006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8007 | struct net_device *dev = info->user_ptr[1]; |
| 8008 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8009 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8010 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8011 | int err; |
| 8012 | |
| 8013 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8014 | return -EINVAL; |
| 8015 | |
| 8016 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8017 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8018 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8019 | nl80211_rekey_policy); |
| 8020 | if (err) |
| 8021 | return err; |
| 8022 | |
| 8023 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8024 | return -ERANGE; |
| 8025 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8026 | return -ERANGE; |
| 8027 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8028 | return -ERANGE; |
| 8029 | |
| 8030 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8031 | NL80211_KEK_LEN); |
| 8032 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8033 | NL80211_KCK_LEN); |
| 8034 | memcpy(rekey_data.replay_ctr, |
| 8035 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8036 | NL80211_REPLAY_CTR_LEN); |
| 8037 | |
| 8038 | wdev_lock(wdev); |
| 8039 | if (!wdev->current_bss) { |
| 8040 | err = -ENOTCONN; |
| 8041 | goto out; |
| 8042 | } |
| 8043 | |
| 8044 | if (!rdev->ops->set_rekey_data) { |
| 8045 | err = -EOPNOTSUPP; |
| 8046 | goto out; |
| 8047 | } |
| 8048 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8049 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8050 | out: |
| 8051 | wdev_unlock(wdev); |
| 8052 | return err; |
| 8053 | } |
| 8054 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8055 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8056 | struct genl_info *info) |
| 8057 | { |
| 8058 | struct net_device *dev = info->user_ptr[1]; |
| 8059 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8060 | |
| 8061 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8062 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8063 | return -EINVAL; |
| 8064 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8065 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8066 | return -EBUSY; |
| 8067 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8068 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8069 | return 0; |
| 8070 | } |
| 8071 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8072 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8073 | struct genl_info *info) |
| 8074 | { |
| 8075 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8076 | struct net_device *dev = info->user_ptr[1]; |
| 8077 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8078 | struct sk_buff *msg; |
| 8079 | void *hdr; |
| 8080 | const u8 *addr; |
| 8081 | u64 cookie; |
| 8082 | int err; |
| 8083 | |
| 8084 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8085 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8086 | return -EOPNOTSUPP; |
| 8087 | |
| 8088 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8089 | return -EINVAL; |
| 8090 | |
| 8091 | if (!rdev->ops->probe_client) |
| 8092 | return -EOPNOTSUPP; |
| 8093 | |
| 8094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8095 | if (!msg) |
| 8096 | return -ENOMEM; |
| 8097 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8098 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8099 | NL80211_CMD_PROBE_CLIENT); |
| 8100 | |
| 8101 | if (IS_ERR(hdr)) { |
| 8102 | err = PTR_ERR(hdr); |
| 8103 | goto free_msg; |
| 8104 | } |
| 8105 | |
| 8106 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8107 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8108 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8109 | if (err) |
| 8110 | goto free_msg; |
| 8111 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8112 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8113 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8114 | |
| 8115 | genlmsg_end(msg, hdr); |
| 8116 | |
| 8117 | return genlmsg_reply(msg, info); |
| 8118 | |
| 8119 | nla_put_failure: |
| 8120 | err = -ENOBUFS; |
| 8121 | free_msg: |
| 8122 | nlmsg_free(msg); |
| 8123 | return err; |
| 8124 | } |
| 8125 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8126 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8127 | { |
| 8128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8129 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8130 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8131 | |
| 8132 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8133 | return -EOPNOTSUPP; |
| 8134 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8135 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8136 | if (!nreg) |
| 8137 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8138 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8139 | /* First, check if already registered. */ |
| 8140 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8141 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8142 | if (reg->nlportid == info->snd_portid) { |
| 8143 | rv = -EALREADY; |
| 8144 | goto out_err; |
| 8145 | } |
| 8146 | } |
| 8147 | /* Add it to the list */ |
| 8148 | nreg->nlportid = info->snd_portid; |
| 8149 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8150 | |
| 8151 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8152 | |
| 8153 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8154 | out_err: |
| 8155 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8156 | kfree(nreg); |
| 8157 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8158 | } |
| 8159 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8160 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8161 | { |
| 8162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8163 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8164 | int err; |
| 8165 | |
| 8166 | if (!rdev->ops->start_p2p_device) |
| 8167 | return -EOPNOTSUPP; |
| 8168 | |
| 8169 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8170 | return -EOPNOTSUPP; |
| 8171 | |
| 8172 | if (wdev->p2p_started) |
| 8173 | return 0; |
| 8174 | |
| 8175 | mutex_lock(&rdev->devlist_mtx); |
| 8176 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 8177 | mutex_unlock(&rdev->devlist_mtx); |
| 8178 | if (err) |
| 8179 | return err; |
| 8180 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8181 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8182 | if (err) |
| 8183 | return err; |
| 8184 | |
| 8185 | wdev->p2p_started = true; |
| 8186 | mutex_lock(&rdev->devlist_mtx); |
| 8187 | rdev->opencount++; |
| 8188 | mutex_unlock(&rdev->devlist_mtx); |
| 8189 | |
| 8190 | return 0; |
| 8191 | } |
| 8192 | |
| 8193 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8194 | { |
| 8195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8196 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8197 | |
| 8198 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8199 | return -EOPNOTSUPP; |
| 8200 | |
| 8201 | if (!rdev->ops->stop_p2p_device) |
| 8202 | return -EOPNOTSUPP; |
| 8203 | |
Johannes Berg | 65e8d5b | 2013-04-19 12:18:19 +0200 | [diff] [blame] | 8204 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8205 | mutex_lock(&rdev->sched_scan_mtx); |
| 8206 | cfg80211_stop_p2p_device(rdev, wdev); |
| 8207 | mutex_unlock(&rdev->sched_scan_mtx); |
Johannes Berg | 65e8d5b | 2013-04-19 12:18:19 +0200 | [diff] [blame] | 8208 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8209 | |
| 8210 | return 0; |
| 8211 | } |
| 8212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8213 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8214 | struct genl_info *info) |
| 8215 | { |
| 8216 | void *hdr; |
| 8217 | struct sk_buff *msg; |
| 8218 | |
| 8219 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8220 | if (!msg) |
| 8221 | return -ENOMEM; |
| 8222 | |
| 8223 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8224 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8225 | if (!hdr) |
| 8226 | goto nla_put_failure; |
| 8227 | |
| 8228 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8229 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8230 | goto nla_put_failure; |
| 8231 | |
| 8232 | genlmsg_end(msg, hdr); |
| 8233 | return genlmsg_reply(msg, info); |
| 8234 | |
| 8235 | nla_put_failure: |
| 8236 | kfree_skb(msg); |
| 8237 | return -ENOBUFS; |
| 8238 | } |
| 8239 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8240 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8241 | { |
| 8242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8243 | struct cfg80211_update_ft_ies_params ft_params; |
| 8244 | struct net_device *dev = info->user_ptr[1]; |
| 8245 | |
| 8246 | if (!rdev->ops->update_ft_ies) |
| 8247 | return -EOPNOTSUPP; |
| 8248 | |
| 8249 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8250 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8251 | return -EINVAL; |
| 8252 | |
| 8253 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8254 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8255 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8256 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8257 | |
| 8258 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8259 | } |
| 8260 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8261 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8262 | struct genl_info *info) |
| 8263 | { |
| 8264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8265 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8266 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8267 | u16 duration; |
| 8268 | int ret; |
| 8269 | |
| 8270 | if (!rdev->ops->crit_proto_start) |
| 8271 | return -EOPNOTSUPP; |
| 8272 | |
| 8273 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8274 | return -EINVAL; |
| 8275 | |
| 8276 | if (rdev->crit_proto_nlportid) |
| 8277 | return -EBUSY; |
| 8278 | |
| 8279 | /* determine protocol if provided */ |
| 8280 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8281 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8282 | |
| 8283 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8284 | return -EINVAL; |
| 8285 | |
| 8286 | /* timeout must be provided */ |
| 8287 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8288 | return -EINVAL; |
| 8289 | |
| 8290 | duration = |
| 8291 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8292 | |
| 8293 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8294 | return -ERANGE; |
| 8295 | |
| 8296 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8297 | if (!ret) |
| 8298 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8299 | |
| 8300 | return ret; |
| 8301 | } |
| 8302 | |
| 8303 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8304 | struct genl_info *info) |
| 8305 | { |
| 8306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8307 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8308 | |
| 8309 | if (!rdev->ops->crit_proto_stop) |
| 8310 | return -EOPNOTSUPP; |
| 8311 | |
| 8312 | if (rdev->crit_proto_nlportid) { |
| 8313 | rdev->crit_proto_nlportid = 0; |
| 8314 | rdev_crit_proto_stop(rdev, wdev); |
| 8315 | } |
| 8316 | return 0; |
| 8317 | } |
| 8318 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8319 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8320 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8321 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8322 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8323 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8324 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8325 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8326 | /* 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] | 8327 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8328 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8329 | |
| 8330 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8331 | struct genl_info *info) |
| 8332 | { |
| 8333 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8334 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8335 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8336 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8337 | |
| 8338 | if (rtnl) |
| 8339 | rtnl_lock(); |
| 8340 | |
| 8341 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8342 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8343 | if (IS_ERR(rdev)) { |
| 8344 | if (rtnl) |
| 8345 | rtnl_unlock(); |
| 8346 | return PTR_ERR(rdev); |
| 8347 | } |
| 8348 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8349 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8350 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8351 | mutex_lock(&cfg80211_mutex); |
| 8352 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8353 | info->attrs); |
| 8354 | if (IS_ERR(wdev)) { |
| 8355 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8356 | if (rtnl) |
| 8357 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8358 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8359 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8360 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8361 | dev = wdev->netdev; |
| 8362 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8363 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8364 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8365 | if (!dev) { |
| 8366 | mutex_unlock(&cfg80211_mutex); |
| 8367 | if (rtnl) |
| 8368 | rtnl_unlock(); |
| 8369 | return -EINVAL; |
| 8370 | } |
| 8371 | |
| 8372 | info->user_ptr[1] = dev; |
| 8373 | } else { |
| 8374 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8375 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8376 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8377 | if (dev) { |
| 8378 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8379 | !netif_running(dev)) { |
| 8380 | mutex_unlock(&cfg80211_mutex); |
| 8381 | if (rtnl) |
| 8382 | rtnl_unlock(); |
| 8383 | return -ENETDOWN; |
| 8384 | } |
| 8385 | |
| 8386 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8387 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8388 | if (!wdev->p2p_started) { |
| 8389 | mutex_unlock(&cfg80211_mutex); |
| 8390 | if (rtnl) |
| 8391 | rtnl_unlock(); |
| 8392 | return -ENETDOWN; |
| 8393 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8394 | } |
| 8395 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8396 | cfg80211_lock_rdev(rdev); |
| 8397 | |
| 8398 | mutex_unlock(&cfg80211_mutex); |
| 8399 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8400 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8401 | } |
| 8402 | |
| 8403 | return 0; |
| 8404 | } |
| 8405 | |
| 8406 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8407 | struct genl_info *info) |
| 8408 | { |
| 8409 | if (info->user_ptr[0]) |
| 8410 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8411 | if (info->user_ptr[1]) { |
| 8412 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8413 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8414 | |
| 8415 | if (wdev->netdev) |
| 8416 | dev_put(wdev->netdev); |
| 8417 | } else { |
| 8418 | dev_put(info->user_ptr[1]); |
| 8419 | } |
| 8420 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8421 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8422 | rtnl_unlock(); |
| 8423 | } |
| 8424 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8425 | static struct genl_ops nl80211_ops[] = { |
| 8426 | { |
| 8427 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8428 | .doit = nl80211_get_wiphy, |
| 8429 | .dumpit = nl80211_dump_wiphy, |
| 8430 | .policy = nl80211_policy, |
| 8431 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8432 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8433 | }, |
| 8434 | { |
| 8435 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8436 | .doit = nl80211_set_wiphy, |
| 8437 | .policy = nl80211_policy, |
| 8438 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8439 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8440 | }, |
| 8441 | { |
| 8442 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8443 | .doit = nl80211_get_interface, |
| 8444 | .dumpit = nl80211_dump_interface, |
| 8445 | .policy = nl80211_policy, |
| 8446 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 8447 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8448 | }, |
| 8449 | { |
| 8450 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8451 | .doit = nl80211_set_interface, |
| 8452 | .policy = nl80211_policy, |
| 8453 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8454 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8455 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8456 | }, |
| 8457 | { |
| 8458 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8459 | .doit = nl80211_new_interface, |
| 8460 | .policy = nl80211_policy, |
| 8461 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8462 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8463 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8464 | }, |
| 8465 | { |
| 8466 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8467 | .doit = nl80211_del_interface, |
| 8468 | .policy = nl80211_policy, |
| 8469 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8470 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8471 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8472 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8473 | { |
| 8474 | .cmd = NL80211_CMD_GET_KEY, |
| 8475 | .doit = nl80211_get_key, |
| 8476 | .policy = nl80211_policy, |
| 8477 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8479 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8480 | }, |
| 8481 | { |
| 8482 | .cmd = NL80211_CMD_SET_KEY, |
| 8483 | .doit = nl80211_set_key, |
| 8484 | .policy = nl80211_policy, |
| 8485 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8486 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8487 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8488 | }, |
| 8489 | { |
| 8490 | .cmd = NL80211_CMD_NEW_KEY, |
| 8491 | .doit = nl80211_new_key, |
| 8492 | .policy = nl80211_policy, |
| 8493 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8494 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8495 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8496 | }, |
| 8497 | { |
| 8498 | .cmd = NL80211_CMD_DEL_KEY, |
| 8499 | .doit = nl80211_del_key, |
| 8500 | .policy = nl80211_policy, |
| 8501 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8502 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8503 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8504 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8505 | { |
| 8506 | .cmd = NL80211_CMD_SET_BEACON, |
| 8507 | .policy = nl80211_policy, |
| 8508 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8509 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8510 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8511 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8512 | }, |
| 8513 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8514 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8515 | .policy = nl80211_policy, |
| 8516 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8517 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8518 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8519 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8520 | }, |
| 8521 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8522 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8523 | .policy = nl80211_policy, |
| 8524 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8525 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8526 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8527 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8528 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8529 | { |
| 8530 | .cmd = NL80211_CMD_GET_STATION, |
| 8531 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8532 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8533 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8534 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8535 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8536 | }, |
| 8537 | { |
| 8538 | .cmd = NL80211_CMD_SET_STATION, |
| 8539 | .doit = nl80211_set_station, |
| 8540 | .policy = nl80211_policy, |
| 8541 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8543 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8544 | }, |
| 8545 | { |
| 8546 | .cmd = NL80211_CMD_NEW_STATION, |
| 8547 | .doit = nl80211_new_station, |
| 8548 | .policy = nl80211_policy, |
| 8549 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8551 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8552 | }, |
| 8553 | { |
| 8554 | .cmd = NL80211_CMD_DEL_STATION, |
| 8555 | .doit = nl80211_del_station, |
| 8556 | .policy = nl80211_policy, |
| 8557 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8558 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8559 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8560 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8561 | { |
| 8562 | .cmd = NL80211_CMD_GET_MPATH, |
| 8563 | .doit = nl80211_get_mpath, |
| 8564 | .dumpit = nl80211_dump_mpath, |
| 8565 | .policy = nl80211_policy, |
| 8566 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8567 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8568 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8569 | }, |
| 8570 | { |
| 8571 | .cmd = NL80211_CMD_SET_MPATH, |
| 8572 | .doit = nl80211_set_mpath, |
| 8573 | .policy = nl80211_policy, |
| 8574 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8575 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8576 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8577 | }, |
| 8578 | { |
| 8579 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8580 | .doit = nl80211_new_mpath, |
| 8581 | .policy = nl80211_policy, |
| 8582 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8583 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8584 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8585 | }, |
| 8586 | { |
| 8587 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8588 | .doit = nl80211_del_mpath, |
| 8589 | .policy = nl80211_policy, |
| 8590 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8592 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8593 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8594 | { |
| 8595 | .cmd = NL80211_CMD_SET_BSS, |
| 8596 | .doit = nl80211_set_bss, |
| 8597 | .policy = nl80211_policy, |
| 8598 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8600 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8601 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8602 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8603 | .cmd = NL80211_CMD_GET_REG, |
| 8604 | .doit = nl80211_get_reg, |
| 8605 | .policy = nl80211_policy, |
| 8606 | /* can be retrieved by unprivileged users */ |
| 8607 | }, |
| 8608 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8609 | .cmd = NL80211_CMD_SET_REG, |
| 8610 | .doit = nl80211_set_reg, |
| 8611 | .policy = nl80211_policy, |
| 8612 | .flags = GENL_ADMIN_PERM, |
| 8613 | }, |
| 8614 | { |
| 8615 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8616 | .doit = nl80211_req_set_reg, |
| 8617 | .policy = nl80211_policy, |
| 8618 | .flags = GENL_ADMIN_PERM, |
| 8619 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8620 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8621 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8622 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8623 | .policy = nl80211_policy, |
| 8624 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8625 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8626 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8627 | }, |
| 8628 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8629 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8630 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8631 | .policy = nl80211_policy, |
| 8632 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8633 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8634 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8635 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8636 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8637 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8638 | .doit = nl80211_trigger_scan, |
| 8639 | .policy = nl80211_policy, |
| 8640 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8641 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8642 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8643 | }, |
| 8644 | { |
| 8645 | .cmd = NL80211_CMD_GET_SCAN, |
| 8646 | .policy = nl80211_policy, |
| 8647 | .dumpit = nl80211_dump_scan, |
| 8648 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8649 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8650 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8651 | .doit = nl80211_start_sched_scan, |
| 8652 | .policy = nl80211_policy, |
| 8653 | .flags = GENL_ADMIN_PERM, |
| 8654 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8655 | NL80211_FLAG_NEED_RTNL, |
| 8656 | }, |
| 8657 | { |
| 8658 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8659 | .doit = nl80211_stop_sched_scan, |
| 8660 | .policy = nl80211_policy, |
| 8661 | .flags = GENL_ADMIN_PERM, |
| 8662 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8663 | NL80211_FLAG_NEED_RTNL, |
| 8664 | }, |
| 8665 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8666 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8667 | .doit = nl80211_authenticate, |
| 8668 | .policy = nl80211_policy, |
| 8669 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8671 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8672 | }, |
| 8673 | { |
| 8674 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8675 | .doit = nl80211_associate, |
| 8676 | .policy = nl80211_policy, |
| 8677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8678 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8679 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8680 | }, |
| 8681 | { |
| 8682 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8683 | .doit = nl80211_deauthenticate, |
| 8684 | .policy = nl80211_policy, |
| 8685 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8687 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8688 | }, |
| 8689 | { |
| 8690 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8691 | .doit = nl80211_disassociate, |
| 8692 | .policy = nl80211_policy, |
| 8693 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8694 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8695 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8696 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8697 | { |
| 8698 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8699 | .doit = nl80211_join_ibss, |
| 8700 | .policy = nl80211_policy, |
| 8701 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8702 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8703 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8704 | }, |
| 8705 | { |
| 8706 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8707 | .doit = nl80211_leave_ibss, |
| 8708 | .policy = nl80211_policy, |
| 8709 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8710 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8711 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8712 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8713 | #ifdef CONFIG_NL80211_TESTMODE |
| 8714 | { |
| 8715 | .cmd = NL80211_CMD_TESTMODE, |
| 8716 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8717 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8718 | .policy = nl80211_policy, |
| 8719 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8720 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8721 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8722 | }, |
| 8723 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8724 | { |
| 8725 | .cmd = NL80211_CMD_CONNECT, |
| 8726 | .doit = nl80211_connect, |
| 8727 | .policy = nl80211_policy, |
| 8728 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8729 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8730 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8731 | }, |
| 8732 | { |
| 8733 | .cmd = NL80211_CMD_DISCONNECT, |
| 8734 | .doit = nl80211_disconnect, |
| 8735 | .policy = nl80211_policy, |
| 8736 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8737 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8738 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8739 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8740 | { |
| 8741 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8742 | .doit = nl80211_wiphy_netns, |
| 8743 | .policy = nl80211_policy, |
| 8744 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8745 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8746 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8747 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8748 | { |
| 8749 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8750 | .policy = nl80211_policy, |
| 8751 | .dumpit = nl80211_dump_survey, |
| 8752 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8753 | { |
| 8754 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8755 | .doit = nl80211_setdel_pmksa, |
| 8756 | .policy = nl80211_policy, |
| 8757 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8759 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8760 | }, |
| 8761 | { |
| 8762 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8763 | .doit = nl80211_setdel_pmksa, |
| 8764 | .policy = nl80211_policy, |
| 8765 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8767 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8768 | }, |
| 8769 | { |
| 8770 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8771 | .doit = nl80211_flush_pmksa, |
| 8772 | .policy = nl80211_policy, |
| 8773 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8775 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8776 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8777 | { |
| 8778 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8779 | .doit = nl80211_remain_on_channel, |
| 8780 | .policy = nl80211_policy, |
| 8781 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8782 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8783 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8784 | }, |
| 8785 | { |
| 8786 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8787 | .doit = nl80211_cancel_remain_on_channel, |
| 8788 | .policy = nl80211_policy, |
| 8789 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8790 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8791 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8792 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8793 | { |
| 8794 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8795 | .doit = nl80211_set_tx_bitrate_mask, |
| 8796 | .policy = nl80211_policy, |
| 8797 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8798 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8799 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8800 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8801 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8802 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8803 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8804 | .policy = nl80211_policy, |
| 8805 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8806 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8807 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8808 | }, |
| 8809 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8810 | .cmd = NL80211_CMD_FRAME, |
| 8811 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8812 | .policy = nl80211_policy, |
| 8813 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8814 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8815 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8816 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8817 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8818 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8819 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8820 | .policy = nl80211_policy, |
| 8821 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8822 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8823 | NL80211_FLAG_NEED_RTNL, |
| 8824 | }, |
| 8825 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8826 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8827 | .doit = nl80211_set_power_save, |
| 8828 | .policy = nl80211_policy, |
| 8829 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8830 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8831 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8832 | }, |
| 8833 | { |
| 8834 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8835 | .doit = nl80211_get_power_save, |
| 8836 | .policy = nl80211_policy, |
| 8837 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8838 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8839 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8840 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8841 | { |
| 8842 | .cmd = NL80211_CMD_SET_CQM, |
| 8843 | .doit = nl80211_set_cqm, |
| 8844 | .policy = nl80211_policy, |
| 8845 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8846 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8847 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8848 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8849 | { |
| 8850 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8851 | .doit = nl80211_set_channel, |
| 8852 | .policy = nl80211_policy, |
| 8853 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8854 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8855 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8856 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8857 | { |
| 8858 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8859 | .doit = nl80211_set_wds_peer, |
| 8860 | .policy = nl80211_policy, |
| 8861 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8862 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8863 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8864 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8865 | { |
| 8866 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8867 | .doit = nl80211_join_mesh, |
| 8868 | .policy = nl80211_policy, |
| 8869 | .flags = GENL_ADMIN_PERM, |
| 8870 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8871 | NL80211_FLAG_NEED_RTNL, |
| 8872 | }, |
| 8873 | { |
| 8874 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8875 | .doit = nl80211_leave_mesh, |
| 8876 | .policy = nl80211_policy, |
| 8877 | .flags = GENL_ADMIN_PERM, |
| 8878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8879 | NL80211_FLAG_NEED_RTNL, |
| 8880 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8881 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8882 | { |
| 8883 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8884 | .doit = nl80211_get_wowlan, |
| 8885 | .policy = nl80211_policy, |
| 8886 | /* can be retrieved by unprivileged users */ |
| 8887 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8888 | NL80211_FLAG_NEED_RTNL, |
| 8889 | }, |
| 8890 | { |
| 8891 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8892 | .doit = nl80211_set_wowlan, |
| 8893 | .policy = nl80211_policy, |
| 8894 | .flags = GENL_ADMIN_PERM, |
| 8895 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8896 | NL80211_FLAG_NEED_RTNL, |
| 8897 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8898 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8899 | { |
| 8900 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8901 | .doit = nl80211_set_rekey_data, |
| 8902 | .policy = nl80211_policy, |
| 8903 | .flags = GENL_ADMIN_PERM, |
| 8904 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8905 | NL80211_FLAG_NEED_RTNL, |
| 8906 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8907 | { |
| 8908 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8909 | .doit = nl80211_tdls_mgmt, |
| 8910 | .policy = nl80211_policy, |
| 8911 | .flags = GENL_ADMIN_PERM, |
| 8912 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8913 | NL80211_FLAG_NEED_RTNL, |
| 8914 | }, |
| 8915 | { |
| 8916 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8917 | .doit = nl80211_tdls_oper, |
| 8918 | .policy = nl80211_policy, |
| 8919 | .flags = GENL_ADMIN_PERM, |
| 8920 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8921 | NL80211_FLAG_NEED_RTNL, |
| 8922 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8923 | { |
| 8924 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8925 | .doit = nl80211_register_unexpected_frame, |
| 8926 | .policy = nl80211_policy, |
| 8927 | .flags = GENL_ADMIN_PERM, |
| 8928 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8929 | NL80211_FLAG_NEED_RTNL, |
| 8930 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8931 | { |
| 8932 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8933 | .doit = nl80211_probe_client, |
| 8934 | .policy = nl80211_policy, |
| 8935 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8936 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8937 | NL80211_FLAG_NEED_RTNL, |
| 8938 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8939 | { |
| 8940 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8941 | .doit = nl80211_register_beacons, |
| 8942 | .policy = nl80211_policy, |
| 8943 | .flags = GENL_ADMIN_PERM, |
| 8944 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8945 | NL80211_FLAG_NEED_RTNL, |
| 8946 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8947 | { |
| 8948 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8949 | .doit = nl80211_set_noack_map, |
| 8950 | .policy = nl80211_policy, |
| 8951 | .flags = GENL_ADMIN_PERM, |
| 8952 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8953 | NL80211_FLAG_NEED_RTNL, |
| 8954 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8955 | { |
| 8956 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8957 | .doit = nl80211_start_p2p_device, |
| 8958 | .policy = nl80211_policy, |
| 8959 | .flags = GENL_ADMIN_PERM, |
| 8960 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8961 | NL80211_FLAG_NEED_RTNL, |
| 8962 | }, |
| 8963 | { |
| 8964 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8965 | .doit = nl80211_stop_p2p_device, |
| 8966 | .policy = nl80211_policy, |
| 8967 | .flags = GENL_ADMIN_PERM, |
| 8968 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8969 | NL80211_FLAG_NEED_RTNL, |
| 8970 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8971 | { |
| 8972 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8973 | .doit = nl80211_set_mcast_rate, |
| 8974 | .policy = nl80211_policy, |
| 8975 | .flags = GENL_ADMIN_PERM, |
| 8976 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8977 | NL80211_FLAG_NEED_RTNL, |
| 8978 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8979 | { |
| 8980 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8981 | .doit = nl80211_set_mac_acl, |
| 8982 | .policy = nl80211_policy, |
| 8983 | .flags = GENL_ADMIN_PERM, |
| 8984 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8985 | NL80211_FLAG_NEED_RTNL, |
| 8986 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8987 | { |
| 8988 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8989 | .doit = nl80211_start_radar_detection, |
| 8990 | .policy = nl80211_policy, |
| 8991 | .flags = GENL_ADMIN_PERM, |
| 8992 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8993 | NL80211_FLAG_NEED_RTNL, |
| 8994 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8995 | { |
| 8996 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8997 | .doit = nl80211_get_protocol_features, |
| 8998 | .policy = nl80211_policy, |
| 8999 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9000 | { |
| 9001 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9002 | .doit = nl80211_update_ft_ies, |
| 9003 | .policy = nl80211_policy, |
| 9004 | .flags = GENL_ADMIN_PERM, |
| 9005 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9006 | NL80211_FLAG_NEED_RTNL, |
| 9007 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9008 | { |
| 9009 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9010 | .doit = nl80211_crit_protocol_start, |
| 9011 | .policy = nl80211_policy, |
| 9012 | .flags = GENL_ADMIN_PERM, |
| 9013 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9014 | NL80211_FLAG_NEED_RTNL, |
| 9015 | }, |
| 9016 | { |
| 9017 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9018 | .doit = nl80211_crit_protocol_stop, |
| 9019 | .policy = nl80211_policy, |
| 9020 | .flags = GENL_ADMIN_PERM, |
| 9021 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9022 | NL80211_FLAG_NEED_RTNL, |
| 9023 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9024 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9025 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9026 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9027 | .name = "mlme", |
| 9028 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9029 | |
| 9030 | /* multicast groups */ |
| 9031 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9032 | .name = "config", |
| 9033 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9034 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9035 | .name = "scan", |
| 9036 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9037 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9038 | .name = "regulatory", |
| 9039 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9040 | |
| 9041 | /* notification functions */ |
| 9042 | |
| 9043 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9044 | { |
| 9045 | struct sk_buff *msg; |
| 9046 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9047 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9048 | if (!msg) |
| 9049 | return; |
| 9050 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9051 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 9052 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9053 | nlmsg_free(msg); |
| 9054 | return; |
| 9055 | } |
| 9056 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9057 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9058 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9059 | } |
| 9060 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9061 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9062 | struct cfg80211_registered_device *rdev) |
| 9063 | { |
| 9064 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9065 | struct nlattr *nest; |
| 9066 | int i; |
| 9067 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9068 | lockdep_assert_held(&rdev->sched_scan_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9069 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9070 | if (WARN_ON(!req)) |
| 9071 | return 0; |
| 9072 | |
| 9073 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9074 | if (!nest) |
| 9075 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9076 | for (i = 0; i < req->n_ssids; i++) { |
| 9077 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9078 | goto nla_put_failure; |
| 9079 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9080 | nla_nest_end(msg, nest); |
| 9081 | |
| 9082 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9083 | if (!nest) |
| 9084 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9085 | for (i = 0; i < req->n_channels; i++) { |
| 9086 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9087 | goto nla_put_failure; |
| 9088 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9089 | nla_nest_end(msg, nest); |
| 9090 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9091 | if (req->ie && |
| 9092 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9093 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9094 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9095 | if (req->flags) |
| 9096 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9097 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9098 | return 0; |
| 9099 | nla_put_failure: |
| 9100 | return -ENOBUFS; |
| 9101 | } |
| 9102 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9103 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9104 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9105 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9106 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9107 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9108 | { |
| 9109 | void *hdr; |
| 9110 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9111 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9112 | if (!hdr) |
| 9113 | return -1; |
| 9114 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9115 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9116 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9117 | wdev->netdev->ifindex)) || |
| 9118 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9119 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9120 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9121 | /* ignore errors and send incomplete event anyway */ |
| 9122 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9123 | |
| 9124 | return genlmsg_end(msg, hdr); |
| 9125 | |
| 9126 | nla_put_failure: |
| 9127 | genlmsg_cancel(msg, hdr); |
| 9128 | return -EMSGSIZE; |
| 9129 | } |
| 9130 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9131 | static int |
| 9132 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9133 | struct cfg80211_registered_device *rdev, |
| 9134 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9135 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9136 | { |
| 9137 | void *hdr; |
| 9138 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9139 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9140 | if (!hdr) |
| 9141 | return -1; |
| 9142 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9143 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9144 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9145 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9146 | |
| 9147 | return genlmsg_end(msg, hdr); |
| 9148 | |
| 9149 | nla_put_failure: |
| 9150 | genlmsg_cancel(msg, hdr); |
| 9151 | return -EMSGSIZE; |
| 9152 | } |
| 9153 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9154 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9155 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9156 | { |
| 9157 | struct sk_buff *msg; |
| 9158 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9159 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9160 | if (!msg) |
| 9161 | return; |
| 9162 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9163 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9164 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9165 | nlmsg_free(msg); |
| 9166 | return; |
| 9167 | } |
| 9168 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9169 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9170 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9171 | } |
| 9172 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9173 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9174 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9175 | { |
| 9176 | struct sk_buff *msg; |
| 9177 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9178 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9179 | if (!msg) |
| 9180 | return; |
| 9181 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9182 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9183 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9184 | nlmsg_free(msg); |
| 9185 | return; |
| 9186 | } |
| 9187 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9188 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9189 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9190 | } |
| 9191 | |
| 9192 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9193 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9194 | { |
| 9195 | struct sk_buff *msg; |
| 9196 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9197 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9198 | if (!msg) |
| 9199 | return; |
| 9200 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9201 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9202 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9203 | nlmsg_free(msg); |
| 9204 | return; |
| 9205 | } |
| 9206 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9207 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9208 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9209 | } |
| 9210 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9211 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9212 | struct net_device *netdev) |
| 9213 | { |
| 9214 | struct sk_buff *msg; |
| 9215 | |
| 9216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9217 | if (!msg) |
| 9218 | return; |
| 9219 | |
| 9220 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9221 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9222 | nlmsg_free(msg); |
| 9223 | return; |
| 9224 | } |
| 9225 | |
| 9226 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9227 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9228 | } |
| 9229 | |
| 9230 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9231 | struct net_device *netdev, u32 cmd) |
| 9232 | { |
| 9233 | struct sk_buff *msg; |
| 9234 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9236 | if (!msg) |
| 9237 | return; |
| 9238 | |
| 9239 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9240 | nlmsg_free(msg); |
| 9241 | return; |
| 9242 | } |
| 9243 | |
| 9244 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9245 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9246 | } |
| 9247 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9248 | /* |
| 9249 | * This can happen on global regulatory changes or device specific settings |
| 9250 | * based on custom world regulatory domains. |
| 9251 | */ |
| 9252 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9253 | { |
| 9254 | struct sk_buff *msg; |
| 9255 | void *hdr; |
| 9256 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9258 | if (!msg) |
| 9259 | return; |
| 9260 | |
| 9261 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9262 | if (!hdr) { |
| 9263 | nlmsg_free(msg); |
| 9264 | return; |
| 9265 | } |
| 9266 | |
| 9267 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9268 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9269 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9270 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9271 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9272 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9273 | NL80211_REGDOM_TYPE_WORLD)) |
| 9274 | goto nla_put_failure; |
| 9275 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9276 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9277 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9278 | goto nla_put_failure; |
| 9279 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9280 | request->intersect) { |
| 9281 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9282 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9283 | goto nla_put_failure; |
| 9284 | } else { |
| 9285 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9286 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9287 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9288 | request->alpha2)) |
| 9289 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9290 | } |
| 9291 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9292 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9293 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9294 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9295 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9296 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9297 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9298 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9299 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9300 | GFP_ATOMIC); |
| 9301 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9302 | |
| 9303 | return; |
| 9304 | |
| 9305 | nla_put_failure: |
| 9306 | genlmsg_cancel(msg, hdr); |
| 9307 | nlmsg_free(msg); |
| 9308 | } |
| 9309 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9310 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9311 | struct net_device *netdev, |
| 9312 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9313 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9314 | { |
| 9315 | struct sk_buff *msg; |
| 9316 | void *hdr; |
| 9317 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9318 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9319 | if (!msg) |
| 9320 | return; |
| 9321 | |
| 9322 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9323 | if (!hdr) { |
| 9324 | nlmsg_free(msg); |
| 9325 | return; |
| 9326 | } |
| 9327 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9329 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9330 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9331 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9332 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9333 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9334 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9335 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9336 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9337 | return; |
| 9338 | |
| 9339 | nla_put_failure: |
| 9340 | genlmsg_cancel(msg, hdr); |
| 9341 | nlmsg_free(msg); |
| 9342 | } |
| 9343 | |
| 9344 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9345 | struct net_device *netdev, const u8 *buf, |
| 9346 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9347 | { |
| 9348 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9349 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9350 | } |
| 9351 | |
| 9352 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9353 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9354 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9355 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9356 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9357 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9358 | } |
| 9359 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9360 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9361 | struct net_device *netdev, const u8 *buf, |
| 9362 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9363 | { |
| 9364 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9365 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9366 | } |
| 9367 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9368 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9369 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9370 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9371 | { |
| 9372 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9373 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9374 | } |
| 9375 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9376 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
| 9377 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9378 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9379 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9380 | struct wiphy *wiphy = wdev->wiphy; |
| 9381 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9382 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9383 | trace_cfg80211_send_unprot_deauth(dev); |
| 9384 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9385 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9386 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9387 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
| 9388 | |
| 9389 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
| 9390 | size_t len) |
| 9391 | { |
| 9392 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9393 | struct wiphy *wiphy = wdev->wiphy; |
| 9394 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9395 | |
| 9396 | trace_cfg80211_send_unprot_disassoc(dev); |
| 9397 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9398 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); |
| 9399 | } |
| 9400 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9401 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9402 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9403 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9404 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9405 | { |
| 9406 | struct sk_buff *msg; |
| 9407 | void *hdr; |
| 9408 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9410 | if (!msg) |
| 9411 | return; |
| 9412 | |
| 9413 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9414 | if (!hdr) { |
| 9415 | nlmsg_free(msg); |
| 9416 | return; |
| 9417 | } |
| 9418 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9419 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9420 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9421 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9422 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9423 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9424 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9425 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9426 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9427 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9428 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9429 | return; |
| 9430 | |
| 9431 | nla_put_failure: |
| 9432 | genlmsg_cancel(msg, hdr); |
| 9433 | nlmsg_free(msg); |
| 9434 | } |
| 9435 | |
| 9436 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9437 | struct net_device *netdev, const u8 *addr, |
| 9438 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9439 | { |
| 9440 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9441 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9442 | } |
| 9443 | |
| 9444 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9445 | struct net_device *netdev, const u8 *addr, |
| 9446 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9447 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9448 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9449 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9450 | } |
| 9451 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9452 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9453 | struct net_device *netdev, const u8 *bssid, |
| 9454 | const u8 *req_ie, size_t req_ie_len, |
| 9455 | const u8 *resp_ie, size_t resp_ie_len, |
| 9456 | u16 status, gfp_t gfp) |
| 9457 | { |
| 9458 | struct sk_buff *msg; |
| 9459 | void *hdr; |
| 9460 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9462 | if (!msg) |
| 9463 | return; |
| 9464 | |
| 9465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9466 | if (!hdr) { |
| 9467 | nlmsg_free(msg); |
| 9468 | return; |
| 9469 | } |
| 9470 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9471 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9472 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9473 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9474 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9475 | (req_ie && |
| 9476 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9477 | (resp_ie && |
| 9478 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9479 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9480 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9481 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9482 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9483 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9484 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9485 | return; |
| 9486 | |
| 9487 | nla_put_failure: |
| 9488 | genlmsg_cancel(msg, hdr); |
| 9489 | nlmsg_free(msg); |
| 9490 | |
| 9491 | } |
| 9492 | |
| 9493 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9494 | struct net_device *netdev, const u8 *bssid, |
| 9495 | const u8 *req_ie, size_t req_ie_len, |
| 9496 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9497 | { |
| 9498 | struct sk_buff *msg; |
| 9499 | void *hdr; |
| 9500 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9501 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9502 | if (!msg) |
| 9503 | return; |
| 9504 | |
| 9505 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9506 | if (!hdr) { |
| 9507 | nlmsg_free(msg); |
| 9508 | return; |
| 9509 | } |
| 9510 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9511 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9512 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9513 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9514 | (req_ie && |
| 9515 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9516 | (resp_ie && |
| 9517 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9518 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9519 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9520 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9521 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9522 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9523 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9524 | return; |
| 9525 | |
| 9526 | nla_put_failure: |
| 9527 | genlmsg_cancel(msg, hdr); |
| 9528 | nlmsg_free(msg); |
| 9529 | |
| 9530 | } |
| 9531 | |
| 9532 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9533 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9534 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9535 | { |
| 9536 | struct sk_buff *msg; |
| 9537 | void *hdr; |
| 9538 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9540 | if (!msg) |
| 9541 | return; |
| 9542 | |
| 9543 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9544 | if (!hdr) { |
| 9545 | nlmsg_free(msg); |
| 9546 | return; |
| 9547 | } |
| 9548 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9549 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9550 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9551 | (from_ap && reason && |
| 9552 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9553 | (from_ap && |
| 9554 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9555 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9556 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9557 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9558 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9559 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9560 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9561 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9562 | return; |
| 9563 | |
| 9564 | nla_put_failure: |
| 9565 | genlmsg_cancel(msg, hdr); |
| 9566 | nlmsg_free(msg); |
| 9567 | |
| 9568 | } |
| 9569 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9570 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9571 | struct net_device *netdev, const u8 *bssid, |
| 9572 | gfp_t gfp) |
| 9573 | { |
| 9574 | struct sk_buff *msg; |
| 9575 | void *hdr; |
| 9576 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9577 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9578 | if (!msg) |
| 9579 | return; |
| 9580 | |
| 9581 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9582 | if (!hdr) { |
| 9583 | nlmsg_free(msg); |
| 9584 | return; |
| 9585 | } |
| 9586 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9587 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9588 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9589 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9590 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9591 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9592 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9593 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9594 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9595 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9596 | return; |
| 9597 | |
| 9598 | nla_put_failure: |
| 9599 | genlmsg_cancel(msg, hdr); |
| 9600 | nlmsg_free(msg); |
| 9601 | } |
| 9602 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9603 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9604 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9605 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9606 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9607 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9608 | struct sk_buff *msg; |
| 9609 | void *hdr; |
| 9610 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9611 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9612 | return; |
| 9613 | |
| 9614 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9615 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9617 | if (!msg) |
| 9618 | return; |
| 9619 | |
| 9620 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9621 | if (!hdr) { |
| 9622 | nlmsg_free(msg); |
| 9623 | return; |
| 9624 | } |
| 9625 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9626 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9627 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9628 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9629 | (ie_len && ie && |
| 9630 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9631 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9632 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9633 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9634 | |
| 9635 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9636 | nl80211_mlme_mcgrp.id, gfp); |
| 9637 | return; |
| 9638 | |
| 9639 | nla_put_failure: |
| 9640 | genlmsg_cancel(msg, hdr); |
| 9641 | nlmsg_free(msg); |
| 9642 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9643 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9644 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9645 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9646 | struct net_device *netdev, const u8 *addr, |
| 9647 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9648 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9649 | { |
| 9650 | struct sk_buff *msg; |
| 9651 | void *hdr; |
| 9652 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9653 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9654 | if (!msg) |
| 9655 | return; |
| 9656 | |
| 9657 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9658 | if (!hdr) { |
| 9659 | nlmsg_free(msg); |
| 9660 | return; |
| 9661 | } |
| 9662 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9663 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9664 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9665 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9666 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9667 | (key_id != -1 && |
| 9668 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9669 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9670 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9671 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9672 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9673 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9674 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9675 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9676 | return; |
| 9677 | |
| 9678 | nla_put_failure: |
| 9679 | genlmsg_cancel(msg, hdr); |
| 9680 | nlmsg_free(msg); |
| 9681 | } |
| 9682 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9683 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9684 | struct ieee80211_channel *channel_before, |
| 9685 | struct ieee80211_channel *channel_after) |
| 9686 | { |
| 9687 | struct sk_buff *msg; |
| 9688 | void *hdr; |
| 9689 | struct nlattr *nl_freq; |
| 9690 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9691 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9692 | if (!msg) |
| 9693 | return; |
| 9694 | |
| 9695 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9696 | if (!hdr) { |
| 9697 | nlmsg_free(msg); |
| 9698 | return; |
| 9699 | } |
| 9700 | |
| 9701 | /* |
| 9702 | * Since we are applying the beacon hint to a wiphy we know its |
| 9703 | * wiphy_idx is valid |
| 9704 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9706 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9707 | |
| 9708 | /* Before */ |
| 9709 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9710 | if (!nl_freq) |
| 9711 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9712 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9713 | goto nla_put_failure; |
| 9714 | nla_nest_end(msg, nl_freq); |
| 9715 | |
| 9716 | /* After */ |
| 9717 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9718 | if (!nl_freq) |
| 9719 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9720 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9721 | goto nla_put_failure; |
| 9722 | nla_nest_end(msg, nl_freq); |
| 9723 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9724 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9725 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9726 | rcu_read_lock(); |
| 9727 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9728 | GFP_ATOMIC); |
| 9729 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9730 | |
| 9731 | return; |
| 9732 | |
| 9733 | nla_put_failure: |
| 9734 | genlmsg_cancel(msg, hdr); |
| 9735 | nlmsg_free(msg); |
| 9736 | } |
| 9737 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9738 | static void nl80211_send_remain_on_chan_event( |
| 9739 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9740 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9741 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9742 | unsigned int duration, gfp_t gfp) |
| 9743 | { |
| 9744 | struct sk_buff *msg; |
| 9745 | void *hdr; |
| 9746 | |
| 9747 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9748 | if (!msg) |
| 9749 | return; |
| 9750 | |
| 9751 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9752 | if (!hdr) { |
| 9753 | nlmsg_free(msg); |
| 9754 | return; |
| 9755 | } |
| 9756 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9757 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9758 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9759 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9760 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9761 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9762 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9763 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9764 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9765 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9766 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9767 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9768 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9769 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9770 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9771 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9772 | |
| 9773 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9774 | nl80211_mlme_mcgrp.id, gfp); |
| 9775 | return; |
| 9776 | |
| 9777 | nla_put_failure: |
| 9778 | genlmsg_cancel(msg, hdr); |
| 9779 | nlmsg_free(msg); |
| 9780 | } |
| 9781 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9782 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9783 | struct ieee80211_channel *chan, |
| 9784 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9785 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9786 | struct wiphy *wiphy = wdev->wiphy; |
| 9787 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9788 | |
| 9789 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9790 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9791 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9792 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9793 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9794 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9795 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9796 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9797 | struct ieee80211_channel *chan, |
| 9798 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9799 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9800 | struct wiphy *wiphy = wdev->wiphy; |
| 9801 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9802 | |
| 9803 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9804 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9805 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9806 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9807 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9808 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9809 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9810 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9811 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9812 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9813 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9814 | struct sk_buff *msg; |
| 9815 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9816 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9817 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9819 | if (!msg) |
| 9820 | return; |
| 9821 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9822 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9823 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9824 | nlmsg_free(msg); |
| 9825 | return; |
| 9826 | } |
| 9827 | |
| 9828 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9829 | nl80211_mlme_mcgrp.id, gfp); |
| 9830 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9831 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9832 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9833 | 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] | 9834 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9835 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9836 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9837 | struct sk_buff *msg; |
| 9838 | void *hdr; |
| 9839 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9840 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9841 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9842 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9843 | if (!msg) |
| 9844 | return; |
| 9845 | |
| 9846 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9847 | if (!hdr) { |
| 9848 | nlmsg_free(msg); |
| 9849 | return; |
| 9850 | } |
| 9851 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9852 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9853 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9854 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9855 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9856 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9857 | |
| 9858 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9859 | nl80211_mlme_mcgrp.id, gfp); |
| 9860 | return; |
| 9861 | |
| 9862 | nla_put_failure: |
| 9863 | genlmsg_cancel(msg, hdr); |
| 9864 | nlmsg_free(msg); |
| 9865 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9866 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9867 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9868 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9869 | enum nl80211_connect_failed_reason reason, |
| 9870 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9871 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9872 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9873 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9874 | struct sk_buff *msg; |
| 9875 | void *hdr; |
| 9876 | |
| 9877 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9878 | if (!msg) |
| 9879 | return; |
| 9880 | |
| 9881 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9882 | if (!hdr) { |
| 9883 | nlmsg_free(msg); |
| 9884 | return; |
| 9885 | } |
| 9886 | |
| 9887 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9888 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9889 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9890 | goto nla_put_failure; |
| 9891 | |
| 9892 | genlmsg_end(msg, hdr); |
| 9893 | |
| 9894 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9895 | nl80211_mlme_mcgrp.id, gfp); |
| 9896 | return; |
| 9897 | |
| 9898 | nla_put_failure: |
| 9899 | genlmsg_cancel(msg, hdr); |
| 9900 | nlmsg_free(msg); |
| 9901 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9902 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9903 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9904 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9905 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9906 | { |
| 9907 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9908 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9909 | struct sk_buff *msg; |
| 9910 | void *hdr; |
| 9911 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9912 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9913 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9914 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9915 | return false; |
| 9916 | |
| 9917 | msg = nlmsg_new(100, gfp); |
| 9918 | if (!msg) |
| 9919 | return true; |
| 9920 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9921 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9922 | if (!hdr) { |
| 9923 | nlmsg_free(msg); |
| 9924 | return true; |
| 9925 | } |
| 9926 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9927 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9928 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9929 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9930 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9931 | |
| 9932 | err = genlmsg_end(msg, hdr); |
| 9933 | if (err < 0) { |
| 9934 | nlmsg_free(msg); |
| 9935 | return true; |
| 9936 | } |
| 9937 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9938 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9939 | return true; |
| 9940 | |
| 9941 | nla_put_failure: |
| 9942 | genlmsg_cancel(msg, hdr); |
| 9943 | nlmsg_free(msg); |
| 9944 | return true; |
| 9945 | } |
| 9946 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9947 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9948 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9949 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9950 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9951 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9952 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9953 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9954 | |
| 9955 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9956 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9957 | trace_cfg80211_return_bool(false); |
| 9958 | return false; |
| 9959 | } |
| 9960 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9961 | addr, gfp); |
| 9962 | trace_cfg80211_return_bool(ret); |
| 9963 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9964 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9965 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9966 | |
| 9967 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9968 | const u8 *addr, gfp_t gfp) |
| 9969 | { |
| 9970 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9971 | bool ret; |
| 9972 | |
| 9973 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9974 | |
| 9975 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9976 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9977 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9978 | trace_cfg80211_return_bool(false); |
| 9979 | return false; |
| 9980 | } |
| 9981 | ret = __nl80211_unexpected_frame(dev, |
| 9982 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9983 | addr, gfp); |
| 9984 | trace_cfg80211_return_bool(ret); |
| 9985 | return ret; |
| 9986 | } |
| 9987 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9988 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9989 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9990 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9991 | int freq, int sig_dbm, |
| 9992 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9993 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9994 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9995 | struct sk_buff *msg; |
| 9996 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9997 | |
| 9998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9999 | if (!msg) |
| 10000 | return -ENOMEM; |
| 10001 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10002 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10003 | if (!hdr) { |
| 10004 | nlmsg_free(msg); |
| 10005 | return -ENOMEM; |
| 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) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10009 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10010 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10011 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10012 | (sig_dbm && |
| 10013 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10014 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10015 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10016 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10017 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10018 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10019 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10020 | |
| 10021 | nla_put_failure: |
| 10022 | genlmsg_cancel(msg, hdr); |
| 10023 | nlmsg_free(msg); |
| 10024 | return -ENOBUFS; |
| 10025 | } |
| 10026 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10027 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10028 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10029 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10030 | struct wiphy *wiphy = wdev->wiphy; |
| 10031 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10032 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10033 | struct sk_buff *msg; |
| 10034 | void *hdr; |
| 10035 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10036 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10037 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10039 | if (!msg) |
| 10040 | return; |
| 10041 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 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) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10049 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10050 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10051 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10052 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10053 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10054 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10055 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10056 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10057 | |
| 10058 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 10059 | return; |
| 10060 | |
| 10061 | nla_put_failure: |
| 10062 | genlmsg_cancel(msg, hdr); |
| 10063 | nlmsg_free(msg); |
| 10064 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10065 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10066 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10067 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10068 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10069 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10070 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10071 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10072 | struct wiphy *wiphy = wdev->wiphy; |
| 10073 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10074 | struct sk_buff *msg; |
| 10075 | struct nlattr *pinfoattr; |
| 10076 | void *hdr; |
| 10077 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10078 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10079 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10081 | if (!msg) |
| 10082 | return; |
| 10083 | |
| 10084 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10085 | if (!hdr) { |
| 10086 | nlmsg_free(msg); |
| 10087 | return; |
| 10088 | } |
| 10089 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10091 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10092 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10093 | |
| 10094 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10095 | if (!pinfoattr) |
| 10096 | goto nla_put_failure; |
| 10097 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10098 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10099 | rssi_event)) |
| 10100 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10101 | |
| 10102 | nla_nest_end(msg, pinfoattr); |
| 10103 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10104 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10105 | |
| 10106 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10107 | nl80211_mlme_mcgrp.id, gfp); |
| 10108 | return; |
| 10109 | |
| 10110 | nla_put_failure: |
| 10111 | genlmsg_cancel(msg, hdr); |
| 10112 | nlmsg_free(msg); |
| 10113 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10114 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10115 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10116 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10117 | struct net_device *netdev, const u8 *bssid, |
| 10118 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10119 | { |
| 10120 | struct sk_buff *msg; |
| 10121 | struct nlattr *rekey_attr; |
| 10122 | void *hdr; |
| 10123 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10124 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10125 | if (!msg) |
| 10126 | return; |
| 10127 | |
| 10128 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10129 | if (!hdr) { |
| 10130 | nlmsg_free(msg); |
| 10131 | return; |
| 10132 | } |
| 10133 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10134 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10135 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10136 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10137 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10138 | |
| 10139 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10140 | if (!rekey_attr) |
| 10141 | goto nla_put_failure; |
| 10142 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10143 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10144 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10145 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10146 | |
| 10147 | nla_nest_end(msg, rekey_attr); |
| 10148 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10149 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10150 | |
| 10151 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10152 | nl80211_mlme_mcgrp.id, gfp); |
| 10153 | return; |
| 10154 | |
| 10155 | nla_put_failure: |
| 10156 | genlmsg_cancel(msg, hdr); |
| 10157 | nlmsg_free(msg); |
| 10158 | } |
| 10159 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10160 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10161 | const u8 *replay_ctr, gfp_t gfp) |
| 10162 | { |
| 10163 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10164 | struct wiphy *wiphy = wdev->wiphy; |
| 10165 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10166 | |
| 10167 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10168 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10169 | } |
| 10170 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10171 | |
| 10172 | static void |
| 10173 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10174 | struct net_device *netdev, int index, |
| 10175 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10176 | { |
| 10177 | struct sk_buff *msg; |
| 10178 | struct nlattr *attr; |
| 10179 | void *hdr; |
| 10180 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10181 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10182 | if (!msg) |
| 10183 | return; |
| 10184 | |
| 10185 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10186 | if (!hdr) { |
| 10187 | nlmsg_free(msg); |
| 10188 | return; |
| 10189 | } |
| 10190 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10191 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10192 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10193 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10194 | |
| 10195 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10196 | if (!attr) |
| 10197 | goto nla_put_failure; |
| 10198 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10199 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10200 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10201 | (preauth && |
| 10202 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10203 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10204 | |
| 10205 | nla_nest_end(msg, attr); |
| 10206 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10207 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10208 | |
| 10209 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10210 | nl80211_mlme_mcgrp.id, gfp); |
| 10211 | return; |
| 10212 | |
| 10213 | nla_put_failure: |
| 10214 | genlmsg_cancel(msg, hdr); |
| 10215 | nlmsg_free(msg); |
| 10216 | } |
| 10217 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10218 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10219 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10220 | { |
| 10221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10222 | struct wiphy *wiphy = wdev->wiphy; |
| 10223 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10224 | |
| 10225 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10226 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10227 | } |
| 10228 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10229 | |
| 10230 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10231 | struct net_device *netdev, |
| 10232 | struct cfg80211_chan_def *chandef, |
| 10233 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10234 | { |
| 10235 | struct sk_buff *msg; |
| 10236 | void *hdr; |
| 10237 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10238 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10239 | if (!msg) |
| 10240 | return; |
| 10241 | |
| 10242 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10243 | if (!hdr) { |
| 10244 | nlmsg_free(msg); |
| 10245 | return; |
| 10246 | } |
| 10247 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10248 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10249 | goto nla_put_failure; |
| 10250 | |
| 10251 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10252 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10253 | |
| 10254 | genlmsg_end(msg, hdr); |
| 10255 | |
| 10256 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10257 | nl80211_mlme_mcgrp.id, gfp); |
| 10258 | return; |
| 10259 | |
| 10260 | nla_put_failure: |
| 10261 | genlmsg_cancel(msg, hdr); |
| 10262 | nlmsg_free(msg); |
| 10263 | } |
| 10264 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10265 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10266 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10267 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10268 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10269 | struct wiphy *wiphy = wdev->wiphy; |
| 10270 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10271 | |
| 10272 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10273 | |
| 10274 | wdev_lock(wdev); |
| 10275 | |
| 10276 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10277 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10278 | goto out; |
| 10279 | |
| 10280 | wdev->channel = chandef->chan; |
| 10281 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10282 | out: |
| 10283 | wdev_unlock(wdev); |
| 10284 | return; |
| 10285 | } |
| 10286 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10287 | |
| 10288 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10289 | const u8 *peer, u32 num_packets, |
| 10290 | u32 rate, u32 intvl, gfp_t gfp) |
| 10291 | { |
| 10292 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10293 | struct wiphy *wiphy = wdev->wiphy; |
| 10294 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10295 | struct sk_buff *msg; |
| 10296 | struct nlattr *pinfoattr; |
| 10297 | void *hdr; |
| 10298 | |
| 10299 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10300 | if (!msg) |
| 10301 | return; |
| 10302 | |
| 10303 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10304 | if (!hdr) { |
| 10305 | nlmsg_free(msg); |
| 10306 | return; |
| 10307 | } |
| 10308 | |
| 10309 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10310 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10311 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10312 | goto nla_put_failure; |
| 10313 | |
| 10314 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10315 | if (!pinfoattr) |
| 10316 | goto nla_put_failure; |
| 10317 | |
| 10318 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10319 | goto nla_put_failure; |
| 10320 | |
| 10321 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10322 | goto nla_put_failure; |
| 10323 | |
| 10324 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10325 | goto nla_put_failure; |
| 10326 | |
| 10327 | nla_nest_end(msg, pinfoattr); |
| 10328 | |
| 10329 | genlmsg_end(msg, hdr); |
| 10330 | |
| 10331 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10332 | nl80211_mlme_mcgrp.id, gfp); |
| 10333 | return; |
| 10334 | |
| 10335 | nla_put_failure: |
| 10336 | genlmsg_cancel(msg, hdr); |
| 10337 | nlmsg_free(msg); |
| 10338 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10339 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10340 | |
| 10341 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10342 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10343 | struct cfg80211_chan_def *chandef, |
| 10344 | enum nl80211_radar_event event, |
| 10345 | struct net_device *netdev, gfp_t gfp) |
| 10346 | { |
| 10347 | struct sk_buff *msg; |
| 10348 | void *hdr; |
| 10349 | |
| 10350 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10351 | if (!msg) |
| 10352 | return; |
| 10353 | |
| 10354 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10355 | if (!hdr) { |
| 10356 | nlmsg_free(msg); |
| 10357 | return; |
| 10358 | } |
| 10359 | |
| 10360 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10361 | goto nla_put_failure; |
| 10362 | |
| 10363 | /* NOP and radar events don't need a netdev parameter */ |
| 10364 | if (netdev) { |
| 10365 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10366 | |
| 10367 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10368 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10369 | goto nla_put_failure; |
| 10370 | } |
| 10371 | |
| 10372 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10373 | goto nla_put_failure; |
| 10374 | |
| 10375 | if (nl80211_send_chandef(msg, chandef)) |
| 10376 | goto nla_put_failure; |
| 10377 | |
| 10378 | if (genlmsg_end(msg, hdr) < 0) { |
| 10379 | nlmsg_free(msg); |
| 10380 | return; |
| 10381 | } |
| 10382 | |
| 10383 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10384 | nl80211_mlme_mcgrp.id, gfp); |
| 10385 | return; |
| 10386 | |
| 10387 | nla_put_failure: |
| 10388 | genlmsg_cancel(msg, hdr); |
| 10389 | nlmsg_free(msg); |
| 10390 | } |
| 10391 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10392 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10393 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10394 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10395 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10396 | struct wiphy *wiphy = wdev->wiphy; |
| 10397 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10398 | struct sk_buff *msg; |
| 10399 | struct nlattr *pinfoattr; |
| 10400 | void *hdr; |
| 10401 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10402 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10403 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10405 | if (!msg) |
| 10406 | return; |
| 10407 | |
| 10408 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10409 | if (!hdr) { |
| 10410 | nlmsg_free(msg); |
| 10411 | return; |
| 10412 | } |
| 10413 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10415 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10416 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10417 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10418 | |
| 10419 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10420 | if (!pinfoattr) |
| 10421 | goto nla_put_failure; |
| 10422 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10423 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10424 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10425 | |
| 10426 | nla_nest_end(msg, pinfoattr); |
| 10427 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10428 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10429 | |
| 10430 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10431 | nl80211_mlme_mcgrp.id, gfp); |
| 10432 | return; |
| 10433 | |
| 10434 | nla_put_failure: |
| 10435 | genlmsg_cancel(msg, hdr); |
| 10436 | nlmsg_free(msg); |
| 10437 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10438 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10439 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10440 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10441 | u64 cookie, bool acked, gfp_t gfp) |
| 10442 | { |
| 10443 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10444 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10445 | struct sk_buff *msg; |
| 10446 | void *hdr; |
| 10447 | int err; |
| 10448 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10449 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10450 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10452 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10453 | if (!msg) |
| 10454 | return; |
| 10455 | |
| 10456 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10457 | if (!hdr) { |
| 10458 | nlmsg_free(msg); |
| 10459 | return; |
| 10460 | } |
| 10461 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10462 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10463 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10465 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10466 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10467 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10468 | |
| 10469 | err = genlmsg_end(msg, hdr); |
| 10470 | if (err < 0) { |
| 10471 | nlmsg_free(msg); |
| 10472 | return; |
| 10473 | } |
| 10474 | |
| 10475 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10476 | nl80211_mlme_mcgrp.id, gfp); |
| 10477 | return; |
| 10478 | |
| 10479 | nla_put_failure: |
| 10480 | genlmsg_cancel(msg, hdr); |
| 10481 | nlmsg_free(msg); |
| 10482 | } |
| 10483 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10484 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10485 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10486 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10487 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10488 | { |
| 10489 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10490 | struct sk_buff *msg; |
| 10491 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10492 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10493 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10494 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10495 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10496 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10497 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10498 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10499 | if (!msg) { |
| 10500 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10501 | return; |
| 10502 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10503 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10504 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10505 | if (!hdr) |
| 10506 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10507 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10508 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10509 | (freq && |
| 10510 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10511 | (sig_dbm && |
| 10512 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10513 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10514 | goto nla_put_failure; |
| 10515 | |
| 10516 | genlmsg_end(msg, hdr); |
| 10517 | |
| 10518 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10519 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10520 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10521 | return; |
| 10522 | |
| 10523 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10524 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10525 | if (hdr) |
| 10526 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10527 | nlmsg_free(msg); |
| 10528 | } |
| 10529 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10530 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10531 | #ifdef CONFIG_PM |
| 10532 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10533 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10534 | gfp_t gfp) |
| 10535 | { |
| 10536 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10537 | struct sk_buff *msg; |
| 10538 | void *hdr; |
| 10539 | int err, size = 200; |
| 10540 | |
| 10541 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10542 | |
| 10543 | if (wakeup) |
| 10544 | size += wakeup->packet_present_len; |
| 10545 | |
| 10546 | msg = nlmsg_new(size, gfp); |
| 10547 | if (!msg) |
| 10548 | return; |
| 10549 | |
| 10550 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10551 | if (!hdr) |
| 10552 | goto free_msg; |
| 10553 | |
| 10554 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10555 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10556 | goto free_msg; |
| 10557 | |
| 10558 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10559 | wdev->netdev->ifindex)) |
| 10560 | goto free_msg; |
| 10561 | |
| 10562 | if (wakeup) { |
| 10563 | struct nlattr *reasons; |
| 10564 | |
| 10565 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10566 | |
| 10567 | if (wakeup->disconnect && |
| 10568 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10569 | goto free_msg; |
| 10570 | if (wakeup->magic_pkt && |
| 10571 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10572 | goto free_msg; |
| 10573 | if (wakeup->gtk_rekey_failure && |
| 10574 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10575 | goto free_msg; |
| 10576 | if (wakeup->eap_identity_req && |
| 10577 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10578 | goto free_msg; |
| 10579 | if (wakeup->four_way_handshake && |
| 10580 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10581 | goto free_msg; |
| 10582 | if (wakeup->rfkill_release && |
| 10583 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10584 | goto free_msg; |
| 10585 | |
| 10586 | if (wakeup->pattern_idx >= 0 && |
| 10587 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10588 | wakeup->pattern_idx)) |
| 10589 | goto free_msg; |
| 10590 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10591 | if (wakeup->tcp_match) |
| 10592 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10593 | |
| 10594 | if (wakeup->tcp_connlost) |
| 10595 | nla_put_flag(msg, |
| 10596 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10597 | |
| 10598 | if (wakeup->tcp_nomoretokens) |
| 10599 | nla_put_flag(msg, |
| 10600 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10601 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10602 | if (wakeup->packet) { |
| 10603 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10604 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10605 | |
| 10606 | if (!wakeup->packet_80211) { |
| 10607 | pkt_attr = |
| 10608 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10609 | len_attr = |
| 10610 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10611 | } |
| 10612 | |
| 10613 | if (wakeup->packet_len && |
| 10614 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10615 | goto free_msg; |
| 10616 | |
| 10617 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10618 | wakeup->packet)) |
| 10619 | goto free_msg; |
| 10620 | } |
| 10621 | |
| 10622 | nla_nest_end(msg, reasons); |
| 10623 | } |
| 10624 | |
| 10625 | err = genlmsg_end(msg, hdr); |
| 10626 | if (err < 0) |
| 10627 | goto free_msg; |
| 10628 | |
| 10629 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10630 | nl80211_mlme_mcgrp.id, gfp); |
| 10631 | return; |
| 10632 | |
| 10633 | free_msg: |
| 10634 | nlmsg_free(msg); |
| 10635 | } |
| 10636 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10637 | #endif |
| 10638 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10639 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10640 | enum nl80211_tdls_operation oper, |
| 10641 | u16 reason_code, gfp_t gfp) |
| 10642 | { |
| 10643 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10644 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10645 | struct sk_buff *msg; |
| 10646 | void *hdr; |
| 10647 | int err; |
| 10648 | |
| 10649 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10650 | reason_code); |
| 10651 | |
| 10652 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10653 | if (!msg) |
| 10654 | return; |
| 10655 | |
| 10656 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10657 | if (!hdr) { |
| 10658 | nlmsg_free(msg); |
| 10659 | return; |
| 10660 | } |
| 10661 | |
| 10662 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10663 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10664 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10665 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10666 | (reason_code > 0 && |
| 10667 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10668 | goto nla_put_failure; |
| 10669 | |
| 10670 | err = genlmsg_end(msg, hdr); |
| 10671 | if (err < 0) { |
| 10672 | nlmsg_free(msg); |
| 10673 | return; |
| 10674 | } |
| 10675 | |
| 10676 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10677 | nl80211_mlme_mcgrp.id, gfp); |
| 10678 | return; |
| 10679 | |
| 10680 | nla_put_failure: |
| 10681 | genlmsg_cancel(msg, hdr); |
| 10682 | nlmsg_free(msg); |
| 10683 | } |
| 10684 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10685 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10686 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10687 | unsigned long state, |
| 10688 | void *_notify) |
| 10689 | { |
| 10690 | struct netlink_notify *notify = _notify; |
| 10691 | struct cfg80211_registered_device *rdev; |
| 10692 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10693 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10694 | |
| 10695 | if (state != NETLINK_URELEASE) |
| 10696 | return NOTIFY_DONE; |
| 10697 | |
| 10698 | rcu_read_lock(); |
| 10699 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10700 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10701 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10702 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10703 | |
| 10704 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10705 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10706 | list) { |
| 10707 | if (reg->nlportid == notify->portid) { |
| 10708 | list_del(®->list); |
| 10709 | kfree(reg); |
| 10710 | break; |
| 10711 | } |
| 10712 | } |
| 10713 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10714 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10715 | |
| 10716 | rcu_read_unlock(); |
| 10717 | |
| 10718 | return NOTIFY_DONE; |
| 10719 | } |
| 10720 | |
| 10721 | static struct notifier_block nl80211_netlink_notifier = { |
| 10722 | .notifier_call = nl80211_netlink_notify, |
| 10723 | }; |
| 10724 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10725 | void cfg80211_ft_event(struct net_device *netdev, |
| 10726 | struct cfg80211_ft_event_params *ft_event) |
| 10727 | { |
| 10728 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10729 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10730 | struct sk_buff *msg; |
| 10731 | void *hdr; |
| 10732 | int err; |
| 10733 | |
| 10734 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10735 | |
| 10736 | if (!ft_event->target_ap) |
| 10737 | return; |
| 10738 | |
| 10739 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10740 | if (!msg) |
| 10741 | return; |
| 10742 | |
| 10743 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10744 | if (!hdr) { |
| 10745 | nlmsg_free(msg); |
| 10746 | return; |
| 10747 | } |
| 10748 | |
| 10749 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10750 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10751 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10752 | if (ft_event->ies) |
| 10753 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10754 | if (ft_event->ric_ies) |
| 10755 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10756 | ft_event->ric_ies); |
| 10757 | |
| 10758 | err = genlmsg_end(msg, hdr); |
| 10759 | if (err < 0) { |
| 10760 | nlmsg_free(msg); |
| 10761 | return; |
| 10762 | } |
| 10763 | |
| 10764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10765 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10766 | } |
| 10767 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10768 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10769 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 10770 | { |
| 10771 | struct cfg80211_registered_device *rdev; |
| 10772 | struct sk_buff *msg; |
| 10773 | void *hdr; |
| 10774 | u32 nlportid; |
| 10775 | |
| 10776 | rdev = wiphy_to_dev(wdev->wiphy); |
| 10777 | if (!rdev->crit_proto_nlportid) |
| 10778 | return; |
| 10779 | |
| 10780 | nlportid = rdev->crit_proto_nlportid; |
| 10781 | rdev->crit_proto_nlportid = 0; |
| 10782 | |
| 10783 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10784 | if (!msg) |
| 10785 | return; |
| 10786 | |
| 10787 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 10788 | if (!hdr) |
| 10789 | goto nla_put_failure; |
| 10790 | |
| 10791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10792 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10793 | goto nla_put_failure; |
| 10794 | |
| 10795 | genlmsg_end(msg, hdr); |
| 10796 | |
| 10797 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 10798 | return; |
| 10799 | |
| 10800 | nla_put_failure: |
| 10801 | if (hdr) |
| 10802 | genlmsg_cancel(msg, hdr); |
| 10803 | nlmsg_free(msg); |
| 10804 | |
| 10805 | } |
| 10806 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 10807 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10808 | /* initialisation/exit functions */ |
| 10809 | |
| 10810 | int nl80211_init(void) |
| 10811 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10812 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10813 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10814 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10815 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10816 | if (err) |
| 10817 | return err; |
| 10818 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10819 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10820 | if (err) |
| 10821 | goto err_out; |
| 10822 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10823 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10824 | if (err) |
| 10825 | goto err_out; |
| 10826 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10827 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10828 | if (err) |
| 10829 | goto err_out; |
| 10830 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10831 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10832 | if (err) |
| 10833 | goto err_out; |
| 10834 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10835 | #ifdef CONFIG_NL80211_TESTMODE |
| 10836 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10837 | if (err) |
| 10838 | goto err_out; |
| 10839 | #endif |
| 10840 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10841 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10842 | if (err) |
| 10843 | goto err_out; |
| 10844 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10845 | return 0; |
| 10846 | err_out: |
| 10847 | genl_unregister_family(&nl80211_fam); |
| 10848 | return err; |
| 10849 | } |
| 10850 | |
| 10851 | void nl80211_exit(void) |
| 10852 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10853 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10854 | genl_unregister_family(&nl80211_fam); |
| 10855 | } |