Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 373 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 374 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 375 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 376 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 377 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 379 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 380 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 381 | }; |
| 382 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 384 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 385 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 386 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 387 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 388 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 389 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 390 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 391 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 392 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 393 | }; |
| 394 | |
| 395 | /* policy for the key default flags */ |
| 396 | static const struct nla_policy |
| 397 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 398 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 399 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 400 | }; |
| 401 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 402 | /* policy for WoWLAN attributes */ |
| 403 | static const struct nla_policy |
| 404 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 405 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 406 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 407 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 408 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 409 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 410 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 411 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 413 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 414 | }; |
| 415 | |
| 416 | static const struct nla_policy |
| 417 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 418 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 419 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 420 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 421 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 422 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 423 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 424 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 425 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 426 | }, |
| 427 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 428 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 429 | }, |
| 430 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 431 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 432 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 433 | }; |
| 434 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 435 | /* policy for GTK rekey offload attributes */ |
| 436 | static const struct nla_policy |
| 437 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 438 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 439 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 440 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 441 | }; |
| 442 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 443 | static const struct nla_policy |
| 444 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 445 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 446 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 447 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 448 | }; |
| 449 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 450 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 451 | struct netlink_callback *cb, |
| 452 | struct cfg80211_registered_device **rdev, |
| 453 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 454 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 455 | int err; |
| 456 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 457 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 458 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 459 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 460 | if (!cb->args[0]) { |
| 461 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 462 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 463 | nl80211_policy); |
| 464 | if (err) |
| 465 | goto out_unlock; |
| 466 | |
| 467 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 468 | nl80211_fam.attrbuf); |
| 469 | if (IS_ERR(*wdev)) { |
| 470 | err = PTR_ERR(*wdev); |
| 471 | goto out_unlock; |
| 472 | } |
| 473 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 474 | cb->args[0] = (*rdev)->wiphy_idx; |
| 475 | cb->args[1] = (*wdev)->identifier; |
| 476 | } else { |
| 477 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 478 | struct wireless_dev *tmp; |
| 479 | |
| 480 | if (!wiphy) { |
| 481 | err = -ENODEV; |
| 482 | goto out_unlock; |
| 483 | } |
| 484 | *rdev = wiphy_to_dev(wiphy); |
| 485 | *wdev = NULL; |
| 486 | |
| 487 | mutex_lock(&(*rdev)->devlist_mtx); |
| 488 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 489 | if (tmp->identifier == cb->args[1]) { |
| 490 | *wdev = tmp; |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | mutex_unlock(&(*rdev)->devlist_mtx); |
| 495 | |
| 496 | if (!*wdev) { |
| 497 | err = -ENODEV; |
| 498 | goto out_unlock; |
| 499 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 500 | } |
| 501 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 502 | cfg80211_lock_rdev(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 503 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 505 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 506 | out_unlock: |
| 507 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 508 | rtnl_unlock(); |
| 509 | return err; |
| 510 | } |
| 511 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 512 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | { |
| 514 | cfg80211_unlock_rdev(rdev); |
| 515 | rtnl_unlock(); |
| 516 | } |
| 517 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 518 | /* IE validation */ |
| 519 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 520 | { |
| 521 | const u8 *pos; |
| 522 | int len; |
| 523 | |
| 524 | if (!attr) |
| 525 | return true; |
| 526 | |
| 527 | pos = nla_data(attr); |
| 528 | len = nla_len(attr); |
| 529 | |
| 530 | while (len) { |
| 531 | u8 elemlen; |
| 532 | |
| 533 | if (len < 2) |
| 534 | return false; |
| 535 | len -= 2; |
| 536 | |
| 537 | elemlen = pos[1]; |
| 538 | if (elemlen > len) |
| 539 | return false; |
| 540 | |
| 541 | len -= elemlen; |
| 542 | pos += 2 + elemlen; |
| 543 | } |
| 544 | |
| 545 | return true; |
| 546 | } |
| 547 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 548 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 549 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 550 | int flags, u8 cmd) |
| 551 | { |
| 552 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 553 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 556 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 557 | struct ieee80211_channel *chan, |
| 558 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 559 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 560 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 561 | chan->center_freq)) |
| 562 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 563 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 564 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 565 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 566 | goto nla_put_failure; |
| 567 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 569 | goto nla_put_failure; |
| 570 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 572 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 573 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 574 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 575 | goto nla_put_failure; |
| 576 | if (large) { |
| 577 | u32 time; |
| 578 | |
| 579 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 580 | |
| 581 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 582 | chan->dfs_state)) |
| 583 | goto nla_put_failure; |
| 584 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 585 | time)) |
| 586 | goto nla_put_failure; |
| 587 | } |
| 588 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 590 | if (large) { |
| 591 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 592 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 593 | goto nla_put_failure; |
| 594 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 595 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 596 | goto nla_put_failure; |
| 597 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 598 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 599 | goto nla_put_failure; |
| 600 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 601 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 602 | goto nla_put_failure; |
| 603 | } |
| 604 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 605 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 606 | DBM_TO_MBM(chan->max_power))) |
| 607 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | |
| 611 | nla_put_failure: |
| 612 | return -ENOBUFS; |
| 613 | } |
| 614 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 615 | /* netlink command implementations */ |
| 616 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 617 | struct key_parse { |
| 618 | struct key_params p; |
| 619 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 620 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 621 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 622 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 623 | }; |
| 624 | |
| 625 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 626 | { |
| 627 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 628 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 629 | nl80211_key_policy); |
| 630 | if (err) |
| 631 | return err; |
| 632 | |
| 633 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 634 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 635 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 636 | if (k->def) { |
| 637 | k->def_uni = true; |
| 638 | k->def_multi = true; |
| 639 | } |
| 640 | if (k->defmgmt) |
| 641 | k->def_multi = true; |
| 642 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 643 | if (tb[NL80211_KEY_IDX]) |
| 644 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 645 | |
| 646 | if (tb[NL80211_KEY_DATA]) { |
| 647 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 648 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 649 | } |
| 650 | |
| 651 | if (tb[NL80211_KEY_SEQ]) { |
| 652 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 653 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 654 | } |
| 655 | |
| 656 | if (tb[NL80211_KEY_CIPHER]) |
| 657 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 658 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 659 | if (tb[NL80211_KEY_TYPE]) { |
| 660 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 661 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 662 | return -EINVAL; |
| 663 | } |
| 664 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 665 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 666 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 667 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 668 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 669 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 670 | if (err) |
| 671 | return err; |
| 672 | |
| 673 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 674 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 675 | } |
| 676 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 681 | { |
| 682 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 683 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 684 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 685 | } |
| 686 | |
| 687 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 688 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 689 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 690 | } |
| 691 | |
| 692 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 693 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 694 | |
| 695 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 696 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 697 | |
| 698 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 699 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 700 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 701 | if (k->def) { |
| 702 | k->def_uni = true; |
| 703 | k->def_multi = true; |
| 704 | } |
| 705 | if (k->defmgmt) |
| 706 | k->def_multi = true; |
| 707 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 708 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 709 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 710 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 714 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 715 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 716 | int err = nla_parse_nested( |
| 717 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 718 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 719 | nl80211_key_default_policy); |
| 720 | if (err) |
| 721 | return err; |
| 722 | |
| 723 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 724 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 725 | } |
| 726 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 731 | { |
| 732 | int err; |
| 733 | |
| 734 | memset(k, 0, sizeof(*k)); |
| 735 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 736 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 737 | |
| 738 | if (info->attrs[NL80211_ATTR_KEY]) |
| 739 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 740 | else |
| 741 | err = nl80211_parse_key_old(info, k); |
| 742 | |
| 743 | if (err) |
| 744 | return err; |
| 745 | |
| 746 | if (k->def && k->defmgmt) |
| 747 | return -EINVAL; |
| 748 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 749 | if (k->defmgmt) { |
| 750 | if (k->def_uni || !k->def_multi) |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 754 | if (k->idx != -1) { |
| 755 | if (k->defmgmt) { |
| 756 | if (k->idx < 4 || k->idx > 5) |
| 757 | return -EINVAL; |
| 758 | } else if (k->def) { |
| 759 | if (k->idx < 0 || k->idx > 3) |
| 760 | return -EINVAL; |
| 761 | } else { |
| 762 | if (k->idx < 0 || k->idx > 5) |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 770 | static struct cfg80211_cached_keys * |
| 771 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 772 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 773 | { |
| 774 | struct key_parse parse; |
| 775 | struct nlattr *key; |
| 776 | struct cfg80211_cached_keys *result; |
| 777 | int rem, err, def = 0; |
| 778 | |
| 779 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 780 | if (!result) |
| 781 | return ERR_PTR(-ENOMEM); |
| 782 | |
| 783 | result->def = -1; |
| 784 | result->defmgmt = -1; |
| 785 | |
| 786 | nla_for_each_nested(key, keys, rem) { |
| 787 | memset(&parse, 0, sizeof(parse)); |
| 788 | parse.idx = -1; |
| 789 | |
| 790 | err = nl80211_parse_key_new(key, &parse); |
| 791 | if (err) |
| 792 | goto error; |
| 793 | err = -EINVAL; |
| 794 | if (!parse.p.key) |
| 795 | goto error; |
| 796 | if (parse.idx < 0 || parse.idx > 4) |
| 797 | goto error; |
| 798 | if (parse.def) { |
| 799 | if (def) |
| 800 | goto error; |
| 801 | def = 1; |
| 802 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 803 | if (!parse.def_uni || !parse.def_multi) |
| 804 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 805 | } else if (parse.defmgmt) |
| 806 | goto error; |
| 807 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 808 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 809 | if (err) |
| 810 | goto error; |
| 811 | result->params[parse.idx].cipher = parse.p.cipher; |
| 812 | result->params[parse.idx].key_len = parse.p.key_len; |
| 813 | result->params[parse.idx].key = result->data[parse.idx]; |
| 814 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 815 | |
| 816 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 817 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 818 | if (no_ht) |
| 819 | *no_ht = true; |
| 820 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | return result; |
| 824 | error: |
| 825 | kfree(result); |
| 826 | return ERR_PTR(err); |
| 827 | } |
| 828 | |
| 829 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 830 | { |
| 831 | ASSERT_WDEV_LOCK(wdev); |
| 832 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 833 | switch (wdev->iftype) { |
| 834 | case NL80211_IFTYPE_AP: |
| 835 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 836 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 837 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 838 | break; |
| 839 | case NL80211_IFTYPE_ADHOC: |
| 840 | if (!wdev->current_bss) |
| 841 | return -ENOLINK; |
| 842 | break; |
| 843 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 845 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 846 | return -ENOLINK; |
| 847 | break; |
| 848 | default: |
| 849 | return -EINVAL; |
| 850 | } |
| 851 | |
| 852 | return 0; |
| 853 | } |
| 854 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 855 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 856 | { |
| 857 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 858 | int i; |
| 859 | |
| 860 | if (!nl_modes) |
| 861 | goto nla_put_failure; |
| 862 | |
| 863 | i = 0; |
| 864 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 865 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 866 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 867 | ifmodes >>= 1; |
| 868 | i++; |
| 869 | } |
| 870 | |
| 871 | nla_nest_end(msg, nl_modes); |
| 872 | return 0; |
| 873 | |
| 874 | nla_put_failure: |
| 875 | return -ENOBUFS; |
| 876 | } |
| 877 | |
| 878 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 879 | struct sk_buff *msg, |
| 880 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 881 | { |
| 882 | struct nlattr *nl_combis; |
| 883 | int i, j; |
| 884 | |
| 885 | nl_combis = nla_nest_start(msg, |
| 886 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 887 | if (!nl_combis) |
| 888 | goto nla_put_failure; |
| 889 | |
| 890 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 891 | const struct ieee80211_iface_combination *c; |
| 892 | struct nlattr *nl_combi, *nl_limits; |
| 893 | |
| 894 | c = &wiphy->iface_combinations[i]; |
| 895 | |
| 896 | nl_combi = nla_nest_start(msg, i + 1); |
| 897 | if (!nl_combi) |
| 898 | goto nla_put_failure; |
| 899 | |
| 900 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 901 | if (!nl_limits) |
| 902 | goto nla_put_failure; |
| 903 | |
| 904 | for (j = 0; j < c->n_limits; j++) { |
| 905 | struct nlattr *nl_limit; |
| 906 | |
| 907 | nl_limit = nla_nest_start(msg, j + 1); |
| 908 | if (!nl_limit) |
| 909 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 910 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 911 | c->limits[j].max)) |
| 912 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 913 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 914 | c->limits[j].types)) |
| 915 | goto nla_put_failure; |
| 916 | nla_nest_end(msg, nl_limit); |
| 917 | } |
| 918 | |
| 919 | nla_nest_end(msg, nl_limits); |
| 920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 921 | if (c->beacon_int_infra_match && |
| 922 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 923 | goto nla_put_failure; |
| 924 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 925 | c->num_different_channels) || |
| 926 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 927 | c->max_interfaces)) |
| 928 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 929 | if (large && |
| 930 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 931 | c->radar_detect_widths)) |
| 932 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 933 | |
| 934 | nla_nest_end(msg, nl_combi); |
| 935 | } |
| 936 | |
| 937 | nla_nest_end(msg, nl_combis); |
| 938 | |
| 939 | return 0; |
| 940 | nla_put_failure: |
| 941 | return -ENOBUFS; |
| 942 | } |
| 943 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 944 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 945 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 946 | struct sk_buff *msg) |
| 947 | { |
| 948 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 949 | struct nlattr *nl_tcp; |
| 950 | |
| 951 | if (!tcp) |
| 952 | return 0; |
| 953 | |
| 954 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 955 | if (!nl_tcp) |
| 956 | return -ENOBUFS; |
| 957 | |
| 958 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 959 | tcp->data_payload_max)) |
| 960 | return -ENOBUFS; |
| 961 | |
| 962 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 963 | tcp->data_payload_max)) |
| 964 | return -ENOBUFS; |
| 965 | |
| 966 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 967 | return -ENOBUFS; |
| 968 | |
| 969 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 970 | sizeof(*tcp->tok), tcp->tok)) |
| 971 | return -ENOBUFS; |
| 972 | |
| 973 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 974 | tcp->data_interval_max)) |
| 975 | return -ENOBUFS; |
| 976 | |
| 977 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 978 | tcp->wake_payload_max)) |
| 979 | return -ENOBUFS; |
| 980 | |
| 981 | nla_nest_end(msg, nl_tcp); |
| 982 | return 0; |
| 983 | } |
| 984 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 985 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 986 | struct cfg80211_registered_device *dev, |
| 987 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | { |
| 989 | struct nlattr *nl_wowlan; |
| 990 | |
| 991 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
| 992 | return 0; |
| 993 | |
| 994 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 995 | if (!nl_wowlan) |
| 996 | return -ENOBUFS; |
| 997 | |
| 998 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 999 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1000 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1001 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1002 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1003 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1004 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1005 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1006 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1007 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1008 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1009 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1010 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1011 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1012 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1013 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1014 | return -ENOBUFS; |
| 1015 | |
| 1016 | if (dev->wiphy.wowlan.n_patterns) { |
| 1017 | struct nl80211_wowlan_pattern_support pat = { |
| 1018 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1019 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, |
| 1020 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, |
| 1021 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, |
| 1022 | }; |
| 1023 | |
| 1024 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1025 | sizeof(pat), &pat)) |
| 1026 | return -ENOBUFS; |
| 1027 | } |
| 1028 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1029 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1030 | return -ENOBUFS; |
| 1031 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1032 | nla_nest_end(msg, nl_wowlan); |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | #endif |
| 1037 | |
| 1038 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1039 | struct ieee80211_supported_band *sband) |
| 1040 | { |
| 1041 | struct nlattr *nl_rates, *nl_rate; |
| 1042 | struct ieee80211_rate *rate; |
| 1043 | int i; |
| 1044 | |
| 1045 | /* add HT info */ |
| 1046 | if (sband->ht_cap.ht_supported && |
| 1047 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1048 | sizeof(sband->ht_cap.mcs), |
| 1049 | &sband->ht_cap.mcs) || |
| 1050 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1051 | sband->ht_cap.cap) || |
| 1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1053 | sband->ht_cap.ampdu_factor) || |
| 1054 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1055 | sband->ht_cap.ampdu_density))) |
| 1056 | return -ENOBUFS; |
| 1057 | |
| 1058 | /* add VHT info */ |
| 1059 | if (sband->vht_cap.vht_supported && |
| 1060 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1061 | sizeof(sband->vht_cap.vht_mcs), |
| 1062 | &sband->vht_cap.vht_mcs) || |
| 1063 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1064 | sband->vht_cap.cap))) |
| 1065 | return -ENOBUFS; |
| 1066 | |
| 1067 | /* add bitrates */ |
| 1068 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1069 | if (!nl_rates) |
| 1070 | return -ENOBUFS; |
| 1071 | |
| 1072 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1073 | nl_rate = nla_nest_start(msg, i); |
| 1074 | if (!nl_rate) |
| 1075 | return -ENOBUFS; |
| 1076 | |
| 1077 | rate = &sband->bitrates[i]; |
| 1078 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1079 | rate->bitrate)) |
| 1080 | return -ENOBUFS; |
| 1081 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1082 | nla_put_flag(msg, |
| 1083 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1084 | return -ENOBUFS; |
| 1085 | |
| 1086 | nla_nest_end(msg, nl_rate); |
| 1087 | } |
| 1088 | |
| 1089 | nla_nest_end(msg, nl_rates); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | static int |
| 1095 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1096 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1097 | { |
| 1098 | u16 stypes; |
| 1099 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1100 | enum nl80211_iftype ift; |
| 1101 | int i; |
| 1102 | |
| 1103 | if (!mgmt_stypes) |
| 1104 | return 0; |
| 1105 | |
| 1106 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1107 | if (!nl_ifs) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1111 | nl_ftypes = nla_nest_start(msg, ift); |
| 1112 | if (!nl_ftypes) |
| 1113 | return -ENOBUFS; |
| 1114 | i = 0; |
| 1115 | stypes = mgmt_stypes[ift].tx; |
| 1116 | while (stypes) { |
| 1117 | if ((stypes & 1) && |
| 1118 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1119 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1120 | return -ENOBUFS; |
| 1121 | stypes >>= 1; |
| 1122 | i++; |
| 1123 | } |
| 1124 | nla_nest_end(msg, nl_ftypes); |
| 1125 | } |
| 1126 | |
| 1127 | nla_nest_end(msg, nl_ifs); |
| 1128 | |
| 1129 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1130 | if (!nl_ifs) |
| 1131 | return -ENOBUFS; |
| 1132 | |
| 1133 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1134 | nl_ftypes = nla_nest_start(msg, ift); |
| 1135 | if (!nl_ftypes) |
| 1136 | return -ENOBUFS; |
| 1137 | i = 0; |
| 1138 | stypes = mgmt_stypes[ift].rx; |
| 1139 | while (stypes) { |
| 1140 | if ((stypes & 1) && |
| 1141 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1142 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1143 | return -ENOBUFS; |
| 1144 | stypes >>= 1; |
| 1145 | i++; |
| 1146 | } |
| 1147 | nla_nest_end(msg, nl_ftypes); |
| 1148 | } |
| 1149 | nla_nest_end(msg, nl_ifs); |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1155 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1156 | int flags, bool split, long *split_start, |
| 1157 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1158 | { |
| 1159 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1160 | struct nlattr *nl_bands, *nl_band; |
| 1161 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1162 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1163 | enum ieee80211_band band; |
| 1164 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1165 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1166 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1167 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1168 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1169 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1170 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1171 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1172 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1173 | return -ENOBUFS; |
| 1174 | |
| 1175 | /* allow always using the variables */ |
| 1176 | if (!split) { |
| 1177 | split_start = &start; |
| 1178 | band_start = &start_band; |
| 1179 | chan_start = &start_chan; |
| 1180 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1184 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1185 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1186 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1187 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1188 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1189 | switch (*split_start) { |
| 1190 | case 0: |
| 1191 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1192 | dev->wiphy.retry_short) || |
| 1193 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1194 | dev->wiphy.retry_long) || |
| 1195 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1196 | dev->wiphy.frag_threshold) || |
| 1197 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1198 | dev->wiphy.rts_threshold) || |
| 1199 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1200 | dev->wiphy.coverage_class) || |
| 1201 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1202 | dev->wiphy.max_scan_ssids) || |
| 1203 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1204 | dev->wiphy.max_sched_scan_ssids) || |
| 1205 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1206 | dev->wiphy.max_scan_ie_len) || |
| 1207 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1208 | dev->wiphy.max_sched_scan_ie_len) || |
| 1209 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1210 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1211 | goto nla_put_failure; |
| 1212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1214 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1215 | goto nla_put_failure; |
| 1216 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1217 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1218 | goto nla_put_failure; |
| 1219 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1220 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1221 | goto nla_put_failure; |
| 1222 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1223 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1224 | goto nla_put_failure; |
| 1225 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1226 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1227 | goto nla_put_failure; |
| 1228 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1229 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1230 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1231 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1232 | (*split_start)++; |
| 1233 | if (split) |
| 1234 | break; |
| 1235 | case 1: |
| 1236 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1237 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1238 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1239 | goto nla_put_failure; |
| 1240 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1241 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1242 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1243 | goto nla_put_failure; |
| 1244 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1245 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1246 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1247 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1248 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1250 | dev->wiphy.available_antennas_tx) || |
| 1251 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1252 | dev->wiphy.available_antennas_rx)) |
| 1253 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1254 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1256 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1257 | dev->wiphy.probe_resp_offload)) |
| 1258 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1259 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | if ((dev->wiphy.available_antennas_tx || |
| 1261 | dev->wiphy.available_antennas_rx) && |
| 1262 | dev->ops->get_antenna) { |
| 1263 | u32 tx_ant = 0, rx_ant = 0; |
| 1264 | int res; |
| 1265 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1266 | if (!res) { |
| 1267 | if (nla_put_u32(msg, |
| 1268 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1269 | tx_ant) || |
| 1270 | nla_put_u32(msg, |
| 1271 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1272 | rx_ant)) |
| 1273 | goto nla_put_failure; |
| 1274 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | (*split_start)++; |
| 1278 | if (split) |
| 1279 | break; |
| 1280 | case 2: |
| 1281 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1282 | dev->wiphy.interface_modes)) |
| 1283 | goto nla_put_failure; |
| 1284 | (*split_start)++; |
| 1285 | if (split) |
| 1286 | break; |
| 1287 | case 3: |
| 1288 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1289 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1290 | goto nla_put_failure; |
| 1291 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
| 1293 | struct ieee80211_supported_band *sband; |
| 1294 | |
| 1295 | sband = dev->wiphy.bands[band]; |
| 1296 | |
| 1297 | if (!sband) |
| 1298 | continue; |
| 1299 | |
| 1300 | nl_band = nla_nest_start(msg, band); |
| 1301 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1302 | goto nla_put_failure; |
| 1303 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | switch (*chan_start) { |
| 1305 | case 0: |
| 1306 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1307 | goto nla_put_failure; |
| 1308 | (*chan_start)++; |
| 1309 | if (split) |
| 1310 | break; |
| 1311 | default: |
| 1312 | /* add frequencies */ |
| 1313 | nl_freqs = nla_nest_start( |
| 1314 | msg, NL80211_BAND_ATTR_FREQS); |
| 1315 | if (!nl_freqs) |
| 1316 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1317 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | for (i = *chan_start - 1; |
| 1319 | i < sband->n_channels; |
| 1320 | i++) { |
| 1321 | nl_freq = nla_nest_start(msg, i); |
| 1322 | if (!nl_freq) |
| 1323 | goto nla_put_failure; |
| 1324 | |
| 1325 | chan = &sband->channels[i]; |
| 1326 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1327 | if (nl80211_msg_put_channel(msg, chan, |
| 1328 | split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
| 1330 | |
| 1331 | nla_nest_end(msg, nl_freq); |
| 1332 | if (split) |
| 1333 | break; |
| 1334 | } |
| 1335 | if (i < sband->n_channels) |
| 1336 | *chan_start = i + 2; |
| 1337 | else |
| 1338 | *chan_start = 0; |
| 1339 | nla_nest_end(msg, nl_freqs); |
| 1340 | } |
| 1341 | |
| 1342 | nla_nest_end(msg, nl_band); |
| 1343 | |
| 1344 | if (split) { |
| 1345 | /* start again here */ |
| 1346 | if (*chan_start) |
| 1347 | band--; |
| 1348 | break; |
| 1349 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1350 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1352 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | if (band < IEEE80211_NUM_BANDS) |
| 1354 | *band_start = band + 1; |
| 1355 | else |
| 1356 | *band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | /* if bands & channels are done, continue outside */ |
| 1359 | if (*band_start == 0 && *chan_start == 0) |
| 1360 | (*split_start)++; |
| 1361 | if (split) |
| 1362 | break; |
| 1363 | case 4: |
| 1364 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1365 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1366 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | |
| 1368 | i = 0; |
| 1369 | #define CMD(op, n) \ |
| 1370 | do { \ |
| 1371 | if (dev->ops->op) { \ |
| 1372 | i++; \ |
| 1373 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1374 | goto nla_put_failure; \ |
| 1375 | } \ |
| 1376 | } while (0) |
| 1377 | |
| 1378 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1379 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1380 | CMD(add_key, NEW_KEY); |
| 1381 | CMD(start_ap, START_AP); |
| 1382 | CMD(add_station, NEW_STATION); |
| 1383 | CMD(add_mpath, NEW_MPATH); |
| 1384 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1385 | CMD(change_bss, SET_BSS); |
| 1386 | CMD(auth, AUTHENTICATE); |
| 1387 | CMD(assoc, ASSOCIATE); |
| 1388 | CMD(deauth, DEAUTHENTICATE); |
| 1389 | CMD(disassoc, DISASSOCIATE); |
| 1390 | CMD(join_ibss, JOIN_IBSS); |
| 1391 | CMD(join_mesh, JOIN_MESH); |
| 1392 | CMD(set_pmksa, SET_PMKSA); |
| 1393 | CMD(del_pmksa, DEL_PMKSA); |
| 1394 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1395 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1396 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1397 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1398 | CMD(mgmt_tx, FRAME); |
| 1399 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1400 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1401 | i++; |
| 1402 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1403 | goto nla_put_failure; |
| 1404 | } |
| 1405 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1406 | dev->ops->join_mesh) { |
| 1407 | i++; |
| 1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1409 | goto nla_put_failure; |
| 1410 | } |
| 1411 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1412 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1413 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1414 | CMD(tdls_oper, TDLS_OPER); |
| 1415 | } |
| 1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1417 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1418 | CMD(probe_client, PROBE_CLIENT); |
| 1419 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1420 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1421 | i++; |
| 1422 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1423 | goto nla_put_failure; |
| 1424 | } |
| 1425 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1426 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1427 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1428 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1430 | #endif |
| 1431 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1432 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1433 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1434 | if (dev->ops->connect || dev->ops->auth) { |
| 1435 | i++; |
| 1436 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1437 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1441 | i++; |
| 1442 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1443 | goto nla_put_failure; |
| 1444 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1445 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | nla_nest_end(msg, nl_cmds); |
| 1447 | (*split_start)++; |
| 1448 | if (split) |
| 1449 | break; |
| 1450 | case 5: |
| 1451 | if (dev->ops->remain_on_channel && |
| 1452 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1453 | nla_put_u32(msg, |
| 1454 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1455 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1456 | goto nla_put_failure; |
| 1457 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1459 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1460 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1461 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1463 | goto nla_put_failure; |
| 1464 | (*split_start)++; |
| 1465 | if (split) |
| 1466 | break; |
| 1467 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1468 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1469 | if (nl80211_send_wowlan(msg, dev, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | goto nla_put_failure; |
| 1471 | (*split_start)++; |
| 1472 | if (split) |
| 1473 | break; |
| 1474 | #else |
| 1475 | (*split_start)++; |
| 1476 | #endif |
| 1477 | case 7: |
| 1478 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1479 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1480 | goto nla_put_failure; |
| 1481 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1482 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1484 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1485 | (*split_start)++; |
| 1486 | if (split) |
| 1487 | break; |
| 1488 | case 8: |
| 1489 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1490 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1491 | dev->wiphy.ap_sme_capa)) |
| 1492 | goto nla_put_failure; |
| 1493 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1494 | features = dev->wiphy.features; |
| 1495 | /* |
| 1496 | * We can only add the per-channel limit information if the |
| 1497 | * dump is split, otherwise it makes it too big. Therefore |
| 1498 | * only advertise it in that case. |
| 1499 | */ |
| 1500 | if (split) |
| 1501 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1502 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | goto nla_put_failure; |
| 1504 | |
| 1505 | if (dev->wiphy.ht_capa_mod_mask && |
| 1506 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1507 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1508 | dev->wiphy.ht_capa_mod_mask)) |
| 1509 | goto nla_put_failure; |
| 1510 | |
| 1511 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1512 | dev->wiphy.max_acl_mac_addrs && |
| 1513 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1514 | dev->wiphy.max_acl_mac_addrs)) |
| 1515 | goto nla_put_failure; |
| 1516 | |
| 1517 | /* |
| 1518 | * Any information below this point is only available to |
| 1519 | * applications that can deal with it being split. This |
| 1520 | * helps ensure that newly added capabilities don't break |
| 1521 | * older tools by overrunning their buffers. |
| 1522 | * |
| 1523 | * We still increment split_start so that in the split |
| 1524 | * case we'll continue with more data in the next round, |
| 1525 | * but break unconditionally so unsplit data stops here. |
| 1526 | */ |
| 1527 | (*split_start)++; |
| 1528 | break; |
| 1529 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1530 | if (dev->wiphy.extended_capabilities && |
| 1531 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1532 | dev->wiphy.extended_capabilities_len, |
| 1533 | dev->wiphy.extended_capabilities) || |
| 1534 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1535 | dev->wiphy.extended_capabilities_len, |
| 1536 | dev->wiphy.extended_capabilities_mask))) |
| 1537 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1538 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1539 | if (dev->wiphy.vht_capa_mod_mask && |
| 1540 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1541 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1542 | dev->wiphy.vht_capa_mod_mask)) |
| 1543 | goto nla_put_failure; |
| 1544 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | /* done */ |
| 1546 | *split_start = 0; |
| 1547 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1548 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1549 | return genlmsg_end(msg, hdr); |
| 1550 | |
| 1551 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1552 | genlmsg_cancel(msg, hdr); |
| 1553 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1557 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1558 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1559 | int start = cb->args[0]; |
| 1560 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1561 | s64 filter_wiphy = -1; |
| 1562 | bool split = false; |
| 1563 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1564 | int res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1565 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1566 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1567 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1568 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1569 | if (res == 0) { |
| 1570 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1571 | if (tb[NL80211_ATTR_WIPHY]) |
| 1572 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1573 | if (tb[NL80211_ATTR_WDEV]) |
| 1574 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1575 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1576 | struct net_device *netdev; |
| 1577 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1578 | |
| 1579 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1580 | if (!netdev) { |
| 1581 | mutex_unlock(&cfg80211_mutex); |
| 1582 | return -ENODEV; |
| 1583 | } |
| 1584 | if (netdev->ieee80211_ptr) { |
| 1585 | dev = wiphy_to_dev( |
| 1586 | netdev->ieee80211_ptr->wiphy); |
| 1587 | filter_wiphy = dev->wiphy_idx; |
| 1588 | } |
| 1589 | dev_put(netdev); |
| 1590 | } |
| 1591 | } |
| 1592 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1593 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1594 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1595 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1596 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1597 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1598 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1599 | continue; |
| 1600 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1601 | do { |
| 1602 | ret = nl80211_send_wiphy(dev, skb, |
| 1603 | NETLINK_CB(cb->skb).portid, |
| 1604 | cb->nlh->nlmsg_seq, |
| 1605 | NLM_F_MULTI, |
| 1606 | split, &cb->args[1], |
| 1607 | &cb->args[2], |
| 1608 | &cb->args[3]); |
| 1609 | if (ret < 0) { |
| 1610 | /* |
| 1611 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1612 | * or EMSGSIZE returned), this SKB is still |
| 1613 | * empty (so it's not too big because another |
| 1614 | * wiphy dataset is already in the skb) and |
| 1615 | * we've not tried to adjust the dump allocation |
| 1616 | * yet ... then adjust the alloc size to be |
| 1617 | * bigger, and return 1 but with the empty skb. |
| 1618 | * This results in an empty message being RX'ed |
| 1619 | * in userspace, but that is ignored. |
| 1620 | * |
| 1621 | * We can then retry with the larger buffer. |
| 1622 | */ |
| 1623 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1624 | !skb->len && |
| 1625 | cb->min_dump_alloc < 4096) { |
| 1626 | cb->min_dump_alloc = 4096; |
| 1627 | mutex_unlock(&cfg80211_mutex); |
| 1628 | return 1; |
| 1629 | } |
| 1630 | idx--; |
| 1631 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1632 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1633 | } while (cb->args[1] > 0); |
| 1634 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1635 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1636 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1637 | |
| 1638 | cb->args[0] = idx; |
| 1639 | |
| 1640 | return skb->len; |
| 1641 | } |
| 1642 | |
| 1643 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1644 | { |
| 1645 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1646 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1647 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1648 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1649 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1650 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1651 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1652 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1653 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1654 | nlmsg_free(msg); |
| 1655 | return -ENOBUFS; |
| 1656 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1657 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1658 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1661 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1662 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1663 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1664 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1665 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1666 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1667 | }; |
| 1668 | |
| 1669 | static int parse_txq_params(struct nlattr *tb[], |
| 1670 | struct ieee80211_txq_params *txq_params) |
| 1671 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1672 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1673 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1674 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1675 | return -EINVAL; |
| 1676 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1677 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1678 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1679 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1680 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1681 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1682 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1683 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1684 | return -EINVAL; |
| 1685 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1686 | return 0; |
| 1687 | } |
| 1688 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1689 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1690 | { |
| 1691 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1692 | * You can only set the channel explicitly for WDS interfaces, |
| 1693 | * all others have their channel managed via their respective |
| 1694 | * "establish a connection" command (connect, join, ...) |
| 1695 | * |
| 1696 | * For AP/GO and mesh mode, the channel can be set with the |
| 1697 | * channel userspace API, but is only stored and passed to the |
| 1698 | * low-level driver when the AP starts or the mesh is joined. |
| 1699 | * This is for backward compatibility, userspace can also give |
| 1700 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1701 | * |
| 1702 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1703 | * whatever else is going on, so they have their own special |
| 1704 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1705 | */ |
| 1706 | return !wdev || |
| 1707 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1708 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1709 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1710 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1713 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1714 | struct genl_info *info, |
| 1715 | struct cfg80211_chan_def *chandef) |
| 1716 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1717 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1718 | |
| 1719 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1720 | return -EINVAL; |
| 1721 | |
| 1722 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1723 | |
| 1724 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1725 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1726 | chandef->center_freq1 = control_freq; |
| 1727 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1728 | |
| 1729 | /* Primary channel not allowed */ |
| 1730 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1731 | return -EINVAL; |
| 1732 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1733 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1734 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1735 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1736 | chantype = nla_get_u32( |
| 1737 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1738 | |
| 1739 | switch (chantype) { |
| 1740 | case NL80211_CHAN_NO_HT: |
| 1741 | case NL80211_CHAN_HT20: |
| 1742 | case NL80211_CHAN_HT40PLUS: |
| 1743 | case NL80211_CHAN_HT40MINUS: |
| 1744 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1745 | chantype); |
| 1746 | break; |
| 1747 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1748 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1749 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1750 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1751 | chandef->width = |
| 1752 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1753 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1754 | chandef->center_freq1 = |
| 1755 | nla_get_u32( |
| 1756 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1757 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1758 | chandef->center_freq2 = |
| 1759 | nla_get_u32( |
| 1760 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1761 | } |
| 1762 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1763 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1764 | return -EINVAL; |
| 1765 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1766 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1767 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1768 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1769 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1770 | return 0; |
| 1771 | } |
| 1772 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1773 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1774 | struct wireless_dev *wdev, |
| 1775 | struct genl_info *info) |
| 1776 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1777 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1778 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1779 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1780 | |
| 1781 | if (wdev) |
| 1782 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1783 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1784 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1785 | return -EOPNOTSUPP; |
| 1786 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1787 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1788 | if (result) |
| 1789 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1790 | |
| 1791 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1792 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1793 | case NL80211_IFTYPE_AP: |
| 1794 | case NL80211_IFTYPE_P2P_GO: |
| 1795 | if (wdev->beacon_interval) { |
| 1796 | result = -EBUSY; |
| 1797 | break; |
| 1798 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1799 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1800 | result = -EINVAL; |
| 1801 | break; |
| 1802 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1803 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1804 | result = 0; |
| 1805 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1806 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1807 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1808 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1809 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1810 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1811 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1812 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1813 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1814 | } |
| 1815 | mutex_unlock(&rdev->devlist_mtx); |
| 1816 | |
| 1817 | return result; |
| 1818 | } |
| 1819 | |
| 1820 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1823 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1824 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1825 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1828 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1829 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1831 | struct net_device *dev = info->user_ptr[1]; |
| 1832 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1833 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1834 | |
| 1835 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1838 | if (netif_running(dev)) |
| 1839 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1840 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1841 | if (!rdev->ops->set_wds_peer) |
| 1842 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1843 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1844 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1845 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1846 | |
| 1847 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1848 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1852 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1853 | { |
| 1854 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1855 | struct net_device *netdev = NULL; |
| 1856 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1857 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1858 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1859 | u32 changed; |
| 1860 | u8 retry_short = 0, retry_long = 0; |
| 1861 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1862 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1863 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1864 | /* |
| 1865 | * Try to find the wiphy and netdev. Normally this |
| 1866 | * function shouldn't need the netdev, but this is |
| 1867 | * done for backward compatibility -- previously |
| 1868 | * setting the channel was done per wiphy, but now |
| 1869 | * it is per netdev. Previous userland like hostapd |
| 1870 | * also passed a netdev to set_wiphy, so that it is |
| 1871 | * possible to let that go to the right netdev! |
| 1872 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1873 | mutex_lock(&cfg80211_mutex); |
| 1874 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1875 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1876 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1877 | |
| 1878 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1879 | if (netdev && netdev->ieee80211_ptr) { |
| 1880 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1881 | mutex_lock(&rdev->mtx); |
| 1882 | } else |
| 1883 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1886 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1887 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1888 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1889 | if (IS_ERR(rdev)) { |
| 1890 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1891 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | } |
| 1893 | wdev = NULL; |
| 1894 | netdev = NULL; |
| 1895 | result = 0; |
| 1896 | |
| 1897 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1898 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1899 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1900 | |
| 1901 | /* |
| 1902 | * end workaround code, by now the rdev is available |
| 1903 | * and locked, and wdev may or may not be NULL. |
| 1904 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1905 | |
| 1906 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1907 | result = cfg80211_dev_rename( |
| 1908 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1909 | |
| 1910 | mutex_unlock(&cfg80211_mutex); |
| 1911 | |
| 1912 | if (result) |
| 1913 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1914 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1915 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1916 | struct ieee80211_txq_params txq_params; |
| 1917 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1918 | |
| 1919 | if (!rdev->ops->set_txq_params) { |
| 1920 | result = -EOPNOTSUPP; |
| 1921 | goto bad_res; |
| 1922 | } |
| 1923 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1924 | if (!netdev) { |
| 1925 | result = -EINVAL; |
| 1926 | goto bad_res; |
| 1927 | } |
| 1928 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1929 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1930 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1931 | result = -EINVAL; |
| 1932 | goto bad_res; |
| 1933 | } |
| 1934 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1935 | if (!netif_running(netdev)) { |
| 1936 | result = -ENETDOWN; |
| 1937 | goto bad_res; |
| 1938 | } |
| 1939 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1940 | nla_for_each_nested(nl_txq_params, |
| 1941 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1942 | rem_txq_params) { |
| 1943 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1944 | nla_data(nl_txq_params), |
| 1945 | nla_len(nl_txq_params), |
| 1946 | txq_params_policy); |
| 1947 | result = parse_txq_params(tb, &txq_params); |
| 1948 | if (result) |
| 1949 | goto bad_res; |
| 1950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1951 | result = rdev_set_txq_params(rdev, netdev, |
| 1952 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1953 | if (result) |
| 1954 | goto bad_res; |
| 1955 | } |
| 1956 | } |
| 1957 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1958 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1959 | result = __nl80211_set_channel(rdev, |
| 1960 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1961 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1962 | if (result) |
| 1963 | goto bad_res; |
| 1964 | } |
| 1965 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1966 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1967 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1968 | enum nl80211_tx_power_setting type; |
| 1969 | int idx, mbm = 0; |
| 1970 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1971 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1972 | txp_wdev = NULL; |
| 1973 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1974 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1975 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1976 | goto bad_res; |
| 1977 | } |
| 1978 | |
| 1979 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1980 | type = nla_get_u32(info->attrs[idx]); |
| 1981 | |
| 1982 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1983 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1984 | result = -EINVAL; |
| 1985 | goto bad_res; |
| 1986 | } |
| 1987 | |
| 1988 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1989 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1990 | mbm = nla_get_u32(info->attrs[idx]); |
| 1991 | } |
| 1992 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1993 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1994 | if (result) |
| 1995 | goto bad_res; |
| 1996 | } |
| 1997 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1998 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1999 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2000 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2001 | if ((!rdev->wiphy.available_antennas_tx && |
| 2002 | !rdev->wiphy.available_antennas_rx) || |
| 2003 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2004 | result = -EOPNOTSUPP; |
| 2005 | goto bad_res; |
| 2006 | } |
| 2007 | |
| 2008 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2009 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2010 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2011 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2012 | * available antenna masks, except for the "all" mask */ |
| 2013 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2014 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2015 | result = -EINVAL; |
| 2016 | goto bad_res; |
| 2017 | } |
| 2018 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2019 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2020 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2021 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2022 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2023 | if (result) |
| 2024 | goto bad_res; |
| 2025 | } |
| 2026 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2027 | changed = 0; |
| 2028 | |
| 2029 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2030 | retry_short = nla_get_u8( |
| 2031 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2032 | if (retry_short == 0) { |
| 2033 | result = -EINVAL; |
| 2034 | goto bad_res; |
| 2035 | } |
| 2036 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2037 | } |
| 2038 | |
| 2039 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2040 | retry_long = nla_get_u8( |
| 2041 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2042 | if (retry_long == 0) { |
| 2043 | result = -EINVAL; |
| 2044 | goto bad_res; |
| 2045 | } |
| 2046 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2047 | } |
| 2048 | |
| 2049 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2050 | frag_threshold = nla_get_u32( |
| 2051 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2052 | if (frag_threshold < 256) { |
| 2053 | result = -EINVAL; |
| 2054 | goto bad_res; |
| 2055 | } |
| 2056 | if (frag_threshold != (u32) -1) { |
| 2057 | /* |
| 2058 | * Fragments (apart from the last one) are required to |
| 2059 | * have even length. Make the fragmentation code |
| 2060 | * simpler by stripping LSB should someone try to use |
| 2061 | * odd threshold value. |
| 2062 | */ |
| 2063 | frag_threshold &= ~0x1; |
| 2064 | } |
| 2065 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2066 | } |
| 2067 | |
| 2068 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2069 | rts_threshold = nla_get_u32( |
| 2070 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2071 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2072 | } |
| 2073 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2074 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2075 | coverage_class = nla_get_u8( |
| 2076 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2077 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2078 | } |
| 2079 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2080 | if (changed) { |
| 2081 | u8 old_retry_short, old_retry_long; |
| 2082 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2083 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2084 | |
| 2085 | if (!rdev->ops->set_wiphy_params) { |
| 2086 | result = -EOPNOTSUPP; |
| 2087 | goto bad_res; |
| 2088 | } |
| 2089 | |
| 2090 | old_retry_short = rdev->wiphy.retry_short; |
| 2091 | old_retry_long = rdev->wiphy.retry_long; |
| 2092 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2093 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2094 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2095 | |
| 2096 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2097 | rdev->wiphy.retry_short = retry_short; |
| 2098 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2099 | rdev->wiphy.retry_long = retry_long; |
| 2100 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2101 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2102 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2103 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2104 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2105 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2106 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2107 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2108 | if (result) { |
| 2109 | rdev->wiphy.retry_short = old_retry_short; |
| 2110 | rdev->wiphy.retry_long = old_retry_long; |
| 2111 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2112 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2113 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2114 | } |
| 2115 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2116 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2117 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2118 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2119 | if (netdev) |
| 2120 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2121 | return result; |
| 2122 | } |
| 2123 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2124 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2125 | { |
| 2126 | return (u64)wdev->identifier | |
| 2127 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2128 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2129 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2130 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2131 | struct cfg80211_chan_def *chandef) |
| 2132 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2133 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2134 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2136 | chandef->chan->center_freq)) |
| 2137 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2138 | switch (chandef->width) { |
| 2139 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2140 | case NL80211_CHAN_WIDTH_20: |
| 2141 | case NL80211_CHAN_WIDTH_40: |
| 2142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2143 | cfg80211_get_chandef_type(chandef))) |
| 2144 | return -ENOBUFS; |
| 2145 | break; |
| 2146 | default: |
| 2147 | break; |
| 2148 | } |
| 2149 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2150 | return -ENOBUFS; |
| 2151 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2152 | return -ENOBUFS; |
| 2153 | if (chandef->center_freq2 && |
| 2154 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2155 | return -ENOBUFS; |
| 2156 | return 0; |
| 2157 | } |
| 2158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2159 | 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] | 2160 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2161 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2162 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2163 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2164 | void *hdr; |
| 2165 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2166 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2167 | if (!hdr) |
| 2168 | return -1; |
| 2169 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2170 | if (dev && |
| 2171 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2172 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2173 | goto nla_put_failure; |
| 2174 | |
| 2175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2176 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2177 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2178 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2179 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2180 | rdev->devlist_generation ^ |
| 2181 | (cfg80211_rdev_list_generation << 2))) |
| 2182 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2183 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2184 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2185 | int ret; |
| 2186 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2187 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2188 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2189 | if (ret == 0) { |
| 2190 | if (nl80211_send_chandef(msg, &chandef)) |
| 2191 | goto nla_put_failure; |
| 2192 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2193 | } |
| 2194 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2195 | if (wdev->ssid_len) { |
| 2196 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2197 | goto nla_put_failure; |
| 2198 | } |
| 2199 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2200 | return genlmsg_end(msg, hdr); |
| 2201 | |
| 2202 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2203 | genlmsg_cancel(msg, hdr); |
| 2204 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2208 | { |
| 2209 | int wp_idx = 0; |
| 2210 | int if_idx = 0; |
| 2211 | int wp_start = cb->args[0]; |
| 2212 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2213 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2214 | struct wireless_dev *wdev; |
| 2215 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2216 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2217 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2218 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2219 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2220 | if (wp_idx < wp_start) { |
| 2221 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2223 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2224 | if_idx = 0; |
| 2225 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2226 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2227 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2228 | if (if_idx < if_start) { |
| 2229 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2230 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2231 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2232 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2233 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2234 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2235 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2236 | goto out; |
| 2237 | } |
| 2238 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2240 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2241 | |
| 2242 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2243 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2244 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2245 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2246 | |
| 2247 | cb->args[0] = wp_idx; |
| 2248 | cb->args[1] = if_idx; |
| 2249 | |
| 2250 | return skb->len; |
| 2251 | } |
| 2252 | |
| 2253 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2254 | { |
| 2255 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2256 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2257 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2258 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2260 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2261 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2263 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2264 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2265 | nlmsg_free(msg); |
| 2266 | return -ENOBUFS; |
| 2267 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2268 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2269 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2270 | } |
| 2271 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2272 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2273 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2274 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2275 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2276 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2277 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2278 | }; |
| 2279 | |
| 2280 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2281 | { |
| 2282 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2283 | int flag; |
| 2284 | |
| 2285 | *mntrflags = 0; |
| 2286 | |
| 2287 | if (!nla) |
| 2288 | return -EINVAL; |
| 2289 | |
| 2290 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2291 | nla, mntr_flags_policy)) |
| 2292 | return -EINVAL; |
| 2293 | |
| 2294 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2295 | if (flags[flag]) |
| 2296 | *mntrflags |= (1<<flag); |
| 2297 | |
| 2298 | return 0; |
| 2299 | } |
| 2300 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2301 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2302 | struct net_device *netdev, u8 use_4addr, |
| 2303 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2304 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2305 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2306 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2307 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2308 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2309 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2310 | |
| 2311 | switch (iftype) { |
| 2312 | case NL80211_IFTYPE_AP_VLAN: |
| 2313 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2314 | return 0; |
| 2315 | break; |
| 2316 | case NL80211_IFTYPE_STATION: |
| 2317 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2318 | return 0; |
| 2319 | break; |
| 2320 | default: |
| 2321 | break; |
| 2322 | } |
| 2323 | |
| 2324 | return -EOPNOTSUPP; |
| 2325 | } |
| 2326 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2327 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2330 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2331 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2332 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2333 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2334 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2335 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2336 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2337 | memset(¶ms, 0, sizeof(params)); |
| 2338 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2339 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2340 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2341 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2342 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2343 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2344 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2345 | if (ntype > NL80211_IFTYPE_MAX) |
| 2346 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2347 | } |
| 2348 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2349 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2350 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2351 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2352 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2353 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2354 | if (netif_running(dev)) |
| 2355 | return -EBUSY; |
| 2356 | |
| 2357 | wdev_lock(wdev); |
| 2358 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2359 | IEEE80211_MAX_MESH_ID_LEN); |
| 2360 | wdev->mesh_id_up_len = |
| 2361 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2362 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2363 | wdev->mesh_id_up_len); |
| 2364 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2365 | } |
| 2366 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2367 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2368 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2369 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2370 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2371 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2372 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2373 | } else { |
| 2374 | params.use_4addr = -1; |
| 2375 | } |
| 2376 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2377 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2378 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2379 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2380 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2381 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2382 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2383 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2384 | |
| 2385 | flags = &_flags; |
| 2386 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2387 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2388 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2389 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2390 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2391 | else |
| 2392 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2393 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2394 | if (!err && params.use_4addr != -1) |
| 2395 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2396 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | return err; |
| 2398 | } |
| 2399 | |
| 2400 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2401 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2403 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2404 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2405 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2406 | int err; |
| 2407 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2408 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2409 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2410 | memset(¶ms, 0, sizeof(params)); |
| 2411 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2412 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2413 | return -EINVAL; |
| 2414 | |
| 2415 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2416 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2417 | if (type > NL80211_IFTYPE_MAX) |
| 2418 | return -EINVAL; |
| 2419 | } |
| 2420 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2421 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2422 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2423 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2425 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2426 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2427 | ETH_ALEN); |
| 2428 | if (!is_valid_ether_addr(params.macaddr)) |
| 2429 | return -EADDRNOTAVAIL; |
| 2430 | } |
| 2431 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2432 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2433 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2434 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2435 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2437 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2438 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2439 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2440 | if (!msg) |
| 2441 | return -ENOMEM; |
| 2442 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2443 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2444 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2445 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2446 | wdev = rdev_add_virtual_intf(rdev, |
| 2447 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2448 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2449 | if (IS_ERR(wdev)) { |
| 2450 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2451 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2452 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2453 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2454 | switch (type) { |
| 2455 | case NL80211_IFTYPE_MESH_POINT: |
| 2456 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2457 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2458 | wdev_lock(wdev); |
| 2459 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2460 | IEEE80211_MAX_MESH_ID_LEN); |
| 2461 | wdev->mesh_id_up_len = |
| 2462 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2463 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2464 | wdev->mesh_id_up_len); |
| 2465 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2466 | break; |
| 2467 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2468 | /* |
| 2469 | * P2P Device doesn't have a netdev, so doesn't go |
| 2470 | * through the netdev notifier and must be added here |
| 2471 | */ |
| 2472 | mutex_init(&wdev->mtx); |
| 2473 | INIT_LIST_HEAD(&wdev->event_list); |
| 2474 | spin_lock_init(&wdev->event_lock); |
| 2475 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2476 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2477 | |
| 2478 | mutex_lock(&rdev->devlist_mtx); |
| 2479 | wdev->identifier = ++rdev->wdev_id; |
| 2480 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2481 | rdev->devlist_generation++; |
| 2482 | mutex_unlock(&rdev->devlist_mtx); |
| 2483 | break; |
| 2484 | default: |
| 2485 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2488 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2489 | rdev, wdev) < 0) { |
| 2490 | nlmsg_free(msg); |
| 2491 | return -ENOBUFS; |
| 2492 | } |
| 2493 | |
| 2494 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2498 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2500 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2501 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2502 | if (!rdev->ops->del_virtual_intf) |
| 2503 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2504 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2505 | /* |
| 2506 | * If we remove a wireless device without a netdev then clear |
| 2507 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2508 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2509 | * since the wdev has been freed, unlike with a netdev where |
| 2510 | * we need the dev_put() for the netdev to really be freed. |
| 2511 | */ |
| 2512 | if (!wdev->netdev) |
| 2513 | info->user_ptr[1] = NULL; |
| 2514 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2515 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2516 | } |
| 2517 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2518 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2519 | { |
| 2520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2521 | struct net_device *dev = info->user_ptr[1]; |
| 2522 | u16 noack_map; |
| 2523 | |
| 2524 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2525 | return -EINVAL; |
| 2526 | |
| 2527 | if (!rdev->ops->set_noack_map) |
| 2528 | return -EOPNOTSUPP; |
| 2529 | |
| 2530 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2531 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2532 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2535 | struct get_key_cookie { |
| 2536 | struct sk_buff *msg; |
| 2537 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2538 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2539 | }; |
| 2540 | |
| 2541 | static void get_key_callback(void *c, struct key_params *params) |
| 2542 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2543 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2544 | struct get_key_cookie *cookie = c; |
| 2545 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2546 | if ((params->key && |
| 2547 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2548 | params->key_len, params->key)) || |
| 2549 | (params->seq && |
| 2550 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2551 | params->seq_len, params->seq)) || |
| 2552 | (params->cipher && |
| 2553 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2554 | params->cipher))) |
| 2555 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2556 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2557 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2558 | if (!key) |
| 2559 | goto nla_put_failure; |
| 2560 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2561 | if ((params->key && |
| 2562 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2563 | params->key_len, params->key)) || |
| 2564 | (params->seq && |
| 2565 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2566 | params->seq_len, params->seq)) || |
| 2567 | (params->cipher && |
| 2568 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2569 | params->cipher))) |
| 2570 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2571 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2572 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2573 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2574 | |
| 2575 | nla_nest_end(cookie->msg, key); |
| 2576 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2577 | return; |
| 2578 | nla_put_failure: |
| 2579 | cookie->error = 1; |
| 2580 | } |
| 2581 | |
| 2582 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2583 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2585 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2586 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2587 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2588 | const u8 *mac_addr = NULL; |
| 2589 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2590 | struct get_key_cookie cookie = { |
| 2591 | .error = 0, |
| 2592 | }; |
| 2593 | void *hdr; |
| 2594 | struct sk_buff *msg; |
| 2595 | |
| 2596 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2597 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2598 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2599 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2600 | return -EINVAL; |
| 2601 | |
| 2602 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2603 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2604 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2605 | pairwise = !!mac_addr; |
| 2606 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2607 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2608 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2609 | return -EINVAL; |
| 2610 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2611 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2612 | return -EINVAL; |
| 2613 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2614 | } |
| 2615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2616 | if (!rdev->ops->get_key) |
| 2617 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2618 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2620 | if (!msg) |
| 2621 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2623 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2624 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2625 | if (IS_ERR(hdr)) |
| 2626 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2627 | |
| 2628 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2629 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2631 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2632 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2633 | goto nla_put_failure; |
| 2634 | if (mac_addr && |
| 2635 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2636 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2637 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2638 | if (pairwise && mac_addr && |
| 2639 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2640 | return -ENOENT; |
| 2641 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2642 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2643 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2644 | |
| 2645 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2646 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2647 | |
| 2648 | if (cookie.error) |
| 2649 | goto nla_put_failure; |
| 2650 | |
| 2651 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2652 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2653 | |
| 2654 | nla_put_failure: |
| 2655 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2656 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2657 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2658 | return err; |
| 2659 | } |
| 2660 | |
| 2661 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2662 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2664 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2665 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2666 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2667 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2668 | err = nl80211_parse_key(info, &key); |
| 2669 | if (err) |
| 2670 | return err; |
| 2671 | |
| 2672 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2673 | return -EINVAL; |
| 2674 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2675 | /* only support setting default key */ |
| 2676 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2677 | return -EINVAL; |
| 2678 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2679 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2680 | |
| 2681 | if (key.def) { |
| 2682 | if (!rdev->ops->set_default_key) { |
| 2683 | err = -EOPNOTSUPP; |
| 2684 | goto out; |
| 2685 | } |
| 2686 | |
| 2687 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2688 | if (err) |
| 2689 | goto out; |
| 2690 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2691 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2692 | key.def_uni, key.def_multi); |
| 2693 | |
| 2694 | if (err) |
| 2695 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2696 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2697 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2698 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2699 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2700 | } else { |
| 2701 | if (key.def_uni || !key.def_multi) { |
| 2702 | err = -EINVAL; |
| 2703 | goto out; |
| 2704 | } |
| 2705 | |
| 2706 | if (!rdev->ops->set_default_mgmt_key) { |
| 2707 | err = -EOPNOTSUPP; |
| 2708 | goto out; |
| 2709 | } |
| 2710 | |
| 2711 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2712 | if (err) |
| 2713 | goto out; |
| 2714 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2715 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2716 | if (err) |
| 2717 | goto out; |
| 2718 | |
| 2719 | #ifdef CONFIG_CFG80211_WEXT |
| 2720 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2721 | #endif |
| 2722 | } |
| 2723 | |
| 2724 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2725 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2726 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2727 | return err; |
| 2728 | } |
| 2729 | |
| 2730 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2731 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2733 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2734 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2735 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2736 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2737 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2738 | err = nl80211_parse_key(info, &key); |
| 2739 | if (err) |
| 2740 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2742 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2743 | return -EINVAL; |
| 2744 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2745 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2746 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2747 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2748 | if (key.type == -1) { |
| 2749 | if (mac_addr) |
| 2750 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2751 | else |
| 2752 | key.type = NL80211_KEYTYPE_GROUP; |
| 2753 | } |
| 2754 | |
| 2755 | /* for now */ |
| 2756 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2757 | key.type != NL80211_KEYTYPE_GROUP) |
| 2758 | return -EINVAL; |
| 2759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2760 | if (!rdev->ops->add_key) |
| 2761 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2762 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2763 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2764 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2765 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2766 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2767 | |
| 2768 | wdev_lock(dev->ieee80211_ptr); |
| 2769 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2770 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2771 | err = rdev_add_key(rdev, dev, key.idx, |
| 2772 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2773 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2774 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2775 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | return err; |
| 2777 | } |
| 2778 | |
| 2779 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2780 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2783 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2784 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2785 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2787 | err = nl80211_parse_key(info, &key); |
| 2788 | if (err) |
| 2789 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | |
| 2791 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2792 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2793 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2794 | if (key.type == -1) { |
| 2795 | if (mac_addr) |
| 2796 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2797 | else |
| 2798 | key.type = NL80211_KEYTYPE_GROUP; |
| 2799 | } |
| 2800 | |
| 2801 | /* for now */ |
| 2802 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2803 | key.type != NL80211_KEYTYPE_GROUP) |
| 2804 | return -EINVAL; |
| 2805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | if (!rdev->ops->del_key) |
| 2807 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2808 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2809 | wdev_lock(dev->ieee80211_ptr); |
| 2810 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2811 | |
| 2812 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2813 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2814 | err = -ENOENT; |
| 2815 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2816 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2817 | err = rdev_del_key(rdev, dev, key.idx, |
| 2818 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2819 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2821 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2822 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2823 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2824 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2825 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2826 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2827 | } |
| 2828 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2829 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2830 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2831 | return err; |
| 2832 | } |
| 2833 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2834 | /* This function returns an error or the number of nested attributes */ |
| 2835 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2836 | { |
| 2837 | struct nlattr *attr; |
| 2838 | int n_entries = 0, tmp; |
| 2839 | |
| 2840 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2841 | if (nla_len(attr) != ETH_ALEN) |
| 2842 | return -EINVAL; |
| 2843 | |
| 2844 | n_entries++; |
| 2845 | } |
| 2846 | |
| 2847 | return n_entries; |
| 2848 | } |
| 2849 | |
| 2850 | /* |
| 2851 | * This function parses ACL information and allocates memory for ACL data. |
| 2852 | * On successful return, the calling function is responsible to free the |
| 2853 | * ACL buffer returned by this function. |
| 2854 | */ |
| 2855 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2856 | struct genl_info *info) |
| 2857 | { |
| 2858 | enum nl80211_acl_policy acl_policy; |
| 2859 | struct nlattr *attr; |
| 2860 | struct cfg80211_acl_data *acl; |
| 2861 | int i = 0, n_entries, tmp; |
| 2862 | |
| 2863 | if (!wiphy->max_acl_mac_addrs) |
| 2864 | return ERR_PTR(-EOPNOTSUPP); |
| 2865 | |
| 2866 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2867 | return ERR_PTR(-EINVAL); |
| 2868 | |
| 2869 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2870 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2871 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2872 | return ERR_PTR(-EINVAL); |
| 2873 | |
| 2874 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2875 | return ERR_PTR(-EINVAL); |
| 2876 | |
| 2877 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2878 | if (n_entries < 0) |
| 2879 | return ERR_PTR(n_entries); |
| 2880 | |
| 2881 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2882 | return ERR_PTR(-ENOTSUPP); |
| 2883 | |
| 2884 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2885 | GFP_KERNEL); |
| 2886 | if (!acl) |
| 2887 | return ERR_PTR(-ENOMEM); |
| 2888 | |
| 2889 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2890 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2891 | i++; |
| 2892 | } |
| 2893 | |
| 2894 | acl->n_acl_entries = n_entries; |
| 2895 | acl->acl_policy = acl_policy; |
| 2896 | |
| 2897 | return acl; |
| 2898 | } |
| 2899 | |
| 2900 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2901 | { |
| 2902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2903 | struct net_device *dev = info->user_ptr[1]; |
| 2904 | struct cfg80211_acl_data *acl; |
| 2905 | int err; |
| 2906 | |
| 2907 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2908 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2909 | return -EOPNOTSUPP; |
| 2910 | |
| 2911 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2912 | return -EINVAL; |
| 2913 | |
| 2914 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2915 | if (IS_ERR(acl)) |
| 2916 | return PTR_ERR(acl); |
| 2917 | |
| 2918 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2919 | |
| 2920 | kfree(acl); |
| 2921 | |
| 2922 | return err; |
| 2923 | } |
| 2924 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2925 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2926 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2927 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2928 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2929 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2930 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2931 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2932 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2933 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2934 | return -EINVAL; |
| 2935 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2936 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2937 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2938 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2939 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2940 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2941 | if (!bcn->head_len) |
| 2942 | return -EINVAL; |
| 2943 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2947 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2948 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2949 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2950 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2951 | } |
| 2952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2953 | if (!haveinfo) |
| 2954 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2955 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2956 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2957 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2958 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2962 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2963 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2964 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2965 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2966 | } |
| 2967 | |
| 2968 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2969 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2970 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2971 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2972 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2973 | } |
| 2974 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2975 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2976 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2977 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2978 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2979 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2980 | } |
| 2981 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2982 | return 0; |
| 2983 | } |
| 2984 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2985 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2986 | struct cfg80211_ap_settings *params) |
| 2987 | { |
| 2988 | struct wireless_dev *wdev; |
| 2989 | bool ret = false; |
| 2990 | |
| 2991 | mutex_lock(&rdev->devlist_mtx); |
| 2992 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2993 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2994 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2995 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2996 | continue; |
| 2997 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2998 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2999 | continue; |
| 3000 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3001 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3002 | ret = true; |
| 3003 | break; |
| 3004 | } |
| 3005 | |
| 3006 | mutex_unlock(&rdev->devlist_mtx); |
| 3007 | |
| 3008 | return ret; |
| 3009 | } |
| 3010 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3011 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3012 | enum nl80211_auth_type auth_type, |
| 3013 | enum nl80211_commands cmd) |
| 3014 | { |
| 3015 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3016 | return false; |
| 3017 | |
| 3018 | switch (cmd) { |
| 3019 | case NL80211_CMD_AUTHENTICATE: |
| 3020 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3021 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3022 | return false; |
| 3023 | return true; |
| 3024 | case NL80211_CMD_CONNECT: |
| 3025 | case NL80211_CMD_START_AP: |
| 3026 | /* SAE not supported yet */ |
| 3027 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3028 | return false; |
| 3029 | return true; |
| 3030 | default: |
| 3031 | return false; |
| 3032 | } |
| 3033 | } |
| 3034 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3035 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3036 | { |
| 3037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3038 | struct net_device *dev = info->user_ptr[1]; |
| 3039 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3040 | struct cfg80211_ap_settings params; |
| 3041 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3042 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3043 | |
| 3044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3046 | return -EOPNOTSUPP; |
| 3047 | |
| 3048 | if (!rdev->ops->start_ap) |
| 3049 | return -EOPNOTSUPP; |
| 3050 | |
| 3051 | if (wdev->beacon_interval) |
| 3052 | return -EALREADY; |
| 3053 | |
| 3054 | memset(¶ms, 0, sizeof(params)); |
| 3055 | |
| 3056 | /* these are required for START_AP */ |
| 3057 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3058 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3059 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3060 | return -EINVAL; |
| 3061 | |
| 3062 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 3063 | if (err) |
| 3064 | return err; |
| 3065 | |
| 3066 | params.beacon_interval = |
| 3067 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3068 | params.dtim_period = |
| 3069 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3070 | |
| 3071 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3072 | if (err) |
| 3073 | return err; |
| 3074 | |
| 3075 | /* |
| 3076 | * In theory, some of these attributes should be required here |
| 3077 | * but since they were not used when the command was originally |
| 3078 | * added, keep them optional for old user space programs to let |
| 3079 | * them continue to work with drivers that do not need the |
| 3080 | * additional information -- drivers must check! |
| 3081 | */ |
| 3082 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3083 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3084 | params.ssid_len = |
| 3085 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3086 | if (params.ssid_len == 0 || |
| 3087 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3088 | return -EINVAL; |
| 3089 | } |
| 3090 | |
| 3091 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3092 | params.hidden_ssid = nla_get_u32( |
| 3093 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3094 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3095 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3096 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3097 | return -EINVAL; |
| 3098 | } |
| 3099 | |
| 3100 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3101 | |
| 3102 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3103 | params.auth_type = nla_get_u32( |
| 3104 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3105 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3106 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3107 | return -EINVAL; |
| 3108 | } else |
| 3109 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3110 | |
| 3111 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3112 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3113 | if (err) |
| 3114 | return err; |
| 3115 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3116 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3117 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3118 | return -EOPNOTSUPP; |
| 3119 | params.inactivity_timeout = nla_get_u16( |
| 3120 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3121 | } |
| 3122 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3123 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3124 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3125 | return -EINVAL; |
| 3126 | params.p2p_ctwindow = |
| 3127 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3128 | if (params.p2p_ctwindow > 127) |
| 3129 | return -EINVAL; |
| 3130 | if (params.p2p_ctwindow != 0 && |
| 3131 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3132 | return -EINVAL; |
| 3133 | } |
| 3134 | |
| 3135 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3136 | u8 tmp; |
| 3137 | |
| 3138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3139 | return -EINVAL; |
| 3140 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3141 | if (tmp > 1) |
| 3142 | return -EINVAL; |
| 3143 | params.p2p_opp_ps = tmp; |
| 3144 | if (params.p2p_opp_ps != 0 && |
| 3145 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3146 | return -EINVAL; |
| 3147 | } |
| 3148 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3149 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3150 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3151 | if (err) |
| 3152 | return err; |
| 3153 | } else if (wdev->preset_chandef.chan) { |
| 3154 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3155 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3156 | return -EINVAL; |
| 3157 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3158 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3159 | return -EINVAL; |
| 3160 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3161 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3162 | if (err < 0) |
| 3163 | return err; |
| 3164 | if (err) { |
| 3165 | radar_detect_width = BIT(params.chandef.width); |
| 3166 | params.radar_required = true; |
| 3167 | } |
| 3168 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3169 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3170 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3171 | params.chandef.chan, |
| 3172 | CHAN_MODE_SHARED, |
| 3173 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3174 | mutex_unlock(&rdev->devlist_mtx); |
| 3175 | |
| 3176 | if (err) |
| 3177 | return err; |
| 3178 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3179 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3180 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3181 | if (IS_ERR(params.acl)) |
| 3182 | return PTR_ERR(params.acl); |
| 3183 | } |
| 3184 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3185 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3186 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3187 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3188 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3189 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3190 | wdev->ssid_len = params.ssid_len; |
| 3191 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3192 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3193 | |
| 3194 | kfree(params.acl); |
| 3195 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3196 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3197 | } |
| 3198 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3199 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3200 | { |
| 3201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3202 | struct net_device *dev = info->user_ptr[1]; |
| 3203 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3204 | struct cfg80211_beacon_data params; |
| 3205 | int err; |
| 3206 | |
| 3207 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3208 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3209 | return -EOPNOTSUPP; |
| 3210 | |
| 3211 | if (!rdev->ops->change_beacon) |
| 3212 | return -EOPNOTSUPP; |
| 3213 | |
| 3214 | if (!wdev->beacon_interval) |
| 3215 | return -EINVAL; |
| 3216 | |
| 3217 | err = nl80211_parse_beacon(info, ¶ms); |
| 3218 | if (err) |
| 3219 | return err; |
| 3220 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3221 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | 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] | 3225 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3227 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3228 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3229 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3232 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3233 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3234 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3235 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3236 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3237 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3238 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3239 | }; |
| 3240 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3241 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3242 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3243 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3244 | { |
| 3245 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3246 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3247 | int flag; |
| 3248 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3249 | /* |
| 3250 | * Try parsing the new attribute first so userspace |
| 3251 | * can specify both for older kernels. |
| 3252 | */ |
| 3253 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3254 | if (nla) { |
| 3255 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3256 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3257 | sta_flags = nla_data(nla); |
| 3258 | params->sta_flags_mask = sta_flags->mask; |
| 3259 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3260 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3261 | if ((params->sta_flags_mask | |
| 3262 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3263 | return -EINVAL; |
| 3264 | return 0; |
| 3265 | } |
| 3266 | |
| 3267 | /* if present, parse the old attribute */ |
| 3268 | |
| 3269 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3270 | if (!nla) |
| 3271 | return 0; |
| 3272 | |
| 3273 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3274 | nla, sta_flags_policy)) |
| 3275 | return -EINVAL; |
| 3276 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3277 | /* |
| 3278 | * Only allow certain flags for interface types so that |
| 3279 | * other attributes are silently ignored. Remember that |
| 3280 | * this is backward compatibility code with old userspace |
| 3281 | * and shouldn't be hit in other cases anyway. |
| 3282 | */ |
| 3283 | switch (iftype) { |
| 3284 | case NL80211_IFTYPE_AP: |
| 3285 | case NL80211_IFTYPE_AP_VLAN: |
| 3286 | case NL80211_IFTYPE_P2P_GO: |
| 3287 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3288 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3289 | BIT(NL80211_STA_FLAG_WME) | |
| 3290 | BIT(NL80211_STA_FLAG_MFP); |
| 3291 | break; |
| 3292 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3293 | case NL80211_IFTYPE_STATION: |
| 3294 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3295 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3296 | break; |
| 3297 | case NL80211_IFTYPE_MESH_POINT: |
| 3298 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3299 | BIT(NL80211_STA_FLAG_MFP) | |
| 3300 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3301 | default: |
| 3302 | return -EINVAL; |
| 3303 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3304 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3305 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3306 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3307 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3308 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3309 | /* no longer support new API additions in old API */ |
| 3310 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3311 | return -EINVAL; |
| 3312 | } |
| 3313 | } |
| 3314 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3315 | return 0; |
| 3316 | } |
| 3317 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3318 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3319 | int attr) |
| 3320 | { |
| 3321 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3322 | u32 bitrate; |
| 3323 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3324 | |
| 3325 | rate = nla_nest_start(msg, attr); |
| 3326 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3327 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3328 | |
| 3329 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3330 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3331 | /* report 16-bit bitrate only if we can */ |
| 3332 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3333 | if (bitrate > 0 && |
| 3334 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3335 | return false; |
| 3336 | if (bitrate_compat > 0 && |
| 3337 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3338 | return false; |
| 3339 | |
| 3340 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3341 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3342 | return false; |
| 3343 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3344 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3345 | return false; |
| 3346 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3347 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3348 | return false; |
| 3349 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3350 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3351 | return false; |
| 3352 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3353 | return false; |
| 3354 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3355 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3356 | return false; |
| 3357 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3358 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3359 | return false; |
| 3360 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3361 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3362 | return false; |
| 3363 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3364 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3365 | return false; |
| 3366 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3367 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3368 | return false; |
| 3369 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3370 | |
| 3371 | nla_nest_end(msg, rate); |
| 3372 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3373 | } |
| 3374 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3375 | 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] | 3376 | int flags, |
| 3377 | struct cfg80211_registered_device *rdev, |
| 3378 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3379 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3380 | { |
| 3381 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3382 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3383 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3384 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3385 | if (!hdr) |
| 3386 | return -1; |
| 3387 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3388 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3391 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3392 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3393 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3394 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3395 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3396 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3397 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3398 | sinfo->connected_time)) |
| 3399 | goto nla_put_failure; |
| 3400 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3401 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3402 | sinfo->inactive_time)) |
| 3403 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3404 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3405 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3406 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3407 | (u32)sinfo->rx_bytes)) |
| 3408 | goto nla_put_failure; |
| 3409 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3410 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3411 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3412 | (u32)sinfo->tx_bytes)) |
| 3413 | goto nla_put_failure; |
| 3414 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3415 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3416 | sinfo->rx_bytes)) |
| 3417 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3418 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3419 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3420 | sinfo->tx_bytes)) |
| 3421 | goto nla_put_failure; |
| 3422 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3423 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3424 | goto nla_put_failure; |
| 3425 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3426 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3427 | goto nla_put_failure; |
| 3428 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3429 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3430 | sinfo->plink_state)) |
| 3431 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3432 | switch (rdev->wiphy.signal_type) { |
| 3433 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3434 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3435 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3436 | sinfo->signal)) |
| 3437 | goto nla_put_failure; |
| 3438 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3439 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3440 | sinfo->signal_avg)) |
| 3441 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3442 | break; |
| 3443 | default: |
| 3444 | break; |
| 3445 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3446 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3447 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3448 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3449 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3450 | } |
| 3451 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3452 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3453 | NL80211_STA_INFO_RX_BITRATE)) |
| 3454 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3455 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3456 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3457 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3458 | sinfo->rx_packets)) |
| 3459 | goto nla_put_failure; |
| 3460 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3461 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3462 | sinfo->tx_packets)) |
| 3463 | goto nla_put_failure; |
| 3464 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3465 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3466 | sinfo->tx_retries)) |
| 3467 | goto nla_put_failure; |
| 3468 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3469 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3470 | sinfo->tx_failed)) |
| 3471 | goto nla_put_failure; |
| 3472 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3473 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3474 | sinfo->beacon_loss_count)) |
| 3475 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3476 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3477 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3478 | sinfo->local_pm)) |
| 3479 | goto nla_put_failure; |
| 3480 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3481 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3482 | sinfo->peer_pm)) |
| 3483 | goto nla_put_failure; |
| 3484 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3485 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3486 | sinfo->nonpeer_pm)) |
| 3487 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3488 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3489 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3490 | if (!bss_param) |
| 3491 | goto nla_put_failure; |
| 3492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3493 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3494 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3495 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3496 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3497 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3498 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3499 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3500 | sinfo->bss_param.dtim_period) || |
| 3501 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3502 | sinfo->bss_param.beacon_interval)) |
| 3503 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3504 | |
| 3505 | nla_nest_end(msg, bss_param); |
| 3506 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3507 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3508 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3509 | sizeof(struct nl80211_sta_flag_update), |
| 3510 | &sinfo->sta_flags)) |
| 3511 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3512 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3513 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3514 | sinfo->t_offset)) |
| 3515 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3516 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3517 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3518 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3519 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3520 | sinfo->assoc_req_ies)) |
| 3521 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3522 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3523 | return genlmsg_end(msg, hdr); |
| 3524 | |
| 3525 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3526 | genlmsg_cancel(msg, hdr); |
| 3527 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3528 | } |
| 3529 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3530 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3531 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3532 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3533 | struct station_info sinfo; |
| 3534 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3535 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3536 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3537 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3538 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3539 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3540 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3541 | if (err) |
| 3542 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3543 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3544 | if (!wdev->netdev) { |
| 3545 | err = -EINVAL; |
| 3546 | goto out_err; |
| 3547 | } |
| 3548 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3549 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3550 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3551 | goto out_err; |
| 3552 | } |
| 3553 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3554 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3555 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3556 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3557 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3558 | if (err == -ENOENT) |
| 3559 | break; |
| 3560 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3561 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3562 | |
| 3563 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3564 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3565 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3566 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3567 | &sinfo) < 0) |
| 3568 | goto out; |
| 3569 | |
| 3570 | sta_idx++; |
| 3571 | } |
| 3572 | |
| 3573 | |
| 3574 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3575 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3576 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3577 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3578 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3579 | |
| 3580 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3581 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3582 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3583 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3584 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3586 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3587 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3588 | struct sk_buff *msg; |
| 3589 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3590 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3591 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3592 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3593 | |
| 3594 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3595 | return -EINVAL; |
| 3596 | |
| 3597 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3598 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3599 | if (!rdev->ops->get_station) |
| 3600 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3601 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3602 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3603 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3604 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3605 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3607 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3608 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3609 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3610 | 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] | 3611 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3612 | nlmsg_free(msg); |
| 3613 | return -ENOBUFS; |
| 3614 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3616 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3617 | } |
| 3618 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3619 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3620 | struct station_parameters *params, |
| 3621 | enum cfg80211_station_type statype) |
| 3622 | { |
| 3623 | if (params->listen_interval != -1) |
| 3624 | return -EINVAL; |
| 3625 | if (params->aid) |
| 3626 | return -EINVAL; |
| 3627 | |
| 3628 | /* When you run into this, adjust the code below for the new flag */ |
| 3629 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3630 | |
| 3631 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3632 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3633 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3634 | /* |
| 3635 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3636 | * code doesn't have the bug of including TDLS in the |
| 3637 | * mask everywhere. |
| 3638 | */ |
| 3639 | if (params->sta_flags_mask & |
| 3640 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3641 | BIT(NL80211_STA_FLAG_MFP) | |
| 3642 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3643 | return -EINVAL; |
| 3644 | break; |
| 3645 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3646 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3647 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3648 | return -EINVAL; |
| 3649 | /* ignore since it can't change */ |
| 3650 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3651 | break; |
| 3652 | default: |
| 3653 | /* disallow mesh-specific things */ |
| 3654 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3655 | return -EINVAL; |
| 3656 | if (params->local_pm) |
| 3657 | return -EINVAL; |
| 3658 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3659 | return -EINVAL; |
| 3660 | } |
| 3661 | |
| 3662 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3663 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3664 | /* TDLS can't be set, ... */ |
| 3665 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3666 | return -EINVAL; |
| 3667 | /* |
| 3668 | * ... but don't bother the driver with it. This works around |
| 3669 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3670 | * TLDS_PEER flag in the mask even for AP mode. |
| 3671 | */ |
| 3672 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3673 | } |
| 3674 | |
| 3675 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3676 | /* reject other things that can't change */ |
| 3677 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3678 | return -EINVAL; |
| 3679 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3680 | return -EINVAL; |
| 3681 | if (params->supported_rates) |
| 3682 | return -EINVAL; |
| 3683 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3684 | return -EINVAL; |
| 3685 | } |
| 3686 | |
| 3687 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3688 | if (params->vlan) |
| 3689 | return -EINVAL; |
| 3690 | } |
| 3691 | |
| 3692 | switch (statype) { |
| 3693 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3694 | /* Use this only for authorizing/unauthorizing a station */ |
| 3695 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3696 | return -EOPNOTSUPP; |
| 3697 | break; |
| 3698 | case CFG80211_STA_AP_CLIENT: |
| 3699 | /* accept only the listed bits */ |
| 3700 | if (params->sta_flags_mask & |
| 3701 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3702 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3703 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3704 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3705 | BIT(NL80211_STA_FLAG_WME) | |
| 3706 | BIT(NL80211_STA_FLAG_MFP))) |
| 3707 | return -EINVAL; |
| 3708 | |
| 3709 | /* but authenticated/associated only if driver handles it */ |
| 3710 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3711 | params->sta_flags_mask & |
| 3712 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3713 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3714 | return -EINVAL; |
| 3715 | break; |
| 3716 | case CFG80211_STA_IBSS: |
| 3717 | case CFG80211_STA_AP_STA: |
| 3718 | /* reject any changes other than AUTHORIZED */ |
| 3719 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3720 | return -EINVAL; |
| 3721 | break; |
| 3722 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3723 | /* reject any changes other than AUTHORIZED or WME */ |
| 3724 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3725 | BIT(NL80211_STA_FLAG_WME))) |
| 3726 | return -EINVAL; |
| 3727 | /* force (at least) rates when authorizing */ |
| 3728 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3729 | !params->supported_rates) |
| 3730 | return -EINVAL; |
| 3731 | break; |
| 3732 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3733 | /* reject any changes */ |
| 3734 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3735 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3736 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3737 | return -EINVAL; |
| 3738 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3739 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3740 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3741 | return -EINVAL; |
| 3742 | break; |
| 3743 | } |
| 3744 | |
| 3745 | return 0; |
| 3746 | } |
| 3747 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3748 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3749 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3750 | * 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] | 3751 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3752 | static struct net_device *get_vlan(struct genl_info *info, |
| 3753 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3754 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3755 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3756 | struct net_device *v; |
| 3757 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3758 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3759 | if (!vlanattr) |
| 3760 | return NULL; |
| 3761 | |
| 3762 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3763 | if (!v) |
| 3764 | return ERR_PTR(-ENODEV); |
| 3765 | |
| 3766 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3767 | ret = -EINVAL; |
| 3768 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3769 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3770 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3771 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3772 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3773 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3774 | ret = -EINVAL; |
| 3775 | goto error; |
| 3776 | } |
| 3777 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3778 | if (!netif_running(v)) { |
| 3779 | ret = -ENETDOWN; |
| 3780 | goto error; |
| 3781 | } |
| 3782 | |
| 3783 | return v; |
| 3784 | error: |
| 3785 | dev_put(v); |
| 3786 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3787 | } |
| 3788 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3789 | static struct nla_policy |
| 3790 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3791 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3792 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3793 | }; |
| 3794 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3795 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3796 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3797 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3798 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3799 | struct nlattr *nla; |
| 3800 | int err; |
| 3801 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3802 | /* parse WME attributes if present */ |
| 3803 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3804 | return 0; |
| 3805 | |
| 3806 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3807 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3808 | nl80211_sta_wme_policy); |
| 3809 | if (err) |
| 3810 | return err; |
| 3811 | |
| 3812 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3813 | params->uapsd_queues = nla_get_u8( |
| 3814 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3815 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3816 | return -EINVAL; |
| 3817 | |
| 3818 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3819 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3820 | |
| 3821 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3822 | return -EINVAL; |
| 3823 | |
| 3824 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3825 | |
| 3826 | return 0; |
| 3827 | } |
| 3828 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3829 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3830 | struct station_parameters *params) |
| 3831 | { |
| 3832 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3833 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3834 | params->ht_capa = |
| 3835 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3836 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3837 | params->vht_capa = |
| 3838 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3839 | |
| 3840 | return nl80211_parse_sta_wme(info, params); |
| 3841 | } |
| 3842 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3843 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3844 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3846 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3847 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3848 | u8 *mac_addr; |
| 3849 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3850 | |
| 3851 | memset(¶ms, 0, sizeof(params)); |
| 3852 | |
| 3853 | params.listen_interval = -1; |
| 3854 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3855 | if (!rdev->ops->change_station) |
| 3856 | return -EOPNOTSUPP; |
| 3857 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3858 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3859 | return -EINVAL; |
| 3860 | |
| 3861 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3862 | return -EINVAL; |
| 3863 | |
| 3864 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3865 | |
| 3866 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3867 | params.supported_rates = |
| 3868 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3869 | params.supported_rates_len = |
| 3870 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3871 | } |
| 3872 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3873 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3874 | params.capability = |
| 3875 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3876 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3877 | } |
| 3878 | |
| 3879 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3880 | params.ext_capab = |
| 3881 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3882 | params.ext_capab_len = |
| 3883 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3884 | } |
| 3885 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3886 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3887 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3888 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3889 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3890 | return -EINVAL; |
| 3891 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3892 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3893 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3894 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3895 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3896 | return -EINVAL; |
| 3897 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3898 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3899 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3900 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3901 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3902 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3903 | return -EINVAL; |
| 3904 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3905 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3906 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3907 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3908 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3909 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3910 | |
| 3911 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3912 | pm > NL80211_MESH_POWER_MAX) |
| 3913 | return -EINVAL; |
| 3914 | |
| 3915 | params.local_pm = pm; |
| 3916 | } |
| 3917 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3918 | /* Include parameters for TDLS peer (will check later) */ |
| 3919 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3920 | if (err) |
| 3921 | return err; |
| 3922 | |
| 3923 | params.vlan = get_vlan(info, rdev); |
| 3924 | if (IS_ERR(params.vlan)) |
| 3925 | return PTR_ERR(params.vlan); |
| 3926 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3927 | switch (dev->ieee80211_ptr->iftype) { |
| 3928 | case NL80211_IFTYPE_AP: |
| 3929 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3930 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3931 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3932 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3933 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3934 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3935 | break; |
| 3936 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3937 | err = -EOPNOTSUPP; |
| 3938 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3939 | } |
| 3940 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3941 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3942 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3943 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3944 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3945 | if (params.vlan) |
| 3946 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3947 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3948 | return err; |
| 3949 | } |
| 3950 | |
| 3951 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3952 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3954 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3955 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3956 | struct station_parameters params; |
| 3957 | u8 *mac_addr = NULL; |
| 3958 | |
| 3959 | memset(¶ms, 0, sizeof(params)); |
| 3960 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3961 | if (!rdev->ops->add_station) |
| 3962 | return -EOPNOTSUPP; |
| 3963 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3964 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3965 | return -EINVAL; |
| 3966 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3967 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3968 | return -EINVAL; |
| 3969 | |
| 3970 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3971 | return -EINVAL; |
| 3972 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3973 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3974 | return -EINVAL; |
| 3975 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3976 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3977 | params.supported_rates = |
| 3978 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3979 | params.supported_rates_len = |
| 3980 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3981 | params.listen_interval = |
| 3982 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3983 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3984 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3985 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3986 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3987 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3988 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3989 | params.capability = |
| 3990 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3991 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3992 | } |
| 3993 | |
| 3994 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3995 | params.ext_capab = |
| 3996 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3997 | params.ext_capab_len = |
| 3998 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3999 | } |
| 4000 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4001 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4002 | params.ht_capa = |
| 4003 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4004 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4005 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4006 | params.vht_capa = |
| 4007 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4008 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4010 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4011 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4012 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4013 | return -EINVAL; |
| 4014 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4015 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4016 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4017 | if (err) |
| 4018 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4019 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4020 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4021 | return -EINVAL; |
| 4022 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4023 | /* When you run into this, adjust the code below for the new flag */ |
| 4024 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4025 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4026 | switch (dev->ieee80211_ptr->iftype) { |
| 4027 | case NL80211_IFTYPE_AP: |
| 4028 | case NL80211_IFTYPE_AP_VLAN: |
| 4029 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4030 | /* ignore WME attributes if iface/sta is not capable */ |
| 4031 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4032 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4033 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4034 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4035 | /* TDLS peers cannot be added */ |
| 4036 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4037 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4038 | /* but don't bother the driver with it */ |
| 4039 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4040 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4041 | /* allow authenticated/associated only if driver handles it */ |
| 4042 | if (!(rdev->wiphy.features & |
| 4043 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4044 | params.sta_flags_mask & |
| 4045 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4046 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4047 | return -EINVAL; |
| 4048 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4049 | /* must be last in here for error handling */ |
| 4050 | params.vlan = get_vlan(info, rdev); |
| 4051 | if (IS_ERR(params.vlan)) |
| 4052 | return PTR_ERR(params.vlan); |
| 4053 | break; |
| 4054 | case NL80211_IFTYPE_MESH_POINT: |
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 | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4058 | /* associated is disallowed */ |
| 4059 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4060 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4061 | /* TDLS peers cannot be added */ |
| 4062 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4063 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4064 | break; |
| 4065 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4066 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4067 | /* ignore uAPSD data */ |
| 4068 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4069 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4070 | /* these are disallowed */ |
| 4071 | if (params.sta_flags_mask & |
| 4072 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4073 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4074 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4075 | /* Only TDLS peers can be added */ |
| 4076 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4077 | return -EINVAL; |
| 4078 | /* Can only add if TDLS ... */ |
| 4079 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4080 | return -EOPNOTSUPP; |
| 4081 | /* ... with external setup is supported */ |
| 4082 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4083 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4084 | /* |
| 4085 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4086 | * as authorized, but it shouldn't yet be. |
| 4087 | */ |
| 4088 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4089 | break; |
| 4090 | default: |
| 4091 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4092 | } |
| 4093 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4094 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4095 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4096 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4097 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4098 | if (params.vlan) |
| 4099 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4100 | return err; |
| 4101 | } |
| 4102 | |
| 4103 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4106 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4107 | u8 *mac_addr = NULL; |
| 4108 | |
| 4109 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4110 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4111 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4112 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4113 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4114 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4115 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4116 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4118 | if (!rdev->ops->del_station) |
| 4119 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4120 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4121 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4122 | } |
| 4123 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4124 | 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] | 4125 | int flags, struct net_device *dev, |
| 4126 | u8 *dst, u8 *next_hop, |
| 4127 | struct mpath_info *pinfo) |
| 4128 | { |
| 4129 | void *hdr; |
| 4130 | struct nlattr *pinfoattr; |
| 4131 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4132 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4133 | if (!hdr) |
| 4134 | return -1; |
| 4135 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4136 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4137 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4138 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4139 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4140 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4141 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4142 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4143 | if (!pinfoattr) |
| 4144 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4145 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4146 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4147 | pinfo->frame_qlen)) |
| 4148 | goto nla_put_failure; |
| 4149 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4150 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4151 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4152 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4153 | pinfo->metric)) || |
| 4154 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4155 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4156 | pinfo->exptime)) || |
| 4157 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4158 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4159 | pinfo->flags)) || |
| 4160 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4161 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4162 | pinfo->discovery_timeout)) || |
| 4163 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4164 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4165 | pinfo->discovery_retries))) |
| 4166 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4167 | |
| 4168 | nla_nest_end(msg, pinfoattr); |
| 4169 | |
| 4170 | return genlmsg_end(msg, hdr); |
| 4171 | |
| 4172 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4173 | genlmsg_cancel(msg, hdr); |
| 4174 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4178 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4179 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4180 | struct mpath_info pinfo; |
| 4181 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4182 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4183 | u8 dst[ETH_ALEN]; |
| 4184 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4185 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4186 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4187 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4188 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4189 | if (err) |
| 4190 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4191 | |
| 4192 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4193 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4194 | goto out_err; |
| 4195 | } |
| 4196 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4197 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4198 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4199 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4202 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4203 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4204 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4205 | if (err == -ENOENT) |
| 4206 | break; |
| 4207 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4208 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4209 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4210 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4211 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4212 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4213 | &pinfo) < 0) |
| 4214 | goto out; |
| 4215 | |
| 4216 | path_idx++; |
| 4217 | } |
| 4218 | |
| 4219 | |
| 4220 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4221 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4222 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4223 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4224 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4225 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4231 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4232 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4233 | struct mpath_info pinfo; |
| 4234 | struct sk_buff *msg; |
| 4235 | u8 *dst = NULL; |
| 4236 | u8 next_hop[ETH_ALEN]; |
| 4237 | |
| 4238 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4239 | |
| 4240 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4241 | return -EINVAL; |
| 4242 | |
| 4243 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4244 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4245 | if (!rdev->ops->get_mpath) |
| 4246 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4247 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4248 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4249 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4250 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4251 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4252 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4253 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4254 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4256 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4258 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4259 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4260 | dev, dst, next_hop, &pinfo) < 0) { |
| 4261 | nlmsg_free(msg); |
| 4262 | return -ENOBUFS; |
| 4263 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4265 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4269 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4271 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4272 | u8 *dst = NULL; |
| 4273 | u8 *next_hop = NULL; |
| 4274 | |
| 4275 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4276 | return -EINVAL; |
| 4277 | |
| 4278 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4279 | return -EINVAL; |
| 4280 | |
| 4281 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4282 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4283 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4284 | if (!rdev->ops->change_mpath) |
| 4285 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4287 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4288 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4289 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4290 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4291 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4292 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4293 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4294 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4296 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4297 | u8 *dst = NULL; |
| 4298 | u8 *next_hop = NULL; |
| 4299 | |
| 4300 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4301 | return -EINVAL; |
| 4302 | |
| 4303 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4304 | return -EINVAL; |
| 4305 | |
| 4306 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4307 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4309 | if (!rdev->ops->add_mpath) |
| 4310 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4311 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4312 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4313 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4314 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4315 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4321 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4322 | u8 *dst = NULL; |
| 4323 | |
| 4324 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4325 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4326 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4327 | if (!rdev->ops->del_mpath) |
| 4328 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4329 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4330 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4333 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4334 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4336 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4337 | struct bss_parameters params; |
| 4338 | |
| 4339 | memset(¶ms, 0, sizeof(params)); |
| 4340 | /* default to not changing parameters */ |
| 4341 | params.use_cts_prot = -1; |
| 4342 | params.use_short_preamble = -1; |
| 4343 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4344 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4345 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4346 | params.p2p_ctwindow = -1; |
| 4347 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4348 | |
| 4349 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4350 | params.use_cts_prot = |
| 4351 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4352 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4353 | params.use_short_preamble = |
| 4354 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4355 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4356 | params.use_short_slot_time = |
| 4357 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4358 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4359 | params.basic_rates = |
| 4360 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4361 | params.basic_rates_len = |
| 4362 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4363 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4364 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4365 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4366 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4367 | params.ht_opmode = |
| 4368 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4369 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4370 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4372 | return -EINVAL; |
| 4373 | params.p2p_ctwindow = |
| 4374 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4375 | if (params.p2p_ctwindow < 0) |
| 4376 | return -EINVAL; |
| 4377 | if (params.p2p_ctwindow != 0 && |
| 4378 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4379 | return -EINVAL; |
| 4380 | } |
| 4381 | |
| 4382 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4383 | u8 tmp; |
| 4384 | |
| 4385 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4386 | return -EINVAL; |
| 4387 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4388 | if (tmp > 1) |
| 4389 | return -EINVAL; |
| 4390 | params.p2p_opp_ps = tmp; |
| 4391 | if (params.p2p_opp_ps && |
| 4392 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4393 | return -EINVAL; |
| 4394 | } |
| 4395 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | if (!rdev->ops->change_bss) |
| 4397 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4398 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4399 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4401 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4402 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4403 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4404 | } |
| 4405 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4406 | 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] | 4407 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4408 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4409 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4410 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4411 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4412 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4413 | }; |
| 4414 | |
| 4415 | static int parse_reg_rule(struct nlattr *tb[], |
| 4416 | struct ieee80211_reg_rule *reg_rule) |
| 4417 | { |
| 4418 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4419 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4420 | |
| 4421 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4422 | return -EINVAL; |
| 4423 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4424 | return -EINVAL; |
| 4425 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4426 | return -EINVAL; |
| 4427 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4428 | return -EINVAL; |
| 4429 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4430 | return -EINVAL; |
| 4431 | |
| 4432 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4433 | |
| 4434 | freq_range->start_freq_khz = |
| 4435 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4436 | freq_range->end_freq_khz = |
| 4437 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4438 | freq_range->max_bandwidth_khz = |
| 4439 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4440 | |
| 4441 | power_rule->max_eirp = |
| 4442 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4443 | |
| 4444 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4445 | power_rule->max_antenna_gain = |
| 4446 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4447 | |
| 4448 | return 0; |
| 4449 | } |
| 4450 | |
| 4451 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4452 | { |
| 4453 | int r; |
| 4454 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4455 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4456 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4457 | /* |
| 4458 | * You should only get this when cfg80211 hasn't yet initialized |
| 4459 | * completely when built-in to the kernel right between the time |
| 4460 | * window between nl80211_init() and regulatory_init(), if that is |
| 4461 | * even possible. |
| 4462 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4463 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4464 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4465 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4466 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4467 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4468 | |
| 4469 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4470 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4471 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4472 | user_reg_hint_type = |
| 4473 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4474 | else |
| 4475 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4476 | |
| 4477 | switch (user_reg_hint_type) { |
| 4478 | case NL80211_USER_REG_HINT_USER: |
| 4479 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4480 | break; |
| 4481 | default: |
| 4482 | return -EINVAL; |
| 4483 | } |
| 4484 | |
| 4485 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4486 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4487 | return r; |
| 4488 | } |
| 4489 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4490 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4491 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4494 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4495 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4496 | struct mesh_config cur_params; |
| 4497 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4498 | void *hdr; |
| 4499 | struct nlattr *pinfoattr; |
| 4500 | struct sk_buff *msg; |
| 4501 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4502 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4503 | return -EOPNOTSUPP; |
| 4504 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4505 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4506 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4507 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4508 | wdev_lock(wdev); |
| 4509 | /* If not connected, get default parameters */ |
| 4510 | if (!wdev->mesh_id_len) |
| 4511 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4512 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4513 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4514 | wdev_unlock(wdev); |
| 4515 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4516 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4517 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4518 | |
| 4519 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | if (!msg) |
| 4522 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4523 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4524 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4525 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4526 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4527 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4528 | if (!pinfoattr) |
| 4529 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4530 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4531 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4532 | cur_params.dot11MeshRetryTimeout) || |
| 4533 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4534 | cur_params.dot11MeshConfirmTimeout) || |
| 4535 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4536 | cur_params.dot11MeshHoldingTimeout) || |
| 4537 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4538 | cur_params.dot11MeshMaxPeerLinks) || |
| 4539 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4540 | cur_params.dot11MeshMaxRetries) || |
| 4541 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4542 | cur_params.dot11MeshTTL) || |
| 4543 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4544 | cur_params.element_ttl) || |
| 4545 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4546 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4547 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4548 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4549 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4550 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4551 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4552 | cur_params.path_refresh_time) || |
| 4553 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4554 | cur_params.min_discovery_timeout) || |
| 4555 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4556 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4557 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4558 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4559 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4560 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4561 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4562 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4563 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4564 | cur_params.dot11MeshHWMPRootMode) || |
| 4565 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4566 | cur_params.dot11MeshHWMPRannInterval) || |
| 4567 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4568 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4569 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4570 | cur_params.dot11MeshForwarding) || |
| 4571 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4572 | cur_params.rssi_threshold) || |
| 4573 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4574 | cur_params.ht_opmode) || |
| 4575 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4576 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4577 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4578 | cur_params.dot11MeshHWMProotInterval) || |
| 4579 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4580 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4581 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4582 | cur_params.power_mode) || |
| 4583 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4584 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4585 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4586 | nla_nest_end(msg, pinfoattr); |
| 4587 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4588 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4589 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4590 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4591 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4592 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4593 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4594 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4597 | 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] | 4598 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4599 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4600 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4601 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4602 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4603 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4604 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4605 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4606 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4607 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4608 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4609 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4610 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4611 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4612 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4613 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4614 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4615 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4616 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4617 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4618 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4619 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4620 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4621 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4622 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4623 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4624 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4625 | }; |
| 4626 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4627 | static const struct nla_policy |
| 4628 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4629 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4630 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4631 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4632 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4633 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4634 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4635 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4636 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4637 | }; |
| 4638 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4639 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4640 | struct mesh_config *cfg, |
| 4641 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4642 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4643 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4644 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4645 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4646 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4647 | do { \ |
| 4648 | if (tb[attr]) { \ |
| 4649 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4650 | return -EINVAL; \ |
| 4651 | cfg->param = fn(tb[attr]); \ |
| 4652 | mask |= (1 << (attr - 1)); \ |
| 4653 | } \ |
| 4654 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4655 | |
| 4656 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4657 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4658 | return -EINVAL; |
| 4659 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4660 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4661 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4662 | return -EINVAL; |
| 4663 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4664 | /* This makes sure that there aren't more than 32 mesh config |
| 4665 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4666 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4667 | |
| 4668 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4670 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4671 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4673 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4674 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4675 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4676 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4677 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4678 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4679 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4680 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4681 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4682 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4683 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4685 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4686 | 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] | 4687 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4688 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4689 | 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] | 4690 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4691 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4693 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4694 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4695 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4697 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4698 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4699 | 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] | 4700 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4701 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4702 | 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] | 4703 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4704 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4706 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4707 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4708 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4710 | 1, 65535, mask, |
| 4711 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4712 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4714 | 1, 65535, mask, |
| 4715 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4716 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4718 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4719 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4720 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4721 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4722 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4723 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4724 | nla_get_u8); |
| 4725 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4726 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4727 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4728 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4729 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4730 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4731 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4733 | mask, NL80211_MESHCONF_FORWARDING, |
| 4734 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4735 | 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] | 4736 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4737 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4738 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4739 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4740 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4742 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4743 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4744 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4745 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4746 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4747 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4748 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4749 | dot11MeshHWMPconfirmationInterval, |
| 4750 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4751 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4752 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4753 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4754 | NL80211_MESH_POWER_ACTIVE, |
| 4755 | NL80211_MESH_POWER_MAX, |
| 4756 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4757 | nla_get_u32); |
| 4758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4759 | 0, 65535, mask, |
| 4760 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4761 | if (mask_out) |
| 4762 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4763 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4764 | return 0; |
| 4765 | |
| 4766 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4767 | } |
| 4768 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4769 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4770 | struct mesh_setup *setup) |
| 4771 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4773 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4774 | |
| 4775 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4776 | return -EINVAL; |
| 4777 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4778 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4779 | nl80211_mesh_setup_params_policy)) |
| 4780 | return -EINVAL; |
| 4781 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4782 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4783 | setup->sync_method = |
| 4784 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4785 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4786 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4787 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4788 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4789 | setup->path_sel_proto = |
| 4790 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4791 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4792 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4793 | |
| 4794 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4795 | setup->path_metric = |
| 4796 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4797 | IEEE80211_PATH_METRIC_VENDOR : |
| 4798 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4799 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4800 | |
| 4801 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4802 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4803 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4804 | if (!is_valid_ie_attr(ieattr)) |
| 4805 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4806 | setup->ie = nla_data(ieattr); |
| 4807 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4808 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4809 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4810 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4811 | return -EINVAL; |
| 4812 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4813 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4814 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4815 | if (setup->is_secure) |
| 4816 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4817 | |
| 4818 | return 0; |
| 4819 | } |
| 4820 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4821 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4822 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4823 | { |
| 4824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4826 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4827 | struct mesh_config cfg; |
| 4828 | u32 mask; |
| 4829 | int err; |
| 4830 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4831 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4832 | return -EOPNOTSUPP; |
| 4833 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4834 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4835 | return -EOPNOTSUPP; |
| 4836 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4837 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4838 | if (err) |
| 4839 | return err; |
| 4840 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4841 | wdev_lock(wdev); |
| 4842 | if (!wdev->mesh_id_len) |
| 4843 | err = -ENOLINK; |
| 4844 | |
| 4845 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4846 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4847 | |
| 4848 | wdev_unlock(wdev); |
| 4849 | |
| 4850 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4851 | } |
| 4852 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4853 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4854 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4855 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4856 | struct sk_buff *msg; |
| 4857 | void *hdr = NULL; |
| 4858 | struct nlattr *nl_reg_rules; |
| 4859 | unsigned int i; |
| 4860 | int err = -EINVAL; |
| 4861 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4862 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4863 | |
| 4864 | if (!cfg80211_regdomain) |
| 4865 | goto out; |
| 4866 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4867 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4868 | if (!msg) { |
| 4869 | err = -ENOBUFS; |
| 4870 | goto out; |
| 4871 | } |
| 4872 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4873 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4874 | NL80211_CMD_GET_REG); |
| 4875 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4876 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4877 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4878 | if (reg_last_request_cell_base() && |
| 4879 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4880 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4881 | goto nla_put_failure; |
| 4882 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4883 | rcu_read_lock(); |
| 4884 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4885 | |
| 4886 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4887 | (regdom->dfs_region && |
| 4888 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4889 | goto nla_put_failure_rcu; |
| 4890 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4891 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4892 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4893 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4894 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4895 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4896 | struct nlattr *nl_reg_rule; |
| 4897 | const struct ieee80211_reg_rule *reg_rule; |
| 4898 | const struct ieee80211_freq_range *freq_range; |
| 4899 | const struct ieee80211_power_rule *power_rule; |
| 4900 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4901 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4902 | freq_range = ®_rule->freq_range; |
| 4903 | power_rule = ®_rule->power_rule; |
| 4904 | |
| 4905 | nl_reg_rule = nla_nest_start(msg, i); |
| 4906 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4907 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4908 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4909 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4910 | reg_rule->flags) || |
| 4911 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4912 | freq_range->start_freq_khz) || |
| 4913 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4914 | freq_range->end_freq_khz) || |
| 4915 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4916 | freq_range->max_bandwidth_khz) || |
| 4917 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4918 | power_rule->max_antenna_gain) || |
| 4919 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4920 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4921 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4922 | |
| 4923 | nla_nest_end(msg, nl_reg_rule); |
| 4924 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4925 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4926 | |
| 4927 | nla_nest_end(msg, nl_reg_rules); |
| 4928 | |
| 4929 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4930 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4931 | goto out; |
| 4932 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4933 | nla_put_failure_rcu: |
| 4934 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4935 | nla_put_failure: |
| 4936 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4937 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4938 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4939 | err = -EMSGSIZE; |
| 4940 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4941 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4942 | return err; |
| 4943 | } |
| 4944 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4945 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4946 | { |
| 4947 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4948 | struct nlattr *nl_reg_rule; |
| 4949 | char *alpha2 = NULL; |
| 4950 | int rem_reg_rules = 0, r = 0; |
| 4951 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4952 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4953 | struct ieee80211_regdomain *rd = NULL; |
| 4954 | |
| 4955 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4956 | return -EINVAL; |
| 4957 | |
| 4958 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4959 | return -EINVAL; |
| 4960 | |
| 4961 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4962 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4963 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4964 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4965 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4966 | 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] | 4967 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4968 | num_rules++; |
| 4969 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4970 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4973 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4974 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4975 | |
| 4976 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4977 | if (!rd) |
| 4978 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4979 | |
| 4980 | rd->n_reg_rules = num_rules; |
| 4981 | rd->alpha2[0] = alpha2[0]; |
| 4982 | rd->alpha2[1] = alpha2[1]; |
| 4983 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4984 | /* |
| 4985 | * Disable DFS master mode if the DFS region was |
| 4986 | * not supported or known on this kernel. |
| 4987 | */ |
| 4988 | if (reg_supported_dfs_region(dfs_region)) |
| 4989 | rd->dfs_region = dfs_region; |
| 4990 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4991 | 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] | 4992 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4993 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4994 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4995 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4996 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4997 | if (r) |
| 4998 | goto bad_reg; |
| 4999 | |
| 5000 | rule_idx++; |
| 5001 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5002 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5003 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5004 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5005 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5008 | mutex_lock(&cfg80211_mutex); |
| 5009 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5010 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5011 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5012 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5013 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5014 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5015 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5016 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5017 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5020 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5021 | { |
| 5022 | struct nlattr *attr1, *attr2; |
| 5023 | int n_channels = 0, tmp1, tmp2; |
| 5024 | |
| 5025 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5026 | n_channels++; |
| 5027 | /* |
| 5028 | * Some hardware has a limited channel list for |
| 5029 | * scanning, and it is pretty much nonsensical |
| 5030 | * to scan for a channel twice, so disallow that |
| 5031 | * and don't require drivers to check that the |
| 5032 | * channel list they get isn't longer than what |
| 5033 | * they can scan, as long as they can scan all |
| 5034 | * the channels they registered at once. |
| 5035 | */ |
| 5036 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5037 | if (attr1 != attr2 && |
| 5038 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5039 | return 0; |
| 5040 | } |
| 5041 | |
| 5042 | return n_channels; |
| 5043 | } |
| 5044 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5045 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5046 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5048 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5049 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5050 | struct nlattr *attr; |
| 5051 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5052 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5053 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5054 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5055 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5056 | return -EINVAL; |
| 5057 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5058 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5059 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5060 | if (!rdev->ops->scan) |
| 5061 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5062 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5063 | mutex_lock(&rdev->sched_scan_mtx); |
| 5064 | if (rdev->scan_req) { |
| 5065 | err = -EBUSY; |
| 5066 | goto unlock; |
| 5067 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5068 | |
| 5069 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5070 | n_channels = validate_scan_freqs( |
| 5071 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5072 | if (!n_channels) { |
| 5073 | err = -EINVAL; |
| 5074 | goto unlock; |
| 5075 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5076 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5077 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5078 | n_channels = 0; |
| 5079 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5080 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5081 | if (wiphy->bands[band]) |
| 5082 | n_channels += wiphy->bands[band]->n_channels; |
| 5083 | } |
| 5084 | |
| 5085 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5086 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5087 | n_ssids++; |
| 5088 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5089 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5090 | err = -EINVAL; |
| 5091 | goto unlock; |
| 5092 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5093 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5094 | if (info->attrs[NL80211_ATTR_IE]) |
| 5095 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5096 | else |
| 5097 | ie_len = 0; |
| 5098 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5099 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5100 | err = -EINVAL; |
| 5101 | goto unlock; |
| 5102 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5103 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5104 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5105 | + sizeof(*request->ssids) * n_ssids |
| 5106 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5107 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5108 | if (!request) { |
| 5109 | err = -ENOMEM; |
| 5110 | goto unlock; |
| 5111 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5112 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5113 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5114 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5115 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5116 | if (ie_len) { |
| 5117 | if (request->ssids) |
| 5118 | request->ie = (void *)(request->ssids + n_ssids); |
| 5119 | else |
| 5120 | request->ie = (void *)(request->channels + n_channels); |
| 5121 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5122 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5123 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5124 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5125 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5126 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5127 | struct ieee80211_channel *chan; |
| 5128 | |
| 5129 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5130 | |
| 5131 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5132 | err = -EINVAL; |
| 5133 | goto out_free; |
| 5134 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5135 | |
| 5136 | /* ignore disabled channels */ |
| 5137 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5138 | continue; |
| 5139 | |
| 5140 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5141 | i++; |
| 5142 | } |
| 5143 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5144 | enum ieee80211_band band; |
| 5145 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5146 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5147 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5148 | int j; |
| 5149 | if (!wiphy->bands[band]) |
| 5150 | continue; |
| 5151 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5152 | struct ieee80211_channel *chan; |
| 5153 | |
| 5154 | chan = &wiphy->bands[band]->channels[j]; |
| 5155 | |
| 5156 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5157 | continue; |
| 5158 | |
| 5159 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5160 | i++; |
| 5161 | } |
| 5162 | } |
| 5163 | } |
| 5164 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5165 | if (!i) { |
| 5166 | err = -EINVAL; |
| 5167 | goto out_free; |
| 5168 | } |
| 5169 | |
| 5170 | request->n_channels = i; |
| 5171 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5172 | i = 0; |
| 5173 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5174 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5175 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5176 | err = -EINVAL; |
| 5177 | goto out_free; |
| 5178 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5179 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5180 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5181 | i++; |
| 5182 | } |
| 5183 | } |
| 5184 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5185 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5186 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5187 | memcpy((void *)request->ie, |
| 5188 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5189 | request->ie_len); |
| 5190 | } |
| 5191 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5192 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5193 | if (wiphy->bands[i]) |
| 5194 | request->rates[i] = |
| 5195 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5196 | |
| 5197 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5198 | nla_for_each_nested(attr, |
| 5199 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5200 | tmp) { |
| 5201 | enum ieee80211_band band = nla_type(attr); |
| 5202 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5203 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5204 | err = -EINVAL; |
| 5205 | goto out_free; |
| 5206 | } |
| 5207 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5208 | nla_data(attr), |
| 5209 | nla_len(attr), |
| 5210 | &request->rates[band]); |
| 5211 | if (err) |
| 5212 | goto out_free; |
| 5213 | } |
| 5214 | } |
| 5215 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5216 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5217 | request->flags = nla_get_u32( |
| 5218 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5219 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5220 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5221 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5222 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5223 | err = -EOPNOTSUPP; |
| 5224 | goto out_free; |
| 5225 | } |
| 5226 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5227 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5228 | request->no_cck = |
| 5229 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5230 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5231 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5232 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5233 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5235 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5236 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5237 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5238 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5239 | nl80211_send_scan_start(rdev, wdev); |
| 5240 | if (wdev->netdev) |
| 5241 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5242 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5243 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5244 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5245 | kfree(request); |
| 5246 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5247 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5248 | unlock: |
| 5249 | mutex_unlock(&rdev->sched_scan_mtx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5250 | return err; |
| 5251 | } |
| 5252 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5253 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5254 | struct genl_info *info) |
| 5255 | { |
| 5256 | struct cfg80211_sched_scan_request *request; |
| 5257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5258 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5259 | struct nlattr *attr; |
| 5260 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5261 | 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] | 5262 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5263 | enum ieee80211_band band; |
| 5264 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5265 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5266 | |
| 5267 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5268 | !rdev->ops->sched_scan_start) |
| 5269 | return -EOPNOTSUPP; |
| 5270 | |
| 5271 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5272 | return -EINVAL; |
| 5273 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5274 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5275 | return -EINVAL; |
| 5276 | |
| 5277 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5278 | if (interval == 0) |
| 5279 | return -EINVAL; |
| 5280 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5281 | wiphy = &rdev->wiphy; |
| 5282 | |
| 5283 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5284 | n_channels = validate_scan_freqs( |
| 5285 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5286 | if (!n_channels) |
| 5287 | return -EINVAL; |
| 5288 | } else { |
| 5289 | n_channels = 0; |
| 5290 | |
| 5291 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5292 | if (wiphy->bands[band]) |
| 5293 | n_channels += wiphy->bands[band]->n_channels; |
| 5294 | } |
| 5295 | |
| 5296 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5297 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5298 | tmp) |
| 5299 | n_ssids++; |
| 5300 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5301 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5302 | return -EINVAL; |
| 5303 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5304 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5305 | nla_for_each_nested(attr, |
| 5306 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5307 | tmp) |
| 5308 | n_match_sets++; |
| 5309 | |
| 5310 | if (n_match_sets > wiphy->max_match_sets) |
| 5311 | return -EINVAL; |
| 5312 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5313 | if (info->attrs[NL80211_ATTR_IE]) |
| 5314 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5315 | else |
| 5316 | ie_len = 0; |
| 5317 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5318 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5319 | return -EINVAL; |
| 5320 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5321 | mutex_lock(&rdev->sched_scan_mtx); |
| 5322 | |
| 5323 | if (rdev->sched_scan_req) { |
| 5324 | err = -EINPROGRESS; |
| 5325 | goto out; |
| 5326 | } |
| 5327 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5328 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5329 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5330 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5331 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5332 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5333 | if (!request) { |
| 5334 | err = -ENOMEM; |
| 5335 | goto out; |
| 5336 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5337 | |
| 5338 | if (n_ssids) |
| 5339 | request->ssids = (void *)&request->channels[n_channels]; |
| 5340 | request->n_ssids = n_ssids; |
| 5341 | if (ie_len) { |
| 5342 | if (request->ssids) |
| 5343 | request->ie = (void *)(request->ssids + n_ssids); |
| 5344 | else |
| 5345 | request->ie = (void *)(request->channels + n_channels); |
| 5346 | } |
| 5347 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5348 | if (n_match_sets) { |
| 5349 | if (request->ie) |
| 5350 | request->match_sets = (void *)(request->ie + ie_len); |
| 5351 | else if (request->ssids) |
| 5352 | request->match_sets = |
| 5353 | (void *)(request->ssids + n_ssids); |
| 5354 | else |
| 5355 | request->match_sets = |
| 5356 | (void *)(request->channels + n_channels); |
| 5357 | } |
| 5358 | request->n_match_sets = n_match_sets; |
| 5359 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5360 | i = 0; |
| 5361 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5362 | /* user specified, bail out if channel not found */ |
| 5363 | nla_for_each_nested(attr, |
| 5364 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5365 | tmp) { |
| 5366 | struct ieee80211_channel *chan; |
| 5367 | |
| 5368 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5369 | |
| 5370 | if (!chan) { |
| 5371 | err = -EINVAL; |
| 5372 | goto out_free; |
| 5373 | } |
| 5374 | |
| 5375 | /* ignore disabled channels */ |
| 5376 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5377 | continue; |
| 5378 | |
| 5379 | request->channels[i] = chan; |
| 5380 | i++; |
| 5381 | } |
| 5382 | } else { |
| 5383 | /* all channels */ |
| 5384 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5385 | int j; |
| 5386 | if (!wiphy->bands[band]) |
| 5387 | continue; |
| 5388 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5389 | struct ieee80211_channel *chan; |
| 5390 | |
| 5391 | chan = &wiphy->bands[band]->channels[j]; |
| 5392 | |
| 5393 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5394 | continue; |
| 5395 | |
| 5396 | request->channels[i] = chan; |
| 5397 | i++; |
| 5398 | } |
| 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | if (!i) { |
| 5403 | err = -EINVAL; |
| 5404 | goto out_free; |
| 5405 | } |
| 5406 | |
| 5407 | request->n_channels = i; |
| 5408 | |
| 5409 | i = 0; |
| 5410 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5411 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5412 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5413 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5414 | err = -EINVAL; |
| 5415 | goto out_free; |
| 5416 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5417 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5418 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5419 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5420 | i++; |
| 5421 | } |
| 5422 | } |
| 5423 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5424 | i = 0; |
| 5425 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5426 | nla_for_each_nested(attr, |
| 5427 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5428 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5429 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5430 | |
| 5431 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5432 | nla_data(attr), nla_len(attr), |
| 5433 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5434 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5435 | if (ssid) { |
| 5436 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5437 | err = -EINVAL; |
| 5438 | goto out_free; |
| 5439 | } |
| 5440 | memcpy(request->match_sets[i].ssid.ssid, |
| 5441 | nla_data(ssid), nla_len(ssid)); |
| 5442 | request->match_sets[i].ssid.ssid_len = |
| 5443 | nla_len(ssid); |
| 5444 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5445 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5446 | if (rssi) |
| 5447 | request->rssi_thold = nla_get_u32(rssi); |
| 5448 | else |
| 5449 | request->rssi_thold = |
| 5450 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5451 | i++; |
| 5452 | } |
| 5453 | } |
| 5454 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5455 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5456 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5457 | memcpy((void *)request->ie, |
| 5458 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5459 | request->ie_len); |
| 5460 | } |
| 5461 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5462 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5463 | request->flags = nla_get_u32( |
| 5464 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5465 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5466 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5467 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5468 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5469 | err = -EOPNOTSUPP; |
| 5470 | goto out_free; |
| 5471 | } |
| 5472 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5473 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5474 | request->dev = dev; |
| 5475 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5476 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5477 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5478 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5479 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5480 | if (!err) { |
| 5481 | rdev->sched_scan_req = request; |
| 5482 | nl80211_send_sched_scan(rdev, dev, |
| 5483 | NL80211_CMD_START_SCHED_SCAN); |
| 5484 | goto out; |
| 5485 | } |
| 5486 | |
| 5487 | out_free: |
| 5488 | kfree(request); |
| 5489 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5490 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5491 | return err; |
| 5492 | } |
| 5493 | |
| 5494 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5495 | struct genl_info *info) |
| 5496 | { |
| 5497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5498 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5499 | |
| 5500 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5501 | !rdev->ops->sched_scan_stop) |
| 5502 | return -EOPNOTSUPP; |
| 5503 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5504 | mutex_lock(&rdev->sched_scan_mtx); |
| 5505 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5506 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5507 | |
| 5508 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5509 | } |
| 5510 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5511 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5512 | struct genl_info *info) |
| 5513 | { |
| 5514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5515 | struct net_device *dev = info->user_ptr[1]; |
| 5516 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5517 | struct cfg80211_chan_def chandef; |
| 5518 | int err; |
| 5519 | |
| 5520 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5521 | if (err) |
| 5522 | return err; |
| 5523 | |
| 5524 | if (wdev->cac_started) |
| 5525 | return -EBUSY; |
| 5526 | |
| 5527 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5528 | if (err < 0) |
| 5529 | return err; |
| 5530 | |
| 5531 | if (err == 0) |
| 5532 | return -EINVAL; |
| 5533 | |
| 5534 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5535 | return -EINVAL; |
| 5536 | |
| 5537 | if (!rdev->ops->start_radar_detection) |
| 5538 | return -EOPNOTSUPP; |
| 5539 | |
| 5540 | mutex_lock(&rdev->devlist_mtx); |
| 5541 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5542 | chandef.chan, CHAN_MODE_SHARED, |
| 5543 | BIT(chandef.width)); |
| 5544 | if (err) |
| 5545 | goto err_locked; |
| 5546 | |
| 5547 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5548 | if (!err) { |
| 5549 | wdev->channel = chandef.chan; |
| 5550 | wdev->cac_started = true; |
| 5551 | wdev->cac_start_time = jiffies; |
| 5552 | } |
| 5553 | err_locked: |
| 5554 | mutex_unlock(&rdev->devlist_mtx); |
| 5555 | |
| 5556 | return err; |
| 5557 | } |
| 5558 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5559 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5560 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5561 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5562 | struct wireless_dev *wdev, |
| 5563 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5564 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5565 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5566 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5567 | void *hdr; |
| 5568 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5569 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5570 | |
| 5571 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5572 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5573 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5574 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5575 | if (!hdr) |
| 5576 | return -1; |
| 5577 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5578 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5579 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5580 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5581 | goto nla_put_failure; |
| 5582 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5583 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5584 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5585 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5586 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5587 | |
| 5588 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5589 | if (!bss) |
| 5590 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5591 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5592 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5593 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5594 | |
| 5595 | rcu_read_lock(); |
| 5596 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5597 | if (ies) { |
| 5598 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5599 | goto fail_unlock_rcu; |
| 5600 | tsf = true; |
| 5601 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5602 | ies->len, ies->data)) |
| 5603 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5604 | } |
| 5605 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5606 | if (ies) { |
| 5607 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5608 | goto fail_unlock_rcu; |
| 5609 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5610 | ies->len, ies->data)) |
| 5611 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5612 | } |
| 5613 | rcu_read_unlock(); |
| 5614 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5615 | if (res->beacon_interval && |
| 5616 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5617 | goto nla_put_failure; |
| 5618 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5619 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5620 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5621 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5622 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5623 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5624 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5625 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5626 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5627 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5628 | break; |
| 5629 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5630 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5631 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5632 | break; |
| 5633 | default: |
| 5634 | break; |
| 5635 | } |
| 5636 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5637 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5638 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5639 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5640 | if (intbss == wdev->current_bss && |
| 5641 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5642 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5643 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5644 | break; |
| 5645 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5646 | if (intbss == wdev->current_bss && |
| 5647 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5648 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5649 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5650 | break; |
| 5651 | default: |
| 5652 | break; |
| 5653 | } |
| 5654 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5655 | nla_nest_end(msg, bss); |
| 5656 | |
| 5657 | return genlmsg_end(msg, hdr); |
| 5658 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5659 | fail_unlock_rcu: |
| 5660 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5661 | nla_put_failure: |
| 5662 | genlmsg_cancel(msg, hdr); |
| 5663 | return -EMSGSIZE; |
| 5664 | } |
| 5665 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5666 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5667 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5668 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5669 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5670 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5671 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5672 | int err; |
| 5673 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5674 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5675 | if (err) |
| 5676 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5677 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5678 | wdev_lock(wdev); |
| 5679 | spin_lock_bh(&rdev->bss_lock); |
| 5680 | cfg80211_bss_expire(rdev); |
| 5681 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5682 | cb->seq = rdev->bss_generation; |
| 5683 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5684 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5685 | if (++idx <= start) |
| 5686 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5687 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5688 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5689 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5690 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5691 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5692 | } |
| 5693 | } |
| 5694 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5695 | spin_unlock_bh(&rdev->bss_lock); |
| 5696 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5697 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5698 | cb->args[2] = idx; |
| 5699 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5700 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5701 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5704 | 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] | 5705 | int flags, struct net_device *dev, |
| 5706 | struct survey_info *survey) |
| 5707 | { |
| 5708 | void *hdr; |
| 5709 | struct nlattr *infoattr; |
| 5710 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5711 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5712 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5713 | if (!hdr) |
| 5714 | return -ENOMEM; |
| 5715 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5716 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5717 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5718 | |
| 5719 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5720 | if (!infoattr) |
| 5721 | goto nla_put_failure; |
| 5722 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5723 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5724 | survey->channel->center_freq)) |
| 5725 | goto nla_put_failure; |
| 5726 | |
| 5727 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5728 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5729 | goto nla_put_failure; |
| 5730 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5731 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5732 | goto nla_put_failure; |
| 5733 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5734 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5735 | survey->channel_time)) |
| 5736 | goto nla_put_failure; |
| 5737 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5738 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5739 | survey->channel_time_busy)) |
| 5740 | goto nla_put_failure; |
| 5741 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5742 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5743 | survey->channel_time_ext_busy)) |
| 5744 | goto nla_put_failure; |
| 5745 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5746 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5747 | survey->channel_time_rx)) |
| 5748 | goto nla_put_failure; |
| 5749 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5750 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5751 | survey->channel_time_tx)) |
| 5752 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5753 | |
| 5754 | nla_nest_end(msg, infoattr); |
| 5755 | |
| 5756 | return genlmsg_end(msg, hdr); |
| 5757 | |
| 5758 | nla_put_failure: |
| 5759 | genlmsg_cancel(msg, hdr); |
| 5760 | return -EMSGSIZE; |
| 5761 | } |
| 5762 | |
| 5763 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5764 | struct netlink_callback *cb) |
| 5765 | { |
| 5766 | struct survey_info survey; |
| 5767 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5768 | struct wireless_dev *wdev; |
| 5769 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5770 | int res; |
| 5771 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5772 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5773 | if (res) |
| 5774 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5775 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5776 | if (!wdev->netdev) { |
| 5777 | res = -EINVAL; |
| 5778 | goto out_err; |
| 5779 | } |
| 5780 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5781 | if (!dev->ops->dump_survey) { |
| 5782 | res = -EOPNOTSUPP; |
| 5783 | goto out_err; |
| 5784 | } |
| 5785 | |
| 5786 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5787 | struct ieee80211_channel *chan; |
| 5788 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5789 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5790 | if (res == -ENOENT) |
| 5791 | break; |
| 5792 | if (res) |
| 5793 | goto out_err; |
| 5794 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5795 | /* Survey without a channel doesn't make sense */ |
| 5796 | if (!survey.channel) { |
| 5797 | res = -EINVAL; |
| 5798 | goto out; |
| 5799 | } |
| 5800 | |
| 5801 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5802 | survey.channel->center_freq); |
| 5803 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5804 | survey_idx++; |
| 5805 | continue; |
| 5806 | } |
| 5807 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5808 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5809 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5810 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5811 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5812 | goto out; |
| 5813 | survey_idx++; |
| 5814 | } |
| 5815 | |
| 5816 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5817 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5818 | res = skb->len; |
| 5819 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5820 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5821 | return res; |
| 5822 | } |
| 5823 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5824 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5825 | { |
| 5826 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5827 | NL80211_WPA_VERSION_2)); |
| 5828 | } |
| 5829 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5830 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5831 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5833 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5834 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5835 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5836 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5837 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5838 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5839 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5840 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5841 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5842 | return -EINVAL; |
| 5843 | |
| 5844 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5845 | return -EINVAL; |
| 5846 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5847 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5848 | return -EINVAL; |
| 5849 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5850 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5851 | return -EINVAL; |
| 5852 | |
| 5853 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5854 | return -EINVAL; |
| 5855 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5856 | err = nl80211_parse_key(info, &key); |
| 5857 | if (err) |
| 5858 | return err; |
| 5859 | |
| 5860 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5861 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5862 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5863 | if (!key.p.key || !key.p.key_len) |
| 5864 | return -EINVAL; |
| 5865 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5866 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5867 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5868 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5869 | return -EINVAL; |
| 5870 | if (key.idx > 4) |
| 5871 | return -EINVAL; |
| 5872 | } else { |
| 5873 | key.p.key_len = 0; |
| 5874 | key.p.key = NULL; |
| 5875 | } |
| 5876 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5877 | if (key.idx >= 0) { |
| 5878 | int i; |
| 5879 | bool ok = false; |
| 5880 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5881 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5882 | ok = true; |
| 5883 | break; |
| 5884 | } |
| 5885 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5886 | if (!ok) |
| 5887 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5888 | } |
| 5889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5890 | if (!rdev->ops->auth) |
| 5891 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5892 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5894 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5895 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5896 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5897 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5898 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5899 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5900 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5901 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5902 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5903 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5904 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5905 | |
| 5906 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5907 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5908 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5909 | } |
| 5910 | |
| 5911 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5912 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5913 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5914 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5915 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5916 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5917 | return -EINVAL; |
| 5918 | |
| 5919 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5920 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5921 | return -EINVAL; |
| 5922 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5923 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5924 | /* need to include at least Auth Transaction and Status Code */ |
| 5925 | if (sae_data_len < 4) |
| 5926 | return -EINVAL; |
| 5927 | } |
| 5928 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5929 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5930 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5931 | /* |
| 5932 | * Since we no longer track auth state, ignore |
| 5933 | * requests to only change local state. |
| 5934 | */ |
| 5935 | if (local_state_change) |
| 5936 | return 0; |
| 5937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5938 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5939 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5940 | key.p.key, key.p.key_len, key.idx, |
| 5941 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5942 | } |
| 5943 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5944 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5945 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5946 | struct cfg80211_crypto_settings *settings, |
| 5947 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5948 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5949 | memset(settings, 0, sizeof(*settings)); |
| 5950 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5951 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5952 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5953 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5954 | u16 proto; |
| 5955 | proto = nla_get_u16( |
| 5956 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5957 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5958 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5959 | proto != ETH_P_PAE) |
| 5960 | return -EINVAL; |
| 5961 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5962 | settings->control_port_no_encrypt = true; |
| 5963 | } else |
| 5964 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5965 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5966 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5967 | void *data; |
| 5968 | int len, i; |
| 5969 | |
| 5970 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5971 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5972 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5973 | |
| 5974 | if (len % sizeof(u32)) |
| 5975 | return -EINVAL; |
| 5976 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5977 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5978 | return -EINVAL; |
| 5979 | |
| 5980 | memcpy(settings->ciphers_pairwise, data, len); |
| 5981 | |
| 5982 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5983 | if (!cfg80211_supported_cipher_suite( |
| 5984 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5985 | settings->ciphers_pairwise[i])) |
| 5986 | return -EINVAL; |
| 5987 | } |
| 5988 | |
| 5989 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5990 | settings->cipher_group = |
| 5991 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5992 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5993 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5994 | return -EINVAL; |
| 5995 | } |
| 5996 | |
| 5997 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5998 | settings->wpa_versions = |
| 5999 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6000 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6001 | return -EINVAL; |
| 6002 | } |
| 6003 | |
| 6004 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6005 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6006 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6007 | |
| 6008 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6009 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6010 | settings->n_akm_suites = len / sizeof(u32); |
| 6011 | |
| 6012 | if (len % sizeof(u32)) |
| 6013 | return -EINVAL; |
| 6014 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6015 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6016 | return -EINVAL; |
| 6017 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6018 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | return 0; |
| 6022 | } |
| 6023 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6024 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6025 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6027 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6028 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6029 | struct cfg80211_assoc_request req = {}; |
| 6030 | const u8 *bssid, *ssid; |
| 6031 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6032 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6033 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6034 | return -EINVAL; |
| 6035 | |
| 6036 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6037 | !info->attrs[NL80211_ATTR_SSID] || |
| 6038 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6039 | return -EINVAL; |
| 6040 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6041 | if (!rdev->ops->assoc) |
| 6042 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6043 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6046 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6047 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6048 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6049 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6050 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6051 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6052 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6053 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6054 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6055 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6056 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6057 | |
| 6058 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6059 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6060 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6061 | } |
| 6062 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6063 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6064 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6065 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6066 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6067 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6068 | else if (mfp != NL80211_MFP_NO) |
| 6069 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6070 | } |
| 6071 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6072 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6073 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6074 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6075 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6076 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6077 | |
| 6078 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6079 | memcpy(&req.ht_capa_mask, |
| 6080 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6081 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6082 | |
| 6083 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6084 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6085 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6086 | memcpy(&req.ht_capa, |
| 6087 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6088 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6089 | } |
| 6090 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6091 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6092 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6093 | |
| 6094 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6095 | memcpy(&req.vht_capa_mask, |
| 6096 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6097 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6098 | |
| 6099 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6100 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6101 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6102 | memcpy(&req.vht_capa, |
| 6103 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6104 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6105 | } |
| 6106 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6107 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6108 | if (!err) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6109 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6110 | ssid, ssid_len, &req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6111 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6112 | return err; |
| 6113 | } |
| 6114 | |
| 6115 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6116 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6117 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6118 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6119 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6120 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6121 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6122 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6123 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6124 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6125 | return -EINVAL; |
| 6126 | |
| 6127 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6128 | return -EINVAL; |
| 6129 | |
| 6130 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6131 | return -EINVAL; |
| 6132 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6133 | if (!rdev->ops->deauth) |
| 6134 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6135 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6136 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6137 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6138 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6139 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6140 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6141 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6142 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6143 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6144 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6145 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6146 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6147 | |
| 6148 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6149 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6150 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6151 | } |
| 6152 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6153 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6154 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6155 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6156 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6157 | } |
| 6158 | |
| 6159 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6160 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6162 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6163 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6164 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6165 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6166 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6167 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6168 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6169 | return -EINVAL; |
| 6170 | |
| 6171 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6172 | return -EINVAL; |
| 6173 | |
| 6174 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6175 | return -EINVAL; |
| 6176 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6177 | if (!rdev->ops->disassoc) |
| 6178 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6179 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6180 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6181 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6182 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6183 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6184 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6185 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6186 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6187 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6188 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6189 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6190 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6191 | |
| 6192 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6193 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6194 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6195 | } |
| 6196 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6197 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6198 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6199 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6200 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6201 | } |
| 6202 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6203 | static bool |
| 6204 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6205 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6206 | int rateval) |
| 6207 | { |
| 6208 | struct wiphy *wiphy = &rdev->wiphy; |
| 6209 | bool found = false; |
| 6210 | int band, i; |
| 6211 | |
| 6212 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6213 | struct ieee80211_supported_band *sband; |
| 6214 | |
| 6215 | sband = wiphy->bands[band]; |
| 6216 | if (!sband) |
| 6217 | continue; |
| 6218 | |
| 6219 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6220 | if (sband->bitrates[i].bitrate == rateval) { |
| 6221 | mcast_rate[band] = i + 1; |
| 6222 | found = true; |
| 6223 | break; |
| 6224 | } |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | return found; |
| 6229 | } |
| 6230 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6231 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6232 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6234 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6235 | struct cfg80211_ibss_params ibss; |
| 6236 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6237 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6238 | int err; |
| 6239 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6240 | memset(&ibss, 0, sizeof(ibss)); |
| 6241 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6242 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6243 | return -EINVAL; |
| 6244 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6245 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6246 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6247 | return -EINVAL; |
| 6248 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6249 | ibss.beacon_interval = 100; |
| 6250 | |
| 6251 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6252 | ibss.beacon_interval = |
| 6253 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6254 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6255 | return -EINVAL; |
| 6256 | } |
| 6257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6258 | if (!rdev->ops->join_ibss) |
| 6259 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6260 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6261 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6262 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6263 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6264 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6265 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6266 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6267 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6268 | |
| 6269 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6270 | return -EINVAL; |
| 6271 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6272 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6273 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6274 | |
| 6275 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6276 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6277 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6278 | } |
| 6279 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6280 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6281 | if (err) |
| 6282 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6283 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6284 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6285 | return -EINVAL; |
| 6286 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6287 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 6288 | return -EINVAL; |
| 6289 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 6290 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 6291 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6292 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6293 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6294 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6295 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6296 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6297 | u8 *rates = |
| 6298 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6299 | int n_rates = |
| 6300 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6301 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6302 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6303 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6304 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6305 | &ibss.basic_rates); |
| 6306 | if (err) |
| 6307 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6308 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6309 | |
| 6310 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6311 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6312 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6313 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6314 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6315 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6316 | bool no_ht = false; |
| 6317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6318 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6319 | info->attrs[NL80211_ATTR_KEYS], |
| 6320 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6321 | if (IS_ERR(connkeys)) |
| 6322 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6323 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6324 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6325 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6326 | kfree(connkeys); |
| 6327 | return -EINVAL; |
| 6328 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6329 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6330 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6331 | ibss.control_port = |
| 6332 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6334 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6335 | if (err) |
| 6336 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6337 | return err; |
| 6338 | } |
| 6339 | |
| 6340 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6341 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6343 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6345 | if (!rdev->ops->leave_ibss) |
| 6346 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6347 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6348 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6349 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6351 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6352 | } |
| 6353 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6354 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6355 | { |
| 6356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6357 | struct net_device *dev = info->user_ptr[1]; |
| 6358 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6359 | u32 nla_rate; |
| 6360 | int err; |
| 6361 | |
| 6362 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6363 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6364 | return -EOPNOTSUPP; |
| 6365 | |
| 6366 | if (!rdev->ops->set_mcast_rate) |
| 6367 | return -EOPNOTSUPP; |
| 6368 | |
| 6369 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6370 | |
| 6371 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6372 | return -EINVAL; |
| 6373 | |
| 6374 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6375 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6376 | return -EINVAL; |
| 6377 | |
| 6378 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6379 | |
| 6380 | return err; |
| 6381 | } |
| 6382 | |
| 6383 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6384 | #ifdef CONFIG_NL80211_TESTMODE |
| 6385 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6386 | .name = "testmode", |
| 6387 | }; |
| 6388 | |
| 6389 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6392 | int err; |
| 6393 | |
| 6394 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6395 | return -EINVAL; |
| 6396 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6397 | err = -EOPNOTSUPP; |
| 6398 | if (rdev->ops->testmode_cmd) { |
| 6399 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6400 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6401 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6402 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6403 | rdev->testmode_info = NULL; |
| 6404 | } |
| 6405 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6406 | return err; |
| 6407 | } |
| 6408 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6409 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6410 | struct netlink_callback *cb) |
| 6411 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6412 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6413 | int err; |
| 6414 | long phy_idx; |
| 6415 | void *data = NULL; |
| 6416 | int data_len = 0; |
| 6417 | |
| 6418 | if (cb->args[0]) { |
| 6419 | /* |
| 6420 | * 0 is a valid index, but not valid for args[0], |
| 6421 | * so we need to offset by 1. |
| 6422 | */ |
| 6423 | phy_idx = cb->args[0] - 1; |
| 6424 | } else { |
| 6425 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6426 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6427 | nl80211_policy); |
| 6428 | if (err) |
| 6429 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6430 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6431 | mutex_lock(&cfg80211_mutex); |
| 6432 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6433 | nl80211_fam.attrbuf); |
| 6434 | if (IS_ERR(rdev)) { |
| 6435 | mutex_unlock(&cfg80211_mutex); |
| 6436 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6437 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6438 | phy_idx = rdev->wiphy_idx; |
| 6439 | rdev = NULL; |
| 6440 | mutex_unlock(&cfg80211_mutex); |
| 6441 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6442 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6443 | cb->args[1] = |
| 6444 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6445 | } |
| 6446 | |
| 6447 | if (cb->args[1]) { |
| 6448 | data = nla_data((void *)cb->args[1]); |
| 6449 | data_len = nla_len((void *)cb->args[1]); |
| 6450 | } |
| 6451 | |
| 6452 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6453 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6454 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6455 | mutex_unlock(&cfg80211_mutex); |
| 6456 | return -ENOENT; |
| 6457 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6458 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6459 | mutex_unlock(&cfg80211_mutex); |
| 6460 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6461 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6462 | err = -EOPNOTSUPP; |
| 6463 | goto out_err; |
| 6464 | } |
| 6465 | |
| 6466 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6467 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6468 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6469 | NL80211_CMD_TESTMODE); |
| 6470 | struct nlattr *tmdata; |
| 6471 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6472 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6473 | genlmsg_cancel(skb, hdr); |
| 6474 | break; |
| 6475 | } |
| 6476 | |
| 6477 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6478 | if (!tmdata) { |
| 6479 | genlmsg_cancel(skb, hdr); |
| 6480 | break; |
| 6481 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6482 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6483 | nla_nest_end(skb, tmdata); |
| 6484 | |
| 6485 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6486 | genlmsg_cancel(skb, hdr); |
| 6487 | break; |
| 6488 | } else if (err) { |
| 6489 | genlmsg_cancel(skb, hdr); |
| 6490 | goto out_err; |
| 6491 | } |
| 6492 | |
| 6493 | genlmsg_end(skb, hdr); |
| 6494 | } |
| 6495 | |
| 6496 | err = skb->len; |
| 6497 | /* see above */ |
| 6498 | cb->args[0] = phy_idx + 1; |
| 6499 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6500 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6501 | return err; |
| 6502 | } |
| 6503 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6504 | static struct sk_buff * |
| 6505 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6506 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6507 | { |
| 6508 | struct sk_buff *skb; |
| 6509 | void *hdr; |
| 6510 | struct nlattr *data; |
| 6511 | |
| 6512 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6513 | if (!skb) |
| 6514 | return NULL; |
| 6515 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6516 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6517 | if (!hdr) { |
| 6518 | kfree_skb(skb); |
| 6519 | return NULL; |
| 6520 | } |
| 6521 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6522 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6523 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6524 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6525 | |
| 6526 | ((void **)skb->cb)[0] = rdev; |
| 6527 | ((void **)skb->cb)[1] = hdr; |
| 6528 | ((void **)skb->cb)[2] = data; |
| 6529 | |
| 6530 | return skb; |
| 6531 | |
| 6532 | nla_put_failure: |
| 6533 | kfree_skb(skb); |
| 6534 | return NULL; |
| 6535 | } |
| 6536 | |
| 6537 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6538 | int approxlen) |
| 6539 | { |
| 6540 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6541 | |
| 6542 | if (WARN_ON(!rdev->testmode_info)) |
| 6543 | return NULL; |
| 6544 | |
| 6545 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6546 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6547 | rdev->testmode_info->snd_seq, |
| 6548 | GFP_KERNEL); |
| 6549 | } |
| 6550 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6551 | |
| 6552 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6553 | { |
| 6554 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6555 | void *hdr = ((void **)skb->cb)[1]; |
| 6556 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6557 | |
| 6558 | if (WARN_ON(!rdev->testmode_info)) { |
| 6559 | kfree_skb(skb); |
| 6560 | return -EINVAL; |
| 6561 | } |
| 6562 | |
| 6563 | nla_nest_end(skb, data); |
| 6564 | genlmsg_end(skb, hdr); |
| 6565 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6566 | } |
| 6567 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6568 | |
| 6569 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6570 | int approxlen, gfp_t gfp) |
| 6571 | { |
| 6572 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6573 | |
| 6574 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6575 | } |
| 6576 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6577 | |
| 6578 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6579 | { |
| 6580 | void *hdr = ((void **)skb->cb)[1]; |
| 6581 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6582 | |
| 6583 | nla_nest_end(skb, data); |
| 6584 | genlmsg_end(skb, hdr); |
| 6585 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6586 | } |
| 6587 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6588 | #endif |
| 6589 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6590 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6591 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6593 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6594 | struct cfg80211_connect_params connect; |
| 6595 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6596 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6597 | int err; |
| 6598 | |
| 6599 | memset(&connect, 0, sizeof(connect)); |
| 6600 | |
| 6601 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6602 | return -EINVAL; |
| 6603 | |
| 6604 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6605 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6606 | return -EINVAL; |
| 6607 | |
| 6608 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6609 | connect.auth_type = |
| 6610 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6611 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6612 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6613 | return -EINVAL; |
| 6614 | } else |
| 6615 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6616 | |
| 6617 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6618 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6619 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6620 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6621 | if (err) |
| 6622 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6623 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6625 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6626 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6627 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6628 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6629 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6630 | connect.bg_scan_period = -1; |
| 6631 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6632 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6633 | connect.bg_scan_period = |
| 6634 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6635 | } |
| 6636 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6637 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6638 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6639 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6640 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6641 | |
| 6642 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6643 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6644 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6645 | } |
| 6646 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6647 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6648 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6649 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6650 | connect.mfp != NL80211_MFP_NO) |
| 6651 | return -EINVAL; |
| 6652 | } else { |
| 6653 | connect.mfp = NL80211_MFP_NO; |
| 6654 | } |
| 6655 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6656 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6657 | connect.channel = |
| 6658 | ieee80211_get_channel(wiphy, |
| 6659 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6660 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6661 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6662 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6665 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6666 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6667 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6668 | if (IS_ERR(connkeys)) |
| 6669 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6670 | } |
| 6671 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6672 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6673 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6674 | |
| 6675 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6676 | memcpy(&connect.ht_capa_mask, |
| 6677 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6678 | sizeof(connect.ht_capa_mask)); |
| 6679 | |
| 6680 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6681 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6682 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6683 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6684 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6685 | memcpy(&connect.ht_capa, |
| 6686 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6687 | sizeof(connect.ht_capa)); |
| 6688 | } |
| 6689 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6690 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6691 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6692 | |
| 6693 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6694 | memcpy(&connect.vht_capa_mask, |
| 6695 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6696 | sizeof(connect.vht_capa_mask)); |
| 6697 | |
| 6698 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6699 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6700 | kfree(connkeys); |
| 6701 | return -EINVAL; |
| 6702 | } |
| 6703 | memcpy(&connect.vht_capa, |
| 6704 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6705 | sizeof(connect.vht_capa)); |
| 6706 | } |
| 6707 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6708 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6709 | if (err) |
| 6710 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6711 | return err; |
| 6712 | } |
| 6713 | |
| 6714 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6715 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6717 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6718 | u16 reason; |
| 6719 | |
| 6720 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6721 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6722 | else |
| 6723 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6724 | |
| 6725 | if (reason == 0) |
| 6726 | return -EINVAL; |
| 6727 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6728 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6729 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6730 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6731 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6732 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6733 | } |
| 6734 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6735 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6738 | struct net *net; |
| 6739 | int err; |
| 6740 | u32 pid; |
| 6741 | |
| 6742 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6743 | return -EINVAL; |
| 6744 | |
| 6745 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6746 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6747 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6748 | if (IS_ERR(net)) |
| 6749 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6750 | |
| 6751 | err = 0; |
| 6752 | |
| 6753 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6754 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6755 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6756 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6757 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6758 | return err; |
| 6759 | } |
| 6760 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6761 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6762 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6764 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6765 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6766 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6767 | struct cfg80211_pmksa pmksa; |
| 6768 | |
| 6769 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6770 | |
| 6771 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6772 | return -EINVAL; |
| 6773 | |
| 6774 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6775 | return -EINVAL; |
| 6776 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6777 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6778 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6779 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6780 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6781 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6782 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6783 | |
| 6784 | switch (info->genlhdr->cmd) { |
| 6785 | case NL80211_CMD_SET_PMKSA: |
| 6786 | rdev_ops = rdev->ops->set_pmksa; |
| 6787 | break; |
| 6788 | case NL80211_CMD_DEL_PMKSA: |
| 6789 | rdev_ops = rdev->ops->del_pmksa; |
| 6790 | break; |
| 6791 | default: |
| 6792 | WARN_ON(1); |
| 6793 | break; |
| 6794 | } |
| 6795 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6796 | if (!rdev_ops) |
| 6797 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6799 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6800 | } |
| 6801 | |
| 6802 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6803 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6805 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6806 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6809 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6810 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6811 | if (!rdev->ops->flush_pmksa) |
| 6812 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6813 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6814 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6815 | } |
| 6816 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6817 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6818 | { |
| 6819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6820 | struct net_device *dev = info->user_ptr[1]; |
| 6821 | u8 action_code, dialog_token; |
| 6822 | u16 status_code; |
| 6823 | u8 *peer; |
| 6824 | |
| 6825 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6826 | !rdev->ops->tdls_mgmt) |
| 6827 | return -EOPNOTSUPP; |
| 6828 | |
| 6829 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6830 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6831 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6832 | !info->attrs[NL80211_ATTR_IE] || |
| 6833 | !info->attrs[NL80211_ATTR_MAC]) |
| 6834 | return -EINVAL; |
| 6835 | |
| 6836 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6837 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6838 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6839 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6840 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6841 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6842 | dialog_token, status_code, |
| 6843 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6844 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6848 | { |
| 6849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6850 | struct net_device *dev = info->user_ptr[1]; |
| 6851 | enum nl80211_tdls_operation operation; |
| 6852 | u8 *peer; |
| 6853 | |
| 6854 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6855 | !rdev->ops->tdls_oper) |
| 6856 | return -EOPNOTSUPP; |
| 6857 | |
| 6858 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6859 | !info->attrs[NL80211_ATTR_MAC]) |
| 6860 | return -EINVAL; |
| 6861 | |
| 6862 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6863 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6864 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6865 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6866 | } |
| 6867 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6868 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6869 | struct genl_info *info) |
| 6870 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6872 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6873 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6874 | struct sk_buff *msg; |
| 6875 | void *hdr; |
| 6876 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6877 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6878 | int err; |
| 6879 | |
| 6880 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6881 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6882 | return -EINVAL; |
| 6883 | |
| 6884 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6885 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6886 | if (!rdev->ops->remain_on_channel || |
| 6887 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6888 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6889 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6890 | /* |
| 6891 | * We should be on that channel for at least a minimum amount of |
| 6892 | * time (10ms) but no longer than the driver supports. |
| 6893 | */ |
| 6894 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6895 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6896 | return -EINVAL; |
| 6897 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6898 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6899 | if (err) |
| 6900 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6901 | |
| 6902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6903 | if (!msg) |
| 6904 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6905 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6906 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6907 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6908 | |
| 6909 | if (IS_ERR(hdr)) { |
| 6910 | err = PTR_ERR(hdr); |
| 6911 | goto free_msg; |
| 6912 | } |
| 6913 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6914 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6915 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6916 | |
| 6917 | if (err) |
| 6918 | goto free_msg; |
| 6919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6920 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6921 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6922 | |
| 6923 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6924 | |
| 6925 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6926 | |
| 6927 | nla_put_failure: |
| 6928 | err = -ENOBUFS; |
| 6929 | free_msg: |
| 6930 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6931 | return err; |
| 6932 | } |
| 6933 | |
| 6934 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6935 | struct genl_info *info) |
| 6936 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6938 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6939 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6940 | |
| 6941 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6942 | return -EINVAL; |
| 6943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6944 | if (!rdev->ops->cancel_remain_on_channel) |
| 6945 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6946 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6947 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6948 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6949 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6950 | } |
| 6951 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6952 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6953 | u8 *rates, u8 rates_len) |
| 6954 | { |
| 6955 | u8 i; |
| 6956 | u32 mask = 0; |
| 6957 | |
| 6958 | for (i = 0; i < rates_len; i++) { |
| 6959 | int rate = (rates[i] & 0x7f) * 5; |
| 6960 | int ridx; |
| 6961 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6962 | struct ieee80211_rate *srate = |
| 6963 | &sband->bitrates[ridx]; |
| 6964 | if (rate == srate->bitrate) { |
| 6965 | mask |= 1 << ridx; |
| 6966 | break; |
| 6967 | } |
| 6968 | } |
| 6969 | if (ridx == sband->n_bitrates) |
| 6970 | return 0; /* rate not found */ |
| 6971 | } |
| 6972 | |
| 6973 | return mask; |
| 6974 | } |
| 6975 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6976 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6977 | u8 *rates, u8 rates_len, |
| 6978 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6979 | { |
| 6980 | u8 i; |
| 6981 | |
| 6982 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6983 | |
| 6984 | for (i = 0; i < rates_len; i++) { |
| 6985 | int ridx, rbit; |
| 6986 | |
| 6987 | ridx = rates[i] / 8; |
| 6988 | rbit = BIT(rates[i] % 8); |
| 6989 | |
| 6990 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6991 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6992 | return false; |
| 6993 | |
| 6994 | /* check availability */ |
| 6995 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6996 | mcs[ridx] |= rbit; |
| 6997 | else |
| 6998 | return false; |
| 6999 | } |
| 7000 | |
| 7001 | return true; |
| 7002 | } |
| 7003 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7004 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7005 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7006 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7007 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7008 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7009 | }; |
| 7010 | |
| 7011 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7012 | struct genl_info *info) |
| 7013 | { |
| 7014 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7016 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7017 | int rem, i; |
| 7018 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7019 | struct nlattr *tx_rates; |
| 7020 | struct ieee80211_supported_band *sband; |
| 7021 | |
| 7022 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7023 | return -EINVAL; |
| 7024 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7025 | if (!rdev->ops->set_bitrate_mask) |
| 7026 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7027 | |
| 7028 | memset(&mask, 0, sizeof(mask)); |
| 7029 | /* Default to all rates enabled */ |
| 7030 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7031 | sband = rdev->wiphy.bands[i]; |
| 7032 | mask.control[i].legacy = |
| 7033 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7034 | if (sband) |
| 7035 | memcpy(mask.control[i].mcs, |
| 7036 | sband->ht_cap.mcs.rx_mask, |
| 7037 | sizeof(mask.control[i].mcs)); |
| 7038 | else |
| 7039 | memset(mask.control[i].mcs, 0, |
| 7040 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7041 | } |
| 7042 | |
| 7043 | /* |
| 7044 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7045 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7046 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7047 | 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] | 7048 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7049 | { |
| 7050 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7051 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7052 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7053 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7054 | if (sband == NULL) |
| 7055 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7056 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7057 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7058 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7059 | mask.control[band].legacy = rateset_to_mask( |
| 7060 | sband, |
| 7061 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7062 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7063 | if ((mask.control[band].legacy == 0) && |
| 7064 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7065 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7066 | } |
| 7067 | if (tb[NL80211_TXRATE_MCS]) { |
| 7068 | if (!ht_rateset_to_mask( |
| 7069 | sband, |
| 7070 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7071 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7072 | mask.control[band].mcs)) |
| 7073 | return -EINVAL; |
| 7074 | } |
| 7075 | |
| 7076 | if (mask.control[band].legacy == 0) { |
| 7077 | /* don't allow empty legacy rates if HT |
| 7078 | * is not even supported. */ |
| 7079 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7080 | return -EINVAL; |
| 7081 | |
| 7082 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7083 | if (mask.control[band].mcs[i]) |
| 7084 | break; |
| 7085 | |
| 7086 | /* legacy and mcs rates may not be both empty */ |
| 7087 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7088 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7089 | } |
| 7090 | } |
| 7091 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7092 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7093 | } |
| 7094 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7095 | 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] | 7096 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7098 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7099 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7100 | |
| 7101 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7102 | return -EINVAL; |
| 7103 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7104 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7105 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7106 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7107 | switch (wdev->iftype) { |
| 7108 | case NL80211_IFTYPE_STATION: |
| 7109 | case NL80211_IFTYPE_ADHOC: |
| 7110 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7111 | case NL80211_IFTYPE_AP: |
| 7112 | case NL80211_IFTYPE_AP_VLAN: |
| 7113 | case NL80211_IFTYPE_MESH_POINT: |
| 7114 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7115 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7116 | break; |
| 7117 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7118 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7119 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7120 | |
| 7121 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7122 | if (!rdev->ops->mgmt_tx) |
| 7123 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7124 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7125 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7126 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7127 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7128 | } |
| 7129 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7130 | 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] | 7131 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7133 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7134 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7135 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7136 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7137 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7138 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7139 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7140 | bool offchan, no_cck, dont_wait_for_ack; |
| 7141 | |
| 7142 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7143 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7144 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7145 | return -EINVAL; |
| 7146 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7147 | if (!rdev->ops->mgmt_tx) |
| 7148 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7149 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7150 | switch (wdev->iftype) { |
| 7151 | case NL80211_IFTYPE_STATION: |
| 7152 | case NL80211_IFTYPE_ADHOC: |
| 7153 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7154 | case NL80211_IFTYPE_AP: |
| 7155 | case NL80211_IFTYPE_AP_VLAN: |
| 7156 | case NL80211_IFTYPE_MESH_POINT: |
| 7157 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7158 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7159 | break; |
| 7160 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7161 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7162 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7163 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7164 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7165 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7166 | return -EINVAL; |
| 7167 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7168 | |
| 7169 | /* |
| 7170 | * We should wait on the channel for at least a minimum amount |
| 7171 | * of time (10ms) but no longer than the driver supports. |
| 7172 | */ |
| 7173 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7174 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7175 | return -EINVAL; |
| 7176 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7177 | } |
| 7178 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7179 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7180 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7181 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7182 | return -EINVAL; |
| 7183 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7184 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7185 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7186 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7187 | if (err) |
| 7188 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7189 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7190 | if (!dont_wait_for_ack) { |
| 7191 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7192 | if (!msg) |
| 7193 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7194 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7195 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7196 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7197 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7198 | if (IS_ERR(hdr)) { |
| 7199 | err = PTR_ERR(hdr); |
| 7200 | goto free_msg; |
| 7201 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7202 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7203 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7204 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7205 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7206 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7207 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7208 | if (err) |
| 7209 | goto free_msg; |
| 7210 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7211 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7212 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7213 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7214 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7215 | genlmsg_end(msg, hdr); |
| 7216 | return genlmsg_reply(msg, info); |
| 7217 | } |
| 7218 | |
| 7219 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7220 | |
| 7221 | nla_put_failure: |
| 7222 | err = -ENOBUFS; |
| 7223 | free_msg: |
| 7224 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7225 | return err; |
| 7226 | } |
| 7227 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7228 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7229 | { |
| 7230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7231 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7232 | u64 cookie; |
| 7233 | |
| 7234 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7235 | return -EINVAL; |
| 7236 | |
| 7237 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7238 | return -EOPNOTSUPP; |
| 7239 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7240 | switch (wdev->iftype) { |
| 7241 | case NL80211_IFTYPE_STATION: |
| 7242 | case NL80211_IFTYPE_ADHOC: |
| 7243 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7244 | case NL80211_IFTYPE_AP: |
| 7245 | case NL80211_IFTYPE_AP_VLAN: |
| 7246 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7247 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7248 | break; |
| 7249 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7250 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7251 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7252 | |
| 7253 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7254 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7255 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7256 | } |
| 7257 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7258 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7259 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7261 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7262 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7263 | u8 ps_state; |
| 7264 | bool state; |
| 7265 | int err; |
| 7266 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7267 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7268 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7269 | |
| 7270 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7272 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7273 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7274 | |
| 7275 | wdev = dev->ieee80211_ptr; |
| 7276 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7277 | if (!rdev->ops->set_power_mgmt) |
| 7278 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7279 | |
| 7280 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7281 | |
| 7282 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7283 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7284 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7285 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7286 | if (!err) |
| 7287 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7288 | return err; |
| 7289 | } |
| 7290 | |
| 7291 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7292 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7294 | enum nl80211_ps_state ps_state; |
| 7295 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7296 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7297 | struct sk_buff *msg; |
| 7298 | void *hdr; |
| 7299 | int err; |
| 7300 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7301 | wdev = dev->ieee80211_ptr; |
| 7302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7303 | if (!rdev->ops->set_power_mgmt) |
| 7304 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7305 | |
| 7306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7307 | if (!msg) |
| 7308 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7309 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7310 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | NL80211_CMD_GET_POWER_SAVE); |
| 7312 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7313 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7314 | goto free_msg; |
| 7315 | } |
| 7316 | |
| 7317 | if (wdev->ps) |
| 7318 | ps_state = NL80211_PS_ENABLED; |
| 7319 | else |
| 7320 | ps_state = NL80211_PS_DISABLED; |
| 7321 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7322 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7323 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7324 | |
| 7325 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7326 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7327 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7328 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7329 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7330 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7331 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7332 | return err; |
| 7333 | } |
| 7334 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7335 | static struct nla_policy |
| 7336 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7337 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7338 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7339 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7340 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7341 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7342 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7343 | }; |
| 7344 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7345 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7346 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7347 | { |
| 7348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7349 | struct wireless_dev *wdev; |
| 7350 | struct net_device *dev = info->user_ptr[1]; |
| 7351 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7352 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7353 | return -EINVAL; |
| 7354 | |
| 7355 | wdev = dev->ieee80211_ptr; |
| 7356 | |
| 7357 | if (!rdev->ops->set_cqm_txe_config) |
| 7358 | return -EOPNOTSUPP; |
| 7359 | |
| 7360 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7361 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7362 | return -EOPNOTSUPP; |
| 7363 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7364 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7365 | } |
| 7366 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7367 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7368 | s32 threshold, u32 hysteresis) |
| 7369 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7371 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7372 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7373 | |
| 7374 | if (threshold > 0) |
| 7375 | return -EINVAL; |
| 7376 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7377 | wdev = dev->ieee80211_ptr; |
| 7378 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7379 | if (!rdev->ops->set_cqm_rssi_config) |
| 7380 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7381 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7382 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7383 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7384 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7385 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7386 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7390 | { |
| 7391 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7392 | struct nlattr *cqm; |
| 7393 | int err; |
| 7394 | |
| 7395 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7396 | if (!cqm) { |
| 7397 | err = -EINVAL; |
| 7398 | goto out; |
| 7399 | } |
| 7400 | |
| 7401 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7402 | nl80211_attr_cqm_policy); |
| 7403 | if (err) |
| 7404 | goto out; |
| 7405 | |
| 7406 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7407 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7408 | s32 threshold; |
| 7409 | u32 hysteresis; |
| 7410 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7411 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7412 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7413 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7414 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7415 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7416 | u32 rate, pkts, intvl; |
| 7417 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7418 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7419 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7420 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7421 | } else |
| 7422 | err = -EINVAL; |
| 7423 | |
| 7424 | out: |
| 7425 | return err; |
| 7426 | } |
| 7427 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7428 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7429 | { |
| 7430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7431 | struct net_device *dev = info->user_ptr[1]; |
| 7432 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7433 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7434 | int err; |
| 7435 | |
| 7436 | /* start with default */ |
| 7437 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7438 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7439 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7440 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7441 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7442 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7443 | if (err) |
| 7444 | return err; |
| 7445 | } |
| 7446 | |
| 7447 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7448 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7449 | return -EINVAL; |
| 7450 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7451 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7452 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7453 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7454 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7455 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7456 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7457 | return -EINVAL; |
| 7458 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7459 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7460 | setup.beacon_interval = |
| 7461 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7462 | if (setup.beacon_interval < 10 || |
| 7463 | setup.beacon_interval > 10000) |
| 7464 | return -EINVAL; |
| 7465 | } |
| 7466 | |
| 7467 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7468 | setup.dtim_period = |
| 7469 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7470 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7471 | return -EINVAL; |
| 7472 | } |
| 7473 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7474 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7475 | /* parse additional setup parameters if given */ |
| 7476 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7477 | if (err) |
| 7478 | return err; |
| 7479 | } |
| 7480 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7481 | if (setup.user_mpm) |
| 7482 | cfg.auto_open_plinks = false; |
| 7483 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7484 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7485 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7486 | if (err) |
| 7487 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7488 | } else { |
| 7489 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7490 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7491 | } |
| 7492 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7493 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7497 | { |
| 7498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7499 | struct net_device *dev = info->user_ptr[1]; |
| 7500 | |
| 7501 | return cfg80211_leave_mesh(rdev, dev); |
| 7502 | } |
| 7503 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7504 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7505 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7506 | struct cfg80211_registered_device *rdev) |
| 7507 | { |
| 7508 | struct nlattr *nl_pats, *nl_pat; |
| 7509 | int i, pat_len; |
| 7510 | |
| 7511 | if (!rdev->wowlan->n_patterns) |
| 7512 | return 0; |
| 7513 | |
| 7514 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7515 | if (!nl_pats) |
| 7516 | return -ENOBUFS; |
| 7517 | |
| 7518 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7519 | nl_pat = nla_nest_start(msg, i + 1); |
| 7520 | if (!nl_pat) |
| 7521 | return -ENOBUFS; |
| 7522 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7523 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7524 | DIV_ROUND_UP(pat_len, 8), |
| 7525 | rdev->wowlan->patterns[i].mask) || |
| 7526 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7527 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7528 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7529 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7530 | return -ENOBUFS; |
| 7531 | nla_nest_end(msg, nl_pat); |
| 7532 | } |
| 7533 | nla_nest_end(msg, nl_pats); |
| 7534 | |
| 7535 | return 0; |
| 7536 | } |
| 7537 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7538 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7539 | struct cfg80211_wowlan_tcp *tcp) |
| 7540 | { |
| 7541 | struct nlattr *nl_tcp; |
| 7542 | |
| 7543 | if (!tcp) |
| 7544 | return 0; |
| 7545 | |
| 7546 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7547 | if (!nl_tcp) |
| 7548 | return -ENOBUFS; |
| 7549 | |
| 7550 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7551 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7552 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7553 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7554 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7555 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7556 | tcp->payload_len, tcp->payload) || |
| 7557 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7558 | tcp->data_interval) || |
| 7559 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7560 | tcp->wake_len, tcp->wake_data) || |
| 7561 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7562 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7563 | return -ENOBUFS; |
| 7564 | |
| 7565 | if (tcp->payload_seq.len && |
| 7566 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7567 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7568 | return -ENOBUFS; |
| 7569 | |
| 7570 | if (tcp->payload_tok.len && |
| 7571 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7572 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7573 | &tcp->payload_tok)) |
| 7574 | return -ENOBUFS; |
| 7575 | |
| 7576 | return 0; |
| 7577 | } |
| 7578 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7579 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7580 | { |
| 7581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7582 | struct sk_buff *msg; |
| 7583 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7584 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7585 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7586 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7587 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7588 | return -EOPNOTSUPP; |
| 7589 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7590 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7591 | /* adjust size to have room for all the data */ |
| 7592 | size += rdev->wowlan->tcp->tokens_size + |
| 7593 | rdev->wowlan->tcp->payload_len + |
| 7594 | rdev->wowlan->tcp->wake_len + |
| 7595 | rdev->wowlan->tcp->wake_len / 8; |
| 7596 | } |
| 7597 | |
| 7598 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7599 | if (!msg) |
| 7600 | return -ENOMEM; |
| 7601 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7602 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7603 | NL80211_CMD_GET_WOWLAN); |
| 7604 | if (!hdr) |
| 7605 | goto nla_put_failure; |
| 7606 | |
| 7607 | if (rdev->wowlan) { |
| 7608 | struct nlattr *nl_wowlan; |
| 7609 | |
| 7610 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7611 | if (!nl_wowlan) |
| 7612 | goto nla_put_failure; |
| 7613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7614 | if ((rdev->wowlan->any && |
| 7615 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7616 | (rdev->wowlan->disconnect && |
| 7617 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7618 | (rdev->wowlan->magic_pkt && |
| 7619 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7620 | (rdev->wowlan->gtk_rekey_failure && |
| 7621 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7622 | (rdev->wowlan->eap_identity_req && |
| 7623 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7624 | (rdev->wowlan->four_way_handshake && |
| 7625 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7626 | (rdev->wowlan->rfkill_release && |
| 7627 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7628 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7629 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7630 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7631 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7632 | |
| 7633 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7634 | goto nla_put_failure; |
| 7635 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7636 | nla_nest_end(msg, nl_wowlan); |
| 7637 | } |
| 7638 | |
| 7639 | genlmsg_end(msg, hdr); |
| 7640 | return genlmsg_reply(msg, info); |
| 7641 | |
| 7642 | nla_put_failure: |
| 7643 | nlmsg_free(msg); |
| 7644 | return -ENOBUFS; |
| 7645 | } |
| 7646 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7647 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7648 | struct nlattr *attr, |
| 7649 | struct cfg80211_wowlan *trig) |
| 7650 | { |
| 7651 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7652 | struct cfg80211_wowlan_tcp *cfg; |
| 7653 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7654 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7655 | u32 size; |
| 7656 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7657 | int err, port; |
| 7658 | |
| 7659 | if (!rdev->wiphy.wowlan.tcp) |
| 7660 | return -EINVAL; |
| 7661 | |
| 7662 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7663 | nla_data(attr), nla_len(attr), |
| 7664 | nl80211_wowlan_tcp_policy); |
| 7665 | if (err) |
| 7666 | return err; |
| 7667 | |
| 7668 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7669 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7670 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7671 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7672 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7673 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7674 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7675 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7676 | return -EINVAL; |
| 7677 | |
| 7678 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7679 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7680 | return -EINVAL; |
| 7681 | |
| 7682 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7683 | rdev->wiphy.wowlan.tcp->data_interval_max || |
| 7684 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7685 | return -EINVAL; |
| 7686 | |
| 7687 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7688 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7689 | return -EINVAL; |
| 7690 | |
| 7691 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7692 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7693 | return -EINVAL; |
| 7694 | |
| 7695 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7696 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7697 | |
| 7698 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7699 | tokens_size = tokln - sizeof(*tok); |
| 7700 | |
| 7701 | if (!tok->len || tokens_size % tok->len) |
| 7702 | return -EINVAL; |
| 7703 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7704 | return -EINVAL; |
| 7705 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7706 | return -EINVAL; |
| 7707 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7708 | return -EINVAL; |
| 7709 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7710 | return -EINVAL; |
| 7711 | if (tok->offset + tok->len > data_size) |
| 7712 | return -EINVAL; |
| 7713 | } |
| 7714 | |
| 7715 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7716 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7717 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7718 | return -EINVAL; |
| 7719 | if (seq->len == 0 || seq->len > 4) |
| 7720 | return -EINVAL; |
| 7721 | if (seq->len + seq->offset > data_size) |
| 7722 | return -EINVAL; |
| 7723 | } |
| 7724 | |
| 7725 | size = sizeof(*cfg); |
| 7726 | size += data_size; |
| 7727 | size += wake_size + wake_mask_size; |
| 7728 | size += tokens_size; |
| 7729 | |
| 7730 | cfg = kzalloc(size, GFP_KERNEL); |
| 7731 | if (!cfg) |
| 7732 | return -ENOMEM; |
| 7733 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7734 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7735 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7736 | ETH_ALEN); |
| 7737 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7738 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7739 | else |
| 7740 | port = 0; |
| 7741 | #ifdef CONFIG_INET |
| 7742 | /* allocate a socket and port for it and use it */ |
| 7743 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7744 | IPPROTO_TCP, &cfg->sock, 1); |
| 7745 | if (err) { |
| 7746 | kfree(cfg); |
| 7747 | return err; |
| 7748 | } |
| 7749 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7750 | sock_release(cfg->sock); |
| 7751 | kfree(cfg); |
| 7752 | return -EADDRINUSE; |
| 7753 | } |
| 7754 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7755 | #else |
| 7756 | if (!port) { |
| 7757 | kfree(cfg); |
| 7758 | return -EINVAL; |
| 7759 | } |
| 7760 | cfg->src_port = port; |
| 7761 | #endif |
| 7762 | |
| 7763 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7764 | cfg->payload_len = data_size; |
| 7765 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7766 | memcpy((void *)cfg->payload, |
| 7767 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7768 | data_size); |
| 7769 | if (seq) |
| 7770 | cfg->payload_seq = *seq; |
| 7771 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7772 | cfg->wake_len = wake_size; |
| 7773 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7774 | memcpy((void *)cfg->wake_data, |
| 7775 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7776 | wake_size); |
| 7777 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7778 | data_size + wake_size; |
| 7779 | memcpy((void *)cfg->wake_mask, |
| 7780 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7781 | wake_mask_size); |
| 7782 | if (tok) { |
| 7783 | cfg->tokens_size = tokens_size; |
| 7784 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7785 | } |
| 7786 | |
| 7787 | trig->tcp = cfg; |
| 7788 | |
| 7789 | return 0; |
| 7790 | } |
| 7791 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7792 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7793 | { |
| 7794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7795 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7796 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7797 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7798 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7799 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7800 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7801 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7802 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7803 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7804 | return -EOPNOTSUPP; |
| 7805 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7806 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7807 | cfg80211_rdev_free_wowlan(rdev); |
| 7808 | rdev->wowlan = NULL; |
| 7809 | goto set_wakeup; |
| 7810 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7811 | |
| 7812 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7813 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7814 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7815 | nl80211_wowlan_policy); |
| 7816 | if (err) |
| 7817 | return err; |
| 7818 | |
| 7819 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7820 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7821 | return -EINVAL; |
| 7822 | new_triggers.any = true; |
| 7823 | } |
| 7824 | |
| 7825 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7826 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7827 | return -EINVAL; |
| 7828 | new_triggers.disconnect = true; |
| 7829 | } |
| 7830 | |
| 7831 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7832 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7833 | return -EINVAL; |
| 7834 | new_triggers.magic_pkt = true; |
| 7835 | } |
| 7836 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7837 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7838 | return -EINVAL; |
| 7839 | |
| 7840 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7841 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7842 | return -EINVAL; |
| 7843 | new_triggers.gtk_rekey_failure = true; |
| 7844 | } |
| 7845 | |
| 7846 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7847 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7848 | return -EINVAL; |
| 7849 | new_triggers.eap_identity_req = true; |
| 7850 | } |
| 7851 | |
| 7852 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7853 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7854 | return -EINVAL; |
| 7855 | new_triggers.four_way_handshake = true; |
| 7856 | } |
| 7857 | |
| 7858 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7859 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7860 | return -EINVAL; |
| 7861 | new_triggers.rfkill_release = true; |
| 7862 | } |
| 7863 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7864 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7865 | struct nlattr *pat; |
| 7866 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7867 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7868 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7869 | |
| 7870 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7871 | rem) |
| 7872 | n_patterns++; |
| 7873 | if (n_patterns > wowlan->n_patterns) |
| 7874 | return -EINVAL; |
| 7875 | |
| 7876 | new_triggers.patterns = kcalloc(n_patterns, |
| 7877 | sizeof(new_triggers.patterns[0]), |
| 7878 | GFP_KERNEL); |
| 7879 | if (!new_triggers.patterns) |
| 7880 | return -ENOMEM; |
| 7881 | |
| 7882 | new_triggers.n_patterns = n_patterns; |
| 7883 | i = 0; |
| 7884 | |
| 7885 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7886 | rem) { |
| 7887 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7888 | nla_data(pat), nla_len(pat), NULL); |
| 7889 | err = -EINVAL; |
| 7890 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7891 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7892 | goto error; |
| 7893 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7894 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7895 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7896 | mask_len) |
| 7897 | goto error; |
| 7898 | if (pat_len > wowlan->pattern_max_len || |
| 7899 | pat_len < wowlan->pattern_min_len) |
| 7900 | goto error; |
| 7901 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7902 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7903 | pkt_offset = 0; |
| 7904 | else |
| 7905 | pkt_offset = nla_get_u32( |
| 7906 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7907 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7908 | goto error; |
| 7909 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7910 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7911 | new_triggers.patterns[i].mask = |
| 7912 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7913 | if (!new_triggers.patterns[i].mask) { |
| 7914 | err = -ENOMEM; |
| 7915 | goto error; |
| 7916 | } |
| 7917 | new_triggers.patterns[i].pattern = |
| 7918 | new_triggers.patterns[i].mask + mask_len; |
| 7919 | memcpy(new_triggers.patterns[i].mask, |
| 7920 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7921 | mask_len); |
| 7922 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7923 | memcpy(new_triggers.patterns[i].pattern, |
| 7924 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7925 | pat_len); |
| 7926 | i++; |
| 7927 | } |
| 7928 | } |
| 7929 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7930 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7931 | err = nl80211_parse_wowlan_tcp( |
| 7932 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7933 | &new_triggers); |
| 7934 | if (err) |
| 7935 | goto error; |
| 7936 | } |
| 7937 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7938 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7939 | if (!ntrig) { |
| 7940 | err = -ENOMEM; |
| 7941 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7942 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7943 | cfg80211_rdev_free_wowlan(rdev); |
| 7944 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7945 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7946 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7947 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7948 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7949 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7950 | return 0; |
| 7951 | error: |
| 7952 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7953 | kfree(new_triggers.patterns[i].mask); |
| 7954 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7955 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7956 | sock_release(new_triggers.tcp->sock); |
| 7957 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7958 | return err; |
| 7959 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7960 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7961 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7962 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7963 | { |
| 7964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7965 | struct net_device *dev = info->user_ptr[1]; |
| 7966 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7967 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7968 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7969 | int err; |
| 7970 | |
| 7971 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7972 | return -EINVAL; |
| 7973 | |
| 7974 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7975 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7976 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7977 | nl80211_rekey_policy); |
| 7978 | if (err) |
| 7979 | return err; |
| 7980 | |
| 7981 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7982 | return -ERANGE; |
| 7983 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7984 | return -ERANGE; |
| 7985 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7986 | return -ERANGE; |
| 7987 | |
| 7988 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7989 | NL80211_KEK_LEN); |
| 7990 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7991 | NL80211_KCK_LEN); |
| 7992 | memcpy(rekey_data.replay_ctr, |
| 7993 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7994 | NL80211_REPLAY_CTR_LEN); |
| 7995 | |
| 7996 | wdev_lock(wdev); |
| 7997 | if (!wdev->current_bss) { |
| 7998 | err = -ENOTCONN; |
| 7999 | goto out; |
| 8000 | } |
| 8001 | |
| 8002 | if (!rdev->ops->set_rekey_data) { |
| 8003 | err = -EOPNOTSUPP; |
| 8004 | goto out; |
| 8005 | } |
| 8006 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8007 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8008 | out: |
| 8009 | wdev_unlock(wdev); |
| 8010 | return err; |
| 8011 | } |
| 8012 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8013 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8014 | struct genl_info *info) |
| 8015 | { |
| 8016 | struct net_device *dev = info->user_ptr[1]; |
| 8017 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8018 | |
| 8019 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8020 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8021 | return -EINVAL; |
| 8022 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8023 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8024 | return -EBUSY; |
| 8025 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8026 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8027 | return 0; |
| 8028 | } |
| 8029 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8030 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8031 | struct genl_info *info) |
| 8032 | { |
| 8033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8034 | struct net_device *dev = info->user_ptr[1]; |
| 8035 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8036 | struct sk_buff *msg; |
| 8037 | void *hdr; |
| 8038 | const u8 *addr; |
| 8039 | u64 cookie; |
| 8040 | int err; |
| 8041 | |
| 8042 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8043 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8044 | return -EOPNOTSUPP; |
| 8045 | |
| 8046 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8047 | return -EINVAL; |
| 8048 | |
| 8049 | if (!rdev->ops->probe_client) |
| 8050 | return -EOPNOTSUPP; |
| 8051 | |
| 8052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8053 | if (!msg) |
| 8054 | return -ENOMEM; |
| 8055 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8056 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8057 | NL80211_CMD_PROBE_CLIENT); |
| 8058 | |
| 8059 | if (IS_ERR(hdr)) { |
| 8060 | err = PTR_ERR(hdr); |
| 8061 | goto free_msg; |
| 8062 | } |
| 8063 | |
| 8064 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8065 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8066 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8067 | if (err) |
| 8068 | goto free_msg; |
| 8069 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8070 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8071 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8072 | |
| 8073 | genlmsg_end(msg, hdr); |
| 8074 | |
| 8075 | return genlmsg_reply(msg, info); |
| 8076 | |
| 8077 | nla_put_failure: |
| 8078 | err = -ENOBUFS; |
| 8079 | free_msg: |
| 8080 | nlmsg_free(msg); |
| 8081 | return err; |
| 8082 | } |
| 8083 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8084 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8085 | { |
| 8086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8087 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8088 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8089 | |
| 8090 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8091 | return -EOPNOTSUPP; |
| 8092 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8093 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8094 | if (!nreg) |
| 8095 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8096 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8097 | /* First, check if already registered. */ |
| 8098 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8099 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8100 | if (reg->nlportid == info->snd_portid) { |
| 8101 | rv = -EALREADY; |
| 8102 | goto out_err; |
| 8103 | } |
| 8104 | } |
| 8105 | /* Add it to the list */ |
| 8106 | nreg->nlportid = info->snd_portid; |
| 8107 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8108 | |
| 8109 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8110 | |
| 8111 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8112 | out_err: |
| 8113 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8114 | kfree(nreg); |
| 8115 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8116 | } |
| 8117 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8118 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8119 | { |
| 8120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8121 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8122 | int err; |
| 8123 | |
| 8124 | if (!rdev->ops->start_p2p_device) |
| 8125 | return -EOPNOTSUPP; |
| 8126 | |
| 8127 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8128 | return -EOPNOTSUPP; |
| 8129 | |
| 8130 | if (wdev->p2p_started) |
| 8131 | return 0; |
| 8132 | |
| 8133 | mutex_lock(&rdev->devlist_mtx); |
| 8134 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 8135 | mutex_unlock(&rdev->devlist_mtx); |
| 8136 | if (err) |
| 8137 | return err; |
| 8138 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8139 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8140 | if (err) |
| 8141 | return err; |
| 8142 | |
| 8143 | wdev->p2p_started = true; |
| 8144 | mutex_lock(&rdev->devlist_mtx); |
| 8145 | rdev->opencount++; |
| 8146 | mutex_unlock(&rdev->devlist_mtx); |
| 8147 | |
| 8148 | return 0; |
| 8149 | } |
| 8150 | |
| 8151 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8152 | { |
| 8153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8154 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8155 | |
| 8156 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8157 | return -EOPNOTSUPP; |
| 8158 | |
| 8159 | if (!rdev->ops->stop_p2p_device) |
| 8160 | return -EOPNOTSUPP; |
| 8161 | |
Johannes Berg | 65e8d5b | 2013-04-19 12:18:19 +0200 | [diff] [blame^] | 8162 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8163 | mutex_lock(&rdev->sched_scan_mtx); |
| 8164 | cfg80211_stop_p2p_device(rdev, wdev); |
| 8165 | mutex_unlock(&rdev->sched_scan_mtx); |
Johannes Berg | 65e8d5b | 2013-04-19 12:18:19 +0200 | [diff] [blame^] | 8166 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8167 | |
| 8168 | return 0; |
| 8169 | } |
| 8170 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8171 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8172 | struct genl_info *info) |
| 8173 | { |
| 8174 | void *hdr; |
| 8175 | struct sk_buff *msg; |
| 8176 | |
| 8177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8178 | if (!msg) |
| 8179 | return -ENOMEM; |
| 8180 | |
| 8181 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8182 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8183 | if (!hdr) |
| 8184 | goto nla_put_failure; |
| 8185 | |
| 8186 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8187 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8188 | goto nla_put_failure; |
| 8189 | |
| 8190 | genlmsg_end(msg, hdr); |
| 8191 | return genlmsg_reply(msg, info); |
| 8192 | |
| 8193 | nla_put_failure: |
| 8194 | kfree_skb(msg); |
| 8195 | return -ENOBUFS; |
| 8196 | } |
| 8197 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8198 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8199 | { |
| 8200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8201 | struct cfg80211_update_ft_ies_params ft_params; |
| 8202 | struct net_device *dev = info->user_ptr[1]; |
| 8203 | |
| 8204 | if (!rdev->ops->update_ft_ies) |
| 8205 | return -EOPNOTSUPP; |
| 8206 | |
| 8207 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8208 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8209 | return -EINVAL; |
| 8210 | |
| 8211 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8212 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8213 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8214 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8215 | |
| 8216 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8217 | } |
| 8218 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8219 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8220 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8221 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8222 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8223 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8224 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8225 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8226 | /* 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] | 8227 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8228 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8229 | |
| 8230 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8231 | struct genl_info *info) |
| 8232 | { |
| 8233 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8234 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8235 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8236 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8237 | |
| 8238 | if (rtnl) |
| 8239 | rtnl_lock(); |
| 8240 | |
| 8241 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8242 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8243 | if (IS_ERR(rdev)) { |
| 8244 | if (rtnl) |
| 8245 | rtnl_unlock(); |
| 8246 | return PTR_ERR(rdev); |
| 8247 | } |
| 8248 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8249 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8250 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8251 | mutex_lock(&cfg80211_mutex); |
| 8252 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8253 | info->attrs); |
| 8254 | if (IS_ERR(wdev)) { |
| 8255 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8256 | if (rtnl) |
| 8257 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8258 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8259 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8260 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8261 | dev = wdev->netdev; |
| 8262 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8263 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8264 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8265 | if (!dev) { |
| 8266 | mutex_unlock(&cfg80211_mutex); |
| 8267 | if (rtnl) |
| 8268 | rtnl_unlock(); |
| 8269 | return -EINVAL; |
| 8270 | } |
| 8271 | |
| 8272 | info->user_ptr[1] = dev; |
| 8273 | } else { |
| 8274 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8275 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8276 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8277 | if (dev) { |
| 8278 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8279 | !netif_running(dev)) { |
| 8280 | mutex_unlock(&cfg80211_mutex); |
| 8281 | if (rtnl) |
| 8282 | rtnl_unlock(); |
| 8283 | return -ENETDOWN; |
| 8284 | } |
| 8285 | |
| 8286 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8287 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8288 | if (!wdev->p2p_started) { |
| 8289 | mutex_unlock(&cfg80211_mutex); |
| 8290 | if (rtnl) |
| 8291 | rtnl_unlock(); |
| 8292 | return -ENETDOWN; |
| 8293 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8294 | } |
| 8295 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8296 | cfg80211_lock_rdev(rdev); |
| 8297 | |
| 8298 | mutex_unlock(&cfg80211_mutex); |
| 8299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8300 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8301 | } |
| 8302 | |
| 8303 | return 0; |
| 8304 | } |
| 8305 | |
| 8306 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8307 | struct genl_info *info) |
| 8308 | { |
| 8309 | if (info->user_ptr[0]) |
| 8310 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8311 | if (info->user_ptr[1]) { |
| 8312 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8313 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8314 | |
| 8315 | if (wdev->netdev) |
| 8316 | dev_put(wdev->netdev); |
| 8317 | } else { |
| 8318 | dev_put(info->user_ptr[1]); |
| 8319 | } |
| 8320 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8321 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8322 | rtnl_unlock(); |
| 8323 | } |
| 8324 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8325 | static struct genl_ops nl80211_ops[] = { |
| 8326 | { |
| 8327 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8328 | .doit = nl80211_get_wiphy, |
| 8329 | .dumpit = nl80211_dump_wiphy, |
| 8330 | .policy = nl80211_policy, |
| 8331 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8332 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8333 | }, |
| 8334 | { |
| 8335 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8336 | .doit = nl80211_set_wiphy, |
| 8337 | .policy = nl80211_policy, |
| 8338 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8339 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8340 | }, |
| 8341 | { |
| 8342 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8343 | .doit = nl80211_get_interface, |
| 8344 | .dumpit = nl80211_dump_interface, |
| 8345 | .policy = nl80211_policy, |
| 8346 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 8347 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8348 | }, |
| 8349 | { |
| 8350 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8351 | .doit = nl80211_set_interface, |
| 8352 | .policy = nl80211_policy, |
| 8353 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8354 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8355 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8356 | }, |
| 8357 | { |
| 8358 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8359 | .doit = nl80211_new_interface, |
| 8360 | .policy = nl80211_policy, |
| 8361 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8362 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8363 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8364 | }, |
| 8365 | { |
| 8366 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8367 | .doit = nl80211_del_interface, |
| 8368 | .policy = nl80211_policy, |
| 8369 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8370 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8371 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8372 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8373 | { |
| 8374 | .cmd = NL80211_CMD_GET_KEY, |
| 8375 | .doit = nl80211_get_key, |
| 8376 | .policy = nl80211_policy, |
| 8377 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8378 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8379 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8380 | }, |
| 8381 | { |
| 8382 | .cmd = NL80211_CMD_SET_KEY, |
| 8383 | .doit = nl80211_set_key, |
| 8384 | .policy = nl80211_policy, |
| 8385 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8386 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8387 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8388 | }, |
| 8389 | { |
| 8390 | .cmd = NL80211_CMD_NEW_KEY, |
| 8391 | .doit = nl80211_new_key, |
| 8392 | .policy = nl80211_policy, |
| 8393 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8395 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8396 | }, |
| 8397 | { |
| 8398 | .cmd = NL80211_CMD_DEL_KEY, |
| 8399 | .doit = nl80211_del_key, |
| 8400 | .policy = nl80211_policy, |
| 8401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8403 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8404 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8405 | { |
| 8406 | .cmd = NL80211_CMD_SET_BEACON, |
| 8407 | .policy = nl80211_policy, |
| 8408 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8409 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8411 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8412 | }, |
| 8413 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8414 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8415 | .policy = nl80211_policy, |
| 8416 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8417 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8419 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8420 | }, |
| 8421 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8422 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8423 | .policy = nl80211_policy, |
| 8424 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8425 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8427 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8428 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8429 | { |
| 8430 | .cmd = NL80211_CMD_GET_STATION, |
| 8431 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8432 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8433 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8434 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8435 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8436 | }, |
| 8437 | { |
| 8438 | .cmd = NL80211_CMD_SET_STATION, |
| 8439 | .doit = nl80211_set_station, |
| 8440 | .policy = nl80211_policy, |
| 8441 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8443 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8444 | }, |
| 8445 | { |
| 8446 | .cmd = NL80211_CMD_NEW_STATION, |
| 8447 | .doit = nl80211_new_station, |
| 8448 | .policy = nl80211_policy, |
| 8449 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8451 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8452 | }, |
| 8453 | { |
| 8454 | .cmd = NL80211_CMD_DEL_STATION, |
| 8455 | .doit = nl80211_del_station, |
| 8456 | .policy = nl80211_policy, |
| 8457 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8459 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8460 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8461 | { |
| 8462 | .cmd = NL80211_CMD_GET_MPATH, |
| 8463 | .doit = nl80211_get_mpath, |
| 8464 | .dumpit = nl80211_dump_mpath, |
| 8465 | .policy = nl80211_policy, |
| 8466 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8468 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8469 | }, |
| 8470 | { |
| 8471 | .cmd = NL80211_CMD_SET_MPATH, |
| 8472 | .doit = nl80211_set_mpath, |
| 8473 | .policy = nl80211_policy, |
| 8474 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8476 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8477 | }, |
| 8478 | { |
| 8479 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8480 | .doit = nl80211_new_mpath, |
| 8481 | .policy = nl80211_policy, |
| 8482 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8484 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8485 | }, |
| 8486 | { |
| 8487 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8488 | .doit = nl80211_del_mpath, |
| 8489 | .policy = nl80211_policy, |
| 8490 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8492 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8493 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8494 | { |
| 8495 | .cmd = NL80211_CMD_SET_BSS, |
| 8496 | .doit = nl80211_set_bss, |
| 8497 | .policy = nl80211_policy, |
| 8498 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8500 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8501 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8502 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8503 | .cmd = NL80211_CMD_GET_REG, |
| 8504 | .doit = nl80211_get_reg, |
| 8505 | .policy = nl80211_policy, |
| 8506 | /* can be retrieved by unprivileged users */ |
| 8507 | }, |
| 8508 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8509 | .cmd = NL80211_CMD_SET_REG, |
| 8510 | .doit = nl80211_set_reg, |
| 8511 | .policy = nl80211_policy, |
| 8512 | .flags = GENL_ADMIN_PERM, |
| 8513 | }, |
| 8514 | { |
| 8515 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8516 | .doit = nl80211_req_set_reg, |
| 8517 | .policy = nl80211_policy, |
| 8518 | .flags = GENL_ADMIN_PERM, |
| 8519 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8520 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8521 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8522 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8523 | .policy = nl80211_policy, |
| 8524 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8526 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8527 | }, |
| 8528 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8529 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8530 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8531 | .policy = nl80211_policy, |
| 8532 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8534 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8535 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8536 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8537 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8538 | .doit = nl80211_trigger_scan, |
| 8539 | .policy = nl80211_policy, |
| 8540 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8541 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8542 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8543 | }, |
| 8544 | { |
| 8545 | .cmd = NL80211_CMD_GET_SCAN, |
| 8546 | .policy = nl80211_policy, |
| 8547 | .dumpit = nl80211_dump_scan, |
| 8548 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8549 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8550 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8551 | .doit = nl80211_start_sched_scan, |
| 8552 | .policy = nl80211_policy, |
| 8553 | .flags = GENL_ADMIN_PERM, |
| 8554 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8555 | NL80211_FLAG_NEED_RTNL, |
| 8556 | }, |
| 8557 | { |
| 8558 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8559 | .doit = nl80211_stop_sched_scan, |
| 8560 | .policy = nl80211_policy, |
| 8561 | .flags = GENL_ADMIN_PERM, |
| 8562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8563 | NL80211_FLAG_NEED_RTNL, |
| 8564 | }, |
| 8565 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8566 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8567 | .doit = nl80211_authenticate, |
| 8568 | .policy = nl80211_policy, |
| 8569 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8570 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8571 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8572 | }, |
| 8573 | { |
| 8574 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8575 | .doit = nl80211_associate, |
| 8576 | .policy = nl80211_policy, |
| 8577 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8579 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8580 | }, |
| 8581 | { |
| 8582 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8583 | .doit = nl80211_deauthenticate, |
| 8584 | .policy = nl80211_policy, |
| 8585 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8587 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8588 | }, |
| 8589 | { |
| 8590 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8591 | .doit = nl80211_disassociate, |
| 8592 | .policy = nl80211_policy, |
| 8593 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8595 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8596 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8597 | { |
| 8598 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8599 | .doit = nl80211_join_ibss, |
| 8600 | .policy = nl80211_policy, |
| 8601 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8603 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8604 | }, |
| 8605 | { |
| 8606 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8607 | .doit = nl80211_leave_ibss, |
| 8608 | .policy = nl80211_policy, |
| 8609 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8611 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8612 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8613 | #ifdef CONFIG_NL80211_TESTMODE |
| 8614 | { |
| 8615 | .cmd = NL80211_CMD_TESTMODE, |
| 8616 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8617 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8618 | .policy = nl80211_policy, |
| 8619 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8620 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8621 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8622 | }, |
| 8623 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8624 | { |
| 8625 | .cmd = NL80211_CMD_CONNECT, |
| 8626 | .doit = nl80211_connect, |
| 8627 | .policy = nl80211_policy, |
| 8628 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8629 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8630 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8631 | }, |
| 8632 | { |
| 8633 | .cmd = NL80211_CMD_DISCONNECT, |
| 8634 | .doit = nl80211_disconnect, |
| 8635 | .policy = nl80211_policy, |
| 8636 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8638 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8639 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8640 | { |
| 8641 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8642 | .doit = nl80211_wiphy_netns, |
| 8643 | .policy = nl80211_policy, |
| 8644 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8645 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8646 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8647 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8648 | { |
| 8649 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8650 | .policy = nl80211_policy, |
| 8651 | .dumpit = nl80211_dump_survey, |
| 8652 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8653 | { |
| 8654 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8655 | .doit = nl80211_setdel_pmksa, |
| 8656 | .policy = nl80211_policy, |
| 8657 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8658 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8659 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8660 | }, |
| 8661 | { |
| 8662 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8663 | .doit = nl80211_setdel_pmksa, |
| 8664 | .policy = nl80211_policy, |
| 8665 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8666 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8667 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8668 | }, |
| 8669 | { |
| 8670 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8671 | .doit = nl80211_flush_pmksa, |
| 8672 | .policy = nl80211_policy, |
| 8673 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8675 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8676 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8677 | { |
| 8678 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8679 | .doit = nl80211_remain_on_channel, |
| 8680 | .policy = nl80211_policy, |
| 8681 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8682 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8683 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8684 | }, |
| 8685 | { |
| 8686 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8687 | .doit = nl80211_cancel_remain_on_channel, |
| 8688 | .policy = nl80211_policy, |
| 8689 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8690 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8691 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8692 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8693 | { |
| 8694 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8695 | .doit = nl80211_set_tx_bitrate_mask, |
| 8696 | .policy = nl80211_policy, |
| 8697 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8698 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8699 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8700 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8701 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8702 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8703 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8704 | .policy = nl80211_policy, |
| 8705 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8706 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8707 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8708 | }, |
| 8709 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8710 | .cmd = NL80211_CMD_FRAME, |
| 8711 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8712 | .policy = nl80211_policy, |
| 8713 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8714 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8715 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8716 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8717 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8718 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8719 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8720 | .policy = nl80211_policy, |
| 8721 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8722 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8723 | NL80211_FLAG_NEED_RTNL, |
| 8724 | }, |
| 8725 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8726 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8727 | .doit = nl80211_set_power_save, |
| 8728 | .policy = nl80211_policy, |
| 8729 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8730 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8731 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8732 | }, |
| 8733 | { |
| 8734 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8735 | .doit = nl80211_get_power_save, |
| 8736 | .policy = nl80211_policy, |
| 8737 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8738 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8739 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8740 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8741 | { |
| 8742 | .cmd = NL80211_CMD_SET_CQM, |
| 8743 | .doit = nl80211_set_cqm, |
| 8744 | .policy = nl80211_policy, |
| 8745 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8746 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8747 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8748 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8749 | { |
| 8750 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8751 | .doit = nl80211_set_channel, |
| 8752 | .policy = nl80211_policy, |
| 8753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8754 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8755 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8756 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8757 | { |
| 8758 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8759 | .doit = nl80211_set_wds_peer, |
| 8760 | .policy = nl80211_policy, |
| 8761 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8762 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8763 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8764 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8765 | { |
| 8766 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8767 | .doit = nl80211_join_mesh, |
| 8768 | .policy = nl80211_policy, |
| 8769 | .flags = GENL_ADMIN_PERM, |
| 8770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8771 | NL80211_FLAG_NEED_RTNL, |
| 8772 | }, |
| 8773 | { |
| 8774 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8775 | .doit = nl80211_leave_mesh, |
| 8776 | .policy = nl80211_policy, |
| 8777 | .flags = GENL_ADMIN_PERM, |
| 8778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8779 | NL80211_FLAG_NEED_RTNL, |
| 8780 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8781 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8782 | { |
| 8783 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8784 | .doit = nl80211_get_wowlan, |
| 8785 | .policy = nl80211_policy, |
| 8786 | /* can be retrieved by unprivileged users */ |
| 8787 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8788 | NL80211_FLAG_NEED_RTNL, |
| 8789 | }, |
| 8790 | { |
| 8791 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8792 | .doit = nl80211_set_wowlan, |
| 8793 | .policy = nl80211_policy, |
| 8794 | .flags = GENL_ADMIN_PERM, |
| 8795 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8796 | NL80211_FLAG_NEED_RTNL, |
| 8797 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8798 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8799 | { |
| 8800 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8801 | .doit = nl80211_set_rekey_data, |
| 8802 | .policy = nl80211_policy, |
| 8803 | .flags = GENL_ADMIN_PERM, |
| 8804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8805 | NL80211_FLAG_NEED_RTNL, |
| 8806 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8807 | { |
| 8808 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8809 | .doit = nl80211_tdls_mgmt, |
| 8810 | .policy = nl80211_policy, |
| 8811 | .flags = GENL_ADMIN_PERM, |
| 8812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8813 | NL80211_FLAG_NEED_RTNL, |
| 8814 | }, |
| 8815 | { |
| 8816 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8817 | .doit = nl80211_tdls_oper, |
| 8818 | .policy = nl80211_policy, |
| 8819 | .flags = GENL_ADMIN_PERM, |
| 8820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8821 | NL80211_FLAG_NEED_RTNL, |
| 8822 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8823 | { |
| 8824 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8825 | .doit = nl80211_register_unexpected_frame, |
| 8826 | .policy = nl80211_policy, |
| 8827 | .flags = GENL_ADMIN_PERM, |
| 8828 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8829 | NL80211_FLAG_NEED_RTNL, |
| 8830 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8831 | { |
| 8832 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8833 | .doit = nl80211_probe_client, |
| 8834 | .policy = nl80211_policy, |
| 8835 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8837 | NL80211_FLAG_NEED_RTNL, |
| 8838 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8839 | { |
| 8840 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8841 | .doit = nl80211_register_beacons, |
| 8842 | .policy = nl80211_policy, |
| 8843 | .flags = GENL_ADMIN_PERM, |
| 8844 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8845 | NL80211_FLAG_NEED_RTNL, |
| 8846 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8847 | { |
| 8848 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8849 | .doit = nl80211_set_noack_map, |
| 8850 | .policy = nl80211_policy, |
| 8851 | .flags = GENL_ADMIN_PERM, |
| 8852 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8853 | NL80211_FLAG_NEED_RTNL, |
| 8854 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8855 | { |
| 8856 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8857 | .doit = nl80211_start_p2p_device, |
| 8858 | .policy = nl80211_policy, |
| 8859 | .flags = GENL_ADMIN_PERM, |
| 8860 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8861 | NL80211_FLAG_NEED_RTNL, |
| 8862 | }, |
| 8863 | { |
| 8864 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8865 | .doit = nl80211_stop_p2p_device, |
| 8866 | .policy = nl80211_policy, |
| 8867 | .flags = GENL_ADMIN_PERM, |
| 8868 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8869 | NL80211_FLAG_NEED_RTNL, |
| 8870 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8871 | { |
| 8872 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8873 | .doit = nl80211_set_mcast_rate, |
| 8874 | .policy = nl80211_policy, |
| 8875 | .flags = GENL_ADMIN_PERM, |
| 8876 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8877 | NL80211_FLAG_NEED_RTNL, |
| 8878 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8879 | { |
| 8880 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8881 | .doit = nl80211_set_mac_acl, |
| 8882 | .policy = nl80211_policy, |
| 8883 | .flags = GENL_ADMIN_PERM, |
| 8884 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8885 | NL80211_FLAG_NEED_RTNL, |
| 8886 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8887 | { |
| 8888 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8889 | .doit = nl80211_start_radar_detection, |
| 8890 | .policy = nl80211_policy, |
| 8891 | .flags = GENL_ADMIN_PERM, |
| 8892 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8893 | NL80211_FLAG_NEED_RTNL, |
| 8894 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8895 | { |
| 8896 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8897 | .doit = nl80211_get_protocol_features, |
| 8898 | .policy = nl80211_policy, |
| 8899 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8900 | { |
| 8901 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 8902 | .doit = nl80211_update_ft_ies, |
| 8903 | .policy = nl80211_policy, |
| 8904 | .flags = GENL_ADMIN_PERM, |
| 8905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8906 | NL80211_FLAG_NEED_RTNL, |
| 8907 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8908 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8909 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8910 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8911 | .name = "mlme", |
| 8912 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8913 | |
| 8914 | /* multicast groups */ |
| 8915 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8916 | .name = "config", |
| 8917 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8918 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8919 | .name = "scan", |
| 8920 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8921 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8922 | .name = "regulatory", |
| 8923 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8924 | |
| 8925 | /* notification functions */ |
| 8926 | |
| 8927 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8928 | { |
| 8929 | struct sk_buff *msg; |
| 8930 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8932 | if (!msg) |
| 8933 | return; |
| 8934 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8935 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 8936 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8937 | nlmsg_free(msg); |
| 8938 | return; |
| 8939 | } |
| 8940 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8941 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8942 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8943 | } |
| 8944 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8945 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8946 | struct cfg80211_registered_device *rdev) |
| 8947 | { |
| 8948 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8949 | struct nlattr *nest; |
| 8950 | int i; |
| 8951 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8952 | lockdep_assert_held(&rdev->sched_scan_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8953 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8954 | if (WARN_ON(!req)) |
| 8955 | return 0; |
| 8956 | |
| 8957 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8958 | if (!nest) |
| 8959 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8960 | for (i = 0; i < req->n_ssids; i++) { |
| 8961 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8962 | goto nla_put_failure; |
| 8963 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8964 | nla_nest_end(msg, nest); |
| 8965 | |
| 8966 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8967 | if (!nest) |
| 8968 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8969 | for (i = 0; i < req->n_channels; i++) { |
| 8970 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8971 | goto nla_put_failure; |
| 8972 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8973 | nla_nest_end(msg, nest); |
| 8974 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8975 | if (req->ie && |
| 8976 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8977 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8978 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8979 | if (req->flags) |
| 8980 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8981 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8982 | return 0; |
| 8983 | nla_put_failure: |
| 8984 | return -ENOBUFS; |
| 8985 | } |
| 8986 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8987 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8988 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8989 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8990 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8991 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8992 | { |
| 8993 | void *hdr; |
| 8994 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8995 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8996 | if (!hdr) |
| 8997 | return -1; |
| 8998 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8999 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9000 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9001 | wdev->netdev->ifindex)) || |
| 9002 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9003 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9004 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9005 | /* ignore errors and send incomplete event anyway */ |
| 9006 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9007 | |
| 9008 | return genlmsg_end(msg, hdr); |
| 9009 | |
| 9010 | nla_put_failure: |
| 9011 | genlmsg_cancel(msg, hdr); |
| 9012 | return -EMSGSIZE; |
| 9013 | } |
| 9014 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9015 | static int |
| 9016 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9017 | struct cfg80211_registered_device *rdev, |
| 9018 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9019 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9020 | { |
| 9021 | void *hdr; |
| 9022 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9023 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9024 | if (!hdr) |
| 9025 | return -1; |
| 9026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9028 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9029 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9030 | |
| 9031 | return genlmsg_end(msg, hdr); |
| 9032 | |
| 9033 | nla_put_failure: |
| 9034 | genlmsg_cancel(msg, hdr); |
| 9035 | return -EMSGSIZE; |
| 9036 | } |
| 9037 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9038 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9039 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9040 | { |
| 9041 | struct sk_buff *msg; |
| 9042 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9044 | if (!msg) |
| 9045 | return; |
| 9046 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9047 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9048 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9049 | nlmsg_free(msg); |
| 9050 | return; |
| 9051 | } |
| 9052 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9053 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9054 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9055 | } |
| 9056 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9057 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9058 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9059 | { |
| 9060 | struct sk_buff *msg; |
| 9061 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9062 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9063 | if (!msg) |
| 9064 | return; |
| 9065 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9066 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9067 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9068 | nlmsg_free(msg); |
| 9069 | return; |
| 9070 | } |
| 9071 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9072 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9073 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9077 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9078 | { |
| 9079 | struct sk_buff *msg; |
| 9080 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9081 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9082 | if (!msg) |
| 9083 | return; |
| 9084 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9085 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9086 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9087 | nlmsg_free(msg); |
| 9088 | return; |
| 9089 | } |
| 9090 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9091 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9092 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9093 | } |
| 9094 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9095 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9096 | struct net_device *netdev) |
| 9097 | { |
| 9098 | struct sk_buff *msg; |
| 9099 | |
| 9100 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9101 | if (!msg) |
| 9102 | return; |
| 9103 | |
| 9104 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9105 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9106 | nlmsg_free(msg); |
| 9107 | return; |
| 9108 | } |
| 9109 | |
| 9110 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9111 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9112 | } |
| 9113 | |
| 9114 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9115 | struct net_device *netdev, u32 cmd) |
| 9116 | { |
| 9117 | struct sk_buff *msg; |
| 9118 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9119 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9120 | if (!msg) |
| 9121 | return; |
| 9122 | |
| 9123 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9124 | nlmsg_free(msg); |
| 9125 | return; |
| 9126 | } |
| 9127 | |
| 9128 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9129 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9130 | } |
| 9131 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9132 | /* |
| 9133 | * This can happen on global regulatory changes or device specific settings |
| 9134 | * based on custom world regulatory domains. |
| 9135 | */ |
| 9136 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9137 | { |
| 9138 | struct sk_buff *msg; |
| 9139 | void *hdr; |
| 9140 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9141 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9142 | if (!msg) |
| 9143 | return; |
| 9144 | |
| 9145 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9146 | if (!hdr) { |
| 9147 | nlmsg_free(msg); |
| 9148 | return; |
| 9149 | } |
| 9150 | |
| 9151 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9152 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9153 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9154 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9155 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9156 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9157 | NL80211_REGDOM_TYPE_WORLD)) |
| 9158 | goto nla_put_failure; |
| 9159 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9160 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9161 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9162 | goto nla_put_failure; |
| 9163 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9164 | request->intersect) { |
| 9165 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9166 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9167 | goto nla_put_failure; |
| 9168 | } else { |
| 9169 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9170 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9171 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9172 | request->alpha2)) |
| 9173 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9174 | } |
| 9175 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9176 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9177 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9178 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9179 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9180 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9181 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9182 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9183 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9184 | GFP_ATOMIC); |
| 9185 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9186 | |
| 9187 | return; |
| 9188 | |
| 9189 | nla_put_failure: |
| 9190 | genlmsg_cancel(msg, hdr); |
| 9191 | nlmsg_free(msg); |
| 9192 | } |
| 9193 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9194 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9195 | struct net_device *netdev, |
| 9196 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9197 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9198 | { |
| 9199 | struct sk_buff *msg; |
| 9200 | void *hdr; |
| 9201 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9203 | if (!msg) |
| 9204 | return; |
| 9205 | |
| 9206 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9207 | if (!hdr) { |
| 9208 | nlmsg_free(msg); |
| 9209 | return; |
| 9210 | } |
| 9211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9213 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9214 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9215 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9216 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9217 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9218 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9219 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9220 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9221 | return; |
| 9222 | |
| 9223 | nla_put_failure: |
| 9224 | genlmsg_cancel(msg, hdr); |
| 9225 | nlmsg_free(msg); |
| 9226 | } |
| 9227 | |
| 9228 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9229 | struct net_device *netdev, const u8 *buf, |
| 9230 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9231 | { |
| 9232 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9233 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9234 | } |
| 9235 | |
| 9236 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9237 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9238 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9239 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9240 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9241 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9242 | } |
| 9243 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9244 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9245 | struct net_device *netdev, const u8 *buf, |
| 9246 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9247 | { |
| 9248 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9249 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9250 | } |
| 9251 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9252 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9253 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9254 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9255 | { |
| 9256 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9257 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9258 | } |
| 9259 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9260 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
| 9261 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9262 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9263 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9264 | struct wiphy *wiphy = wdev->wiphy; |
| 9265 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9266 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9267 | trace_cfg80211_send_unprot_deauth(dev); |
| 9268 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9269 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9270 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9271 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
| 9272 | |
| 9273 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
| 9274 | size_t len) |
| 9275 | { |
| 9276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9277 | struct wiphy *wiphy = wdev->wiphy; |
| 9278 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9279 | |
| 9280 | trace_cfg80211_send_unprot_disassoc(dev); |
| 9281 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9282 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); |
| 9283 | } |
| 9284 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9285 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9286 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9287 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9288 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9289 | { |
| 9290 | struct sk_buff *msg; |
| 9291 | void *hdr; |
| 9292 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9294 | if (!msg) |
| 9295 | return; |
| 9296 | |
| 9297 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9298 | if (!hdr) { |
| 9299 | nlmsg_free(msg); |
| 9300 | return; |
| 9301 | } |
| 9302 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9303 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9304 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9305 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9306 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9307 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9308 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9309 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9310 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9311 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9312 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9313 | return; |
| 9314 | |
| 9315 | nla_put_failure: |
| 9316 | genlmsg_cancel(msg, hdr); |
| 9317 | nlmsg_free(msg); |
| 9318 | } |
| 9319 | |
| 9320 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9321 | struct net_device *netdev, const u8 *addr, |
| 9322 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9323 | { |
| 9324 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9325 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9326 | } |
| 9327 | |
| 9328 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9329 | struct net_device *netdev, const u8 *addr, |
| 9330 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9331 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9332 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9333 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9334 | } |
| 9335 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9336 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9337 | struct net_device *netdev, const u8 *bssid, |
| 9338 | const u8 *req_ie, size_t req_ie_len, |
| 9339 | const u8 *resp_ie, size_t resp_ie_len, |
| 9340 | u16 status, gfp_t gfp) |
| 9341 | { |
| 9342 | struct sk_buff *msg; |
| 9343 | void *hdr; |
| 9344 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9345 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9346 | if (!msg) |
| 9347 | return; |
| 9348 | |
| 9349 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9350 | if (!hdr) { |
| 9351 | nlmsg_free(msg); |
| 9352 | return; |
| 9353 | } |
| 9354 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9356 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9357 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9358 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9359 | (req_ie && |
| 9360 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9361 | (resp_ie && |
| 9362 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9363 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9364 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9365 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9366 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9367 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9368 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9369 | return; |
| 9370 | |
| 9371 | nla_put_failure: |
| 9372 | genlmsg_cancel(msg, hdr); |
| 9373 | nlmsg_free(msg); |
| 9374 | |
| 9375 | } |
| 9376 | |
| 9377 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9378 | struct net_device *netdev, const u8 *bssid, |
| 9379 | const u8 *req_ie, size_t req_ie_len, |
| 9380 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9381 | { |
| 9382 | struct sk_buff *msg; |
| 9383 | void *hdr; |
| 9384 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9386 | if (!msg) |
| 9387 | return; |
| 9388 | |
| 9389 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9390 | if (!hdr) { |
| 9391 | nlmsg_free(msg); |
| 9392 | return; |
| 9393 | } |
| 9394 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9395 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9396 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9397 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9398 | (req_ie && |
| 9399 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9400 | (resp_ie && |
| 9401 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9402 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9403 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9404 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9405 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9406 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9407 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9408 | return; |
| 9409 | |
| 9410 | nla_put_failure: |
| 9411 | genlmsg_cancel(msg, hdr); |
| 9412 | nlmsg_free(msg); |
| 9413 | |
| 9414 | } |
| 9415 | |
| 9416 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9417 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9418 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9419 | { |
| 9420 | struct sk_buff *msg; |
| 9421 | void *hdr; |
| 9422 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9424 | if (!msg) |
| 9425 | return; |
| 9426 | |
| 9427 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9428 | if (!hdr) { |
| 9429 | nlmsg_free(msg); |
| 9430 | return; |
| 9431 | } |
| 9432 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9434 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9435 | (from_ap && reason && |
| 9436 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9437 | (from_ap && |
| 9438 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9439 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9440 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9441 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9442 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9443 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9444 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9445 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9446 | return; |
| 9447 | |
| 9448 | nla_put_failure: |
| 9449 | genlmsg_cancel(msg, hdr); |
| 9450 | nlmsg_free(msg); |
| 9451 | |
| 9452 | } |
| 9453 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9454 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9455 | struct net_device *netdev, const u8 *bssid, |
| 9456 | gfp_t gfp) |
| 9457 | { |
| 9458 | struct sk_buff *msg; |
| 9459 | void *hdr; |
| 9460 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9462 | if (!msg) |
| 9463 | return; |
| 9464 | |
| 9465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9466 | if (!hdr) { |
| 9467 | nlmsg_free(msg); |
| 9468 | return; |
| 9469 | } |
| 9470 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9471 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9472 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9473 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9474 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9475 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9476 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9477 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9478 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9479 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9480 | return; |
| 9481 | |
| 9482 | nla_put_failure: |
| 9483 | genlmsg_cancel(msg, hdr); |
| 9484 | nlmsg_free(msg); |
| 9485 | } |
| 9486 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9487 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9488 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9489 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9491 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9492 | struct sk_buff *msg; |
| 9493 | void *hdr; |
| 9494 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9495 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9496 | return; |
| 9497 | |
| 9498 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9499 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9500 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9501 | if (!msg) |
| 9502 | return; |
| 9503 | |
| 9504 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9505 | if (!hdr) { |
| 9506 | nlmsg_free(msg); |
| 9507 | return; |
| 9508 | } |
| 9509 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9510 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9511 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9512 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9513 | (ie_len && ie && |
| 9514 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9515 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9516 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9517 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9518 | |
| 9519 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9520 | nl80211_mlme_mcgrp.id, gfp); |
| 9521 | return; |
| 9522 | |
| 9523 | nla_put_failure: |
| 9524 | genlmsg_cancel(msg, hdr); |
| 9525 | nlmsg_free(msg); |
| 9526 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9527 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9528 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9529 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9530 | struct net_device *netdev, const u8 *addr, |
| 9531 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9532 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9533 | { |
| 9534 | struct sk_buff *msg; |
| 9535 | void *hdr; |
| 9536 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9538 | if (!msg) |
| 9539 | return; |
| 9540 | |
| 9541 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9542 | if (!hdr) { |
| 9543 | nlmsg_free(msg); |
| 9544 | return; |
| 9545 | } |
| 9546 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9547 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9548 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9549 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9550 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9551 | (key_id != -1 && |
| 9552 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9553 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9554 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9555 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9556 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9557 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9558 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9559 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9560 | return; |
| 9561 | |
| 9562 | nla_put_failure: |
| 9563 | genlmsg_cancel(msg, hdr); |
| 9564 | nlmsg_free(msg); |
| 9565 | } |
| 9566 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9567 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9568 | struct ieee80211_channel *channel_before, |
| 9569 | struct ieee80211_channel *channel_after) |
| 9570 | { |
| 9571 | struct sk_buff *msg; |
| 9572 | void *hdr; |
| 9573 | struct nlattr *nl_freq; |
| 9574 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9576 | if (!msg) |
| 9577 | return; |
| 9578 | |
| 9579 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9580 | if (!hdr) { |
| 9581 | nlmsg_free(msg); |
| 9582 | return; |
| 9583 | } |
| 9584 | |
| 9585 | /* |
| 9586 | * Since we are applying the beacon hint to a wiphy we know its |
| 9587 | * wiphy_idx is valid |
| 9588 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9589 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9590 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9591 | |
| 9592 | /* Before */ |
| 9593 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9594 | if (!nl_freq) |
| 9595 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9596 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9597 | goto nla_put_failure; |
| 9598 | nla_nest_end(msg, nl_freq); |
| 9599 | |
| 9600 | /* After */ |
| 9601 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9602 | if (!nl_freq) |
| 9603 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9604 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9605 | goto nla_put_failure; |
| 9606 | nla_nest_end(msg, nl_freq); |
| 9607 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9608 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9609 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9610 | rcu_read_lock(); |
| 9611 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9612 | GFP_ATOMIC); |
| 9613 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9614 | |
| 9615 | return; |
| 9616 | |
| 9617 | nla_put_failure: |
| 9618 | genlmsg_cancel(msg, hdr); |
| 9619 | nlmsg_free(msg); |
| 9620 | } |
| 9621 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9622 | static void nl80211_send_remain_on_chan_event( |
| 9623 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9624 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9625 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9626 | unsigned int duration, gfp_t gfp) |
| 9627 | { |
| 9628 | struct sk_buff *msg; |
| 9629 | void *hdr; |
| 9630 | |
| 9631 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9632 | if (!msg) |
| 9633 | return; |
| 9634 | |
| 9635 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9636 | if (!hdr) { |
| 9637 | nlmsg_free(msg); |
| 9638 | return; |
| 9639 | } |
| 9640 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9641 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9642 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9643 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9644 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9645 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9646 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9647 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9648 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9649 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9650 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9651 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9652 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9653 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9654 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9655 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9656 | |
| 9657 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9658 | nl80211_mlme_mcgrp.id, gfp); |
| 9659 | return; |
| 9660 | |
| 9661 | nla_put_failure: |
| 9662 | genlmsg_cancel(msg, hdr); |
| 9663 | nlmsg_free(msg); |
| 9664 | } |
| 9665 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9666 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9667 | struct ieee80211_channel *chan, |
| 9668 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9669 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9670 | struct wiphy *wiphy = wdev->wiphy; |
| 9671 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9672 | |
| 9673 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9674 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9675 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9676 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9677 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9678 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9679 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9680 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9681 | struct ieee80211_channel *chan, |
| 9682 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9683 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9684 | struct wiphy *wiphy = wdev->wiphy; |
| 9685 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9686 | |
| 9687 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9688 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9689 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9690 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9691 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9692 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9693 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9694 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9695 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9696 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9697 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9698 | struct sk_buff *msg; |
| 9699 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9700 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9701 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9703 | if (!msg) |
| 9704 | return; |
| 9705 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9706 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9707 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9708 | nlmsg_free(msg); |
| 9709 | return; |
| 9710 | } |
| 9711 | |
| 9712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9713 | nl80211_mlme_mcgrp.id, gfp); |
| 9714 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9715 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9716 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9717 | 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] | 9718 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9719 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9720 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9721 | struct sk_buff *msg; |
| 9722 | void *hdr; |
| 9723 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9724 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9725 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9727 | if (!msg) |
| 9728 | return; |
| 9729 | |
| 9730 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9731 | if (!hdr) { |
| 9732 | nlmsg_free(msg); |
| 9733 | return; |
| 9734 | } |
| 9735 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9736 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9737 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9738 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9739 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9740 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9741 | |
| 9742 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9743 | nl80211_mlme_mcgrp.id, gfp); |
| 9744 | return; |
| 9745 | |
| 9746 | nla_put_failure: |
| 9747 | genlmsg_cancel(msg, hdr); |
| 9748 | nlmsg_free(msg); |
| 9749 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9750 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9751 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9752 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9753 | enum nl80211_connect_failed_reason reason, |
| 9754 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9755 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9756 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9757 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9758 | struct sk_buff *msg; |
| 9759 | void *hdr; |
| 9760 | |
| 9761 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9762 | if (!msg) |
| 9763 | return; |
| 9764 | |
| 9765 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9766 | if (!hdr) { |
| 9767 | nlmsg_free(msg); |
| 9768 | return; |
| 9769 | } |
| 9770 | |
| 9771 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9772 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9773 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9774 | goto nla_put_failure; |
| 9775 | |
| 9776 | genlmsg_end(msg, hdr); |
| 9777 | |
| 9778 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9779 | nl80211_mlme_mcgrp.id, gfp); |
| 9780 | return; |
| 9781 | |
| 9782 | nla_put_failure: |
| 9783 | genlmsg_cancel(msg, hdr); |
| 9784 | nlmsg_free(msg); |
| 9785 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9786 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9787 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9788 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9789 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9790 | { |
| 9791 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9792 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9793 | struct sk_buff *msg; |
| 9794 | void *hdr; |
| 9795 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9796 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9797 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9798 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9799 | return false; |
| 9800 | |
| 9801 | msg = nlmsg_new(100, gfp); |
| 9802 | if (!msg) |
| 9803 | return true; |
| 9804 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9805 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9806 | if (!hdr) { |
| 9807 | nlmsg_free(msg); |
| 9808 | return true; |
| 9809 | } |
| 9810 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9812 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9814 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9815 | |
| 9816 | err = genlmsg_end(msg, hdr); |
| 9817 | if (err < 0) { |
| 9818 | nlmsg_free(msg); |
| 9819 | return true; |
| 9820 | } |
| 9821 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9822 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9823 | return true; |
| 9824 | |
| 9825 | nla_put_failure: |
| 9826 | genlmsg_cancel(msg, hdr); |
| 9827 | nlmsg_free(msg); |
| 9828 | return true; |
| 9829 | } |
| 9830 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9831 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9832 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9833 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9834 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9835 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9836 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9837 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9838 | |
| 9839 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9840 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9841 | trace_cfg80211_return_bool(false); |
| 9842 | return false; |
| 9843 | } |
| 9844 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9845 | addr, gfp); |
| 9846 | trace_cfg80211_return_bool(ret); |
| 9847 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9848 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9849 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9850 | |
| 9851 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9852 | const u8 *addr, gfp_t gfp) |
| 9853 | { |
| 9854 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9855 | bool ret; |
| 9856 | |
| 9857 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9858 | |
| 9859 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9860 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9861 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9862 | trace_cfg80211_return_bool(false); |
| 9863 | return false; |
| 9864 | } |
| 9865 | ret = __nl80211_unexpected_frame(dev, |
| 9866 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9867 | addr, gfp); |
| 9868 | trace_cfg80211_return_bool(ret); |
| 9869 | return ret; |
| 9870 | } |
| 9871 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9872 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9873 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9874 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9875 | int freq, int sig_dbm, |
| 9876 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9877 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9878 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9879 | struct sk_buff *msg; |
| 9880 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9881 | |
| 9882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9883 | if (!msg) |
| 9884 | return -ENOMEM; |
| 9885 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9886 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9887 | if (!hdr) { |
| 9888 | nlmsg_free(msg); |
| 9889 | return -ENOMEM; |
| 9890 | } |
| 9891 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9892 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9893 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9894 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9895 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9896 | (sig_dbm && |
| 9897 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9898 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9899 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9900 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9901 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9902 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9903 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9904 | |
| 9905 | nla_put_failure: |
| 9906 | genlmsg_cancel(msg, hdr); |
| 9907 | nlmsg_free(msg); |
| 9908 | return -ENOBUFS; |
| 9909 | } |
| 9910 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9911 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 9912 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9913 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9914 | struct wiphy *wiphy = wdev->wiphy; |
| 9915 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9916 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9917 | struct sk_buff *msg; |
| 9918 | void *hdr; |
| 9919 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9920 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 9921 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9923 | if (!msg) |
| 9924 | return; |
| 9925 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9927 | if (!hdr) { |
| 9928 | nlmsg_free(msg); |
| 9929 | return; |
| 9930 | } |
| 9931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9932 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9933 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9934 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9935 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9936 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9937 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9938 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9939 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9940 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9941 | |
| 9942 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9943 | return; |
| 9944 | |
| 9945 | nla_put_failure: |
| 9946 | genlmsg_cancel(msg, hdr); |
| 9947 | nlmsg_free(msg); |
| 9948 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9949 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9950 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9951 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 9952 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9953 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9954 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9956 | struct wiphy *wiphy = wdev->wiphy; |
| 9957 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9958 | struct sk_buff *msg; |
| 9959 | struct nlattr *pinfoattr; |
| 9960 | void *hdr; |
| 9961 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9962 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 9963 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9964 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9965 | if (!msg) |
| 9966 | return; |
| 9967 | |
| 9968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9969 | if (!hdr) { |
| 9970 | nlmsg_free(msg); |
| 9971 | return; |
| 9972 | } |
| 9973 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9974 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9975 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9976 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9977 | |
| 9978 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9979 | if (!pinfoattr) |
| 9980 | goto nla_put_failure; |
| 9981 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9982 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9983 | rssi_event)) |
| 9984 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9985 | |
| 9986 | nla_nest_end(msg, pinfoattr); |
| 9987 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9988 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9989 | |
| 9990 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9991 | nl80211_mlme_mcgrp.id, gfp); |
| 9992 | return; |
| 9993 | |
| 9994 | nla_put_failure: |
| 9995 | genlmsg_cancel(msg, hdr); |
| 9996 | nlmsg_free(msg); |
| 9997 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9998 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9999 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10000 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10001 | struct net_device *netdev, const u8 *bssid, |
| 10002 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10003 | { |
| 10004 | struct sk_buff *msg; |
| 10005 | struct nlattr *rekey_attr; |
| 10006 | void *hdr; |
| 10007 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10009 | if (!msg) |
| 10010 | return; |
| 10011 | |
| 10012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10013 | if (!hdr) { |
| 10014 | nlmsg_free(msg); |
| 10015 | return; |
| 10016 | } |
| 10017 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10019 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10020 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10021 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10022 | |
| 10023 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10024 | if (!rekey_attr) |
| 10025 | goto nla_put_failure; |
| 10026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10027 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10028 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10029 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10030 | |
| 10031 | nla_nest_end(msg, rekey_attr); |
| 10032 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10033 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10034 | |
| 10035 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10036 | nl80211_mlme_mcgrp.id, gfp); |
| 10037 | return; |
| 10038 | |
| 10039 | nla_put_failure: |
| 10040 | genlmsg_cancel(msg, hdr); |
| 10041 | nlmsg_free(msg); |
| 10042 | } |
| 10043 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10044 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10045 | const u8 *replay_ctr, gfp_t gfp) |
| 10046 | { |
| 10047 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10048 | struct wiphy *wiphy = wdev->wiphy; |
| 10049 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10050 | |
| 10051 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10052 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10053 | } |
| 10054 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10055 | |
| 10056 | static void |
| 10057 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10058 | struct net_device *netdev, int index, |
| 10059 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10060 | { |
| 10061 | struct sk_buff *msg; |
| 10062 | struct nlattr *attr; |
| 10063 | void *hdr; |
| 10064 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10066 | if (!msg) |
| 10067 | return; |
| 10068 | |
| 10069 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10070 | if (!hdr) { |
| 10071 | nlmsg_free(msg); |
| 10072 | return; |
| 10073 | } |
| 10074 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10076 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10077 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10078 | |
| 10079 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10080 | if (!attr) |
| 10081 | goto nla_put_failure; |
| 10082 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10083 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10084 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10085 | (preauth && |
| 10086 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10087 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10088 | |
| 10089 | nla_nest_end(msg, attr); |
| 10090 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10091 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10092 | |
| 10093 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10094 | nl80211_mlme_mcgrp.id, gfp); |
| 10095 | return; |
| 10096 | |
| 10097 | nla_put_failure: |
| 10098 | genlmsg_cancel(msg, hdr); |
| 10099 | nlmsg_free(msg); |
| 10100 | } |
| 10101 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10102 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10103 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10104 | { |
| 10105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10106 | struct wiphy *wiphy = wdev->wiphy; |
| 10107 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10108 | |
| 10109 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10110 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10111 | } |
| 10112 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10113 | |
| 10114 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10115 | struct net_device *netdev, |
| 10116 | struct cfg80211_chan_def *chandef, |
| 10117 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10118 | { |
| 10119 | struct sk_buff *msg; |
| 10120 | void *hdr; |
| 10121 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10123 | if (!msg) |
| 10124 | return; |
| 10125 | |
| 10126 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10127 | if (!hdr) { |
| 10128 | nlmsg_free(msg); |
| 10129 | return; |
| 10130 | } |
| 10131 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10132 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10133 | goto nla_put_failure; |
| 10134 | |
| 10135 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10136 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10137 | |
| 10138 | genlmsg_end(msg, hdr); |
| 10139 | |
| 10140 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10141 | nl80211_mlme_mcgrp.id, gfp); |
| 10142 | return; |
| 10143 | |
| 10144 | nla_put_failure: |
| 10145 | genlmsg_cancel(msg, hdr); |
| 10146 | nlmsg_free(msg); |
| 10147 | } |
| 10148 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10149 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10150 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10151 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10152 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10153 | struct wiphy *wiphy = wdev->wiphy; |
| 10154 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10155 | |
| 10156 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10157 | |
| 10158 | wdev_lock(wdev); |
| 10159 | |
| 10160 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10161 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10162 | goto out; |
| 10163 | |
| 10164 | wdev->channel = chandef->chan; |
| 10165 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10166 | out: |
| 10167 | wdev_unlock(wdev); |
| 10168 | return; |
| 10169 | } |
| 10170 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10171 | |
| 10172 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10173 | const u8 *peer, u32 num_packets, |
| 10174 | u32 rate, u32 intvl, gfp_t gfp) |
| 10175 | { |
| 10176 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10177 | struct wiphy *wiphy = wdev->wiphy; |
| 10178 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10179 | struct sk_buff *msg; |
| 10180 | struct nlattr *pinfoattr; |
| 10181 | void *hdr; |
| 10182 | |
| 10183 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10184 | if (!msg) |
| 10185 | return; |
| 10186 | |
| 10187 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10188 | if (!hdr) { |
| 10189 | nlmsg_free(msg); |
| 10190 | return; |
| 10191 | } |
| 10192 | |
| 10193 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10194 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10195 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10196 | goto nla_put_failure; |
| 10197 | |
| 10198 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10199 | if (!pinfoattr) |
| 10200 | goto nla_put_failure; |
| 10201 | |
| 10202 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10203 | goto nla_put_failure; |
| 10204 | |
| 10205 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10206 | goto nla_put_failure; |
| 10207 | |
| 10208 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10209 | goto nla_put_failure; |
| 10210 | |
| 10211 | nla_nest_end(msg, pinfoattr); |
| 10212 | |
| 10213 | genlmsg_end(msg, hdr); |
| 10214 | |
| 10215 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10216 | nl80211_mlme_mcgrp.id, gfp); |
| 10217 | return; |
| 10218 | |
| 10219 | nla_put_failure: |
| 10220 | genlmsg_cancel(msg, hdr); |
| 10221 | nlmsg_free(msg); |
| 10222 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10223 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10224 | |
| 10225 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10226 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10227 | struct cfg80211_chan_def *chandef, |
| 10228 | enum nl80211_radar_event event, |
| 10229 | struct net_device *netdev, gfp_t gfp) |
| 10230 | { |
| 10231 | struct sk_buff *msg; |
| 10232 | void *hdr; |
| 10233 | |
| 10234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10235 | if (!msg) |
| 10236 | return; |
| 10237 | |
| 10238 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10239 | if (!hdr) { |
| 10240 | nlmsg_free(msg); |
| 10241 | return; |
| 10242 | } |
| 10243 | |
| 10244 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10245 | goto nla_put_failure; |
| 10246 | |
| 10247 | /* NOP and radar events don't need a netdev parameter */ |
| 10248 | if (netdev) { |
| 10249 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10250 | |
| 10251 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10252 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10253 | goto nla_put_failure; |
| 10254 | } |
| 10255 | |
| 10256 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10257 | goto nla_put_failure; |
| 10258 | |
| 10259 | if (nl80211_send_chandef(msg, chandef)) |
| 10260 | goto nla_put_failure; |
| 10261 | |
| 10262 | if (genlmsg_end(msg, hdr) < 0) { |
| 10263 | nlmsg_free(msg); |
| 10264 | return; |
| 10265 | } |
| 10266 | |
| 10267 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10268 | nl80211_mlme_mcgrp.id, gfp); |
| 10269 | return; |
| 10270 | |
| 10271 | nla_put_failure: |
| 10272 | genlmsg_cancel(msg, hdr); |
| 10273 | nlmsg_free(msg); |
| 10274 | } |
| 10275 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10276 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10277 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10278 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10279 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10280 | struct wiphy *wiphy = wdev->wiphy; |
| 10281 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10282 | struct sk_buff *msg; |
| 10283 | struct nlattr *pinfoattr; |
| 10284 | void *hdr; |
| 10285 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10286 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10287 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10289 | if (!msg) |
| 10290 | return; |
| 10291 | |
| 10292 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10293 | if (!hdr) { |
| 10294 | nlmsg_free(msg); |
| 10295 | return; |
| 10296 | } |
| 10297 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10298 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10299 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10300 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10301 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10302 | |
| 10303 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10304 | if (!pinfoattr) |
| 10305 | goto nla_put_failure; |
| 10306 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10307 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10308 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10309 | |
| 10310 | nla_nest_end(msg, pinfoattr); |
| 10311 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10312 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10313 | |
| 10314 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10315 | nl80211_mlme_mcgrp.id, gfp); |
| 10316 | return; |
| 10317 | |
| 10318 | nla_put_failure: |
| 10319 | genlmsg_cancel(msg, hdr); |
| 10320 | nlmsg_free(msg); |
| 10321 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10322 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10323 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10324 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10325 | u64 cookie, bool acked, gfp_t gfp) |
| 10326 | { |
| 10327 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10328 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10329 | struct sk_buff *msg; |
| 10330 | void *hdr; |
| 10331 | int err; |
| 10332 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10333 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10334 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10335 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10336 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10337 | if (!msg) |
| 10338 | return; |
| 10339 | |
| 10340 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10341 | if (!hdr) { |
| 10342 | nlmsg_free(msg); |
| 10343 | return; |
| 10344 | } |
| 10345 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10347 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10348 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10349 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10350 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10351 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10352 | |
| 10353 | err = genlmsg_end(msg, hdr); |
| 10354 | if (err < 0) { |
| 10355 | nlmsg_free(msg); |
| 10356 | return; |
| 10357 | } |
| 10358 | |
| 10359 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10360 | nl80211_mlme_mcgrp.id, gfp); |
| 10361 | return; |
| 10362 | |
| 10363 | nla_put_failure: |
| 10364 | genlmsg_cancel(msg, hdr); |
| 10365 | nlmsg_free(msg); |
| 10366 | } |
| 10367 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10368 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10369 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10370 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10371 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10372 | { |
| 10373 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10374 | struct sk_buff *msg; |
| 10375 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10376 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10377 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10378 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10379 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10380 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10381 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10382 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10383 | if (!msg) { |
| 10384 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10385 | return; |
| 10386 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10387 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10388 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10389 | if (!hdr) |
| 10390 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10391 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10393 | (freq && |
| 10394 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10395 | (sig_dbm && |
| 10396 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10397 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10398 | goto nla_put_failure; |
| 10399 | |
| 10400 | genlmsg_end(msg, hdr); |
| 10401 | |
| 10402 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10403 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10404 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10405 | return; |
| 10406 | |
| 10407 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10408 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10409 | if (hdr) |
| 10410 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10411 | nlmsg_free(msg); |
| 10412 | } |
| 10413 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10414 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10415 | #ifdef CONFIG_PM |
| 10416 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10417 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10418 | gfp_t gfp) |
| 10419 | { |
| 10420 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10421 | struct sk_buff *msg; |
| 10422 | void *hdr; |
| 10423 | int err, size = 200; |
| 10424 | |
| 10425 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10426 | |
| 10427 | if (wakeup) |
| 10428 | size += wakeup->packet_present_len; |
| 10429 | |
| 10430 | msg = nlmsg_new(size, gfp); |
| 10431 | if (!msg) |
| 10432 | return; |
| 10433 | |
| 10434 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10435 | if (!hdr) |
| 10436 | goto free_msg; |
| 10437 | |
| 10438 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10439 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10440 | goto free_msg; |
| 10441 | |
| 10442 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10443 | wdev->netdev->ifindex)) |
| 10444 | goto free_msg; |
| 10445 | |
| 10446 | if (wakeup) { |
| 10447 | struct nlattr *reasons; |
| 10448 | |
| 10449 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10450 | |
| 10451 | if (wakeup->disconnect && |
| 10452 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10453 | goto free_msg; |
| 10454 | if (wakeup->magic_pkt && |
| 10455 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10456 | goto free_msg; |
| 10457 | if (wakeup->gtk_rekey_failure && |
| 10458 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10459 | goto free_msg; |
| 10460 | if (wakeup->eap_identity_req && |
| 10461 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10462 | goto free_msg; |
| 10463 | if (wakeup->four_way_handshake && |
| 10464 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10465 | goto free_msg; |
| 10466 | if (wakeup->rfkill_release && |
| 10467 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10468 | goto free_msg; |
| 10469 | |
| 10470 | if (wakeup->pattern_idx >= 0 && |
| 10471 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10472 | wakeup->pattern_idx)) |
| 10473 | goto free_msg; |
| 10474 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10475 | if (wakeup->tcp_match) |
| 10476 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10477 | |
| 10478 | if (wakeup->tcp_connlost) |
| 10479 | nla_put_flag(msg, |
| 10480 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10481 | |
| 10482 | if (wakeup->tcp_nomoretokens) |
| 10483 | nla_put_flag(msg, |
| 10484 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10485 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10486 | if (wakeup->packet) { |
| 10487 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10488 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10489 | |
| 10490 | if (!wakeup->packet_80211) { |
| 10491 | pkt_attr = |
| 10492 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10493 | len_attr = |
| 10494 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10495 | } |
| 10496 | |
| 10497 | if (wakeup->packet_len && |
| 10498 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10499 | goto free_msg; |
| 10500 | |
| 10501 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10502 | wakeup->packet)) |
| 10503 | goto free_msg; |
| 10504 | } |
| 10505 | |
| 10506 | nla_nest_end(msg, reasons); |
| 10507 | } |
| 10508 | |
| 10509 | err = genlmsg_end(msg, hdr); |
| 10510 | if (err < 0) |
| 10511 | goto free_msg; |
| 10512 | |
| 10513 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10514 | nl80211_mlme_mcgrp.id, gfp); |
| 10515 | return; |
| 10516 | |
| 10517 | free_msg: |
| 10518 | nlmsg_free(msg); |
| 10519 | } |
| 10520 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10521 | #endif |
| 10522 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10523 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10524 | enum nl80211_tdls_operation oper, |
| 10525 | u16 reason_code, gfp_t gfp) |
| 10526 | { |
| 10527 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10528 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10529 | struct sk_buff *msg; |
| 10530 | void *hdr; |
| 10531 | int err; |
| 10532 | |
| 10533 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10534 | reason_code); |
| 10535 | |
| 10536 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10537 | if (!msg) |
| 10538 | return; |
| 10539 | |
| 10540 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10541 | if (!hdr) { |
| 10542 | nlmsg_free(msg); |
| 10543 | return; |
| 10544 | } |
| 10545 | |
| 10546 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10547 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10548 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10549 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10550 | (reason_code > 0 && |
| 10551 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10552 | goto nla_put_failure; |
| 10553 | |
| 10554 | err = genlmsg_end(msg, hdr); |
| 10555 | if (err < 0) { |
| 10556 | nlmsg_free(msg); |
| 10557 | return; |
| 10558 | } |
| 10559 | |
| 10560 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10561 | nl80211_mlme_mcgrp.id, gfp); |
| 10562 | return; |
| 10563 | |
| 10564 | nla_put_failure: |
| 10565 | genlmsg_cancel(msg, hdr); |
| 10566 | nlmsg_free(msg); |
| 10567 | } |
| 10568 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10569 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10570 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10571 | unsigned long state, |
| 10572 | void *_notify) |
| 10573 | { |
| 10574 | struct netlink_notify *notify = _notify; |
| 10575 | struct cfg80211_registered_device *rdev; |
| 10576 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10577 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10578 | |
| 10579 | if (state != NETLINK_URELEASE) |
| 10580 | return NOTIFY_DONE; |
| 10581 | |
| 10582 | rcu_read_lock(); |
| 10583 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10584 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10585 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10586 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10587 | |
| 10588 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10589 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10590 | list) { |
| 10591 | if (reg->nlportid == notify->portid) { |
| 10592 | list_del(®->list); |
| 10593 | kfree(reg); |
| 10594 | break; |
| 10595 | } |
| 10596 | } |
| 10597 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10598 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10599 | |
| 10600 | rcu_read_unlock(); |
| 10601 | |
| 10602 | return NOTIFY_DONE; |
| 10603 | } |
| 10604 | |
| 10605 | static struct notifier_block nl80211_netlink_notifier = { |
| 10606 | .notifier_call = nl80211_netlink_notify, |
| 10607 | }; |
| 10608 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10609 | void cfg80211_ft_event(struct net_device *netdev, |
| 10610 | struct cfg80211_ft_event_params *ft_event) |
| 10611 | { |
| 10612 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10613 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10614 | struct sk_buff *msg; |
| 10615 | void *hdr; |
| 10616 | int err; |
| 10617 | |
| 10618 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10619 | |
| 10620 | if (!ft_event->target_ap) |
| 10621 | return; |
| 10622 | |
| 10623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10624 | if (!msg) |
| 10625 | return; |
| 10626 | |
| 10627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10628 | if (!hdr) { |
| 10629 | nlmsg_free(msg); |
| 10630 | return; |
| 10631 | } |
| 10632 | |
| 10633 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10634 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10635 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10636 | if (ft_event->ies) |
| 10637 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10638 | if (ft_event->ric_ies) |
| 10639 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10640 | ft_event->ric_ies); |
| 10641 | |
| 10642 | err = genlmsg_end(msg, hdr); |
| 10643 | if (err < 0) { |
| 10644 | nlmsg_free(msg); |
| 10645 | return; |
| 10646 | } |
| 10647 | |
| 10648 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10649 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10650 | } |
| 10651 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10652 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10653 | /* initialisation/exit functions */ |
| 10654 | |
| 10655 | int nl80211_init(void) |
| 10656 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10657 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10658 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10659 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10660 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10661 | if (err) |
| 10662 | return err; |
| 10663 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10664 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10665 | if (err) |
| 10666 | goto err_out; |
| 10667 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10668 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10669 | if (err) |
| 10670 | goto err_out; |
| 10671 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10672 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10673 | if (err) |
| 10674 | goto err_out; |
| 10675 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10676 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10677 | if (err) |
| 10678 | goto err_out; |
| 10679 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10680 | #ifdef CONFIG_NL80211_TESTMODE |
| 10681 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10682 | if (err) |
| 10683 | goto err_out; |
| 10684 | #endif |
| 10685 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10686 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10687 | if (err) |
| 10688 | goto err_out; |
| 10689 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10690 | return 0; |
| 10691 | err_out: |
| 10692 | genl_unregister_family(&nl80211_fam); |
| 10693 | return err; |
| 10694 | } |
| 10695 | |
| 10696 | void nl80211_exit(void) |
| 10697 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10698 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10699 | genl_unregister_family(&nl80211_fam); |
| 10700 | } |