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 | 36aedc90 | 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 | dc6382c | 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 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 450 | /* ifidx get helper */ |
| 451 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 452 | { |
| 453 | int res; |
| 454 | |
| 455 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 456 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 457 | nl80211_policy); |
| 458 | if (res) |
| 459 | return res; |
| 460 | |
| 461 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 462 | return -EINVAL; |
| 463 | |
| 464 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 465 | if (!res) |
| 466 | return -EINVAL; |
| 467 | return res; |
| 468 | } |
| 469 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 470 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 471 | struct netlink_callback *cb, |
| 472 | struct cfg80211_registered_device **rdev, |
| 473 | struct net_device **dev) |
| 474 | { |
| 475 | int ifidx = cb->args[0]; |
| 476 | int err; |
| 477 | |
| 478 | if (!ifidx) |
| 479 | ifidx = nl80211_get_ifidx(cb); |
| 480 | if (ifidx < 0) |
| 481 | return ifidx; |
| 482 | |
| 483 | cb->args[0] = ifidx; |
| 484 | |
| 485 | rtnl_lock(); |
| 486 | |
| 487 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 488 | if (!*dev) { |
| 489 | err = -ENODEV; |
| 490 | goto out_rtnl; |
| 491 | } |
| 492 | |
| 493 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 494 | if (IS_ERR(*rdev)) { |
| 495 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 496 | goto out_rtnl; |
| 497 | } |
| 498 | |
| 499 | return 0; |
| 500 | out_rtnl: |
| 501 | rtnl_unlock(); |
| 502 | return err; |
| 503 | } |
| 504 | |
| 505 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 506 | { |
| 507 | cfg80211_unlock_rdev(rdev); |
| 508 | rtnl_unlock(); |
| 509 | } |
| 510 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 511 | /* IE validation */ |
| 512 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 513 | { |
| 514 | const u8 *pos; |
| 515 | int len; |
| 516 | |
| 517 | if (!attr) |
| 518 | return true; |
| 519 | |
| 520 | pos = nla_data(attr); |
| 521 | len = nla_len(attr); |
| 522 | |
| 523 | while (len) { |
| 524 | u8 elemlen; |
| 525 | |
| 526 | if (len < 2) |
| 527 | return false; |
| 528 | len -= 2; |
| 529 | |
| 530 | elemlen = pos[1]; |
| 531 | if (elemlen > len) |
| 532 | return false; |
| 533 | |
| 534 | len -= elemlen; |
| 535 | pos += 2 + elemlen; |
| 536 | } |
| 537 | |
| 538 | return true; |
| 539 | } |
| 540 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 541 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 542 | 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] | 543 | int flags, u8 cmd) |
| 544 | { |
| 545 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 546 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 547 | } |
| 548 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 549 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 550 | struct ieee80211_channel *chan, |
| 551 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 552 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 553 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 554 | chan->center_freq)) |
| 555 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 556 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 557 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 559 | goto nla_put_failure; |
| 560 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 562 | goto nla_put_failure; |
| 563 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 565 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 566 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 567 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 568 | goto nla_put_failure; |
| 569 | if (large) { |
| 570 | u32 time; |
| 571 | |
| 572 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 573 | |
| 574 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 575 | chan->dfs_state)) |
| 576 | goto nla_put_failure; |
| 577 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 578 | time)) |
| 579 | goto nla_put_failure; |
| 580 | } |
| 581 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 582 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 583 | if (large) { |
| 584 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 585 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 586 | goto nla_put_failure; |
| 587 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 588 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 589 | goto nla_put_failure; |
| 590 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 591 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 592 | goto nla_put_failure; |
| 593 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 594 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 595 | goto nla_put_failure; |
| 596 | } |
| 597 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 598 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 599 | DBM_TO_MBM(chan->max_power))) |
| 600 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 601 | |
| 602 | return 0; |
| 603 | |
| 604 | nla_put_failure: |
| 605 | return -ENOBUFS; |
| 606 | } |
| 607 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 608 | /* netlink command implementations */ |
| 609 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 610 | struct key_parse { |
| 611 | struct key_params p; |
| 612 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 613 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 614 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 615 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 616 | }; |
| 617 | |
| 618 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 619 | { |
| 620 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 621 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 622 | nl80211_key_policy); |
| 623 | if (err) |
| 624 | return err; |
| 625 | |
| 626 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 627 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 628 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 629 | if (k->def) { |
| 630 | k->def_uni = true; |
| 631 | k->def_multi = true; |
| 632 | } |
| 633 | if (k->defmgmt) |
| 634 | k->def_multi = true; |
| 635 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 636 | if (tb[NL80211_KEY_IDX]) |
| 637 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 638 | |
| 639 | if (tb[NL80211_KEY_DATA]) { |
| 640 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 641 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 642 | } |
| 643 | |
| 644 | if (tb[NL80211_KEY_SEQ]) { |
| 645 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 646 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 647 | } |
| 648 | |
| 649 | if (tb[NL80211_KEY_CIPHER]) |
| 650 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 651 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 652 | if (tb[NL80211_KEY_TYPE]) { |
| 653 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 654 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 655 | return -EINVAL; |
| 656 | } |
| 657 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 658 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 659 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 660 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 661 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 662 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 663 | if (err) |
| 664 | return err; |
| 665 | |
| 666 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 667 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 668 | } |
| 669 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 674 | { |
| 675 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 676 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 677 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 678 | } |
| 679 | |
| 680 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 681 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 682 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 683 | } |
| 684 | |
| 685 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 686 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 687 | |
| 688 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 689 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 690 | |
| 691 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 692 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 693 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 694 | if (k->def) { |
| 695 | k->def_uni = true; |
| 696 | k->def_multi = true; |
| 697 | } |
| 698 | if (k->defmgmt) |
| 699 | k->def_multi = true; |
| 700 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 701 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 702 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 703 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 704 | return -EINVAL; |
| 705 | } |
| 706 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 707 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 708 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 709 | int err = nla_parse_nested( |
| 710 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 711 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 712 | nl80211_key_default_policy); |
| 713 | if (err) |
| 714 | return err; |
| 715 | |
| 716 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 717 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 718 | } |
| 719 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 724 | { |
| 725 | int err; |
| 726 | |
| 727 | memset(k, 0, sizeof(*k)); |
| 728 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 729 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 730 | |
| 731 | if (info->attrs[NL80211_ATTR_KEY]) |
| 732 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 733 | else |
| 734 | err = nl80211_parse_key_old(info, k); |
| 735 | |
| 736 | if (err) |
| 737 | return err; |
| 738 | |
| 739 | if (k->def && k->defmgmt) |
| 740 | return -EINVAL; |
| 741 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 742 | if (k->defmgmt) { |
| 743 | if (k->def_uni || !k->def_multi) |
| 744 | return -EINVAL; |
| 745 | } |
| 746 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 747 | if (k->idx != -1) { |
| 748 | if (k->defmgmt) { |
| 749 | if (k->idx < 4 || k->idx > 5) |
| 750 | return -EINVAL; |
| 751 | } else if (k->def) { |
| 752 | if (k->idx < 0 || k->idx > 3) |
| 753 | return -EINVAL; |
| 754 | } else { |
| 755 | if (k->idx < 0 || k->idx > 5) |
| 756 | return -EINVAL; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 763 | static struct cfg80211_cached_keys * |
| 764 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 765 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 766 | { |
| 767 | struct key_parse parse; |
| 768 | struct nlattr *key; |
| 769 | struct cfg80211_cached_keys *result; |
| 770 | int rem, err, def = 0; |
| 771 | |
| 772 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 773 | if (!result) |
| 774 | return ERR_PTR(-ENOMEM); |
| 775 | |
| 776 | result->def = -1; |
| 777 | result->defmgmt = -1; |
| 778 | |
| 779 | nla_for_each_nested(key, keys, rem) { |
| 780 | memset(&parse, 0, sizeof(parse)); |
| 781 | parse.idx = -1; |
| 782 | |
| 783 | err = nl80211_parse_key_new(key, &parse); |
| 784 | if (err) |
| 785 | goto error; |
| 786 | err = -EINVAL; |
| 787 | if (!parse.p.key) |
| 788 | goto error; |
| 789 | if (parse.idx < 0 || parse.idx > 4) |
| 790 | goto error; |
| 791 | if (parse.def) { |
| 792 | if (def) |
| 793 | goto error; |
| 794 | def = 1; |
| 795 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 796 | if (!parse.def_uni || !parse.def_multi) |
| 797 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 798 | } else if (parse.defmgmt) |
| 799 | goto error; |
| 800 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 801 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 802 | if (err) |
| 803 | goto error; |
| 804 | result->params[parse.idx].cipher = parse.p.cipher; |
| 805 | result->params[parse.idx].key_len = parse.p.key_len; |
| 806 | result->params[parse.idx].key = result->data[parse.idx]; |
| 807 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 808 | |
| 809 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 810 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 811 | if (no_ht) |
| 812 | *no_ht = true; |
| 813 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | return result; |
| 817 | error: |
| 818 | kfree(result); |
| 819 | return ERR_PTR(err); |
| 820 | } |
| 821 | |
| 822 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 823 | { |
| 824 | ASSERT_WDEV_LOCK(wdev); |
| 825 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 826 | switch (wdev->iftype) { |
| 827 | case NL80211_IFTYPE_AP: |
| 828 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 829 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 830 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 831 | break; |
| 832 | case NL80211_IFTYPE_ADHOC: |
| 833 | if (!wdev->current_bss) |
| 834 | return -ENOLINK; |
| 835 | break; |
| 836 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 837 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 838 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 839 | return -ENOLINK; |
| 840 | break; |
| 841 | default: |
| 842 | return -EINVAL; |
| 843 | } |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 848 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 849 | { |
| 850 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 851 | int i; |
| 852 | |
| 853 | if (!nl_modes) |
| 854 | goto nla_put_failure; |
| 855 | |
| 856 | i = 0; |
| 857 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 858 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 859 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 860 | ifmodes >>= 1; |
| 861 | i++; |
| 862 | } |
| 863 | |
| 864 | nla_nest_end(msg, nl_modes); |
| 865 | return 0; |
| 866 | |
| 867 | nla_put_failure: |
| 868 | return -ENOBUFS; |
| 869 | } |
| 870 | |
| 871 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 872 | struct sk_buff *msg, |
| 873 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 874 | { |
| 875 | struct nlattr *nl_combis; |
| 876 | int i, j; |
| 877 | |
| 878 | nl_combis = nla_nest_start(msg, |
| 879 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 880 | if (!nl_combis) |
| 881 | goto nla_put_failure; |
| 882 | |
| 883 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 884 | const struct ieee80211_iface_combination *c; |
| 885 | struct nlattr *nl_combi, *nl_limits; |
| 886 | |
| 887 | c = &wiphy->iface_combinations[i]; |
| 888 | |
| 889 | nl_combi = nla_nest_start(msg, i + 1); |
| 890 | if (!nl_combi) |
| 891 | goto nla_put_failure; |
| 892 | |
| 893 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 894 | if (!nl_limits) |
| 895 | goto nla_put_failure; |
| 896 | |
| 897 | for (j = 0; j < c->n_limits; j++) { |
| 898 | struct nlattr *nl_limit; |
| 899 | |
| 900 | nl_limit = nla_nest_start(msg, j + 1); |
| 901 | if (!nl_limit) |
| 902 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 903 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 904 | c->limits[j].max)) |
| 905 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 906 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 907 | c->limits[j].types)) |
| 908 | goto nla_put_failure; |
| 909 | nla_nest_end(msg, nl_limit); |
| 910 | } |
| 911 | |
| 912 | nla_nest_end(msg, nl_limits); |
| 913 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 914 | if (c->beacon_int_infra_match && |
| 915 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 916 | goto nla_put_failure; |
| 917 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 918 | c->num_different_channels) || |
| 919 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 920 | c->max_interfaces)) |
| 921 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 922 | if (large && |
| 923 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 924 | c->radar_detect_widths)) |
| 925 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 926 | |
| 927 | nla_nest_end(msg, nl_combi); |
| 928 | } |
| 929 | |
| 930 | nla_nest_end(msg, nl_combis); |
| 931 | |
| 932 | return 0; |
| 933 | nla_put_failure: |
| 934 | return -ENOBUFS; |
| 935 | } |
| 936 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 937 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 938 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 939 | struct sk_buff *msg) |
| 940 | { |
| 941 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 942 | struct nlattr *nl_tcp; |
| 943 | |
| 944 | if (!tcp) |
| 945 | return 0; |
| 946 | |
| 947 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 948 | if (!nl_tcp) |
| 949 | return -ENOBUFS; |
| 950 | |
| 951 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 952 | tcp->data_payload_max)) |
| 953 | return -ENOBUFS; |
| 954 | |
| 955 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 956 | tcp->data_payload_max)) |
| 957 | return -ENOBUFS; |
| 958 | |
| 959 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 960 | return -ENOBUFS; |
| 961 | |
| 962 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 963 | sizeof(*tcp->tok), tcp->tok)) |
| 964 | return -ENOBUFS; |
| 965 | |
| 966 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 967 | tcp->data_interval_max)) |
| 968 | return -ENOBUFS; |
| 969 | |
| 970 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 971 | tcp->wake_payload_max)) |
| 972 | return -ENOBUFS; |
| 973 | |
| 974 | nla_nest_end(msg, nl_tcp); |
| 975 | return 0; |
| 976 | } |
| 977 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 978 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 979 | struct cfg80211_registered_device *dev, |
| 980 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 981 | { |
| 982 | struct nlattr *nl_wowlan; |
| 983 | |
| 984 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
| 985 | return 0; |
| 986 | |
| 987 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 988 | if (!nl_wowlan) |
| 989 | return -ENOBUFS; |
| 990 | |
| 991 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 992 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 993 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 994 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 995 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 996 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 997 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 998 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 999 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1000 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1001 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1003 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1005 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1007 | return -ENOBUFS; |
| 1008 | |
| 1009 | if (dev->wiphy.wowlan.n_patterns) { |
| 1010 | struct nl80211_wowlan_pattern_support pat = { |
| 1011 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1012 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, |
| 1013 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, |
| 1014 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, |
| 1015 | }; |
| 1016 | |
| 1017 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1018 | sizeof(pat), &pat)) |
| 1019 | return -ENOBUFS; |
| 1020 | } |
| 1021 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1022 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1023 | return -ENOBUFS; |
| 1024 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1025 | nla_nest_end(msg, nl_wowlan); |
| 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | #endif |
| 1030 | |
| 1031 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1032 | struct ieee80211_supported_band *sband) |
| 1033 | { |
| 1034 | struct nlattr *nl_rates, *nl_rate; |
| 1035 | struct ieee80211_rate *rate; |
| 1036 | int i; |
| 1037 | |
| 1038 | /* add HT info */ |
| 1039 | if (sband->ht_cap.ht_supported && |
| 1040 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1041 | sizeof(sband->ht_cap.mcs), |
| 1042 | &sband->ht_cap.mcs) || |
| 1043 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1044 | sband->ht_cap.cap) || |
| 1045 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1046 | sband->ht_cap.ampdu_factor) || |
| 1047 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1048 | sband->ht_cap.ampdu_density))) |
| 1049 | return -ENOBUFS; |
| 1050 | |
| 1051 | /* add VHT info */ |
| 1052 | if (sband->vht_cap.vht_supported && |
| 1053 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1054 | sizeof(sband->vht_cap.vht_mcs), |
| 1055 | &sband->vht_cap.vht_mcs) || |
| 1056 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1057 | sband->vht_cap.cap))) |
| 1058 | return -ENOBUFS; |
| 1059 | |
| 1060 | /* add bitrates */ |
| 1061 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1062 | if (!nl_rates) |
| 1063 | return -ENOBUFS; |
| 1064 | |
| 1065 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1066 | nl_rate = nla_nest_start(msg, i); |
| 1067 | if (!nl_rate) |
| 1068 | return -ENOBUFS; |
| 1069 | |
| 1070 | rate = &sband->bitrates[i]; |
| 1071 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1072 | rate->bitrate)) |
| 1073 | return -ENOBUFS; |
| 1074 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1075 | nla_put_flag(msg, |
| 1076 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1077 | return -ENOBUFS; |
| 1078 | |
| 1079 | nla_nest_end(msg, nl_rate); |
| 1080 | } |
| 1081 | |
| 1082 | nla_nest_end(msg, nl_rates); |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | static int |
| 1088 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1089 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1090 | { |
| 1091 | u16 stypes; |
| 1092 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1093 | enum nl80211_iftype ift; |
| 1094 | int i; |
| 1095 | |
| 1096 | if (!mgmt_stypes) |
| 1097 | return 0; |
| 1098 | |
| 1099 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1100 | if (!nl_ifs) |
| 1101 | return -ENOBUFS; |
| 1102 | |
| 1103 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1104 | nl_ftypes = nla_nest_start(msg, ift); |
| 1105 | if (!nl_ftypes) |
| 1106 | return -ENOBUFS; |
| 1107 | i = 0; |
| 1108 | stypes = mgmt_stypes[ift].tx; |
| 1109 | while (stypes) { |
| 1110 | if ((stypes & 1) && |
| 1111 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1112 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1113 | return -ENOBUFS; |
| 1114 | stypes >>= 1; |
| 1115 | i++; |
| 1116 | } |
| 1117 | nla_nest_end(msg, nl_ftypes); |
| 1118 | } |
| 1119 | |
| 1120 | nla_nest_end(msg, nl_ifs); |
| 1121 | |
| 1122 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1123 | if (!nl_ifs) |
| 1124 | return -ENOBUFS; |
| 1125 | |
| 1126 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1127 | nl_ftypes = nla_nest_start(msg, ift); |
| 1128 | if (!nl_ftypes) |
| 1129 | return -ENOBUFS; |
| 1130 | i = 0; |
| 1131 | stypes = mgmt_stypes[ift].rx; |
| 1132 | while (stypes) { |
| 1133 | if ((stypes & 1) && |
| 1134 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1135 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1136 | return -ENOBUFS; |
| 1137 | stypes >>= 1; |
| 1138 | i++; |
| 1139 | } |
| 1140 | nla_nest_end(msg, nl_ftypes); |
| 1141 | } |
| 1142 | nla_nest_end(msg, nl_ifs); |
| 1143 | |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1148 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1149 | int flags, bool split, long *split_start, |
| 1150 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1151 | { |
| 1152 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1153 | struct nlattr *nl_bands, *nl_band; |
| 1154 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1155 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1156 | enum ieee80211_band band; |
| 1157 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1158 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1159 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1160 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1161 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1162 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1163 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1164 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1165 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1166 | return -ENOBUFS; |
| 1167 | |
| 1168 | /* allow always using the variables */ |
| 1169 | if (!split) { |
| 1170 | split_start = &start; |
| 1171 | band_start = &start_band; |
| 1172 | chan_start = &start_chan; |
| 1173 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1174 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1176 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1177 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1178 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1179 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1180 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1181 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1182 | switch (*split_start) { |
| 1183 | case 0: |
| 1184 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1185 | dev->wiphy.retry_short) || |
| 1186 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1187 | dev->wiphy.retry_long) || |
| 1188 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1189 | dev->wiphy.frag_threshold) || |
| 1190 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1191 | dev->wiphy.rts_threshold) || |
| 1192 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1193 | dev->wiphy.coverage_class) || |
| 1194 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1195 | dev->wiphy.max_scan_ssids) || |
| 1196 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1197 | dev->wiphy.max_sched_scan_ssids) || |
| 1198 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1199 | dev->wiphy.max_scan_ie_len) || |
| 1200 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1201 | dev->wiphy.max_sched_scan_ie_len) || |
| 1202 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1203 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1204 | goto nla_put_failure; |
| 1205 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1206 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1207 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1208 | goto nla_put_failure; |
| 1209 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1210 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1211 | goto nla_put_failure; |
| 1212 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1213 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1214 | goto nla_put_failure; |
| 1215 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1216 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1217 | goto nla_put_failure; |
| 1218 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1219 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1220 | goto nla_put_failure; |
| 1221 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1222 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1223 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1224 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1225 | (*split_start)++; |
| 1226 | if (split) |
| 1227 | break; |
| 1228 | case 1: |
| 1229 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1230 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1231 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1232 | goto nla_put_failure; |
| 1233 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1234 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1235 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1236 | goto nla_put_failure; |
| 1237 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1238 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1239 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1240 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1241 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1243 | dev->wiphy.available_antennas_tx) || |
| 1244 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1245 | dev->wiphy.available_antennas_rx)) |
| 1246 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1247 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1248 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1249 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1250 | dev->wiphy.probe_resp_offload)) |
| 1251 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1252 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | if ((dev->wiphy.available_antennas_tx || |
| 1254 | dev->wiphy.available_antennas_rx) && |
| 1255 | dev->ops->get_antenna) { |
| 1256 | u32 tx_ant = 0, rx_ant = 0; |
| 1257 | int res; |
| 1258 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1259 | if (!res) { |
| 1260 | if (nla_put_u32(msg, |
| 1261 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1262 | tx_ant) || |
| 1263 | nla_put_u32(msg, |
| 1264 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1265 | rx_ant)) |
| 1266 | goto nla_put_failure; |
| 1267 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | (*split_start)++; |
| 1271 | if (split) |
| 1272 | break; |
| 1273 | case 2: |
| 1274 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1275 | dev->wiphy.interface_modes)) |
| 1276 | goto nla_put_failure; |
| 1277 | (*split_start)++; |
| 1278 | if (split) |
| 1279 | break; |
| 1280 | case 3: |
| 1281 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1282 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1283 | goto nla_put_failure; |
| 1284 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
| 1286 | struct ieee80211_supported_band *sband; |
| 1287 | |
| 1288 | sband = dev->wiphy.bands[band]; |
| 1289 | |
| 1290 | if (!sband) |
| 1291 | continue; |
| 1292 | |
| 1293 | nl_band = nla_nest_start(msg, band); |
| 1294 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1295 | goto nla_put_failure; |
| 1296 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | switch (*chan_start) { |
| 1298 | case 0: |
| 1299 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1300 | goto nla_put_failure; |
| 1301 | (*chan_start)++; |
| 1302 | if (split) |
| 1303 | break; |
| 1304 | default: |
| 1305 | /* add frequencies */ |
| 1306 | nl_freqs = nla_nest_start( |
| 1307 | msg, NL80211_BAND_ATTR_FREQS); |
| 1308 | if (!nl_freqs) |
| 1309 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1310 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | for (i = *chan_start - 1; |
| 1312 | i < sband->n_channels; |
| 1313 | i++) { |
| 1314 | nl_freq = nla_nest_start(msg, i); |
| 1315 | if (!nl_freq) |
| 1316 | goto nla_put_failure; |
| 1317 | |
| 1318 | chan = &sband->channels[i]; |
| 1319 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1320 | if (nl80211_msg_put_channel(msg, chan, |
| 1321 | split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | goto nla_put_failure; |
| 1323 | |
| 1324 | nla_nest_end(msg, nl_freq); |
| 1325 | if (split) |
| 1326 | break; |
| 1327 | } |
| 1328 | if (i < sband->n_channels) |
| 1329 | *chan_start = i + 2; |
| 1330 | else |
| 1331 | *chan_start = 0; |
| 1332 | nla_nest_end(msg, nl_freqs); |
| 1333 | } |
| 1334 | |
| 1335 | nla_nest_end(msg, nl_band); |
| 1336 | |
| 1337 | if (split) { |
| 1338 | /* start again here */ |
| 1339 | if (*chan_start) |
| 1340 | band--; |
| 1341 | break; |
| 1342 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1343 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1345 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1346 | if (band < IEEE80211_NUM_BANDS) |
| 1347 | *band_start = band + 1; |
| 1348 | else |
| 1349 | *band_start = 0; |
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 | /* if bands & channels are done, continue outside */ |
| 1352 | if (*band_start == 0 && *chan_start == 0) |
| 1353 | (*split_start)++; |
| 1354 | if (split) |
| 1355 | break; |
| 1356 | case 4: |
| 1357 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1358 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1359 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | |
| 1361 | i = 0; |
| 1362 | #define CMD(op, n) \ |
| 1363 | do { \ |
| 1364 | if (dev->ops->op) { \ |
| 1365 | i++; \ |
| 1366 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1367 | goto nla_put_failure; \ |
| 1368 | } \ |
| 1369 | } while (0) |
| 1370 | |
| 1371 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1372 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1373 | CMD(add_key, NEW_KEY); |
| 1374 | CMD(start_ap, START_AP); |
| 1375 | CMD(add_station, NEW_STATION); |
| 1376 | CMD(add_mpath, NEW_MPATH); |
| 1377 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1378 | CMD(change_bss, SET_BSS); |
| 1379 | CMD(auth, AUTHENTICATE); |
| 1380 | CMD(assoc, ASSOCIATE); |
| 1381 | CMD(deauth, DEAUTHENTICATE); |
| 1382 | CMD(disassoc, DISASSOCIATE); |
| 1383 | CMD(join_ibss, JOIN_IBSS); |
| 1384 | CMD(join_mesh, JOIN_MESH); |
| 1385 | CMD(set_pmksa, SET_PMKSA); |
| 1386 | CMD(del_pmksa, DEL_PMKSA); |
| 1387 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1388 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1389 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1390 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1391 | CMD(mgmt_tx, FRAME); |
| 1392 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1393 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1394 | i++; |
| 1395 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1396 | goto nla_put_failure; |
| 1397 | } |
| 1398 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1399 | dev->ops->join_mesh) { |
| 1400 | i++; |
| 1401 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1402 | goto nla_put_failure; |
| 1403 | } |
| 1404 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1405 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1406 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1407 | CMD(tdls_oper, TDLS_OPER); |
| 1408 | } |
| 1409 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1410 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1411 | CMD(probe_client, PROBE_CLIENT); |
| 1412 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1413 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1414 | i++; |
| 1415 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1416 | goto nla_put_failure; |
| 1417 | } |
| 1418 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1419 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1420 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1421 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1422 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1423 | #endif |
| 1424 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1425 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1426 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1427 | if (dev->ops->connect || dev->ops->auth) { |
| 1428 | i++; |
| 1429 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1430 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1431 | } |
| 1432 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1434 | i++; |
| 1435 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1436 | goto nla_put_failure; |
| 1437 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1438 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1439 | nla_nest_end(msg, nl_cmds); |
| 1440 | (*split_start)++; |
| 1441 | if (split) |
| 1442 | break; |
| 1443 | case 5: |
| 1444 | if (dev->ops->remain_on_channel && |
| 1445 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1446 | nla_put_u32(msg, |
| 1447 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1448 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1449 | goto nla_put_failure; |
| 1450 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1451 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1452 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1453 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1454 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1455 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1456 | goto nla_put_failure; |
| 1457 | (*split_start)++; |
| 1458 | if (split) |
| 1459 | break; |
| 1460 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1461 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1462 | if (nl80211_send_wowlan(msg, dev, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1463 | goto nla_put_failure; |
| 1464 | (*split_start)++; |
| 1465 | if (split) |
| 1466 | break; |
| 1467 | #else |
| 1468 | (*split_start)++; |
| 1469 | #endif |
| 1470 | case 7: |
| 1471 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1472 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1473 | goto nla_put_failure; |
| 1474 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1475 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1477 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1478 | (*split_start)++; |
| 1479 | if (split) |
| 1480 | break; |
| 1481 | case 8: |
| 1482 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1483 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1484 | dev->wiphy.ap_sme_capa)) |
| 1485 | goto nla_put_failure; |
| 1486 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1487 | features = dev->wiphy.features; |
| 1488 | /* |
| 1489 | * We can only add the per-channel limit information if the |
| 1490 | * dump is split, otherwise it makes it too big. Therefore |
| 1491 | * only advertise it in that case. |
| 1492 | */ |
| 1493 | if (split) |
| 1494 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1495 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | goto nla_put_failure; |
| 1497 | |
| 1498 | if (dev->wiphy.ht_capa_mod_mask && |
| 1499 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1500 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1501 | dev->wiphy.ht_capa_mod_mask)) |
| 1502 | goto nla_put_failure; |
| 1503 | |
| 1504 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1505 | dev->wiphy.max_acl_mac_addrs && |
| 1506 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1507 | dev->wiphy.max_acl_mac_addrs)) |
| 1508 | goto nla_put_failure; |
| 1509 | |
| 1510 | /* |
| 1511 | * Any information below this point is only available to |
| 1512 | * applications that can deal with it being split. This |
| 1513 | * helps ensure that newly added capabilities don't break |
| 1514 | * older tools by overrunning their buffers. |
| 1515 | * |
| 1516 | * We still increment split_start so that in the split |
| 1517 | * case we'll continue with more data in the next round, |
| 1518 | * but break unconditionally so unsplit data stops here. |
| 1519 | */ |
| 1520 | (*split_start)++; |
| 1521 | break; |
| 1522 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1523 | if (dev->wiphy.extended_capabilities && |
| 1524 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1525 | dev->wiphy.extended_capabilities_len, |
| 1526 | dev->wiphy.extended_capabilities) || |
| 1527 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1528 | dev->wiphy.extended_capabilities_len, |
| 1529 | dev->wiphy.extended_capabilities_mask))) |
| 1530 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1532 | if (dev->wiphy.vht_capa_mod_mask && |
| 1533 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1534 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1535 | dev->wiphy.vht_capa_mod_mask)) |
| 1536 | goto nla_put_failure; |
| 1537 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1538 | /* done */ |
| 1539 | *split_start = 0; |
| 1540 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1541 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1542 | return genlmsg_end(msg, hdr); |
| 1543 | |
| 1544 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1545 | genlmsg_cancel(msg, hdr); |
| 1546 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1550 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1551 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1552 | int start = cb->args[0]; |
| 1553 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1554 | s64 filter_wiphy = -1; |
| 1555 | bool split = false; |
| 1556 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1557 | int res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1558 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1559 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1561 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1562 | if (res == 0) { |
| 1563 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1564 | if (tb[NL80211_ATTR_WIPHY]) |
| 1565 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1566 | if (tb[NL80211_ATTR_WDEV]) |
| 1567 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1568 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1569 | struct net_device *netdev; |
| 1570 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1571 | |
| 1572 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1573 | if (!netdev) { |
| 1574 | mutex_unlock(&cfg80211_mutex); |
| 1575 | return -ENODEV; |
| 1576 | } |
| 1577 | if (netdev->ieee80211_ptr) { |
| 1578 | dev = wiphy_to_dev( |
| 1579 | netdev->ieee80211_ptr->wiphy); |
| 1580 | filter_wiphy = dev->wiphy_idx; |
| 1581 | } |
| 1582 | dev_put(netdev); |
| 1583 | } |
| 1584 | } |
| 1585 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1586 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1587 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1588 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1589 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1590 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1591 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1592 | continue; |
| 1593 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1594 | do { |
| 1595 | ret = nl80211_send_wiphy(dev, skb, |
| 1596 | NETLINK_CB(cb->skb).portid, |
| 1597 | cb->nlh->nlmsg_seq, |
| 1598 | NLM_F_MULTI, |
| 1599 | split, &cb->args[1], |
| 1600 | &cb->args[2], |
| 1601 | &cb->args[3]); |
| 1602 | if (ret < 0) { |
| 1603 | /* |
| 1604 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1605 | * or EMSGSIZE returned), this SKB is still |
| 1606 | * empty (so it's not too big because another |
| 1607 | * wiphy dataset is already in the skb) and |
| 1608 | * we've not tried to adjust the dump allocation |
| 1609 | * yet ... then adjust the alloc size to be |
| 1610 | * bigger, and return 1 but with the empty skb. |
| 1611 | * This results in an empty message being RX'ed |
| 1612 | * in userspace, but that is ignored. |
| 1613 | * |
| 1614 | * We can then retry with the larger buffer. |
| 1615 | */ |
| 1616 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1617 | !skb->len && |
| 1618 | cb->min_dump_alloc < 4096) { |
| 1619 | cb->min_dump_alloc = 4096; |
| 1620 | mutex_unlock(&cfg80211_mutex); |
| 1621 | return 1; |
| 1622 | } |
| 1623 | idx--; |
| 1624 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1625 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1626 | } while (cb->args[1] > 0); |
| 1627 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1628 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1629 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1630 | |
| 1631 | cb->args[0] = idx; |
| 1632 | |
| 1633 | return skb->len; |
| 1634 | } |
| 1635 | |
| 1636 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1637 | { |
| 1638 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1639 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1640 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1641 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1642 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1643 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1644 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1645 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1646 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1647 | nlmsg_free(msg); |
| 1648 | return -ENOBUFS; |
| 1649 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1650 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1651 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1652 | } |
| 1653 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1654 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1655 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1656 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1657 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1658 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1659 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1660 | }; |
| 1661 | |
| 1662 | static int parse_txq_params(struct nlattr *tb[], |
| 1663 | struct ieee80211_txq_params *txq_params) |
| 1664 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1665 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1666 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1667 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1668 | return -EINVAL; |
| 1669 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1670 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1671 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1672 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1673 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1674 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1675 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1676 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1677 | return -EINVAL; |
| 1678 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1679 | return 0; |
| 1680 | } |
| 1681 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1682 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1683 | { |
| 1684 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1685 | * You can only set the channel explicitly for WDS interfaces, |
| 1686 | * all others have their channel managed via their respective |
| 1687 | * "establish a connection" command (connect, join, ...) |
| 1688 | * |
| 1689 | * For AP/GO and mesh mode, the channel can be set with the |
| 1690 | * channel userspace API, but is only stored and passed to the |
| 1691 | * low-level driver when the AP starts or the mesh is joined. |
| 1692 | * This is for backward compatibility, userspace can also give |
| 1693 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1694 | * |
| 1695 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1696 | * whatever else is going on, so they have their own special |
| 1697 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1698 | */ |
| 1699 | return !wdev || |
| 1700 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1701 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1702 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1703 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1704 | } |
| 1705 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1706 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1707 | struct genl_info *info, |
| 1708 | struct cfg80211_chan_def *chandef) |
| 1709 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1710 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1711 | |
| 1712 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1713 | return -EINVAL; |
| 1714 | |
| 1715 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1716 | |
| 1717 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1718 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1719 | chandef->center_freq1 = control_freq; |
| 1720 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1721 | |
| 1722 | /* Primary channel not allowed */ |
| 1723 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1724 | return -EINVAL; |
| 1725 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1726 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1727 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1728 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1729 | chantype = nla_get_u32( |
| 1730 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1731 | |
| 1732 | switch (chantype) { |
| 1733 | case NL80211_CHAN_NO_HT: |
| 1734 | case NL80211_CHAN_HT20: |
| 1735 | case NL80211_CHAN_HT40PLUS: |
| 1736 | case NL80211_CHAN_HT40MINUS: |
| 1737 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1738 | chantype); |
| 1739 | break; |
| 1740 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1741 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1742 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1743 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1744 | chandef->width = |
| 1745 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1746 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1747 | chandef->center_freq1 = |
| 1748 | nla_get_u32( |
| 1749 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1750 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1751 | chandef->center_freq2 = |
| 1752 | nla_get_u32( |
| 1753 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1754 | } |
| 1755 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1756 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1757 | return -EINVAL; |
| 1758 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1759 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1760 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1761 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1762 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1763 | return 0; |
| 1764 | } |
| 1765 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1766 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1767 | struct wireless_dev *wdev, |
| 1768 | struct genl_info *info) |
| 1769 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1770 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1771 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1772 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1773 | |
| 1774 | if (wdev) |
| 1775 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1776 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1777 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1778 | return -EOPNOTSUPP; |
| 1779 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1780 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1781 | if (result) |
| 1782 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1783 | |
| 1784 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1785 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1786 | case NL80211_IFTYPE_AP: |
| 1787 | case NL80211_IFTYPE_P2P_GO: |
| 1788 | if (wdev->beacon_interval) { |
| 1789 | result = -EBUSY; |
| 1790 | break; |
| 1791 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1792 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1793 | result = -EINVAL; |
| 1794 | break; |
| 1795 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1796 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1797 | result = 0; |
| 1798 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1799 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1800 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1801 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1802 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1803 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1804 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1805 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1806 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1807 | } |
| 1808 | mutex_unlock(&rdev->devlist_mtx); |
| 1809 | |
| 1810 | return result; |
| 1811 | } |
| 1812 | |
| 1813 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1814 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1816 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1817 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1818 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1819 | } |
| 1820 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1821 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1822 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1824 | struct net_device *dev = info->user_ptr[1]; |
| 1825 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1826 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1827 | |
| 1828 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1829 | return -EINVAL; |
| 1830 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1831 | if (netif_running(dev)) |
| 1832 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1833 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1834 | if (!rdev->ops->set_wds_peer) |
| 1835 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1836 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1837 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1838 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1839 | |
| 1840 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1841 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1845 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1846 | { |
| 1847 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1848 | struct net_device *netdev = NULL; |
| 1849 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1850 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1851 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1852 | u32 changed; |
| 1853 | u8 retry_short = 0, retry_long = 0; |
| 1854 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1855 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1856 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1857 | /* |
| 1858 | * Try to find the wiphy and netdev. Normally this |
| 1859 | * function shouldn't need the netdev, but this is |
| 1860 | * done for backward compatibility -- previously |
| 1861 | * setting the channel was done per wiphy, but now |
| 1862 | * it is per netdev. Previous userland like hostapd |
| 1863 | * also passed a netdev to set_wiphy, so that it is |
| 1864 | * possible to let that go to the right netdev! |
| 1865 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1866 | mutex_lock(&cfg80211_mutex); |
| 1867 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1868 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1869 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1870 | |
| 1871 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1872 | if (netdev && netdev->ieee80211_ptr) { |
| 1873 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1874 | mutex_lock(&rdev->mtx); |
| 1875 | } else |
| 1876 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1877 | } |
| 1878 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1879 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1880 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1881 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1882 | if (IS_ERR(rdev)) { |
| 1883 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1884 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1885 | } |
| 1886 | wdev = NULL; |
| 1887 | netdev = NULL; |
| 1888 | result = 0; |
| 1889 | |
| 1890 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1891 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1893 | |
| 1894 | /* |
| 1895 | * end workaround code, by now the rdev is available |
| 1896 | * and locked, and wdev may or may not be NULL. |
| 1897 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1898 | |
| 1899 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1900 | result = cfg80211_dev_rename( |
| 1901 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1902 | |
| 1903 | mutex_unlock(&cfg80211_mutex); |
| 1904 | |
| 1905 | if (result) |
| 1906 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1907 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1908 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1909 | struct ieee80211_txq_params txq_params; |
| 1910 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1911 | |
| 1912 | if (!rdev->ops->set_txq_params) { |
| 1913 | result = -EOPNOTSUPP; |
| 1914 | goto bad_res; |
| 1915 | } |
| 1916 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1917 | if (!netdev) { |
| 1918 | result = -EINVAL; |
| 1919 | goto bad_res; |
| 1920 | } |
| 1921 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1922 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1923 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1924 | result = -EINVAL; |
| 1925 | goto bad_res; |
| 1926 | } |
| 1927 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1928 | if (!netif_running(netdev)) { |
| 1929 | result = -ENETDOWN; |
| 1930 | goto bad_res; |
| 1931 | } |
| 1932 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1933 | nla_for_each_nested(nl_txq_params, |
| 1934 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1935 | rem_txq_params) { |
| 1936 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1937 | nla_data(nl_txq_params), |
| 1938 | nla_len(nl_txq_params), |
| 1939 | txq_params_policy); |
| 1940 | result = parse_txq_params(tb, &txq_params); |
| 1941 | if (result) |
| 1942 | goto bad_res; |
| 1943 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1944 | result = rdev_set_txq_params(rdev, netdev, |
| 1945 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1946 | if (result) |
| 1947 | goto bad_res; |
| 1948 | } |
| 1949 | } |
| 1950 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1951 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1952 | result = __nl80211_set_channel(rdev, |
| 1953 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1954 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1955 | if (result) |
| 1956 | goto bad_res; |
| 1957 | } |
| 1958 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1959 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1960 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1961 | enum nl80211_tx_power_setting type; |
| 1962 | int idx, mbm = 0; |
| 1963 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1964 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1965 | txp_wdev = NULL; |
| 1966 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1967 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1968 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1969 | goto bad_res; |
| 1970 | } |
| 1971 | |
| 1972 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1973 | type = nla_get_u32(info->attrs[idx]); |
| 1974 | |
| 1975 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1976 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1977 | result = -EINVAL; |
| 1978 | goto bad_res; |
| 1979 | } |
| 1980 | |
| 1981 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1982 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1983 | mbm = nla_get_u32(info->attrs[idx]); |
| 1984 | } |
| 1985 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1986 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1987 | if (result) |
| 1988 | goto bad_res; |
| 1989 | } |
| 1990 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1991 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1992 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1993 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1994 | if ((!rdev->wiphy.available_antennas_tx && |
| 1995 | !rdev->wiphy.available_antennas_rx) || |
| 1996 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1997 | result = -EOPNOTSUPP; |
| 1998 | goto bad_res; |
| 1999 | } |
| 2000 | |
| 2001 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2002 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2003 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2004 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2005 | * available antenna masks, except for the "all" mask */ |
| 2006 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2007 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2008 | result = -EINVAL; |
| 2009 | goto bad_res; |
| 2010 | } |
| 2011 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2012 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2013 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2014 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2015 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2016 | if (result) |
| 2017 | goto bad_res; |
| 2018 | } |
| 2019 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2020 | changed = 0; |
| 2021 | |
| 2022 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2023 | retry_short = nla_get_u8( |
| 2024 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2025 | if (retry_short == 0) { |
| 2026 | result = -EINVAL; |
| 2027 | goto bad_res; |
| 2028 | } |
| 2029 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2030 | } |
| 2031 | |
| 2032 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2033 | retry_long = nla_get_u8( |
| 2034 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2035 | if (retry_long == 0) { |
| 2036 | result = -EINVAL; |
| 2037 | goto bad_res; |
| 2038 | } |
| 2039 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2040 | } |
| 2041 | |
| 2042 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2043 | frag_threshold = nla_get_u32( |
| 2044 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2045 | if (frag_threshold < 256) { |
| 2046 | result = -EINVAL; |
| 2047 | goto bad_res; |
| 2048 | } |
| 2049 | if (frag_threshold != (u32) -1) { |
| 2050 | /* |
| 2051 | * Fragments (apart from the last one) are required to |
| 2052 | * have even length. Make the fragmentation code |
| 2053 | * simpler by stripping LSB should someone try to use |
| 2054 | * odd threshold value. |
| 2055 | */ |
| 2056 | frag_threshold &= ~0x1; |
| 2057 | } |
| 2058 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2059 | } |
| 2060 | |
| 2061 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2062 | rts_threshold = nla_get_u32( |
| 2063 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2064 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2065 | } |
| 2066 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2067 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2068 | coverage_class = nla_get_u8( |
| 2069 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2070 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2071 | } |
| 2072 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2073 | if (changed) { |
| 2074 | u8 old_retry_short, old_retry_long; |
| 2075 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2076 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2077 | |
| 2078 | if (!rdev->ops->set_wiphy_params) { |
| 2079 | result = -EOPNOTSUPP; |
| 2080 | goto bad_res; |
| 2081 | } |
| 2082 | |
| 2083 | old_retry_short = rdev->wiphy.retry_short; |
| 2084 | old_retry_long = rdev->wiphy.retry_long; |
| 2085 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2086 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2087 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2088 | |
| 2089 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2090 | rdev->wiphy.retry_short = retry_short; |
| 2091 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2092 | rdev->wiphy.retry_long = retry_long; |
| 2093 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2094 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2095 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2096 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2097 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2098 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2099 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2100 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2101 | if (result) { |
| 2102 | rdev->wiphy.retry_short = old_retry_short; |
| 2103 | rdev->wiphy.retry_long = old_retry_long; |
| 2104 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2105 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2106 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2107 | } |
| 2108 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2109 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2110 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2111 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2112 | if (netdev) |
| 2113 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2114 | return result; |
| 2115 | } |
| 2116 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2117 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2118 | { |
| 2119 | return (u64)wdev->identifier | |
| 2120 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2121 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2122 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2123 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2124 | struct cfg80211_chan_def *chandef) |
| 2125 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2126 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2127 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2128 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2129 | chandef->chan->center_freq)) |
| 2130 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2131 | switch (chandef->width) { |
| 2132 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2133 | case NL80211_CHAN_WIDTH_20: |
| 2134 | case NL80211_CHAN_WIDTH_40: |
| 2135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2136 | cfg80211_get_chandef_type(chandef))) |
| 2137 | return -ENOBUFS; |
| 2138 | break; |
| 2139 | default: |
| 2140 | break; |
| 2141 | } |
| 2142 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2143 | return -ENOBUFS; |
| 2144 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2145 | return -ENOBUFS; |
| 2146 | if (chandef->center_freq2 && |
| 2147 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2148 | return -ENOBUFS; |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2152 | 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] | 2153 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2154 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2155 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2156 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2157 | void *hdr; |
| 2158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2159 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2160 | if (!hdr) |
| 2161 | return -1; |
| 2162 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2163 | if (dev && |
| 2164 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2165 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2166 | goto nla_put_failure; |
| 2167 | |
| 2168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2169 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2170 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2171 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2172 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2173 | rdev->devlist_generation ^ |
| 2174 | (cfg80211_rdev_list_generation << 2))) |
| 2175 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2176 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2177 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2178 | int ret; |
| 2179 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2180 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2181 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2182 | if (ret == 0) { |
| 2183 | if (nl80211_send_chandef(msg, &chandef)) |
| 2184 | goto nla_put_failure; |
| 2185 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2186 | } |
| 2187 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2188 | if (wdev->ssid_len) { |
| 2189 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2190 | goto nla_put_failure; |
| 2191 | } |
| 2192 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2193 | return genlmsg_end(msg, hdr); |
| 2194 | |
| 2195 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2196 | genlmsg_cancel(msg, hdr); |
| 2197 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2201 | { |
| 2202 | int wp_idx = 0; |
| 2203 | int if_idx = 0; |
| 2204 | int wp_start = cb->args[0]; |
| 2205 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2206 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2207 | struct wireless_dev *wdev; |
| 2208 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2209 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2210 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2211 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2212 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2213 | if (wp_idx < wp_start) { |
| 2214 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2215 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2216 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2217 | if_idx = 0; |
| 2218 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2219 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2220 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2221 | if (if_idx < if_start) { |
| 2222 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2223 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2224 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2225 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2226 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2227 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2228 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2229 | goto out; |
| 2230 | } |
| 2231 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2232 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2233 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2234 | |
| 2235 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2236 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2237 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2238 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | |
| 2240 | cb->args[0] = wp_idx; |
| 2241 | cb->args[1] = if_idx; |
| 2242 | |
| 2243 | return skb->len; |
| 2244 | } |
| 2245 | |
| 2246 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2247 | { |
| 2248 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2249 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2250 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2251 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2253 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2254 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2255 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2256 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2257 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2258 | nlmsg_free(msg); |
| 2259 | return -ENOBUFS; |
| 2260 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2261 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2262 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2263 | } |
| 2264 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2265 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2266 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2267 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2268 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2269 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2270 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2271 | }; |
| 2272 | |
| 2273 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2274 | { |
| 2275 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2276 | int flag; |
| 2277 | |
| 2278 | *mntrflags = 0; |
| 2279 | |
| 2280 | if (!nla) |
| 2281 | return -EINVAL; |
| 2282 | |
| 2283 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2284 | nla, mntr_flags_policy)) |
| 2285 | return -EINVAL; |
| 2286 | |
| 2287 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2288 | if (flags[flag]) |
| 2289 | *mntrflags |= (1<<flag); |
| 2290 | |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2294 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2295 | struct net_device *netdev, u8 use_4addr, |
| 2296 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2297 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2298 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2299 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2300 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2301 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2302 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2303 | |
| 2304 | switch (iftype) { |
| 2305 | case NL80211_IFTYPE_AP_VLAN: |
| 2306 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2307 | return 0; |
| 2308 | break; |
| 2309 | case NL80211_IFTYPE_STATION: |
| 2310 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2311 | return 0; |
| 2312 | break; |
| 2313 | default: |
| 2314 | break; |
| 2315 | } |
| 2316 | |
| 2317 | return -EOPNOTSUPP; |
| 2318 | } |
| 2319 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2320 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2321 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2323 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2324 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2325 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2326 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2327 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2328 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2329 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2330 | memset(¶ms, 0, sizeof(params)); |
| 2331 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2332 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2333 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2334 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2335 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2336 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2337 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2338 | if (ntype > NL80211_IFTYPE_MAX) |
| 2339 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2340 | } |
| 2341 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2342 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2343 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2345 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2346 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2347 | if (netif_running(dev)) |
| 2348 | return -EBUSY; |
| 2349 | |
| 2350 | wdev_lock(wdev); |
| 2351 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2352 | IEEE80211_MAX_MESH_ID_LEN); |
| 2353 | wdev->mesh_id_up_len = |
| 2354 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2355 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2356 | wdev->mesh_id_up_len); |
| 2357 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2360 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2361 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2362 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2363 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2364 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2365 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2366 | } else { |
| 2367 | params.use_4addr = -1; |
| 2368 | } |
| 2369 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2370 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2371 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2372 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2373 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2374 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2375 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2376 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2377 | |
| 2378 | flags = &_flags; |
| 2379 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2380 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2381 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2382 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2383 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2384 | else |
| 2385 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2386 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2387 | if (!err && params.use_4addr != -1) |
| 2388 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2389 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2390 | return err; |
| 2391 | } |
| 2392 | |
| 2393 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2394 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2396 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2397 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2398 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2399 | int err; |
| 2400 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2401 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2402 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2403 | memset(¶ms, 0, sizeof(params)); |
| 2404 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2405 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2406 | return -EINVAL; |
| 2407 | |
| 2408 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2409 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2410 | if (type > NL80211_IFTYPE_MAX) |
| 2411 | return -EINVAL; |
| 2412 | } |
| 2413 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2414 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2415 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2416 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2417 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2418 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2419 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2420 | ETH_ALEN); |
| 2421 | if (!is_valid_ether_addr(params.macaddr)) |
| 2422 | return -EADDRNOTAVAIL; |
| 2423 | } |
| 2424 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2425 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2426 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2427 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2428 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2430 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2431 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2433 | if (!msg) |
| 2434 | return -ENOMEM; |
| 2435 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2436 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2437 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2438 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2439 | wdev = rdev_add_virtual_intf(rdev, |
| 2440 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2441 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2442 | if (IS_ERR(wdev)) { |
| 2443 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2444 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2445 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2446 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2447 | switch (type) { |
| 2448 | case NL80211_IFTYPE_MESH_POINT: |
| 2449 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2450 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2451 | wdev_lock(wdev); |
| 2452 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2453 | IEEE80211_MAX_MESH_ID_LEN); |
| 2454 | wdev->mesh_id_up_len = |
| 2455 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2456 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2457 | wdev->mesh_id_up_len); |
| 2458 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2459 | break; |
| 2460 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2461 | /* |
| 2462 | * P2P Device doesn't have a netdev, so doesn't go |
| 2463 | * through the netdev notifier and must be added here |
| 2464 | */ |
| 2465 | mutex_init(&wdev->mtx); |
| 2466 | INIT_LIST_HEAD(&wdev->event_list); |
| 2467 | spin_lock_init(&wdev->event_lock); |
| 2468 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2469 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2470 | |
| 2471 | mutex_lock(&rdev->devlist_mtx); |
| 2472 | wdev->identifier = ++rdev->wdev_id; |
| 2473 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2474 | rdev->devlist_generation++; |
| 2475 | mutex_unlock(&rdev->devlist_mtx); |
| 2476 | break; |
| 2477 | default: |
| 2478 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2479 | } |
| 2480 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2481 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2482 | rdev, wdev) < 0) { |
| 2483 | nlmsg_free(msg); |
| 2484 | return -ENOBUFS; |
| 2485 | } |
| 2486 | |
| 2487 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2491 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2493 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2494 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2495 | if (!rdev->ops->del_virtual_intf) |
| 2496 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2497 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2498 | /* |
| 2499 | * If we remove a wireless device without a netdev then clear |
| 2500 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2501 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2502 | * since the wdev has been freed, unlike with a netdev where |
| 2503 | * we need the dev_put() for the netdev to really be freed. |
| 2504 | */ |
| 2505 | if (!wdev->netdev) |
| 2506 | info->user_ptr[1] = NULL; |
| 2507 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2508 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2509 | } |
| 2510 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2511 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2512 | { |
| 2513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2514 | struct net_device *dev = info->user_ptr[1]; |
| 2515 | u16 noack_map; |
| 2516 | |
| 2517 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2518 | return -EINVAL; |
| 2519 | |
| 2520 | if (!rdev->ops->set_noack_map) |
| 2521 | return -EOPNOTSUPP; |
| 2522 | |
| 2523 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2524 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2525 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2526 | } |
| 2527 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2528 | struct get_key_cookie { |
| 2529 | struct sk_buff *msg; |
| 2530 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2531 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2532 | }; |
| 2533 | |
| 2534 | static void get_key_callback(void *c, struct key_params *params) |
| 2535 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2536 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2537 | struct get_key_cookie *cookie = c; |
| 2538 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2539 | if ((params->key && |
| 2540 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2541 | params->key_len, params->key)) || |
| 2542 | (params->seq && |
| 2543 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2544 | params->seq_len, params->seq)) || |
| 2545 | (params->cipher && |
| 2546 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2547 | params->cipher))) |
| 2548 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2549 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2550 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2551 | if (!key) |
| 2552 | goto nla_put_failure; |
| 2553 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2554 | if ((params->key && |
| 2555 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2556 | params->key_len, params->key)) || |
| 2557 | (params->seq && |
| 2558 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2559 | params->seq_len, params->seq)) || |
| 2560 | (params->cipher && |
| 2561 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2562 | params->cipher))) |
| 2563 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2564 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2565 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2566 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2567 | |
| 2568 | nla_nest_end(cookie->msg, key); |
| 2569 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2570 | return; |
| 2571 | nla_put_failure: |
| 2572 | cookie->error = 1; |
| 2573 | } |
| 2574 | |
| 2575 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2576 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2578 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2579 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2580 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2581 | const u8 *mac_addr = NULL; |
| 2582 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2583 | struct get_key_cookie cookie = { |
| 2584 | .error = 0, |
| 2585 | }; |
| 2586 | void *hdr; |
| 2587 | struct sk_buff *msg; |
| 2588 | |
| 2589 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2590 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2591 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2592 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2593 | return -EINVAL; |
| 2594 | |
| 2595 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2596 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2597 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2598 | pairwise = !!mac_addr; |
| 2599 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2600 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2601 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2602 | return -EINVAL; |
| 2603 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2604 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2605 | return -EINVAL; |
| 2606 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2607 | } |
| 2608 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2609 | if (!rdev->ops->get_key) |
| 2610 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2611 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2612 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2613 | if (!msg) |
| 2614 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2615 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2616 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2617 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2618 | if (IS_ERR(hdr)) |
| 2619 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2620 | |
| 2621 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2622 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2623 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2624 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2625 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2626 | goto nla_put_failure; |
| 2627 | if (mac_addr && |
| 2628 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2629 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2630 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2631 | if (pairwise && mac_addr && |
| 2632 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2633 | return -ENOENT; |
| 2634 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2635 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2636 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2637 | |
| 2638 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2639 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2640 | |
| 2641 | if (cookie.error) |
| 2642 | goto nla_put_failure; |
| 2643 | |
| 2644 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2645 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2646 | |
| 2647 | nla_put_failure: |
| 2648 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2649 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2650 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2651 | return err; |
| 2652 | } |
| 2653 | |
| 2654 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2655 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2657 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2658 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2659 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2660 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2661 | err = nl80211_parse_key(info, &key); |
| 2662 | if (err) |
| 2663 | return err; |
| 2664 | |
| 2665 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2666 | return -EINVAL; |
| 2667 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2668 | /* only support setting default key */ |
| 2669 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2670 | return -EINVAL; |
| 2671 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2672 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2673 | |
| 2674 | if (key.def) { |
| 2675 | if (!rdev->ops->set_default_key) { |
| 2676 | err = -EOPNOTSUPP; |
| 2677 | goto out; |
| 2678 | } |
| 2679 | |
| 2680 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2681 | if (err) |
| 2682 | goto out; |
| 2683 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2684 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2685 | key.def_uni, key.def_multi); |
| 2686 | |
| 2687 | if (err) |
| 2688 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2689 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2690 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2691 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2692 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2693 | } else { |
| 2694 | if (key.def_uni || !key.def_multi) { |
| 2695 | err = -EINVAL; |
| 2696 | goto out; |
| 2697 | } |
| 2698 | |
| 2699 | if (!rdev->ops->set_default_mgmt_key) { |
| 2700 | err = -EOPNOTSUPP; |
| 2701 | goto out; |
| 2702 | } |
| 2703 | |
| 2704 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2705 | if (err) |
| 2706 | goto out; |
| 2707 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2708 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2709 | if (err) |
| 2710 | goto out; |
| 2711 | |
| 2712 | #ifdef CONFIG_CFG80211_WEXT |
| 2713 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2714 | #endif |
| 2715 | } |
| 2716 | |
| 2717 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2718 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2719 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2720 | return err; |
| 2721 | } |
| 2722 | |
| 2723 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2724 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2726 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2728 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2729 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2730 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2731 | err = nl80211_parse_key(info, &key); |
| 2732 | if (err) |
| 2733 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2734 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2735 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2736 | return -EINVAL; |
| 2737 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2738 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2739 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2740 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2741 | if (key.type == -1) { |
| 2742 | if (mac_addr) |
| 2743 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2744 | else |
| 2745 | key.type = NL80211_KEYTYPE_GROUP; |
| 2746 | } |
| 2747 | |
| 2748 | /* for now */ |
| 2749 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2750 | key.type != NL80211_KEYTYPE_GROUP) |
| 2751 | return -EINVAL; |
| 2752 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2753 | if (!rdev->ops->add_key) |
| 2754 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2755 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2756 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2757 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2758 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2759 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2760 | |
| 2761 | wdev_lock(dev->ieee80211_ptr); |
| 2762 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2763 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2764 | err = rdev_add_key(rdev, dev, key.idx, |
| 2765 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2766 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2767 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2768 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2769 | return err; |
| 2770 | } |
| 2771 | |
| 2772 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2773 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2775 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2776 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2777 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2778 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2779 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2780 | err = nl80211_parse_key(info, &key); |
| 2781 | if (err) |
| 2782 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | |
| 2784 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2785 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2786 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2787 | if (key.type == -1) { |
| 2788 | if (mac_addr) |
| 2789 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2790 | else |
| 2791 | key.type = NL80211_KEYTYPE_GROUP; |
| 2792 | } |
| 2793 | |
| 2794 | /* for now */ |
| 2795 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2796 | key.type != NL80211_KEYTYPE_GROUP) |
| 2797 | return -EINVAL; |
| 2798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2799 | if (!rdev->ops->del_key) |
| 2800 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2801 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2802 | wdev_lock(dev->ieee80211_ptr); |
| 2803 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2804 | |
| 2805 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2806 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2807 | err = -ENOENT; |
| 2808 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2809 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2810 | err = rdev_del_key(rdev, dev, key.idx, |
| 2811 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2812 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2813 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2814 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2815 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2816 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2817 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2818 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2819 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2820 | } |
| 2821 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2822 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2823 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2824 | return err; |
| 2825 | } |
| 2826 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2827 | /* This function returns an error or the number of nested attributes */ |
| 2828 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2829 | { |
| 2830 | struct nlattr *attr; |
| 2831 | int n_entries = 0, tmp; |
| 2832 | |
| 2833 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2834 | if (nla_len(attr) != ETH_ALEN) |
| 2835 | return -EINVAL; |
| 2836 | |
| 2837 | n_entries++; |
| 2838 | } |
| 2839 | |
| 2840 | return n_entries; |
| 2841 | } |
| 2842 | |
| 2843 | /* |
| 2844 | * This function parses ACL information and allocates memory for ACL data. |
| 2845 | * On successful return, the calling function is responsible to free the |
| 2846 | * ACL buffer returned by this function. |
| 2847 | */ |
| 2848 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2849 | struct genl_info *info) |
| 2850 | { |
| 2851 | enum nl80211_acl_policy acl_policy; |
| 2852 | struct nlattr *attr; |
| 2853 | struct cfg80211_acl_data *acl; |
| 2854 | int i = 0, n_entries, tmp; |
| 2855 | |
| 2856 | if (!wiphy->max_acl_mac_addrs) |
| 2857 | return ERR_PTR(-EOPNOTSUPP); |
| 2858 | |
| 2859 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2860 | return ERR_PTR(-EINVAL); |
| 2861 | |
| 2862 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2863 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2864 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2865 | return ERR_PTR(-EINVAL); |
| 2866 | |
| 2867 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2868 | return ERR_PTR(-EINVAL); |
| 2869 | |
| 2870 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2871 | if (n_entries < 0) |
| 2872 | return ERR_PTR(n_entries); |
| 2873 | |
| 2874 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2875 | return ERR_PTR(-ENOTSUPP); |
| 2876 | |
| 2877 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2878 | GFP_KERNEL); |
| 2879 | if (!acl) |
| 2880 | return ERR_PTR(-ENOMEM); |
| 2881 | |
| 2882 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2883 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2884 | i++; |
| 2885 | } |
| 2886 | |
| 2887 | acl->n_acl_entries = n_entries; |
| 2888 | acl->acl_policy = acl_policy; |
| 2889 | |
| 2890 | return acl; |
| 2891 | } |
| 2892 | |
| 2893 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2894 | { |
| 2895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2896 | struct net_device *dev = info->user_ptr[1]; |
| 2897 | struct cfg80211_acl_data *acl; |
| 2898 | int err; |
| 2899 | |
| 2900 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2901 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2902 | return -EOPNOTSUPP; |
| 2903 | |
| 2904 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2905 | return -EINVAL; |
| 2906 | |
| 2907 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2908 | if (IS_ERR(acl)) |
| 2909 | return PTR_ERR(acl); |
| 2910 | |
| 2911 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2912 | |
| 2913 | kfree(acl); |
| 2914 | |
| 2915 | return err; |
| 2916 | } |
| 2917 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2918 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2919 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2920 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2921 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2922 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2923 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2924 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2925 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2926 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2927 | return -EINVAL; |
| 2928 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2929 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2930 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2931 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2932 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2933 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2934 | if (!bcn->head_len) |
| 2935 | return -EINVAL; |
| 2936 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2940 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2941 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2942 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2943 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2944 | } |
| 2945 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2946 | if (!haveinfo) |
| 2947 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2948 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2949 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2950 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2951 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2955 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2956 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2957 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2958 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2959 | } |
| 2960 | |
| 2961 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2962 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2963 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2964 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2965 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2966 | } |
| 2967 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2968 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2969 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2970 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2971 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2972 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2973 | } |
| 2974 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2975 | return 0; |
| 2976 | } |
| 2977 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2978 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2979 | struct cfg80211_ap_settings *params) |
| 2980 | { |
| 2981 | struct wireless_dev *wdev; |
| 2982 | bool ret = false; |
| 2983 | |
| 2984 | mutex_lock(&rdev->devlist_mtx); |
| 2985 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2986 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2987 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2988 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2989 | continue; |
| 2990 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2991 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2992 | continue; |
| 2993 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2994 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2995 | ret = true; |
| 2996 | break; |
| 2997 | } |
| 2998 | |
| 2999 | mutex_unlock(&rdev->devlist_mtx); |
| 3000 | |
| 3001 | return ret; |
| 3002 | } |
| 3003 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3004 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3005 | enum nl80211_auth_type auth_type, |
| 3006 | enum nl80211_commands cmd) |
| 3007 | { |
| 3008 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3009 | return false; |
| 3010 | |
| 3011 | switch (cmd) { |
| 3012 | case NL80211_CMD_AUTHENTICATE: |
| 3013 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3014 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3015 | return false; |
| 3016 | return true; |
| 3017 | case NL80211_CMD_CONNECT: |
| 3018 | case NL80211_CMD_START_AP: |
| 3019 | /* SAE not supported yet */ |
| 3020 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3021 | return false; |
| 3022 | return true; |
| 3023 | default: |
| 3024 | return false; |
| 3025 | } |
| 3026 | } |
| 3027 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3028 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3029 | { |
| 3030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3031 | struct net_device *dev = info->user_ptr[1]; |
| 3032 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3033 | struct cfg80211_ap_settings params; |
| 3034 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3035 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3036 | |
| 3037 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3038 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3039 | return -EOPNOTSUPP; |
| 3040 | |
| 3041 | if (!rdev->ops->start_ap) |
| 3042 | return -EOPNOTSUPP; |
| 3043 | |
| 3044 | if (wdev->beacon_interval) |
| 3045 | return -EALREADY; |
| 3046 | |
| 3047 | memset(¶ms, 0, sizeof(params)); |
| 3048 | |
| 3049 | /* these are required for START_AP */ |
| 3050 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3051 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3052 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3053 | return -EINVAL; |
| 3054 | |
| 3055 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 3056 | if (err) |
| 3057 | return err; |
| 3058 | |
| 3059 | params.beacon_interval = |
| 3060 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3061 | params.dtim_period = |
| 3062 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3063 | |
| 3064 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3065 | if (err) |
| 3066 | return err; |
| 3067 | |
| 3068 | /* |
| 3069 | * In theory, some of these attributes should be required here |
| 3070 | * but since they were not used when the command was originally |
| 3071 | * added, keep them optional for old user space programs to let |
| 3072 | * them continue to work with drivers that do not need the |
| 3073 | * additional information -- drivers must check! |
| 3074 | */ |
| 3075 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3076 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3077 | params.ssid_len = |
| 3078 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3079 | if (params.ssid_len == 0 || |
| 3080 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3081 | return -EINVAL; |
| 3082 | } |
| 3083 | |
| 3084 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3085 | params.hidden_ssid = nla_get_u32( |
| 3086 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3087 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3088 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3089 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3090 | return -EINVAL; |
| 3091 | } |
| 3092 | |
| 3093 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3094 | |
| 3095 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3096 | params.auth_type = nla_get_u32( |
| 3097 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3098 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3099 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3100 | return -EINVAL; |
| 3101 | } else |
| 3102 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3103 | |
| 3104 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3105 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3106 | if (err) |
| 3107 | return err; |
| 3108 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3109 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3110 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3111 | return -EOPNOTSUPP; |
| 3112 | params.inactivity_timeout = nla_get_u16( |
| 3113 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3114 | } |
| 3115 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3116 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3117 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3118 | return -EINVAL; |
| 3119 | params.p2p_ctwindow = |
| 3120 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3121 | if (params.p2p_ctwindow > 127) |
| 3122 | return -EINVAL; |
| 3123 | if (params.p2p_ctwindow != 0 && |
| 3124 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3125 | return -EINVAL; |
| 3126 | } |
| 3127 | |
| 3128 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3129 | u8 tmp; |
| 3130 | |
| 3131 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3132 | return -EINVAL; |
| 3133 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3134 | if (tmp > 1) |
| 3135 | return -EINVAL; |
| 3136 | params.p2p_opp_ps = tmp; |
| 3137 | if (params.p2p_opp_ps != 0 && |
| 3138 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3139 | return -EINVAL; |
| 3140 | } |
| 3141 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3142 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3143 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3144 | if (err) |
| 3145 | return err; |
| 3146 | } else if (wdev->preset_chandef.chan) { |
| 3147 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3148 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3149 | return -EINVAL; |
| 3150 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3151 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3152 | return -EINVAL; |
| 3153 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3154 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3155 | if (err < 0) |
| 3156 | return err; |
| 3157 | if (err) { |
| 3158 | radar_detect_width = BIT(params.chandef.width); |
| 3159 | params.radar_required = true; |
| 3160 | } |
| 3161 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3162 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3163 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3164 | params.chandef.chan, |
| 3165 | CHAN_MODE_SHARED, |
| 3166 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3167 | mutex_unlock(&rdev->devlist_mtx); |
| 3168 | |
| 3169 | if (err) |
| 3170 | return err; |
| 3171 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3172 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3173 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3174 | if (IS_ERR(params.acl)) |
| 3175 | return PTR_ERR(params.acl); |
| 3176 | } |
| 3177 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3178 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3179 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3180 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3181 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3182 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3183 | wdev->ssid_len = params.ssid_len; |
| 3184 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3185 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3186 | |
| 3187 | kfree(params.acl); |
| 3188 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3189 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3190 | } |
| 3191 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3192 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3193 | { |
| 3194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3195 | struct net_device *dev = info->user_ptr[1]; |
| 3196 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3197 | struct cfg80211_beacon_data params; |
| 3198 | int err; |
| 3199 | |
| 3200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3202 | return -EOPNOTSUPP; |
| 3203 | |
| 3204 | if (!rdev->ops->change_beacon) |
| 3205 | return -EOPNOTSUPP; |
| 3206 | |
| 3207 | if (!wdev->beacon_interval) |
| 3208 | return -EINVAL; |
| 3209 | |
| 3210 | err = nl80211_parse_beacon(info, ¶ms); |
| 3211 | if (err) |
| 3212 | return err; |
| 3213 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3214 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | 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] | 3218 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3220 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3221 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3222 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3223 | } |
| 3224 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3225 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3226 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3227 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3228 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3229 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3230 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3231 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3232 | }; |
| 3233 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3234 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3235 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3236 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3237 | { |
| 3238 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3239 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3240 | int flag; |
| 3241 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3242 | /* |
| 3243 | * Try parsing the new attribute first so userspace |
| 3244 | * can specify both for older kernels. |
| 3245 | */ |
| 3246 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3247 | if (nla) { |
| 3248 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3249 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3250 | sta_flags = nla_data(nla); |
| 3251 | params->sta_flags_mask = sta_flags->mask; |
| 3252 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3253 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3254 | if ((params->sta_flags_mask | |
| 3255 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3256 | return -EINVAL; |
| 3257 | return 0; |
| 3258 | } |
| 3259 | |
| 3260 | /* if present, parse the old attribute */ |
| 3261 | |
| 3262 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3263 | if (!nla) |
| 3264 | return 0; |
| 3265 | |
| 3266 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3267 | nla, sta_flags_policy)) |
| 3268 | return -EINVAL; |
| 3269 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3270 | /* |
| 3271 | * Only allow certain flags for interface types so that |
| 3272 | * other attributes are silently ignored. Remember that |
| 3273 | * this is backward compatibility code with old userspace |
| 3274 | * and shouldn't be hit in other cases anyway. |
| 3275 | */ |
| 3276 | switch (iftype) { |
| 3277 | case NL80211_IFTYPE_AP: |
| 3278 | case NL80211_IFTYPE_AP_VLAN: |
| 3279 | case NL80211_IFTYPE_P2P_GO: |
| 3280 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3281 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3282 | BIT(NL80211_STA_FLAG_WME) | |
| 3283 | BIT(NL80211_STA_FLAG_MFP); |
| 3284 | break; |
| 3285 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3286 | case NL80211_IFTYPE_STATION: |
| 3287 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3288 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3289 | break; |
| 3290 | case NL80211_IFTYPE_MESH_POINT: |
| 3291 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3292 | BIT(NL80211_STA_FLAG_MFP) | |
| 3293 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3294 | default: |
| 3295 | return -EINVAL; |
| 3296 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3297 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3298 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3299 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3300 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3301 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3302 | /* no longer support new API additions in old API */ |
| 3303 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3304 | return -EINVAL; |
| 3305 | } |
| 3306 | } |
| 3307 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3308 | return 0; |
| 3309 | } |
| 3310 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3311 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3312 | int attr) |
| 3313 | { |
| 3314 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3315 | u32 bitrate; |
| 3316 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3317 | |
| 3318 | rate = nla_nest_start(msg, attr); |
| 3319 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3320 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3321 | |
| 3322 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3323 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3324 | /* report 16-bit bitrate only if we can */ |
| 3325 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3326 | if (bitrate > 0 && |
| 3327 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3328 | return false; |
| 3329 | if (bitrate_compat > 0 && |
| 3330 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3331 | return false; |
| 3332 | |
| 3333 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3334 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3335 | return false; |
| 3336 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3337 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3338 | return false; |
| 3339 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3340 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3341 | return false; |
| 3342 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3343 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3344 | return false; |
| 3345 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 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_80_MHZ_WIDTH && |
| 3351 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3352 | return false; |
| 3353 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3354 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3355 | return false; |
| 3356 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3357 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3358 | return false; |
| 3359 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3360 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3361 | return false; |
| 3362 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3363 | |
| 3364 | nla_nest_end(msg, rate); |
| 3365 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3366 | } |
| 3367 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3368 | 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] | 3369 | int flags, |
| 3370 | struct cfg80211_registered_device *rdev, |
| 3371 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3372 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3373 | { |
| 3374 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3375 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3376 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3377 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3378 | if (!hdr) |
| 3379 | return -1; |
| 3380 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3381 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3382 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3383 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3384 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3385 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3386 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3387 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3388 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3389 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3390 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3391 | sinfo->connected_time)) |
| 3392 | goto nla_put_failure; |
| 3393 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3394 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3395 | sinfo->inactive_time)) |
| 3396 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3397 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3398 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3399 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3400 | (u32)sinfo->rx_bytes)) |
| 3401 | goto nla_put_failure; |
| 3402 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3403 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3404 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3405 | (u32)sinfo->tx_bytes)) |
| 3406 | goto nla_put_failure; |
| 3407 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3408 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3409 | sinfo->rx_bytes)) |
| 3410 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3411 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3412 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3413 | sinfo->tx_bytes)) |
| 3414 | goto nla_put_failure; |
| 3415 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3416 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3417 | goto nla_put_failure; |
| 3418 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3419 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3420 | goto nla_put_failure; |
| 3421 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3422 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3423 | sinfo->plink_state)) |
| 3424 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3425 | switch (rdev->wiphy.signal_type) { |
| 3426 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3427 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3428 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3429 | sinfo->signal)) |
| 3430 | goto nla_put_failure; |
| 3431 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3432 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3433 | sinfo->signal_avg)) |
| 3434 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3435 | break; |
| 3436 | default: |
| 3437 | break; |
| 3438 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3439 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3440 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3441 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3442 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3443 | } |
| 3444 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3445 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3446 | NL80211_STA_INFO_RX_BITRATE)) |
| 3447 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3448 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3449 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3450 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3451 | sinfo->rx_packets)) |
| 3452 | goto nla_put_failure; |
| 3453 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3454 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3455 | sinfo->tx_packets)) |
| 3456 | goto nla_put_failure; |
| 3457 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3458 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3459 | sinfo->tx_retries)) |
| 3460 | goto nla_put_failure; |
| 3461 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3462 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3463 | sinfo->tx_failed)) |
| 3464 | goto nla_put_failure; |
| 3465 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3466 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3467 | sinfo->beacon_loss_count)) |
| 3468 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3469 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3470 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3471 | sinfo->local_pm)) |
| 3472 | goto nla_put_failure; |
| 3473 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3474 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3475 | sinfo->peer_pm)) |
| 3476 | goto nla_put_failure; |
| 3477 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3478 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3479 | sinfo->nonpeer_pm)) |
| 3480 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3481 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3482 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3483 | if (!bss_param) |
| 3484 | goto nla_put_failure; |
| 3485 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3486 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3487 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3488 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3489 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3490 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3491 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3492 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3493 | sinfo->bss_param.dtim_period) || |
| 3494 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3495 | sinfo->bss_param.beacon_interval)) |
| 3496 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3497 | |
| 3498 | nla_nest_end(msg, bss_param); |
| 3499 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3500 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3501 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3502 | sizeof(struct nl80211_sta_flag_update), |
| 3503 | &sinfo->sta_flags)) |
| 3504 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3505 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3506 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3507 | sinfo->t_offset)) |
| 3508 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3509 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3510 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3511 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3512 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3513 | sinfo->assoc_req_ies)) |
| 3514 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3515 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3516 | return genlmsg_end(msg, hdr); |
| 3517 | |
| 3518 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3519 | genlmsg_cancel(msg, hdr); |
| 3520 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3521 | } |
| 3522 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3523 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3524 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3525 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3526 | struct station_info sinfo; |
| 3527 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3528 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3529 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3530 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3531 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3532 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3533 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3534 | if (err) |
| 3535 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3536 | |
| 3537 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3538 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3539 | goto out_err; |
| 3540 | } |
| 3541 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3542 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3543 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3544 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3545 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3546 | if (err == -ENOENT) |
| 3547 | break; |
| 3548 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3549 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3550 | |
| 3551 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3552 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3553 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3554 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3555 | &sinfo) < 0) |
| 3556 | goto out; |
| 3557 | |
| 3558 | sta_idx++; |
| 3559 | } |
| 3560 | |
| 3561 | |
| 3562 | out: |
| 3563 | cb->args[1] = sta_idx; |
| 3564 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3565 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3566 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3567 | |
| 3568 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3569 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3570 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3571 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3572 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3574 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3575 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3576 | struct sk_buff *msg; |
| 3577 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3578 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3579 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3580 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3581 | |
| 3582 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3583 | return -EINVAL; |
| 3584 | |
| 3585 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3586 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3587 | if (!rdev->ops->get_station) |
| 3588 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3589 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3590 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3591 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3592 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3593 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3595 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3596 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3597 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3598 | 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] | 3599 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3600 | nlmsg_free(msg); |
| 3601 | return -ENOBUFS; |
| 3602 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3603 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3604 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3607 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3608 | struct station_parameters *params, |
| 3609 | enum cfg80211_station_type statype) |
| 3610 | { |
| 3611 | if (params->listen_interval != -1) |
| 3612 | return -EINVAL; |
| 3613 | if (params->aid) |
| 3614 | return -EINVAL; |
| 3615 | |
| 3616 | /* When you run into this, adjust the code below for the new flag */ |
| 3617 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3618 | |
| 3619 | switch (statype) { |
| 3620 | case CFG80211_STA_MESH_PEER_NONSEC: |
| 3621 | case CFG80211_STA_MESH_PEER_SECURE: |
| 3622 | /* |
| 3623 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3624 | * code doesn't have the bug of including TDLS in the |
| 3625 | * mask everywhere. |
| 3626 | */ |
| 3627 | if (params->sta_flags_mask & |
| 3628 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3629 | BIT(NL80211_STA_FLAG_MFP) | |
| 3630 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3631 | return -EINVAL; |
| 3632 | break; |
| 3633 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3634 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3635 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3636 | return -EINVAL; |
| 3637 | /* ignore since it can't change */ |
| 3638 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3639 | break; |
| 3640 | default: |
| 3641 | /* disallow mesh-specific things */ |
| 3642 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3643 | return -EINVAL; |
| 3644 | if (params->local_pm) |
| 3645 | return -EINVAL; |
| 3646 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3647 | return -EINVAL; |
| 3648 | } |
| 3649 | |
| 3650 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3651 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3652 | /* TDLS can't be set, ... */ |
| 3653 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3654 | return -EINVAL; |
| 3655 | /* |
| 3656 | * ... but don't bother the driver with it. This works around |
| 3657 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3658 | * TLDS_PEER flag in the mask even for AP mode. |
| 3659 | */ |
| 3660 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3661 | } |
| 3662 | |
| 3663 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3664 | /* reject other things that can't change */ |
| 3665 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3666 | return -EINVAL; |
| 3667 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3668 | return -EINVAL; |
| 3669 | if (params->supported_rates) |
| 3670 | return -EINVAL; |
| 3671 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3672 | return -EINVAL; |
| 3673 | } |
| 3674 | |
| 3675 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3676 | if (params->vlan) |
| 3677 | return -EINVAL; |
| 3678 | } |
| 3679 | |
| 3680 | switch (statype) { |
| 3681 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3682 | /* Use this only for authorizing/unauthorizing a station */ |
| 3683 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3684 | return -EOPNOTSUPP; |
| 3685 | break; |
| 3686 | case CFG80211_STA_AP_CLIENT: |
| 3687 | /* accept only the listed bits */ |
| 3688 | if (params->sta_flags_mask & |
| 3689 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3690 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3691 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3692 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3693 | BIT(NL80211_STA_FLAG_WME) | |
| 3694 | BIT(NL80211_STA_FLAG_MFP))) |
| 3695 | return -EINVAL; |
| 3696 | |
| 3697 | /* but authenticated/associated only if driver handles it */ |
| 3698 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3699 | params->sta_flags_mask & |
| 3700 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3701 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3702 | return -EINVAL; |
| 3703 | break; |
| 3704 | case CFG80211_STA_IBSS: |
| 3705 | case CFG80211_STA_AP_STA: |
| 3706 | /* reject any changes other than AUTHORIZED */ |
| 3707 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3708 | return -EINVAL; |
| 3709 | break; |
| 3710 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3711 | /* reject any changes other than AUTHORIZED or WME */ |
| 3712 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3713 | BIT(NL80211_STA_FLAG_WME))) |
| 3714 | return -EINVAL; |
| 3715 | /* force (at least) rates when authorizing */ |
| 3716 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3717 | !params->supported_rates) |
| 3718 | return -EINVAL; |
| 3719 | break; |
| 3720 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3721 | /* reject any changes */ |
| 3722 | return -EINVAL; |
| 3723 | case CFG80211_STA_MESH_PEER_NONSEC: |
| 3724 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3725 | return -EINVAL; |
| 3726 | break; |
| 3727 | case CFG80211_STA_MESH_PEER_SECURE: |
| 3728 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3729 | return -EINVAL; |
| 3730 | break; |
| 3731 | } |
| 3732 | |
| 3733 | return 0; |
| 3734 | } |
| 3735 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3736 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3737 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3738 | * 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] | 3739 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3740 | static struct net_device *get_vlan(struct genl_info *info, |
| 3741 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3742 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3743 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3744 | struct net_device *v; |
| 3745 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3746 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3747 | if (!vlanattr) |
| 3748 | return NULL; |
| 3749 | |
| 3750 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3751 | if (!v) |
| 3752 | return ERR_PTR(-ENODEV); |
| 3753 | |
| 3754 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3755 | ret = -EINVAL; |
| 3756 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3757 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3758 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3759 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3760 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3761 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3762 | ret = -EINVAL; |
| 3763 | goto error; |
| 3764 | } |
| 3765 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3766 | if (!netif_running(v)) { |
| 3767 | ret = -ENETDOWN; |
| 3768 | goto error; |
| 3769 | } |
| 3770 | |
| 3771 | return v; |
| 3772 | error: |
| 3773 | dev_put(v); |
| 3774 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3775 | } |
| 3776 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3777 | static struct nla_policy |
| 3778 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3779 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3780 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3781 | }; |
| 3782 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3783 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3784 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3785 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3786 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3787 | struct nlattr *nla; |
| 3788 | int err; |
| 3789 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3790 | /* parse WME attributes if present */ |
| 3791 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3792 | return 0; |
| 3793 | |
| 3794 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3795 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3796 | nl80211_sta_wme_policy); |
| 3797 | if (err) |
| 3798 | return err; |
| 3799 | |
| 3800 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3801 | params->uapsd_queues = nla_get_u8( |
| 3802 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3803 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3804 | return -EINVAL; |
| 3805 | |
| 3806 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3807 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3808 | |
| 3809 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3810 | return -EINVAL; |
| 3811 | |
| 3812 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3813 | |
| 3814 | return 0; |
| 3815 | } |
| 3816 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3817 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3818 | struct station_parameters *params) |
| 3819 | { |
| 3820 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3821 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3822 | params->ht_capa = |
| 3823 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3824 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3825 | params->vht_capa = |
| 3826 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3827 | |
| 3828 | return nl80211_parse_sta_wme(info, params); |
| 3829 | } |
| 3830 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3831 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3832 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3834 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3835 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3836 | u8 *mac_addr; |
| 3837 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3838 | |
| 3839 | memset(¶ms, 0, sizeof(params)); |
| 3840 | |
| 3841 | params.listen_interval = -1; |
| 3842 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3843 | if (!rdev->ops->change_station) |
| 3844 | return -EOPNOTSUPP; |
| 3845 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3846 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3847 | return -EINVAL; |
| 3848 | |
| 3849 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3850 | return -EINVAL; |
| 3851 | |
| 3852 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3853 | |
| 3854 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3855 | params.supported_rates = |
| 3856 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3857 | params.supported_rates_len = |
| 3858 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3859 | } |
| 3860 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3861 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3862 | params.capability = |
| 3863 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3864 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3865 | } |
| 3866 | |
| 3867 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3868 | params.ext_capab = |
| 3869 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3870 | params.ext_capab_len = |
| 3871 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3872 | } |
| 3873 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3874 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3875 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3876 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3877 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3878 | return -EINVAL; |
| 3879 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3880 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3881 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3882 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3883 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3884 | return -EINVAL; |
| 3885 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3886 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3887 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3888 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3889 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3890 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3891 | return -EINVAL; |
| 3892 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3893 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3894 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3895 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3896 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3897 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3898 | |
| 3899 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3900 | pm > NL80211_MESH_POWER_MAX) |
| 3901 | return -EINVAL; |
| 3902 | |
| 3903 | params.local_pm = pm; |
| 3904 | } |
| 3905 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3906 | /* Include parameters for TDLS peer (will check later) */ |
| 3907 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3908 | if (err) |
| 3909 | return err; |
| 3910 | |
| 3911 | params.vlan = get_vlan(info, rdev); |
| 3912 | if (IS_ERR(params.vlan)) |
| 3913 | return PTR_ERR(params.vlan); |
| 3914 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3915 | switch (dev->ieee80211_ptr->iftype) { |
| 3916 | case NL80211_IFTYPE_AP: |
| 3917 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3918 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3919 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3920 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3921 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3922 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3923 | break; |
| 3924 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3925 | err = -EOPNOTSUPP; |
| 3926 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3927 | } |
| 3928 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3929 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3930 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3931 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3932 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3933 | if (params.vlan) |
| 3934 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3935 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3936 | return err; |
| 3937 | } |
| 3938 | |
| 3939 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3940 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3942 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3943 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3944 | struct station_parameters params; |
| 3945 | u8 *mac_addr = NULL; |
| 3946 | |
| 3947 | memset(¶ms, 0, sizeof(params)); |
| 3948 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3949 | if (!rdev->ops->add_station) |
| 3950 | return -EOPNOTSUPP; |
| 3951 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3952 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3953 | return -EINVAL; |
| 3954 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3955 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3956 | return -EINVAL; |
| 3957 | |
| 3958 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3959 | return -EINVAL; |
| 3960 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3961 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3962 | return -EINVAL; |
| 3963 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3964 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3965 | params.supported_rates = |
| 3966 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3967 | params.supported_rates_len = |
| 3968 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3969 | params.listen_interval = |
| 3970 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3971 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3972 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3973 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3974 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3975 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3976 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3977 | params.capability = |
| 3978 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3979 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3980 | } |
| 3981 | |
| 3982 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3983 | params.ext_capab = |
| 3984 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3985 | params.ext_capab_len = |
| 3986 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3987 | } |
| 3988 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3989 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3990 | params.ht_capa = |
| 3991 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3992 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3993 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3994 | params.vht_capa = |
| 3995 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3996 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3997 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3998 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3999 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4000 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4001 | return -EINVAL; |
| 4002 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4003 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4004 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4005 | if (err) |
| 4006 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4007 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4008 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4009 | return -EINVAL; |
| 4010 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4011 | /* When you run into this, adjust the code below for the new flag */ |
| 4012 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4013 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4014 | switch (dev->ieee80211_ptr->iftype) { |
| 4015 | case NL80211_IFTYPE_AP: |
| 4016 | case NL80211_IFTYPE_AP_VLAN: |
| 4017 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4018 | /* ignore WME attributes if iface/sta is not capable */ |
| 4019 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4020 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4021 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4022 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4023 | /* TDLS peers cannot be added */ |
| 4024 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4025 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4026 | /* but don't bother the driver with it */ |
| 4027 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4028 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4029 | /* allow authenticated/associated only if driver handles it */ |
| 4030 | if (!(rdev->wiphy.features & |
| 4031 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4032 | params.sta_flags_mask & |
| 4033 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4034 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4035 | return -EINVAL; |
| 4036 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4037 | /* must be last in here for error handling */ |
| 4038 | params.vlan = get_vlan(info, rdev); |
| 4039 | if (IS_ERR(params.vlan)) |
| 4040 | return PTR_ERR(params.vlan); |
| 4041 | break; |
| 4042 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4043 | /* ignore uAPSD data */ |
| 4044 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4045 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4046 | /* associated is disallowed */ |
| 4047 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4048 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4049 | /* TDLS peers cannot be added */ |
| 4050 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4051 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4052 | break; |
| 4053 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame^] | 4054 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4055 | /* ignore uAPSD data */ |
| 4056 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4057 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4058 | /* these are disallowed */ |
| 4059 | if (params.sta_flags_mask & |
| 4060 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4061 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4062 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4063 | /* Only TDLS peers can be added */ |
| 4064 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4065 | return -EINVAL; |
| 4066 | /* Can only add if TDLS ... */ |
| 4067 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4068 | return -EOPNOTSUPP; |
| 4069 | /* ... with external setup is supported */ |
| 4070 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4071 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4072 | /* |
| 4073 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4074 | * as authorized, but it shouldn't yet be. |
| 4075 | */ |
| 4076 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4077 | break; |
| 4078 | default: |
| 4079 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4080 | } |
| 4081 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4082 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4083 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4084 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4085 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4086 | if (params.vlan) |
| 4087 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4088 | return err; |
| 4089 | } |
| 4090 | |
| 4091 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4092 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4094 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4095 | u8 *mac_addr = NULL; |
| 4096 | |
| 4097 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4098 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4099 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4100 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4103 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4104 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4105 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4106 | if (!rdev->ops->del_station) |
| 4107 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4108 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4109 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4110 | } |
| 4111 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4112 | 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] | 4113 | int flags, struct net_device *dev, |
| 4114 | u8 *dst, u8 *next_hop, |
| 4115 | struct mpath_info *pinfo) |
| 4116 | { |
| 4117 | void *hdr; |
| 4118 | struct nlattr *pinfoattr; |
| 4119 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4120 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4121 | if (!hdr) |
| 4122 | return -1; |
| 4123 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4124 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4125 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4126 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4127 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4128 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4129 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4130 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4131 | if (!pinfoattr) |
| 4132 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4133 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4134 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4135 | pinfo->frame_qlen)) |
| 4136 | goto nla_put_failure; |
| 4137 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4138 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4139 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4140 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4141 | pinfo->metric)) || |
| 4142 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4143 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4144 | pinfo->exptime)) || |
| 4145 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4146 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4147 | pinfo->flags)) || |
| 4148 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4149 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4150 | pinfo->discovery_timeout)) || |
| 4151 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4152 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4153 | pinfo->discovery_retries))) |
| 4154 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4155 | |
| 4156 | nla_nest_end(msg, pinfoattr); |
| 4157 | |
| 4158 | return genlmsg_end(msg, hdr); |
| 4159 | |
| 4160 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4161 | genlmsg_cancel(msg, hdr); |
| 4162 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4166 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4167 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4168 | struct mpath_info pinfo; |
| 4169 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4170 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4171 | u8 dst[ETH_ALEN]; |
| 4172 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4173 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4174 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4175 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4176 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4177 | if (err) |
| 4178 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4179 | |
| 4180 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4181 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4182 | goto out_err; |
| 4183 | } |
| 4184 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4185 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4186 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4187 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4188 | } |
| 4189 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4190 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4191 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 4192 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4193 | if (err == -ENOENT) |
| 4194 | break; |
| 4195 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4196 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4197 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4198 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4199 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4200 | netdev, dst, next_hop, |
| 4201 | &pinfo) < 0) |
| 4202 | goto out; |
| 4203 | |
| 4204 | path_idx++; |
| 4205 | } |
| 4206 | |
| 4207 | |
| 4208 | out: |
| 4209 | cb->args[1] = path_idx; |
| 4210 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4211 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4212 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4213 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4217 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4219 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4220 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4221 | struct mpath_info pinfo; |
| 4222 | struct sk_buff *msg; |
| 4223 | u8 *dst = NULL; |
| 4224 | u8 next_hop[ETH_ALEN]; |
| 4225 | |
| 4226 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4227 | |
| 4228 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4229 | return -EINVAL; |
| 4230 | |
| 4231 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4232 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4233 | if (!rdev->ops->get_mpath) |
| 4234 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4235 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4236 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4237 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4238 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4239 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4240 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4241 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4242 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4244 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4245 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4246 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4247 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4248 | dev, dst, next_hop, &pinfo) < 0) { |
| 4249 | nlmsg_free(msg); |
| 4250 | return -ENOBUFS; |
| 4251 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4252 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4253 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4259 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4260 | u8 *dst = NULL; |
| 4261 | u8 *next_hop = NULL; |
| 4262 | |
| 4263 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4264 | return -EINVAL; |
| 4265 | |
| 4266 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4267 | return -EINVAL; |
| 4268 | |
| 4269 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4270 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4272 | if (!rdev->ops->change_mpath) |
| 4273 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4274 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4275 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4276 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4277 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4278 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4279 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4280 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4281 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4282 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4284 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4285 | u8 *dst = NULL; |
| 4286 | u8 *next_hop = NULL; |
| 4287 | |
| 4288 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4289 | return -EINVAL; |
| 4290 | |
| 4291 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4292 | return -EINVAL; |
| 4293 | |
| 4294 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4295 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4297 | if (!rdev->ops->add_mpath) |
| 4298 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4300 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4301 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4302 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4303 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4307 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4309 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4310 | u8 *dst = NULL; |
| 4311 | |
| 4312 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4313 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4314 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4315 | if (!rdev->ops->del_mpath) |
| 4316 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4317 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4318 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4321 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4322 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4324 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4325 | struct bss_parameters params; |
| 4326 | |
| 4327 | memset(¶ms, 0, sizeof(params)); |
| 4328 | /* default to not changing parameters */ |
| 4329 | params.use_cts_prot = -1; |
| 4330 | params.use_short_preamble = -1; |
| 4331 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4332 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4333 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4334 | params.p2p_ctwindow = -1; |
| 4335 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4336 | |
| 4337 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4338 | params.use_cts_prot = |
| 4339 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4340 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4341 | params.use_short_preamble = |
| 4342 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4343 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4344 | params.use_short_slot_time = |
| 4345 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4346 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4347 | params.basic_rates = |
| 4348 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4349 | params.basic_rates_len = |
| 4350 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4351 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4352 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4353 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4354 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4355 | params.ht_opmode = |
| 4356 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4357 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4358 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4359 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4360 | return -EINVAL; |
| 4361 | params.p2p_ctwindow = |
| 4362 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4363 | if (params.p2p_ctwindow < 0) |
| 4364 | return -EINVAL; |
| 4365 | if (params.p2p_ctwindow != 0 && |
| 4366 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4367 | return -EINVAL; |
| 4368 | } |
| 4369 | |
| 4370 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4371 | u8 tmp; |
| 4372 | |
| 4373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4374 | return -EINVAL; |
| 4375 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4376 | if (tmp > 1) |
| 4377 | return -EINVAL; |
| 4378 | params.p2p_opp_ps = tmp; |
| 4379 | if (params.p2p_opp_ps && |
| 4380 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4381 | return -EINVAL; |
| 4382 | } |
| 4383 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4384 | if (!rdev->ops->change_bss) |
| 4385 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4386 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4388 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4389 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4390 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4391 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4392 | } |
| 4393 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4394 | 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] | 4395 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4396 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4397 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4398 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4399 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4400 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4401 | }; |
| 4402 | |
| 4403 | static int parse_reg_rule(struct nlattr *tb[], |
| 4404 | struct ieee80211_reg_rule *reg_rule) |
| 4405 | { |
| 4406 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4407 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4408 | |
| 4409 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4410 | return -EINVAL; |
| 4411 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4412 | return -EINVAL; |
| 4413 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4414 | return -EINVAL; |
| 4415 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4416 | return -EINVAL; |
| 4417 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4418 | return -EINVAL; |
| 4419 | |
| 4420 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4421 | |
| 4422 | freq_range->start_freq_khz = |
| 4423 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4424 | freq_range->end_freq_khz = |
| 4425 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4426 | freq_range->max_bandwidth_khz = |
| 4427 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4428 | |
| 4429 | power_rule->max_eirp = |
| 4430 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4431 | |
| 4432 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4433 | power_rule->max_antenna_gain = |
| 4434 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4435 | |
| 4436 | return 0; |
| 4437 | } |
| 4438 | |
| 4439 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4440 | { |
| 4441 | int r; |
| 4442 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4443 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4444 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4445 | /* |
| 4446 | * You should only get this when cfg80211 hasn't yet initialized |
| 4447 | * completely when built-in to the kernel right between the time |
| 4448 | * window between nl80211_init() and regulatory_init(), if that is |
| 4449 | * even possible. |
| 4450 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4451 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4452 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4453 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4454 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4455 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4456 | |
| 4457 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4458 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4459 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4460 | user_reg_hint_type = |
| 4461 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4462 | else |
| 4463 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4464 | |
| 4465 | switch (user_reg_hint_type) { |
| 4466 | case NL80211_USER_REG_HINT_USER: |
| 4467 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4468 | break; |
| 4469 | default: |
| 4470 | return -EINVAL; |
| 4471 | } |
| 4472 | |
| 4473 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4474 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4475 | return r; |
| 4476 | } |
| 4477 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4478 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4479 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4480 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4482 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4483 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4484 | struct mesh_config cur_params; |
| 4485 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4486 | void *hdr; |
| 4487 | struct nlattr *pinfoattr; |
| 4488 | struct sk_buff *msg; |
| 4489 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4490 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4491 | return -EOPNOTSUPP; |
| 4492 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4493 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4494 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4495 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4496 | wdev_lock(wdev); |
| 4497 | /* If not connected, get default parameters */ |
| 4498 | if (!wdev->mesh_id_len) |
| 4499 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4500 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4501 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4502 | wdev_unlock(wdev); |
| 4503 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4504 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4505 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4506 | |
| 4507 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4508 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4509 | if (!msg) |
| 4510 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4511 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4512 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4513 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4514 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4515 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4516 | if (!pinfoattr) |
| 4517 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4518 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4519 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4520 | cur_params.dot11MeshRetryTimeout) || |
| 4521 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4522 | cur_params.dot11MeshConfirmTimeout) || |
| 4523 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4524 | cur_params.dot11MeshHoldingTimeout) || |
| 4525 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4526 | cur_params.dot11MeshMaxPeerLinks) || |
| 4527 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4528 | cur_params.dot11MeshMaxRetries) || |
| 4529 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4530 | cur_params.dot11MeshTTL) || |
| 4531 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4532 | cur_params.element_ttl) || |
| 4533 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4534 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4535 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4536 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4537 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4538 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4539 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4540 | cur_params.path_refresh_time) || |
| 4541 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4542 | cur_params.min_discovery_timeout) || |
| 4543 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4544 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4545 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4546 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4547 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4548 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4549 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4550 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4551 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4552 | cur_params.dot11MeshHWMPRootMode) || |
| 4553 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4554 | cur_params.dot11MeshHWMPRannInterval) || |
| 4555 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4556 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4557 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4558 | cur_params.dot11MeshForwarding) || |
| 4559 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4560 | cur_params.rssi_threshold) || |
| 4561 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4562 | cur_params.ht_opmode) || |
| 4563 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4564 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4565 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4566 | cur_params.dot11MeshHWMProotInterval) || |
| 4567 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4568 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4569 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4570 | cur_params.power_mode) || |
| 4571 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4572 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4573 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4574 | nla_nest_end(msg, pinfoattr); |
| 4575 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4576 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4577 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4578 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4579 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4580 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4581 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4582 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4585 | 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] | 4586 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4587 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4588 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4589 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4590 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4591 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4592 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4593 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4594 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4595 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4596 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4597 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4598 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4599 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4600 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4601 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4602 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4603 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4604 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4605 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4606 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4607 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4608 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4609 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4610 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4611 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4612 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4613 | }; |
| 4614 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4615 | static const struct nla_policy |
| 4616 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4617 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4618 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4619 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4620 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4621 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4622 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4623 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4624 | }; |
| 4625 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4626 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4627 | struct mesh_config *cfg, |
| 4628 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4629 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4630 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4631 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4632 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4633 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4634 | do { \ |
| 4635 | if (tb[attr]) { \ |
| 4636 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4637 | return -EINVAL; \ |
| 4638 | cfg->param = fn(tb[attr]); \ |
| 4639 | mask |= (1 << (attr - 1)); \ |
| 4640 | } \ |
| 4641 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4642 | |
| 4643 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4644 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4645 | return -EINVAL; |
| 4646 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4647 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4648 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4649 | return -EINVAL; |
| 4650 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4651 | /* This makes sure that there aren't more than 32 mesh config |
| 4652 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4653 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4654 | |
| 4655 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4656 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4657 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4658 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4659 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4660 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4661 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4662 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4663 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4664 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4665 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4666 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4667 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4668 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4669 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4670 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4671 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4672 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4673 | 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] | 4674 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4675 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4676 | 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] | 4677 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4678 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4679 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4680 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4681 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4682 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4683 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4684 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4685 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4686 | 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] | 4687 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4688 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4689 | 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] | 4690 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4691 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4693 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4694 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4695 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4697 | 1, 65535, mask, |
| 4698 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4699 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4700 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4701 | 1, 65535, mask, |
| 4702 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4703 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4704 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4705 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4706 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4707 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4708 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4710 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4711 | nla_get_u8); |
| 4712 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4713 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4714 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4716 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4717 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4718 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4719 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4720 | mask, NL80211_MESHCONF_FORWARDING, |
| 4721 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4722 | 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] | 4723 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4724 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4725 | 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] | 4726 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4727 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4728 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4729 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4730 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4731 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4733 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4734 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4735 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4736 | dot11MeshHWMPconfirmationInterval, |
| 4737 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4738 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4739 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4740 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4741 | NL80211_MESH_POWER_ACTIVE, |
| 4742 | NL80211_MESH_POWER_MAX, |
| 4743 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4744 | nla_get_u32); |
| 4745 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4746 | 0, 65535, mask, |
| 4747 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4748 | if (mask_out) |
| 4749 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4750 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4751 | return 0; |
| 4752 | |
| 4753 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4754 | } |
| 4755 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4756 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4757 | struct mesh_setup *setup) |
| 4758 | { |
| 4759 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4760 | |
| 4761 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4762 | return -EINVAL; |
| 4763 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4764 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4765 | nl80211_mesh_setup_params_policy)) |
| 4766 | return -EINVAL; |
| 4767 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4768 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4769 | setup->sync_method = |
| 4770 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4771 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4772 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4773 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4774 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4775 | setup->path_sel_proto = |
| 4776 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4777 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4778 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4779 | |
| 4780 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4781 | setup->path_metric = |
| 4782 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4783 | IEEE80211_PATH_METRIC_VENDOR : |
| 4784 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4785 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4786 | |
| 4787 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4788 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4789 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4790 | if (!is_valid_ie_attr(ieattr)) |
| 4791 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4792 | setup->ie = nla_data(ieattr); |
| 4793 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4794 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4795 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4796 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4797 | |
| 4798 | return 0; |
| 4799 | } |
| 4800 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4801 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4802 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4803 | { |
| 4804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4805 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4806 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4807 | struct mesh_config cfg; |
| 4808 | u32 mask; |
| 4809 | int err; |
| 4810 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4811 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4812 | return -EOPNOTSUPP; |
| 4813 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4814 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4815 | return -EOPNOTSUPP; |
| 4816 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4817 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4818 | if (err) |
| 4819 | return err; |
| 4820 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4821 | wdev_lock(wdev); |
| 4822 | if (!wdev->mesh_id_len) |
| 4823 | err = -ENOLINK; |
| 4824 | |
| 4825 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4826 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4827 | |
| 4828 | wdev_unlock(wdev); |
| 4829 | |
| 4830 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4831 | } |
| 4832 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4833 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4834 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4835 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4836 | struct sk_buff *msg; |
| 4837 | void *hdr = NULL; |
| 4838 | struct nlattr *nl_reg_rules; |
| 4839 | unsigned int i; |
| 4840 | int err = -EINVAL; |
| 4841 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4842 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4843 | |
| 4844 | if (!cfg80211_regdomain) |
| 4845 | goto out; |
| 4846 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4847 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4848 | if (!msg) { |
| 4849 | err = -ENOBUFS; |
| 4850 | goto out; |
| 4851 | } |
| 4852 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4853 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4854 | NL80211_CMD_GET_REG); |
| 4855 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4856 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4857 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4858 | if (reg_last_request_cell_base() && |
| 4859 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4860 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4861 | goto nla_put_failure; |
| 4862 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4863 | rcu_read_lock(); |
| 4864 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4865 | |
| 4866 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4867 | (regdom->dfs_region && |
| 4868 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4869 | goto nla_put_failure_rcu; |
| 4870 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4871 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4872 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4873 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4874 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4875 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4876 | struct nlattr *nl_reg_rule; |
| 4877 | const struct ieee80211_reg_rule *reg_rule; |
| 4878 | const struct ieee80211_freq_range *freq_range; |
| 4879 | const struct ieee80211_power_rule *power_rule; |
| 4880 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4881 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4882 | freq_range = ®_rule->freq_range; |
| 4883 | power_rule = ®_rule->power_rule; |
| 4884 | |
| 4885 | nl_reg_rule = nla_nest_start(msg, i); |
| 4886 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4887 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4888 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4889 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4890 | reg_rule->flags) || |
| 4891 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4892 | freq_range->start_freq_khz) || |
| 4893 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4894 | freq_range->end_freq_khz) || |
| 4895 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4896 | freq_range->max_bandwidth_khz) || |
| 4897 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4898 | power_rule->max_antenna_gain) || |
| 4899 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4900 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4901 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4902 | |
| 4903 | nla_nest_end(msg, nl_reg_rule); |
| 4904 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4905 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4906 | |
| 4907 | nla_nest_end(msg, nl_reg_rules); |
| 4908 | |
| 4909 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4910 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4911 | goto out; |
| 4912 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4913 | nla_put_failure_rcu: |
| 4914 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4915 | nla_put_failure: |
| 4916 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4917 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4918 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4919 | err = -EMSGSIZE; |
| 4920 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4921 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4922 | return err; |
| 4923 | } |
| 4924 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4925 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4926 | { |
| 4927 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4928 | struct nlattr *nl_reg_rule; |
| 4929 | char *alpha2 = NULL; |
| 4930 | int rem_reg_rules = 0, r = 0; |
| 4931 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4932 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4933 | struct ieee80211_regdomain *rd = NULL; |
| 4934 | |
| 4935 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4936 | return -EINVAL; |
| 4937 | |
| 4938 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4939 | return -EINVAL; |
| 4940 | |
| 4941 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4942 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4944 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4945 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4946 | 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] | 4947 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4948 | num_rules++; |
| 4949 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4950 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4953 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4954 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4955 | |
| 4956 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4957 | if (!rd) |
| 4958 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4959 | |
| 4960 | rd->n_reg_rules = num_rules; |
| 4961 | rd->alpha2[0] = alpha2[0]; |
| 4962 | rd->alpha2[1] = alpha2[1]; |
| 4963 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4964 | /* |
| 4965 | * Disable DFS master mode if the DFS region was |
| 4966 | * not supported or known on this kernel. |
| 4967 | */ |
| 4968 | if (reg_supported_dfs_region(dfs_region)) |
| 4969 | rd->dfs_region = dfs_region; |
| 4970 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4971 | 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] | 4972 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4973 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4974 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4975 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4976 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4977 | if (r) |
| 4978 | goto bad_reg; |
| 4979 | |
| 4980 | rule_idx++; |
| 4981 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4982 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4983 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4984 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4985 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4988 | mutex_lock(&cfg80211_mutex); |
| 4989 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4990 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4991 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4992 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4993 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4994 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4995 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4996 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4997 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4998 | } |
| 4999 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5000 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5001 | { |
| 5002 | struct nlattr *attr1, *attr2; |
| 5003 | int n_channels = 0, tmp1, tmp2; |
| 5004 | |
| 5005 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5006 | n_channels++; |
| 5007 | /* |
| 5008 | * Some hardware has a limited channel list for |
| 5009 | * scanning, and it is pretty much nonsensical |
| 5010 | * to scan for a channel twice, so disallow that |
| 5011 | * and don't require drivers to check that the |
| 5012 | * channel list they get isn't longer than what |
| 5013 | * they can scan, as long as they can scan all |
| 5014 | * the channels they registered at once. |
| 5015 | */ |
| 5016 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5017 | if (attr1 != attr2 && |
| 5018 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5019 | return 0; |
| 5020 | } |
| 5021 | |
| 5022 | return n_channels; |
| 5023 | } |
| 5024 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5025 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5028 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5029 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5030 | struct nlattr *attr; |
| 5031 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5032 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5033 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5034 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5035 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5036 | return -EINVAL; |
| 5037 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5038 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5039 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5040 | if (!rdev->ops->scan) |
| 5041 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5042 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5043 | if (rdev->scan_req) |
| 5044 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5045 | |
| 5046 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5047 | n_channels = validate_scan_freqs( |
| 5048 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5049 | if (!n_channels) |
| 5050 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5051 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5052 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5053 | n_channels = 0; |
| 5054 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5055 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5056 | if (wiphy->bands[band]) |
| 5057 | n_channels += wiphy->bands[band]->n_channels; |
| 5058 | } |
| 5059 | |
| 5060 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5061 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5062 | n_ssids++; |
| 5063 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5064 | if (n_ssids > wiphy->max_scan_ssids) |
| 5065 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5066 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5067 | if (info->attrs[NL80211_ATTR_IE]) |
| 5068 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5069 | else |
| 5070 | ie_len = 0; |
| 5071 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5072 | if (ie_len > wiphy->max_scan_ie_len) |
| 5073 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5074 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5075 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5076 | + sizeof(*request->ssids) * n_ssids |
| 5077 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5078 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5079 | if (!request) |
| 5080 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5081 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5082 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5083 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5084 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5085 | if (ie_len) { |
| 5086 | if (request->ssids) |
| 5087 | request->ie = (void *)(request->ssids + n_ssids); |
| 5088 | else |
| 5089 | request->ie = (void *)(request->channels + n_channels); |
| 5090 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5091 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5092 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5093 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5094 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5095 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5096 | struct ieee80211_channel *chan; |
| 5097 | |
| 5098 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5099 | |
| 5100 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5101 | err = -EINVAL; |
| 5102 | goto out_free; |
| 5103 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5104 | |
| 5105 | /* ignore disabled channels */ |
| 5106 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5107 | continue; |
| 5108 | |
| 5109 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5110 | i++; |
| 5111 | } |
| 5112 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5113 | enum ieee80211_band band; |
| 5114 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5115 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5116 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5117 | int j; |
| 5118 | if (!wiphy->bands[band]) |
| 5119 | continue; |
| 5120 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5121 | struct ieee80211_channel *chan; |
| 5122 | |
| 5123 | chan = &wiphy->bands[band]->channels[j]; |
| 5124 | |
| 5125 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5126 | continue; |
| 5127 | |
| 5128 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5129 | i++; |
| 5130 | } |
| 5131 | } |
| 5132 | } |
| 5133 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5134 | if (!i) { |
| 5135 | err = -EINVAL; |
| 5136 | goto out_free; |
| 5137 | } |
| 5138 | |
| 5139 | request->n_channels = i; |
| 5140 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5141 | i = 0; |
| 5142 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5143 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5144 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5145 | err = -EINVAL; |
| 5146 | goto out_free; |
| 5147 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5148 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5149 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5150 | i++; |
| 5151 | } |
| 5152 | } |
| 5153 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5154 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5155 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5156 | memcpy((void *)request->ie, |
| 5157 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5158 | request->ie_len); |
| 5159 | } |
| 5160 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5161 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5162 | if (wiphy->bands[i]) |
| 5163 | request->rates[i] = |
| 5164 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5165 | |
| 5166 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5167 | nla_for_each_nested(attr, |
| 5168 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5169 | tmp) { |
| 5170 | enum ieee80211_band band = nla_type(attr); |
| 5171 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5172 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5173 | err = -EINVAL; |
| 5174 | goto out_free; |
| 5175 | } |
| 5176 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5177 | nla_data(attr), |
| 5178 | nla_len(attr), |
| 5179 | &request->rates[band]); |
| 5180 | if (err) |
| 5181 | goto out_free; |
| 5182 | } |
| 5183 | } |
| 5184 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5185 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5186 | request->flags = nla_get_u32( |
| 5187 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5188 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5189 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5190 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5191 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5192 | err = -EOPNOTSUPP; |
| 5193 | goto out_free; |
| 5194 | } |
| 5195 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5196 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5197 | request->no_cck = |
| 5198 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5199 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5200 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5201 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5202 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5203 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5204 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5205 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5206 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5207 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5208 | nl80211_send_scan_start(rdev, wdev); |
| 5209 | if (wdev->netdev) |
| 5210 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5211 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5212 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5213 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5214 | kfree(request); |
| 5215 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5216 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5217 | return err; |
| 5218 | } |
| 5219 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5220 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5221 | struct genl_info *info) |
| 5222 | { |
| 5223 | struct cfg80211_sched_scan_request *request; |
| 5224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5225 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5226 | struct nlattr *attr; |
| 5227 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5228 | 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] | 5229 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5230 | enum ieee80211_band band; |
| 5231 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5232 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5233 | |
| 5234 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5235 | !rdev->ops->sched_scan_start) |
| 5236 | return -EOPNOTSUPP; |
| 5237 | |
| 5238 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5239 | return -EINVAL; |
| 5240 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5241 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5242 | return -EINVAL; |
| 5243 | |
| 5244 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5245 | if (interval == 0) |
| 5246 | return -EINVAL; |
| 5247 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5248 | wiphy = &rdev->wiphy; |
| 5249 | |
| 5250 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5251 | n_channels = validate_scan_freqs( |
| 5252 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5253 | if (!n_channels) |
| 5254 | return -EINVAL; |
| 5255 | } else { |
| 5256 | n_channels = 0; |
| 5257 | |
| 5258 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5259 | if (wiphy->bands[band]) |
| 5260 | n_channels += wiphy->bands[band]->n_channels; |
| 5261 | } |
| 5262 | |
| 5263 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5264 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5265 | tmp) |
| 5266 | n_ssids++; |
| 5267 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5268 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5269 | return -EINVAL; |
| 5270 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5271 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5272 | nla_for_each_nested(attr, |
| 5273 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5274 | tmp) |
| 5275 | n_match_sets++; |
| 5276 | |
| 5277 | if (n_match_sets > wiphy->max_match_sets) |
| 5278 | return -EINVAL; |
| 5279 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5280 | if (info->attrs[NL80211_ATTR_IE]) |
| 5281 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5282 | else |
| 5283 | ie_len = 0; |
| 5284 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5285 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5286 | return -EINVAL; |
| 5287 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5288 | mutex_lock(&rdev->sched_scan_mtx); |
| 5289 | |
| 5290 | if (rdev->sched_scan_req) { |
| 5291 | err = -EINPROGRESS; |
| 5292 | goto out; |
| 5293 | } |
| 5294 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5295 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5296 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5297 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5298 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5299 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5300 | if (!request) { |
| 5301 | err = -ENOMEM; |
| 5302 | goto out; |
| 5303 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5304 | |
| 5305 | if (n_ssids) |
| 5306 | request->ssids = (void *)&request->channels[n_channels]; |
| 5307 | request->n_ssids = n_ssids; |
| 5308 | if (ie_len) { |
| 5309 | if (request->ssids) |
| 5310 | request->ie = (void *)(request->ssids + n_ssids); |
| 5311 | else |
| 5312 | request->ie = (void *)(request->channels + n_channels); |
| 5313 | } |
| 5314 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5315 | if (n_match_sets) { |
| 5316 | if (request->ie) |
| 5317 | request->match_sets = (void *)(request->ie + ie_len); |
| 5318 | else if (request->ssids) |
| 5319 | request->match_sets = |
| 5320 | (void *)(request->ssids + n_ssids); |
| 5321 | else |
| 5322 | request->match_sets = |
| 5323 | (void *)(request->channels + n_channels); |
| 5324 | } |
| 5325 | request->n_match_sets = n_match_sets; |
| 5326 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5327 | i = 0; |
| 5328 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5329 | /* user specified, bail out if channel not found */ |
| 5330 | nla_for_each_nested(attr, |
| 5331 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5332 | tmp) { |
| 5333 | struct ieee80211_channel *chan; |
| 5334 | |
| 5335 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5336 | |
| 5337 | if (!chan) { |
| 5338 | err = -EINVAL; |
| 5339 | goto out_free; |
| 5340 | } |
| 5341 | |
| 5342 | /* ignore disabled channels */ |
| 5343 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5344 | continue; |
| 5345 | |
| 5346 | request->channels[i] = chan; |
| 5347 | i++; |
| 5348 | } |
| 5349 | } else { |
| 5350 | /* all channels */ |
| 5351 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5352 | int j; |
| 5353 | if (!wiphy->bands[band]) |
| 5354 | continue; |
| 5355 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5356 | struct ieee80211_channel *chan; |
| 5357 | |
| 5358 | chan = &wiphy->bands[band]->channels[j]; |
| 5359 | |
| 5360 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5361 | continue; |
| 5362 | |
| 5363 | request->channels[i] = chan; |
| 5364 | i++; |
| 5365 | } |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | if (!i) { |
| 5370 | err = -EINVAL; |
| 5371 | goto out_free; |
| 5372 | } |
| 5373 | |
| 5374 | request->n_channels = i; |
| 5375 | |
| 5376 | i = 0; |
| 5377 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5378 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5379 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5380 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5381 | err = -EINVAL; |
| 5382 | goto out_free; |
| 5383 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5384 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5385 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5386 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5387 | i++; |
| 5388 | } |
| 5389 | } |
| 5390 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5391 | i = 0; |
| 5392 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5393 | nla_for_each_nested(attr, |
| 5394 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5395 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5396 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5397 | |
| 5398 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5399 | nla_data(attr), nla_len(attr), |
| 5400 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5401 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5402 | if (ssid) { |
| 5403 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5404 | err = -EINVAL; |
| 5405 | goto out_free; |
| 5406 | } |
| 5407 | memcpy(request->match_sets[i].ssid.ssid, |
| 5408 | nla_data(ssid), nla_len(ssid)); |
| 5409 | request->match_sets[i].ssid.ssid_len = |
| 5410 | nla_len(ssid); |
| 5411 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5412 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5413 | if (rssi) |
| 5414 | request->rssi_thold = nla_get_u32(rssi); |
| 5415 | else |
| 5416 | request->rssi_thold = |
| 5417 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5418 | i++; |
| 5419 | } |
| 5420 | } |
| 5421 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5422 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5423 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5424 | memcpy((void *)request->ie, |
| 5425 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5426 | request->ie_len); |
| 5427 | } |
| 5428 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5429 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5430 | request->flags = nla_get_u32( |
| 5431 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5432 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5433 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5434 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5435 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5436 | err = -EOPNOTSUPP; |
| 5437 | goto out_free; |
| 5438 | } |
| 5439 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5440 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5441 | request->dev = dev; |
| 5442 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5443 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5444 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5445 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5446 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5447 | if (!err) { |
| 5448 | rdev->sched_scan_req = request; |
| 5449 | nl80211_send_sched_scan(rdev, dev, |
| 5450 | NL80211_CMD_START_SCHED_SCAN); |
| 5451 | goto out; |
| 5452 | } |
| 5453 | |
| 5454 | out_free: |
| 5455 | kfree(request); |
| 5456 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5457 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5458 | return err; |
| 5459 | } |
| 5460 | |
| 5461 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5462 | struct genl_info *info) |
| 5463 | { |
| 5464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5465 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5466 | |
| 5467 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5468 | !rdev->ops->sched_scan_stop) |
| 5469 | return -EOPNOTSUPP; |
| 5470 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5471 | mutex_lock(&rdev->sched_scan_mtx); |
| 5472 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5473 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5474 | |
| 5475 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5476 | } |
| 5477 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5478 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5479 | struct genl_info *info) |
| 5480 | { |
| 5481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5482 | struct net_device *dev = info->user_ptr[1]; |
| 5483 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5484 | struct cfg80211_chan_def chandef; |
| 5485 | int err; |
| 5486 | |
| 5487 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5488 | if (err) |
| 5489 | return err; |
| 5490 | |
| 5491 | if (wdev->cac_started) |
| 5492 | return -EBUSY; |
| 5493 | |
| 5494 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5495 | if (err < 0) |
| 5496 | return err; |
| 5497 | |
| 5498 | if (err == 0) |
| 5499 | return -EINVAL; |
| 5500 | |
| 5501 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5502 | return -EINVAL; |
| 5503 | |
| 5504 | if (!rdev->ops->start_radar_detection) |
| 5505 | return -EOPNOTSUPP; |
| 5506 | |
| 5507 | mutex_lock(&rdev->devlist_mtx); |
| 5508 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5509 | chandef.chan, CHAN_MODE_SHARED, |
| 5510 | BIT(chandef.width)); |
| 5511 | if (err) |
| 5512 | goto err_locked; |
| 5513 | |
| 5514 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5515 | if (!err) { |
| 5516 | wdev->channel = chandef.chan; |
| 5517 | wdev->cac_started = true; |
| 5518 | wdev->cac_start_time = jiffies; |
| 5519 | } |
| 5520 | err_locked: |
| 5521 | mutex_unlock(&rdev->devlist_mtx); |
| 5522 | |
| 5523 | return err; |
| 5524 | } |
| 5525 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5526 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5527 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5528 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5529 | struct wireless_dev *wdev, |
| 5530 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5531 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5532 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5533 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5534 | void *hdr; |
| 5535 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5536 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5537 | |
| 5538 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5539 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5540 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5541 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5542 | if (!hdr) |
| 5543 | return -1; |
| 5544 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5545 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5546 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5547 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5548 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5549 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5550 | |
| 5551 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5552 | if (!bss) |
| 5553 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5554 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5555 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5556 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5557 | |
| 5558 | rcu_read_lock(); |
| 5559 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5560 | if (ies) { |
| 5561 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5562 | goto fail_unlock_rcu; |
| 5563 | tsf = true; |
| 5564 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5565 | ies->len, ies->data)) |
| 5566 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5567 | } |
| 5568 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5569 | if (ies) { |
| 5570 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5571 | goto fail_unlock_rcu; |
| 5572 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5573 | ies->len, ies->data)) |
| 5574 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5575 | } |
| 5576 | rcu_read_unlock(); |
| 5577 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5578 | if (res->beacon_interval && |
| 5579 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5580 | goto nla_put_failure; |
| 5581 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5582 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5583 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5584 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5585 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5586 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5587 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5588 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5589 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5590 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5591 | break; |
| 5592 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5593 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5594 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5595 | break; |
| 5596 | default: |
| 5597 | break; |
| 5598 | } |
| 5599 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5600 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5601 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5602 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5603 | if (intbss == wdev->current_bss && |
| 5604 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5605 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5606 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5607 | break; |
| 5608 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5609 | if (intbss == wdev->current_bss && |
| 5610 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5611 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5612 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5613 | break; |
| 5614 | default: |
| 5615 | break; |
| 5616 | } |
| 5617 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5618 | nla_nest_end(msg, bss); |
| 5619 | |
| 5620 | return genlmsg_end(msg, hdr); |
| 5621 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5622 | fail_unlock_rcu: |
| 5623 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5624 | nla_put_failure: |
| 5625 | genlmsg_cancel(msg, hdr); |
| 5626 | return -EMSGSIZE; |
| 5627 | } |
| 5628 | |
| 5629 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5630 | struct netlink_callback *cb) |
| 5631 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5632 | struct cfg80211_registered_device *rdev; |
| 5633 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5634 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5635 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5636 | int start = cb->args[1], idx = 0; |
| 5637 | int err; |
| 5638 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5639 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5640 | if (err) |
| 5641 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5642 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5643 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5644 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5645 | wdev_lock(wdev); |
| 5646 | spin_lock_bh(&rdev->bss_lock); |
| 5647 | cfg80211_bss_expire(rdev); |
| 5648 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5649 | cb->seq = rdev->bss_generation; |
| 5650 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5651 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5652 | if (++idx <= start) |
| 5653 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5654 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5655 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5656 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5657 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5658 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5659 | } |
| 5660 | } |
| 5661 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5662 | spin_unlock_bh(&rdev->bss_lock); |
| 5663 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5664 | |
| 5665 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5666 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5667 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5668 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5669 | } |
| 5670 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5671 | 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] | 5672 | int flags, struct net_device *dev, |
| 5673 | struct survey_info *survey) |
| 5674 | { |
| 5675 | void *hdr; |
| 5676 | struct nlattr *infoattr; |
| 5677 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5678 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5679 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5680 | if (!hdr) |
| 5681 | return -ENOMEM; |
| 5682 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5683 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5684 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5685 | |
| 5686 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5687 | if (!infoattr) |
| 5688 | goto nla_put_failure; |
| 5689 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5690 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5691 | survey->channel->center_freq)) |
| 5692 | goto nla_put_failure; |
| 5693 | |
| 5694 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5695 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5696 | goto nla_put_failure; |
| 5697 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5698 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5699 | goto nla_put_failure; |
| 5700 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5701 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5702 | survey->channel_time)) |
| 5703 | goto nla_put_failure; |
| 5704 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5705 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5706 | survey->channel_time_busy)) |
| 5707 | goto nla_put_failure; |
| 5708 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5709 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5710 | survey->channel_time_ext_busy)) |
| 5711 | goto nla_put_failure; |
| 5712 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5713 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5714 | survey->channel_time_rx)) |
| 5715 | goto nla_put_failure; |
| 5716 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5717 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5718 | survey->channel_time_tx)) |
| 5719 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5720 | |
| 5721 | nla_nest_end(msg, infoattr); |
| 5722 | |
| 5723 | return genlmsg_end(msg, hdr); |
| 5724 | |
| 5725 | nla_put_failure: |
| 5726 | genlmsg_cancel(msg, hdr); |
| 5727 | return -EMSGSIZE; |
| 5728 | } |
| 5729 | |
| 5730 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5731 | struct netlink_callback *cb) |
| 5732 | { |
| 5733 | struct survey_info survey; |
| 5734 | struct cfg80211_registered_device *dev; |
| 5735 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5736 | int survey_idx = cb->args[1]; |
| 5737 | int res; |
| 5738 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5739 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5740 | if (res) |
| 5741 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5742 | |
| 5743 | if (!dev->ops->dump_survey) { |
| 5744 | res = -EOPNOTSUPP; |
| 5745 | goto out_err; |
| 5746 | } |
| 5747 | |
| 5748 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5749 | struct ieee80211_channel *chan; |
| 5750 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5751 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5752 | if (res == -ENOENT) |
| 5753 | break; |
| 5754 | if (res) |
| 5755 | goto out_err; |
| 5756 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5757 | /* Survey without a channel doesn't make sense */ |
| 5758 | if (!survey.channel) { |
| 5759 | res = -EINVAL; |
| 5760 | goto out; |
| 5761 | } |
| 5762 | |
| 5763 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5764 | survey.channel->center_freq); |
| 5765 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5766 | survey_idx++; |
| 5767 | continue; |
| 5768 | } |
| 5769 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5770 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5771 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5772 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5773 | netdev, |
| 5774 | &survey) < 0) |
| 5775 | goto out; |
| 5776 | survey_idx++; |
| 5777 | } |
| 5778 | |
| 5779 | out: |
| 5780 | cb->args[1] = survey_idx; |
| 5781 | res = skb->len; |
| 5782 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5783 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5784 | return res; |
| 5785 | } |
| 5786 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5787 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5788 | { |
| 5789 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5790 | NL80211_WPA_VERSION_2)); |
| 5791 | } |
| 5792 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5793 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5794 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5796 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5797 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5798 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5799 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5800 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5801 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5802 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5803 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5804 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5805 | return -EINVAL; |
| 5806 | |
| 5807 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5808 | return -EINVAL; |
| 5809 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5810 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5811 | return -EINVAL; |
| 5812 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5813 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5814 | return -EINVAL; |
| 5815 | |
| 5816 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5817 | return -EINVAL; |
| 5818 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5819 | err = nl80211_parse_key(info, &key); |
| 5820 | if (err) |
| 5821 | return err; |
| 5822 | |
| 5823 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5824 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5825 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5826 | if (!key.p.key || !key.p.key_len) |
| 5827 | return -EINVAL; |
| 5828 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5829 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5830 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5831 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5832 | return -EINVAL; |
| 5833 | if (key.idx > 4) |
| 5834 | return -EINVAL; |
| 5835 | } else { |
| 5836 | key.p.key_len = 0; |
| 5837 | key.p.key = NULL; |
| 5838 | } |
| 5839 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5840 | if (key.idx >= 0) { |
| 5841 | int i; |
| 5842 | bool ok = false; |
| 5843 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5844 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5845 | ok = true; |
| 5846 | break; |
| 5847 | } |
| 5848 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5849 | if (!ok) |
| 5850 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5851 | } |
| 5852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5853 | if (!rdev->ops->auth) |
| 5854 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5855 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5856 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5857 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5858 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5859 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5860 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5861 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5862 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5863 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5864 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5865 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5866 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5867 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5868 | |
| 5869 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5870 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5871 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5872 | } |
| 5873 | |
| 5874 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5875 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5876 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5877 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5878 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5879 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5880 | return -EINVAL; |
| 5881 | |
| 5882 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5883 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5884 | return -EINVAL; |
| 5885 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5886 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5887 | /* need to include at least Auth Transaction and Status Code */ |
| 5888 | if (sae_data_len < 4) |
| 5889 | return -EINVAL; |
| 5890 | } |
| 5891 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5892 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5893 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5894 | /* |
| 5895 | * Since we no longer track auth state, ignore |
| 5896 | * requests to only change local state. |
| 5897 | */ |
| 5898 | if (local_state_change) |
| 5899 | return 0; |
| 5900 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5901 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5902 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5903 | key.p.key, key.p.key_len, key.idx, |
| 5904 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5905 | } |
| 5906 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5907 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5908 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5909 | struct cfg80211_crypto_settings *settings, |
| 5910 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5911 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5912 | memset(settings, 0, sizeof(*settings)); |
| 5913 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5914 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5915 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5916 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5917 | u16 proto; |
| 5918 | proto = nla_get_u16( |
| 5919 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5920 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5921 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5922 | proto != ETH_P_PAE) |
| 5923 | return -EINVAL; |
| 5924 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5925 | settings->control_port_no_encrypt = true; |
| 5926 | } else |
| 5927 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5928 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5929 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5930 | void *data; |
| 5931 | int len, i; |
| 5932 | |
| 5933 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5934 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5935 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5936 | |
| 5937 | if (len % sizeof(u32)) |
| 5938 | return -EINVAL; |
| 5939 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5940 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5941 | return -EINVAL; |
| 5942 | |
| 5943 | memcpy(settings->ciphers_pairwise, data, len); |
| 5944 | |
| 5945 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5946 | if (!cfg80211_supported_cipher_suite( |
| 5947 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5948 | settings->ciphers_pairwise[i])) |
| 5949 | return -EINVAL; |
| 5950 | } |
| 5951 | |
| 5952 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5953 | settings->cipher_group = |
| 5954 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5955 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5956 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5957 | return -EINVAL; |
| 5958 | } |
| 5959 | |
| 5960 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5961 | settings->wpa_versions = |
| 5962 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5963 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5964 | return -EINVAL; |
| 5965 | } |
| 5966 | |
| 5967 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5968 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5969 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5970 | |
| 5971 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5972 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5973 | settings->n_akm_suites = len / sizeof(u32); |
| 5974 | |
| 5975 | if (len % sizeof(u32)) |
| 5976 | return -EINVAL; |
| 5977 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5978 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5979 | return -EINVAL; |
| 5980 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5981 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | return 0; |
| 5985 | } |
| 5986 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5987 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5988 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5990 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5991 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 5992 | struct cfg80211_assoc_request req = {}; |
| 5993 | const u8 *bssid, *ssid; |
| 5994 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5995 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5996 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5997 | return -EINVAL; |
| 5998 | |
| 5999 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6000 | !info->attrs[NL80211_ATTR_SSID] || |
| 6001 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6002 | return -EINVAL; |
| 6003 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6004 | if (!rdev->ops->assoc) |
| 6005 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6006 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6007 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6009 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6010 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6011 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6012 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6013 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6014 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6015 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6016 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6017 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6018 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6019 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6020 | |
| 6021 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6022 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6023 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6024 | } |
| 6025 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6026 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6027 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6028 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6029 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6030 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6031 | else if (mfp != NL80211_MFP_NO) |
| 6032 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6033 | } |
| 6034 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6035 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6036 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6037 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6038 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6039 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6040 | |
| 6041 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6042 | memcpy(&req.ht_capa_mask, |
| 6043 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6044 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6045 | |
| 6046 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6047 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6048 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6049 | memcpy(&req.ht_capa, |
| 6050 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6051 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6052 | } |
| 6053 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6054 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6055 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6056 | |
| 6057 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6058 | memcpy(&req.vht_capa_mask, |
| 6059 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6060 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6061 | |
| 6062 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6063 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6064 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6065 | memcpy(&req.vht_capa, |
| 6066 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6067 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6068 | } |
| 6069 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6070 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6071 | if (!err) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6072 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6073 | ssid, ssid_len, &req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6074 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6075 | return err; |
| 6076 | } |
| 6077 | |
| 6078 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6079 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6081 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6082 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6083 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6084 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6085 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6086 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6087 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6088 | return -EINVAL; |
| 6089 | |
| 6090 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6091 | return -EINVAL; |
| 6092 | |
| 6093 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6094 | return -EINVAL; |
| 6095 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6096 | if (!rdev->ops->deauth) |
| 6097 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6098 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6099 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6100 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6101 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6102 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6103 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6104 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6105 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6106 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6107 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6108 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6109 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6110 | |
| 6111 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6112 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6113 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6114 | } |
| 6115 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6116 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6118 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6119 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6123 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6125 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6126 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6127 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6128 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6129 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6130 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6131 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6132 | return -EINVAL; |
| 6133 | |
| 6134 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6135 | return -EINVAL; |
| 6136 | |
| 6137 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6138 | return -EINVAL; |
| 6139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6140 | if (!rdev->ops->disassoc) |
| 6141 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6142 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6143 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6144 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6145 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6146 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6147 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6148 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6149 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6150 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6151 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6153 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6154 | |
| 6155 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6156 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6157 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6158 | } |
| 6159 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6160 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6161 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6162 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6163 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6164 | } |
| 6165 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6166 | static bool |
| 6167 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6168 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6169 | int rateval) |
| 6170 | { |
| 6171 | struct wiphy *wiphy = &rdev->wiphy; |
| 6172 | bool found = false; |
| 6173 | int band, i; |
| 6174 | |
| 6175 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6176 | struct ieee80211_supported_band *sband; |
| 6177 | |
| 6178 | sband = wiphy->bands[band]; |
| 6179 | if (!sband) |
| 6180 | continue; |
| 6181 | |
| 6182 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6183 | if (sband->bitrates[i].bitrate == rateval) { |
| 6184 | mcast_rate[band] = i + 1; |
| 6185 | found = true; |
| 6186 | break; |
| 6187 | } |
| 6188 | } |
| 6189 | } |
| 6190 | |
| 6191 | return found; |
| 6192 | } |
| 6193 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6194 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6195 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6197 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6198 | struct cfg80211_ibss_params ibss; |
| 6199 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6200 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6201 | int err; |
| 6202 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6203 | memset(&ibss, 0, sizeof(ibss)); |
| 6204 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6205 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6206 | return -EINVAL; |
| 6207 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6208 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6209 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6210 | return -EINVAL; |
| 6211 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6212 | ibss.beacon_interval = 100; |
| 6213 | |
| 6214 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6215 | ibss.beacon_interval = |
| 6216 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6217 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6218 | return -EINVAL; |
| 6219 | } |
| 6220 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6221 | if (!rdev->ops->join_ibss) |
| 6222 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6224 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6225 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6226 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6227 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6228 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6229 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6230 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6231 | |
| 6232 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6233 | return -EINVAL; |
| 6234 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6235 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6236 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6237 | |
| 6238 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6239 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6240 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6241 | } |
| 6242 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6243 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6244 | if (err) |
| 6245 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6246 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6247 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6248 | return -EINVAL; |
| 6249 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6250 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 6251 | return -EINVAL; |
| 6252 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 6253 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 6254 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6255 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6256 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6257 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6258 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6259 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6260 | u8 *rates = |
| 6261 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6262 | int n_rates = |
| 6263 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6264 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6265 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6266 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6267 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6268 | &ibss.basic_rates); |
| 6269 | if (err) |
| 6270 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6271 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6272 | |
| 6273 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6274 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6275 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6276 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6277 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6278 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6279 | bool no_ht = false; |
| 6280 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6281 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6282 | info->attrs[NL80211_ATTR_KEYS], |
| 6283 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6284 | if (IS_ERR(connkeys)) |
| 6285 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6286 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6287 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6288 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6289 | kfree(connkeys); |
| 6290 | return -EINVAL; |
| 6291 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6292 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6293 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6294 | ibss.control_port = |
| 6295 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6297 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6298 | if (err) |
| 6299 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6300 | return err; |
| 6301 | } |
| 6302 | |
| 6303 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6304 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6306 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6307 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6308 | if (!rdev->ops->leave_ibss) |
| 6309 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6310 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6311 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6312 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6314 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6315 | } |
| 6316 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6317 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6318 | { |
| 6319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6320 | struct net_device *dev = info->user_ptr[1]; |
| 6321 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6322 | u32 nla_rate; |
| 6323 | int err; |
| 6324 | |
| 6325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6326 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6327 | return -EOPNOTSUPP; |
| 6328 | |
| 6329 | if (!rdev->ops->set_mcast_rate) |
| 6330 | return -EOPNOTSUPP; |
| 6331 | |
| 6332 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6333 | |
| 6334 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6335 | return -EINVAL; |
| 6336 | |
| 6337 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6338 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6339 | return -EINVAL; |
| 6340 | |
| 6341 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6342 | |
| 6343 | return err; |
| 6344 | } |
| 6345 | |
| 6346 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6347 | #ifdef CONFIG_NL80211_TESTMODE |
| 6348 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6349 | .name = "testmode", |
| 6350 | }; |
| 6351 | |
| 6352 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6355 | int err; |
| 6356 | |
| 6357 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6358 | return -EINVAL; |
| 6359 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6360 | err = -EOPNOTSUPP; |
| 6361 | if (rdev->ops->testmode_cmd) { |
| 6362 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6363 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6364 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6365 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6366 | rdev->testmode_info = NULL; |
| 6367 | } |
| 6368 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6369 | return err; |
| 6370 | } |
| 6371 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6372 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6373 | struct netlink_callback *cb) |
| 6374 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6375 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6376 | int err; |
| 6377 | long phy_idx; |
| 6378 | void *data = NULL; |
| 6379 | int data_len = 0; |
| 6380 | |
| 6381 | if (cb->args[0]) { |
| 6382 | /* |
| 6383 | * 0 is a valid index, but not valid for args[0], |
| 6384 | * so we need to offset by 1. |
| 6385 | */ |
| 6386 | phy_idx = cb->args[0] - 1; |
| 6387 | } else { |
| 6388 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6389 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6390 | nl80211_policy); |
| 6391 | if (err) |
| 6392 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6393 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6394 | mutex_lock(&cfg80211_mutex); |
| 6395 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6396 | nl80211_fam.attrbuf); |
| 6397 | if (IS_ERR(rdev)) { |
| 6398 | mutex_unlock(&cfg80211_mutex); |
| 6399 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6400 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6401 | phy_idx = rdev->wiphy_idx; |
| 6402 | rdev = NULL; |
| 6403 | mutex_unlock(&cfg80211_mutex); |
| 6404 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6405 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6406 | cb->args[1] = |
| 6407 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6408 | } |
| 6409 | |
| 6410 | if (cb->args[1]) { |
| 6411 | data = nla_data((void *)cb->args[1]); |
| 6412 | data_len = nla_len((void *)cb->args[1]); |
| 6413 | } |
| 6414 | |
| 6415 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6416 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6417 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6418 | mutex_unlock(&cfg80211_mutex); |
| 6419 | return -ENOENT; |
| 6420 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6421 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6422 | mutex_unlock(&cfg80211_mutex); |
| 6423 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6424 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6425 | err = -EOPNOTSUPP; |
| 6426 | goto out_err; |
| 6427 | } |
| 6428 | |
| 6429 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6430 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6431 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6432 | NL80211_CMD_TESTMODE); |
| 6433 | struct nlattr *tmdata; |
| 6434 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6435 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6436 | genlmsg_cancel(skb, hdr); |
| 6437 | break; |
| 6438 | } |
| 6439 | |
| 6440 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6441 | if (!tmdata) { |
| 6442 | genlmsg_cancel(skb, hdr); |
| 6443 | break; |
| 6444 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6445 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6446 | nla_nest_end(skb, tmdata); |
| 6447 | |
| 6448 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6449 | genlmsg_cancel(skb, hdr); |
| 6450 | break; |
| 6451 | } else if (err) { |
| 6452 | genlmsg_cancel(skb, hdr); |
| 6453 | goto out_err; |
| 6454 | } |
| 6455 | |
| 6456 | genlmsg_end(skb, hdr); |
| 6457 | } |
| 6458 | |
| 6459 | err = skb->len; |
| 6460 | /* see above */ |
| 6461 | cb->args[0] = phy_idx + 1; |
| 6462 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6463 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6464 | return err; |
| 6465 | } |
| 6466 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6467 | static struct sk_buff * |
| 6468 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6469 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6470 | { |
| 6471 | struct sk_buff *skb; |
| 6472 | void *hdr; |
| 6473 | struct nlattr *data; |
| 6474 | |
| 6475 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6476 | if (!skb) |
| 6477 | return NULL; |
| 6478 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6479 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6480 | if (!hdr) { |
| 6481 | kfree_skb(skb); |
| 6482 | return NULL; |
| 6483 | } |
| 6484 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6485 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6486 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6487 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6488 | |
| 6489 | ((void **)skb->cb)[0] = rdev; |
| 6490 | ((void **)skb->cb)[1] = hdr; |
| 6491 | ((void **)skb->cb)[2] = data; |
| 6492 | |
| 6493 | return skb; |
| 6494 | |
| 6495 | nla_put_failure: |
| 6496 | kfree_skb(skb); |
| 6497 | return NULL; |
| 6498 | } |
| 6499 | |
| 6500 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6501 | int approxlen) |
| 6502 | { |
| 6503 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6504 | |
| 6505 | if (WARN_ON(!rdev->testmode_info)) |
| 6506 | return NULL; |
| 6507 | |
| 6508 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6509 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6510 | rdev->testmode_info->snd_seq, |
| 6511 | GFP_KERNEL); |
| 6512 | } |
| 6513 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6514 | |
| 6515 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6516 | { |
| 6517 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6518 | void *hdr = ((void **)skb->cb)[1]; |
| 6519 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6520 | |
| 6521 | if (WARN_ON(!rdev->testmode_info)) { |
| 6522 | kfree_skb(skb); |
| 6523 | return -EINVAL; |
| 6524 | } |
| 6525 | |
| 6526 | nla_nest_end(skb, data); |
| 6527 | genlmsg_end(skb, hdr); |
| 6528 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6529 | } |
| 6530 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6531 | |
| 6532 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6533 | int approxlen, gfp_t gfp) |
| 6534 | { |
| 6535 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6536 | |
| 6537 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6538 | } |
| 6539 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6540 | |
| 6541 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6542 | { |
| 6543 | void *hdr = ((void **)skb->cb)[1]; |
| 6544 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6545 | |
| 6546 | nla_nest_end(skb, data); |
| 6547 | genlmsg_end(skb, hdr); |
| 6548 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6549 | } |
| 6550 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6551 | #endif |
| 6552 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6553 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6554 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6556 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6557 | struct cfg80211_connect_params connect; |
| 6558 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6559 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6560 | int err; |
| 6561 | |
| 6562 | memset(&connect, 0, sizeof(connect)); |
| 6563 | |
| 6564 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6565 | return -EINVAL; |
| 6566 | |
| 6567 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6568 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6569 | return -EINVAL; |
| 6570 | |
| 6571 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6572 | connect.auth_type = |
| 6573 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6574 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6575 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6576 | return -EINVAL; |
| 6577 | } else |
| 6578 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6579 | |
| 6580 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6581 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6582 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6583 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6584 | if (err) |
| 6585 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6586 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6587 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6588 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6589 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6590 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6591 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6592 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6593 | connect.bg_scan_period = -1; |
| 6594 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6595 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6596 | connect.bg_scan_period = |
| 6597 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6598 | } |
| 6599 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6600 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6601 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6602 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6603 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6604 | |
| 6605 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6606 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6607 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6608 | } |
| 6609 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6610 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6611 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6612 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6613 | connect.mfp != NL80211_MFP_NO) |
| 6614 | return -EINVAL; |
| 6615 | } else { |
| 6616 | connect.mfp = NL80211_MFP_NO; |
| 6617 | } |
| 6618 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6619 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6620 | connect.channel = |
| 6621 | ieee80211_get_channel(wiphy, |
| 6622 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6623 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6624 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6625 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6626 | } |
| 6627 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6628 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6629 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6630 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6631 | if (IS_ERR(connkeys)) |
| 6632 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6633 | } |
| 6634 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6635 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6636 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6637 | |
| 6638 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6639 | memcpy(&connect.ht_capa_mask, |
| 6640 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6641 | sizeof(connect.ht_capa_mask)); |
| 6642 | |
| 6643 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6644 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6645 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6646 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6647 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6648 | memcpy(&connect.ht_capa, |
| 6649 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6650 | sizeof(connect.ht_capa)); |
| 6651 | } |
| 6652 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6653 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6654 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6655 | |
| 6656 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6657 | memcpy(&connect.vht_capa_mask, |
| 6658 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6659 | sizeof(connect.vht_capa_mask)); |
| 6660 | |
| 6661 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6662 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6663 | kfree(connkeys); |
| 6664 | return -EINVAL; |
| 6665 | } |
| 6666 | memcpy(&connect.vht_capa, |
| 6667 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6668 | sizeof(connect.vht_capa)); |
| 6669 | } |
| 6670 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6671 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6672 | if (err) |
| 6673 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6674 | return err; |
| 6675 | } |
| 6676 | |
| 6677 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6678 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6679 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6680 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6681 | u16 reason; |
| 6682 | |
| 6683 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6684 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6685 | else |
| 6686 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6687 | |
| 6688 | if (reason == 0) |
| 6689 | return -EINVAL; |
| 6690 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6691 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6692 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6693 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6694 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6695 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6696 | } |
| 6697 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6698 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6701 | struct net *net; |
| 6702 | int err; |
| 6703 | u32 pid; |
| 6704 | |
| 6705 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6706 | return -EINVAL; |
| 6707 | |
| 6708 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6709 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6710 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6711 | if (IS_ERR(net)) |
| 6712 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6713 | |
| 6714 | err = 0; |
| 6715 | |
| 6716 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6717 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6718 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6719 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6720 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6721 | return err; |
| 6722 | } |
| 6723 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6724 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6725 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6727 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6728 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6729 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6730 | struct cfg80211_pmksa pmksa; |
| 6731 | |
| 6732 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6733 | |
| 6734 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6735 | return -EINVAL; |
| 6736 | |
| 6737 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6738 | return -EINVAL; |
| 6739 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6740 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6741 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6742 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6743 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6744 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6745 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6746 | |
| 6747 | switch (info->genlhdr->cmd) { |
| 6748 | case NL80211_CMD_SET_PMKSA: |
| 6749 | rdev_ops = rdev->ops->set_pmksa; |
| 6750 | break; |
| 6751 | case NL80211_CMD_DEL_PMKSA: |
| 6752 | rdev_ops = rdev->ops->del_pmksa; |
| 6753 | break; |
| 6754 | default: |
| 6755 | WARN_ON(1); |
| 6756 | break; |
| 6757 | } |
| 6758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6759 | if (!rdev_ops) |
| 6760 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6762 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6766 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6768 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 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 | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6774 | if (!rdev->ops->flush_pmksa) |
| 6775 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6776 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6777 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6778 | } |
| 6779 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6780 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6781 | { |
| 6782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6783 | struct net_device *dev = info->user_ptr[1]; |
| 6784 | u8 action_code, dialog_token; |
| 6785 | u16 status_code; |
| 6786 | u8 *peer; |
| 6787 | |
| 6788 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6789 | !rdev->ops->tdls_mgmt) |
| 6790 | return -EOPNOTSUPP; |
| 6791 | |
| 6792 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6793 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6794 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6795 | !info->attrs[NL80211_ATTR_IE] || |
| 6796 | !info->attrs[NL80211_ATTR_MAC]) |
| 6797 | return -EINVAL; |
| 6798 | |
| 6799 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6800 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6801 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6802 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6803 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6804 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6805 | dialog_token, status_code, |
| 6806 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6807 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6811 | { |
| 6812 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6813 | struct net_device *dev = info->user_ptr[1]; |
| 6814 | enum nl80211_tdls_operation operation; |
| 6815 | u8 *peer; |
| 6816 | |
| 6817 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6818 | !rdev->ops->tdls_oper) |
| 6819 | return -EOPNOTSUPP; |
| 6820 | |
| 6821 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6822 | !info->attrs[NL80211_ATTR_MAC]) |
| 6823 | return -EINVAL; |
| 6824 | |
| 6825 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6826 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6827 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6828 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6829 | } |
| 6830 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6831 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6832 | struct genl_info *info) |
| 6833 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6835 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6836 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6837 | struct sk_buff *msg; |
| 6838 | void *hdr; |
| 6839 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6840 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6841 | int err; |
| 6842 | |
| 6843 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6844 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6845 | return -EINVAL; |
| 6846 | |
| 6847 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6848 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6849 | if (!rdev->ops->remain_on_channel || |
| 6850 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6851 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6852 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6853 | /* |
| 6854 | * We should be on that channel for at least a minimum amount of |
| 6855 | * time (10ms) but no longer than the driver supports. |
| 6856 | */ |
| 6857 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6858 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6859 | return -EINVAL; |
| 6860 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6861 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6862 | if (err) |
| 6863 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6864 | |
| 6865 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6866 | if (!msg) |
| 6867 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6868 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6869 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6870 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6871 | |
| 6872 | if (IS_ERR(hdr)) { |
| 6873 | err = PTR_ERR(hdr); |
| 6874 | goto free_msg; |
| 6875 | } |
| 6876 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6877 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6878 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6879 | |
| 6880 | if (err) |
| 6881 | goto free_msg; |
| 6882 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6883 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6884 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6885 | |
| 6886 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6887 | |
| 6888 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6889 | |
| 6890 | nla_put_failure: |
| 6891 | err = -ENOBUFS; |
| 6892 | free_msg: |
| 6893 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6894 | return err; |
| 6895 | } |
| 6896 | |
| 6897 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6898 | struct genl_info *info) |
| 6899 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6901 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6902 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6903 | |
| 6904 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6905 | return -EINVAL; |
| 6906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6907 | if (!rdev->ops->cancel_remain_on_channel) |
| 6908 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6909 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6910 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6911 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6912 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6913 | } |
| 6914 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6915 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6916 | u8 *rates, u8 rates_len) |
| 6917 | { |
| 6918 | u8 i; |
| 6919 | u32 mask = 0; |
| 6920 | |
| 6921 | for (i = 0; i < rates_len; i++) { |
| 6922 | int rate = (rates[i] & 0x7f) * 5; |
| 6923 | int ridx; |
| 6924 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6925 | struct ieee80211_rate *srate = |
| 6926 | &sband->bitrates[ridx]; |
| 6927 | if (rate == srate->bitrate) { |
| 6928 | mask |= 1 << ridx; |
| 6929 | break; |
| 6930 | } |
| 6931 | } |
| 6932 | if (ridx == sband->n_bitrates) |
| 6933 | return 0; /* rate not found */ |
| 6934 | } |
| 6935 | |
| 6936 | return mask; |
| 6937 | } |
| 6938 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6939 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6940 | u8 *rates, u8 rates_len, |
| 6941 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6942 | { |
| 6943 | u8 i; |
| 6944 | |
| 6945 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6946 | |
| 6947 | for (i = 0; i < rates_len; i++) { |
| 6948 | int ridx, rbit; |
| 6949 | |
| 6950 | ridx = rates[i] / 8; |
| 6951 | rbit = BIT(rates[i] % 8); |
| 6952 | |
| 6953 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6954 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6955 | return false; |
| 6956 | |
| 6957 | /* check availability */ |
| 6958 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6959 | mcs[ridx] |= rbit; |
| 6960 | else |
| 6961 | return false; |
| 6962 | } |
| 6963 | |
| 6964 | return true; |
| 6965 | } |
| 6966 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6967 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6968 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6969 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6970 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6971 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6972 | }; |
| 6973 | |
| 6974 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6975 | struct genl_info *info) |
| 6976 | { |
| 6977 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6979 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6980 | int rem, i; |
| 6981 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6982 | struct nlattr *tx_rates; |
| 6983 | struct ieee80211_supported_band *sband; |
| 6984 | |
| 6985 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6986 | return -EINVAL; |
| 6987 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6988 | if (!rdev->ops->set_bitrate_mask) |
| 6989 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6990 | |
| 6991 | memset(&mask, 0, sizeof(mask)); |
| 6992 | /* Default to all rates enabled */ |
| 6993 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6994 | sband = rdev->wiphy.bands[i]; |
| 6995 | mask.control[i].legacy = |
| 6996 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6997 | if (sband) |
| 6998 | memcpy(mask.control[i].mcs, |
| 6999 | sband->ht_cap.mcs.rx_mask, |
| 7000 | sizeof(mask.control[i].mcs)); |
| 7001 | else |
| 7002 | memset(mask.control[i].mcs, 0, |
| 7003 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | /* |
| 7007 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7008 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7009 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7010 | 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] | 7011 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7012 | { |
| 7013 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7014 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7015 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7016 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7017 | if (sband == NULL) |
| 7018 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7019 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7020 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7021 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7022 | mask.control[band].legacy = rateset_to_mask( |
| 7023 | sband, |
| 7024 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7025 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7026 | if ((mask.control[band].legacy == 0) && |
| 7027 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7028 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7029 | } |
| 7030 | if (tb[NL80211_TXRATE_MCS]) { |
| 7031 | if (!ht_rateset_to_mask( |
| 7032 | sband, |
| 7033 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7034 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7035 | mask.control[band].mcs)) |
| 7036 | return -EINVAL; |
| 7037 | } |
| 7038 | |
| 7039 | if (mask.control[band].legacy == 0) { |
| 7040 | /* don't allow empty legacy rates if HT |
| 7041 | * is not even supported. */ |
| 7042 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7043 | return -EINVAL; |
| 7044 | |
| 7045 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7046 | if (mask.control[band].mcs[i]) |
| 7047 | break; |
| 7048 | |
| 7049 | /* legacy and mcs rates may not be both empty */ |
| 7050 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7051 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7052 | } |
| 7053 | } |
| 7054 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7055 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7056 | } |
| 7057 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7058 | 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] | 7059 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7060 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7061 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7062 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7063 | |
| 7064 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7065 | return -EINVAL; |
| 7066 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7067 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7068 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7069 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7070 | switch (wdev->iftype) { |
| 7071 | case NL80211_IFTYPE_STATION: |
| 7072 | case NL80211_IFTYPE_ADHOC: |
| 7073 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7074 | case NL80211_IFTYPE_AP: |
| 7075 | case NL80211_IFTYPE_AP_VLAN: |
| 7076 | case NL80211_IFTYPE_MESH_POINT: |
| 7077 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7078 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7079 | break; |
| 7080 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7081 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7082 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7083 | |
| 7084 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7085 | if (!rdev->ops->mgmt_tx) |
| 7086 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7087 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7088 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7089 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7090 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7091 | } |
| 7092 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7093 | 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] | 7094 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7096 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7097 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7098 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7099 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7100 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7101 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7102 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7103 | bool offchan, no_cck, dont_wait_for_ack; |
| 7104 | |
| 7105 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7106 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7107 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7108 | return -EINVAL; |
| 7109 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7110 | if (!rdev->ops->mgmt_tx) |
| 7111 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7112 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7113 | switch (wdev->iftype) { |
| 7114 | case NL80211_IFTYPE_STATION: |
| 7115 | case NL80211_IFTYPE_ADHOC: |
| 7116 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7117 | case NL80211_IFTYPE_AP: |
| 7118 | case NL80211_IFTYPE_AP_VLAN: |
| 7119 | case NL80211_IFTYPE_MESH_POINT: |
| 7120 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7121 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7122 | break; |
| 7123 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7124 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7125 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7126 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7127 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7128 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7129 | return -EINVAL; |
| 7130 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7131 | |
| 7132 | /* |
| 7133 | * We should wait on the channel for at least a minimum amount |
| 7134 | * of time (10ms) but no longer than the driver supports. |
| 7135 | */ |
| 7136 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7137 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7138 | return -EINVAL; |
| 7139 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7140 | } |
| 7141 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7142 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7143 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7144 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7145 | return -EINVAL; |
| 7146 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7147 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7148 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7149 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7150 | if (err) |
| 7151 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7152 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7153 | if (!dont_wait_for_ack) { |
| 7154 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7155 | if (!msg) |
| 7156 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7157 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7158 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7159 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7160 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7161 | if (IS_ERR(hdr)) { |
| 7162 | err = PTR_ERR(hdr); |
| 7163 | goto free_msg; |
| 7164 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7165 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7166 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7167 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7168 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7169 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7170 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7171 | if (err) |
| 7172 | goto free_msg; |
| 7173 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7174 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7175 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7176 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7177 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7178 | genlmsg_end(msg, hdr); |
| 7179 | return genlmsg_reply(msg, info); |
| 7180 | } |
| 7181 | |
| 7182 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7183 | |
| 7184 | nla_put_failure: |
| 7185 | err = -ENOBUFS; |
| 7186 | free_msg: |
| 7187 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7188 | return err; |
| 7189 | } |
| 7190 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7191 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7192 | { |
| 7193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7194 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7195 | u64 cookie; |
| 7196 | |
| 7197 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7198 | return -EINVAL; |
| 7199 | |
| 7200 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7201 | return -EOPNOTSUPP; |
| 7202 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7203 | switch (wdev->iftype) { |
| 7204 | case NL80211_IFTYPE_STATION: |
| 7205 | case NL80211_IFTYPE_ADHOC: |
| 7206 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7207 | case NL80211_IFTYPE_AP: |
| 7208 | case NL80211_IFTYPE_AP_VLAN: |
| 7209 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7210 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7211 | break; |
| 7212 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7213 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7214 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7215 | |
| 7216 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7217 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7218 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7219 | } |
| 7220 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7221 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7222 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7224 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7225 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7226 | u8 ps_state; |
| 7227 | bool state; |
| 7228 | int err; |
| 7229 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7230 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7231 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7232 | |
| 7233 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7234 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7235 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7236 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7237 | |
| 7238 | wdev = dev->ieee80211_ptr; |
| 7239 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7240 | if (!rdev->ops->set_power_mgmt) |
| 7241 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7242 | |
| 7243 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7244 | |
| 7245 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7246 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7247 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7248 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7249 | if (!err) |
| 7250 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7251 | return err; |
| 7252 | } |
| 7253 | |
| 7254 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7255 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7257 | enum nl80211_ps_state ps_state; |
| 7258 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7259 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7260 | struct sk_buff *msg; |
| 7261 | void *hdr; |
| 7262 | int err; |
| 7263 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7264 | wdev = dev->ieee80211_ptr; |
| 7265 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7266 | if (!rdev->ops->set_power_mgmt) |
| 7267 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7268 | |
| 7269 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | if (!msg) |
| 7271 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7272 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7273 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7274 | NL80211_CMD_GET_POWER_SAVE); |
| 7275 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7276 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7277 | goto free_msg; |
| 7278 | } |
| 7279 | |
| 7280 | if (wdev->ps) |
| 7281 | ps_state = NL80211_PS_ENABLED; |
| 7282 | else |
| 7283 | ps_state = NL80211_PS_DISABLED; |
| 7284 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7285 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7286 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7287 | |
| 7288 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7289 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7291 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7292 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7293 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7294 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7295 | return err; |
| 7296 | } |
| 7297 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7298 | static struct nla_policy |
| 7299 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7300 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7301 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7302 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7303 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7304 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7305 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7306 | }; |
| 7307 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7308 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7309 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7310 | { |
| 7311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7312 | struct wireless_dev *wdev; |
| 7313 | struct net_device *dev = info->user_ptr[1]; |
| 7314 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7315 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7316 | return -EINVAL; |
| 7317 | |
| 7318 | wdev = dev->ieee80211_ptr; |
| 7319 | |
| 7320 | if (!rdev->ops->set_cqm_txe_config) |
| 7321 | return -EOPNOTSUPP; |
| 7322 | |
| 7323 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7324 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7325 | return -EOPNOTSUPP; |
| 7326 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7327 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7328 | } |
| 7329 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7330 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7331 | s32 threshold, u32 hysteresis) |
| 7332 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7334 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7335 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7336 | |
| 7337 | if (threshold > 0) |
| 7338 | return -EINVAL; |
| 7339 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7340 | wdev = dev->ieee80211_ptr; |
| 7341 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7342 | if (!rdev->ops->set_cqm_rssi_config) |
| 7343 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7344 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7345 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7346 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7347 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7348 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7349 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7350 | } |
| 7351 | |
| 7352 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7353 | { |
| 7354 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7355 | struct nlattr *cqm; |
| 7356 | int err; |
| 7357 | |
| 7358 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7359 | if (!cqm) { |
| 7360 | err = -EINVAL; |
| 7361 | goto out; |
| 7362 | } |
| 7363 | |
| 7364 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7365 | nl80211_attr_cqm_policy); |
| 7366 | if (err) |
| 7367 | goto out; |
| 7368 | |
| 7369 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7370 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7371 | s32 threshold; |
| 7372 | u32 hysteresis; |
| 7373 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7374 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7375 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7376 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7377 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7378 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7379 | u32 rate, pkts, intvl; |
| 7380 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7381 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7382 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7383 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7384 | } else |
| 7385 | err = -EINVAL; |
| 7386 | |
| 7387 | out: |
| 7388 | return err; |
| 7389 | } |
| 7390 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7391 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7392 | { |
| 7393 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7394 | struct net_device *dev = info->user_ptr[1]; |
| 7395 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7396 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7397 | int err; |
| 7398 | |
| 7399 | /* start with default */ |
| 7400 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7401 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7402 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7403 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7404 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7405 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7406 | if (err) |
| 7407 | return err; |
| 7408 | } |
| 7409 | |
| 7410 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7411 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7412 | return -EINVAL; |
| 7413 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7414 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7415 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7416 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7417 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7418 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7419 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7420 | return -EINVAL; |
| 7421 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7422 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7423 | setup.beacon_interval = |
| 7424 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7425 | if (setup.beacon_interval < 10 || |
| 7426 | setup.beacon_interval > 10000) |
| 7427 | return -EINVAL; |
| 7428 | } |
| 7429 | |
| 7430 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7431 | setup.dtim_period = |
| 7432 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7433 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7434 | return -EINVAL; |
| 7435 | } |
| 7436 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7437 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7438 | /* parse additional setup parameters if given */ |
| 7439 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7440 | if (err) |
| 7441 | return err; |
| 7442 | } |
| 7443 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7444 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7445 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7446 | if (err) |
| 7447 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7448 | } else { |
| 7449 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7450 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7451 | } |
| 7452 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7453 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7457 | { |
| 7458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7459 | struct net_device *dev = info->user_ptr[1]; |
| 7460 | |
| 7461 | return cfg80211_leave_mesh(rdev, dev); |
| 7462 | } |
| 7463 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7464 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7465 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7466 | struct cfg80211_registered_device *rdev) |
| 7467 | { |
| 7468 | struct nlattr *nl_pats, *nl_pat; |
| 7469 | int i, pat_len; |
| 7470 | |
| 7471 | if (!rdev->wowlan->n_patterns) |
| 7472 | return 0; |
| 7473 | |
| 7474 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7475 | if (!nl_pats) |
| 7476 | return -ENOBUFS; |
| 7477 | |
| 7478 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7479 | nl_pat = nla_nest_start(msg, i + 1); |
| 7480 | if (!nl_pat) |
| 7481 | return -ENOBUFS; |
| 7482 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7483 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7484 | DIV_ROUND_UP(pat_len, 8), |
| 7485 | rdev->wowlan->patterns[i].mask) || |
| 7486 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7487 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7488 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7489 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7490 | return -ENOBUFS; |
| 7491 | nla_nest_end(msg, nl_pat); |
| 7492 | } |
| 7493 | nla_nest_end(msg, nl_pats); |
| 7494 | |
| 7495 | return 0; |
| 7496 | } |
| 7497 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7498 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7499 | struct cfg80211_wowlan_tcp *tcp) |
| 7500 | { |
| 7501 | struct nlattr *nl_tcp; |
| 7502 | |
| 7503 | if (!tcp) |
| 7504 | return 0; |
| 7505 | |
| 7506 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7507 | if (!nl_tcp) |
| 7508 | return -ENOBUFS; |
| 7509 | |
| 7510 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7511 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7512 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7513 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7514 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7515 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7516 | tcp->payload_len, tcp->payload) || |
| 7517 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7518 | tcp->data_interval) || |
| 7519 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7520 | tcp->wake_len, tcp->wake_data) || |
| 7521 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7522 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7523 | return -ENOBUFS; |
| 7524 | |
| 7525 | if (tcp->payload_seq.len && |
| 7526 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7527 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7528 | return -ENOBUFS; |
| 7529 | |
| 7530 | if (tcp->payload_tok.len && |
| 7531 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7532 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7533 | &tcp->payload_tok)) |
| 7534 | return -ENOBUFS; |
| 7535 | |
| 7536 | return 0; |
| 7537 | } |
| 7538 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7539 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7540 | { |
| 7541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7542 | struct sk_buff *msg; |
| 7543 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7544 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7545 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7546 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7547 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7548 | return -EOPNOTSUPP; |
| 7549 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7550 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7551 | /* adjust size to have room for all the data */ |
| 7552 | size += rdev->wowlan->tcp->tokens_size + |
| 7553 | rdev->wowlan->tcp->payload_len + |
| 7554 | rdev->wowlan->tcp->wake_len + |
| 7555 | rdev->wowlan->tcp->wake_len / 8; |
| 7556 | } |
| 7557 | |
| 7558 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7559 | if (!msg) |
| 7560 | return -ENOMEM; |
| 7561 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7562 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7563 | NL80211_CMD_GET_WOWLAN); |
| 7564 | if (!hdr) |
| 7565 | goto nla_put_failure; |
| 7566 | |
| 7567 | if (rdev->wowlan) { |
| 7568 | struct nlattr *nl_wowlan; |
| 7569 | |
| 7570 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7571 | if (!nl_wowlan) |
| 7572 | goto nla_put_failure; |
| 7573 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7574 | if ((rdev->wowlan->any && |
| 7575 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7576 | (rdev->wowlan->disconnect && |
| 7577 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7578 | (rdev->wowlan->magic_pkt && |
| 7579 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7580 | (rdev->wowlan->gtk_rekey_failure && |
| 7581 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7582 | (rdev->wowlan->eap_identity_req && |
| 7583 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7584 | (rdev->wowlan->four_way_handshake && |
| 7585 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7586 | (rdev->wowlan->rfkill_release && |
| 7587 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7588 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7589 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7590 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7591 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7592 | |
| 7593 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7594 | goto nla_put_failure; |
| 7595 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7596 | nla_nest_end(msg, nl_wowlan); |
| 7597 | } |
| 7598 | |
| 7599 | genlmsg_end(msg, hdr); |
| 7600 | return genlmsg_reply(msg, info); |
| 7601 | |
| 7602 | nla_put_failure: |
| 7603 | nlmsg_free(msg); |
| 7604 | return -ENOBUFS; |
| 7605 | } |
| 7606 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7607 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7608 | struct nlattr *attr, |
| 7609 | struct cfg80211_wowlan *trig) |
| 7610 | { |
| 7611 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7612 | struct cfg80211_wowlan_tcp *cfg; |
| 7613 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7614 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7615 | u32 size; |
| 7616 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7617 | int err, port; |
| 7618 | |
| 7619 | if (!rdev->wiphy.wowlan.tcp) |
| 7620 | return -EINVAL; |
| 7621 | |
| 7622 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7623 | nla_data(attr), nla_len(attr), |
| 7624 | nl80211_wowlan_tcp_policy); |
| 7625 | if (err) |
| 7626 | return err; |
| 7627 | |
| 7628 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7629 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7630 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7631 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7632 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7633 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7634 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7635 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7636 | return -EINVAL; |
| 7637 | |
| 7638 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7639 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7640 | return -EINVAL; |
| 7641 | |
| 7642 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7643 | rdev->wiphy.wowlan.tcp->data_interval_max || |
| 7644 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7645 | return -EINVAL; |
| 7646 | |
| 7647 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7648 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7649 | return -EINVAL; |
| 7650 | |
| 7651 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7652 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7653 | return -EINVAL; |
| 7654 | |
| 7655 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7656 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7657 | |
| 7658 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7659 | tokens_size = tokln - sizeof(*tok); |
| 7660 | |
| 7661 | if (!tok->len || tokens_size % tok->len) |
| 7662 | return -EINVAL; |
| 7663 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7664 | return -EINVAL; |
| 7665 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7666 | return -EINVAL; |
| 7667 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7668 | return -EINVAL; |
| 7669 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7670 | return -EINVAL; |
| 7671 | if (tok->offset + tok->len > data_size) |
| 7672 | return -EINVAL; |
| 7673 | } |
| 7674 | |
| 7675 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7676 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7677 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7678 | return -EINVAL; |
| 7679 | if (seq->len == 0 || seq->len > 4) |
| 7680 | return -EINVAL; |
| 7681 | if (seq->len + seq->offset > data_size) |
| 7682 | return -EINVAL; |
| 7683 | } |
| 7684 | |
| 7685 | size = sizeof(*cfg); |
| 7686 | size += data_size; |
| 7687 | size += wake_size + wake_mask_size; |
| 7688 | size += tokens_size; |
| 7689 | |
| 7690 | cfg = kzalloc(size, GFP_KERNEL); |
| 7691 | if (!cfg) |
| 7692 | return -ENOMEM; |
| 7693 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7694 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7695 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7696 | ETH_ALEN); |
| 7697 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7698 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7699 | else |
| 7700 | port = 0; |
| 7701 | #ifdef CONFIG_INET |
| 7702 | /* allocate a socket and port for it and use it */ |
| 7703 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7704 | IPPROTO_TCP, &cfg->sock, 1); |
| 7705 | if (err) { |
| 7706 | kfree(cfg); |
| 7707 | return err; |
| 7708 | } |
| 7709 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7710 | sock_release(cfg->sock); |
| 7711 | kfree(cfg); |
| 7712 | return -EADDRINUSE; |
| 7713 | } |
| 7714 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7715 | #else |
| 7716 | if (!port) { |
| 7717 | kfree(cfg); |
| 7718 | return -EINVAL; |
| 7719 | } |
| 7720 | cfg->src_port = port; |
| 7721 | #endif |
| 7722 | |
| 7723 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7724 | cfg->payload_len = data_size; |
| 7725 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7726 | memcpy((void *)cfg->payload, |
| 7727 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7728 | data_size); |
| 7729 | if (seq) |
| 7730 | cfg->payload_seq = *seq; |
| 7731 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7732 | cfg->wake_len = wake_size; |
| 7733 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7734 | memcpy((void *)cfg->wake_data, |
| 7735 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7736 | wake_size); |
| 7737 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7738 | data_size + wake_size; |
| 7739 | memcpy((void *)cfg->wake_mask, |
| 7740 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7741 | wake_mask_size); |
| 7742 | if (tok) { |
| 7743 | cfg->tokens_size = tokens_size; |
| 7744 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7745 | } |
| 7746 | |
| 7747 | trig->tcp = cfg; |
| 7748 | |
| 7749 | return 0; |
| 7750 | } |
| 7751 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7752 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7753 | { |
| 7754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7755 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7756 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7757 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7758 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7759 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7760 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7761 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7762 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7763 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7764 | return -EOPNOTSUPP; |
| 7765 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7766 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7767 | cfg80211_rdev_free_wowlan(rdev); |
| 7768 | rdev->wowlan = NULL; |
| 7769 | goto set_wakeup; |
| 7770 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7771 | |
| 7772 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7773 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7774 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7775 | nl80211_wowlan_policy); |
| 7776 | if (err) |
| 7777 | return err; |
| 7778 | |
| 7779 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7780 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7781 | return -EINVAL; |
| 7782 | new_triggers.any = true; |
| 7783 | } |
| 7784 | |
| 7785 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7786 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7787 | return -EINVAL; |
| 7788 | new_triggers.disconnect = true; |
| 7789 | } |
| 7790 | |
| 7791 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7792 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7793 | return -EINVAL; |
| 7794 | new_triggers.magic_pkt = true; |
| 7795 | } |
| 7796 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7797 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7798 | return -EINVAL; |
| 7799 | |
| 7800 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7801 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7802 | return -EINVAL; |
| 7803 | new_triggers.gtk_rekey_failure = true; |
| 7804 | } |
| 7805 | |
| 7806 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7807 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7808 | return -EINVAL; |
| 7809 | new_triggers.eap_identity_req = true; |
| 7810 | } |
| 7811 | |
| 7812 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7813 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7814 | return -EINVAL; |
| 7815 | new_triggers.four_way_handshake = true; |
| 7816 | } |
| 7817 | |
| 7818 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7819 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7820 | return -EINVAL; |
| 7821 | new_triggers.rfkill_release = true; |
| 7822 | } |
| 7823 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7824 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7825 | struct nlattr *pat; |
| 7826 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7827 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7828 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7829 | |
| 7830 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7831 | rem) |
| 7832 | n_patterns++; |
| 7833 | if (n_patterns > wowlan->n_patterns) |
| 7834 | return -EINVAL; |
| 7835 | |
| 7836 | new_triggers.patterns = kcalloc(n_patterns, |
| 7837 | sizeof(new_triggers.patterns[0]), |
| 7838 | GFP_KERNEL); |
| 7839 | if (!new_triggers.patterns) |
| 7840 | return -ENOMEM; |
| 7841 | |
| 7842 | new_triggers.n_patterns = n_patterns; |
| 7843 | i = 0; |
| 7844 | |
| 7845 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7846 | rem) { |
| 7847 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7848 | nla_data(pat), nla_len(pat), NULL); |
| 7849 | err = -EINVAL; |
| 7850 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7851 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7852 | goto error; |
| 7853 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7854 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7855 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7856 | mask_len) |
| 7857 | goto error; |
| 7858 | if (pat_len > wowlan->pattern_max_len || |
| 7859 | pat_len < wowlan->pattern_min_len) |
| 7860 | goto error; |
| 7861 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7862 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7863 | pkt_offset = 0; |
| 7864 | else |
| 7865 | pkt_offset = nla_get_u32( |
| 7866 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7867 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7868 | goto error; |
| 7869 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7870 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7871 | new_triggers.patterns[i].mask = |
| 7872 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7873 | if (!new_triggers.patterns[i].mask) { |
| 7874 | err = -ENOMEM; |
| 7875 | goto error; |
| 7876 | } |
| 7877 | new_triggers.patterns[i].pattern = |
| 7878 | new_triggers.patterns[i].mask + mask_len; |
| 7879 | memcpy(new_triggers.patterns[i].mask, |
| 7880 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7881 | mask_len); |
| 7882 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7883 | memcpy(new_triggers.patterns[i].pattern, |
| 7884 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7885 | pat_len); |
| 7886 | i++; |
| 7887 | } |
| 7888 | } |
| 7889 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7890 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7891 | err = nl80211_parse_wowlan_tcp( |
| 7892 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7893 | &new_triggers); |
| 7894 | if (err) |
| 7895 | goto error; |
| 7896 | } |
| 7897 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7898 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7899 | if (!ntrig) { |
| 7900 | err = -ENOMEM; |
| 7901 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7902 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7903 | cfg80211_rdev_free_wowlan(rdev); |
| 7904 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7905 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7906 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7907 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7908 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7909 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7910 | return 0; |
| 7911 | error: |
| 7912 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7913 | kfree(new_triggers.patterns[i].mask); |
| 7914 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7915 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7916 | sock_release(new_triggers.tcp->sock); |
| 7917 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7918 | return err; |
| 7919 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7920 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7921 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7922 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7923 | { |
| 7924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7925 | struct net_device *dev = info->user_ptr[1]; |
| 7926 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7927 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7928 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7929 | int err; |
| 7930 | |
| 7931 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7932 | return -EINVAL; |
| 7933 | |
| 7934 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7935 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7936 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7937 | nl80211_rekey_policy); |
| 7938 | if (err) |
| 7939 | return err; |
| 7940 | |
| 7941 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7942 | return -ERANGE; |
| 7943 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7944 | return -ERANGE; |
| 7945 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7946 | return -ERANGE; |
| 7947 | |
| 7948 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7949 | NL80211_KEK_LEN); |
| 7950 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7951 | NL80211_KCK_LEN); |
| 7952 | memcpy(rekey_data.replay_ctr, |
| 7953 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7954 | NL80211_REPLAY_CTR_LEN); |
| 7955 | |
| 7956 | wdev_lock(wdev); |
| 7957 | if (!wdev->current_bss) { |
| 7958 | err = -ENOTCONN; |
| 7959 | goto out; |
| 7960 | } |
| 7961 | |
| 7962 | if (!rdev->ops->set_rekey_data) { |
| 7963 | err = -EOPNOTSUPP; |
| 7964 | goto out; |
| 7965 | } |
| 7966 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7967 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7968 | out: |
| 7969 | wdev_unlock(wdev); |
| 7970 | return err; |
| 7971 | } |
| 7972 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7973 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7974 | struct genl_info *info) |
| 7975 | { |
| 7976 | struct net_device *dev = info->user_ptr[1]; |
| 7977 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7978 | |
| 7979 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7980 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7981 | return -EINVAL; |
| 7982 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7983 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7984 | return -EBUSY; |
| 7985 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7986 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7987 | return 0; |
| 7988 | } |
| 7989 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7990 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7991 | struct genl_info *info) |
| 7992 | { |
| 7993 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7994 | struct net_device *dev = info->user_ptr[1]; |
| 7995 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7996 | struct sk_buff *msg; |
| 7997 | void *hdr; |
| 7998 | const u8 *addr; |
| 7999 | u64 cookie; |
| 8000 | int err; |
| 8001 | |
| 8002 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8003 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8004 | return -EOPNOTSUPP; |
| 8005 | |
| 8006 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8007 | return -EINVAL; |
| 8008 | |
| 8009 | if (!rdev->ops->probe_client) |
| 8010 | return -EOPNOTSUPP; |
| 8011 | |
| 8012 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8013 | if (!msg) |
| 8014 | return -ENOMEM; |
| 8015 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8016 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8017 | NL80211_CMD_PROBE_CLIENT); |
| 8018 | |
| 8019 | if (IS_ERR(hdr)) { |
| 8020 | err = PTR_ERR(hdr); |
| 8021 | goto free_msg; |
| 8022 | } |
| 8023 | |
| 8024 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8026 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8027 | if (err) |
| 8028 | goto free_msg; |
| 8029 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8030 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8031 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8032 | |
| 8033 | genlmsg_end(msg, hdr); |
| 8034 | |
| 8035 | return genlmsg_reply(msg, info); |
| 8036 | |
| 8037 | nla_put_failure: |
| 8038 | err = -ENOBUFS; |
| 8039 | free_msg: |
| 8040 | nlmsg_free(msg); |
| 8041 | return err; |
| 8042 | } |
| 8043 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8044 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8045 | { |
| 8046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8047 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8048 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8049 | |
| 8050 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8051 | return -EOPNOTSUPP; |
| 8052 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8053 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8054 | if (!nreg) |
| 8055 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8056 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8057 | /* First, check if already registered. */ |
| 8058 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8059 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8060 | if (reg->nlportid == info->snd_portid) { |
| 8061 | rv = -EALREADY; |
| 8062 | goto out_err; |
| 8063 | } |
| 8064 | } |
| 8065 | /* Add it to the list */ |
| 8066 | nreg->nlportid = info->snd_portid; |
| 8067 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8068 | |
| 8069 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8070 | |
| 8071 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8072 | out_err: |
| 8073 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8074 | kfree(nreg); |
| 8075 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8076 | } |
| 8077 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8078 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8079 | { |
| 8080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8081 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8082 | int err; |
| 8083 | |
| 8084 | if (!rdev->ops->start_p2p_device) |
| 8085 | return -EOPNOTSUPP; |
| 8086 | |
| 8087 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8088 | return -EOPNOTSUPP; |
| 8089 | |
| 8090 | if (wdev->p2p_started) |
| 8091 | return 0; |
| 8092 | |
| 8093 | mutex_lock(&rdev->devlist_mtx); |
| 8094 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 8095 | mutex_unlock(&rdev->devlist_mtx); |
| 8096 | if (err) |
| 8097 | return err; |
| 8098 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8099 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8100 | if (err) |
| 8101 | return err; |
| 8102 | |
| 8103 | wdev->p2p_started = true; |
| 8104 | mutex_lock(&rdev->devlist_mtx); |
| 8105 | rdev->opencount++; |
| 8106 | mutex_unlock(&rdev->devlist_mtx); |
| 8107 | |
| 8108 | return 0; |
| 8109 | } |
| 8110 | |
| 8111 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8112 | { |
| 8113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8114 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8115 | |
| 8116 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8117 | return -EOPNOTSUPP; |
| 8118 | |
| 8119 | if (!rdev->ops->stop_p2p_device) |
| 8120 | return -EOPNOTSUPP; |
| 8121 | |
| 8122 | if (!wdev->p2p_started) |
| 8123 | return 0; |
| 8124 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8125 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8126 | wdev->p2p_started = false; |
| 8127 | |
| 8128 | mutex_lock(&rdev->devlist_mtx); |
| 8129 | rdev->opencount--; |
| 8130 | mutex_unlock(&rdev->devlist_mtx); |
| 8131 | |
| 8132 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 8133 | rdev->scan_req->aborted = true; |
| 8134 | ___cfg80211_scan_done(rdev, true); |
| 8135 | } |
| 8136 | |
| 8137 | return 0; |
| 8138 | } |
| 8139 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8140 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8141 | struct genl_info *info) |
| 8142 | { |
| 8143 | void *hdr; |
| 8144 | struct sk_buff *msg; |
| 8145 | |
| 8146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8147 | if (!msg) |
| 8148 | return -ENOMEM; |
| 8149 | |
| 8150 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8151 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8152 | if (!hdr) |
| 8153 | goto nla_put_failure; |
| 8154 | |
| 8155 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8156 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8157 | goto nla_put_failure; |
| 8158 | |
| 8159 | genlmsg_end(msg, hdr); |
| 8160 | return genlmsg_reply(msg, info); |
| 8161 | |
| 8162 | nla_put_failure: |
| 8163 | kfree_skb(msg); |
| 8164 | return -ENOBUFS; |
| 8165 | } |
| 8166 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8167 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8168 | { |
| 8169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8170 | struct cfg80211_update_ft_ies_params ft_params; |
| 8171 | struct net_device *dev = info->user_ptr[1]; |
| 8172 | |
| 8173 | if (!rdev->ops->update_ft_ies) |
| 8174 | return -EOPNOTSUPP; |
| 8175 | |
| 8176 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8177 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8178 | return -EINVAL; |
| 8179 | |
| 8180 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8181 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8182 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8183 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8184 | |
| 8185 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8186 | } |
| 8187 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8188 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8189 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8190 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8191 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8192 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8193 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8194 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8195 | /* 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] | 8196 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8197 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8198 | |
| 8199 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8200 | struct genl_info *info) |
| 8201 | { |
| 8202 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8203 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8204 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8205 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8206 | |
| 8207 | if (rtnl) |
| 8208 | rtnl_lock(); |
| 8209 | |
| 8210 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8211 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8212 | if (IS_ERR(rdev)) { |
| 8213 | if (rtnl) |
| 8214 | rtnl_unlock(); |
| 8215 | return PTR_ERR(rdev); |
| 8216 | } |
| 8217 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8218 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8219 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8220 | mutex_lock(&cfg80211_mutex); |
| 8221 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8222 | info->attrs); |
| 8223 | if (IS_ERR(wdev)) { |
| 8224 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8225 | if (rtnl) |
| 8226 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8227 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8228 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8229 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8230 | dev = wdev->netdev; |
| 8231 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8232 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8233 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8234 | if (!dev) { |
| 8235 | mutex_unlock(&cfg80211_mutex); |
| 8236 | if (rtnl) |
| 8237 | rtnl_unlock(); |
| 8238 | return -EINVAL; |
| 8239 | } |
| 8240 | |
| 8241 | info->user_ptr[1] = dev; |
| 8242 | } else { |
| 8243 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8244 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8245 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8246 | if (dev) { |
| 8247 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8248 | !netif_running(dev)) { |
| 8249 | mutex_unlock(&cfg80211_mutex); |
| 8250 | if (rtnl) |
| 8251 | rtnl_unlock(); |
| 8252 | return -ENETDOWN; |
| 8253 | } |
| 8254 | |
| 8255 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8256 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8257 | if (!wdev->p2p_started) { |
| 8258 | mutex_unlock(&cfg80211_mutex); |
| 8259 | if (rtnl) |
| 8260 | rtnl_unlock(); |
| 8261 | return -ENETDOWN; |
| 8262 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8263 | } |
| 8264 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8265 | cfg80211_lock_rdev(rdev); |
| 8266 | |
| 8267 | mutex_unlock(&cfg80211_mutex); |
| 8268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8269 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8270 | } |
| 8271 | |
| 8272 | return 0; |
| 8273 | } |
| 8274 | |
| 8275 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8276 | struct genl_info *info) |
| 8277 | { |
| 8278 | if (info->user_ptr[0]) |
| 8279 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8280 | if (info->user_ptr[1]) { |
| 8281 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8282 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8283 | |
| 8284 | if (wdev->netdev) |
| 8285 | dev_put(wdev->netdev); |
| 8286 | } else { |
| 8287 | dev_put(info->user_ptr[1]); |
| 8288 | } |
| 8289 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8290 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8291 | rtnl_unlock(); |
| 8292 | } |
| 8293 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8294 | static struct genl_ops nl80211_ops[] = { |
| 8295 | { |
| 8296 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8297 | .doit = nl80211_get_wiphy, |
| 8298 | .dumpit = nl80211_dump_wiphy, |
| 8299 | .policy = nl80211_policy, |
| 8300 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8301 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8302 | }, |
| 8303 | { |
| 8304 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8305 | .doit = nl80211_set_wiphy, |
| 8306 | .policy = nl80211_policy, |
| 8307 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8308 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8309 | }, |
| 8310 | { |
| 8311 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8312 | .doit = nl80211_get_interface, |
| 8313 | .dumpit = nl80211_dump_interface, |
| 8314 | .policy = nl80211_policy, |
| 8315 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 8316 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8317 | }, |
| 8318 | { |
| 8319 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8320 | .doit = nl80211_set_interface, |
| 8321 | .policy = nl80211_policy, |
| 8322 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8323 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8325 | }, |
| 8326 | { |
| 8327 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8328 | .doit = nl80211_new_interface, |
| 8329 | .policy = nl80211_policy, |
| 8330 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8331 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8332 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8333 | }, |
| 8334 | { |
| 8335 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8336 | .doit = nl80211_del_interface, |
| 8337 | .policy = nl80211_policy, |
| 8338 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8339 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8340 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8341 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8342 | { |
| 8343 | .cmd = NL80211_CMD_GET_KEY, |
| 8344 | .doit = nl80211_get_key, |
| 8345 | .policy = nl80211_policy, |
| 8346 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8348 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8349 | }, |
| 8350 | { |
| 8351 | .cmd = NL80211_CMD_SET_KEY, |
| 8352 | .doit = nl80211_set_key, |
| 8353 | .policy = nl80211_policy, |
| 8354 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8355 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8356 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8357 | }, |
| 8358 | { |
| 8359 | .cmd = NL80211_CMD_NEW_KEY, |
| 8360 | .doit = nl80211_new_key, |
| 8361 | .policy = nl80211_policy, |
| 8362 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8363 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8364 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8365 | }, |
| 8366 | { |
| 8367 | .cmd = NL80211_CMD_DEL_KEY, |
| 8368 | .doit = nl80211_del_key, |
| 8369 | .policy = nl80211_policy, |
| 8370 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8372 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8373 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8374 | { |
| 8375 | .cmd = NL80211_CMD_SET_BEACON, |
| 8376 | .policy = nl80211_policy, |
| 8377 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8378 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8379 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8380 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8381 | }, |
| 8382 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8383 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8384 | .policy = nl80211_policy, |
| 8385 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8386 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8388 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8389 | }, |
| 8390 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8391 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8392 | .policy = nl80211_policy, |
| 8393 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8394 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8396 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8397 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8398 | { |
| 8399 | .cmd = NL80211_CMD_GET_STATION, |
| 8400 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8401 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8402 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8403 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8404 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8405 | }, |
| 8406 | { |
| 8407 | .cmd = NL80211_CMD_SET_STATION, |
| 8408 | .doit = nl80211_set_station, |
| 8409 | .policy = nl80211_policy, |
| 8410 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8412 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8413 | }, |
| 8414 | { |
| 8415 | .cmd = NL80211_CMD_NEW_STATION, |
| 8416 | .doit = nl80211_new_station, |
| 8417 | .policy = nl80211_policy, |
| 8418 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8420 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8421 | }, |
| 8422 | { |
| 8423 | .cmd = NL80211_CMD_DEL_STATION, |
| 8424 | .doit = nl80211_del_station, |
| 8425 | .policy = nl80211_policy, |
| 8426 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8428 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8429 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8430 | { |
| 8431 | .cmd = NL80211_CMD_GET_MPATH, |
| 8432 | .doit = nl80211_get_mpath, |
| 8433 | .dumpit = nl80211_dump_mpath, |
| 8434 | .policy = nl80211_policy, |
| 8435 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8437 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8438 | }, |
| 8439 | { |
| 8440 | .cmd = NL80211_CMD_SET_MPATH, |
| 8441 | .doit = nl80211_set_mpath, |
| 8442 | .policy = nl80211_policy, |
| 8443 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8445 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8446 | }, |
| 8447 | { |
| 8448 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8449 | .doit = nl80211_new_mpath, |
| 8450 | .policy = nl80211_policy, |
| 8451 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8453 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8454 | }, |
| 8455 | { |
| 8456 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8457 | .doit = nl80211_del_mpath, |
| 8458 | .policy = nl80211_policy, |
| 8459 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8460 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8461 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8462 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8463 | { |
| 8464 | .cmd = NL80211_CMD_SET_BSS, |
| 8465 | .doit = nl80211_set_bss, |
| 8466 | .policy = nl80211_policy, |
| 8467 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8468 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8469 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8470 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8471 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8472 | .cmd = NL80211_CMD_GET_REG, |
| 8473 | .doit = nl80211_get_reg, |
| 8474 | .policy = nl80211_policy, |
| 8475 | /* can be retrieved by unprivileged users */ |
| 8476 | }, |
| 8477 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8478 | .cmd = NL80211_CMD_SET_REG, |
| 8479 | .doit = nl80211_set_reg, |
| 8480 | .policy = nl80211_policy, |
| 8481 | .flags = GENL_ADMIN_PERM, |
| 8482 | }, |
| 8483 | { |
| 8484 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8485 | .doit = nl80211_req_set_reg, |
| 8486 | .policy = nl80211_policy, |
| 8487 | .flags = GENL_ADMIN_PERM, |
| 8488 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8489 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8490 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8491 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8492 | .policy = nl80211_policy, |
| 8493 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8496 | }, |
| 8497 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8498 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8499 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8500 | .policy = nl80211_policy, |
| 8501 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8504 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8505 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8506 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8507 | .doit = nl80211_trigger_scan, |
| 8508 | .policy = nl80211_policy, |
| 8509 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8510 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8511 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8512 | }, |
| 8513 | { |
| 8514 | .cmd = NL80211_CMD_GET_SCAN, |
| 8515 | .policy = nl80211_policy, |
| 8516 | .dumpit = nl80211_dump_scan, |
| 8517 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8518 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8519 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8520 | .doit = nl80211_start_sched_scan, |
| 8521 | .policy = nl80211_policy, |
| 8522 | .flags = GENL_ADMIN_PERM, |
| 8523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8524 | NL80211_FLAG_NEED_RTNL, |
| 8525 | }, |
| 8526 | { |
| 8527 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8528 | .doit = nl80211_stop_sched_scan, |
| 8529 | .policy = nl80211_policy, |
| 8530 | .flags = GENL_ADMIN_PERM, |
| 8531 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8532 | NL80211_FLAG_NEED_RTNL, |
| 8533 | }, |
| 8534 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8535 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8536 | .doit = nl80211_authenticate, |
| 8537 | .policy = nl80211_policy, |
| 8538 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8539 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8540 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8541 | }, |
| 8542 | { |
| 8543 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8544 | .doit = nl80211_associate, |
| 8545 | .policy = nl80211_policy, |
| 8546 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8547 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8548 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8549 | }, |
| 8550 | { |
| 8551 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8552 | .doit = nl80211_deauthenticate, |
| 8553 | .policy = nl80211_policy, |
| 8554 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8556 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8557 | }, |
| 8558 | { |
| 8559 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8560 | .doit = nl80211_disassociate, |
| 8561 | .policy = nl80211_policy, |
| 8562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8564 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8565 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8566 | { |
| 8567 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8568 | .doit = nl80211_join_ibss, |
| 8569 | .policy = nl80211_policy, |
| 8570 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8571 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8572 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8573 | }, |
| 8574 | { |
| 8575 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8576 | .doit = nl80211_leave_ibss, |
| 8577 | .policy = nl80211_policy, |
| 8578 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8580 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8581 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8582 | #ifdef CONFIG_NL80211_TESTMODE |
| 8583 | { |
| 8584 | .cmd = NL80211_CMD_TESTMODE, |
| 8585 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8586 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8587 | .policy = nl80211_policy, |
| 8588 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8589 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8590 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8591 | }, |
| 8592 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8593 | { |
| 8594 | .cmd = NL80211_CMD_CONNECT, |
| 8595 | .doit = nl80211_connect, |
| 8596 | .policy = nl80211_policy, |
| 8597 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8599 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8600 | }, |
| 8601 | { |
| 8602 | .cmd = NL80211_CMD_DISCONNECT, |
| 8603 | .doit = nl80211_disconnect, |
| 8604 | .policy = nl80211_policy, |
| 8605 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8606 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8607 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8608 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8609 | { |
| 8610 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8611 | .doit = nl80211_wiphy_netns, |
| 8612 | .policy = nl80211_policy, |
| 8613 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8614 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8615 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8616 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8617 | { |
| 8618 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8619 | .policy = nl80211_policy, |
| 8620 | .dumpit = nl80211_dump_survey, |
| 8621 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8622 | { |
| 8623 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8624 | .doit = nl80211_setdel_pmksa, |
| 8625 | .policy = nl80211_policy, |
| 8626 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8627 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8628 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8629 | }, |
| 8630 | { |
| 8631 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8632 | .doit = nl80211_setdel_pmksa, |
| 8633 | .policy = nl80211_policy, |
| 8634 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8635 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8636 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8637 | }, |
| 8638 | { |
| 8639 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8640 | .doit = nl80211_flush_pmksa, |
| 8641 | .policy = nl80211_policy, |
| 8642 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8643 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8644 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8645 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8646 | { |
| 8647 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8648 | .doit = nl80211_remain_on_channel, |
| 8649 | .policy = nl80211_policy, |
| 8650 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8651 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8652 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8653 | }, |
| 8654 | { |
| 8655 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8656 | .doit = nl80211_cancel_remain_on_channel, |
| 8657 | .policy = nl80211_policy, |
| 8658 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8659 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8660 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8661 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8662 | { |
| 8663 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8664 | .doit = nl80211_set_tx_bitrate_mask, |
| 8665 | .policy = nl80211_policy, |
| 8666 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8667 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8668 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8669 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8670 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8671 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8672 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8673 | .policy = nl80211_policy, |
| 8674 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8675 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8676 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8677 | }, |
| 8678 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8679 | .cmd = NL80211_CMD_FRAME, |
| 8680 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8681 | .policy = nl80211_policy, |
| 8682 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8683 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8684 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8685 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8686 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8687 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8688 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8689 | .policy = nl80211_policy, |
| 8690 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8691 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8692 | NL80211_FLAG_NEED_RTNL, |
| 8693 | }, |
| 8694 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8695 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8696 | .doit = nl80211_set_power_save, |
| 8697 | .policy = nl80211_policy, |
| 8698 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8699 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8700 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8701 | }, |
| 8702 | { |
| 8703 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8704 | .doit = nl80211_get_power_save, |
| 8705 | .policy = nl80211_policy, |
| 8706 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8707 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8708 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8709 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8710 | { |
| 8711 | .cmd = NL80211_CMD_SET_CQM, |
| 8712 | .doit = nl80211_set_cqm, |
| 8713 | .policy = nl80211_policy, |
| 8714 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8715 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8716 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8717 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8718 | { |
| 8719 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8720 | .doit = nl80211_set_channel, |
| 8721 | .policy = nl80211_policy, |
| 8722 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8723 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8724 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8725 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8726 | { |
| 8727 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8728 | .doit = nl80211_set_wds_peer, |
| 8729 | .policy = nl80211_policy, |
| 8730 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8731 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8732 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8733 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8734 | { |
| 8735 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8736 | .doit = nl80211_join_mesh, |
| 8737 | .policy = nl80211_policy, |
| 8738 | .flags = GENL_ADMIN_PERM, |
| 8739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8740 | NL80211_FLAG_NEED_RTNL, |
| 8741 | }, |
| 8742 | { |
| 8743 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8744 | .doit = nl80211_leave_mesh, |
| 8745 | .policy = nl80211_policy, |
| 8746 | .flags = GENL_ADMIN_PERM, |
| 8747 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8748 | NL80211_FLAG_NEED_RTNL, |
| 8749 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8750 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8751 | { |
| 8752 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8753 | .doit = nl80211_get_wowlan, |
| 8754 | .policy = nl80211_policy, |
| 8755 | /* can be retrieved by unprivileged users */ |
| 8756 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8757 | NL80211_FLAG_NEED_RTNL, |
| 8758 | }, |
| 8759 | { |
| 8760 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8761 | .doit = nl80211_set_wowlan, |
| 8762 | .policy = nl80211_policy, |
| 8763 | .flags = GENL_ADMIN_PERM, |
| 8764 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8765 | NL80211_FLAG_NEED_RTNL, |
| 8766 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8767 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8768 | { |
| 8769 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8770 | .doit = nl80211_set_rekey_data, |
| 8771 | .policy = nl80211_policy, |
| 8772 | .flags = GENL_ADMIN_PERM, |
| 8773 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8774 | NL80211_FLAG_NEED_RTNL, |
| 8775 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8776 | { |
| 8777 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8778 | .doit = nl80211_tdls_mgmt, |
| 8779 | .policy = nl80211_policy, |
| 8780 | .flags = GENL_ADMIN_PERM, |
| 8781 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8782 | NL80211_FLAG_NEED_RTNL, |
| 8783 | }, |
| 8784 | { |
| 8785 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8786 | .doit = nl80211_tdls_oper, |
| 8787 | .policy = nl80211_policy, |
| 8788 | .flags = GENL_ADMIN_PERM, |
| 8789 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8790 | NL80211_FLAG_NEED_RTNL, |
| 8791 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8792 | { |
| 8793 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8794 | .doit = nl80211_register_unexpected_frame, |
| 8795 | .policy = nl80211_policy, |
| 8796 | .flags = GENL_ADMIN_PERM, |
| 8797 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8798 | NL80211_FLAG_NEED_RTNL, |
| 8799 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8800 | { |
| 8801 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8802 | .doit = nl80211_probe_client, |
| 8803 | .policy = nl80211_policy, |
| 8804 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8805 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8806 | NL80211_FLAG_NEED_RTNL, |
| 8807 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8808 | { |
| 8809 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8810 | .doit = nl80211_register_beacons, |
| 8811 | .policy = nl80211_policy, |
| 8812 | .flags = GENL_ADMIN_PERM, |
| 8813 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8814 | NL80211_FLAG_NEED_RTNL, |
| 8815 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8816 | { |
| 8817 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8818 | .doit = nl80211_set_noack_map, |
| 8819 | .policy = nl80211_policy, |
| 8820 | .flags = GENL_ADMIN_PERM, |
| 8821 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8822 | NL80211_FLAG_NEED_RTNL, |
| 8823 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8824 | { |
| 8825 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8826 | .doit = nl80211_start_p2p_device, |
| 8827 | .policy = nl80211_policy, |
| 8828 | .flags = GENL_ADMIN_PERM, |
| 8829 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8830 | NL80211_FLAG_NEED_RTNL, |
| 8831 | }, |
| 8832 | { |
| 8833 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8834 | .doit = nl80211_stop_p2p_device, |
| 8835 | .policy = nl80211_policy, |
| 8836 | .flags = GENL_ADMIN_PERM, |
| 8837 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8838 | NL80211_FLAG_NEED_RTNL, |
| 8839 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8840 | { |
| 8841 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8842 | .doit = nl80211_set_mcast_rate, |
| 8843 | .policy = nl80211_policy, |
| 8844 | .flags = GENL_ADMIN_PERM, |
| 8845 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8846 | NL80211_FLAG_NEED_RTNL, |
| 8847 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8848 | { |
| 8849 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8850 | .doit = nl80211_set_mac_acl, |
| 8851 | .policy = nl80211_policy, |
| 8852 | .flags = GENL_ADMIN_PERM, |
| 8853 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8854 | NL80211_FLAG_NEED_RTNL, |
| 8855 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8856 | { |
| 8857 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8858 | .doit = nl80211_start_radar_detection, |
| 8859 | .policy = nl80211_policy, |
| 8860 | .flags = GENL_ADMIN_PERM, |
| 8861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8862 | NL80211_FLAG_NEED_RTNL, |
| 8863 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8864 | { |
| 8865 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8866 | .doit = nl80211_get_protocol_features, |
| 8867 | .policy = nl80211_policy, |
| 8868 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8869 | { |
| 8870 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 8871 | .doit = nl80211_update_ft_ies, |
| 8872 | .policy = nl80211_policy, |
| 8873 | .flags = GENL_ADMIN_PERM, |
| 8874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8875 | NL80211_FLAG_NEED_RTNL, |
| 8876 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8877 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8878 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8879 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8880 | .name = "mlme", |
| 8881 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8882 | |
| 8883 | /* multicast groups */ |
| 8884 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8885 | .name = "config", |
| 8886 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8887 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8888 | .name = "scan", |
| 8889 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8890 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8891 | .name = "regulatory", |
| 8892 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8893 | |
| 8894 | /* notification functions */ |
| 8895 | |
| 8896 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8897 | { |
| 8898 | struct sk_buff *msg; |
| 8899 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8901 | if (!msg) |
| 8902 | return; |
| 8903 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8904 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 8905 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8906 | nlmsg_free(msg); |
| 8907 | return; |
| 8908 | } |
| 8909 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8910 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8911 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8912 | } |
| 8913 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8914 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8915 | struct cfg80211_registered_device *rdev) |
| 8916 | { |
| 8917 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8918 | struct nlattr *nest; |
| 8919 | int i; |
| 8920 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8921 | ASSERT_RDEV_LOCK(rdev); |
| 8922 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8923 | if (WARN_ON(!req)) |
| 8924 | return 0; |
| 8925 | |
| 8926 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8927 | if (!nest) |
| 8928 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8929 | for (i = 0; i < req->n_ssids; i++) { |
| 8930 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8931 | goto nla_put_failure; |
| 8932 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8933 | nla_nest_end(msg, nest); |
| 8934 | |
| 8935 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8936 | if (!nest) |
| 8937 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8938 | for (i = 0; i < req->n_channels; i++) { |
| 8939 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8940 | goto nla_put_failure; |
| 8941 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8942 | nla_nest_end(msg, nest); |
| 8943 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8944 | if (req->ie && |
| 8945 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8946 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8947 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8948 | if (req->flags) |
| 8949 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8950 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8951 | return 0; |
| 8952 | nla_put_failure: |
| 8953 | return -ENOBUFS; |
| 8954 | } |
| 8955 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8956 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8957 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8958 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8959 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8960 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8961 | { |
| 8962 | void *hdr; |
| 8963 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8964 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8965 | if (!hdr) |
| 8966 | return -1; |
| 8967 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8969 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8970 | wdev->netdev->ifindex)) || |
| 8971 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8972 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8973 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8974 | /* ignore errors and send incomplete event anyway */ |
| 8975 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8976 | |
| 8977 | return genlmsg_end(msg, hdr); |
| 8978 | |
| 8979 | nla_put_failure: |
| 8980 | genlmsg_cancel(msg, hdr); |
| 8981 | return -EMSGSIZE; |
| 8982 | } |
| 8983 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8984 | static int |
| 8985 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8986 | struct cfg80211_registered_device *rdev, |
| 8987 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8988 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8989 | { |
| 8990 | void *hdr; |
| 8991 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8992 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8993 | if (!hdr) |
| 8994 | return -1; |
| 8995 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8996 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8997 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8998 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8999 | |
| 9000 | return genlmsg_end(msg, hdr); |
| 9001 | |
| 9002 | nla_put_failure: |
| 9003 | genlmsg_cancel(msg, hdr); |
| 9004 | return -EMSGSIZE; |
| 9005 | } |
| 9006 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9007 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9008 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9009 | { |
| 9010 | struct sk_buff *msg; |
| 9011 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9012 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9013 | if (!msg) |
| 9014 | return; |
| 9015 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9016 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9017 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9018 | nlmsg_free(msg); |
| 9019 | return; |
| 9020 | } |
| 9021 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9022 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9023 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9024 | } |
| 9025 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9026 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9027 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9028 | { |
| 9029 | struct sk_buff *msg; |
| 9030 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9032 | if (!msg) |
| 9033 | return; |
| 9034 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9035 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9036 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9037 | nlmsg_free(msg); |
| 9038 | return; |
| 9039 | } |
| 9040 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9041 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9042 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9043 | } |
| 9044 | |
| 9045 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9046 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9047 | { |
| 9048 | struct sk_buff *msg; |
| 9049 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9050 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9051 | if (!msg) |
| 9052 | return; |
| 9053 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9054 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9055 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9056 | nlmsg_free(msg); |
| 9057 | return; |
| 9058 | } |
| 9059 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9060 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9061 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9062 | } |
| 9063 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9064 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9065 | struct net_device *netdev) |
| 9066 | { |
| 9067 | struct sk_buff *msg; |
| 9068 | |
| 9069 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9070 | if (!msg) |
| 9071 | return; |
| 9072 | |
| 9073 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9074 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9075 | nlmsg_free(msg); |
| 9076 | return; |
| 9077 | } |
| 9078 | |
| 9079 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9080 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9081 | } |
| 9082 | |
| 9083 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9084 | struct net_device *netdev, u32 cmd) |
| 9085 | { |
| 9086 | struct sk_buff *msg; |
| 9087 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9088 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9089 | if (!msg) |
| 9090 | return; |
| 9091 | |
| 9092 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9093 | nlmsg_free(msg); |
| 9094 | return; |
| 9095 | } |
| 9096 | |
| 9097 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9098 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9099 | } |
| 9100 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9101 | /* |
| 9102 | * This can happen on global regulatory changes or device specific settings |
| 9103 | * based on custom world regulatory domains. |
| 9104 | */ |
| 9105 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9106 | { |
| 9107 | struct sk_buff *msg; |
| 9108 | void *hdr; |
| 9109 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9110 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9111 | if (!msg) |
| 9112 | return; |
| 9113 | |
| 9114 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9115 | if (!hdr) { |
| 9116 | nlmsg_free(msg); |
| 9117 | return; |
| 9118 | } |
| 9119 | |
| 9120 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9121 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9122 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9123 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9124 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9125 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9126 | NL80211_REGDOM_TYPE_WORLD)) |
| 9127 | goto nla_put_failure; |
| 9128 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9129 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9130 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9131 | goto nla_put_failure; |
| 9132 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9133 | request->intersect) { |
| 9134 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9135 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9136 | goto nla_put_failure; |
| 9137 | } else { |
| 9138 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9139 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9140 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9141 | request->alpha2)) |
| 9142 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9143 | } |
| 9144 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9145 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9146 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9147 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9148 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9149 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9150 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9151 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9152 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9153 | GFP_ATOMIC); |
| 9154 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9155 | |
| 9156 | return; |
| 9157 | |
| 9158 | nla_put_failure: |
| 9159 | genlmsg_cancel(msg, hdr); |
| 9160 | nlmsg_free(msg); |
| 9161 | } |
| 9162 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9163 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9164 | struct net_device *netdev, |
| 9165 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9166 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9167 | { |
| 9168 | struct sk_buff *msg; |
| 9169 | void *hdr; |
| 9170 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9172 | if (!msg) |
| 9173 | return; |
| 9174 | |
| 9175 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9176 | if (!hdr) { |
| 9177 | nlmsg_free(msg); |
| 9178 | return; |
| 9179 | } |
| 9180 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9182 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9183 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9184 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9185 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9186 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 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_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9190 | return; |
| 9191 | |
| 9192 | nla_put_failure: |
| 9193 | genlmsg_cancel(msg, hdr); |
| 9194 | nlmsg_free(msg); |
| 9195 | } |
| 9196 | |
| 9197 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9198 | struct net_device *netdev, const u8 *buf, |
| 9199 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9200 | { |
| 9201 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9202 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9203 | } |
| 9204 | |
| 9205 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9206 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9207 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9208 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9209 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9210 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9211 | } |
| 9212 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9213 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9214 | struct net_device *netdev, const u8 *buf, |
| 9215 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9216 | { |
| 9217 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9218 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9219 | } |
| 9220 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9221 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9222 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9223 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9224 | { |
| 9225 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9226 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9227 | } |
| 9228 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9229 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
| 9230 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9231 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9232 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9233 | struct wiphy *wiphy = wdev->wiphy; |
| 9234 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9235 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9236 | trace_cfg80211_send_unprot_deauth(dev); |
| 9237 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9238 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9239 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9240 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
| 9241 | |
| 9242 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
| 9243 | size_t len) |
| 9244 | { |
| 9245 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9246 | struct wiphy *wiphy = wdev->wiphy; |
| 9247 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9248 | |
| 9249 | trace_cfg80211_send_unprot_disassoc(dev); |
| 9250 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9251 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); |
| 9252 | } |
| 9253 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9254 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9255 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9256 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9257 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9258 | { |
| 9259 | struct sk_buff *msg; |
| 9260 | void *hdr; |
| 9261 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9263 | if (!msg) |
| 9264 | return; |
| 9265 | |
| 9266 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9267 | if (!hdr) { |
| 9268 | nlmsg_free(msg); |
| 9269 | return; |
| 9270 | } |
| 9271 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9272 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9273 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9274 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9275 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9276 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9277 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9278 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9279 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9280 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9281 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9282 | return; |
| 9283 | |
| 9284 | nla_put_failure: |
| 9285 | genlmsg_cancel(msg, hdr); |
| 9286 | nlmsg_free(msg); |
| 9287 | } |
| 9288 | |
| 9289 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9290 | struct net_device *netdev, const u8 *addr, |
| 9291 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9292 | { |
| 9293 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9294 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9295 | } |
| 9296 | |
| 9297 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9298 | struct net_device *netdev, const u8 *addr, |
| 9299 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9300 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9301 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9302 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9303 | } |
| 9304 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9305 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9306 | struct net_device *netdev, const u8 *bssid, |
| 9307 | const u8 *req_ie, size_t req_ie_len, |
| 9308 | const u8 *resp_ie, size_t resp_ie_len, |
| 9309 | u16 status, gfp_t gfp) |
| 9310 | { |
| 9311 | struct sk_buff *msg; |
| 9312 | void *hdr; |
| 9313 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9314 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9315 | if (!msg) |
| 9316 | return; |
| 9317 | |
| 9318 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9319 | if (!hdr) { |
| 9320 | nlmsg_free(msg); |
| 9321 | return; |
| 9322 | } |
| 9323 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9324 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9325 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9326 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9327 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9328 | (req_ie && |
| 9329 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9330 | (resp_ie && |
| 9331 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9332 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9333 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9334 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9335 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9336 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9337 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9338 | return; |
| 9339 | |
| 9340 | nla_put_failure: |
| 9341 | genlmsg_cancel(msg, hdr); |
| 9342 | nlmsg_free(msg); |
| 9343 | |
| 9344 | } |
| 9345 | |
| 9346 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9347 | struct net_device *netdev, const u8 *bssid, |
| 9348 | const u8 *req_ie, size_t req_ie_len, |
| 9349 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9350 | { |
| 9351 | struct sk_buff *msg; |
| 9352 | void *hdr; |
| 9353 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9354 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9355 | if (!msg) |
| 9356 | return; |
| 9357 | |
| 9358 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9359 | if (!hdr) { |
| 9360 | nlmsg_free(msg); |
| 9361 | return; |
| 9362 | } |
| 9363 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9364 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9365 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9366 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9367 | (req_ie && |
| 9368 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9369 | (resp_ie && |
| 9370 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9371 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9372 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9373 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9374 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9375 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9376 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9377 | return; |
| 9378 | |
| 9379 | nla_put_failure: |
| 9380 | genlmsg_cancel(msg, hdr); |
| 9381 | nlmsg_free(msg); |
| 9382 | |
| 9383 | } |
| 9384 | |
| 9385 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9386 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9387 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9388 | { |
| 9389 | struct sk_buff *msg; |
| 9390 | void *hdr; |
| 9391 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9392 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9393 | if (!msg) |
| 9394 | return; |
| 9395 | |
| 9396 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9397 | if (!hdr) { |
| 9398 | nlmsg_free(msg); |
| 9399 | return; |
| 9400 | } |
| 9401 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9402 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9403 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9404 | (from_ap && reason && |
| 9405 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9406 | (from_ap && |
| 9407 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9408 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9409 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9410 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9411 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9412 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9413 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9414 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9415 | return; |
| 9416 | |
| 9417 | nla_put_failure: |
| 9418 | genlmsg_cancel(msg, hdr); |
| 9419 | nlmsg_free(msg); |
| 9420 | |
| 9421 | } |
| 9422 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9423 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9424 | struct net_device *netdev, const u8 *bssid, |
| 9425 | gfp_t gfp) |
| 9426 | { |
| 9427 | struct sk_buff *msg; |
| 9428 | void *hdr; |
| 9429 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9430 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9431 | if (!msg) |
| 9432 | return; |
| 9433 | |
| 9434 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9435 | if (!hdr) { |
| 9436 | nlmsg_free(msg); |
| 9437 | return; |
| 9438 | } |
| 9439 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9440 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9441 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9442 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9443 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9444 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9445 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9446 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9447 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9448 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9449 | return; |
| 9450 | |
| 9451 | nla_put_failure: |
| 9452 | genlmsg_cancel(msg, hdr); |
| 9453 | nlmsg_free(msg); |
| 9454 | } |
| 9455 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9456 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9457 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9458 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9459 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9460 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9461 | struct sk_buff *msg; |
| 9462 | void *hdr; |
| 9463 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9464 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9465 | return; |
| 9466 | |
| 9467 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9468 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9470 | if (!msg) |
| 9471 | return; |
| 9472 | |
| 9473 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9474 | if (!hdr) { |
| 9475 | nlmsg_free(msg); |
| 9476 | return; |
| 9477 | } |
| 9478 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9479 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9480 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9481 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9482 | (ie_len && ie && |
| 9483 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9484 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9485 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9486 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9487 | |
| 9488 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9489 | nl80211_mlme_mcgrp.id, gfp); |
| 9490 | return; |
| 9491 | |
| 9492 | nla_put_failure: |
| 9493 | genlmsg_cancel(msg, hdr); |
| 9494 | nlmsg_free(msg); |
| 9495 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9496 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9497 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9498 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9499 | struct net_device *netdev, const u8 *addr, |
| 9500 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9501 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9502 | { |
| 9503 | struct sk_buff *msg; |
| 9504 | void *hdr; |
| 9505 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9507 | if (!msg) |
| 9508 | return; |
| 9509 | |
| 9510 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9511 | if (!hdr) { |
| 9512 | nlmsg_free(msg); |
| 9513 | return; |
| 9514 | } |
| 9515 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9517 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9518 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9519 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9520 | (key_id != -1 && |
| 9521 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9522 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9523 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9524 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9525 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9526 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9527 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9528 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9529 | return; |
| 9530 | |
| 9531 | nla_put_failure: |
| 9532 | genlmsg_cancel(msg, hdr); |
| 9533 | nlmsg_free(msg); |
| 9534 | } |
| 9535 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9536 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9537 | struct ieee80211_channel *channel_before, |
| 9538 | struct ieee80211_channel *channel_after) |
| 9539 | { |
| 9540 | struct sk_buff *msg; |
| 9541 | void *hdr; |
| 9542 | struct nlattr *nl_freq; |
| 9543 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9544 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9545 | if (!msg) |
| 9546 | return; |
| 9547 | |
| 9548 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9549 | if (!hdr) { |
| 9550 | nlmsg_free(msg); |
| 9551 | return; |
| 9552 | } |
| 9553 | |
| 9554 | /* |
| 9555 | * Since we are applying the beacon hint to a wiphy we know its |
| 9556 | * wiphy_idx is valid |
| 9557 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9558 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9559 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9560 | |
| 9561 | /* Before */ |
| 9562 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9563 | if (!nl_freq) |
| 9564 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9565 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9566 | goto nla_put_failure; |
| 9567 | nla_nest_end(msg, nl_freq); |
| 9568 | |
| 9569 | /* After */ |
| 9570 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9571 | if (!nl_freq) |
| 9572 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9573 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9574 | goto nla_put_failure; |
| 9575 | nla_nest_end(msg, nl_freq); |
| 9576 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9577 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9578 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9579 | rcu_read_lock(); |
| 9580 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9581 | GFP_ATOMIC); |
| 9582 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9583 | |
| 9584 | return; |
| 9585 | |
| 9586 | nla_put_failure: |
| 9587 | genlmsg_cancel(msg, hdr); |
| 9588 | nlmsg_free(msg); |
| 9589 | } |
| 9590 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9591 | static void nl80211_send_remain_on_chan_event( |
| 9592 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9593 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9594 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9595 | unsigned int duration, gfp_t gfp) |
| 9596 | { |
| 9597 | struct sk_buff *msg; |
| 9598 | void *hdr; |
| 9599 | |
| 9600 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9601 | if (!msg) |
| 9602 | return; |
| 9603 | |
| 9604 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9605 | if (!hdr) { |
| 9606 | nlmsg_free(msg); |
| 9607 | return; |
| 9608 | } |
| 9609 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9610 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9611 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9612 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9613 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9614 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9615 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9616 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9617 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9618 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9619 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9620 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9621 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9622 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9623 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9624 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9625 | |
| 9626 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9627 | nl80211_mlme_mcgrp.id, gfp); |
| 9628 | return; |
| 9629 | |
| 9630 | nla_put_failure: |
| 9631 | genlmsg_cancel(msg, hdr); |
| 9632 | nlmsg_free(msg); |
| 9633 | } |
| 9634 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9635 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9636 | struct ieee80211_channel *chan, |
| 9637 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9638 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9639 | struct wiphy *wiphy = wdev->wiphy; |
| 9640 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9641 | |
| 9642 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9643 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9644 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9645 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9646 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9647 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9648 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9649 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9650 | struct ieee80211_channel *chan, |
| 9651 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9652 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9653 | struct wiphy *wiphy = wdev->wiphy; |
| 9654 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9655 | |
| 9656 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9657 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9658 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9659 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9660 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9661 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9662 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9663 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9664 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9665 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9666 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9667 | struct sk_buff *msg; |
| 9668 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9669 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9670 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9672 | if (!msg) |
| 9673 | return; |
| 9674 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9675 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9676 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9677 | nlmsg_free(msg); |
| 9678 | return; |
| 9679 | } |
| 9680 | |
| 9681 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9682 | nl80211_mlme_mcgrp.id, gfp); |
| 9683 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9684 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9685 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9686 | 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] | 9687 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9688 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9689 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9690 | struct sk_buff *msg; |
| 9691 | void *hdr; |
| 9692 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9693 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9694 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9695 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9696 | if (!msg) |
| 9697 | return; |
| 9698 | |
| 9699 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9700 | if (!hdr) { |
| 9701 | nlmsg_free(msg); |
| 9702 | return; |
| 9703 | } |
| 9704 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9705 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9706 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9707 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9708 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9709 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9710 | |
| 9711 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9712 | nl80211_mlme_mcgrp.id, gfp); |
| 9713 | return; |
| 9714 | |
| 9715 | nla_put_failure: |
| 9716 | genlmsg_cancel(msg, hdr); |
| 9717 | nlmsg_free(msg); |
| 9718 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9719 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9720 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9721 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9722 | enum nl80211_connect_failed_reason reason, |
| 9723 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9724 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9725 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9726 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9727 | struct sk_buff *msg; |
| 9728 | void *hdr; |
| 9729 | |
| 9730 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9731 | if (!msg) |
| 9732 | return; |
| 9733 | |
| 9734 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9735 | if (!hdr) { |
| 9736 | nlmsg_free(msg); |
| 9737 | return; |
| 9738 | } |
| 9739 | |
| 9740 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9741 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9742 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9743 | goto nla_put_failure; |
| 9744 | |
| 9745 | genlmsg_end(msg, hdr); |
| 9746 | |
| 9747 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9748 | nl80211_mlme_mcgrp.id, gfp); |
| 9749 | return; |
| 9750 | |
| 9751 | nla_put_failure: |
| 9752 | genlmsg_cancel(msg, hdr); |
| 9753 | nlmsg_free(msg); |
| 9754 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9755 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9756 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9757 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9758 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9759 | { |
| 9760 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9761 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9762 | struct sk_buff *msg; |
| 9763 | void *hdr; |
| 9764 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9765 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9766 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9767 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9768 | return false; |
| 9769 | |
| 9770 | msg = nlmsg_new(100, gfp); |
| 9771 | if (!msg) |
| 9772 | return true; |
| 9773 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9774 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9775 | if (!hdr) { |
| 9776 | nlmsg_free(msg); |
| 9777 | return true; |
| 9778 | } |
| 9779 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9780 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9781 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9782 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9783 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9784 | |
| 9785 | err = genlmsg_end(msg, hdr); |
| 9786 | if (err < 0) { |
| 9787 | nlmsg_free(msg); |
| 9788 | return true; |
| 9789 | } |
| 9790 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9791 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9792 | return true; |
| 9793 | |
| 9794 | nla_put_failure: |
| 9795 | genlmsg_cancel(msg, hdr); |
| 9796 | nlmsg_free(msg); |
| 9797 | return true; |
| 9798 | } |
| 9799 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9800 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9801 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9802 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9804 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9805 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9806 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9807 | |
| 9808 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9809 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9810 | trace_cfg80211_return_bool(false); |
| 9811 | return false; |
| 9812 | } |
| 9813 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9814 | addr, gfp); |
| 9815 | trace_cfg80211_return_bool(ret); |
| 9816 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9817 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9818 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9819 | |
| 9820 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9821 | const u8 *addr, gfp_t gfp) |
| 9822 | { |
| 9823 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9824 | bool ret; |
| 9825 | |
| 9826 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9827 | |
| 9828 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9829 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9830 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9831 | trace_cfg80211_return_bool(false); |
| 9832 | return false; |
| 9833 | } |
| 9834 | ret = __nl80211_unexpected_frame(dev, |
| 9835 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9836 | addr, gfp); |
| 9837 | trace_cfg80211_return_bool(ret); |
| 9838 | return ret; |
| 9839 | } |
| 9840 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9841 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9842 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9843 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9844 | int freq, int sig_dbm, |
| 9845 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9846 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9847 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9848 | struct sk_buff *msg; |
| 9849 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9850 | |
| 9851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9852 | if (!msg) |
| 9853 | return -ENOMEM; |
| 9854 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9855 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9856 | if (!hdr) { |
| 9857 | nlmsg_free(msg); |
| 9858 | return -ENOMEM; |
| 9859 | } |
| 9860 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9861 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9862 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9863 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9864 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9865 | (sig_dbm && |
| 9866 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9867 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9868 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9869 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9870 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9871 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9872 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9873 | |
| 9874 | nla_put_failure: |
| 9875 | genlmsg_cancel(msg, hdr); |
| 9876 | nlmsg_free(msg); |
| 9877 | return -ENOBUFS; |
| 9878 | } |
| 9879 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9880 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 9881 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9882 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9883 | struct wiphy *wiphy = wdev->wiphy; |
| 9884 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9885 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9886 | struct sk_buff *msg; |
| 9887 | void *hdr; |
| 9888 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9889 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 9890 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9891 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9892 | if (!msg) |
| 9893 | return; |
| 9894 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9895 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9896 | if (!hdr) { |
| 9897 | nlmsg_free(msg); |
| 9898 | return; |
| 9899 | } |
| 9900 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9901 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9902 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9903 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9904 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9905 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9906 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9907 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9908 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9909 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9910 | |
| 9911 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9912 | return; |
| 9913 | |
| 9914 | nla_put_failure: |
| 9915 | genlmsg_cancel(msg, hdr); |
| 9916 | nlmsg_free(msg); |
| 9917 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9918 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9919 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9920 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 9921 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9922 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9923 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9924 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9925 | struct wiphy *wiphy = wdev->wiphy; |
| 9926 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9927 | struct sk_buff *msg; |
| 9928 | struct nlattr *pinfoattr; |
| 9929 | void *hdr; |
| 9930 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9931 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 9932 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9933 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9934 | if (!msg) |
| 9935 | return; |
| 9936 | |
| 9937 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9938 | if (!hdr) { |
| 9939 | nlmsg_free(msg); |
| 9940 | return; |
| 9941 | } |
| 9942 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9943 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9944 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9945 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9946 | |
| 9947 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9948 | if (!pinfoattr) |
| 9949 | goto nla_put_failure; |
| 9950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9951 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9952 | rssi_event)) |
| 9953 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9954 | |
| 9955 | nla_nest_end(msg, pinfoattr); |
| 9956 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9957 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9958 | |
| 9959 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9960 | nl80211_mlme_mcgrp.id, gfp); |
| 9961 | return; |
| 9962 | |
| 9963 | nla_put_failure: |
| 9964 | genlmsg_cancel(msg, hdr); |
| 9965 | nlmsg_free(msg); |
| 9966 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9967 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9968 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9969 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9970 | struct net_device *netdev, const u8 *bssid, |
| 9971 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9972 | { |
| 9973 | struct sk_buff *msg; |
| 9974 | struct nlattr *rekey_attr; |
| 9975 | void *hdr; |
| 9976 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9978 | if (!msg) |
| 9979 | return; |
| 9980 | |
| 9981 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9982 | if (!hdr) { |
| 9983 | nlmsg_free(msg); |
| 9984 | return; |
| 9985 | } |
| 9986 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9987 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9988 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9989 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9990 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9991 | |
| 9992 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9993 | if (!rekey_attr) |
| 9994 | goto nla_put_failure; |
| 9995 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9996 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9997 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9998 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9999 | |
| 10000 | nla_nest_end(msg, rekey_attr); |
| 10001 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10002 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10003 | |
| 10004 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10005 | nl80211_mlme_mcgrp.id, gfp); |
| 10006 | return; |
| 10007 | |
| 10008 | nla_put_failure: |
| 10009 | genlmsg_cancel(msg, hdr); |
| 10010 | nlmsg_free(msg); |
| 10011 | } |
| 10012 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10013 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10014 | const u8 *replay_ctr, gfp_t gfp) |
| 10015 | { |
| 10016 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10017 | struct wiphy *wiphy = wdev->wiphy; |
| 10018 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10019 | |
| 10020 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10021 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10022 | } |
| 10023 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10024 | |
| 10025 | static void |
| 10026 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10027 | struct net_device *netdev, int index, |
| 10028 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10029 | { |
| 10030 | struct sk_buff *msg; |
| 10031 | struct nlattr *attr; |
| 10032 | void *hdr; |
| 10033 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10034 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10035 | if (!msg) |
| 10036 | return; |
| 10037 | |
| 10038 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10039 | if (!hdr) { |
| 10040 | nlmsg_free(msg); |
| 10041 | return; |
| 10042 | } |
| 10043 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10044 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10045 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10046 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10047 | |
| 10048 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10049 | if (!attr) |
| 10050 | goto nla_put_failure; |
| 10051 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10052 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10053 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10054 | (preauth && |
| 10055 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10056 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10057 | |
| 10058 | nla_nest_end(msg, attr); |
| 10059 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10060 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10061 | |
| 10062 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10063 | nl80211_mlme_mcgrp.id, gfp); |
| 10064 | return; |
| 10065 | |
| 10066 | nla_put_failure: |
| 10067 | genlmsg_cancel(msg, hdr); |
| 10068 | nlmsg_free(msg); |
| 10069 | } |
| 10070 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10071 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10072 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10073 | { |
| 10074 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10075 | struct wiphy *wiphy = wdev->wiphy; |
| 10076 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10077 | |
| 10078 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10079 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10080 | } |
| 10081 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10082 | |
| 10083 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10084 | struct net_device *netdev, |
| 10085 | struct cfg80211_chan_def *chandef, |
| 10086 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10087 | { |
| 10088 | struct sk_buff *msg; |
| 10089 | void *hdr; |
| 10090 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10092 | if (!msg) |
| 10093 | return; |
| 10094 | |
| 10095 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10096 | if (!hdr) { |
| 10097 | nlmsg_free(msg); |
| 10098 | return; |
| 10099 | } |
| 10100 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10101 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10102 | goto nla_put_failure; |
| 10103 | |
| 10104 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10105 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10106 | |
| 10107 | genlmsg_end(msg, hdr); |
| 10108 | |
| 10109 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10110 | nl80211_mlme_mcgrp.id, gfp); |
| 10111 | return; |
| 10112 | |
| 10113 | nla_put_failure: |
| 10114 | genlmsg_cancel(msg, hdr); |
| 10115 | nlmsg_free(msg); |
| 10116 | } |
| 10117 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10118 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10119 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10120 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10121 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10122 | struct wiphy *wiphy = wdev->wiphy; |
| 10123 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10124 | |
| 10125 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10126 | |
| 10127 | wdev_lock(wdev); |
| 10128 | |
| 10129 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10130 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10131 | goto out; |
| 10132 | |
| 10133 | wdev->channel = chandef->chan; |
| 10134 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10135 | out: |
| 10136 | wdev_unlock(wdev); |
| 10137 | return; |
| 10138 | } |
| 10139 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10140 | |
| 10141 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10142 | const u8 *peer, u32 num_packets, |
| 10143 | u32 rate, u32 intvl, gfp_t gfp) |
| 10144 | { |
| 10145 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10146 | struct wiphy *wiphy = wdev->wiphy; |
| 10147 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10148 | struct sk_buff *msg; |
| 10149 | struct nlattr *pinfoattr; |
| 10150 | void *hdr; |
| 10151 | |
| 10152 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10153 | if (!msg) |
| 10154 | return; |
| 10155 | |
| 10156 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10157 | if (!hdr) { |
| 10158 | nlmsg_free(msg); |
| 10159 | return; |
| 10160 | } |
| 10161 | |
| 10162 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10163 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10164 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10165 | goto nla_put_failure; |
| 10166 | |
| 10167 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10168 | if (!pinfoattr) |
| 10169 | goto nla_put_failure; |
| 10170 | |
| 10171 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10172 | goto nla_put_failure; |
| 10173 | |
| 10174 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10175 | goto nla_put_failure; |
| 10176 | |
| 10177 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10178 | goto nla_put_failure; |
| 10179 | |
| 10180 | nla_nest_end(msg, pinfoattr); |
| 10181 | |
| 10182 | genlmsg_end(msg, hdr); |
| 10183 | |
| 10184 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10185 | nl80211_mlme_mcgrp.id, gfp); |
| 10186 | return; |
| 10187 | |
| 10188 | nla_put_failure: |
| 10189 | genlmsg_cancel(msg, hdr); |
| 10190 | nlmsg_free(msg); |
| 10191 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10192 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10193 | |
| 10194 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10195 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10196 | struct cfg80211_chan_def *chandef, |
| 10197 | enum nl80211_radar_event event, |
| 10198 | struct net_device *netdev, gfp_t gfp) |
| 10199 | { |
| 10200 | struct sk_buff *msg; |
| 10201 | void *hdr; |
| 10202 | |
| 10203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10204 | if (!msg) |
| 10205 | return; |
| 10206 | |
| 10207 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10208 | if (!hdr) { |
| 10209 | nlmsg_free(msg); |
| 10210 | return; |
| 10211 | } |
| 10212 | |
| 10213 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10214 | goto nla_put_failure; |
| 10215 | |
| 10216 | /* NOP and radar events don't need a netdev parameter */ |
| 10217 | if (netdev) { |
| 10218 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10219 | |
| 10220 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10221 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10222 | goto nla_put_failure; |
| 10223 | } |
| 10224 | |
| 10225 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10226 | goto nla_put_failure; |
| 10227 | |
| 10228 | if (nl80211_send_chandef(msg, chandef)) |
| 10229 | goto nla_put_failure; |
| 10230 | |
| 10231 | if (genlmsg_end(msg, hdr) < 0) { |
| 10232 | nlmsg_free(msg); |
| 10233 | return; |
| 10234 | } |
| 10235 | |
| 10236 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10237 | nl80211_mlme_mcgrp.id, gfp); |
| 10238 | return; |
| 10239 | |
| 10240 | nla_put_failure: |
| 10241 | genlmsg_cancel(msg, hdr); |
| 10242 | nlmsg_free(msg); |
| 10243 | } |
| 10244 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10245 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10246 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10247 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10248 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10249 | struct wiphy *wiphy = wdev->wiphy; |
| 10250 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10251 | struct sk_buff *msg; |
| 10252 | struct nlattr *pinfoattr; |
| 10253 | void *hdr; |
| 10254 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10255 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10256 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10258 | if (!msg) |
| 10259 | return; |
| 10260 | |
| 10261 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10262 | if (!hdr) { |
| 10263 | nlmsg_free(msg); |
| 10264 | return; |
| 10265 | } |
| 10266 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10267 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10268 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10269 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10270 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10271 | |
| 10272 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10273 | if (!pinfoattr) |
| 10274 | goto nla_put_failure; |
| 10275 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10276 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10277 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10278 | |
| 10279 | nla_nest_end(msg, pinfoattr); |
| 10280 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10281 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10282 | |
| 10283 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10284 | nl80211_mlme_mcgrp.id, gfp); |
| 10285 | return; |
| 10286 | |
| 10287 | nla_put_failure: |
| 10288 | genlmsg_cancel(msg, hdr); |
| 10289 | nlmsg_free(msg); |
| 10290 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10291 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10292 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10293 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10294 | u64 cookie, bool acked, gfp_t gfp) |
| 10295 | { |
| 10296 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10297 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10298 | struct sk_buff *msg; |
| 10299 | void *hdr; |
| 10300 | int err; |
| 10301 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10302 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10303 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10305 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10306 | if (!msg) |
| 10307 | return; |
| 10308 | |
| 10309 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10310 | if (!hdr) { |
| 10311 | nlmsg_free(msg); |
| 10312 | return; |
| 10313 | } |
| 10314 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10315 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10316 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10317 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10318 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10319 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10320 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10321 | |
| 10322 | err = genlmsg_end(msg, hdr); |
| 10323 | if (err < 0) { |
| 10324 | nlmsg_free(msg); |
| 10325 | return; |
| 10326 | } |
| 10327 | |
| 10328 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10329 | nl80211_mlme_mcgrp.id, gfp); |
| 10330 | return; |
| 10331 | |
| 10332 | nla_put_failure: |
| 10333 | genlmsg_cancel(msg, hdr); |
| 10334 | nlmsg_free(msg); |
| 10335 | } |
| 10336 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10337 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10338 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10339 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10340 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10341 | { |
| 10342 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10343 | struct sk_buff *msg; |
| 10344 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10345 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10346 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10347 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10348 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10349 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10350 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10351 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10352 | if (!msg) { |
| 10353 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10354 | return; |
| 10355 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10356 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10357 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10358 | if (!hdr) |
| 10359 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10360 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10361 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10362 | (freq && |
| 10363 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10364 | (sig_dbm && |
| 10365 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10366 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10367 | goto nla_put_failure; |
| 10368 | |
| 10369 | genlmsg_end(msg, hdr); |
| 10370 | |
| 10371 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10372 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10373 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10374 | return; |
| 10375 | |
| 10376 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10377 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10378 | if (hdr) |
| 10379 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10380 | nlmsg_free(msg); |
| 10381 | } |
| 10382 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10383 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10384 | #ifdef CONFIG_PM |
| 10385 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10386 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10387 | gfp_t gfp) |
| 10388 | { |
| 10389 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10390 | struct sk_buff *msg; |
| 10391 | void *hdr; |
| 10392 | int err, size = 200; |
| 10393 | |
| 10394 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10395 | |
| 10396 | if (wakeup) |
| 10397 | size += wakeup->packet_present_len; |
| 10398 | |
| 10399 | msg = nlmsg_new(size, gfp); |
| 10400 | if (!msg) |
| 10401 | return; |
| 10402 | |
| 10403 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10404 | if (!hdr) |
| 10405 | goto free_msg; |
| 10406 | |
| 10407 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10408 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10409 | goto free_msg; |
| 10410 | |
| 10411 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10412 | wdev->netdev->ifindex)) |
| 10413 | goto free_msg; |
| 10414 | |
| 10415 | if (wakeup) { |
| 10416 | struct nlattr *reasons; |
| 10417 | |
| 10418 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10419 | |
| 10420 | if (wakeup->disconnect && |
| 10421 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10422 | goto free_msg; |
| 10423 | if (wakeup->magic_pkt && |
| 10424 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10425 | goto free_msg; |
| 10426 | if (wakeup->gtk_rekey_failure && |
| 10427 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10428 | goto free_msg; |
| 10429 | if (wakeup->eap_identity_req && |
| 10430 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10431 | goto free_msg; |
| 10432 | if (wakeup->four_way_handshake && |
| 10433 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10434 | goto free_msg; |
| 10435 | if (wakeup->rfkill_release && |
| 10436 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10437 | goto free_msg; |
| 10438 | |
| 10439 | if (wakeup->pattern_idx >= 0 && |
| 10440 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10441 | wakeup->pattern_idx)) |
| 10442 | goto free_msg; |
| 10443 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10444 | if (wakeup->tcp_match) |
| 10445 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10446 | |
| 10447 | if (wakeup->tcp_connlost) |
| 10448 | nla_put_flag(msg, |
| 10449 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10450 | |
| 10451 | if (wakeup->tcp_nomoretokens) |
| 10452 | nla_put_flag(msg, |
| 10453 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10454 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10455 | if (wakeup->packet) { |
| 10456 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10457 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10458 | |
| 10459 | if (!wakeup->packet_80211) { |
| 10460 | pkt_attr = |
| 10461 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10462 | len_attr = |
| 10463 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10464 | } |
| 10465 | |
| 10466 | if (wakeup->packet_len && |
| 10467 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10468 | goto free_msg; |
| 10469 | |
| 10470 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10471 | wakeup->packet)) |
| 10472 | goto free_msg; |
| 10473 | } |
| 10474 | |
| 10475 | nla_nest_end(msg, reasons); |
| 10476 | } |
| 10477 | |
| 10478 | err = genlmsg_end(msg, hdr); |
| 10479 | if (err < 0) |
| 10480 | goto free_msg; |
| 10481 | |
| 10482 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10483 | nl80211_mlme_mcgrp.id, gfp); |
| 10484 | return; |
| 10485 | |
| 10486 | free_msg: |
| 10487 | nlmsg_free(msg); |
| 10488 | } |
| 10489 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10490 | #endif |
| 10491 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10492 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10493 | enum nl80211_tdls_operation oper, |
| 10494 | u16 reason_code, gfp_t gfp) |
| 10495 | { |
| 10496 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10497 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10498 | struct sk_buff *msg; |
| 10499 | void *hdr; |
| 10500 | int err; |
| 10501 | |
| 10502 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10503 | reason_code); |
| 10504 | |
| 10505 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10506 | if (!msg) |
| 10507 | return; |
| 10508 | |
| 10509 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10510 | if (!hdr) { |
| 10511 | nlmsg_free(msg); |
| 10512 | return; |
| 10513 | } |
| 10514 | |
| 10515 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10516 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10517 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10518 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10519 | (reason_code > 0 && |
| 10520 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10521 | goto nla_put_failure; |
| 10522 | |
| 10523 | err = genlmsg_end(msg, hdr); |
| 10524 | if (err < 0) { |
| 10525 | nlmsg_free(msg); |
| 10526 | return; |
| 10527 | } |
| 10528 | |
| 10529 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10530 | nl80211_mlme_mcgrp.id, gfp); |
| 10531 | return; |
| 10532 | |
| 10533 | nla_put_failure: |
| 10534 | genlmsg_cancel(msg, hdr); |
| 10535 | nlmsg_free(msg); |
| 10536 | } |
| 10537 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10538 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10539 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10540 | unsigned long state, |
| 10541 | void *_notify) |
| 10542 | { |
| 10543 | struct netlink_notify *notify = _notify; |
| 10544 | struct cfg80211_registered_device *rdev; |
| 10545 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10546 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10547 | |
| 10548 | if (state != NETLINK_URELEASE) |
| 10549 | return NOTIFY_DONE; |
| 10550 | |
| 10551 | rcu_read_lock(); |
| 10552 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10553 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10554 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10555 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10556 | |
| 10557 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10558 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10559 | list) { |
| 10560 | if (reg->nlportid == notify->portid) { |
| 10561 | list_del(®->list); |
| 10562 | kfree(reg); |
| 10563 | break; |
| 10564 | } |
| 10565 | } |
| 10566 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10567 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10568 | |
| 10569 | rcu_read_unlock(); |
| 10570 | |
| 10571 | return NOTIFY_DONE; |
| 10572 | } |
| 10573 | |
| 10574 | static struct notifier_block nl80211_netlink_notifier = { |
| 10575 | .notifier_call = nl80211_netlink_notify, |
| 10576 | }; |
| 10577 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10578 | void cfg80211_ft_event(struct net_device *netdev, |
| 10579 | struct cfg80211_ft_event_params *ft_event) |
| 10580 | { |
| 10581 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10582 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10583 | struct sk_buff *msg; |
| 10584 | void *hdr; |
| 10585 | int err; |
| 10586 | |
| 10587 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10588 | |
| 10589 | if (!ft_event->target_ap) |
| 10590 | return; |
| 10591 | |
| 10592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10593 | if (!msg) |
| 10594 | return; |
| 10595 | |
| 10596 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10597 | if (!hdr) { |
| 10598 | nlmsg_free(msg); |
| 10599 | return; |
| 10600 | } |
| 10601 | |
| 10602 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10603 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10604 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10605 | if (ft_event->ies) |
| 10606 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10607 | if (ft_event->ric_ies) |
| 10608 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10609 | ft_event->ric_ies); |
| 10610 | |
| 10611 | err = genlmsg_end(msg, hdr); |
| 10612 | if (err < 0) { |
| 10613 | nlmsg_free(msg); |
| 10614 | return; |
| 10615 | } |
| 10616 | |
| 10617 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10618 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10619 | } |
| 10620 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10621 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10622 | /* initialisation/exit functions */ |
| 10623 | |
| 10624 | int nl80211_init(void) |
| 10625 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10626 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10627 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10628 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10629 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10630 | if (err) |
| 10631 | return err; |
| 10632 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10633 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10634 | if (err) |
| 10635 | goto err_out; |
| 10636 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10637 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10638 | if (err) |
| 10639 | goto err_out; |
| 10640 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10641 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10642 | if (err) |
| 10643 | goto err_out; |
| 10644 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10645 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10646 | if (err) |
| 10647 | goto err_out; |
| 10648 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10649 | #ifdef CONFIG_NL80211_TESTMODE |
| 10650 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10651 | if (err) |
| 10652 | goto err_out; |
| 10653 | #endif |
| 10654 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10655 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10656 | if (err) |
| 10657 | goto err_out; |
| 10658 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10659 | return 0; |
| 10660 | err_out: |
| 10661 | genl_unregister_family(&nl80211_fam); |
| 10662 | return err; |
| 10663 | } |
| 10664 | |
| 10665 | void nl80211_exit(void) |
| 10666 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10667 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10668 | genl_unregister_family(&nl80211_fam); |
| 10669 | } |