Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 373 | }; |
| 374 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 376 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 377 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 379 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 380 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 381 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 382 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 384 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 385 | }; |
| 386 | |
| 387 | /* policy for the key default flags */ |
| 388 | static const struct nla_policy |
| 389 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 390 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 391 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 392 | }; |
| 393 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 394 | /* policy for WoWLAN attributes */ |
| 395 | static const struct nla_policy |
| 396 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 397 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 398 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 399 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 400 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 401 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 402 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 403 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 404 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 405 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 406 | }; |
| 407 | |
| 408 | static const struct nla_policy |
| 409 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 410 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 411 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 412 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 413 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 414 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 415 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 416 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 417 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 418 | }, |
| 419 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 420 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 421 | }, |
| 422 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 423 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 424 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 425 | }; |
| 426 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 427 | /* policy for GTK rekey offload attributes */ |
| 428 | static const struct nla_policy |
| 429 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 430 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 431 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 432 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 433 | }; |
| 434 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 435 | static const struct nla_policy |
| 436 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 437 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 438 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 439 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 440 | }; |
| 441 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 442 | /* ifidx get helper */ |
| 443 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 444 | { |
| 445 | int res; |
| 446 | |
| 447 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 448 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 449 | nl80211_policy); |
| 450 | if (res) |
| 451 | return res; |
| 452 | |
| 453 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 454 | return -EINVAL; |
| 455 | |
| 456 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 457 | if (!res) |
| 458 | return -EINVAL; |
| 459 | return res; |
| 460 | } |
| 461 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 462 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 463 | struct netlink_callback *cb, |
| 464 | struct cfg80211_registered_device **rdev, |
| 465 | struct net_device **dev) |
| 466 | { |
| 467 | int ifidx = cb->args[0]; |
| 468 | int err; |
| 469 | |
| 470 | if (!ifidx) |
| 471 | ifidx = nl80211_get_ifidx(cb); |
| 472 | if (ifidx < 0) |
| 473 | return ifidx; |
| 474 | |
| 475 | cb->args[0] = ifidx; |
| 476 | |
| 477 | rtnl_lock(); |
| 478 | |
| 479 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 480 | if (!*dev) { |
| 481 | err = -ENODEV; |
| 482 | goto out_rtnl; |
| 483 | } |
| 484 | |
| 485 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 486 | if (IS_ERR(*rdev)) { |
| 487 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 488 | goto out_rtnl; |
| 489 | } |
| 490 | |
| 491 | return 0; |
| 492 | out_rtnl: |
| 493 | rtnl_unlock(); |
| 494 | return err; |
| 495 | } |
| 496 | |
| 497 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 498 | { |
| 499 | cfg80211_unlock_rdev(rdev); |
| 500 | rtnl_unlock(); |
| 501 | } |
| 502 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 503 | /* IE validation */ |
| 504 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 505 | { |
| 506 | const u8 *pos; |
| 507 | int len; |
| 508 | |
| 509 | if (!attr) |
| 510 | return true; |
| 511 | |
| 512 | pos = nla_data(attr); |
| 513 | len = nla_len(attr); |
| 514 | |
| 515 | while (len) { |
| 516 | u8 elemlen; |
| 517 | |
| 518 | if (len < 2) |
| 519 | return false; |
| 520 | len -= 2; |
| 521 | |
| 522 | elemlen = pos[1]; |
| 523 | if (elemlen > len) |
| 524 | return false; |
| 525 | |
| 526 | len -= elemlen; |
| 527 | pos += 2 + elemlen; |
| 528 | } |
| 529 | |
| 530 | return true; |
| 531 | } |
| 532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 533 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 534 | 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] | 535 | int flags, u8 cmd) |
| 536 | { |
| 537 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 538 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 541 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 542 | struct ieee80211_channel *chan) |
| 543 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 545 | chan->center_freq)) |
| 546 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 547 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 548 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 549 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 550 | goto nla_put_failure; |
| 551 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 552 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 553 | goto nla_put_failure; |
| 554 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 556 | goto nla_put_failure; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 557 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 558 | u32 time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 559 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 560 | goto nla_put_failure; |
| 561 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 562 | chan->dfs_state)) |
| 563 | goto nla_put_failure; |
| 564 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, time)) |
| 565 | goto nla_put_failure; |
| 566 | } |
Johannes Berg | 50640f1 | 2012-12-12 17:59:39 +0100 | [diff] [blame] | 567 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 569 | goto nla_put_failure; |
| 570 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 572 | goto nla_put_failure; |
| 573 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 574 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 575 | goto nla_put_failure; |
| 576 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 578 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 580 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 581 | DBM_TO_MBM(chan->max_power))) |
| 582 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 583 | |
| 584 | return 0; |
| 585 | |
| 586 | nla_put_failure: |
| 587 | return -ENOBUFS; |
| 588 | } |
| 589 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 590 | /* netlink command implementations */ |
| 591 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 592 | struct key_parse { |
| 593 | struct key_params p; |
| 594 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 595 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 596 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 597 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 601 | { |
| 602 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 603 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 604 | nl80211_key_policy); |
| 605 | if (err) |
| 606 | return err; |
| 607 | |
| 608 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 609 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 610 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 611 | if (k->def) { |
| 612 | k->def_uni = true; |
| 613 | k->def_multi = true; |
| 614 | } |
| 615 | if (k->defmgmt) |
| 616 | k->def_multi = true; |
| 617 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 618 | if (tb[NL80211_KEY_IDX]) |
| 619 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 620 | |
| 621 | if (tb[NL80211_KEY_DATA]) { |
| 622 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 623 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 624 | } |
| 625 | |
| 626 | if (tb[NL80211_KEY_SEQ]) { |
| 627 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 628 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 629 | } |
| 630 | |
| 631 | if (tb[NL80211_KEY_CIPHER]) |
| 632 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 633 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 634 | if (tb[NL80211_KEY_TYPE]) { |
| 635 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 636 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 637 | return -EINVAL; |
| 638 | } |
| 639 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 640 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 641 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 642 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 643 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 644 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 645 | if (err) |
| 646 | return err; |
| 647 | |
| 648 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 649 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 650 | } |
| 651 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 656 | { |
| 657 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 658 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 659 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 660 | } |
| 661 | |
| 662 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 663 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 664 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 665 | } |
| 666 | |
| 667 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 668 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 669 | |
| 670 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 671 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 672 | |
| 673 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 674 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 675 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 676 | if (k->def) { |
| 677 | k->def_uni = true; |
| 678 | k->def_multi = true; |
| 679 | } |
| 680 | if (k->defmgmt) |
| 681 | k->def_multi = true; |
| 682 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 683 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 684 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 685 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 686 | return -EINVAL; |
| 687 | } |
| 688 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 689 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 690 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 691 | int err = nla_parse_nested( |
| 692 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 693 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 694 | nl80211_key_default_policy); |
| 695 | if (err) |
| 696 | return err; |
| 697 | |
| 698 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 699 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 700 | } |
| 701 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 706 | { |
| 707 | int err; |
| 708 | |
| 709 | memset(k, 0, sizeof(*k)); |
| 710 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 711 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 712 | |
| 713 | if (info->attrs[NL80211_ATTR_KEY]) |
| 714 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 715 | else |
| 716 | err = nl80211_parse_key_old(info, k); |
| 717 | |
| 718 | if (err) |
| 719 | return err; |
| 720 | |
| 721 | if (k->def && k->defmgmt) |
| 722 | return -EINVAL; |
| 723 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 724 | if (k->defmgmt) { |
| 725 | if (k->def_uni || !k->def_multi) |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 729 | if (k->idx != -1) { |
| 730 | if (k->defmgmt) { |
| 731 | if (k->idx < 4 || k->idx > 5) |
| 732 | return -EINVAL; |
| 733 | } else if (k->def) { |
| 734 | if (k->idx < 0 || k->idx > 3) |
| 735 | return -EINVAL; |
| 736 | } else { |
| 737 | if (k->idx < 0 || k->idx > 5) |
| 738 | return -EINVAL; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 745 | static struct cfg80211_cached_keys * |
| 746 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 747 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 748 | { |
| 749 | struct key_parse parse; |
| 750 | struct nlattr *key; |
| 751 | struct cfg80211_cached_keys *result; |
| 752 | int rem, err, def = 0; |
| 753 | |
| 754 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 755 | if (!result) |
| 756 | return ERR_PTR(-ENOMEM); |
| 757 | |
| 758 | result->def = -1; |
| 759 | result->defmgmt = -1; |
| 760 | |
| 761 | nla_for_each_nested(key, keys, rem) { |
| 762 | memset(&parse, 0, sizeof(parse)); |
| 763 | parse.idx = -1; |
| 764 | |
| 765 | err = nl80211_parse_key_new(key, &parse); |
| 766 | if (err) |
| 767 | goto error; |
| 768 | err = -EINVAL; |
| 769 | if (!parse.p.key) |
| 770 | goto error; |
| 771 | if (parse.idx < 0 || parse.idx > 4) |
| 772 | goto error; |
| 773 | if (parse.def) { |
| 774 | if (def) |
| 775 | goto error; |
| 776 | def = 1; |
| 777 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 778 | if (!parse.def_uni || !parse.def_multi) |
| 779 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 780 | } else if (parse.defmgmt) |
| 781 | goto error; |
| 782 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 783 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 784 | if (err) |
| 785 | goto error; |
| 786 | result->params[parse.idx].cipher = parse.p.cipher; |
| 787 | result->params[parse.idx].key_len = parse.p.key_len; |
| 788 | result->params[parse.idx].key = result->data[parse.idx]; |
| 789 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 790 | |
| 791 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 792 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 793 | if (no_ht) |
| 794 | *no_ht = true; |
| 795 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | return result; |
| 799 | error: |
| 800 | kfree(result); |
| 801 | return ERR_PTR(err); |
| 802 | } |
| 803 | |
| 804 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 805 | { |
| 806 | ASSERT_WDEV_LOCK(wdev); |
| 807 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 808 | switch (wdev->iftype) { |
| 809 | case NL80211_IFTYPE_AP: |
| 810 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 811 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 812 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | break; |
| 814 | case NL80211_IFTYPE_ADHOC: |
| 815 | if (!wdev->current_bss) |
| 816 | return -ENOLINK; |
| 817 | break; |
| 818 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 819 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 820 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 821 | return -ENOLINK; |
| 822 | break; |
| 823 | default: |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | |
| 827 | return 0; |
| 828 | } |
| 829 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 830 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 831 | { |
| 832 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 833 | int i; |
| 834 | |
| 835 | if (!nl_modes) |
| 836 | goto nla_put_failure; |
| 837 | |
| 838 | i = 0; |
| 839 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 840 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 841 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 842 | ifmodes >>= 1; |
| 843 | i++; |
| 844 | } |
| 845 | |
| 846 | nla_nest_end(msg, nl_modes); |
| 847 | return 0; |
| 848 | |
| 849 | nla_put_failure: |
| 850 | return -ENOBUFS; |
| 851 | } |
| 852 | |
| 853 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 854 | struct sk_buff *msg) |
| 855 | { |
| 856 | struct nlattr *nl_combis; |
| 857 | int i, j; |
| 858 | |
| 859 | nl_combis = nla_nest_start(msg, |
| 860 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 861 | if (!nl_combis) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 865 | const struct ieee80211_iface_combination *c; |
| 866 | struct nlattr *nl_combi, *nl_limits; |
| 867 | |
| 868 | c = &wiphy->iface_combinations[i]; |
| 869 | |
| 870 | nl_combi = nla_nest_start(msg, i + 1); |
| 871 | if (!nl_combi) |
| 872 | goto nla_put_failure; |
| 873 | |
| 874 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 875 | if (!nl_limits) |
| 876 | goto nla_put_failure; |
| 877 | |
| 878 | for (j = 0; j < c->n_limits; j++) { |
| 879 | struct nlattr *nl_limit; |
| 880 | |
| 881 | nl_limit = nla_nest_start(msg, j + 1); |
| 882 | if (!nl_limit) |
| 883 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 884 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 885 | c->limits[j].max)) |
| 886 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 887 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 888 | c->limits[j].types)) |
| 889 | goto nla_put_failure; |
| 890 | nla_nest_end(msg, nl_limit); |
| 891 | } |
| 892 | |
| 893 | nla_nest_end(msg, nl_limits); |
| 894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 895 | if (c->beacon_int_infra_match && |
| 896 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 897 | goto nla_put_failure; |
| 898 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 899 | c->num_different_channels) || |
| 900 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 901 | c->max_interfaces)) |
| 902 | goto nla_put_failure; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 903 | if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 904 | c->radar_detect_widths)) |
| 905 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 906 | |
| 907 | nla_nest_end(msg, nl_combi); |
| 908 | } |
| 909 | |
| 910 | nla_nest_end(msg, nl_combis); |
| 911 | |
| 912 | return 0; |
| 913 | nla_put_failure: |
| 914 | return -ENOBUFS; |
| 915 | } |
| 916 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 917 | #ifdef CONFIG_PM |
| 918 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 919 | struct sk_buff *msg) |
| 920 | { |
| 921 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 922 | struct nlattr *nl_tcp; |
| 923 | |
| 924 | if (!tcp) |
| 925 | return 0; |
| 926 | |
| 927 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 928 | if (!nl_tcp) |
| 929 | return -ENOBUFS; |
| 930 | |
| 931 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 932 | tcp->data_payload_max)) |
| 933 | return -ENOBUFS; |
| 934 | |
| 935 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 936 | tcp->data_payload_max)) |
| 937 | return -ENOBUFS; |
| 938 | |
| 939 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 940 | return -ENOBUFS; |
| 941 | |
| 942 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 943 | sizeof(*tcp->tok), tcp->tok)) |
| 944 | return -ENOBUFS; |
| 945 | |
| 946 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 947 | tcp->data_interval_max)) |
| 948 | return -ENOBUFS; |
| 949 | |
| 950 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 951 | tcp->wake_payload_max)) |
| 952 | return -ENOBUFS; |
| 953 | |
| 954 | nla_nest_end(msg, nl_tcp); |
| 955 | return 0; |
| 956 | } |
| 957 | #endif |
| 958 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 959 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 960 | struct cfg80211_registered_device *dev) |
| 961 | { |
| 962 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 963 | struct nlattr *nl_bands, *nl_band; |
| 964 | struct nlattr *nl_freqs, *nl_freq; |
| 965 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 966 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 967 | enum ieee80211_band band; |
| 968 | struct ieee80211_channel *chan; |
| 969 | struct ieee80211_rate *rate; |
| 970 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 971 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 972 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 973 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 974 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 975 | if (!hdr) |
| 976 | return -1; |
| 977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 979 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 980 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 981 | cfg80211_rdev_list_generation) || |
| 982 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 983 | dev->wiphy.retry_short) || |
| 984 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 985 | dev->wiphy.retry_long) || |
| 986 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 987 | dev->wiphy.frag_threshold) || |
| 988 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 989 | dev->wiphy.rts_threshold) || |
| 990 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 991 | dev->wiphy.coverage_class) || |
| 992 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 993 | dev->wiphy.max_scan_ssids) || |
| 994 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 995 | dev->wiphy.max_sched_scan_ssids) || |
| 996 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 997 | dev->wiphy.max_scan_ie_len) || |
| 998 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 999 | dev->wiphy.max_sched_scan_ie_len) || |
| 1000 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1001 | dev->wiphy.max_match_sets)) |
| 1002 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1003 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1004 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1005 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1006 | goto nla_put_failure; |
| 1007 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1008 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1009 | goto nla_put_failure; |
| 1010 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1011 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1012 | goto nla_put_failure; |
| 1013 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1014 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1015 | goto nla_put_failure; |
| 1016 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1017 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1018 | goto nla_put_failure; |
| 1019 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1020 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 1021 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1022 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1023 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1024 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1025 | dev->wiphy.cipher_suites)) |
| 1026 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1027 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1028 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1029 | dev->wiphy.max_num_pmkids)) |
| 1030 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 1031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1032 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1033 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1034 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 1035 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1036 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1037 | dev->wiphy.available_antennas_tx) || |
| 1038 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1039 | dev->wiphy.available_antennas_rx)) |
| 1040 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1041 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1042 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1043 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1044 | dev->wiphy.probe_resp_offload)) |
| 1045 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 1046 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1047 | if ((dev->wiphy.available_antennas_tx || |
| 1048 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1049 | u32 tx_ant = 0, rx_ant = 0; |
| 1050 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1051 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1052 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1054 | tx_ant) || |
| 1055 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1056 | rx_ant)) |
| 1057 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1061 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1062 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1063 | goto nla_put_failure; |
| 1064 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1065 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1066 | if (!nl_bands) |
| 1067 | goto nla_put_failure; |
| 1068 | |
| 1069 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1070 | if (!dev->wiphy.bands[band]) |
| 1071 | continue; |
| 1072 | |
| 1073 | nl_band = nla_nest_start(msg, band); |
| 1074 | if (!nl_band) |
| 1075 | goto nla_put_failure; |
| 1076 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1077 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1078 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 1079 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1080 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 1081 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 1082 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1083 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 1084 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1085 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 1086 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1087 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 1088 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1089 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1090 | /* add VHT info */ |
| 1091 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1092 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1093 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1094 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1095 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1096 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1097 | goto nla_put_failure; |
| 1098 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1099 | /* add frequencies */ |
| 1100 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1101 | if (!nl_freqs) |
| 1102 | goto nla_put_failure; |
| 1103 | |
| 1104 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1105 | nl_freq = nla_nest_start(msg, i); |
| 1106 | if (!nl_freq) |
| 1107 | goto nla_put_failure; |
| 1108 | |
| 1109 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1110 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1111 | if (nl80211_msg_put_channel(msg, chan)) |
| 1112 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1113 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1114 | nla_nest_end(msg, nl_freq); |
| 1115 | } |
| 1116 | |
| 1117 | nla_nest_end(msg, nl_freqs); |
| 1118 | |
| 1119 | /* add bitrates */ |
| 1120 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1121 | if (!nl_rates) |
| 1122 | goto nla_put_failure; |
| 1123 | |
| 1124 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1125 | nl_rate = nla_nest_start(msg, i); |
| 1126 | if (!nl_rate) |
| 1127 | goto nla_put_failure; |
| 1128 | |
| 1129 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1130 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1131 | rate->bitrate)) |
| 1132 | goto nla_put_failure; |
| 1133 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1134 | nla_put_flag(msg, |
| 1135 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1136 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1137 | |
| 1138 | nla_nest_end(msg, nl_rate); |
| 1139 | } |
| 1140 | |
| 1141 | nla_nest_end(msg, nl_rates); |
| 1142 | |
| 1143 | nla_nest_end(msg, nl_band); |
| 1144 | } |
| 1145 | nla_nest_end(msg, nl_bands); |
| 1146 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1147 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1148 | if (!nl_cmds) |
| 1149 | goto nla_put_failure; |
| 1150 | |
| 1151 | i = 0; |
| 1152 | #define CMD(op, n) \ |
| 1153 | do { \ |
| 1154 | if (dev->ops->op) { \ |
| 1155 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1156 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1157 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1158 | } \ |
| 1159 | } while (0) |
| 1160 | |
| 1161 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1162 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1163 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1164 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1165 | CMD(add_station, NEW_STATION); |
| 1166 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1167 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1168 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1169 | CMD(auth, AUTHENTICATE); |
| 1170 | CMD(assoc, ASSOCIATE); |
| 1171 | CMD(deauth, DEAUTHENTICATE); |
| 1172 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1173 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1174 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1175 | CMD(set_pmksa, SET_PMKSA); |
| 1176 | CMD(del_pmksa, DEL_PMKSA); |
| 1177 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1178 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1179 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1180 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1181 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1182 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1183 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1184 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1185 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1186 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1187 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1188 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1189 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1190 | i++; |
| 1191 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1192 | goto nla_put_failure; |
| 1193 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1194 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1195 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1196 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1197 | CMD(tdls_oper, TDLS_OPER); |
| 1198 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1199 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1200 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1201 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1202 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1203 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1204 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1205 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1206 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1207 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1208 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1209 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1210 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1211 | #ifdef CONFIG_NL80211_TESTMODE |
| 1212 | CMD(testmode_cmd, TESTMODE); |
| 1213 | #endif |
| 1214 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1215 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1216 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1217 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1218 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1219 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1220 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1223 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1224 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1225 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1226 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1229 | nla_nest_end(msg, nl_cmds); |
| 1230 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1231 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1232 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1233 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1234 | dev->wiphy.max_remain_on_channel_duration)) |
| 1235 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1236 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1237 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1238 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1239 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1240 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1241 | if (mgmt_stypes) { |
| 1242 | u16 stypes; |
| 1243 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1244 | enum nl80211_iftype ift; |
| 1245 | |
| 1246 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1247 | if (!nl_ifs) |
| 1248 | goto nla_put_failure; |
| 1249 | |
| 1250 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1251 | nl_ftypes = nla_nest_start(msg, ift); |
| 1252 | if (!nl_ftypes) |
| 1253 | goto nla_put_failure; |
| 1254 | i = 0; |
| 1255 | stypes = mgmt_stypes[ift].tx; |
| 1256 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1257 | if ((stypes & 1) && |
| 1258 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1259 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1260 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1261 | stypes >>= 1; |
| 1262 | i++; |
| 1263 | } |
| 1264 | nla_nest_end(msg, nl_ftypes); |
| 1265 | } |
| 1266 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1267 | nla_nest_end(msg, nl_ifs); |
| 1268 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1269 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1270 | if (!nl_ifs) |
| 1271 | goto nla_put_failure; |
| 1272 | |
| 1273 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1274 | nl_ftypes = nla_nest_start(msg, ift); |
| 1275 | if (!nl_ftypes) |
| 1276 | goto nla_put_failure; |
| 1277 | i = 0; |
| 1278 | stypes = mgmt_stypes[ift].rx; |
| 1279 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1280 | if ((stypes & 1) && |
| 1281 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1282 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1283 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1284 | stypes >>= 1; |
| 1285 | i++; |
| 1286 | } |
| 1287 | nla_nest_end(msg, nl_ftypes); |
| 1288 | } |
| 1289 | nla_nest_end(msg, nl_ifs); |
| 1290 | } |
| 1291 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1292 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1293 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1294 | struct nlattr *nl_wowlan; |
| 1295 | |
| 1296 | nl_wowlan = nla_nest_start(msg, |
| 1297 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1298 | if (!nl_wowlan) |
| 1299 | goto nla_put_failure; |
| 1300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1301 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1303 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1305 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1307 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1308 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1309 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1310 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1311 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1312 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1313 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1314 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1315 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1316 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1317 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1318 | if (dev->wiphy.wowlan.n_patterns) { |
| 1319 | struct nl80211_wowlan_pattern_support pat = { |
| 1320 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1321 | .min_pattern_len = |
| 1322 | dev->wiphy.wowlan.pattern_min_len, |
| 1323 | .max_pattern_len = |
| 1324 | dev->wiphy.wowlan.pattern_max_len, |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 1325 | .max_pkt_offset = |
| 1326 | dev->wiphy.wowlan.max_pkt_offset, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1327 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1328 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1329 | sizeof(pat), &pat)) |
| 1330 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 1333 | if (nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1334 | goto nla_put_failure; |
| 1335 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1336 | nla_nest_end(msg, nl_wowlan); |
| 1337 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1338 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1339 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1340 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1341 | dev->wiphy.software_iftypes)) |
| 1342 | goto nla_put_failure; |
| 1343 | |
| 1344 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1345 | goto nla_put_failure; |
| 1346 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1347 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1348 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1349 | dev->wiphy.ap_sme_capa)) |
| 1350 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1351 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1352 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1353 | dev->wiphy.features)) |
| 1354 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1355 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1356 | if (dev->wiphy.ht_capa_mod_mask && |
| 1357 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1358 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1359 | dev->wiphy.ht_capa_mod_mask)) |
| 1360 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1361 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 1362 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1363 | dev->wiphy.max_acl_mac_addrs && |
| 1364 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1365 | dev->wiphy.max_acl_mac_addrs)) |
| 1366 | goto nla_put_failure; |
| 1367 | |
Johannes Berg | a50df0c | 2013-02-11 14:20:05 +0100 | [diff] [blame] | 1368 | if (dev->wiphy.extended_capabilities && |
| 1369 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1370 | dev->wiphy.extended_capabilities_len, |
| 1371 | dev->wiphy.extended_capabilities) || |
| 1372 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1373 | dev->wiphy.extended_capabilities_len, |
| 1374 | dev->wiphy.extended_capabilities_mask))) |
| 1375 | goto nla_put_failure; |
| 1376 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1377 | return genlmsg_end(msg, hdr); |
| 1378 | |
| 1379 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1380 | genlmsg_cancel(msg, hdr); |
| 1381 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1385 | { |
| 1386 | int idx = 0; |
| 1387 | int start = cb->args[0]; |
| 1388 | struct cfg80211_registered_device *dev; |
| 1389 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1390 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1391 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1392 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1393 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1394 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1395 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1396 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1397 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1398 | dev) < 0) { |
| 1399 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1400 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1401 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1402 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1403 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1404 | |
| 1405 | cb->args[0] = idx; |
| 1406 | |
| 1407 | return skb->len; |
| 1408 | } |
| 1409 | |
| 1410 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1411 | { |
| 1412 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1413 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1414 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1415 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1416 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1417 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1418 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1419 | if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1420 | nlmsg_free(msg); |
| 1421 | return -ENOBUFS; |
| 1422 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1423 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1424 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1425 | } |
| 1426 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1427 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1428 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1429 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1430 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1431 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1432 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1433 | }; |
| 1434 | |
| 1435 | static int parse_txq_params(struct nlattr *tb[], |
| 1436 | struct ieee80211_txq_params *txq_params) |
| 1437 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1438 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1439 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1440 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1441 | return -EINVAL; |
| 1442 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1443 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1444 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1445 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1446 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1447 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1448 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1449 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1450 | return -EINVAL; |
| 1451 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1452 | return 0; |
| 1453 | } |
| 1454 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1455 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1456 | { |
| 1457 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1458 | * You can only set the channel explicitly for WDS interfaces, |
| 1459 | * all others have their channel managed via their respective |
| 1460 | * "establish a connection" command (connect, join, ...) |
| 1461 | * |
| 1462 | * For AP/GO and mesh mode, the channel can be set with the |
| 1463 | * channel userspace API, but is only stored and passed to the |
| 1464 | * low-level driver when the AP starts or the mesh is joined. |
| 1465 | * This is for backward compatibility, userspace can also give |
| 1466 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1467 | * |
| 1468 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1469 | * whatever else is going on, so they have their own special |
| 1470 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1471 | */ |
| 1472 | return !wdev || |
| 1473 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1474 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1475 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1476 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1479 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1480 | struct genl_info *info, |
| 1481 | struct cfg80211_chan_def *chandef) |
| 1482 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1483 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1484 | |
| 1485 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1486 | return -EINVAL; |
| 1487 | |
| 1488 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1489 | |
| 1490 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1491 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1492 | chandef->center_freq1 = control_freq; |
| 1493 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1494 | |
| 1495 | /* Primary channel not allowed */ |
| 1496 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1497 | return -EINVAL; |
| 1498 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1499 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1500 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1501 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1502 | chantype = nla_get_u32( |
| 1503 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1504 | |
| 1505 | switch (chantype) { |
| 1506 | case NL80211_CHAN_NO_HT: |
| 1507 | case NL80211_CHAN_HT20: |
| 1508 | case NL80211_CHAN_HT40PLUS: |
| 1509 | case NL80211_CHAN_HT40MINUS: |
| 1510 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1511 | chantype); |
| 1512 | break; |
| 1513 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1514 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1515 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1516 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1517 | chandef->width = |
| 1518 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1519 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1520 | chandef->center_freq1 = |
| 1521 | nla_get_u32( |
| 1522 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1523 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1524 | chandef->center_freq2 = |
| 1525 | nla_get_u32( |
| 1526 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1527 | } |
| 1528 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1529 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1530 | return -EINVAL; |
| 1531 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1532 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1533 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1534 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1535 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1536 | return 0; |
| 1537 | } |
| 1538 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1539 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1540 | struct wireless_dev *wdev, |
| 1541 | struct genl_info *info) |
| 1542 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1543 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1544 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1545 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1546 | |
| 1547 | if (wdev) |
| 1548 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1549 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1550 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1551 | return -EOPNOTSUPP; |
| 1552 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1553 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1554 | if (result) |
| 1555 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1556 | |
| 1557 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1558 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1559 | case NL80211_IFTYPE_AP: |
| 1560 | case NL80211_IFTYPE_P2P_GO: |
| 1561 | if (wdev->beacon_interval) { |
| 1562 | result = -EBUSY; |
| 1563 | break; |
| 1564 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1565 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1566 | result = -EINVAL; |
| 1567 | break; |
| 1568 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1569 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1570 | result = 0; |
| 1571 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1572 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1573 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1574 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1575 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1576 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1577 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1578 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1579 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1580 | } |
| 1581 | mutex_unlock(&rdev->devlist_mtx); |
| 1582 | |
| 1583 | return result; |
| 1584 | } |
| 1585 | |
| 1586 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1587 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1589 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1590 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1591 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1592 | } |
| 1593 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1594 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1595 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1597 | struct net_device *dev = info->user_ptr[1]; |
| 1598 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1599 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1600 | |
| 1601 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1602 | return -EINVAL; |
| 1603 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1604 | if (netif_running(dev)) |
| 1605 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1606 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1607 | if (!rdev->ops->set_wds_peer) |
| 1608 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1609 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1610 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1611 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1612 | |
| 1613 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1614 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1619 | { |
| 1620 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1621 | struct net_device *netdev = NULL; |
| 1622 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1623 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1624 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1625 | u32 changed; |
| 1626 | u8 retry_short = 0, retry_long = 0; |
| 1627 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1628 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1629 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1630 | /* |
| 1631 | * Try to find the wiphy and netdev. Normally this |
| 1632 | * function shouldn't need the netdev, but this is |
| 1633 | * done for backward compatibility -- previously |
| 1634 | * setting the channel was done per wiphy, but now |
| 1635 | * it is per netdev. Previous userland like hostapd |
| 1636 | * also passed a netdev to set_wiphy, so that it is |
| 1637 | * possible to let that go to the right netdev! |
| 1638 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1639 | mutex_lock(&cfg80211_mutex); |
| 1640 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1641 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1642 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1643 | |
| 1644 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1645 | if (netdev && netdev->ieee80211_ptr) { |
| 1646 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1647 | mutex_lock(&rdev->mtx); |
| 1648 | } else |
| 1649 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1652 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1653 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1654 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1655 | if (IS_ERR(rdev)) { |
| 1656 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1657 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1658 | } |
| 1659 | wdev = NULL; |
| 1660 | netdev = NULL; |
| 1661 | result = 0; |
| 1662 | |
| 1663 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1664 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1665 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1666 | |
| 1667 | /* |
| 1668 | * end workaround code, by now the rdev is available |
| 1669 | * and locked, and wdev may or may not be NULL. |
| 1670 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1671 | |
| 1672 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1673 | result = cfg80211_dev_rename( |
| 1674 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1675 | |
| 1676 | mutex_unlock(&cfg80211_mutex); |
| 1677 | |
| 1678 | if (result) |
| 1679 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1680 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1681 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1682 | struct ieee80211_txq_params txq_params; |
| 1683 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1684 | |
| 1685 | if (!rdev->ops->set_txq_params) { |
| 1686 | result = -EOPNOTSUPP; |
| 1687 | goto bad_res; |
| 1688 | } |
| 1689 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1690 | if (!netdev) { |
| 1691 | result = -EINVAL; |
| 1692 | goto bad_res; |
| 1693 | } |
| 1694 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1695 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1696 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1697 | result = -EINVAL; |
| 1698 | goto bad_res; |
| 1699 | } |
| 1700 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1701 | if (!netif_running(netdev)) { |
| 1702 | result = -ENETDOWN; |
| 1703 | goto bad_res; |
| 1704 | } |
| 1705 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1706 | nla_for_each_nested(nl_txq_params, |
| 1707 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1708 | rem_txq_params) { |
| 1709 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1710 | nla_data(nl_txq_params), |
| 1711 | nla_len(nl_txq_params), |
| 1712 | txq_params_policy); |
| 1713 | result = parse_txq_params(tb, &txq_params); |
| 1714 | if (result) |
| 1715 | goto bad_res; |
| 1716 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1717 | result = rdev_set_txq_params(rdev, netdev, |
| 1718 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1719 | if (result) |
| 1720 | goto bad_res; |
| 1721 | } |
| 1722 | } |
| 1723 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1724 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1725 | result = __nl80211_set_channel(rdev, |
| 1726 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1727 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1728 | if (result) |
| 1729 | goto bad_res; |
| 1730 | } |
| 1731 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1732 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1733 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1734 | enum nl80211_tx_power_setting type; |
| 1735 | int idx, mbm = 0; |
| 1736 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1737 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1738 | txp_wdev = NULL; |
| 1739 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1740 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1741 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1742 | goto bad_res; |
| 1743 | } |
| 1744 | |
| 1745 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1746 | type = nla_get_u32(info->attrs[idx]); |
| 1747 | |
| 1748 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1749 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1750 | result = -EINVAL; |
| 1751 | goto bad_res; |
| 1752 | } |
| 1753 | |
| 1754 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1755 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1756 | mbm = nla_get_u32(info->attrs[idx]); |
| 1757 | } |
| 1758 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1759 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1760 | if (result) |
| 1761 | goto bad_res; |
| 1762 | } |
| 1763 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1764 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1765 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1766 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1767 | if ((!rdev->wiphy.available_antennas_tx && |
| 1768 | !rdev->wiphy.available_antennas_rx) || |
| 1769 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1770 | result = -EOPNOTSUPP; |
| 1771 | goto bad_res; |
| 1772 | } |
| 1773 | |
| 1774 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1775 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1776 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1777 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1778 | * available antenna masks, except for the "all" mask */ |
| 1779 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1780 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1781 | result = -EINVAL; |
| 1782 | goto bad_res; |
| 1783 | } |
| 1784 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1785 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1786 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1787 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1788 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1789 | if (result) |
| 1790 | goto bad_res; |
| 1791 | } |
| 1792 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1793 | changed = 0; |
| 1794 | |
| 1795 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1796 | retry_short = nla_get_u8( |
| 1797 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1798 | if (retry_short == 0) { |
| 1799 | result = -EINVAL; |
| 1800 | goto bad_res; |
| 1801 | } |
| 1802 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1803 | } |
| 1804 | |
| 1805 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1806 | retry_long = nla_get_u8( |
| 1807 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1808 | if (retry_long == 0) { |
| 1809 | result = -EINVAL; |
| 1810 | goto bad_res; |
| 1811 | } |
| 1812 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1813 | } |
| 1814 | |
| 1815 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1816 | frag_threshold = nla_get_u32( |
| 1817 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1818 | if (frag_threshold < 256) { |
| 1819 | result = -EINVAL; |
| 1820 | goto bad_res; |
| 1821 | } |
| 1822 | if (frag_threshold != (u32) -1) { |
| 1823 | /* |
| 1824 | * Fragments (apart from the last one) are required to |
| 1825 | * have even length. Make the fragmentation code |
| 1826 | * simpler by stripping LSB should someone try to use |
| 1827 | * odd threshold value. |
| 1828 | */ |
| 1829 | frag_threshold &= ~0x1; |
| 1830 | } |
| 1831 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1832 | } |
| 1833 | |
| 1834 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1835 | rts_threshold = nla_get_u32( |
| 1836 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1837 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1838 | } |
| 1839 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1840 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1841 | coverage_class = nla_get_u8( |
| 1842 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1843 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1844 | } |
| 1845 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1846 | if (changed) { |
| 1847 | u8 old_retry_short, old_retry_long; |
| 1848 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1849 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1850 | |
| 1851 | if (!rdev->ops->set_wiphy_params) { |
| 1852 | result = -EOPNOTSUPP; |
| 1853 | goto bad_res; |
| 1854 | } |
| 1855 | |
| 1856 | old_retry_short = rdev->wiphy.retry_short; |
| 1857 | old_retry_long = rdev->wiphy.retry_long; |
| 1858 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1859 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1860 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1861 | |
| 1862 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1863 | rdev->wiphy.retry_short = retry_short; |
| 1864 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1865 | rdev->wiphy.retry_long = retry_long; |
| 1866 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1867 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1868 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1869 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1870 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1871 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1872 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1873 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1874 | if (result) { |
| 1875 | rdev->wiphy.retry_short = old_retry_short; |
| 1876 | rdev->wiphy.retry_long = old_retry_long; |
| 1877 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1878 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1879 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1880 | } |
| 1881 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1882 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1883 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1884 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1885 | if (netdev) |
| 1886 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1887 | return result; |
| 1888 | } |
| 1889 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1890 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1891 | { |
| 1892 | return (u64)wdev->identifier | |
| 1893 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1894 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1895 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1896 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1897 | struct cfg80211_chan_def *chandef) |
| 1898 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1899 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1900 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1901 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1902 | chandef->chan->center_freq)) |
| 1903 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1904 | switch (chandef->width) { |
| 1905 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1906 | case NL80211_CHAN_WIDTH_20: |
| 1907 | case NL80211_CHAN_WIDTH_40: |
| 1908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1909 | cfg80211_get_chandef_type(chandef))) |
| 1910 | return -ENOBUFS; |
| 1911 | break; |
| 1912 | default: |
| 1913 | break; |
| 1914 | } |
| 1915 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1916 | return -ENOBUFS; |
| 1917 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1918 | return -ENOBUFS; |
| 1919 | if (chandef->center_freq2 && |
| 1920 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1921 | return -ENOBUFS; |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1925 | 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] | 1926 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1927 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1928 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1929 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1930 | void *hdr; |
| 1931 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1932 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1933 | if (!hdr) |
| 1934 | return -1; |
| 1935 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1936 | if (dev && |
| 1937 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1938 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1939 | goto nla_put_failure; |
| 1940 | |
| 1941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1942 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1943 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1944 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1945 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1946 | rdev->devlist_generation ^ |
| 1947 | (cfg80211_rdev_list_generation << 2))) |
| 1948 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1949 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1950 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1951 | int ret; |
| 1952 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1953 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1954 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1955 | if (ret == 0) { |
| 1956 | if (nl80211_send_chandef(msg, &chandef)) |
| 1957 | goto nla_put_failure; |
| 1958 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1959 | } |
| 1960 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1961 | if (wdev->ssid_len) { |
| 1962 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1963 | goto nla_put_failure; |
| 1964 | } |
| 1965 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1966 | return genlmsg_end(msg, hdr); |
| 1967 | |
| 1968 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1969 | genlmsg_cancel(msg, hdr); |
| 1970 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1974 | { |
| 1975 | int wp_idx = 0; |
| 1976 | int if_idx = 0; |
| 1977 | int wp_start = cb->args[0]; |
| 1978 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1979 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1980 | struct wireless_dev *wdev; |
| 1981 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1982 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1983 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1984 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1985 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1986 | if (wp_idx < wp_start) { |
| 1987 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1988 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1989 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1990 | if_idx = 0; |
| 1991 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1992 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1993 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1994 | if (if_idx < if_start) { |
| 1995 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1996 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1997 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1998 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1999 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2000 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2001 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2002 | goto out; |
| 2003 | } |
| 2004 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2005 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2006 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2007 | |
| 2008 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2009 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2010 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2011 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2012 | |
| 2013 | cb->args[0] = wp_idx; |
| 2014 | cb->args[1] = if_idx; |
| 2015 | |
| 2016 | return skb->len; |
| 2017 | } |
| 2018 | |
| 2019 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2020 | { |
| 2021 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2022 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2023 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2024 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2026 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2028 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2029 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2030 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2031 | nlmsg_free(msg); |
| 2032 | return -ENOBUFS; |
| 2033 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2034 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2035 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2038 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2039 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2040 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2041 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2042 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2043 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2044 | }; |
| 2045 | |
| 2046 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2047 | { |
| 2048 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2049 | int flag; |
| 2050 | |
| 2051 | *mntrflags = 0; |
| 2052 | |
| 2053 | if (!nla) |
| 2054 | return -EINVAL; |
| 2055 | |
| 2056 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2057 | nla, mntr_flags_policy)) |
| 2058 | return -EINVAL; |
| 2059 | |
| 2060 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2061 | if (flags[flag]) |
| 2062 | *mntrflags |= (1<<flag); |
| 2063 | |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2067 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2068 | struct net_device *netdev, u8 use_4addr, |
| 2069 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2070 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2071 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2072 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2073 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2074 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2075 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2076 | |
| 2077 | switch (iftype) { |
| 2078 | case NL80211_IFTYPE_AP_VLAN: |
| 2079 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2080 | return 0; |
| 2081 | break; |
| 2082 | case NL80211_IFTYPE_STATION: |
| 2083 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2084 | return 0; |
| 2085 | break; |
| 2086 | default: |
| 2087 | break; |
| 2088 | } |
| 2089 | |
| 2090 | return -EOPNOTSUPP; |
| 2091 | } |
| 2092 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2093 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2094 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2096 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2097 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2098 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2099 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2100 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2101 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2102 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2103 | memset(¶ms, 0, sizeof(params)); |
| 2104 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2105 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2106 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2107 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2108 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2109 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2110 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2111 | if (ntype > NL80211_IFTYPE_MAX) |
| 2112 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2115 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2116 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2118 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2119 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2120 | if (netif_running(dev)) |
| 2121 | return -EBUSY; |
| 2122 | |
| 2123 | wdev_lock(wdev); |
| 2124 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2125 | IEEE80211_MAX_MESH_ID_LEN); |
| 2126 | wdev->mesh_id_up_len = |
| 2127 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2128 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2129 | wdev->mesh_id_up_len); |
| 2130 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2133 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2134 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2135 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2136 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2137 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2139 | } else { |
| 2140 | params.use_4addr = -1; |
| 2141 | } |
| 2142 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2143 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2144 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2145 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2146 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2147 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2148 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2149 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2150 | |
| 2151 | flags = &_flags; |
| 2152 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2153 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2154 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2155 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2156 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2157 | else |
| 2158 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2159 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2160 | if (!err && params.use_4addr != -1) |
| 2161 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2162 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2163 | return err; |
| 2164 | } |
| 2165 | |
| 2166 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2167 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2168 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2169 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2170 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2171 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2172 | int err; |
| 2173 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2174 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2175 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2176 | memset(¶ms, 0, sizeof(params)); |
| 2177 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2178 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2179 | return -EINVAL; |
| 2180 | |
| 2181 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2182 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2183 | if (type > NL80211_IFTYPE_MAX) |
| 2184 | return -EINVAL; |
| 2185 | } |
| 2186 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2187 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2188 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2189 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2190 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2191 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2192 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2193 | ETH_ALEN); |
| 2194 | if (!is_valid_ether_addr(params.macaddr)) |
| 2195 | return -EADDRNOTAVAIL; |
| 2196 | } |
| 2197 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2198 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2199 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2200 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2201 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2202 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2203 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2204 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2205 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2206 | if (!msg) |
| 2207 | return -ENOMEM; |
| 2208 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2209 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2210 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2211 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2212 | wdev = rdev_add_virtual_intf(rdev, |
| 2213 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2214 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2215 | if (IS_ERR(wdev)) { |
| 2216 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2217 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2218 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2219 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2220 | switch (type) { |
| 2221 | case NL80211_IFTYPE_MESH_POINT: |
| 2222 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2223 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2224 | wdev_lock(wdev); |
| 2225 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2226 | IEEE80211_MAX_MESH_ID_LEN); |
| 2227 | wdev->mesh_id_up_len = |
| 2228 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2229 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2230 | wdev->mesh_id_up_len); |
| 2231 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2232 | break; |
| 2233 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2234 | /* |
| 2235 | * P2P Device doesn't have a netdev, so doesn't go |
| 2236 | * through the netdev notifier and must be added here |
| 2237 | */ |
| 2238 | mutex_init(&wdev->mtx); |
| 2239 | INIT_LIST_HEAD(&wdev->event_list); |
| 2240 | spin_lock_init(&wdev->event_lock); |
| 2241 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2242 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2243 | |
| 2244 | mutex_lock(&rdev->devlist_mtx); |
| 2245 | wdev->identifier = ++rdev->wdev_id; |
| 2246 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2247 | rdev->devlist_generation++; |
| 2248 | mutex_unlock(&rdev->devlist_mtx); |
| 2249 | break; |
| 2250 | default: |
| 2251 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2252 | } |
| 2253 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2254 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2255 | rdev, wdev) < 0) { |
| 2256 | nlmsg_free(msg); |
| 2257 | return -ENOBUFS; |
| 2258 | } |
| 2259 | |
| 2260 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2264 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2266 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2267 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2268 | if (!rdev->ops->del_virtual_intf) |
| 2269 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2270 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2271 | /* |
| 2272 | * If we remove a wireless device without a netdev then clear |
| 2273 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2274 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2275 | * since the wdev has been freed, unlike with a netdev where |
| 2276 | * we need the dev_put() for the netdev to really be freed. |
| 2277 | */ |
| 2278 | if (!wdev->netdev) |
| 2279 | info->user_ptr[1] = NULL; |
| 2280 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2281 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2282 | } |
| 2283 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2284 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2285 | { |
| 2286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2287 | struct net_device *dev = info->user_ptr[1]; |
| 2288 | u16 noack_map; |
| 2289 | |
| 2290 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2291 | return -EINVAL; |
| 2292 | |
| 2293 | if (!rdev->ops->set_noack_map) |
| 2294 | return -EOPNOTSUPP; |
| 2295 | |
| 2296 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2297 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2298 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2301 | struct get_key_cookie { |
| 2302 | struct sk_buff *msg; |
| 2303 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2304 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2305 | }; |
| 2306 | |
| 2307 | static void get_key_callback(void *c, struct key_params *params) |
| 2308 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2309 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2310 | struct get_key_cookie *cookie = c; |
| 2311 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2312 | if ((params->key && |
| 2313 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2314 | params->key_len, params->key)) || |
| 2315 | (params->seq && |
| 2316 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2317 | params->seq_len, params->seq)) || |
| 2318 | (params->cipher && |
| 2319 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2320 | params->cipher))) |
| 2321 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2322 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2323 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2324 | if (!key) |
| 2325 | goto nla_put_failure; |
| 2326 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2327 | if ((params->key && |
| 2328 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2329 | params->key_len, params->key)) || |
| 2330 | (params->seq && |
| 2331 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2332 | params->seq_len, params->seq)) || |
| 2333 | (params->cipher && |
| 2334 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2335 | params->cipher))) |
| 2336 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2337 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2338 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2339 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2340 | |
| 2341 | nla_nest_end(cookie->msg, key); |
| 2342 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2343 | return; |
| 2344 | nla_put_failure: |
| 2345 | cookie->error = 1; |
| 2346 | } |
| 2347 | |
| 2348 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2349 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2351 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2352 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2353 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2354 | const u8 *mac_addr = NULL; |
| 2355 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2356 | struct get_key_cookie cookie = { |
| 2357 | .error = 0, |
| 2358 | }; |
| 2359 | void *hdr; |
| 2360 | struct sk_buff *msg; |
| 2361 | |
| 2362 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2363 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2364 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2365 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2366 | return -EINVAL; |
| 2367 | |
| 2368 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2369 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2370 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2371 | pairwise = !!mac_addr; |
| 2372 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2373 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2374 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2375 | return -EINVAL; |
| 2376 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2377 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2378 | return -EINVAL; |
| 2379 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2380 | } |
| 2381 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | if (!rdev->ops->get_key) |
| 2383 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2384 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2386 | if (!msg) |
| 2387 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2388 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2389 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2390 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2391 | if (IS_ERR(hdr)) |
| 2392 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2393 | |
| 2394 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2395 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2396 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2397 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2398 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2399 | goto nla_put_failure; |
| 2400 | if (mac_addr && |
| 2401 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2402 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2403 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2404 | if (pairwise && mac_addr && |
| 2405 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2406 | return -ENOENT; |
| 2407 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2408 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2409 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2410 | |
| 2411 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2412 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2413 | |
| 2414 | if (cookie.error) |
| 2415 | goto nla_put_failure; |
| 2416 | |
| 2417 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2418 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2419 | |
| 2420 | nla_put_failure: |
| 2421 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2422 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2423 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2424 | return err; |
| 2425 | } |
| 2426 | |
| 2427 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2428 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2430 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2431 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2432 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2433 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2434 | err = nl80211_parse_key(info, &key); |
| 2435 | if (err) |
| 2436 | return err; |
| 2437 | |
| 2438 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2439 | return -EINVAL; |
| 2440 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2441 | /* only support setting default key */ |
| 2442 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2443 | return -EINVAL; |
| 2444 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2445 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2446 | |
| 2447 | if (key.def) { |
| 2448 | if (!rdev->ops->set_default_key) { |
| 2449 | err = -EOPNOTSUPP; |
| 2450 | goto out; |
| 2451 | } |
| 2452 | |
| 2453 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2454 | if (err) |
| 2455 | goto out; |
| 2456 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2457 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2458 | key.def_uni, key.def_multi); |
| 2459 | |
| 2460 | if (err) |
| 2461 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2462 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2463 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2464 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2465 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2466 | } else { |
| 2467 | if (key.def_uni || !key.def_multi) { |
| 2468 | err = -EINVAL; |
| 2469 | goto out; |
| 2470 | } |
| 2471 | |
| 2472 | if (!rdev->ops->set_default_mgmt_key) { |
| 2473 | err = -EOPNOTSUPP; |
| 2474 | goto out; |
| 2475 | } |
| 2476 | |
| 2477 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2478 | if (err) |
| 2479 | goto out; |
| 2480 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2481 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2482 | if (err) |
| 2483 | goto out; |
| 2484 | |
| 2485 | #ifdef CONFIG_CFG80211_WEXT |
| 2486 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2487 | #endif |
| 2488 | } |
| 2489 | |
| 2490 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2491 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2492 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2493 | return err; |
| 2494 | } |
| 2495 | |
| 2496 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2497 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2499 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2500 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2501 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2502 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2503 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2504 | err = nl80211_parse_key(info, &key); |
| 2505 | if (err) |
| 2506 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2507 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2508 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2509 | return -EINVAL; |
| 2510 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2511 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2512 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2513 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2514 | if (key.type == -1) { |
| 2515 | if (mac_addr) |
| 2516 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2517 | else |
| 2518 | key.type = NL80211_KEYTYPE_GROUP; |
| 2519 | } |
| 2520 | |
| 2521 | /* for now */ |
| 2522 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2523 | key.type != NL80211_KEYTYPE_GROUP) |
| 2524 | return -EINVAL; |
| 2525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2526 | if (!rdev->ops->add_key) |
| 2527 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2528 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2529 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2530 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2531 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2532 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2533 | |
| 2534 | wdev_lock(dev->ieee80211_ptr); |
| 2535 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2536 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2537 | err = rdev_add_key(rdev, dev, key.idx, |
| 2538 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2539 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2540 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2541 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2542 | return err; |
| 2543 | } |
| 2544 | |
| 2545 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2546 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2548 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2549 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2550 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2551 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2552 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2553 | err = nl80211_parse_key(info, &key); |
| 2554 | if (err) |
| 2555 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2556 | |
| 2557 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2558 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2559 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2560 | if (key.type == -1) { |
| 2561 | if (mac_addr) |
| 2562 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2563 | else |
| 2564 | key.type = NL80211_KEYTYPE_GROUP; |
| 2565 | } |
| 2566 | |
| 2567 | /* for now */ |
| 2568 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2569 | key.type != NL80211_KEYTYPE_GROUP) |
| 2570 | return -EINVAL; |
| 2571 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2572 | if (!rdev->ops->del_key) |
| 2573 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2574 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2575 | wdev_lock(dev->ieee80211_ptr); |
| 2576 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2577 | |
| 2578 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2579 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2580 | err = -ENOENT; |
| 2581 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2582 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2583 | err = rdev_del_key(rdev, dev, key.idx, |
| 2584 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2585 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2586 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2587 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2588 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2589 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2590 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2591 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2592 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2593 | } |
| 2594 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2595 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2596 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2597 | return err; |
| 2598 | } |
| 2599 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2600 | /* This function returns an error or the number of nested attributes */ |
| 2601 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2602 | { |
| 2603 | struct nlattr *attr; |
| 2604 | int n_entries = 0, tmp; |
| 2605 | |
| 2606 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2607 | if (nla_len(attr) != ETH_ALEN) |
| 2608 | return -EINVAL; |
| 2609 | |
| 2610 | n_entries++; |
| 2611 | } |
| 2612 | |
| 2613 | return n_entries; |
| 2614 | } |
| 2615 | |
| 2616 | /* |
| 2617 | * This function parses ACL information and allocates memory for ACL data. |
| 2618 | * On successful return, the calling function is responsible to free the |
| 2619 | * ACL buffer returned by this function. |
| 2620 | */ |
| 2621 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2622 | struct genl_info *info) |
| 2623 | { |
| 2624 | enum nl80211_acl_policy acl_policy; |
| 2625 | struct nlattr *attr; |
| 2626 | struct cfg80211_acl_data *acl; |
| 2627 | int i = 0, n_entries, tmp; |
| 2628 | |
| 2629 | if (!wiphy->max_acl_mac_addrs) |
| 2630 | return ERR_PTR(-EOPNOTSUPP); |
| 2631 | |
| 2632 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2633 | return ERR_PTR(-EINVAL); |
| 2634 | |
| 2635 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2636 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2637 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2638 | return ERR_PTR(-EINVAL); |
| 2639 | |
| 2640 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2641 | return ERR_PTR(-EINVAL); |
| 2642 | |
| 2643 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2644 | if (n_entries < 0) |
| 2645 | return ERR_PTR(n_entries); |
| 2646 | |
| 2647 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2648 | return ERR_PTR(-ENOTSUPP); |
| 2649 | |
| 2650 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2651 | GFP_KERNEL); |
| 2652 | if (!acl) |
| 2653 | return ERR_PTR(-ENOMEM); |
| 2654 | |
| 2655 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2656 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2657 | i++; |
| 2658 | } |
| 2659 | |
| 2660 | acl->n_acl_entries = n_entries; |
| 2661 | acl->acl_policy = acl_policy; |
| 2662 | |
| 2663 | return acl; |
| 2664 | } |
| 2665 | |
| 2666 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2667 | { |
| 2668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2669 | struct net_device *dev = info->user_ptr[1]; |
| 2670 | struct cfg80211_acl_data *acl; |
| 2671 | int err; |
| 2672 | |
| 2673 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2674 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2675 | return -EOPNOTSUPP; |
| 2676 | |
| 2677 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2678 | return -EINVAL; |
| 2679 | |
| 2680 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2681 | if (IS_ERR(acl)) |
| 2682 | return PTR_ERR(acl); |
| 2683 | |
| 2684 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2685 | |
| 2686 | kfree(acl); |
| 2687 | |
| 2688 | return err; |
| 2689 | } |
| 2690 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2691 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2692 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2693 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2694 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2695 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2696 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2697 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2698 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2699 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2700 | return -EINVAL; |
| 2701 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2702 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2703 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2704 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2705 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2706 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2707 | if (!bcn->head_len) |
| 2708 | return -EINVAL; |
| 2709 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2713 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2714 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2715 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2716 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2717 | } |
| 2718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2719 | if (!haveinfo) |
| 2720 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2721 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2722 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2723 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2724 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2728 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2729 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2730 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2731 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2732 | } |
| 2733 | |
| 2734 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2735 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2736 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2737 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2738 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2739 | } |
| 2740 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2741 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2742 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2743 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2744 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2745 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2746 | } |
| 2747 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2748 | return 0; |
| 2749 | } |
| 2750 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2751 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2752 | struct cfg80211_ap_settings *params) |
| 2753 | { |
| 2754 | struct wireless_dev *wdev; |
| 2755 | bool ret = false; |
| 2756 | |
| 2757 | mutex_lock(&rdev->devlist_mtx); |
| 2758 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2759 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2760 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2761 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2762 | continue; |
| 2763 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2764 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2765 | continue; |
| 2766 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2767 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2768 | ret = true; |
| 2769 | break; |
| 2770 | } |
| 2771 | |
| 2772 | mutex_unlock(&rdev->devlist_mtx); |
| 2773 | |
| 2774 | return ret; |
| 2775 | } |
| 2776 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2777 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2778 | enum nl80211_auth_type auth_type, |
| 2779 | enum nl80211_commands cmd) |
| 2780 | { |
| 2781 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2782 | return false; |
| 2783 | |
| 2784 | switch (cmd) { |
| 2785 | case NL80211_CMD_AUTHENTICATE: |
| 2786 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2787 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2788 | return false; |
| 2789 | return true; |
| 2790 | case NL80211_CMD_CONNECT: |
| 2791 | case NL80211_CMD_START_AP: |
| 2792 | /* SAE not supported yet */ |
| 2793 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2794 | return false; |
| 2795 | return true; |
| 2796 | default: |
| 2797 | return false; |
| 2798 | } |
| 2799 | } |
| 2800 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2801 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2802 | { |
| 2803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2804 | struct net_device *dev = info->user_ptr[1]; |
| 2805 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2806 | struct cfg80211_ap_settings params; |
| 2807 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2808 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2809 | |
| 2810 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2811 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2812 | return -EOPNOTSUPP; |
| 2813 | |
| 2814 | if (!rdev->ops->start_ap) |
| 2815 | return -EOPNOTSUPP; |
| 2816 | |
| 2817 | if (wdev->beacon_interval) |
| 2818 | return -EALREADY; |
| 2819 | |
| 2820 | memset(¶ms, 0, sizeof(params)); |
| 2821 | |
| 2822 | /* these are required for START_AP */ |
| 2823 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2824 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2825 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2826 | return -EINVAL; |
| 2827 | |
| 2828 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2829 | if (err) |
| 2830 | return err; |
| 2831 | |
| 2832 | params.beacon_interval = |
| 2833 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2834 | params.dtim_period = |
| 2835 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2836 | |
| 2837 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2838 | if (err) |
| 2839 | return err; |
| 2840 | |
| 2841 | /* |
| 2842 | * In theory, some of these attributes should be required here |
| 2843 | * but since they were not used when the command was originally |
| 2844 | * added, keep them optional for old user space programs to let |
| 2845 | * them continue to work with drivers that do not need the |
| 2846 | * additional information -- drivers must check! |
| 2847 | */ |
| 2848 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2849 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2850 | params.ssid_len = |
| 2851 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2852 | if (params.ssid_len == 0 || |
| 2853 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2854 | return -EINVAL; |
| 2855 | } |
| 2856 | |
| 2857 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2858 | params.hidden_ssid = nla_get_u32( |
| 2859 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2860 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2861 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2862 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2863 | return -EINVAL; |
| 2864 | } |
| 2865 | |
| 2866 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2867 | |
| 2868 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2869 | params.auth_type = nla_get_u32( |
| 2870 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2871 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2872 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2873 | return -EINVAL; |
| 2874 | } else |
| 2875 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2876 | |
| 2877 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2878 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2879 | if (err) |
| 2880 | return err; |
| 2881 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2882 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2883 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2884 | return -EOPNOTSUPP; |
| 2885 | params.inactivity_timeout = nla_get_u16( |
| 2886 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2887 | } |
| 2888 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2889 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2890 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2891 | return -EINVAL; |
| 2892 | params.p2p_ctwindow = |
| 2893 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2894 | if (params.p2p_ctwindow > 127) |
| 2895 | return -EINVAL; |
| 2896 | if (params.p2p_ctwindow != 0 && |
| 2897 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2898 | return -EINVAL; |
| 2899 | } |
| 2900 | |
| 2901 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2902 | u8 tmp; |
| 2903 | |
| 2904 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2905 | return -EINVAL; |
| 2906 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2907 | if (tmp > 1) |
| 2908 | return -EINVAL; |
| 2909 | params.p2p_opp_ps = tmp; |
| 2910 | if (params.p2p_opp_ps != 0 && |
| 2911 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2912 | return -EINVAL; |
| 2913 | } |
| 2914 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2915 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2916 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2917 | if (err) |
| 2918 | return err; |
| 2919 | } else if (wdev->preset_chandef.chan) { |
| 2920 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2921 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2922 | return -EINVAL; |
| 2923 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2924 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2925 | return -EINVAL; |
| 2926 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2927 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 2928 | if (err < 0) |
| 2929 | return err; |
| 2930 | if (err) { |
| 2931 | radar_detect_width = BIT(params.chandef.width); |
| 2932 | params.radar_required = true; |
| 2933 | } |
| 2934 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2935 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2936 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 2937 | params.chandef.chan, |
| 2938 | CHAN_MODE_SHARED, |
| 2939 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2940 | mutex_unlock(&rdev->devlist_mtx); |
| 2941 | |
| 2942 | if (err) |
| 2943 | return err; |
| 2944 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2945 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 2946 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 2947 | if (IS_ERR(params.acl)) |
| 2948 | return PTR_ERR(params.acl); |
| 2949 | } |
| 2950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2951 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2952 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2953 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2954 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2955 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2956 | wdev->ssid_len = params.ssid_len; |
| 2957 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2958 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2959 | |
| 2960 | kfree(params.acl); |
| 2961 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2962 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2963 | } |
| 2964 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2965 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2966 | { |
| 2967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2968 | struct net_device *dev = info->user_ptr[1]; |
| 2969 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2970 | struct cfg80211_beacon_data params; |
| 2971 | int err; |
| 2972 | |
| 2973 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2974 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2975 | return -EOPNOTSUPP; |
| 2976 | |
| 2977 | if (!rdev->ops->change_beacon) |
| 2978 | return -EOPNOTSUPP; |
| 2979 | |
| 2980 | if (!wdev->beacon_interval) |
| 2981 | return -EINVAL; |
| 2982 | |
| 2983 | err = nl80211_parse_beacon(info, ¶ms); |
| 2984 | if (err) |
| 2985 | return err; |
| 2986 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2987 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | 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] | 2991 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2993 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2994 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2995 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2996 | } |
| 2997 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2998 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2999 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3000 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3001 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3002 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3003 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3004 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3005 | }; |
| 3006 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3007 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3008 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3009 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3010 | { |
| 3011 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3012 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3013 | int flag; |
| 3014 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3015 | /* |
| 3016 | * Try parsing the new attribute first so userspace |
| 3017 | * can specify both for older kernels. |
| 3018 | */ |
| 3019 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3020 | if (nla) { |
| 3021 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3022 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3023 | sta_flags = nla_data(nla); |
| 3024 | params->sta_flags_mask = sta_flags->mask; |
| 3025 | params->sta_flags_set = sta_flags->set; |
| 3026 | if ((params->sta_flags_mask | |
| 3027 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3028 | return -EINVAL; |
| 3029 | return 0; |
| 3030 | } |
| 3031 | |
| 3032 | /* if present, parse the old attribute */ |
| 3033 | |
| 3034 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3035 | if (!nla) |
| 3036 | return 0; |
| 3037 | |
| 3038 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3039 | nla, sta_flags_policy)) |
| 3040 | return -EINVAL; |
| 3041 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3042 | /* |
| 3043 | * Only allow certain flags for interface types so that |
| 3044 | * other attributes are silently ignored. Remember that |
| 3045 | * this is backward compatibility code with old userspace |
| 3046 | * and shouldn't be hit in other cases anyway. |
| 3047 | */ |
| 3048 | switch (iftype) { |
| 3049 | case NL80211_IFTYPE_AP: |
| 3050 | case NL80211_IFTYPE_AP_VLAN: |
| 3051 | case NL80211_IFTYPE_P2P_GO: |
| 3052 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3053 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3054 | BIT(NL80211_STA_FLAG_WME) | |
| 3055 | BIT(NL80211_STA_FLAG_MFP); |
| 3056 | break; |
| 3057 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3058 | case NL80211_IFTYPE_STATION: |
| 3059 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3060 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3061 | break; |
| 3062 | case NL80211_IFTYPE_MESH_POINT: |
| 3063 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3064 | BIT(NL80211_STA_FLAG_MFP) | |
| 3065 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3066 | default: |
| 3067 | return -EINVAL; |
| 3068 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3069 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3070 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3071 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3072 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3073 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3074 | /* no longer support new API additions in old API */ |
| 3075 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3076 | return -EINVAL; |
| 3077 | } |
| 3078 | } |
| 3079 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3080 | return 0; |
| 3081 | } |
| 3082 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3083 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3084 | int attr) |
| 3085 | { |
| 3086 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3087 | u32 bitrate; |
| 3088 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3089 | |
| 3090 | rate = nla_nest_start(msg, attr); |
| 3091 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3092 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3093 | |
| 3094 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3095 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3096 | /* report 16-bit bitrate only if we can */ |
| 3097 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3098 | if (bitrate > 0 && |
| 3099 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3100 | return false; |
| 3101 | if (bitrate_compat > 0 && |
| 3102 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3103 | return false; |
| 3104 | |
| 3105 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3106 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3107 | return false; |
| 3108 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3109 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3110 | return false; |
| 3111 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3112 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3113 | return false; |
| 3114 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3115 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3116 | return false; |
| 3117 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3118 | return false; |
| 3119 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3120 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3121 | return false; |
| 3122 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3123 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3124 | return false; |
| 3125 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3126 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3127 | return false; |
| 3128 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3129 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3130 | return false; |
| 3131 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3132 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3133 | return false; |
| 3134 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3135 | |
| 3136 | nla_nest_end(msg, rate); |
| 3137 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3138 | } |
| 3139 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3140 | 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] | 3141 | int flags, |
| 3142 | struct cfg80211_registered_device *rdev, |
| 3143 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3144 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3145 | { |
| 3146 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3147 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3148 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3149 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3150 | if (!hdr) |
| 3151 | return -1; |
| 3152 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3153 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3154 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3155 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3156 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3157 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3158 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3159 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3160 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3161 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3162 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3163 | sinfo->connected_time)) |
| 3164 | goto nla_put_failure; |
| 3165 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3166 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3167 | sinfo->inactive_time)) |
| 3168 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3169 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3170 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3171 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3172 | (u32)sinfo->rx_bytes)) |
| 3173 | goto nla_put_failure; |
| 3174 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3175 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3176 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3177 | (u32)sinfo->tx_bytes)) |
| 3178 | goto nla_put_failure; |
| 3179 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3180 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3181 | sinfo->rx_bytes)) |
| 3182 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3183 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3184 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3185 | sinfo->tx_bytes)) |
| 3186 | goto nla_put_failure; |
| 3187 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3188 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3189 | goto nla_put_failure; |
| 3190 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3191 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3192 | goto nla_put_failure; |
| 3193 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3194 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3195 | sinfo->plink_state)) |
| 3196 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3197 | switch (rdev->wiphy.signal_type) { |
| 3198 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3199 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3200 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3201 | sinfo->signal)) |
| 3202 | goto nla_put_failure; |
| 3203 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3204 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3205 | sinfo->signal_avg)) |
| 3206 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3207 | break; |
| 3208 | default: |
| 3209 | break; |
| 3210 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3211 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3212 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3213 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3214 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3215 | } |
| 3216 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3217 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3218 | NL80211_STA_INFO_RX_BITRATE)) |
| 3219 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3220 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3221 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3222 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3223 | sinfo->rx_packets)) |
| 3224 | goto nla_put_failure; |
| 3225 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3226 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3227 | sinfo->tx_packets)) |
| 3228 | goto nla_put_failure; |
| 3229 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3230 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3231 | sinfo->tx_retries)) |
| 3232 | goto nla_put_failure; |
| 3233 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3234 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3235 | sinfo->tx_failed)) |
| 3236 | goto nla_put_failure; |
| 3237 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3238 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3239 | sinfo->beacon_loss_count)) |
| 3240 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3241 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3242 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3243 | sinfo->local_pm)) |
| 3244 | goto nla_put_failure; |
| 3245 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3246 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3247 | sinfo->peer_pm)) |
| 3248 | goto nla_put_failure; |
| 3249 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3250 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3251 | sinfo->nonpeer_pm)) |
| 3252 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3253 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3254 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3255 | if (!bss_param) |
| 3256 | goto nla_put_failure; |
| 3257 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3258 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3259 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3260 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3261 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3262 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3263 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3264 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3265 | sinfo->bss_param.dtim_period) || |
| 3266 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3267 | sinfo->bss_param.beacon_interval)) |
| 3268 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3269 | |
| 3270 | nla_nest_end(msg, bss_param); |
| 3271 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3272 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3273 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3274 | sizeof(struct nl80211_sta_flag_update), |
| 3275 | &sinfo->sta_flags)) |
| 3276 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3277 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3278 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3279 | sinfo->t_offset)) |
| 3280 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3281 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3282 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3283 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3284 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3285 | sinfo->assoc_req_ies)) |
| 3286 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3287 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3288 | return genlmsg_end(msg, hdr); |
| 3289 | |
| 3290 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3291 | genlmsg_cancel(msg, hdr); |
| 3292 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3293 | } |
| 3294 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3295 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3296 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3297 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3298 | struct station_info sinfo; |
| 3299 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3300 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3301 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3302 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3303 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3304 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3305 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3306 | if (err) |
| 3307 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3308 | |
| 3309 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3310 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3311 | goto out_err; |
| 3312 | } |
| 3313 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3314 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3315 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3316 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3317 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3318 | if (err == -ENOENT) |
| 3319 | break; |
| 3320 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3321 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3322 | |
| 3323 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3324 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3325 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3326 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3327 | &sinfo) < 0) |
| 3328 | goto out; |
| 3329 | |
| 3330 | sta_idx++; |
| 3331 | } |
| 3332 | |
| 3333 | |
| 3334 | out: |
| 3335 | cb->args[1] = sta_idx; |
| 3336 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3337 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3338 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3339 | |
| 3340 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3341 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3342 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3343 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3344 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3346 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3347 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3348 | struct sk_buff *msg; |
| 3349 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3350 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3351 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3352 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3353 | |
| 3354 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3355 | return -EINVAL; |
| 3356 | |
| 3357 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3358 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3359 | if (!rdev->ops->get_station) |
| 3360 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3361 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3362 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3363 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3364 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3365 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3366 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3367 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3368 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3369 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3370 | 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] | 3371 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3372 | nlmsg_free(msg); |
| 3373 | return -ENOBUFS; |
| 3374 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3376 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3380 | * 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] | 3381 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3382 | static struct net_device *get_vlan(struct genl_info *info, |
| 3383 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3384 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3385 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3386 | struct net_device *v; |
| 3387 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3388 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3389 | if (!vlanattr) |
| 3390 | return NULL; |
| 3391 | |
| 3392 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3393 | if (!v) |
| 3394 | return ERR_PTR(-ENODEV); |
| 3395 | |
| 3396 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3397 | ret = -EINVAL; |
| 3398 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3399 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3400 | |
| 3401 | if (!netif_running(v)) { |
| 3402 | ret = -ENETDOWN; |
| 3403 | goto error; |
| 3404 | } |
| 3405 | |
| 3406 | return v; |
| 3407 | error: |
| 3408 | dev_put(v); |
| 3409 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3410 | } |
| 3411 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame^] | 3412 | static struct nla_policy |
| 3413 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3414 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3415 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3416 | }; |
| 3417 | |
| 3418 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3419 | struct station_parameters *params) |
| 3420 | { |
| 3421 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3422 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3423 | struct nlattr *nla; |
| 3424 | int err; |
| 3425 | |
| 3426 | /* Can only set if TDLS ... */ |
| 3427 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3428 | return -EOPNOTSUPP; |
| 3429 | |
| 3430 | /* ... with external setup is supported */ |
| 3431 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3432 | return -EOPNOTSUPP; |
| 3433 | |
| 3434 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3435 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3436 | params->ht_capa = |
| 3437 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3438 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3439 | params->vht_capa = |
| 3440 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3441 | |
| 3442 | /* parse WME attributes if present */ |
| 3443 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3444 | return 0; |
| 3445 | |
| 3446 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3447 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3448 | nl80211_sta_wme_policy); |
| 3449 | if (err) |
| 3450 | return err; |
| 3451 | |
| 3452 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3453 | params->uapsd_queues = nla_get_u8( |
| 3454 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3455 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3456 | return -EINVAL; |
| 3457 | |
| 3458 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3459 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3460 | |
| 3461 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3462 | return -EINVAL; |
| 3463 | |
| 3464 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3465 | |
| 3466 | return 0; |
| 3467 | } |
| 3468 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3469 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3470 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3472 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3473 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3474 | struct station_parameters params; |
| 3475 | u8 *mac_addr = NULL; |
| 3476 | |
| 3477 | memset(¶ms, 0, sizeof(params)); |
| 3478 | |
| 3479 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3480 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3481 | |
| 3482 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3483 | return -EINVAL; |
| 3484 | |
| 3485 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3486 | return -EINVAL; |
| 3487 | |
| 3488 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3489 | |
| 3490 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3491 | params.supported_rates = |
| 3492 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3493 | params.supported_rates_len = |
| 3494 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3495 | } |
| 3496 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3497 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3498 | params.capability = |
| 3499 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3500 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3501 | } |
| 3502 | |
| 3503 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3504 | params.ext_capab = |
| 3505 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3506 | params.ext_capab_len = |
| 3507 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3508 | } |
| 3509 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame^] | 3510 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3511 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3512 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3513 | if (!rdev->ops->change_station) |
| 3514 | return -EOPNOTSUPP; |
| 3515 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3516 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3517 | return -EINVAL; |
| 3518 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3519 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3520 | params.plink_action = |
| 3521 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3522 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3523 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3524 | params.plink_state = |
| 3525 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3526 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3527 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3528 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3529 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3530 | |
| 3531 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3532 | pm > NL80211_MESH_POWER_MAX) |
| 3533 | return -EINVAL; |
| 3534 | |
| 3535 | params.local_pm = pm; |
| 3536 | } |
| 3537 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3538 | switch (dev->ieee80211_ptr->iftype) { |
| 3539 | case NL80211_IFTYPE_AP: |
| 3540 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3541 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3542 | /* disallow mesh-specific things */ |
| 3543 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3544 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3545 | if (params.local_pm) |
| 3546 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3547 | |
| 3548 | /* TDLS can't be set, ... */ |
| 3549 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3550 | return -EINVAL; |
| 3551 | /* |
| 3552 | * ... but don't bother the driver with it. This works around |
| 3553 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3554 | * TLDS_PEER flag in the mask even for AP mode. |
| 3555 | */ |
| 3556 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3557 | |
| 3558 | /* accept only the listed bits */ |
| 3559 | if (params.sta_flags_mask & |
| 3560 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3561 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3562 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3563 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3564 | BIT(NL80211_STA_FLAG_WME) | |
| 3565 | BIT(NL80211_STA_FLAG_MFP))) |
| 3566 | return -EINVAL; |
| 3567 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3568 | /* but authenticated/associated only if driver handles it */ |
| 3569 | if (!(rdev->wiphy.features & |
| 3570 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3571 | params.sta_flags_mask & |
| 3572 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3573 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3574 | return -EINVAL; |
| 3575 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3576 | /* reject other things that can't change */ |
| 3577 | if (params.supported_rates) |
| 3578 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3579 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3580 | return -EINVAL; |
| 3581 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3582 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame^] | 3583 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3584 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3585 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3586 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3587 | /* must be last in here for error handling */ |
| 3588 | params.vlan = get_vlan(info, rdev); |
| 3589 | if (IS_ERR(params.vlan)) |
| 3590 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3591 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3592 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3593 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3594 | /* |
| 3595 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3596 | * but silently ignore attempts to change it since we |
| 3597 | * don't have state here to verify that it doesn't try |
| 3598 | * to change the flag. |
| 3599 | */ |
| 3600 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame^] | 3601 | /* Include parameters for TDLS peer (driver will check) */ |
| 3602 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3603 | if (err) |
| 3604 | return err; |
| 3605 | /* disallow things sta doesn't support */ |
| 3606 | if (params.plink_action) |
| 3607 | return -EINVAL; |
| 3608 | if (params.local_pm) |
| 3609 | return -EINVAL; |
| 3610 | /* reject any changes other than AUTHORIZED or WME (for TDLS) */ |
| 3611 | if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3612 | BIT(NL80211_STA_FLAG_WME))) |
| 3613 | return -EINVAL; |
| 3614 | break; |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3615 | case NL80211_IFTYPE_ADHOC: |
| 3616 | /* disallow things sta doesn't support */ |
| 3617 | if (params.plink_action) |
| 3618 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3619 | if (params.local_pm) |
| 3620 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame^] | 3621 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3622 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3623 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3624 | /* reject any changes other than AUTHORIZED */ |
| 3625 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3626 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3627 | break; |
| 3628 | case NL80211_IFTYPE_MESH_POINT: |
| 3629 | /* disallow things mesh doesn't support */ |
| 3630 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3631 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3632 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3633 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3634 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3635 | return -EINVAL; |
| 3636 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3637 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame^] | 3638 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3639 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3640 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3641 | /* |
| 3642 | * No special handling for TDLS here -- the userspace |
| 3643 | * mesh code doesn't have this bug. |
| 3644 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3645 | if (params.sta_flags_mask & |
| 3646 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3647 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3648 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3649 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3650 | break; |
| 3651 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3652 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3653 | } |
| 3654 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3655 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3656 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3657 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3658 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3659 | if (params.vlan) |
| 3660 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3661 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3662 | return err; |
| 3663 | } |
| 3664 | |
| 3665 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3666 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3668 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3669 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3670 | struct station_parameters params; |
| 3671 | u8 *mac_addr = NULL; |
| 3672 | |
| 3673 | memset(¶ms, 0, sizeof(params)); |
| 3674 | |
| 3675 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3676 | return -EINVAL; |
| 3677 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3678 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3679 | return -EINVAL; |
| 3680 | |
| 3681 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3682 | return -EINVAL; |
| 3683 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3684 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3685 | return -EINVAL; |
| 3686 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3687 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3688 | params.supported_rates = |
| 3689 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3690 | params.supported_rates_len = |
| 3691 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3692 | params.listen_interval = |
| 3693 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3694 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3695 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3696 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3697 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3698 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3699 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3700 | params.capability = |
| 3701 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3702 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3703 | } |
| 3704 | |
| 3705 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3706 | params.ext_capab = |
| 3707 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3708 | params.ext_capab_len = |
| 3709 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3710 | } |
| 3711 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3712 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3713 | params.ht_capa = |
| 3714 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3715 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3716 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3717 | params.vht_capa = |
| 3718 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3719 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3720 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3721 | params.plink_action = |
| 3722 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3723 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3724 | if (!rdev->ops->add_station) |
| 3725 | return -EOPNOTSUPP; |
| 3726 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3727 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3728 | return -EINVAL; |
| 3729 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3730 | switch (dev->ieee80211_ptr->iftype) { |
| 3731 | case NL80211_IFTYPE_AP: |
| 3732 | case NL80211_IFTYPE_AP_VLAN: |
| 3733 | case NL80211_IFTYPE_P2P_GO: |
| 3734 | /* parse WME attributes if sta is WME capable */ |
| 3735 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3736 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3737 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3738 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3739 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3740 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3741 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3742 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3743 | nl80211_sta_wme_policy); |
| 3744 | if (err) |
| 3745 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3746 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3747 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3748 | params.uapsd_queues = |
| 3749 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3750 | if (params.uapsd_queues & |
| 3751 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3752 | return -EINVAL; |
| 3753 | |
| 3754 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3755 | params.max_sp = |
| 3756 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3757 | |
| 3758 | if (params.max_sp & |
| 3759 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3760 | return -EINVAL; |
| 3761 | |
| 3762 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3763 | } |
| 3764 | /* TDLS peers cannot be added */ |
| 3765 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3766 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3767 | /* but don't bother the driver with it */ |
| 3768 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3769 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3770 | /* allow authenticated/associated only if driver handles it */ |
| 3771 | if (!(rdev->wiphy.features & |
| 3772 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3773 | params.sta_flags_mask & |
| 3774 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3775 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3776 | return -EINVAL; |
| 3777 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3778 | /* must be last in here for error handling */ |
| 3779 | params.vlan = get_vlan(info, rdev); |
| 3780 | if (IS_ERR(params.vlan)) |
| 3781 | return PTR_ERR(params.vlan); |
| 3782 | break; |
| 3783 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3784 | /* associated is disallowed */ |
| 3785 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3786 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3787 | /* TDLS peers cannot be added */ |
| 3788 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3789 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3790 | break; |
| 3791 | case NL80211_IFTYPE_STATION: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3792 | /* associated is disallowed */ |
| 3793 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3794 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3795 | /* Only TDLS peers can be added */ |
| 3796 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3797 | return -EINVAL; |
| 3798 | /* Can only add if TDLS ... */ |
| 3799 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3800 | return -EOPNOTSUPP; |
| 3801 | /* ... with external setup is supported */ |
| 3802 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3803 | return -EOPNOTSUPP; |
| 3804 | break; |
| 3805 | default: |
| 3806 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3807 | } |
| 3808 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3809 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3810 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3811 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3812 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3813 | if (params.vlan) |
| 3814 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3815 | return err; |
| 3816 | } |
| 3817 | |
| 3818 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3819 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3821 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3822 | u8 *mac_addr = NULL; |
| 3823 | |
| 3824 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3825 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3826 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3827 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3828 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3829 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3830 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3831 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3832 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3833 | if (!rdev->ops->del_station) |
| 3834 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3835 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3836 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3837 | } |
| 3838 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3839 | 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] | 3840 | int flags, struct net_device *dev, |
| 3841 | u8 *dst, u8 *next_hop, |
| 3842 | struct mpath_info *pinfo) |
| 3843 | { |
| 3844 | void *hdr; |
| 3845 | struct nlattr *pinfoattr; |
| 3846 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3847 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3848 | if (!hdr) |
| 3849 | return -1; |
| 3850 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3851 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3852 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3853 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3854 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3855 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3856 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3857 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3858 | if (!pinfoattr) |
| 3859 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3860 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3861 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3862 | pinfo->frame_qlen)) |
| 3863 | goto nla_put_failure; |
| 3864 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3865 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3866 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3867 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3868 | pinfo->metric)) || |
| 3869 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3870 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3871 | pinfo->exptime)) || |
| 3872 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3873 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3874 | pinfo->flags)) || |
| 3875 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3876 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3877 | pinfo->discovery_timeout)) || |
| 3878 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3879 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3880 | pinfo->discovery_retries))) |
| 3881 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3882 | |
| 3883 | nla_nest_end(msg, pinfoattr); |
| 3884 | |
| 3885 | return genlmsg_end(msg, hdr); |
| 3886 | |
| 3887 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3888 | genlmsg_cancel(msg, hdr); |
| 3889 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3893 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3894 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3895 | struct mpath_info pinfo; |
| 3896 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3897 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3898 | u8 dst[ETH_ALEN]; |
| 3899 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3900 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3901 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3902 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3903 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3904 | if (err) |
| 3905 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3906 | |
| 3907 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3908 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3909 | goto out_err; |
| 3910 | } |
| 3911 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3912 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3913 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3914 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3915 | } |
| 3916 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3917 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3918 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3919 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3920 | if (err == -ENOENT) |
| 3921 | break; |
| 3922 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3923 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3924 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3925 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3926 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3927 | netdev, dst, next_hop, |
| 3928 | &pinfo) < 0) |
| 3929 | goto out; |
| 3930 | |
| 3931 | path_idx++; |
| 3932 | } |
| 3933 | |
| 3934 | |
| 3935 | out: |
| 3936 | cb->args[1] = path_idx; |
| 3937 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3938 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3939 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3940 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3944 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3946 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3947 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3948 | struct mpath_info pinfo; |
| 3949 | struct sk_buff *msg; |
| 3950 | u8 *dst = NULL; |
| 3951 | u8 next_hop[ETH_ALEN]; |
| 3952 | |
| 3953 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3954 | |
| 3955 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3956 | return -EINVAL; |
| 3957 | |
| 3958 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3959 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3960 | if (!rdev->ops->get_mpath) |
| 3961 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3963 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3964 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3965 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3966 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3967 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3968 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3969 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3970 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3971 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3972 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3973 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3974 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3975 | dev, dst, next_hop, &pinfo) < 0) { |
| 3976 | nlmsg_free(msg); |
| 3977 | return -ENOBUFS; |
| 3978 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3980 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3984 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3986 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3987 | u8 *dst = NULL; |
| 3988 | u8 *next_hop = NULL; |
| 3989 | |
| 3990 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3991 | return -EINVAL; |
| 3992 | |
| 3993 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3994 | return -EINVAL; |
| 3995 | |
| 3996 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3997 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3999 | if (!rdev->ops->change_mpath) |
| 4000 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4001 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4002 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4003 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4004 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4005 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4006 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4007 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4008 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4009 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4011 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4012 | u8 *dst = NULL; |
| 4013 | u8 *next_hop = NULL; |
| 4014 | |
| 4015 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4016 | return -EINVAL; |
| 4017 | |
| 4018 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4019 | return -EINVAL; |
| 4020 | |
| 4021 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4022 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4023 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4024 | if (!rdev->ops->add_mpath) |
| 4025 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4026 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4027 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4028 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4029 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4030 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4034 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4036 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4037 | u8 *dst = NULL; |
| 4038 | |
| 4039 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4040 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4041 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4042 | if (!rdev->ops->del_mpath) |
| 4043 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4044 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4045 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4046 | } |
| 4047 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4048 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4049 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4050 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4051 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4052 | struct bss_parameters params; |
| 4053 | |
| 4054 | memset(¶ms, 0, sizeof(params)); |
| 4055 | /* default to not changing parameters */ |
| 4056 | params.use_cts_prot = -1; |
| 4057 | params.use_short_preamble = -1; |
| 4058 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4059 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4060 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4061 | params.p2p_ctwindow = -1; |
| 4062 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4063 | |
| 4064 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4065 | params.use_cts_prot = |
| 4066 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4067 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4068 | params.use_short_preamble = |
| 4069 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4070 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4071 | params.use_short_slot_time = |
| 4072 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4073 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4074 | params.basic_rates = |
| 4075 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4076 | params.basic_rates_len = |
| 4077 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4078 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4079 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4080 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4081 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4082 | params.ht_opmode = |
| 4083 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4084 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4085 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4086 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4087 | return -EINVAL; |
| 4088 | params.p2p_ctwindow = |
| 4089 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4090 | if (params.p2p_ctwindow < 0) |
| 4091 | return -EINVAL; |
| 4092 | if (params.p2p_ctwindow != 0 && |
| 4093 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4094 | return -EINVAL; |
| 4095 | } |
| 4096 | |
| 4097 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4098 | u8 tmp; |
| 4099 | |
| 4100 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4101 | return -EINVAL; |
| 4102 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4103 | if (tmp > 1) |
| 4104 | return -EINVAL; |
| 4105 | params.p2p_opp_ps = tmp; |
| 4106 | if (params.p2p_opp_ps && |
| 4107 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4108 | return -EINVAL; |
| 4109 | } |
| 4110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4111 | if (!rdev->ops->change_bss) |
| 4112 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4113 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4114 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4115 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4116 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4117 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4118 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4119 | } |
| 4120 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4121 | 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] | 4122 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4123 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4124 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4125 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4126 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4127 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4128 | }; |
| 4129 | |
| 4130 | static int parse_reg_rule(struct nlattr *tb[], |
| 4131 | struct ieee80211_reg_rule *reg_rule) |
| 4132 | { |
| 4133 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4134 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4135 | |
| 4136 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4137 | return -EINVAL; |
| 4138 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4139 | return -EINVAL; |
| 4140 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4141 | return -EINVAL; |
| 4142 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4143 | return -EINVAL; |
| 4144 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4145 | return -EINVAL; |
| 4146 | |
| 4147 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4148 | |
| 4149 | freq_range->start_freq_khz = |
| 4150 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4151 | freq_range->end_freq_khz = |
| 4152 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4153 | freq_range->max_bandwidth_khz = |
| 4154 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4155 | |
| 4156 | power_rule->max_eirp = |
| 4157 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4158 | |
| 4159 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4160 | power_rule->max_antenna_gain = |
| 4161 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4162 | |
| 4163 | return 0; |
| 4164 | } |
| 4165 | |
| 4166 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4167 | { |
| 4168 | int r; |
| 4169 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4170 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4171 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4172 | /* |
| 4173 | * You should only get this when cfg80211 hasn't yet initialized |
| 4174 | * completely when built-in to the kernel right between the time |
| 4175 | * window between nl80211_init() and regulatory_init(), if that is |
| 4176 | * even possible. |
| 4177 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4178 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4179 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4180 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4181 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4182 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4183 | |
| 4184 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4185 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4186 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4187 | user_reg_hint_type = |
| 4188 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4189 | else |
| 4190 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4191 | |
| 4192 | switch (user_reg_hint_type) { |
| 4193 | case NL80211_USER_REG_HINT_USER: |
| 4194 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4195 | break; |
| 4196 | default: |
| 4197 | return -EINVAL; |
| 4198 | } |
| 4199 | |
| 4200 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4201 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4202 | return r; |
| 4203 | } |
| 4204 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4205 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4206 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4207 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4209 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4210 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4211 | struct mesh_config cur_params; |
| 4212 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4213 | void *hdr; |
| 4214 | struct nlattr *pinfoattr; |
| 4215 | struct sk_buff *msg; |
| 4216 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4217 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4218 | return -EOPNOTSUPP; |
| 4219 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4220 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4221 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4222 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4223 | wdev_lock(wdev); |
| 4224 | /* If not connected, get default parameters */ |
| 4225 | if (!wdev->mesh_id_len) |
| 4226 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4227 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4228 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4229 | wdev_unlock(wdev); |
| 4230 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4231 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4232 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4233 | |
| 4234 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4236 | if (!msg) |
| 4237 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4238 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4239 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4240 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4241 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4242 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4243 | if (!pinfoattr) |
| 4244 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4245 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4246 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4247 | cur_params.dot11MeshRetryTimeout) || |
| 4248 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4249 | cur_params.dot11MeshConfirmTimeout) || |
| 4250 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4251 | cur_params.dot11MeshHoldingTimeout) || |
| 4252 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4253 | cur_params.dot11MeshMaxPeerLinks) || |
| 4254 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4255 | cur_params.dot11MeshMaxRetries) || |
| 4256 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4257 | cur_params.dot11MeshTTL) || |
| 4258 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4259 | cur_params.element_ttl) || |
| 4260 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4261 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4262 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4263 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4264 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4265 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4266 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4267 | cur_params.path_refresh_time) || |
| 4268 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4269 | cur_params.min_discovery_timeout) || |
| 4270 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4271 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4272 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4273 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4274 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4275 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4276 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4277 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4278 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4279 | cur_params.dot11MeshHWMPRootMode) || |
| 4280 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4281 | cur_params.dot11MeshHWMPRannInterval) || |
| 4282 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4283 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4284 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4285 | cur_params.dot11MeshForwarding) || |
| 4286 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4287 | cur_params.rssi_threshold) || |
| 4288 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4289 | cur_params.ht_opmode) || |
| 4290 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4291 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4292 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4293 | cur_params.dot11MeshHWMProotInterval) || |
| 4294 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4295 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4296 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4297 | cur_params.power_mode) || |
| 4298 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4299 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4300 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4301 | nla_nest_end(msg, pinfoattr); |
| 4302 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4303 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4304 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4305 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4306 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4307 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4308 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4309 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4312 | 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] | 4313 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4314 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4315 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4316 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4317 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4318 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4319 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4320 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4321 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4322 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4323 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4324 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4325 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4326 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4327 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4328 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4329 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4330 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4331 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4332 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4333 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4334 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4335 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4336 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4337 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4338 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4339 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4340 | }; |
| 4341 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4342 | static const struct nla_policy |
| 4343 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4344 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4345 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4346 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4347 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4348 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4349 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4350 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4351 | }; |
| 4352 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4353 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4354 | struct mesh_config *cfg, |
| 4355 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4356 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4357 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4358 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4359 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4360 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4361 | do { \ |
| 4362 | if (tb[attr]) { \ |
| 4363 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4364 | return -EINVAL; \ |
| 4365 | cfg->param = fn(tb[attr]); \ |
| 4366 | mask |= (1 << (attr - 1)); \ |
| 4367 | } \ |
| 4368 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4369 | |
| 4370 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4371 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4372 | return -EINVAL; |
| 4373 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4374 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4375 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4376 | return -EINVAL; |
| 4377 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4378 | /* This makes sure that there aren't more than 32 mesh config |
| 4379 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4380 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4381 | |
| 4382 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4383 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4384 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4385 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4386 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4387 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4388 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4389 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4390 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4391 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4392 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4393 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4394 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4395 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4396 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4397 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4398 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4399 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4400 | 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] | 4401 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4402 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4403 | 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] | 4404 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4405 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4406 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4407 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4408 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4409 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4410 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4411 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4412 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4413 | 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] | 4414 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4415 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4416 | 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] | 4417 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4418 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4419 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4420 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4421 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4422 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4423 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4424 | 1, 65535, mask, |
| 4425 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4426 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4427 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4428 | 1, 65535, mask, |
| 4429 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4430 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4431 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4432 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4433 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4434 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4435 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4436 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4437 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4438 | nla_get_u8); |
| 4439 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4440 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4441 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4442 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4443 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4444 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4445 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4446 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4447 | mask, NL80211_MESHCONF_FORWARDING, |
| 4448 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4449 | 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] | 4450 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4451 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4452 | 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] | 4453 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4454 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4455 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4456 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4457 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4458 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4459 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4460 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4461 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4462 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4463 | dot11MeshHWMPconfirmationInterval, |
| 4464 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4465 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4466 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4467 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4468 | NL80211_MESH_POWER_ACTIVE, |
| 4469 | NL80211_MESH_POWER_MAX, |
| 4470 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4471 | nla_get_u32); |
| 4472 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4473 | 0, 65535, mask, |
| 4474 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4475 | if (mask_out) |
| 4476 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4477 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4478 | return 0; |
| 4479 | |
| 4480 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4481 | } |
| 4482 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4483 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4484 | struct mesh_setup *setup) |
| 4485 | { |
| 4486 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4487 | |
| 4488 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4489 | return -EINVAL; |
| 4490 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4491 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4492 | nl80211_mesh_setup_params_policy)) |
| 4493 | return -EINVAL; |
| 4494 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4495 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4496 | setup->sync_method = |
| 4497 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4498 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4499 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4500 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4501 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4502 | setup->path_sel_proto = |
| 4503 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4504 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4505 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4506 | |
| 4507 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4508 | setup->path_metric = |
| 4509 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4510 | IEEE80211_PATH_METRIC_VENDOR : |
| 4511 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4512 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4513 | |
| 4514 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4515 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4516 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4517 | if (!is_valid_ie_attr(ieattr)) |
| 4518 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4519 | setup->ie = nla_data(ieattr); |
| 4520 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4521 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4522 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4523 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4524 | |
| 4525 | return 0; |
| 4526 | } |
| 4527 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4528 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4529 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4530 | { |
| 4531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4532 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4534 | struct mesh_config cfg; |
| 4535 | u32 mask; |
| 4536 | int err; |
| 4537 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4538 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4539 | return -EOPNOTSUPP; |
| 4540 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4541 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4542 | return -EOPNOTSUPP; |
| 4543 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4544 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4545 | if (err) |
| 4546 | return err; |
| 4547 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4548 | wdev_lock(wdev); |
| 4549 | if (!wdev->mesh_id_len) |
| 4550 | err = -ENOLINK; |
| 4551 | |
| 4552 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4553 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4554 | |
| 4555 | wdev_unlock(wdev); |
| 4556 | |
| 4557 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4560 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4561 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4562 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4563 | struct sk_buff *msg; |
| 4564 | void *hdr = NULL; |
| 4565 | struct nlattr *nl_reg_rules; |
| 4566 | unsigned int i; |
| 4567 | int err = -EINVAL; |
| 4568 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4569 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4570 | |
| 4571 | if (!cfg80211_regdomain) |
| 4572 | goto out; |
| 4573 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4574 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4575 | if (!msg) { |
| 4576 | err = -ENOBUFS; |
| 4577 | goto out; |
| 4578 | } |
| 4579 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4580 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4581 | NL80211_CMD_GET_REG); |
| 4582 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4583 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4584 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4585 | if (reg_last_request_cell_base() && |
| 4586 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4587 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4588 | goto nla_put_failure; |
| 4589 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4590 | rcu_read_lock(); |
| 4591 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4592 | |
| 4593 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4594 | (regdom->dfs_region && |
| 4595 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4596 | goto nla_put_failure_rcu; |
| 4597 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4598 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4599 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4600 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4601 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4602 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4603 | struct nlattr *nl_reg_rule; |
| 4604 | const struct ieee80211_reg_rule *reg_rule; |
| 4605 | const struct ieee80211_freq_range *freq_range; |
| 4606 | const struct ieee80211_power_rule *power_rule; |
| 4607 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4608 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4609 | freq_range = ®_rule->freq_range; |
| 4610 | power_rule = ®_rule->power_rule; |
| 4611 | |
| 4612 | nl_reg_rule = nla_nest_start(msg, i); |
| 4613 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4614 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4616 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4617 | reg_rule->flags) || |
| 4618 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4619 | freq_range->start_freq_khz) || |
| 4620 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4621 | freq_range->end_freq_khz) || |
| 4622 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4623 | freq_range->max_bandwidth_khz) || |
| 4624 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4625 | power_rule->max_antenna_gain) || |
| 4626 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4627 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4628 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4629 | |
| 4630 | nla_nest_end(msg, nl_reg_rule); |
| 4631 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4632 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4633 | |
| 4634 | nla_nest_end(msg, nl_reg_rules); |
| 4635 | |
| 4636 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4637 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4638 | goto out; |
| 4639 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4640 | nla_put_failure_rcu: |
| 4641 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4642 | nla_put_failure: |
| 4643 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4644 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4645 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4646 | err = -EMSGSIZE; |
| 4647 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4648 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4649 | return err; |
| 4650 | } |
| 4651 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4652 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4653 | { |
| 4654 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4655 | struct nlattr *nl_reg_rule; |
| 4656 | char *alpha2 = NULL; |
| 4657 | int rem_reg_rules = 0, r = 0; |
| 4658 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4659 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4660 | struct ieee80211_regdomain *rd = NULL; |
| 4661 | |
| 4662 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4663 | return -EINVAL; |
| 4664 | |
| 4665 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4666 | return -EINVAL; |
| 4667 | |
| 4668 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4669 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4670 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4671 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4672 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4673 | 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] | 4674 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4675 | num_rules++; |
| 4676 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4677 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4680 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4681 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4682 | |
| 4683 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4684 | if (!rd) |
| 4685 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4686 | |
| 4687 | rd->n_reg_rules = num_rules; |
| 4688 | rd->alpha2[0] = alpha2[0]; |
| 4689 | rd->alpha2[1] = alpha2[1]; |
| 4690 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4691 | /* |
| 4692 | * Disable DFS master mode if the DFS region was |
| 4693 | * not supported or known on this kernel. |
| 4694 | */ |
| 4695 | if (reg_supported_dfs_region(dfs_region)) |
| 4696 | rd->dfs_region = dfs_region; |
| 4697 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4698 | 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] | 4699 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4700 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4701 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4702 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4703 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4704 | if (r) |
| 4705 | goto bad_reg; |
| 4706 | |
| 4707 | rule_idx++; |
| 4708 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4709 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4710 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4711 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4712 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4713 | } |
| 4714 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4715 | mutex_lock(&cfg80211_mutex); |
| 4716 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4717 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4718 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4719 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4720 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4721 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4722 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4723 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4724 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4725 | } |
| 4726 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4727 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4728 | { |
| 4729 | struct nlattr *attr1, *attr2; |
| 4730 | int n_channels = 0, tmp1, tmp2; |
| 4731 | |
| 4732 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4733 | n_channels++; |
| 4734 | /* |
| 4735 | * Some hardware has a limited channel list for |
| 4736 | * scanning, and it is pretty much nonsensical |
| 4737 | * to scan for a channel twice, so disallow that |
| 4738 | * and don't require drivers to check that the |
| 4739 | * channel list they get isn't longer than what |
| 4740 | * they can scan, as long as they can scan all |
| 4741 | * the channels they registered at once. |
| 4742 | */ |
| 4743 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4744 | if (attr1 != attr2 && |
| 4745 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4746 | return 0; |
| 4747 | } |
| 4748 | |
| 4749 | return n_channels; |
| 4750 | } |
| 4751 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4752 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4755 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4756 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4757 | struct nlattr *attr; |
| 4758 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4759 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4760 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4761 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4762 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4763 | return -EINVAL; |
| 4764 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4765 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4766 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4767 | if (!rdev->ops->scan) |
| 4768 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4769 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4770 | if (rdev->scan_req) |
| 4771 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4772 | |
| 4773 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4774 | n_channels = validate_scan_freqs( |
| 4775 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4776 | if (!n_channels) |
| 4777 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4778 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4779 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4780 | n_channels = 0; |
| 4781 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4782 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4783 | if (wiphy->bands[band]) |
| 4784 | n_channels += wiphy->bands[band]->n_channels; |
| 4785 | } |
| 4786 | |
| 4787 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4788 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4789 | n_ssids++; |
| 4790 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4791 | if (n_ssids > wiphy->max_scan_ssids) |
| 4792 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4793 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4794 | if (info->attrs[NL80211_ATTR_IE]) |
| 4795 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4796 | else |
| 4797 | ie_len = 0; |
| 4798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4799 | if (ie_len > wiphy->max_scan_ie_len) |
| 4800 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4801 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4802 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4803 | + sizeof(*request->ssids) * n_ssids |
| 4804 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4805 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4806 | if (!request) |
| 4807 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4808 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4809 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4810 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4811 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4812 | if (ie_len) { |
| 4813 | if (request->ssids) |
| 4814 | request->ie = (void *)(request->ssids + n_ssids); |
| 4815 | else |
| 4816 | request->ie = (void *)(request->channels + n_channels); |
| 4817 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4818 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4819 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4820 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4821 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4822 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4823 | struct ieee80211_channel *chan; |
| 4824 | |
| 4825 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4826 | |
| 4827 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4828 | err = -EINVAL; |
| 4829 | goto out_free; |
| 4830 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4831 | |
| 4832 | /* ignore disabled channels */ |
| 4833 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4834 | continue; |
| 4835 | |
| 4836 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4837 | i++; |
| 4838 | } |
| 4839 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4840 | enum ieee80211_band band; |
| 4841 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4842 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4843 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4844 | int j; |
| 4845 | if (!wiphy->bands[band]) |
| 4846 | continue; |
| 4847 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4848 | struct ieee80211_channel *chan; |
| 4849 | |
| 4850 | chan = &wiphy->bands[band]->channels[j]; |
| 4851 | |
| 4852 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4853 | continue; |
| 4854 | |
| 4855 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4856 | i++; |
| 4857 | } |
| 4858 | } |
| 4859 | } |
| 4860 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4861 | if (!i) { |
| 4862 | err = -EINVAL; |
| 4863 | goto out_free; |
| 4864 | } |
| 4865 | |
| 4866 | request->n_channels = i; |
| 4867 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4868 | i = 0; |
| 4869 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4870 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4871 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4872 | err = -EINVAL; |
| 4873 | goto out_free; |
| 4874 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4875 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4876 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4877 | i++; |
| 4878 | } |
| 4879 | } |
| 4880 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4881 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4882 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4883 | memcpy((void *)request->ie, |
| 4884 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4885 | request->ie_len); |
| 4886 | } |
| 4887 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4888 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4889 | if (wiphy->bands[i]) |
| 4890 | request->rates[i] = |
| 4891 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4892 | |
| 4893 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4894 | nla_for_each_nested(attr, |
| 4895 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4896 | tmp) { |
| 4897 | enum ieee80211_band band = nla_type(attr); |
| 4898 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4899 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4900 | err = -EINVAL; |
| 4901 | goto out_free; |
| 4902 | } |
| 4903 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4904 | nla_data(attr), |
| 4905 | nla_len(attr), |
| 4906 | &request->rates[band]); |
| 4907 | if (err) |
| 4908 | goto out_free; |
| 4909 | } |
| 4910 | } |
| 4911 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4912 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4913 | request->flags = nla_get_u32( |
| 4914 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4915 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4916 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4917 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4918 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4919 | err = -EOPNOTSUPP; |
| 4920 | goto out_free; |
| 4921 | } |
| 4922 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4923 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4924 | request->no_cck = |
| 4925 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4926 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4927 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4928 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4929 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4930 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4931 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4932 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4933 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4934 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4935 | nl80211_send_scan_start(rdev, wdev); |
| 4936 | if (wdev->netdev) |
| 4937 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4938 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4939 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4940 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4941 | kfree(request); |
| 4942 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4943 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4944 | return err; |
| 4945 | } |
| 4946 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4947 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4948 | struct genl_info *info) |
| 4949 | { |
| 4950 | struct cfg80211_sched_scan_request *request; |
| 4951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4952 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4953 | struct nlattr *attr; |
| 4954 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4955 | 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] | 4956 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4957 | enum ieee80211_band band; |
| 4958 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4959 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4960 | |
| 4961 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4962 | !rdev->ops->sched_scan_start) |
| 4963 | return -EOPNOTSUPP; |
| 4964 | |
| 4965 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4966 | return -EINVAL; |
| 4967 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4968 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4969 | return -EINVAL; |
| 4970 | |
| 4971 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4972 | if (interval == 0) |
| 4973 | return -EINVAL; |
| 4974 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4975 | wiphy = &rdev->wiphy; |
| 4976 | |
| 4977 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4978 | n_channels = validate_scan_freqs( |
| 4979 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4980 | if (!n_channels) |
| 4981 | return -EINVAL; |
| 4982 | } else { |
| 4983 | n_channels = 0; |
| 4984 | |
| 4985 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4986 | if (wiphy->bands[band]) |
| 4987 | n_channels += wiphy->bands[band]->n_channels; |
| 4988 | } |
| 4989 | |
| 4990 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4991 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4992 | tmp) |
| 4993 | n_ssids++; |
| 4994 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4995 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4996 | return -EINVAL; |
| 4997 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4998 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4999 | nla_for_each_nested(attr, |
| 5000 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5001 | tmp) |
| 5002 | n_match_sets++; |
| 5003 | |
| 5004 | if (n_match_sets > wiphy->max_match_sets) |
| 5005 | return -EINVAL; |
| 5006 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5007 | if (info->attrs[NL80211_ATTR_IE]) |
| 5008 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5009 | else |
| 5010 | ie_len = 0; |
| 5011 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5012 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5013 | return -EINVAL; |
| 5014 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5015 | mutex_lock(&rdev->sched_scan_mtx); |
| 5016 | |
| 5017 | if (rdev->sched_scan_req) { |
| 5018 | err = -EINPROGRESS; |
| 5019 | goto out; |
| 5020 | } |
| 5021 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5022 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5023 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5024 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5025 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5026 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5027 | if (!request) { |
| 5028 | err = -ENOMEM; |
| 5029 | goto out; |
| 5030 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5031 | |
| 5032 | if (n_ssids) |
| 5033 | request->ssids = (void *)&request->channels[n_channels]; |
| 5034 | request->n_ssids = n_ssids; |
| 5035 | if (ie_len) { |
| 5036 | if (request->ssids) |
| 5037 | request->ie = (void *)(request->ssids + n_ssids); |
| 5038 | else |
| 5039 | request->ie = (void *)(request->channels + n_channels); |
| 5040 | } |
| 5041 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5042 | if (n_match_sets) { |
| 5043 | if (request->ie) |
| 5044 | request->match_sets = (void *)(request->ie + ie_len); |
| 5045 | else if (request->ssids) |
| 5046 | request->match_sets = |
| 5047 | (void *)(request->ssids + n_ssids); |
| 5048 | else |
| 5049 | request->match_sets = |
| 5050 | (void *)(request->channels + n_channels); |
| 5051 | } |
| 5052 | request->n_match_sets = n_match_sets; |
| 5053 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5054 | i = 0; |
| 5055 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5056 | /* user specified, bail out if channel not found */ |
| 5057 | nla_for_each_nested(attr, |
| 5058 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5059 | tmp) { |
| 5060 | struct ieee80211_channel *chan; |
| 5061 | |
| 5062 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5063 | |
| 5064 | if (!chan) { |
| 5065 | err = -EINVAL; |
| 5066 | goto out_free; |
| 5067 | } |
| 5068 | |
| 5069 | /* ignore disabled channels */ |
| 5070 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5071 | continue; |
| 5072 | |
| 5073 | request->channels[i] = chan; |
| 5074 | i++; |
| 5075 | } |
| 5076 | } else { |
| 5077 | /* all channels */ |
| 5078 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5079 | int j; |
| 5080 | if (!wiphy->bands[band]) |
| 5081 | continue; |
| 5082 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5083 | struct ieee80211_channel *chan; |
| 5084 | |
| 5085 | chan = &wiphy->bands[band]->channels[j]; |
| 5086 | |
| 5087 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5088 | continue; |
| 5089 | |
| 5090 | request->channels[i] = chan; |
| 5091 | i++; |
| 5092 | } |
| 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | if (!i) { |
| 5097 | err = -EINVAL; |
| 5098 | goto out_free; |
| 5099 | } |
| 5100 | |
| 5101 | request->n_channels = i; |
| 5102 | |
| 5103 | i = 0; |
| 5104 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5105 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5106 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5107 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5108 | err = -EINVAL; |
| 5109 | goto out_free; |
| 5110 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5111 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5112 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5113 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5114 | i++; |
| 5115 | } |
| 5116 | } |
| 5117 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5118 | i = 0; |
| 5119 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5120 | nla_for_each_nested(attr, |
| 5121 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5122 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5123 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5124 | |
| 5125 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5126 | nla_data(attr), nla_len(attr), |
| 5127 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5128 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5129 | if (ssid) { |
| 5130 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5131 | err = -EINVAL; |
| 5132 | goto out_free; |
| 5133 | } |
| 5134 | memcpy(request->match_sets[i].ssid.ssid, |
| 5135 | nla_data(ssid), nla_len(ssid)); |
| 5136 | request->match_sets[i].ssid.ssid_len = |
| 5137 | nla_len(ssid); |
| 5138 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5139 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5140 | if (rssi) |
| 5141 | request->rssi_thold = nla_get_u32(rssi); |
| 5142 | else |
| 5143 | request->rssi_thold = |
| 5144 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5145 | i++; |
| 5146 | } |
| 5147 | } |
| 5148 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5149 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5150 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5151 | memcpy((void *)request->ie, |
| 5152 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5153 | request->ie_len); |
| 5154 | } |
| 5155 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5156 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5157 | request->flags = nla_get_u32( |
| 5158 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5159 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5160 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5161 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5162 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5163 | err = -EOPNOTSUPP; |
| 5164 | goto out_free; |
| 5165 | } |
| 5166 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5167 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5168 | request->dev = dev; |
| 5169 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5170 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5171 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5172 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5173 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5174 | if (!err) { |
| 5175 | rdev->sched_scan_req = request; |
| 5176 | nl80211_send_sched_scan(rdev, dev, |
| 5177 | NL80211_CMD_START_SCHED_SCAN); |
| 5178 | goto out; |
| 5179 | } |
| 5180 | |
| 5181 | out_free: |
| 5182 | kfree(request); |
| 5183 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5184 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5185 | return err; |
| 5186 | } |
| 5187 | |
| 5188 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5189 | struct genl_info *info) |
| 5190 | { |
| 5191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5192 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5193 | |
| 5194 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5195 | !rdev->ops->sched_scan_stop) |
| 5196 | return -EOPNOTSUPP; |
| 5197 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5198 | mutex_lock(&rdev->sched_scan_mtx); |
| 5199 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5200 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5201 | |
| 5202 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5203 | } |
| 5204 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5205 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5206 | struct genl_info *info) |
| 5207 | { |
| 5208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5209 | struct net_device *dev = info->user_ptr[1]; |
| 5210 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5211 | struct cfg80211_chan_def chandef; |
| 5212 | int err; |
| 5213 | |
| 5214 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5215 | if (err) |
| 5216 | return err; |
| 5217 | |
| 5218 | if (wdev->cac_started) |
| 5219 | return -EBUSY; |
| 5220 | |
| 5221 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5222 | if (err < 0) |
| 5223 | return err; |
| 5224 | |
| 5225 | if (err == 0) |
| 5226 | return -EINVAL; |
| 5227 | |
| 5228 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5229 | return -EINVAL; |
| 5230 | |
| 5231 | if (!rdev->ops->start_radar_detection) |
| 5232 | return -EOPNOTSUPP; |
| 5233 | |
| 5234 | mutex_lock(&rdev->devlist_mtx); |
| 5235 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5236 | chandef.chan, CHAN_MODE_SHARED, |
| 5237 | BIT(chandef.width)); |
| 5238 | if (err) |
| 5239 | goto err_locked; |
| 5240 | |
| 5241 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5242 | if (!err) { |
| 5243 | wdev->channel = chandef.chan; |
| 5244 | wdev->cac_started = true; |
| 5245 | wdev->cac_start_time = jiffies; |
| 5246 | } |
| 5247 | err_locked: |
| 5248 | mutex_unlock(&rdev->devlist_mtx); |
| 5249 | |
| 5250 | return err; |
| 5251 | } |
| 5252 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5253 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5254 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5255 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5256 | struct wireless_dev *wdev, |
| 5257 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5258 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5259 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5260 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | void *hdr; |
| 5262 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5263 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5264 | |
| 5265 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5266 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5267 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5268 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5269 | if (!hdr) |
| 5270 | return -1; |
| 5271 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5272 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5273 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5274 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5275 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5276 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5277 | |
| 5278 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5279 | if (!bss) |
| 5280 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5281 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5282 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5283 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5284 | |
| 5285 | rcu_read_lock(); |
| 5286 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5287 | if (ies) { |
| 5288 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5289 | goto fail_unlock_rcu; |
| 5290 | tsf = true; |
| 5291 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5292 | ies->len, ies->data)) |
| 5293 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5294 | } |
| 5295 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5296 | if (ies) { |
| 5297 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5298 | goto fail_unlock_rcu; |
| 5299 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5300 | ies->len, ies->data)) |
| 5301 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5302 | } |
| 5303 | rcu_read_unlock(); |
| 5304 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5305 | if (res->beacon_interval && |
| 5306 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5307 | goto nla_put_failure; |
| 5308 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5309 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5310 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5311 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5312 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5313 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5314 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5315 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5316 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5317 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5318 | break; |
| 5319 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5320 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5321 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | break; |
| 5323 | default: |
| 5324 | break; |
| 5325 | } |
| 5326 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5327 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5328 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5329 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5330 | if (intbss == wdev->current_bss && |
| 5331 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5332 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5333 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5334 | break; |
| 5335 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5336 | if (intbss == wdev->current_bss && |
| 5337 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5338 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5339 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5340 | break; |
| 5341 | default: |
| 5342 | break; |
| 5343 | } |
| 5344 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5345 | nla_nest_end(msg, bss); |
| 5346 | |
| 5347 | return genlmsg_end(msg, hdr); |
| 5348 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5349 | fail_unlock_rcu: |
| 5350 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5351 | nla_put_failure: |
| 5352 | genlmsg_cancel(msg, hdr); |
| 5353 | return -EMSGSIZE; |
| 5354 | } |
| 5355 | |
| 5356 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5357 | struct netlink_callback *cb) |
| 5358 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5359 | struct cfg80211_registered_device *rdev; |
| 5360 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5361 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5362 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5363 | int start = cb->args[1], idx = 0; |
| 5364 | int err; |
| 5365 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5366 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5367 | if (err) |
| 5368 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5369 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5370 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5371 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5372 | wdev_lock(wdev); |
| 5373 | spin_lock_bh(&rdev->bss_lock); |
| 5374 | cfg80211_bss_expire(rdev); |
| 5375 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5376 | cb->seq = rdev->bss_generation; |
| 5377 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5378 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5379 | if (++idx <= start) |
| 5380 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5381 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5382 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5383 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5384 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5385 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5386 | } |
| 5387 | } |
| 5388 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5389 | spin_unlock_bh(&rdev->bss_lock); |
| 5390 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5391 | |
| 5392 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5393 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5394 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5395 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5396 | } |
| 5397 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5398 | 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] | 5399 | int flags, struct net_device *dev, |
| 5400 | struct survey_info *survey) |
| 5401 | { |
| 5402 | void *hdr; |
| 5403 | struct nlattr *infoattr; |
| 5404 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5405 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5406 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5407 | if (!hdr) |
| 5408 | return -ENOMEM; |
| 5409 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5410 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5411 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5412 | |
| 5413 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5414 | if (!infoattr) |
| 5415 | goto nla_put_failure; |
| 5416 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5417 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5418 | survey->channel->center_freq)) |
| 5419 | goto nla_put_failure; |
| 5420 | |
| 5421 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5422 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5423 | goto nla_put_failure; |
| 5424 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5425 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5426 | goto nla_put_failure; |
| 5427 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5428 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5429 | survey->channel_time)) |
| 5430 | goto nla_put_failure; |
| 5431 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5432 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5433 | survey->channel_time_busy)) |
| 5434 | goto nla_put_failure; |
| 5435 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5436 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5437 | survey->channel_time_ext_busy)) |
| 5438 | goto nla_put_failure; |
| 5439 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5440 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5441 | survey->channel_time_rx)) |
| 5442 | goto nla_put_failure; |
| 5443 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5444 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5445 | survey->channel_time_tx)) |
| 5446 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5447 | |
| 5448 | nla_nest_end(msg, infoattr); |
| 5449 | |
| 5450 | return genlmsg_end(msg, hdr); |
| 5451 | |
| 5452 | nla_put_failure: |
| 5453 | genlmsg_cancel(msg, hdr); |
| 5454 | return -EMSGSIZE; |
| 5455 | } |
| 5456 | |
| 5457 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5458 | struct netlink_callback *cb) |
| 5459 | { |
| 5460 | struct survey_info survey; |
| 5461 | struct cfg80211_registered_device *dev; |
| 5462 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5463 | int survey_idx = cb->args[1]; |
| 5464 | int res; |
| 5465 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5466 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5467 | if (res) |
| 5468 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5469 | |
| 5470 | if (!dev->ops->dump_survey) { |
| 5471 | res = -EOPNOTSUPP; |
| 5472 | goto out_err; |
| 5473 | } |
| 5474 | |
| 5475 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5476 | struct ieee80211_channel *chan; |
| 5477 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5478 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5479 | if (res == -ENOENT) |
| 5480 | break; |
| 5481 | if (res) |
| 5482 | goto out_err; |
| 5483 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5484 | /* Survey without a channel doesn't make sense */ |
| 5485 | if (!survey.channel) { |
| 5486 | res = -EINVAL; |
| 5487 | goto out; |
| 5488 | } |
| 5489 | |
| 5490 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5491 | survey.channel->center_freq); |
| 5492 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5493 | survey_idx++; |
| 5494 | continue; |
| 5495 | } |
| 5496 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5497 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5498 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5499 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5500 | netdev, |
| 5501 | &survey) < 0) |
| 5502 | goto out; |
| 5503 | survey_idx++; |
| 5504 | } |
| 5505 | |
| 5506 | out: |
| 5507 | cb->args[1] = survey_idx; |
| 5508 | res = skb->len; |
| 5509 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5510 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5511 | return res; |
| 5512 | } |
| 5513 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5514 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5515 | { |
| 5516 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5517 | NL80211_WPA_VERSION_2)); |
| 5518 | } |
| 5519 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5520 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5521 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5523 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5524 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5525 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5526 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5527 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5528 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5529 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5530 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5531 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5532 | return -EINVAL; |
| 5533 | |
| 5534 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5535 | return -EINVAL; |
| 5536 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5537 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5538 | return -EINVAL; |
| 5539 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5540 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5541 | return -EINVAL; |
| 5542 | |
| 5543 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5544 | return -EINVAL; |
| 5545 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5546 | err = nl80211_parse_key(info, &key); |
| 5547 | if (err) |
| 5548 | return err; |
| 5549 | |
| 5550 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5551 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5552 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5553 | if (!key.p.key || !key.p.key_len) |
| 5554 | return -EINVAL; |
| 5555 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5556 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5557 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5558 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5559 | return -EINVAL; |
| 5560 | if (key.idx > 4) |
| 5561 | return -EINVAL; |
| 5562 | } else { |
| 5563 | key.p.key_len = 0; |
| 5564 | key.p.key = NULL; |
| 5565 | } |
| 5566 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5567 | if (key.idx >= 0) { |
| 5568 | int i; |
| 5569 | bool ok = false; |
| 5570 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5571 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5572 | ok = true; |
| 5573 | break; |
| 5574 | } |
| 5575 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5576 | if (!ok) |
| 5577 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5578 | } |
| 5579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5580 | if (!rdev->ops->auth) |
| 5581 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5582 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5583 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5584 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5585 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5586 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5587 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5588 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5589 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5590 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5591 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5592 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5593 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5594 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5595 | |
| 5596 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5597 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5598 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5599 | } |
| 5600 | |
| 5601 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5602 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5603 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5604 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5605 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5606 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5607 | return -EINVAL; |
| 5608 | |
| 5609 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5610 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5611 | return -EINVAL; |
| 5612 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5613 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5614 | /* need to include at least Auth Transaction and Status Code */ |
| 5615 | if (sae_data_len < 4) |
| 5616 | return -EINVAL; |
| 5617 | } |
| 5618 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5619 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5620 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5621 | /* |
| 5622 | * Since we no longer track auth state, ignore |
| 5623 | * requests to only change local state. |
| 5624 | */ |
| 5625 | if (local_state_change) |
| 5626 | return 0; |
| 5627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5628 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5629 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5630 | key.p.key, key.p.key_len, key.idx, |
| 5631 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5632 | } |
| 5633 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5634 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5635 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5636 | struct cfg80211_crypto_settings *settings, |
| 5637 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5638 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5639 | memset(settings, 0, sizeof(*settings)); |
| 5640 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5641 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5642 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5643 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5644 | u16 proto; |
| 5645 | proto = nla_get_u16( |
| 5646 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5647 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5648 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5649 | proto != ETH_P_PAE) |
| 5650 | return -EINVAL; |
| 5651 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5652 | settings->control_port_no_encrypt = true; |
| 5653 | } else |
| 5654 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5655 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5656 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5657 | void *data; |
| 5658 | int len, i; |
| 5659 | |
| 5660 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5661 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5662 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5663 | |
| 5664 | if (len % sizeof(u32)) |
| 5665 | return -EINVAL; |
| 5666 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5667 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5668 | return -EINVAL; |
| 5669 | |
| 5670 | memcpy(settings->ciphers_pairwise, data, len); |
| 5671 | |
| 5672 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5673 | if (!cfg80211_supported_cipher_suite( |
| 5674 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5675 | settings->ciphers_pairwise[i])) |
| 5676 | return -EINVAL; |
| 5677 | } |
| 5678 | |
| 5679 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5680 | settings->cipher_group = |
| 5681 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5682 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5683 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5684 | return -EINVAL; |
| 5685 | } |
| 5686 | |
| 5687 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5688 | settings->wpa_versions = |
| 5689 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5690 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5691 | return -EINVAL; |
| 5692 | } |
| 5693 | |
| 5694 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5695 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5696 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5697 | |
| 5698 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5699 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5700 | settings->n_akm_suites = len / sizeof(u32); |
| 5701 | |
| 5702 | if (len % sizeof(u32)) |
| 5703 | return -EINVAL; |
| 5704 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5705 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5706 | return -EINVAL; |
| 5707 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5708 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | return 0; |
| 5712 | } |
| 5713 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5714 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5715 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5717 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5718 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5719 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5720 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5721 | int err, ssid_len, ie_len = 0; |
| 5722 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5723 | u32 flags = 0; |
| 5724 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5725 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5726 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5727 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5728 | return -EINVAL; |
| 5729 | |
| 5730 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5731 | !info->attrs[NL80211_ATTR_SSID] || |
| 5732 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5733 | return -EINVAL; |
| 5734 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5735 | if (!rdev->ops->assoc) |
| 5736 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5737 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5738 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5739 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5740 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5741 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5742 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5743 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5744 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5745 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5746 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5747 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5748 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5749 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5750 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5751 | |
| 5752 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5753 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5754 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5755 | } |
| 5756 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5757 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5758 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5759 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5760 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5761 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5762 | else if (mfp != NL80211_MFP_NO) |
| 5763 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5764 | } |
| 5765 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5766 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5767 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5768 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5769 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5770 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5771 | |
| 5772 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5773 | ht_capa_mask = |
| 5774 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5775 | |
| 5776 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5777 | if (!ht_capa_mask) |
| 5778 | return -EINVAL; |
| 5779 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5780 | } |
| 5781 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5782 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5783 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5784 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5785 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5786 | &crypto, flags, ht_capa, |
| 5787 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5788 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5789 | return err; |
| 5790 | } |
| 5791 | |
| 5792 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5795 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5796 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5797 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5798 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5799 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5800 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5801 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5802 | return -EINVAL; |
| 5803 | |
| 5804 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5805 | return -EINVAL; |
| 5806 | |
| 5807 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5808 | return -EINVAL; |
| 5809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5810 | if (!rdev->ops->deauth) |
| 5811 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5812 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5813 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5814 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5815 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5816 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5817 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5818 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5819 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5820 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5821 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5822 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5823 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5824 | |
| 5825 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5826 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5827 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5828 | } |
| 5829 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5830 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5831 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5832 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5833 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5837 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5839 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5840 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5841 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5842 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5843 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5844 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5845 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5846 | return -EINVAL; |
| 5847 | |
| 5848 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5849 | return -EINVAL; |
| 5850 | |
| 5851 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5852 | return -EINVAL; |
| 5853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5854 | if (!rdev->ops->disassoc) |
| 5855 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5856 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5857 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5858 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5859 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5860 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5861 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5862 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5863 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5864 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5865 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5866 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5867 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5868 | |
| 5869 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5870 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5871 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5872 | } |
| 5873 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5874 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5876 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5877 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5878 | } |
| 5879 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5880 | static bool |
| 5881 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5882 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5883 | int rateval) |
| 5884 | { |
| 5885 | struct wiphy *wiphy = &rdev->wiphy; |
| 5886 | bool found = false; |
| 5887 | int band, i; |
| 5888 | |
| 5889 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5890 | struct ieee80211_supported_band *sband; |
| 5891 | |
| 5892 | sband = wiphy->bands[band]; |
| 5893 | if (!sband) |
| 5894 | continue; |
| 5895 | |
| 5896 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5897 | if (sband->bitrates[i].bitrate == rateval) { |
| 5898 | mcast_rate[band] = i + 1; |
| 5899 | found = true; |
| 5900 | break; |
| 5901 | } |
| 5902 | } |
| 5903 | } |
| 5904 | |
| 5905 | return found; |
| 5906 | } |
| 5907 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5908 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5909 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5910 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5911 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5912 | struct cfg80211_ibss_params ibss; |
| 5913 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5914 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5915 | int err; |
| 5916 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5917 | memset(&ibss, 0, sizeof(ibss)); |
| 5918 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5919 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5920 | return -EINVAL; |
| 5921 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5922 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5923 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5924 | return -EINVAL; |
| 5925 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5926 | ibss.beacon_interval = 100; |
| 5927 | |
| 5928 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5929 | ibss.beacon_interval = |
| 5930 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5931 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5932 | return -EINVAL; |
| 5933 | } |
| 5934 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5935 | if (!rdev->ops->join_ibss) |
| 5936 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5938 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5939 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5940 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5941 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5942 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5943 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5944 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5945 | |
| 5946 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5947 | return -EINVAL; |
| 5948 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5949 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5950 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5951 | |
| 5952 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5953 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5954 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5955 | } |
| 5956 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5957 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5958 | if (err) |
| 5959 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5960 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5961 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5962 | return -EINVAL; |
| 5963 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5964 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5965 | return -EINVAL; |
| 5966 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5967 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5968 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5969 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5970 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5971 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5972 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5973 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5974 | u8 *rates = |
| 5975 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5976 | int n_rates = |
| 5977 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5978 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5979 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5980 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5981 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5982 | &ibss.basic_rates); |
| 5983 | if (err) |
| 5984 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5985 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5986 | |
| 5987 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5988 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5989 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5990 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5991 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5992 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5993 | bool no_ht = false; |
| 5994 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5995 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5996 | info->attrs[NL80211_ATTR_KEYS], |
| 5997 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5998 | if (IS_ERR(connkeys)) |
| 5999 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6000 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6001 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6002 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6003 | kfree(connkeys); |
| 6004 | return -EINVAL; |
| 6005 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6006 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6007 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6008 | ibss.control_port = |
| 6009 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6011 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6012 | if (err) |
| 6013 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6014 | return err; |
| 6015 | } |
| 6016 | |
| 6017 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6018 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6020 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6022 | if (!rdev->ops->leave_ibss) |
| 6023 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6024 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6025 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6026 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6027 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6028 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6029 | } |
| 6030 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6031 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6032 | { |
| 6033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6034 | struct net_device *dev = info->user_ptr[1]; |
| 6035 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6036 | u32 nla_rate; |
| 6037 | int err; |
| 6038 | |
| 6039 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6040 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6041 | return -EOPNOTSUPP; |
| 6042 | |
| 6043 | if (!rdev->ops->set_mcast_rate) |
| 6044 | return -EOPNOTSUPP; |
| 6045 | |
| 6046 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6047 | |
| 6048 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6049 | return -EINVAL; |
| 6050 | |
| 6051 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6052 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6053 | return -EINVAL; |
| 6054 | |
| 6055 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6056 | |
| 6057 | return err; |
| 6058 | } |
| 6059 | |
| 6060 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6061 | #ifdef CONFIG_NL80211_TESTMODE |
| 6062 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6063 | .name = "testmode", |
| 6064 | }; |
| 6065 | |
| 6066 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6067 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6069 | int err; |
| 6070 | |
| 6071 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6072 | return -EINVAL; |
| 6073 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6074 | err = -EOPNOTSUPP; |
| 6075 | if (rdev->ops->testmode_cmd) { |
| 6076 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6077 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6078 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6079 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6080 | rdev->testmode_info = NULL; |
| 6081 | } |
| 6082 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6083 | return err; |
| 6084 | } |
| 6085 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6086 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6087 | struct netlink_callback *cb) |
| 6088 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6089 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6090 | int err; |
| 6091 | long phy_idx; |
| 6092 | void *data = NULL; |
| 6093 | int data_len = 0; |
| 6094 | |
| 6095 | if (cb->args[0]) { |
| 6096 | /* |
| 6097 | * 0 is a valid index, but not valid for args[0], |
| 6098 | * so we need to offset by 1. |
| 6099 | */ |
| 6100 | phy_idx = cb->args[0] - 1; |
| 6101 | } else { |
| 6102 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6103 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6104 | nl80211_policy); |
| 6105 | if (err) |
| 6106 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6107 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6108 | mutex_lock(&cfg80211_mutex); |
| 6109 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6110 | nl80211_fam.attrbuf); |
| 6111 | if (IS_ERR(rdev)) { |
| 6112 | mutex_unlock(&cfg80211_mutex); |
| 6113 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6114 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6115 | phy_idx = rdev->wiphy_idx; |
| 6116 | rdev = NULL; |
| 6117 | mutex_unlock(&cfg80211_mutex); |
| 6118 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6119 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6120 | cb->args[1] = |
| 6121 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6122 | } |
| 6123 | |
| 6124 | if (cb->args[1]) { |
| 6125 | data = nla_data((void *)cb->args[1]); |
| 6126 | data_len = nla_len((void *)cb->args[1]); |
| 6127 | } |
| 6128 | |
| 6129 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6130 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6131 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6132 | mutex_unlock(&cfg80211_mutex); |
| 6133 | return -ENOENT; |
| 6134 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6135 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6136 | mutex_unlock(&cfg80211_mutex); |
| 6137 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6138 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6139 | err = -EOPNOTSUPP; |
| 6140 | goto out_err; |
| 6141 | } |
| 6142 | |
| 6143 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6144 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6145 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6146 | NL80211_CMD_TESTMODE); |
| 6147 | struct nlattr *tmdata; |
| 6148 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6149 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6150 | genlmsg_cancel(skb, hdr); |
| 6151 | break; |
| 6152 | } |
| 6153 | |
| 6154 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6155 | if (!tmdata) { |
| 6156 | genlmsg_cancel(skb, hdr); |
| 6157 | break; |
| 6158 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6159 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6160 | nla_nest_end(skb, tmdata); |
| 6161 | |
| 6162 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6163 | genlmsg_cancel(skb, hdr); |
| 6164 | break; |
| 6165 | } else if (err) { |
| 6166 | genlmsg_cancel(skb, hdr); |
| 6167 | goto out_err; |
| 6168 | } |
| 6169 | |
| 6170 | genlmsg_end(skb, hdr); |
| 6171 | } |
| 6172 | |
| 6173 | err = skb->len; |
| 6174 | /* see above */ |
| 6175 | cb->args[0] = phy_idx + 1; |
| 6176 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6177 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6178 | return err; |
| 6179 | } |
| 6180 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6181 | static struct sk_buff * |
| 6182 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6183 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6184 | { |
| 6185 | struct sk_buff *skb; |
| 6186 | void *hdr; |
| 6187 | struct nlattr *data; |
| 6188 | |
| 6189 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6190 | if (!skb) |
| 6191 | return NULL; |
| 6192 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6193 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6194 | if (!hdr) { |
| 6195 | kfree_skb(skb); |
| 6196 | return NULL; |
| 6197 | } |
| 6198 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6199 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6200 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6201 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6202 | |
| 6203 | ((void **)skb->cb)[0] = rdev; |
| 6204 | ((void **)skb->cb)[1] = hdr; |
| 6205 | ((void **)skb->cb)[2] = data; |
| 6206 | |
| 6207 | return skb; |
| 6208 | |
| 6209 | nla_put_failure: |
| 6210 | kfree_skb(skb); |
| 6211 | return NULL; |
| 6212 | } |
| 6213 | |
| 6214 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6215 | int approxlen) |
| 6216 | { |
| 6217 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6218 | |
| 6219 | if (WARN_ON(!rdev->testmode_info)) |
| 6220 | return NULL; |
| 6221 | |
| 6222 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6223 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6224 | rdev->testmode_info->snd_seq, |
| 6225 | GFP_KERNEL); |
| 6226 | } |
| 6227 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6228 | |
| 6229 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6230 | { |
| 6231 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6232 | void *hdr = ((void **)skb->cb)[1]; |
| 6233 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6234 | |
| 6235 | if (WARN_ON(!rdev->testmode_info)) { |
| 6236 | kfree_skb(skb); |
| 6237 | return -EINVAL; |
| 6238 | } |
| 6239 | |
| 6240 | nla_nest_end(skb, data); |
| 6241 | genlmsg_end(skb, hdr); |
| 6242 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6243 | } |
| 6244 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6245 | |
| 6246 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6247 | int approxlen, gfp_t gfp) |
| 6248 | { |
| 6249 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6250 | |
| 6251 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6252 | } |
| 6253 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6254 | |
| 6255 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6256 | { |
| 6257 | void *hdr = ((void **)skb->cb)[1]; |
| 6258 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6259 | |
| 6260 | nla_nest_end(skb, data); |
| 6261 | genlmsg_end(skb, hdr); |
| 6262 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6263 | } |
| 6264 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6265 | #endif |
| 6266 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6267 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6268 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6270 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6271 | struct cfg80211_connect_params connect; |
| 6272 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6273 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6274 | int err; |
| 6275 | |
| 6276 | memset(&connect, 0, sizeof(connect)); |
| 6277 | |
| 6278 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6279 | return -EINVAL; |
| 6280 | |
| 6281 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6282 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6283 | return -EINVAL; |
| 6284 | |
| 6285 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6286 | connect.auth_type = |
| 6287 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6288 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6289 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6290 | return -EINVAL; |
| 6291 | } else |
| 6292 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6293 | |
| 6294 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6295 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6296 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6297 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6298 | if (err) |
| 6299 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6300 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6301 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6302 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6303 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6304 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6305 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6306 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6307 | connect.bg_scan_period = -1; |
| 6308 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6309 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6310 | connect.bg_scan_period = |
| 6311 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6312 | } |
| 6313 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6314 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6315 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6316 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6317 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6318 | |
| 6319 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6320 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6321 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6322 | } |
| 6323 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6324 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6325 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6326 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6327 | connect.mfp != NL80211_MFP_NO) |
| 6328 | return -EINVAL; |
| 6329 | } else { |
| 6330 | connect.mfp = NL80211_MFP_NO; |
| 6331 | } |
| 6332 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6333 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6334 | connect.channel = |
| 6335 | ieee80211_get_channel(wiphy, |
| 6336 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6337 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6338 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6339 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6340 | } |
| 6341 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6342 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6343 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6344 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6345 | if (IS_ERR(connkeys)) |
| 6346 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6347 | } |
| 6348 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6349 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6350 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6351 | |
| 6352 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6353 | memcpy(&connect.ht_capa_mask, |
| 6354 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6355 | sizeof(connect.ht_capa_mask)); |
| 6356 | |
| 6357 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6358 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6359 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6360 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6361 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6362 | memcpy(&connect.ht_capa, |
| 6363 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6364 | sizeof(connect.ht_capa)); |
| 6365 | } |
| 6366 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6367 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6368 | if (err) |
| 6369 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6370 | return err; |
| 6371 | } |
| 6372 | |
| 6373 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6374 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6376 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6377 | u16 reason; |
| 6378 | |
| 6379 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6380 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6381 | else |
| 6382 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6383 | |
| 6384 | if (reason == 0) |
| 6385 | return -EINVAL; |
| 6386 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6388 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6389 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6390 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6391 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6392 | } |
| 6393 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6394 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6395 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6397 | struct net *net; |
| 6398 | int err; |
| 6399 | u32 pid; |
| 6400 | |
| 6401 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6402 | return -EINVAL; |
| 6403 | |
| 6404 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6405 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6406 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6407 | if (IS_ERR(net)) |
| 6408 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6409 | |
| 6410 | err = 0; |
| 6411 | |
| 6412 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6413 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6414 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6415 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6416 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6417 | return err; |
| 6418 | } |
| 6419 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6420 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6421 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6423 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6424 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6425 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6426 | struct cfg80211_pmksa pmksa; |
| 6427 | |
| 6428 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6429 | |
| 6430 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6431 | return -EINVAL; |
| 6432 | |
| 6433 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6434 | return -EINVAL; |
| 6435 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6436 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6437 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6438 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6441 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6442 | |
| 6443 | switch (info->genlhdr->cmd) { |
| 6444 | case NL80211_CMD_SET_PMKSA: |
| 6445 | rdev_ops = rdev->ops->set_pmksa; |
| 6446 | break; |
| 6447 | case NL80211_CMD_DEL_PMKSA: |
| 6448 | rdev_ops = rdev->ops->del_pmksa; |
| 6449 | break; |
| 6450 | default: |
| 6451 | WARN_ON(1); |
| 6452 | break; |
| 6453 | } |
| 6454 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6455 | if (!rdev_ops) |
| 6456 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6457 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6458 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6462 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6464 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6465 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6466 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6467 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6468 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6470 | if (!rdev->ops->flush_pmksa) |
| 6471 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6472 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6473 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6474 | } |
| 6475 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6476 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6477 | { |
| 6478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6479 | struct net_device *dev = info->user_ptr[1]; |
| 6480 | u8 action_code, dialog_token; |
| 6481 | u16 status_code; |
| 6482 | u8 *peer; |
| 6483 | |
| 6484 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6485 | !rdev->ops->tdls_mgmt) |
| 6486 | return -EOPNOTSUPP; |
| 6487 | |
| 6488 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6489 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6490 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6491 | !info->attrs[NL80211_ATTR_IE] || |
| 6492 | !info->attrs[NL80211_ATTR_MAC]) |
| 6493 | return -EINVAL; |
| 6494 | |
| 6495 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6496 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6497 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6498 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6499 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6500 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6501 | dialog_token, status_code, |
| 6502 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6503 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6504 | } |
| 6505 | |
| 6506 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6507 | { |
| 6508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6509 | struct net_device *dev = info->user_ptr[1]; |
| 6510 | enum nl80211_tdls_operation operation; |
| 6511 | u8 *peer; |
| 6512 | |
| 6513 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6514 | !rdev->ops->tdls_oper) |
| 6515 | return -EOPNOTSUPP; |
| 6516 | |
| 6517 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6518 | !info->attrs[NL80211_ATTR_MAC]) |
| 6519 | return -EINVAL; |
| 6520 | |
| 6521 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6522 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6523 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6524 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6525 | } |
| 6526 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6527 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6528 | struct genl_info *info) |
| 6529 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6530 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6531 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6532 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6533 | struct sk_buff *msg; |
| 6534 | void *hdr; |
| 6535 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6536 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6537 | int err; |
| 6538 | |
| 6539 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6540 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6541 | return -EINVAL; |
| 6542 | |
| 6543 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6544 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6545 | if (!rdev->ops->remain_on_channel || |
| 6546 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6547 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6548 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6549 | /* |
| 6550 | * We should be on that channel for at least a minimum amount of |
| 6551 | * time (10ms) but no longer than the driver supports. |
| 6552 | */ |
| 6553 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6554 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6555 | return -EINVAL; |
| 6556 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6557 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6558 | if (err) |
| 6559 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6560 | |
| 6561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6562 | if (!msg) |
| 6563 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6564 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6565 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6566 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6567 | |
| 6568 | if (IS_ERR(hdr)) { |
| 6569 | err = PTR_ERR(hdr); |
| 6570 | goto free_msg; |
| 6571 | } |
| 6572 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6573 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6574 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6575 | |
| 6576 | if (err) |
| 6577 | goto free_msg; |
| 6578 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6579 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6580 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6581 | |
| 6582 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6583 | |
| 6584 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6585 | |
| 6586 | nla_put_failure: |
| 6587 | err = -ENOBUFS; |
| 6588 | free_msg: |
| 6589 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6590 | return err; |
| 6591 | } |
| 6592 | |
| 6593 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6594 | struct genl_info *info) |
| 6595 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6597 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6598 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6599 | |
| 6600 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6601 | return -EINVAL; |
| 6602 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6603 | if (!rdev->ops->cancel_remain_on_channel) |
| 6604 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6605 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6606 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6607 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6608 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6609 | } |
| 6610 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6611 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6612 | u8 *rates, u8 rates_len) |
| 6613 | { |
| 6614 | u8 i; |
| 6615 | u32 mask = 0; |
| 6616 | |
| 6617 | for (i = 0; i < rates_len; i++) { |
| 6618 | int rate = (rates[i] & 0x7f) * 5; |
| 6619 | int ridx; |
| 6620 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6621 | struct ieee80211_rate *srate = |
| 6622 | &sband->bitrates[ridx]; |
| 6623 | if (rate == srate->bitrate) { |
| 6624 | mask |= 1 << ridx; |
| 6625 | break; |
| 6626 | } |
| 6627 | } |
| 6628 | if (ridx == sband->n_bitrates) |
| 6629 | return 0; /* rate not found */ |
| 6630 | } |
| 6631 | |
| 6632 | return mask; |
| 6633 | } |
| 6634 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6635 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6636 | u8 *rates, u8 rates_len, |
| 6637 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6638 | { |
| 6639 | u8 i; |
| 6640 | |
| 6641 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6642 | |
| 6643 | for (i = 0; i < rates_len; i++) { |
| 6644 | int ridx, rbit; |
| 6645 | |
| 6646 | ridx = rates[i] / 8; |
| 6647 | rbit = BIT(rates[i] % 8); |
| 6648 | |
| 6649 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6650 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6651 | return false; |
| 6652 | |
| 6653 | /* check availability */ |
| 6654 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6655 | mcs[ridx] |= rbit; |
| 6656 | else |
| 6657 | return false; |
| 6658 | } |
| 6659 | |
| 6660 | return true; |
| 6661 | } |
| 6662 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6663 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6664 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6665 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6666 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6667 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6668 | }; |
| 6669 | |
| 6670 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6671 | struct genl_info *info) |
| 6672 | { |
| 6673 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6675 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6676 | int rem, i; |
| 6677 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6678 | struct nlattr *tx_rates; |
| 6679 | struct ieee80211_supported_band *sband; |
| 6680 | |
| 6681 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6682 | return -EINVAL; |
| 6683 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6684 | if (!rdev->ops->set_bitrate_mask) |
| 6685 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6686 | |
| 6687 | memset(&mask, 0, sizeof(mask)); |
| 6688 | /* Default to all rates enabled */ |
| 6689 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6690 | sband = rdev->wiphy.bands[i]; |
| 6691 | mask.control[i].legacy = |
| 6692 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6693 | if (sband) |
| 6694 | memcpy(mask.control[i].mcs, |
| 6695 | sband->ht_cap.mcs.rx_mask, |
| 6696 | sizeof(mask.control[i].mcs)); |
| 6697 | else |
| 6698 | memset(mask.control[i].mcs, 0, |
| 6699 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | /* |
| 6703 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6704 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6705 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6706 | 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] | 6707 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6708 | { |
| 6709 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6710 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6711 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6712 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6713 | if (sband == NULL) |
| 6714 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6715 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6716 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6717 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6718 | mask.control[band].legacy = rateset_to_mask( |
| 6719 | sband, |
| 6720 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6721 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6722 | if ((mask.control[band].legacy == 0) && |
| 6723 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6724 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6725 | } |
| 6726 | if (tb[NL80211_TXRATE_MCS]) { |
| 6727 | if (!ht_rateset_to_mask( |
| 6728 | sband, |
| 6729 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6730 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6731 | mask.control[band].mcs)) |
| 6732 | return -EINVAL; |
| 6733 | } |
| 6734 | |
| 6735 | if (mask.control[band].legacy == 0) { |
| 6736 | /* don't allow empty legacy rates if HT |
| 6737 | * is not even supported. */ |
| 6738 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6739 | return -EINVAL; |
| 6740 | |
| 6741 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6742 | if (mask.control[band].mcs[i]) |
| 6743 | break; |
| 6744 | |
| 6745 | /* legacy and mcs rates may not be both empty */ |
| 6746 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6748 | } |
| 6749 | } |
| 6750 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6751 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6752 | } |
| 6753 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6754 | 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] | 6755 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6757 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6758 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6759 | |
| 6760 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6761 | return -EINVAL; |
| 6762 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6763 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6764 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6765 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6766 | switch (wdev->iftype) { |
| 6767 | case NL80211_IFTYPE_STATION: |
| 6768 | case NL80211_IFTYPE_ADHOC: |
| 6769 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6770 | case NL80211_IFTYPE_AP: |
| 6771 | case NL80211_IFTYPE_AP_VLAN: |
| 6772 | case NL80211_IFTYPE_MESH_POINT: |
| 6773 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6774 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6775 | break; |
| 6776 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6777 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6778 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6779 | |
| 6780 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6781 | if (!rdev->ops->mgmt_tx) |
| 6782 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6783 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6784 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6785 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6786 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6787 | } |
| 6788 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6789 | 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] | 6790 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6792 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6793 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6794 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6795 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6796 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6797 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6798 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6799 | bool offchan, no_cck, dont_wait_for_ack; |
| 6800 | |
| 6801 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6802 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6803 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6804 | return -EINVAL; |
| 6805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6806 | if (!rdev->ops->mgmt_tx) |
| 6807 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6808 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6809 | switch (wdev->iftype) { |
| 6810 | case NL80211_IFTYPE_STATION: |
| 6811 | case NL80211_IFTYPE_ADHOC: |
| 6812 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6813 | case NL80211_IFTYPE_AP: |
| 6814 | case NL80211_IFTYPE_AP_VLAN: |
| 6815 | case NL80211_IFTYPE_MESH_POINT: |
| 6816 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6817 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6818 | break; |
| 6819 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6820 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6821 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6822 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6823 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6824 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6825 | return -EINVAL; |
| 6826 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6827 | |
| 6828 | /* |
| 6829 | * We should wait on the channel for at least a minimum amount |
| 6830 | * of time (10ms) but no longer than the driver supports. |
| 6831 | */ |
| 6832 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6833 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6834 | return -EINVAL; |
| 6835 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6836 | } |
| 6837 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6838 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6839 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6840 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6841 | return -EINVAL; |
| 6842 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6843 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6844 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6845 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6846 | if (err) |
| 6847 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6848 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6849 | if (!dont_wait_for_ack) { |
| 6850 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6851 | if (!msg) |
| 6852 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6853 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6854 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6855 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6856 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6857 | if (IS_ERR(hdr)) { |
| 6858 | err = PTR_ERR(hdr); |
| 6859 | goto free_msg; |
| 6860 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6861 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6862 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6863 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6864 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6865 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6866 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6867 | if (err) |
| 6868 | goto free_msg; |
| 6869 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6870 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6871 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6872 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6873 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6874 | genlmsg_end(msg, hdr); |
| 6875 | return genlmsg_reply(msg, info); |
| 6876 | } |
| 6877 | |
| 6878 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6879 | |
| 6880 | nla_put_failure: |
| 6881 | err = -ENOBUFS; |
| 6882 | free_msg: |
| 6883 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6884 | return err; |
| 6885 | } |
| 6886 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6887 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6888 | { |
| 6889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6890 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6891 | u64 cookie; |
| 6892 | |
| 6893 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6894 | return -EINVAL; |
| 6895 | |
| 6896 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6897 | return -EOPNOTSUPP; |
| 6898 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6899 | switch (wdev->iftype) { |
| 6900 | case NL80211_IFTYPE_STATION: |
| 6901 | case NL80211_IFTYPE_ADHOC: |
| 6902 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6903 | case NL80211_IFTYPE_AP: |
| 6904 | case NL80211_IFTYPE_AP_VLAN: |
| 6905 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6906 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6907 | break; |
| 6908 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6909 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6910 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6911 | |
| 6912 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6913 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6914 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6915 | } |
| 6916 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6917 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6920 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6921 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6922 | u8 ps_state; |
| 6923 | bool state; |
| 6924 | int err; |
| 6925 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6926 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6927 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6928 | |
| 6929 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6930 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6931 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6932 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6933 | |
| 6934 | wdev = dev->ieee80211_ptr; |
| 6935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6936 | if (!rdev->ops->set_power_mgmt) |
| 6937 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6938 | |
| 6939 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6940 | |
| 6941 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6942 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6943 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6944 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6945 | if (!err) |
| 6946 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6947 | return err; |
| 6948 | } |
| 6949 | |
| 6950 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6951 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6953 | enum nl80211_ps_state ps_state; |
| 6954 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6955 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6956 | struct sk_buff *msg; |
| 6957 | void *hdr; |
| 6958 | int err; |
| 6959 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6960 | wdev = dev->ieee80211_ptr; |
| 6961 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6962 | if (!rdev->ops->set_power_mgmt) |
| 6963 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6964 | |
| 6965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6966 | if (!msg) |
| 6967 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6968 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6969 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6970 | NL80211_CMD_GET_POWER_SAVE); |
| 6971 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6972 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6973 | goto free_msg; |
| 6974 | } |
| 6975 | |
| 6976 | if (wdev->ps) |
| 6977 | ps_state = NL80211_PS_ENABLED; |
| 6978 | else |
| 6979 | ps_state = NL80211_PS_DISABLED; |
| 6980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6981 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6982 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6983 | |
| 6984 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6985 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6987 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6988 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6989 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6990 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6991 | return err; |
| 6992 | } |
| 6993 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6994 | static struct nla_policy |
| 6995 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6996 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6997 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6998 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6999 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7000 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7001 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7002 | }; |
| 7003 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7004 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7005 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7006 | { |
| 7007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7008 | struct wireless_dev *wdev; |
| 7009 | struct net_device *dev = info->user_ptr[1]; |
| 7010 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7011 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7012 | return -EINVAL; |
| 7013 | |
| 7014 | wdev = dev->ieee80211_ptr; |
| 7015 | |
| 7016 | if (!rdev->ops->set_cqm_txe_config) |
| 7017 | return -EOPNOTSUPP; |
| 7018 | |
| 7019 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7020 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7021 | return -EOPNOTSUPP; |
| 7022 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7023 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7024 | } |
| 7025 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7026 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7027 | s32 threshold, u32 hysteresis) |
| 7028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7030 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7031 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7032 | |
| 7033 | if (threshold > 0) |
| 7034 | return -EINVAL; |
| 7035 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7036 | wdev = dev->ieee80211_ptr; |
| 7037 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7038 | if (!rdev->ops->set_cqm_rssi_config) |
| 7039 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7040 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7041 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7042 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7043 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7044 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7045 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7049 | { |
| 7050 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7051 | struct nlattr *cqm; |
| 7052 | int err; |
| 7053 | |
| 7054 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7055 | if (!cqm) { |
| 7056 | err = -EINVAL; |
| 7057 | goto out; |
| 7058 | } |
| 7059 | |
| 7060 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7061 | nl80211_attr_cqm_policy); |
| 7062 | if (err) |
| 7063 | goto out; |
| 7064 | |
| 7065 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7066 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7067 | s32 threshold; |
| 7068 | u32 hysteresis; |
| 7069 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7070 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7071 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7072 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7073 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7074 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7075 | u32 rate, pkts, intvl; |
| 7076 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7077 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7078 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7079 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7080 | } else |
| 7081 | err = -EINVAL; |
| 7082 | |
| 7083 | out: |
| 7084 | return err; |
| 7085 | } |
| 7086 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7087 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7088 | { |
| 7089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7090 | struct net_device *dev = info->user_ptr[1]; |
| 7091 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7092 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7093 | int err; |
| 7094 | |
| 7095 | /* start with default */ |
| 7096 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7097 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7098 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7099 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7100 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7101 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7102 | if (err) |
| 7103 | return err; |
| 7104 | } |
| 7105 | |
| 7106 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7107 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7108 | return -EINVAL; |
| 7109 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7110 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7111 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7112 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7113 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7114 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7115 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7116 | return -EINVAL; |
| 7117 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7118 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7119 | setup.beacon_interval = |
| 7120 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7121 | if (setup.beacon_interval < 10 || |
| 7122 | setup.beacon_interval > 10000) |
| 7123 | return -EINVAL; |
| 7124 | } |
| 7125 | |
| 7126 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7127 | setup.dtim_period = |
| 7128 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7129 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7130 | return -EINVAL; |
| 7131 | } |
| 7132 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7133 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7134 | /* parse additional setup parameters if given */ |
| 7135 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7136 | if (err) |
| 7137 | return err; |
| 7138 | } |
| 7139 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7140 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7141 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7142 | if (err) |
| 7143 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7144 | } else { |
| 7145 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7146 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7147 | } |
| 7148 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7149 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7153 | { |
| 7154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7155 | struct net_device *dev = info->user_ptr[1]; |
| 7156 | |
| 7157 | return cfg80211_leave_mesh(rdev, dev); |
| 7158 | } |
| 7159 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7160 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7161 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7162 | struct cfg80211_registered_device *rdev) |
| 7163 | { |
| 7164 | struct nlattr *nl_pats, *nl_pat; |
| 7165 | int i, pat_len; |
| 7166 | |
| 7167 | if (!rdev->wowlan->n_patterns) |
| 7168 | return 0; |
| 7169 | |
| 7170 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7171 | if (!nl_pats) |
| 7172 | return -ENOBUFS; |
| 7173 | |
| 7174 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7175 | nl_pat = nla_nest_start(msg, i + 1); |
| 7176 | if (!nl_pat) |
| 7177 | return -ENOBUFS; |
| 7178 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7179 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7180 | DIV_ROUND_UP(pat_len, 8), |
| 7181 | rdev->wowlan->patterns[i].mask) || |
| 7182 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7183 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7184 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7185 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7186 | return -ENOBUFS; |
| 7187 | nla_nest_end(msg, nl_pat); |
| 7188 | } |
| 7189 | nla_nest_end(msg, nl_pats); |
| 7190 | |
| 7191 | return 0; |
| 7192 | } |
| 7193 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7194 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7195 | struct cfg80211_wowlan_tcp *tcp) |
| 7196 | { |
| 7197 | struct nlattr *nl_tcp; |
| 7198 | |
| 7199 | if (!tcp) |
| 7200 | return 0; |
| 7201 | |
| 7202 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7203 | if (!nl_tcp) |
| 7204 | return -ENOBUFS; |
| 7205 | |
| 7206 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7207 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7208 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7209 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7210 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7211 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7212 | tcp->payload_len, tcp->payload) || |
| 7213 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7214 | tcp->data_interval) || |
| 7215 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7216 | tcp->wake_len, tcp->wake_data) || |
| 7217 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7218 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7219 | return -ENOBUFS; |
| 7220 | |
| 7221 | if (tcp->payload_seq.len && |
| 7222 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7223 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7224 | return -ENOBUFS; |
| 7225 | |
| 7226 | if (tcp->payload_tok.len && |
| 7227 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7228 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7229 | &tcp->payload_tok)) |
| 7230 | return -ENOBUFS; |
| 7231 | |
| 7232 | return 0; |
| 7233 | } |
| 7234 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7235 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7236 | { |
| 7237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7238 | struct sk_buff *msg; |
| 7239 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7240 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7241 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7242 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7243 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7244 | return -EOPNOTSUPP; |
| 7245 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7246 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7247 | /* adjust size to have room for all the data */ |
| 7248 | size += rdev->wowlan->tcp->tokens_size + |
| 7249 | rdev->wowlan->tcp->payload_len + |
| 7250 | rdev->wowlan->tcp->wake_len + |
| 7251 | rdev->wowlan->tcp->wake_len / 8; |
| 7252 | } |
| 7253 | |
| 7254 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7255 | if (!msg) |
| 7256 | return -ENOMEM; |
| 7257 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7258 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7259 | NL80211_CMD_GET_WOWLAN); |
| 7260 | if (!hdr) |
| 7261 | goto nla_put_failure; |
| 7262 | |
| 7263 | if (rdev->wowlan) { |
| 7264 | struct nlattr *nl_wowlan; |
| 7265 | |
| 7266 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7267 | if (!nl_wowlan) |
| 7268 | goto nla_put_failure; |
| 7269 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7270 | if ((rdev->wowlan->any && |
| 7271 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7272 | (rdev->wowlan->disconnect && |
| 7273 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7274 | (rdev->wowlan->magic_pkt && |
| 7275 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7276 | (rdev->wowlan->gtk_rekey_failure && |
| 7277 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7278 | (rdev->wowlan->eap_identity_req && |
| 7279 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7280 | (rdev->wowlan->four_way_handshake && |
| 7281 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7282 | (rdev->wowlan->rfkill_release && |
| 7283 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7284 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7285 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7286 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7287 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7288 | |
| 7289 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7290 | goto nla_put_failure; |
| 7291 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7292 | nla_nest_end(msg, nl_wowlan); |
| 7293 | } |
| 7294 | |
| 7295 | genlmsg_end(msg, hdr); |
| 7296 | return genlmsg_reply(msg, info); |
| 7297 | |
| 7298 | nla_put_failure: |
| 7299 | nlmsg_free(msg); |
| 7300 | return -ENOBUFS; |
| 7301 | } |
| 7302 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7303 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7304 | struct nlattr *attr, |
| 7305 | struct cfg80211_wowlan *trig) |
| 7306 | { |
| 7307 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7308 | struct cfg80211_wowlan_tcp *cfg; |
| 7309 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7310 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7311 | u32 size; |
| 7312 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7313 | int err, port; |
| 7314 | |
| 7315 | if (!rdev->wiphy.wowlan.tcp) |
| 7316 | return -EINVAL; |
| 7317 | |
| 7318 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7319 | nla_data(attr), nla_len(attr), |
| 7320 | nl80211_wowlan_tcp_policy); |
| 7321 | if (err) |
| 7322 | return err; |
| 7323 | |
| 7324 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7325 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7326 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7327 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7328 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7329 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7330 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7331 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7332 | return -EINVAL; |
| 7333 | |
| 7334 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7335 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7336 | return -EINVAL; |
| 7337 | |
| 7338 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 7339 | rdev->wiphy.wowlan.tcp->data_interval_max) |
| 7340 | return -EINVAL; |
| 7341 | |
| 7342 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7343 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7344 | return -EINVAL; |
| 7345 | |
| 7346 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7347 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7348 | return -EINVAL; |
| 7349 | |
| 7350 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7351 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7352 | |
| 7353 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7354 | tokens_size = tokln - sizeof(*tok); |
| 7355 | |
| 7356 | if (!tok->len || tokens_size % tok->len) |
| 7357 | return -EINVAL; |
| 7358 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7359 | return -EINVAL; |
| 7360 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7361 | return -EINVAL; |
| 7362 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7363 | return -EINVAL; |
| 7364 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7365 | return -EINVAL; |
| 7366 | if (tok->offset + tok->len > data_size) |
| 7367 | return -EINVAL; |
| 7368 | } |
| 7369 | |
| 7370 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7371 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7372 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7373 | return -EINVAL; |
| 7374 | if (seq->len == 0 || seq->len > 4) |
| 7375 | return -EINVAL; |
| 7376 | if (seq->len + seq->offset > data_size) |
| 7377 | return -EINVAL; |
| 7378 | } |
| 7379 | |
| 7380 | size = sizeof(*cfg); |
| 7381 | size += data_size; |
| 7382 | size += wake_size + wake_mask_size; |
| 7383 | size += tokens_size; |
| 7384 | |
| 7385 | cfg = kzalloc(size, GFP_KERNEL); |
| 7386 | if (!cfg) |
| 7387 | return -ENOMEM; |
| 7388 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7389 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7390 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7391 | ETH_ALEN); |
| 7392 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7393 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7394 | else |
| 7395 | port = 0; |
| 7396 | #ifdef CONFIG_INET |
| 7397 | /* allocate a socket and port for it and use it */ |
| 7398 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7399 | IPPROTO_TCP, &cfg->sock, 1); |
| 7400 | if (err) { |
| 7401 | kfree(cfg); |
| 7402 | return err; |
| 7403 | } |
| 7404 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7405 | sock_release(cfg->sock); |
| 7406 | kfree(cfg); |
| 7407 | return -EADDRINUSE; |
| 7408 | } |
| 7409 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7410 | #else |
| 7411 | if (!port) { |
| 7412 | kfree(cfg); |
| 7413 | return -EINVAL; |
| 7414 | } |
| 7415 | cfg->src_port = port; |
| 7416 | #endif |
| 7417 | |
| 7418 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7419 | cfg->payload_len = data_size; |
| 7420 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7421 | memcpy((void *)cfg->payload, |
| 7422 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7423 | data_size); |
| 7424 | if (seq) |
| 7425 | cfg->payload_seq = *seq; |
| 7426 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7427 | cfg->wake_len = wake_size; |
| 7428 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7429 | memcpy((void *)cfg->wake_data, |
| 7430 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7431 | wake_size); |
| 7432 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7433 | data_size + wake_size; |
| 7434 | memcpy((void *)cfg->wake_mask, |
| 7435 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7436 | wake_mask_size); |
| 7437 | if (tok) { |
| 7438 | cfg->tokens_size = tokens_size; |
| 7439 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7440 | } |
| 7441 | |
| 7442 | trig->tcp = cfg; |
| 7443 | |
| 7444 | return 0; |
| 7445 | } |
| 7446 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7447 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7448 | { |
| 7449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7450 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7451 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7452 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7453 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7454 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7455 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7456 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7457 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7458 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7459 | return -EOPNOTSUPP; |
| 7460 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7461 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7462 | cfg80211_rdev_free_wowlan(rdev); |
| 7463 | rdev->wowlan = NULL; |
| 7464 | goto set_wakeup; |
| 7465 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7466 | |
| 7467 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7468 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7469 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7470 | nl80211_wowlan_policy); |
| 7471 | if (err) |
| 7472 | return err; |
| 7473 | |
| 7474 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7475 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7476 | return -EINVAL; |
| 7477 | new_triggers.any = true; |
| 7478 | } |
| 7479 | |
| 7480 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7481 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7482 | return -EINVAL; |
| 7483 | new_triggers.disconnect = true; |
| 7484 | } |
| 7485 | |
| 7486 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7487 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7488 | return -EINVAL; |
| 7489 | new_triggers.magic_pkt = true; |
| 7490 | } |
| 7491 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7492 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7493 | return -EINVAL; |
| 7494 | |
| 7495 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7496 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7497 | return -EINVAL; |
| 7498 | new_triggers.gtk_rekey_failure = true; |
| 7499 | } |
| 7500 | |
| 7501 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7502 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7503 | return -EINVAL; |
| 7504 | new_triggers.eap_identity_req = true; |
| 7505 | } |
| 7506 | |
| 7507 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7508 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7509 | return -EINVAL; |
| 7510 | new_triggers.four_way_handshake = true; |
| 7511 | } |
| 7512 | |
| 7513 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7514 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7515 | return -EINVAL; |
| 7516 | new_triggers.rfkill_release = true; |
| 7517 | } |
| 7518 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7519 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7520 | struct nlattr *pat; |
| 7521 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7522 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7523 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7524 | |
| 7525 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7526 | rem) |
| 7527 | n_patterns++; |
| 7528 | if (n_patterns > wowlan->n_patterns) |
| 7529 | return -EINVAL; |
| 7530 | |
| 7531 | new_triggers.patterns = kcalloc(n_patterns, |
| 7532 | sizeof(new_triggers.patterns[0]), |
| 7533 | GFP_KERNEL); |
| 7534 | if (!new_triggers.patterns) |
| 7535 | return -ENOMEM; |
| 7536 | |
| 7537 | new_triggers.n_patterns = n_patterns; |
| 7538 | i = 0; |
| 7539 | |
| 7540 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7541 | rem) { |
| 7542 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7543 | nla_data(pat), nla_len(pat), NULL); |
| 7544 | err = -EINVAL; |
| 7545 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7546 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7547 | goto error; |
| 7548 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7549 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7550 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7551 | mask_len) |
| 7552 | goto error; |
| 7553 | if (pat_len > wowlan->pattern_max_len || |
| 7554 | pat_len < wowlan->pattern_min_len) |
| 7555 | goto error; |
| 7556 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7557 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7558 | pkt_offset = 0; |
| 7559 | else |
| 7560 | pkt_offset = nla_get_u32( |
| 7561 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7562 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7563 | goto error; |
| 7564 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7565 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7566 | new_triggers.patterns[i].mask = |
| 7567 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7568 | if (!new_triggers.patterns[i].mask) { |
| 7569 | err = -ENOMEM; |
| 7570 | goto error; |
| 7571 | } |
| 7572 | new_triggers.patterns[i].pattern = |
| 7573 | new_triggers.patterns[i].mask + mask_len; |
| 7574 | memcpy(new_triggers.patterns[i].mask, |
| 7575 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7576 | mask_len); |
| 7577 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7578 | memcpy(new_triggers.patterns[i].pattern, |
| 7579 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7580 | pat_len); |
| 7581 | i++; |
| 7582 | } |
| 7583 | } |
| 7584 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7585 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7586 | err = nl80211_parse_wowlan_tcp( |
| 7587 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7588 | &new_triggers); |
| 7589 | if (err) |
| 7590 | goto error; |
| 7591 | } |
| 7592 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7593 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7594 | if (!ntrig) { |
| 7595 | err = -ENOMEM; |
| 7596 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7597 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7598 | cfg80211_rdev_free_wowlan(rdev); |
| 7599 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7600 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7601 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7602 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7603 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7604 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7605 | return 0; |
| 7606 | error: |
| 7607 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7608 | kfree(new_triggers.patterns[i].mask); |
| 7609 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7610 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7611 | sock_release(new_triggers.tcp->sock); |
| 7612 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7613 | return err; |
| 7614 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7615 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7616 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7617 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7618 | { |
| 7619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7620 | struct net_device *dev = info->user_ptr[1]; |
| 7621 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7622 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7623 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7624 | int err; |
| 7625 | |
| 7626 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7627 | return -EINVAL; |
| 7628 | |
| 7629 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7630 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7631 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7632 | nl80211_rekey_policy); |
| 7633 | if (err) |
| 7634 | return err; |
| 7635 | |
| 7636 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7637 | return -ERANGE; |
| 7638 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7639 | return -ERANGE; |
| 7640 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7641 | return -ERANGE; |
| 7642 | |
| 7643 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7644 | NL80211_KEK_LEN); |
| 7645 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7646 | NL80211_KCK_LEN); |
| 7647 | memcpy(rekey_data.replay_ctr, |
| 7648 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7649 | NL80211_REPLAY_CTR_LEN); |
| 7650 | |
| 7651 | wdev_lock(wdev); |
| 7652 | if (!wdev->current_bss) { |
| 7653 | err = -ENOTCONN; |
| 7654 | goto out; |
| 7655 | } |
| 7656 | |
| 7657 | if (!rdev->ops->set_rekey_data) { |
| 7658 | err = -EOPNOTSUPP; |
| 7659 | goto out; |
| 7660 | } |
| 7661 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7662 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7663 | out: |
| 7664 | wdev_unlock(wdev); |
| 7665 | return err; |
| 7666 | } |
| 7667 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7668 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7669 | struct genl_info *info) |
| 7670 | { |
| 7671 | struct net_device *dev = info->user_ptr[1]; |
| 7672 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7673 | |
| 7674 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7675 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7676 | return -EINVAL; |
| 7677 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7678 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7679 | return -EBUSY; |
| 7680 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7681 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7682 | return 0; |
| 7683 | } |
| 7684 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7685 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7686 | struct genl_info *info) |
| 7687 | { |
| 7688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7689 | struct net_device *dev = info->user_ptr[1]; |
| 7690 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7691 | struct sk_buff *msg; |
| 7692 | void *hdr; |
| 7693 | const u8 *addr; |
| 7694 | u64 cookie; |
| 7695 | int err; |
| 7696 | |
| 7697 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7698 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7699 | return -EOPNOTSUPP; |
| 7700 | |
| 7701 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7702 | return -EINVAL; |
| 7703 | |
| 7704 | if (!rdev->ops->probe_client) |
| 7705 | return -EOPNOTSUPP; |
| 7706 | |
| 7707 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7708 | if (!msg) |
| 7709 | return -ENOMEM; |
| 7710 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7711 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7712 | NL80211_CMD_PROBE_CLIENT); |
| 7713 | |
| 7714 | if (IS_ERR(hdr)) { |
| 7715 | err = PTR_ERR(hdr); |
| 7716 | goto free_msg; |
| 7717 | } |
| 7718 | |
| 7719 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7720 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7721 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7722 | if (err) |
| 7723 | goto free_msg; |
| 7724 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7725 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7726 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7727 | |
| 7728 | genlmsg_end(msg, hdr); |
| 7729 | |
| 7730 | return genlmsg_reply(msg, info); |
| 7731 | |
| 7732 | nla_put_failure: |
| 7733 | err = -ENOBUFS; |
| 7734 | free_msg: |
| 7735 | nlmsg_free(msg); |
| 7736 | return err; |
| 7737 | } |
| 7738 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7739 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7740 | { |
| 7741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7742 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7743 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7744 | |
| 7745 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7746 | return -EOPNOTSUPP; |
| 7747 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7748 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7749 | if (!nreg) |
| 7750 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7751 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7752 | /* First, check if already registered. */ |
| 7753 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7754 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7755 | if (reg->nlportid == info->snd_portid) { |
| 7756 | rv = -EALREADY; |
| 7757 | goto out_err; |
| 7758 | } |
| 7759 | } |
| 7760 | /* Add it to the list */ |
| 7761 | nreg->nlportid = info->snd_portid; |
| 7762 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7763 | |
| 7764 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7765 | |
| 7766 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7767 | out_err: |
| 7768 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7769 | kfree(nreg); |
| 7770 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7771 | } |
| 7772 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7773 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7774 | { |
| 7775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7776 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7777 | int err; |
| 7778 | |
| 7779 | if (!rdev->ops->start_p2p_device) |
| 7780 | return -EOPNOTSUPP; |
| 7781 | |
| 7782 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7783 | return -EOPNOTSUPP; |
| 7784 | |
| 7785 | if (wdev->p2p_started) |
| 7786 | return 0; |
| 7787 | |
| 7788 | mutex_lock(&rdev->devlist_mtx); |
| 7789 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7790 | mutex_unlock(&rdev->devlist_mtx); |
| 7791 | if (err) |
| 7792 | return err; |
| 7793 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7794 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7795 | if (err) |
| 7796 | return err; |
| 7797 | |
| 7798 | wdev->p2p_started = true; |
| 7799 | mutex_lock(&rdev->devlist_mtx); |
| 7800 | rdev->opencount++; |
| 7801 | mutex_unlock(&rdev->devlist_mtx); |
| 7802 | |
| 7803 | return 0; |
| 7804 | } |
| 7805 | |
| 7806 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7807 | { |
| 7808 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7809 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7810 | |
| 7811 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7812 | return -EOPNOTSUPP; |
| 7813 | |
| 7814 | if (!rdev->ops->stop_p2p_device) |
| 7815 | return -EOPNOTSUPP; |
| 7816 | |
| 7817 | if (!wdev->p2p_started) |
| 7818 | return 0; |
| 7819 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7820 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7821 | wdev->p2p_started = false; |
| 7822 | |
| 7823 | mutex_lock(&rdev->devlist_mtx); |
| 7824 | rdev->opencount--; |
| 7825 | mutex_unlock(&rdev->devlist_mtx); |
| 7826 | |
| 7827 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7828 | rdev->scan_req->aborted = true; |
| 7829 | ___cfg80211_scan_done(rdev, true); |
| 7830 | } |
| 7831 | |
| 7832 | return 0; |
| 7833 | } |
| 7834 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7835 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7836 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7837 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7838 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7839 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7840 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7841 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7842 | /* 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] | 7843 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7844 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7845 | |
| 7846 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7847 | struct genl_info *info) |
| 7848 | { |
| 7849 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7850 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7851 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7852 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7853 | |
| 7854 | if (rtnl) |
| 7855 | rtnl_lock(); |
| 7856 | |
| 7857 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7858 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7859 | if (IS_ERR(rdev)) { |
| 7860 | if (rtnl) |
| 7861 | rtnl_unlock(); |
| 7862 | return PTR_ERR(rdev); |
| 7863 | } |
| 7864 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7865 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7866 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7867 | mutex_lock(&cfg80211_mutex); |
| 7868 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7869 | info->attrs); |
| 7870 | if (IS_ERR(wdev)) { |
| 7871 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7872 | if (rtnl) |
| 7873 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7874 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7875 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7876 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7877 | dev = wdev->netdev; |
| 7878 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7879 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7880 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7881 | if (!dev) { |
| 7882 | mutex_unlock(&cfg80211_mutex); |
| 7883 | if (rtnl) |
| 7884 | rtnl_unlock(); |
| 7885 | return -EINVAL; |
| 7886 | } |
| 7887 | |
| 7888 | info->user_ptr[1] = dev; |
| 7889 | } else { |
| 7890 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7891 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7892 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7893 | if (dev) { |
| 7894 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7895 | !netif_running(dev)) { |
| 7896 | mutex_unlock(&cfg80211_mutex); |
| 7897 | if (rtnl) |
| 7898 | rtnl_unlock(); |
| 7899 | return -ENETDOWN; |
| 7900 | } |
| 7901 | |
| 7902 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7903 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7904 | if (!wdev->p2p_started) { |
| 7905 | mutex_unlock(&cfg80211_mutex); |
| 7906 | if (rtnl) |
| 7907 | rtnl_unlock(); |
| 7908 | return -ENETDOWN; |
| 7909 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7910 | } |
| 7911 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7912 | cfg80211_lock_rdev(rdev); |
| 7913 | |
| 7914 | mutex_unlock(&cfg80211_mutex); |
| 7915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7916 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7917 | } |
| 7918 | |
| 7919 | return 0; |
| 7920 | } |
| 7921 | |
| 7922 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7923 | struct genl_info *info) |
| 7924 | { |
| 7925 | if (info->user_ptr[0]) |
| 7926 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7927 | if (info->user_ptr[1]) { |
| 7928 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7929 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7930 | |
| 7931 | if (wdev->netdev) |
| 7932 | dev_put(wdev->netdev); |
| 7933 | } else { |
| 7934 | dev_put(info->user_ptr[1]); |
| 7935 | } |
| 7936 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7937 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7938 | rtnl_unlock(); |
| 7939 | } |
| 7940 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7941 | static struct genl_ops nl80211_ops[] = { |
| 7942 | { |
| 7943 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7944 | .doit = nl80211_get_wiphy, |
| 7945 | .dumpit = nl80211_dump_wiphy, |
| 7946 | .policy = nl80211_policy, |
| 7947 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7948 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7949 | }, |
| 7950 | { |
| 7951 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7952 | .doit = nl80211_set_wiphy, |
| 7953 | .policy = nl80211_policy, |
| 7954 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7955 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7956 | }, |
| 7957 | { |
| 7958 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7959 | .doit = nl80211_get_interface, |
| 7960 | .dumpit = nl80211_dump_interface, |
| 7961 | .policy = nl80211_policy, |
| 7962 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7963 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7964 | }, |
| 7965 | { |
| 7966 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7967 | .doit = nl80211_set_interface, |
| 7968 | .policy = nl80211_policy, |
| 7969 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7970 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7971 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7972 | }, |
| 7973 | { |
| 7974 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7975 | .doit = nl80211_new_interface, |
| 7976 | .policy = nl80211_policy, |
| 7977 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7978 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7979 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7980 | }, |
| 7981 | { |
| 7982 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7983 | .doit = nl80211_del_interface, |
| 7984 | .policy = nl80211_policy, |
| 7985 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7986 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7987 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7988 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7989 | { |
| 7990 | .cmd = NL80211_CMD_GET_KEY, |
| 7991 | .doit = nl80211_get_key, |
| 7992 | .policy = nl80211_policy, |
| 7993 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7995 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7996 | }, |
| 7997 | { |
| 7998 | .cmd = NL80211_CMD_SET_KEY, |
| 7999 | .doit = nl80211_set_key, |
| 8000 | .policy = nl80211_policy, |
| 8001 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8003 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8004 | }, |
| 8005 | { |
| 8006 | .cmd = NL80211_CMD_NEW_KEY, |
| 8007 | .doit = nl80211_new_key, |
| 8008 | .policy = nl80211_policy, |
| 8009 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8010 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8011 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8012 | }, |
| 8013 | { |
| 8014 | .cmd = NL80211_CMD_DEL_KEY, |
| 8015 | .doit = nl80211_del_key, |
| 8016 | .policy = nl80211_policy, |
| 8017 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8018 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8019 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8020 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8021 | { |
| 8022 | .cmd = NL80211_CMD_SET_BEACON, |
| 8023 | .policy = nl80211_policy, |
| 8024 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8025 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8026 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8027 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8028 | }, |
| 8029 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8030 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8031 | .policy = nl80211_policy, |
| 8032 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8033 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8034 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8035 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8036 | }, |
| 8037 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8038 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8039 | .policy = nl80211_policy, |
| 8040 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8041 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8043 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8044 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8045 | { |
| 8046 | .cmd = NL80211_CMD_GET_STATION, |
| 8047 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8048 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8049 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8050 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8051 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8052 | }, |
| 8053 | { |
| 8054 | .cmd = NL80211_CMD_SET_STATION, |
| 8055 | .doit = nl80211_set_station, |
| 8056 | .policy = nl80211_policy, |
| 8057 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8059 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8060 | }, |
| 8061 | { |
| 8062 | .cmd = NL80211_CMD_NEW_STATION, |
| 8063 | .doit = nl80211_new_station, |
| 8064 | .policy = nl80211_policy, |
| 8065 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8066 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8067 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8068 | }, |
| 8069 | { |
| 8070 | .cmd = NL80211_CMD_DEL_STATION, |
| 8071 | .doit = nl80211_del_station, |
| 8072 | .policy = nl80211_policy, |
| 8073 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8074 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8075 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8076 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8077 | { |
| 8078 | .cmd = NL80211_CMD_GET_MPATH, |
| 8079 | .doit = nl80211_get_mpath, |
| 8080 | .dumpit = nl80211_dump_mpath, |
| 8081 | .policy = nl80211_policy, |
| 8082 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8083 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8084 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8085 | }, |
| 8086 | { |
| 8087 | .cmd = NL80211_CMD_SET_MPATH, |
| 8088 | .doit = nl80211_set_mpath, |
| 8089 | .policy = nl80211_policy, |
| 8090 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8091 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8092 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8093 | }, |
| 8094 | { |
| 8095 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8096 | .doit = nl80211_new_mpath, |
| 8097 | .policy = nl80211_policy, |
| 8098 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8099 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8100 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8101 | }, |
| 8102 | { |
| 8103 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8104 | .doit = nl80211_del_mpath, |
| 8105 | .policy = nl80211_policy, |
| 8106 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8107 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8108 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8109 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8110 | { |
| 8111 | .cmd = NL80211_CMD_SET_BSS, |
| 8112 | .doit = nl80211_set_bss, |
| 8113 | .policy = nl80211_policy, |
| 8114 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8115 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8116 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8117 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8118 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8119 | .cmd = NL80211_CMD_GET_REG, |
| 8120 | .doit = nl80211_get_reg, |
| 8121 | .policy = nl80211_policy, |
| 8122 | /* can be retrieved by unprivileged users */ |
| 8123 | }, |
| 8124 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8125 | .cmd = NL80211_CMD_SET_REG, |
| 8126 | .doit = nl80211_set_reg, |
| 8127 | .policy = nl80211_policy, |
| 8128 | .flags = GENL_ADMIN_PERM, |
| 8129 | }, |
| 8130 | { |
| 8131 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8132 | .doit = nl80211_req_set_reg, |
| 8133 | .policy = nl80211_policy, |
| 8134 | .flags = GENL_ADMIN_PERM, |
| 8135 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8136 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8137 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8138 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8139 | .policy = nl80211_policy, |
| 8140 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8141 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8142 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8143 | }, |
| 8144 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8145 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8146 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8147 | .policy = nl80211_policy, |
| 8148 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8149 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8150 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8151 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8152 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8153 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8154 | .doit = nl80211_trigger_scan, |
| 8155 | .policy = nl80211_policy, |
| 8156 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8157 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8158 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8159 | }, |
| 8160 | { |
| 8161 | .cmd = NL80211_CMD_GET_SCAN, |
| 8162 | .policy = nl80211_policy, |
| 8163 | .dumpit = nl80211_dump_scan, |
| 8164 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8165 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8166 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8167 | .doit = nl80211_start_sched_scan, |
| 8168 | .policy = nl80211_policy, |
| 8169 | .flags = GENL_ADMIN_PERM, |
| 8170 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8171 | NL80211_FLAG_NEED_RTNL, |
| 8172 | }, |
| 8173 | { |
| 8174 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8175 | .doit = nl80211_stop_sched_scan, |
| 8176 | .policy = nl80211_policy, |
| 8177 | .flags = GENL_ADMIN_PERM, |
| 8178 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8179 | NL80211_FLAG_NEED_RTNL, |
| 8180 | }, |
| 8181 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8182 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8183 | .doit = nl80211_authenticate, |
| 8184 | .policy = nl80211_policy, |
| 8185 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8186 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8187 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8188 | }, |
| 8189 | { |
| 8190 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8191 | .doit = nl80211_associate, |
| 8192 | .policy = nl80211_policy, |
| 8193 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8194 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8195 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8196 | }, |
| 8197 | { |
| 8198 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8199 | .doit = nl80211_deauthenticate, |
| 8200 | .policy = nl80211_policy, |
| 8201 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8203 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8204 | }, |
| 8205 | { |
| 8206 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8207 | .doit = nl80211_disassociate, |
| 8208 | .policy = nl80211_policy, |
| 8209 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8211 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8212 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8213 | { |
| 8214 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8215 | .doit = nl80211_join_ibss, |
| 8216 | .policy = nl80211_policy, |
| 8217 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8219 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8220 | }, |
| 8221 | { |
| 8222 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8223 | .doit = nl80211_leave_ibss, |
| 8224 | .policy = nl80211_policy, |
| 8225 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8226 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8227 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8228 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8229 | #ifdef CONFIG_NL80211_TESTMODE |
| 8230 | { |
| 8231 | .cmd = NL80211_CMD_TESTMODE, |
| 8232 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8233 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8234 | .policy = nl80211_policy, |
| 8235 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8236 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8237 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8238 | }, |
| 8239 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8240 | { |
| 8241 | .cmd = NL80211_CMD_CONNECT, |
| 8242 | .doit = nl80211_connect, |
| 8243 | .policy = nl80211_policy, |
| 8244 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8245 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8246 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8247 | }, |
| 8248 | { |
| 8249 | .cmd = NL80211_CMD_DISCONNECT, |
| 8250 | .doit = nl80211_disconnect, |
| 8251 | .policy = nl80211_policy, |
| 8252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8253 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8254 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8255 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8256 | { |
| 8257 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8258 | .doit = nl80211_wiphy_netns, |
| 8259 | .policy = nl80211_policy, |
| 8260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8261 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8262 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8263 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8264 | { |
| 8265 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8266 | .policy = nl80211_policy, |
| 8267 | .dumpit = nl80211_dump_survey, |
| 8268 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8269 | { |
| 8270 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8271 | .doit = nl80211_setdel_pmksa, |
| 8272 | .policy = nl80211_policy, |
| 8273 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8274 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8275 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8276 | }, |
| 8277 | { |
| 8278 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8279 | .doit = nl80211_setdel_pmksa, |
| 8280 | .policy = nl80211_policy, |
| 8281 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8282 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8283 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8284 | }, |
| 8285 | { |
| 8286 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8287 | .doit = nl80211_flush_pmksa, |
| 8288 | .policy = nl80211_policy, |
| 8289 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8290 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8291 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8292 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8293 | { |
| 8294 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8295 | .doit = nl80211_remain_on_channel, |
| 8296 | .policy = nl80211_policy, |
| 8297 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8298 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8299 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8300 | }, |
| 8301 | { |
| 8302 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8303 | .doit = nl80211_cancel_remain_on_channel, |
| 8304 | .policy = nl80211_policy, |
| 8305 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8306 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8307 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8308 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8309 | { |
| 8310 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8311 | .doit = nl80211_set_tx_bitrate_mask, |
| 8312 | .policy = nl80211_policy, |
| 8313 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8314 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8315 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8316 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8317 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8318 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8319 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8320 | .policy = nl80211_policy, |
| 8321 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8322 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8323 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8324 | }, |
| 8325 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8326 | .cmd = NL80211_CMD_FRAME, |
| 8327 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8328 | .policy = nl80211_policy, |
| 8329 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8330 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8331 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8332 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8333 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8334 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8335 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8336 | .policy = nl80211_policy, |
| 8337 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8338 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8339 | NL80211_FLAG_NEED_RTNL, |
| 8340 | }, |
| 8341 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8342 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8343 | .doit = nl80211_set_power_save, |
| 8344 | .policy = nl80211_policy, |
| 8345 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8346 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8347 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8348 | }, |
| 8349 | { |
| 8350 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8351 | .doit = nl80211_get_power_save, |
| 8352 | .policy = nl80211_policy, |
| 8353 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8354 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8355 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8356 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8357 | { |
| 8358 | .cmd = NL80211_CMD_SET_CQM, |
| 8359 | .doit = nl80211_set_cqm, |
| 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_NETDEV | |
| 8363 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8364 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8365 | { |
| 8366 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8367 | .doit = nl80211_set_channel, |
| 8368 | .policy = nl80211_policy, |
| 8369 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8370 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8371 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8372 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8373 | { |
| 8374 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8375 | .doit = nl80211_set_wds_peer, |
| 8376 | .policy = nl80211_policy, |
| 8377 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8378 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8379 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8380 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8381 | { |
| 8382 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8383 | .doit = nl80211_join_mesh, |
| 8384 | .policy = nl80211_policy, |
| 8385 | .flags = GENL_ADMIN_PERM, |
| 8386 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8387 | NL80211_FLAG_NEED_RTNL, |
| 8388 | }, |
| 8389 | { |
| 8390 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8391 | .doit = nl80211_leave_mesh, |
| 8392 | .policy = nl80211_policy, |
| 8393 | .flags = GENL_ADMIN_PERM, |
| 8394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8395 | NL80211_FLAG_NEED_RTNL, |
| 8396 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8397 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8398 | { |
| 8399 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8400 | .doit = nl80211_get_wowlan, |
| 8401 | .policy = nl80211_policy, |
| 8402 | /* can be retrieved by unprivileged users */ |
| 8403 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8404 | NL80211_FLAG_NEED_RTNL, |
| 8405 | }, |
| 8406 | { |
| 8407 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8408 | .doit = nl80211_set_wowlan, |
| 8409 | .policy = nl80211_policy, |
| 8410 | .flags = GENL_ADMIN_PERM, |
| 8411 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8412 | NL80211_FLAG_NEED_RTNL, |
| 8413 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8414 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8415 | { |
| 8416 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8417 | .doit = nl80211_set_rekey_data, |
| 8418 | .policy = nl80211_policy, |
| 8419 | .flags = GENL_ADMIN_PERM, |
| 8420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8421 | NL80211_FLAG_NEED_RTNL, |
| 8422 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8423 | { |
| 8424 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8425 | .doit = nl80211_tdls_mgmt, |
| 8426 | .policy = nl80211_policy, |
| 8427 | .flags = GENL_ADMIN_PERM, |
| 8428 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8429 | NL80211_FLAG_NEED_RTNL, |
| 8430 | }, |
| 8431 | { |
| 8432 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8433 | .doit = nl80211_tdls_oper, |
| 8434 | .policy = nl80211_policy, |
| 8435 | .flags = GENL_ADMIN_PERM, |
| 8436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8437 | NL80211_FLAG_NEED_RTNL, |
| 8438 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8439 | { |
| 8440 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8441 | .doit = nl80211_register_unexpected_frame, |
| 8442 | .policy = nl80211_policy, |
| 8443 | .flags = GENL_ADMIN_PERM, |
| 8444 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8445 | NL80211_FLAG_NEED_RTNL, |
| 8446 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8447 | { |
| 8448 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8449 | .doit = nl80211_probe_client, |
| 8450 | .policy = nl80211_policy, |
| 8451 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8453 | NL80211_FLAG_NEED_RTNL, |
| 8454 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8455 | { |
| 8456 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8457 | .doit = nl80211_register_beacons, |
| 8458 | .policy = nl80211_policy, |
| 8459 | .flags = GENL_ADMIN_PERM, |
| 8460 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8461 | NL80211_FLAG_NEED_RTNL, |
| 8462 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8463 | { |
| 8464 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8465 | .doit = nl80211_set_noack_map, |
| 8466 | .policy = nl80211_policy, |
| 8467 | .flags = GENL_ADMIN_PERM, |
| 8468 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8469 | NL80211_FLAG_NEED_RTNL, |
| 8470 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8471 | { |
| 8472 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8473 | .doit = nl80211_start_p2p_device, |
| 8474 | .policy = nl80211_policy, |
| 8475 | .flags = GENL_ADMIN_PERM, |
| 8476 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8477 | NL80211_FLAG_NEED_RTNL, |
| 8478 | }, |
| 8479 | { |
| 8480 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8481 | .doit = nl80211_stop_p2p_device, |
| 8482 | .policy = nl80211_policy, |
| 8483 | .flags = GENL_ADMIN_PERM, |
| 8484 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8485 | NL80211_FLAG_NEED_RTNL, |
| 8486 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8487 | { |
| 8488 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8489 | .doit = nl80211_set_mcast_rate, |
| 8490 | .policy = nl80211_policy, |
| 8491 | .flags = GENL_ADMIN_PERM, |
| 8492 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8493 | NL80211_FLAG_NEED_RTNL, |
| 8494 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8495 | { |
| 8496 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8497 | .doit = nl80211_set_mac_acl, |
| 8498 | .policy = nl80211_policy, |
| 8499 | .flags = GENL_ADMIN_PERM, |
| 8500 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8501 | NL80211_FLAG_NEED_RTNL, |
| 8502 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8503 | { |
| 8504 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8505 | .doit = nl80211_start_radar_detection, |
| 8506 | .policy = nl80211_policy, |
| 8507 | .flags = GENL_ADMIN_PERM, |
| 8508 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8509 | NL80211_FLAG_NEED_RTNL, |
| 8510 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8511 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8512 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8513 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8514 | .name = "mlme", |
| 8515 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8516 | |
| 8517 | /* multicast groups */ |
| 8518 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8519 | .name = "config", |
| 8520 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8521 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8522 | .name = "scan", |
| 8523 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8524 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8525 | .name = "regulatory", |
| 8526 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8527 | |
| 8528 | /* notification functions */ |
| 8529 | |
| 8530 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8531 | { |
| 8532 | struct sk_buff *msg; |
| 8533 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8534 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8535 | if (!msg) |
| 8536 | return; |
| 8537 | |
| 8538 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8539 | nlmsg_free(msg); |
| 8540 | return; |
| 8541 | } |
| 8542 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8543 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8544 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8545 | } |
| 8546 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8547 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8548 | struct cfg80211_registered_device *rdev) |
| 8549 | { |
| 8550 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8551 | struct nlattr *nest; |
| 8552 | int i; |
| 8553 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8554 | ASSERT_RDEV_LOCK(rdev); |
| 8555 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8556 | if (WARN_ON(!req)) |
| 8557 | return 0; |
| 8558 | |
| 8559 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8560 | if (!nest) |
| 8561 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8562 | for (i = 0; i < req->n_ssids; i++) { |
| 8563 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8564 | goto nla_put_failure; |
| 8565 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8566 | nla_nest_end(msg, nest); |
| 8567 | |
| 8568 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8569 | if (!nest) |
| 8570 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8571 | for (i = 0; i < req->n_channels; i++) { |
| 8572 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8573 | goto nla_put_failure; |
| 8574 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8575 | nla_nest_end(msg, nest); |
| 8576 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8577 | if (req->ie && |
| 8578 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8579 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8580 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8581 | if (req->flags) |
| 8582 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8583 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8584 | return 0; |
| 8585 | nla_put_failure: |
| 8586 | return -ENOBUFS; |
| 8587 | } |
| 8588 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8589 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8590 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8591 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8592 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8593 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8594 | { |
| 8595 | void *hdr; |
| 8596 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8597 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8598 | if (!hdr) |
| 8599 | return -1; |
| 8600 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8601 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8602 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8603 | wdev->netdev->ifindex)) || |
| 8604 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8605 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8606 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8607 | /* ignore errors and send incomplete event anyway */ |
| 8608 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8609 | |
| 8610 | return genlmsg_end(msg, hdr); |
| 8611 | |
| 8612 | nla_put_failure: |
| 8613 | genlmsg_cancel(msg, hdr); |
| 8614 | return -EMSGSIZE; |
| 8615 | } |
| 8616 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8617 | static int |
| 8618 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8619 | struct cfg80211_registered_device *rdev, |
| 8620 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8621 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8622 | { |
| 8623 | void *hdr; |
| 8624 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8625 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8626 | if (!hdr) |
| 8627 | return -1; |
| 8628 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8629 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8630 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8631 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8632 | |
| 8633 | return genlmsg_end(msg, hdr); |
| 8634 | |
| 8635 | nla_put_failure: |
| 8636 | genlmsg_cancel(msg, hdr); |
| 8637 | return -EMSGSIZE; |
| 8638 | } |
| 8639 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8640 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8641 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8642 | { |
| 8643 | struct sk_buff *msg; |
| 8644 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8645 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8646 | if (!msg) |
| 8647 | return; |
| 8648 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8649 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8650 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8651 | nlmsg_free(msg); |
| 8652 | return; |
| 8653 | } |
| 8654 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8655 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8656 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8657 | } |
| 8658 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8659 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8660 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8661 | { |
| 8662 | struct sk_buff *msg; |
| 8663 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8665 | if (!msg) |
| 8666 | return; |
| 8667 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8668 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8669 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8670 | nlmsg_free(msg); |
| 8671 | return; |
| 8672 | } |
| 8673 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8674 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8675 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8679 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8680 | { |
| 8681 | struct sk_buff *msg; |
| 8682 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8684 | if (!msg) |
| 8685 | return; |
| 8686 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8687 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8688 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8689 | nlmsg_free(msg); |
| 8690 | return; |
| 8691 | } |
| 8692 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8693 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8694 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8695 | } |
| 8696 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8697 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8698 | struct net_device *netdev) |
| 8699 | { |
| 8700 | struct sk_buff *msg; |
| 8701 | |
| 8702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8703 | if (!msg) |
| 8704 | return; |
| 8705 | |
| 8706 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8707 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8708 | nlmsg_free(msg); |
| 8709 | return; |
| 8710 | } |
| 8711 | |
| 8712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8713 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8714 | } |
| 8715 | |
| 8716 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8717 | struct net_device *netdev, u32 cmd) |
| 8718 | { |
| 8719 | struct sk_buff *msg; |
| 8720 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8722 | if (!msg) |
| 8723 | return; |
| 8724 | |
| 8725 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8726 | nlmsg_free(msg); |
| 8727 | return; |
| 8728 | } |
| 8729 | |
| 8730 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8731 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8732 | } |
| 8733 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8734 | /* |
| 8735 | * This can happen on global regulatory changes or device specific settings |
| 8736 | * based on custom world regulatory domains. |
| 8737 | */ |
| 8738 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8739 | { |
| 8740 | struct sk_buff *msg; |
| 8741 | void *hdr; |
| 8742 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8744 | if (!msg) |
| 8745 | return; |
| 8746 | |
| 8747 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8748 | if (!hdr) { |
| 8749 | nlmsg_free(msg); |
| 8750 | return; |
| 8751 | } |
| 8752 | |
| 8753 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8754 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8755 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8756 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8757 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8758 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8759 | NL80211_REGDOM_TYPE_WORLD)) |
| 8760 | goto nla_put_failure; |
| 8761 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8762 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8763 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8764 | goto nla_put_failure; |
| 8765 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8766 | request->intersect) { |
| 8767 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8768 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8769 | goto nla_put_failure; |
| 8770 | } else { |
| 8771 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8772 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8773 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8774 | request->alpha2)) |
| 8775 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8776 | } |
| 8777 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8778 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8779 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8780 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8781 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8782 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8783 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8784 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8785 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8786 | GFP_ATOMIC); |
| 8787 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8788 | |
| 8789 | return; |
| 8790 | |
| 8791 | nla_put_failure: |
| 8792 | genlmsg_cancel(msg, hdr); |
| 8793 | nlmsg_free(msg); |
| 8794 | } |
| 8795 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8796 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8797 | struct net_device *netdev, |
| 8798 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8799 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8800 | { |
| 8801 | struct sk_buff *msg; |
| 8802 | void *hdr; |
| 8803 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8804 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8805 | if (!msg) |
| 8806 | return; |
| 8807 | |
| 8808 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8809 | if (!hdr) { |
| 8810 | nlmsg_free(msg); |
| 8811 | return; |
| 8812 | } |
| 8813 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8814 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8815 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8816 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8817 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8818 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8819 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8820 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8821 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8822 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8823 | return; |
| 8824 | |
| 8825 | nla_put_failure: |
| 8826 | genlmsg_cancel(msg, hdr); |
| 8827 | nlmsg_free(msg); |
| 8828 | } |
| 8829 | |
| 8830 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8831 | struct net_device *netdev, const u8 *buf, |
| 8832 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8833 | { |
| 8834 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8835 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8836 | } |
| 8837 | |
| 8838 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8839 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8840 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8841 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8842 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8843 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8844 | } |
| 8845 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8846 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8847 | struct net_device *netdev, const u8 *buf, |
| 8848 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8849 | { |
| 8850 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8851 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8852 | } |
| 8853 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8854 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8855 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8856 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8857 | { |
| 8858 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8859 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8860 | } |
| 8861 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8862 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8863 | struct net_device *netdev, const u8 *buf, |
| 8864 | size_t len, gfp_t gfp) |
| 8865 | { |
| 8866 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8867 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8868 | } |
| 8869 | |
| 8870 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8871 | struct net_device *netdev, const u8 *buf, |
| 8872 | size_t len, gfp_t gfp) |
| 8873 | { |
| 8874 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8875 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8876 | } |
| 8877 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8878 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8879 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8880 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8881 | { |
| 8882 | struct sk_buff *msg; |
| 8883 | void *hdr; |
| 8884 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8885 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8886 | if (!msg) |
| 8887 | return; |
| 8888 | |
| 8889 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8890 | if (!hdr) { |
| 8891 | nlmsg_free(msg); |
| 8892 | return; |
| 8893 | } |
| 8894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8895 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8896 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8897 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8898 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8899 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8900 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8901 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8902 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8903 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8904 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8905 | return; |
| 8906 | |
| 8907 | nla_put_failure: |
| 8908 | genlmsg_cancel(msg, hdr); |
| 8909 | nlmsg_free(msg); |
| 8910 | } |
| 8911 | |
| 8912 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8913 | struct net_device *netdev, const u8 *addr, |
| 8914 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8915 | { |
| 8916 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8917 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8918 | } |
| 8919 | |
| 8920 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8921 | struct net_device *netdev, const u8 *addr, |
| 8922 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8923 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8924 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8925 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8926 | } |
| 8927 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8928 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8929 | struct net_device *netdev, const u8 *bssid, |
| 8930 | const u8 *req_ie, size_t req_ie_len, |
| 8931 | const u8 *resp_ie, size_t resp_ie_len, |
| 8932 | u16 status, gfp_t gfp) |
| 8933 | { |
| 8934 | struct sk_buff *msg; |
| 8935 | void *hdr; |
| 8936 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8937 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8938 | if (!msg) |
| 8939 | return; |
| 8940 | |
| 8941 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8942 | if (!hdr) { |
| 8943 | nlmsg_free(msg); |
| 8944 | return; |
| 8945 | } |
| 8946 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8947 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8948 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8949 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8950 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8951 | (req_ie && |
| 8952 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8953 | (resp_ie && |
| 8954 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8955 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8956 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8957 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8958 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8959 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8960 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8961 | return; |
| 8962 | |
| 8963 | nla_put_failure: |
| 8964 | genlmsg_cancel(msg, hdr); |
| 8965 | nlmsg_free(msg); |
| 8966 | |
| 8967 | } |
| 8968 | |
| 8969 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8970 | struct net_device *netdev, const u8 *bssid, |
| 8971 | const u8 *req_ie, size_t req_ie_len, |
| 8972 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8973 | { |
| 8974 | struct sk_buff *msg; |
| 8975 | void *hdr; |
| 8976 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8978 | if (!msg) |
| 8979 | return; |
| 8980 | |
| 8981 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8982 | if (!hdr) { |
| 8983 | nlmsg_free(msg); |
| 8984 | return; |
| 8985 | } |
| 8986 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8987 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8988 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8989 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8990 | (req_ie && |
| 8991 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8992 | (resp_ie && |
| 8993 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8994 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8995 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8996 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8997 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8998 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8999 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9000 | return; |
| 9001 | |
| 9002 | nla_put_failure: |
| 9003 | genlmsg_cancel(msg, hdr); |
| 9004 | nlmsg_free(msg); |
| 9005 | |
| 9006 | } |
| 9007 | |
| 9008 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9009 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9010 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9011 | { |
| 9012 | struct sk_buff *msg; |
| 9013 | void *hdr; |
| 9014 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9016 | if (!msg) |
| 9017 | return; |
| 9018 | |
| 9019 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9020 | if (!hdr) { |
| 9021 | nlmsg_free(msg); |
| 9022 | return; |
| 9023 | } |
| 9024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9025 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9026 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9027 | (from_ap && reason && |
| 9028 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9029 | (from_ap && |
| 9030 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9031 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9032 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9033 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9034 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9035 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9036 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9037 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9038 | return; |
| 9039 | |
| 9040 | nla_put_failure: |
| 9041 | genlmsg_cancel(msg, hdr); |
| 9042 | nlmsg_free(msg); |
| 9043 | |
| 9044 | } |
| 9045 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9046 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9047 | struct net_device *netdev, const u8 *bssid, |
| 9048 | gfp_t gfp) |
| 9049 | { |
| 9050 | struct sk_buff *msg; |
| 9051 | void *hdr; |
| 9052 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9053 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9054 | if (!msg) |
| 9055 | return; |
| 9056 | |
| 9057 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9058 | if (!hdr) { |
| 9059 | nlmsg_free(msg); |
| 9060 | return; |
| 9061 | } |
| 9062 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9063 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9064 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9065 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9066 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9067 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9068 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9069 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9070 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9071 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9072 | return; |
| 9073 | |
| 9074 | nla_put_failure: |
| 9075 | genlmsg_cancel(msg, hdr); |
| 9076 | nlmsg_free(msg); |
| 9077 | } |
| 9078 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9079 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 9080 | struct net_device *netdev, |
| 9081 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 9082 | gfp_t gfp) |
| 9083 | { |
| 9084 | struct sk_buff *msg; |
| 9085 | void *hdr; |
| 9086 | |
| 9087 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9088 | if (!msg) |
| 9089 | return; |
| 9090 | |
| 9091 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9092 | if (!hdr) { |
| 9093 | nlmsg_free(msg); |
| 9094 | return; |
| 9095 | } |
| 9096 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9097 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9098 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9099 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 9100 | (ie_len && ie && |
| 9101 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9102 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9103 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9104 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9105 | |
| 9106 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9107 | nl80211_mlme_mcgrp.id, gfp); |
| 9108 | return; |
| 9109 | |
| 9110 | nla_put_failure: |
| 9111 | genlmsg_cancel(msg, hdr); |
| 9112 | nlmsg_free(msg); |
| 9113 | } |
| 9114 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9115 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9116 | struct net_device *netdev, const u8 *addr, |
| 9117 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9118 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9119 | { |
| 9120 | struct sk_buff *msg; |
| 9121 | void *hdr; |
| 9122 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9123 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9124 | if (!msg) |
| 9125 | return; |
| 9126 | |
| 9127 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9128 | if (!hdr) { |
| 9129 | nlmsg_free(msg); |
| 9130 | return; |
| 9131 | } |
| 9132 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9133 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9134 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9135 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9136 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9137 | (key_id != -1 && |
| 9138 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9139 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9140 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9141 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9142 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9143 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9144 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9145 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9146 | return; |
| 9147 | |
| 9148 | nla_put_failure: |
| 9149 | genlmsg_cancel(msg, hdr); |
| 9150 | nlmsg_free(msg); |
| 9151 | } |
| 9152 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9153 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9154 | struct ieee80211_channel *channel_before, |
| 9155 | struct ieee80211_channel *channel_after) |
| 9156 | { |
| 9157 | struct sk_buff *msg; |
| 9158 | void *hdr; |
| 9159 | struct nlattr *nl_freq; |
| 9160 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9161 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9162 | if (!msg) |
| 9163 | return; |
| 9164 | |
| 9165 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9166 | if (!hdr) { |
| 9167 | nlmsg_free(msg); |
| 9168 | return; |
| 9169 | } |
| 9170 | |
| 9171 | /* |
| 9172 | * Since we are applying the beacon hint to a wiphy we know its |
| 9173 | * wiphy_idx is valid |
| 9174 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9176 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9177 | |
| 9178 | /* Before */ |
| 9179 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9180 | if (!nl_freq) |
| 9181 | goto nla_put_failure; |
| 9182 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 9183 | goto nla_put_failure; |
| 9184 | nla_nest_end(msg, nl_freq); |
| 9185 | |
| 9186 | /* After */ |
| 9187 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9188 | if (!nl_freq) |
| 9189 | goto nla_put_failure; |
| 9190 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 9191 | goto nla_put_failure; |
| 9192 | nla_nest_end(msg, nl_freq); |
| 9193 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9194 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9195 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9196 | rcu_read_lock(); |
| 9197 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9198 | GFP_ATOMIC); |
| 9199 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9200 | |
| 9201 | return; |
| 9202 | |
| 9203 | nla_put_failure: |
| 9204 | genlmsg_cancel(msg, hdr); |
| 9205 | nlmsg_free(msg); |
| 9206 | } |
| 9207 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9208 | static void nl80211_send_remain_on_chan_event( |
| 9209 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9210 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9211 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9212 | unsigned int duration, gfp_t gfp) |
| 9213 | { |
| 9214 | struct sk_buff *msg; |
| 9215 | void *hdr; |
| 9216 | |
| 9217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9218 | if (!msg) |
| 9219 | return; |
| 9220 | |
| 9221 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9222 | if (!hdr) { |
| 9223 | nlmsg_free(msg); |
| 9224 | return; |
| 9225 | } |
| 9226 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9227 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9228 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9229 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9230 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9231 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9232 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9233 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9234 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9235 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9236 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9237 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9238 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9239 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9240 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9241 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9242 | |
| 9243 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9244 | nl80211_mlme_mcgrp.id, gfp); |
| 9245 | return; |
| 9246 | |
| 9247 | nla_put_failure: |
| 9248 | genlmsg_cancel(msg, hdr); |
| 9249 | nlmsg_free(msg); |
| 9250 | } |
| 9251 | |
| 9252 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9253 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9254 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9255 | unsigned int duration, gfp_t gfp) |
| 9256 | { |
| 9257 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9258 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9259 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9260 | } |
| 9261 | |
| 9262 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9263 | struct cfg80211_registered_device *rdev, |
| 9264 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9265 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9266 | { |
| 9267 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9268 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9269 | } |
| 9270 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9271 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 9272 | struct net_device *dev, const u8 *mac_addr, |
| 9273 | struct station_info *sinfo, gfp_t gfp) |
| 9274 | { |
| 9275 | struct sk_buff *msg; |
| 9276 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9277 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9278 | if (!msg) |
| 9279 | return; |
| 9280 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9281 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9282 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9283 | nlmsg_free(msg); |
| 9284 | return; |
| 9285 | } |
| 9286 | |
| 9287 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9288 | nl80211_mlme_mcgrp.id, gfp); |
| 9289 | } |
| 9290 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9291 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 9292 | struct net_device *dev, const u8 *mac_addr, |
| 9293 | gfp_t gfp) |
| 9294 | { |
| 9295 | struct sk_buff *msg; |
| 9296 | void *hdr; |
| 9297 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9298 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9299 | if (!msg) |
| 9300 | return; |
| 9301 | |
| 9302 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9303 | if (!hdr) { |
| 9304 | nlmsg_free(msg); |
| 9305 | return; |
| 9306 | } |
| 9307 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9308 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9309 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9310 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9311 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9312 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9313 | |
| 9314 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9315 | nl80211_mlme_mcgrp.id, gfp); |
| 9316 | return; |
| 9317 | |
| 9318 | nla_put_failure: |
| 9319 | genlmsg_cancel(msg, hdr); |
| 9320 | nlmsg_free(msg); |
| 9321 | } |
| 9322 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9323 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 9324 | struct net_device *dev, const u8 *mac_addr, |
| 9325 | enum nl80211_connect_failed_reason reason, |
| 9326 | gfp_t gfp) |
| 9327 | { |
| 9328 | struct sk_buff *msg; |
| 9329 | void *hdr; |
| 9330 | |
| 9331 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9332 | if (!msg) |
| 9333 | return; |
| 9334 | |
| 9335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9336 | if (!hdr) { |
| 9337 | nlmsg_free(msg); |
| 9338 | return; |
| 9339 | } |
| 9340 | |
| 9341 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9342 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9343 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9344 | goto nla_put_failure; |
| 9345 | |
| 9346 | genlmsg_end(msg, hdr); |
| 9347 | |
| 9348 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9349 | nl80211_mlme_mcgrp.id, gfp); |
| 9350 | return; |
| 9351 | |
| 9352 | nla_put_failure: |
| 9353 | genlmsg_cancel(msg, hdr); |
| 9354 | nlmsg_free(msg); |
| 9355 | } |
| 9356 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9357 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9358 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9359 | { |
| 9360 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9361 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9362 | struct sk_buff *msg; |
| 9363 | void *hdr; |
| 9364 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9365 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9366 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9367 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9368 | return false; |
| 9369 | |
| 9370 | msg = nlmsg_new(100, gfp); |
| 9371 | if (!msg) |
| 9372 | return true; |
| 9373 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9374 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9375 | if (!hdr) { |
| 9376 | nlmsg_free(msg); |
| 9377 | return true; |
| 9378 | } |
| 9379 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9380 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9381 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9382 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9383 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9384 | |
| 9385 | err = genlmsg_end(msg, hdr); |
| 9386 | if (err < 0) { |
| 9387 | nlmsg_free(msg); |
| 9388 | return true; |
| 9389 | } |
| 9390 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9391 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9392 | return true; |
| 9393 | |
| 9394 | nla_put_failure: |
| 9395 | genlmsg_cancel(msg, hdr); |
| 9396 | nlmsg_free(msg); |
| 9397 | return true; |
| 9398 | } |
| 9399 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9400 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 9401 | { |
| 9402 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9403 | addr, gfp); |
| 9404 | } |
| 9405 | |
| 9406 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 9407 | const u8 *addr, gfp_t gfp) |
| 9408 | { |
| 9409 | return __nl80211_unexpected_frame(dev, |
| 9410 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9411 | addr, gfp); |
| 9412 | } |
| 9413 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9414 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9415 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9416 | int freq, int sig_dbm, |
| 9417 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9418 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9419 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9420 | struct sk_buff *msg; |
| 9421 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9422 | |
| 9423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9424 | if (!msg) |
| 9425 | return -ENOMEM; |
| 9426 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9427 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9428 | if (!hdr) { |
| 9429 | nlmsg_free(msg); |
| 9430 | return -ENOMEM; |
| 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) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9434 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9435 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9436 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9437 | (sig_dbm && |
| 9438 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9439 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9440 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9441 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9442 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9443 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9444 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9445 | |
| 9446 | nla_put_failure: |
| 9447 | genlmsg_cancel(msg, hdr); |
| 9448 | nlmsg_free(msg); |
| 9449 | return -ENOBUFS; |
| 9450 | } |
| 9451 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9452 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9453 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9454 | const u8 *buf, size_t len, bool ack, |
| 9455 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9456 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9457 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9458 | struct sk_buff *msg; |
| 9459 | void *hdr; |
| 9460 | |
| 9461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9462 | if (!msg) |
| 9463 | return; |
| 9464 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 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) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9472 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9473 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9474 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9475 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9476 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9477 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9478 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9479 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9480 | |
| 9481 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9482 | return; |
| 9483 | |
| 9484 | nla_put_failure: |
| 9485 | genlmsg_cancel(msg, hdr); |
| 9486 | nlmsg_free(msg); |
| 9487 | } |
| 9488 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9489 | void |
| 9490 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9491 | struct net_device *netdev, |
| 9492 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9493 | gfp_t gfp) |
| 9494 | { |
| 9495 | struct sk_buff *msg; |
| 9496 | struct nlattr *pinfoattr; |
| 9497 | void *hdr; |
| 9498 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9499 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9500 | if (!msg) |
| 9501 | return; |
| 9502 | |
| 9503 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9504 | if (!hdr) { |
| 9505 | nlmsg_free(msg); |
| 9506 | return; |
| 9507 | } |
| 9508 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9509 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9510 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9511 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9512 | |
| 9513 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9514 | if (!pinfoattr) |
| 9515 | goto nla_put_failure; |
| 9516 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9517 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9518 | rssi_event)) |
| 9519 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9520 | |
| 9521 | nla_nest_end(msg, pinfoattr); |
| 9522 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9523 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9524 | |
| 9525 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9526 | nl80211_mlme_mcgrp.id, gfp); |
| 9527 | return; |
| 9528 | |
| 9529 | nla_put_failure: |
| 9530 | genlmsg_cancel(msg, hdr); |
| 9531 | nlmsg_free(msg); |
| 9532 | } |
| 9533 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9534 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9535 | struct net_device *netdev, const u8 *bssid, |
| 9536 | const u8 *replay_ctr, gfp_t gfp) |
| 9537 | { |
| 9538 | struct sk_buff *msg; |
| 9539 | struct nlattr *rekey_attr; |
| 9540 | void *hdr; |
| 9541 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9542 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9543 | if (!msg) |
| 9544 | return; |
| 9545 | |
| 9546 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9547 | if (!hdr) { |
| 9548 | nlmsg_free(msg); |
| 9549 | return; |
| 9550 | } |
| 9551 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9552 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9553 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9554 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9555 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9556 | |
| 9557 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9558 | if (!rekey_attr) |
| 9559 | goto nla_put_failure; |
| 9560 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9561 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9562 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9563 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9564 | |
| 9565 | nla_nest_end(msg, rekey_attr); |
| 9566 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9567 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9568 | |
| 9569 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9570 | nl80211_mlme_mcgrp.id, gfp); |
| 9571 | return; |
| 9572 | |
| 9573 | nla_put_failure: |
| 9574 | genlmsg_cancel(msg, hdr); |
| 9575 | nlmsg_free(msg); |
| 9576 | } |
| 9577 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9578 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9579 | struct net_device *netdev, int index, |
| 9580 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9581 | { |
| 9582 | struct sk_buff *msg; |
| 9583 | struct nlattr *attr; |
| 9584 | void *hdr; |
| 9585 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9587 | if (!msg) |
| 9588 | return; |
| 9589 | |
| 9590 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9591 | if (!hdr) { |
| 9592 | nlmsg_free(msg); |
| 9593 | return; |
| 9594 | } |
| 9595 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9596 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9597 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9598 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9599 | |
| 9600 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9601 | if (!attr) |
| 9602 | goto nla_put_failure; |
| 9603 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9604 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9605 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9606 | (preauth && |
| 9607 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9608 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9609 | |
| 9610 | nla_nest_end(msg, attr); |
| 9611 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9612 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9613 | |
| 9614 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9615 | nl80211_mlme_mcgrp.id, gfp); |
| 9616 | return; |
| 9617 | |
| 9618 | nla_put_failure: |
| 9619 | genlmsg_cancel(msg, hdr); |
| 9620 | nlmsg_free(msg); |
| 9621 | } |
| 9622 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9623 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9624 | struct net_device *netdev, |
| 9625 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9626 | { |
| 9627 | struct sk_buff *msg; |
| 9628 | void *hdr; |
| 9629 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9631 | if (!msg) |
| 9632 | return; |
| 9633 | |
| 9634 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9635 | if (!hdr) { |
| 9636 | nlmsg_free(msg); |
| 9637 | return; |
| 9638 | } |
| 9639 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9640 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9641 | goto nla_put_failure; |
| 9642 | |
| 9643 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9644 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9645 | |
| 9646 | genlmsg_end(msg, hdr); |
| 9647 | |
| 9648 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9649 | nl80211_mlme_mcgrp.id, gfp); |
| 9650 | return; |
| 9651 | |
| 9652 | nla_put_failure: |
| 9653 | genlmsg_cancel(msg, hdr); |
| 9654 | nlmsg_free(msg); |
| 9655 | } |
| 9656 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9657 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9658 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9659 | struct net_device *netdev, const u8 *peer, |
| 9660 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9661 | { |
| 9662 | struct sk_buff *msg; |
| 9663 | struct nlattr *pinfoattr; |
| 9664 | void *hdr; |
| 9665 | |
| 9666 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9667 | if (!msg) |
| 9668 | return; |
| 9669 | |
| 9670 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9671 | if (!hdr) { |
| 9672 | nlmsg_free(msg); |
| 9673 | return; |
| 9674 | } |
| 9675 | |
| 9676 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9677 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9678 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9679 | goto nla_put_failure; |
| 9680 | |
| 9681 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9682 | if (!pinfoattr) |
| 9683 | goto nla_put_failure; |
| 9684 | |
| 9685 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9686 | goto nla_put_failure; |
| 9687 | |
| 9688 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9689 | goto nla_put_failure; |
| 9690 | |
| 9691 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9692 | goto nla_put_failure; |
| 9693 | |
| 9694 | nla_nest_end(msg, pinfoattr); |
| 9695 | |
| 9696 | genlmsg_end(msg, hdr); |
| 9697 | |
| 9698 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9699 | nl80211_mlme_mcgrp.id, gfp); |
| 9700 | return; |
| 9701 | |
| 9702 | nla_put_failure: |
| 9703 | genlmsg_cancel(msg, hdr); |
| 9704 | nlmsg_free(msg); |
| 9705 | } |
| 9706 | |
| 9707 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9708 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 9709 | struct cfg80211_chan_def *chandef, |
| 9710 | enum nl80211_radar_event event, |
| 9711 | struct net_device *netdev, gfp_t gfp) |
| 9712 | { |
| 9713 | struct sk_buff *msg; |
| 9714 | void *hdr; |
| 9715 | |
| 9716 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9717 | if (!msg) |
| 9718 | return; |
| 9719 | |
| 9720 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 9721 | if (!hdr) { |
| 9722 | nlmsg_free(msg); |
| 9723 | return; |
| 9724 | } |
| 9725 | |
| 9726 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9727 | goto nla_put_failure; |
| 9728 | |
| 9729 | /* NOP and radar events don't need a netdev parameter */ |
| 9730 | if (netdev) { |
| 9731 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 9732 | |
| 9733 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9734 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9735 | goto nla_put_failure; |
| 9736 | } |
| 9737 | |
| 9738 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 9739 | goto nla_put_failure; |
| 9740 | |
| 9741 | if (nl80211_send_chandef(msg, chandef)) |
| 9742 | goto nla_put_failure; |
| 9743 | |
| 9744 | if (genlmsg_end(msg, hdr) < 0) { |
| 9745 | nlmsg_free(msg); |
| 9746 | return; |
| 9747 | } |
| 9748 | |
| 9749 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9750 | nl80211_mlme_mcgrp.id, gfp); |
| 9751 | return; |
| 9752 | |
| 9753 | nla_put_failure: |
| 9754 | genlmsg_cancel(msg, hdr); |
| 9755 | nlmsg_free(msg); |
| 9756 | } |
| 9757 | |
| 9758 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9759 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9760 | struct net_device *netdev, const u8 *peer, |
| 9761 | u32 num_packets, gfp_t gfp) |
| 9762 | { |
| 9763 | struct sk_buff *msg; |
| 9764 | struct nlattr *pinfoattr; |
| 9765 | void *hdr; |
| 9766 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9767 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9768 | if (!msg) |
| 9769 | return; |
| 9770 | |
| 9771 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9772 | if (!hdr) { |
| 9773 | nlmsg_free(msg); |
| 9774 | return; |
| 9775 | } |
| 9776 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9777 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9778 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9779 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9780 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9781 | |
| 9782 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9783 | if (!pinfoattr) |
| 9784 | goto nla_put_failure; |
| 9785 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9786 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9787 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9788 | |
| 9789 | nla_nest_end(msg, pinfoattr); |
| 9790 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9791 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9792 | |
| 9793 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9794 | nl80211_mlme_mcgrp.id, gfp); |
| 9795 | return; |
| 9796 | |
| 9797 | nla_put_failure: |
| 9798 | genlmsg_cancel(msg, hdr); |
| 9799 | nlmsg_free(msg); |
| 9800 | } |
| 9801 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9802 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9803 | u64 cookie, bool acked, gfp_t gfp) |
| 9804 | { |
| 9805 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9806 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9807 | struct sk_buff *msg; |
| 9808 | void *hdr; |
| 9809 | int err; |
| 9810 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9811 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9812 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9813 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9814 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9815 | if (!msg) |
| 9816 | return; |
| 9817 | |
| 9818 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9819 | if (!hdr) { |
| 9820 | nlmsg_free(msg); |
| 9821 | return; |
| 9822 | } |
| 9823 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9824 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9825 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9826 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9827 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9828 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9829 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9830 | |
| 9831 | err = genlmsg_end(msg, hdr); |
| 9832 | if (err < 0) { |
| 9833 | nlmsg_free(msg); |
| 9834 | return; |
| 9835 | } |
| 9836 | |
| 9837 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9838 | nl80211_mlme_mcgrp.id, gfp); |
| 9839 | return; |
| 9840 | |
| 9841 | nla_put_failure: |
| 9842 | genlmsg_cancel(msg, hdr); |
| 9843 | nlmsg_free(msg); |
| 9844 | } |
| 9845 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9846 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9847 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9848 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9849 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9850 | { |
| 9851 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9852 | struct sk_buff *msg; |
| 9853 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9854 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9855 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9856 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9857 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9858 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9859 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9860 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9861 | if (!msg) { |
| 9862 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9863 | return; |
| 9864 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9865 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9866 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9867 | if (!hdr) |
| 9868 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9869 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9870 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9871 | (freq && |
| 9872 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9873 | (sig_dbm && |
| 9874 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9875 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9876 | goto nla_put_failure; |
| 9877 | |
| 9878 | genlmsg_end(msg, hdr); |
| 9879 | |
| 9880 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9881 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9882 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9883 | return; |
| 9884 | |
| 9885 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9886 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9887 | if (hdr) |
| 9888 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9889 | nlmsg_free(msg); |
| 9890 | } |
| 9891 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9892 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9893 | #ifdef CONFIG_PM |
| 9894 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9895 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9896 | gfp_t gfp) |
| 9897 | { |
| 9898 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9899 | struct sk_buff *msg; |
| 9900 | void *hdr; |
| 9901 | int err, size = 200; |
| 9902 | |
| 9903 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9904 | |
| 9905 | if (wakeup) |
| 9906 | size += wakeup->packet_present_len; |
| 9907 | |
| 9908 | msg = nlmsg_new(size, gfp); |
| 9909 | if (!msg) |
| 9910 | return; |
| 9911 | |
| 9912 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9913 | if (!hdr) |
| 9914 | goto free_msg; |
| 9915 | |
| 9916 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9917 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9918 | goto free_msg; |
| 9919 | |
| 9920 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9921 | wdev->netdev->ifindex)) |
| 9922 | goto free_msg; |
| 9923 | |
| 9924 | if (wakeup) { |
| 9925 | struct nlattr *reasons; |
| 9926 | |
| 9927 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9928 | |
| 9929 | if (wakeup->disconnect && |
| 9930 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9931 | goto free_msg; |
| 9932 | if (wakeup->magic_pkt && |
| 9933 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9934 | goto free_msg; |
| 9935 | if (wakeup->gtk_rekey_failure && |
| 9936 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9937 | goto free_msg; |
| 9938 | if (wakeup->eap_identity_req && |
| 9939 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9940 | goto free_msg; |
| 9941 | if (wakeup->four_way_handshake && |
| 9942 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9943 | goto free_msg; |
| 9944 | if (wakeup->rfkill_release && |
| 9945 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9946 | goto free_msg; |
| 9947 | |
| 9948 | if (wakeup->pattern_idx >= 0 && |
| 9949 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9950 | wakeup->pattern_idx)) |
| 9951 | goto free_msg; |
| 9952 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9953 | if (wakeup->tcp_match) |
| 9954 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 9955 | |
| 9956 | if (wakeup->tcp_connlost) |
| 9957 | nla_put_flag(msg, |
| 9958 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 9959 | |
| 9960 | if (wakeup->tcp_nomoretokens) |
| 9961 | nla_put_flag(msg, |
| 9962 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 9963 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9964 | if (wakeup->packet) { |
| 9965 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9966 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9967 | |
| 9968 | if (!wakeup->packet_80211) { |
| 9969 | pkt_attr = |
| 9970 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9971 | len_attr = |
| 9972 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9973 | } |
| 9974 | |
| 9975 | if (wakeup->packet_len && |
| 9976 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9977 | goto free_msg; |
| 9978 | |
| 9979 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9980 | wakeup->packet)) |
| 9981 | goto free_msg; |
| 9982 | } |
| 9983 | |
| 9984 | nla_nest_end(msg, reasons); |
| 9985 | } |
| 9986 | |
| 9987 | err = genlmsg_end(msg, hdr); |
| 9988 | if (err < 0) |
| 9989 | goto free_msg; |
| 9990 | |
| 9991 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9992 | nl80211_mlme_mcgrp.id, gfp); |
| 9993 | return; |
| 9994 | |
| 9995 | free_msg: |
| 9996 | nlmsg_free(msg); |
| 9997 | } |
| 9998 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9999 | #endif |
| 10000 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10001 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10002 | enum nl80211_tdls_operation oper, |
| 10003 | u16 reason_code, gfp_t gfp) |
| 10004 | { |
| 10005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10006 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10007 | struct sk_buff *msg; |
| 10008 | void *hdr; |
| 10009 | int err; |
| 10010 | |
| 10011 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10012 | reason_code); |
| 10013 | |
| 10014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10015 | if (!msg) |
| 10016 | return; |
| 10017 | |
| 10018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10019 | if (!hdr) { |
| 10020 | nlmsg_free(msg); |
| 10021 | return; |
| 10022 | } |
| 10023 | |
| 10024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10025 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10026 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10027 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10028 | (reason_code > 0 && |
| 10029 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10030 | goto nla_put_failure; |
| 10031 | |
| 10032 | err = genlmsg_end(msg, hdr); |
| 10033 | if (err < 0) { |
| 10034 | nlmsg_free(msg); |
| 10035 | return; |
| 10036 | } |
| 10037 | |
| 10038 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10039 | nl80211_mlme_mcgrp.id, gfp); |
| 10040 | return; |
| 10041 | |
| 10042 | nla_put_failure: |
| 10043 | genlmsg_cancel(msg, hdr); |
| 10044 | nlmsg_free(msg); |
| 10045 | } |
| 10046 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10047 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10048 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10049 | unsigned long state, |
| 10050 | void *_notify) |
| 10051 | { |
| 10052 | struct netlink_notify *notify = _notify; |
| 10053 | struct cfg80211_registered_device *rdev; |
| 10054 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10055 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10056 | |
| 10057 | if (state != NETLINK_URELEASE) |
| 10058 | return NOTIFY_DONE; |
| 10059 | |
| 10060 | rcu_read_lock(); |
| 10061 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10062 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10063 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10064 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10065 | |
| 10066 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10067 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10068 | list) { |
| 10069 | if (reg->nlportid == notify->portid) { |
| 10070 | list_del(®->list); |
| 10071 | kfree(reg); |
| 10072 | break; |
| 10073 | } |
| 10074 | } |
| 10075 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10076 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10077 | |
| 10078 | rcu_read_unlock(); |
| 10079 | |
| 10080 | return NOTIFY_DONE; |
| 10081 | } |
| 10082 | |
| 10083 | static struct notifier_block nl80211_netlink_notifier = { |
| 10084 | .notifier_call = nl80211_netlink_notify, |
| 10085 | }; |
| 10086 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10087 | /* initialisation/exit functions */ |
| 10088 | |
| 10089 | int nl80211_init(void) |
| 10090 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10091 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10092 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10093 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10094 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10095 | if (err) |
| 10096 | return err; |
| 10097 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10098 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10099 | if (err) |
| 10100 | goto err_out; |
| 10101 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10102 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10103 | if (err) |
| 10104 | goto err_out; |
| 10105 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10106 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10107 | if (err) |
| 10108 | goto err_out; |
| 10109 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10110 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10111 | if (err) |
| 10112 | goto err_out; |
| 10113 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10114 | #ifdef CONFIG_NL80211_TESTMODE |
| 10115 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10116 | if (err) |
| 10117 | goto err_out; |
| 10118 | #endif |
| 10119 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10120 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10121 | if (err) |
| 10122 | goto err_out; |
| 10123 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10124 | return 0; |
| 10125 | err_out: |
| 10126 | genl_unregister_family(&nl80211_fam); |
| 10127 | return err; |
| 10128 | } |
| 10129 | |
| 10130 | void nl80211_exit(void) |
| 10131 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10132 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10133 | genl_unregister_family(&nl80211_fam); |
| 10134 | } |