Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 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; |
Johannes Berg | 1c33a05 | 2013-02-18 23:44:38 +0100 | [diff] [blame] | 557 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 559 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 560 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 561 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 562 | DBM_TO_MBM(chan->max_power))) |
| 563 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | |
| 567 | nla_put_failure: |
| 568 | return -ENOBUFS; |
| 569 | } |
| 570 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 571 | /* netlink command implementations */ |
| 572 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 573 | struct key_parse { |
| 574 | struct key_params p; |
| 575 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 576 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 577 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 578 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 579 | }; |
| 580 | |
| 581 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 582 | { |
| 583 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 584 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 585 | nl80211_key_policy); |
| 586 | if (err) |
| 587 | return err; |
| 588 | |
| 589 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 590 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 591 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 592 | if (k->def) { |
| 593 | k->def_uni = true; |
| 594 | k->def_multi = true; |
| 595 | } |
| 596 | if (k->defmgmt) |
| 597 | k->def_multi = true; |
| 598 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 599 | if (tb[NL80211_KEY_IDX]) |
| 600 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 601 | |
| 602 | if (tb[NL80211_KEY_DATA]) { |
| 603 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 604 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 605 | } |
| 606 | |
| 607 | if (tb[NL80211_KEY_SEQ]) { |
| 608 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 609 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 610 | } |
| 611 | |
| 612 | if (tb[NL80211_KEY_CIPHER]) |
| 613 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 614 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 615 | if (tb[NL80211_KEY_TYPE]) { |
| 616 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 617 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 621 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 622 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 623 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 624 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 625 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 626 | if (err) |
| 627 | return err; |
| 628 | |
| 629 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 630 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 631 | } |
| 632 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 637 | { |
| 638 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 639 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 640 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 641 | } |
| 642 | |
| 643 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 644 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 645 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 646 | } |
| 647 | |
| 648 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 649 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 650 | |
| 651 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 652 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 653 | |
| 654 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 655 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 656 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 657 | if (k->def) { |
| 658 | k->def_uni = true; |
| 659 | k->def_multi = true; |
| 660 | } |
| 661 | if (k->defmgmt) |
| 662 | k->def_multi = true; |
| 663 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 664 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 665 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 666 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 667 | return -EINVAL; |
| 668 | } |
| 669 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 670 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 671 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 672 | int err = nla_parse_nested( |
| 673 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 674 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 675 | nl80211_key_default_policy); |
| 676 | if (err) |
| 677 | return err; |
| 678 | |
| 679 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 680 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 681 | } |
| 682 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 687 | { |
| 688 | int err; |
| 689 | |
| 690 | memset(k, 0, sizeof(*k)); |
| 691 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 692 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 693 | |
| 694 | if (info->attrs[NL80211_ATTR_KEY]) |
| 695 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 696 | else |
| 697 | err = nl80211_parse_key_old(info, k); |
| 698 | |
| 699 | if (err) |
| 700 | return err; |
| 701 | |
| 702 | if (k->def && k->defmgmt) |
| 703 | return -EINVAL; |
| 704 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 705 | if (k->defmgmt) { |
| 706 | if (k->def_uni || !k->def_multi) |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 710 | if (k->idx != -1) { |
| 711 | if (k->defmgmt) { |
| 712 | if (k->idx < 4 || k->idx > 5) |
| 713 | return -EINVAL; |
| 714 | } else if (k->def) { |
| 715 | if (k->idx < 0 || k->idx > 3) |
| 716 | return -EINVAL; |
| 717 | } else { |
| 718 | if (k->idx < 0 || k->idx > 5) |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 726 | static struct cfg80211_cached_keys * |
| 727 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 728 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 729 | { |
| 730 | struct key_parse parse; |
| 731 | struct nlattr *key; |
| 732 | struct cfg80211_cached_keys *result; |
| 733 | int rem, err, def = 0; |
| 734 | |
| 735 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 736 | if (!result) |
| 737 | return ERR_PTR(-ENOMEM); |
| 738 | |
| 739 | result->def = -1; |
| 740 | result->defmgmt = -1; |
| 741 | |
| 742 | nla_for_each_nested(key, keys, rem) { |
| 743 | memset(&parse, 0, sizeof(parse)); |
| 744 | parse.idx = -1; |
| 745 | |
| 746 | err = nl80211_parse_key_new(key, &parse); |
| 747 | if (err) |
| 748 | goto error; |
| 749 | err = -EINVAL; |
| 750 | if (!parse.p.key) |
| 751 | goto error; |
| 752 | if (parse.idx < 0 || parse.idx > 4) |
| 753 | goto error; |
| 754 | if (parse.def) { |
| 755 | if (def) |
| 756 | goto error; |
| 757 | def = 1; |
| 758 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 759 | if (!parse.def_uni || !parse.def_multi) |
| 760 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 761 | } else if (parse.defmgmt) |
| 762 | goto error; |
| 763 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 764 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 765 | if (err) |
| 766 | goto error; |
| 767 | result->params[parse.idx].cipher = parse.p.cipher; |
| 768 | result->params[parse.idx].key_len = parse.p.key_len; |
| 769 | result->params[parse.idx].key = result->data[parse.idx]; |
| 770 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 771 | |
| 772 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 773 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 774 | if (no_ht) |
| 775 | *no_ht = true; |
| 776 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | return result; |
| 780 | error: |
| 781 | kfree(result); |
| 782 | return ERR_PTR(err); |
| 783 | } |
| 784 | |
| 785 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 786 | { |
| 787 | ASSERT_WDEV_LOCK(wdev); |
| 788 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 789 | switch (wdev->iftype) { |
| 790 | case NL80211_IFTYPE_AP: |
| 791 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 792 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 793 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 794 | break; |
| 795 | case NL80211_IFTYPE_ADHOC: |
| 796 | if (!wdev->current_bss) |
| 797 | return -ENOLINK; |
| 798 | break; |
| 799 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 800 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 801 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 802 | return -ENOLINK; |
| 803 | break; |
| 804 | default: |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
| 808 | return 0; |
| 809 | } |
| 810 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 811 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 812 | { |
| 813 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 814 | int i; |
| 815 | |
| 816 | if (!nl_modes) |
| 817 | goto nla_put_failure; |
| 818 | |
| 819 | i = 0; |
| 820 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 821 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 822 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 823 | ifmodes >>= 1; |
| 824 | i++; |
| 825 | } |
| 826 | |
| 827 | nla_nest_end(msg, nl_modes); |
| 828 | return 0; |
| 829 | |
| 830 | nla_put_failure: |
| 831 | return -ENOBUFS; |
| 832 | } |
| 833 | |
| 834 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 835 | struct sk_buff *msg) |
| 836 | { |
| 837 | struct nlattr *nl_combis; |
| 838 | int i, j; |
| 839 | |
| 840 | nl_combis = nla_nest_start(msg, |
| 841 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 842 | if (!nl_combis) |
| 843 | goto nla_put_failure; |
| 844 | |
| 845 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 846 | const struct ieee80211_iface_combination *c; |
| 847 | struct nlattr *nl_combi, *nl_limits; |
| 848 | |
| 849 | c = &wiphy->iface_combinations[i]; |
| 850 | |
| 851 | nl_combi = nla_nest_start(msg, i + 1); |
| 852 | if (!nl_combi) |
| 853 | goto nla_put_failure; |
| 854 | |
| 855 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 856 | if (!nl_limits) |
| 857 | goto nla_put_failure; |
| 858 | |
| 859 | for (j = 0; j < c->n_limits; j++) { |
| 860 | struct nlattr *nl_limit; |
| 861 | |
| 862 | nl_limit = nla_nest_start(msg, j + 1); |
| 863 | if (!nl_limit) |
| 864 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 865 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 866 | c->limits[j].max)) |
| 867 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 868 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 869 | c->limits[j].types)) |
| 870 | goto nla_put_failure; |
| 871 | nla_nest_end(msg, nl_limit); |
| 872 | } |
| 873 | |
| 874 | nla_nest_end(msg, nl_limits); |
| 875 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 876 | if (c->beacon_int_infra_match && |
| 877 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 878 | goto nla_put_failure; |
| 879 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 880 | c->num_different_channels) || |
| 881 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 882 | c->max_interfaces)) |
| 883 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 884 | |
| 885 | nla_nest_end(msg, nl_combi); |
| 886 | } |
| 887 | |
| 888 | nla_nest_end(msg, nl_combis); |
| 889 | |
| 890 | return 0; |
| 891 | nla_put_failure: |
| 892 | return -ENOBUFS; |
| 893 | } |
| 894 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 895 | 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] | 896 | struct cfg80211_registered_device *dev) |
| 897 | { |
| 898 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 899 | struct nlattr *nl_bands, *nl_band; |
| 900 | struct nlattr *nl_freqs, *nl_freq; |
| 901 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 902 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 903 | enum ieee80211_band band; |
| 904 | struct ieee80211_channel *chan; |
| 905 | struct ieee80211_rate *rate; |
| 906 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 907 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 908 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 909 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 910 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 911 | if (!hdr) |
| 912 | return -1; |
| 913 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 915 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 916 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 917 | cfg80211_rdev_list_generation) || |
| 918 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 919 | dev->wiphy.retry_short) || |
| 920 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 921 | dev->wiphy.retry_long) || |
| 922 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 923 | dev->wiphy.frag_threshold) || |
| 924 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 925 | dev->wiphy.rts_threshold) || |
| 926 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 927 | dev->wiphy.coverage_class) || |
| 928 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 929 | dev->wiphy.max_scan_ssids) || |
| 930 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 931 | dev->wiphy.max_sched_scan_ssids) || |
| 932 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 933 | dev->wiphy.max_scan_ie_len) || |
| 934 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 935 | dev->wiphy.max_sched_scan_ie_len) || |
| 936 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 937 | dev->wiphy.max_match_sets)) |
| 938 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 939 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 940 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 941 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 942 | goto nla_put_failure; |
| 943 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 944 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 945 | goto nla_put_failure; |
| 946 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 947 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 948 | goto nla_put_failure; |
| 949 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 950 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 951 | goto nla_put_failure; |
| 952 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 953 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 954 | goto nla_put_failure; |
| 955 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 956 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 957 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 958 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 959 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 960 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 961 | dev->wiphy.cipher_suites)) |
| 962 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 963 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 964 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 965 | dev->wiphy.max_num_pmkids)) |
| 966 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 967 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 968 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 969 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 970 | goto nla_put_failure; |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 971 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 972 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 973 | dev->wiphy.available_antennas_tx) || |
| 974 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 975 | dev->wiphy.available_antennas_rx)) |
| 976 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 978 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 979 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 980 | dev->wiphy.probe_resp_offload)) |
| 981 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 982 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 983 | if ((dev->wiphy.available_antennas_tx || |
| 984 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 985 | u32 tx_ant = 0, rx_ant = 0; |
| 986 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 987 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 988 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 989 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 990 | tx_ant) || |
| 991 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 992 | rx_ant)) |
| 993 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 997 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 998 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 999 | goto nla_put_failure; |
| 1000 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1001 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1002 | if (!nl_bands) |
| 1003 | goto nla_put_failure; |
| 1004 | |
| 1005 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1006 | if (!dev->wiphy.bands[band]) |
| 1007 | continue; |
| 1008 | |
| 1009 | nl_band = nla_nest_start(msg, band); |
| 1010 | if (!nl_band) |
| 1011 | goto nla_put_failure; |
| 1012 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1013 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1014 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 1015 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1016 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 1017 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 1018 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1019 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 1020 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1021 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 1022 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1023 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 1024 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1025 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1026 | /* add VHT info */ |
| 1027 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1028 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1029 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1030 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1031 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1032 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1033 | goto nla_put_failure; |
| 1034 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1035 | /* add frequencies */ |
| 1036 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1037 | if (!nl_freqs) |
| 1038 | goto nla_put_failure; |
| 1039 | |
| 1040 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1041 | nl_freq = nla_nest_start(msg, i); |
| 1042 | if (!nl_freq) |
| 1043 | goto nla_put_failure; |
| 1044 | |
| 1045 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1046 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1047 | if (nl80211_msg_put_channel(msg, chan)) |
| 1048 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1049 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1050 | nla_nest_end(msg, nl_freq); |
| 1051 | } |
| 1052 | |
| 1053 | nla_nest_end(msg, nl_freqs); |
| 1054 | |
| 1055 | /* add bitrates */ |
| 1056 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1057 | if (!nl_rates) |
| 1058 | goto nla_put_failure; |
| 1059 | |
| 1060 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1061 | nl_rate = nla_nest_start(msg, i); |
| 1062 | if (!nl_rate) |
| 1063 | goto nla_put_failure; |
| 1064 | |
| 1065 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1066 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1067 | rate->bitrate)) |
| 1068 | goto nla_put_failure; |
| 1069 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1070 | nla_put_flag(msg, |
| 1071 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1072 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1073 | |
| 1074 | nla_nest_end(msg, nl_rate); |
| 1075 | } |
| 1076 | |
| 1077 | nla_nest_end(msg, nl_rates); |
| 1078 | |
| 1079 | nla_nest_end(msg, nl_band); |
| 1080 | } |
| 1081 | nla_nest_end(msg, nl_bands); |
| 1082 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1083 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1084 | if (!nl_cmds) |
| 1085 | goto nla_put_failure; |
| 1086 | |
| 1087 | i = 0; |
| 1088 | #define CMD(op, n) \ |
| 1089 | do { \ |
| 1090 | if (dev->ops->op) { \ |
| 1091 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1092 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1093 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1094 | } \ |
| 1095 | } while (0) |
| 1096 | |
| 1097 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1098 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1099 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1100 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1101 | CMD(add_station, NEW_STATION); |
| 1102 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1103 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1104 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1105 | CMD(auth, AUTHENTICATE); |
| 1106 | CMD(assoc, ASSOCIATE); |
| 1107 | CMD(deauth, DEAUTHENTICATE); |
| 1108 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1109 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1110 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1111 | CMD(set_pmksa, SET_PMKSA); |
| 1112 | CMD(del_pmksa, DEL_PMKSA); |
| 1113 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1114 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1115 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1116 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1117 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1118 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1119 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1120 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1121 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1122 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1123 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1124 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1125 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1126 | i++; |
| 1127 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1128 | goto nla_put_failure; |
| 1129 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1130 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1131 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1132 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1133 | CMD(tdls_oper, TDLS_OPER); |
| 1134 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1135 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1136 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1137 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1138 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1139 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1140 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1141 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1142 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1143 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1144 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1145 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1146 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1147 | #ifdef CONFIG_NL80211_TESTMODE |
| 1148 | CMD(testmode_cmd, TESTMODE); |
| 1149 | #endif |
| 1150 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1151 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1152 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1153 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1154 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1155 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1156 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1159 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1160 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1161 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1162 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1165 | nla_nest_end(msg, nl_cmds); |
| 1166 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1167 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1168 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1169 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1170 | dev->wiphy.max_remain_on_channel_duration)) |
| 1171 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1172 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1173 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1174 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1175 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1176 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1177 | if (mgmt_stypes) { |
| 1178 | u16 stypes; |
| 1179 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1180 | enum nl80211_iftype ift; |
| 1181 | |
| 1182 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1183 | if (!nl_ifs) |
| 1184 | goto nla_put_failure; |
| 1185 | |
| 1186 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1187 | nl_ftypes = nla_nest_start(msg, ift); |
| 1188 | if (!nl_ftypes) |
| 1189 | goto nla_put_failure; |
| 1190 | i = 0; |
| 1191 | stypes = mgmt_stypes[ift].tx; |
| 1192 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1193 | if ((stypes & 1) && |
| 1194 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1195 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1196 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1197 | stypes >>= 1; |
| 1198 | i++; |
| 1199 | } |
| 1200 | nla_nest_end(msg, nl_ftypes); |
| 1201 | } |
| 1202 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1203 | nla_nest_end(msg, nl_ifs); |
| 1204 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1205 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1206 | if (!nl_ifs) |
| 1207 | goto nla_put_failure; |
| 1208 | |
| 1209 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1210 | nl_ftypes = nla_nest_start(msg, ift); |
| 1211 | if (!nl_ftypes) |
| 1212 | goto nla_put_failure; |
| 1213 | i = 0; |
| 1214 | stypes = mgmt_stypes[ift].rx; |
| 1215 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1216 | if ((stypes & 1) && |
| 1217 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1218 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1219 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1220 | stypes >>= 1; |
| 1221 | i++; |
| 1222 | } |
| 1223 | nla_nest_end(msg, nl_ftypes); |
| 1224 | } |
| 1225 | nla_nest_end(msg, nl_ifs); |
| 1226 | } |
| 1227 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1228 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1229 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1230 | struct nlattr *nl_wowlan; |
| 1231 | |
| 1232 | nl_wowlan = nla_nest_start(msg, |
| 1233 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1234 | if (!nl_wowlan) |
| 1235 | goto nla_put_failure; |
| 1236 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1237 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1238 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1239 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1240 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1241 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1242 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1243 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1244 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1245 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1246 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1247 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1248 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1249 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1250 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1251 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1252 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1253 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1254 | if (dev->wiphy.wowlan.n_patterns) { |
| 1255 | struct nl80211_wowlan_pattern_support pat = { |
| 1256 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1257 | .min_pattern_len = |
| 1258 | dev->wiphy.wowlan.pattern_min_len, |
| 1259 | .max_pattern_len = |
| 1260 | dev->wiphy.wowlan.pattern_max_len, |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 1261 | .max_pkt_offset = |
| 1262 | dev->wiphy.wowlan.max_pkt_offset, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1263 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1264 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1265 | sizeof(pat), &pat)) |
| 1266 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | nla_nest_end(msg, nl_wowlan); |
| 1270 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1271 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1272 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1273 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1274 | dev->wiphy.software_iftypes)) |
| 1275 | goto nla_put_failure; |
| 1276 | |
| 1277 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1278 | goto nla_put_failure; |
| 1279 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1280 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1281 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1282 | dev->wiphy.ap_sme_capa)) |
| 1283 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1284 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1285 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1286 | dev->wiphy.features)) |
| 1287 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1288 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1289 | if (dev->wiphy.ht_capa_mod_mask && |
| 1290 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1291 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1292 | dev->wiphy.ht_capa_mod_mask)) |
| 1293 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1294 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 1295 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1296 | dev->wiphy.max_acl_mac_addrs && |
| 1297 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1298 | dev->wiphy.max_acl_mac_addrs)) |
| 1299 | goto nla_put_failure; |
| 1300 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1301 | return genlmsg_end(msg, hdr); |
| 1302 | |
| 1303 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1304 | genlmsg_cancel(msg, hdr); |
| 1305 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1309 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1310 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1311 | int start = cb->args[0]; |
| 1312 | struct cfg80211_registered_device *dev; |
| 1313 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1314 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1315 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1316 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1317 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1318 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1319 | continue; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1320 | ret = nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
| 1321 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1322 | dev); |
| 1323 | if (ret < 0) { |
| 1324 | /* |
| 1325 | * If sending the wiphy data didn't fit (ENOBUFS or |
| 1326 | * EMSGSIZE returned), this SKB is still empty (so |
| 1327 | * it's not too big because another wiphy dataset is |
| 1328 | * already in the skb) and we've not tried to adjust |
| 1329 | * the dump allocation yet ... then adjust the alloc |
| 1330 | * size to be bigger, and return 1 but with the empty |
| 1331 | * skb. This results in an empty message being RX'ed |
| 1332 | * in userspace, but that is ignored. |
| 1333 | * |
| 1334 | * We can then retry with the larger buffer. |
| 1335 | */ |
| 1336 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1337 | !skb->len && |
| 1338 | cb->min_dump_alloc < 4096) { |
| 1339 | cb->min_dump_alloc = 4096; |
| 1340 | mutex_unlock(&cfg80211_mutex); |
| 1341 | return 1; |
| 1342 | } |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1343 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1344 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1345 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1346 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1347 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1348 | |
| 1349 | cb->args[0] = idx; |
| 1350 | |
| 1351 | return skb->len; |
| 1352 | } |
| 1353 | |
| 1354 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1355 | { |
| 1356 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1357 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1358 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1359 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1360 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1361 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1362 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1363 | 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] | 1364 | nlmsg_free(msg); |
| 1365 | return -ENOBUFS; |
| 1366 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1367 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1368 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1371 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1372 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1373 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1374 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1375 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1376 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1377 | }; |
| 1378 | |
| 1379 | static int parse_txq_params(struct nlattr *tb[], |
| 1380 | struct ieee80211_txq_params *txq_params) |
| 1381 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1382 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1383 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1384 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1385 | return -EINVAL; |
| 1386 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1387 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1388 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1389 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1390 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1391 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1392 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1393 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1394 | return -EINVAL; |
| 1395 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1396 | return 0; |
| 1397 | } |
| 1398 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1399 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1400 | { |
| 1401 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1402 | * You can only set the channel explicitly for WDS interfaces, |
| 1403 | * all others have their channel managed via their respective |
| 1404 | * "establish a connection" command (connect, join, ...) |
| 1405 | * |
| 1406 | * For AP/GO and mesh mode, the channel can be set with the |
| 1407 | * channel userspace API, but is only stored and passed to the |
| 1408 | * low-level driver when the AP starts or the mesh is joined. |
| 1409 | * This is for backward compatibility, userspace can also give |
| 1410 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1411 | * |
| 1412 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1413 | * whatever else is going on, so they have their own special |
| 1414 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1415 | */ |
| 1416 | return !wdev || |
| 1417 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1418 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1419 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1420 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1421 | } |
| 1422 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1423 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1424 | struct genl_info *info, |
| 1425 | struct cfg80211_chan_def *chandef) |
| 1426 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1427 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1428 | |
| 1429 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1430 | return -EINVAL; |
| 1431 | |
| 1432 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1433 | |
| 1434 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1435 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1436 | chandef->center_freq1 = control_freq; |
| 1437 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1438 | |
| 1439 | /* Primary channel not allowed */ |
| 1440 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1441 | return -EINVAL; |
| 1442 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1443 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1444 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1445 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1446 | chantype = nla_get_u32( |
| 1447 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1448 | |
| 1449 | switch (chantype) { |
| 1450 | case NL80211_CHAN_NO_HT: |
| 1451 | case NL80211_CHAN_HT20: |
| 1452 | case NL80211_CHAN_HT40PLUS: |
| 1453 | case NL80211_CHAN_HT40MINUS: |
| 1454 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1455 | chantype); |
| 1456 | break; |
| 1457 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1458 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1459 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1460 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1461 | chandef->width = |
| 1462 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1463 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1464 | chandef->center_freq1 = |
| 1465 | nla_get_u32( |
| 1466 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1467 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1468 | chandef->center_freq2 = |
| 1469 | nla_get_u32( |
| 1470 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1471 | } |
| 1472 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1473 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1474 | return -EINVAL; |
| 1475 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1476 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1477 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1478 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1479 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1480 | return 0; |
| 1481 | } |
| 1482 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1483 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1484 | struct wireless_dev *wdev, |
| 1485 | struct genl_info *info) |
| 1486 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1487 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1488 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1489 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1490 | |
| 1491 | if (wdev) |
| 1492 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1493 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1494 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1495 | return -EOPNOTSUPP; |
| 1496 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1497 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1498 | if (result) |
| 1499 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1500 | |
| 1501 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1502 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1503 | case NL80211_IFTYPE_AP: |
| 1504 | case NL80211_IFTYPE_P2P_GO: |
| 1505 | if (wdev->beacon_interval) { |
| 1506 | result = -EBUSY; |
| 1507 | break; |
| 1508 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1509 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1510 | result = -EINVAL; |
| 1511 | break; |
| 1512 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1513 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1514 | result = 0; |
| 1515 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1516 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1517 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1518 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1519 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1520 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1521 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1522 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1523 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1524 | } |
| 1525 | mutex_unlock(&rdev->devlist_mtx); |
| 1526 | |
| 1527 | return result; |
| 1528 | } |
| 1529 | |
| 1530 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1531 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1533 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1534 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1535 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1538 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1539 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1541 | struct net_device *dev = info->user_ptr[1]; |
| 1542 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1543 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1544 | |
| 1545 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1546 | return -EINVAL; |
| 1547 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1548 | if (netif_running(dev)) |
| 1549 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1550 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1551 | if (!rdev->ops->set_wds_peer) |
| 1552 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1553 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1554 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1555 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1556 | |
| 1557 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1558 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1562 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1563 | { |
| 1564 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1565 | struct net_device *netdev = NULL; |
| 1566 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1567 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1568 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1569 | u32 changed; |
| 1570 | u8 retry_short = 0, retry_long = 0; |
| 1571 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1572 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1573 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1574 | /* |
| 1575 | * Try to find the wiphy and netdev. Normally this |
| 1576 | * function shouldn't need the netdev, but this is |
| 1577 | * done for backward compatibility -- previously |
| 1578 | * setting the channel was done per wiphy, but now |
| 1579 | * it is per netdev. Previous userland like hostapd |
| 1580 | * also passed a netdev to set_wiphy, so that it is |
| 1581 | * possible to let that go to the right netdev! |
| 1582 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1583 | mutex_lock(&cfg80211_mutex); |
| 1584 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1585 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1586 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1587 | |
| 1588 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1589 | if (netdev && netdev->ieee80211_ptr) { |
| 1590 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1591 | mutex_lock(&rdev->mtx); |
| 1592 | } else |
| 1593 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1594 | } |
| 1595 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1596 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1597 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1598 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1599 | if (IS_ERR(rdev)) { |
| 1600 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1601 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1602 | } |
| 1603 | wdev = NULL; |
| 1604 | netdev = NULL; |
| 1605 | result = 0; |
| 1606 | |
| 1607 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1608 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1609 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1610 | |
| 1611 | /* |
| 1612 | * end workaround code, by now the rdev is available |
| 1613 | * and locked, and wdev may or may not be NULL. |
| 1614 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1615 | |
| 1616 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1617 | result = cfg80211_dev_rename( |
| 1618 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1619 | |
| 1620 | mutex_unlock(&cfg80211_mutex); |
| 1621 | |
| 1622 | if (result) |
| 1623 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1624 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1625 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1626 | struct ieee80211_txq_params txq_params; |
| 1627 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1628 | |
| 1629 | if (!rdev->ops->set_txq_params) { |
| 1630 | result = -EOPNOTSUPP; |
| 1631 | goto bad_res; |
| 1632 | } |
| 1633 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1634 | if (!netdev) { |
| 1635 | result = -EINVAL; |
| 1636 | goto bad_res; |
| 1637 | } |
| 1638 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1639 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1640 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1641 | result = -EINVAL; |
| 1642 | goto bad_res; |
| 1643 | } |
| 1644 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1645 | if (!netif_running(netdev)) { |
| 1646 | result = -ENETDOWN; |
| 1647 | goto bad_res; |
| 1648 | } |
| 1649 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1650 | nla_for_each_nested(nl_txq_params, |
| 1651 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1652 | rem_txq_params) { |
| 1653 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1654 | nla_data(nl_txq_params), |
| 1655 | nla_len(nl_txq_params), |
| 1656 | txq_params_policy); |
| 1657 | result = parse_txq_params(tb, &txq_params); |
| 1658 | if (result) |
| 1659 | goto bad_res; |
| 1660 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1661 | result = rdev_set_txq_params(rdev, netdev, |
| 1662 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1663 | if (result) |
| 1664 | goto bad_res; |
| 1665 | } |
| 1666 | } |
| 1667 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1668 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1669 | result = __nl80211_set_channel(rdev, |
| 1670 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1671 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1672 | if (result) |
| 1673 | goto bad_res; |
| 1674 | } |
| 1675 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1676 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1677 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1678 | enum nl80211_tx_power_setting type; |
| 1679 | int idx, mbm = 0; |
| 1680 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1681 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1682 | txp_wdev = NULL; |
| 1683 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1684 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1685 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1686 | goto bad_res; |
| 1687 | } |
| 1688 | |
| 1689 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1690 | type = nla_get_u32(info->attrs[idx]); |
| 1691 | |
| 1692 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1693 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1694 | result = -EINVAL; |
| 1695 | goto bad_res; |
| 1696 | } |
| 1697 | |
| 1698 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1699 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1700 | mbm = nla_get_u32(info->attrs[idx]); |
| 1701 | } |
| 1702 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1703 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1704 | if (result) |
| 1705 | goto bad_res; |
| 1706 | } |
| 1707 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1708 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1709 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1710 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1711 | if ((!rdev->wiphy.available_antennas_tx && |
| 1712 | !rdev->wiphy.available_antennas_rx) || |
| 1713 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1714 | result = -EOPNOTSUPP; |
| 1715 | goto bad_res; |
| 1716 | } |
| 1717 | |
| 1718 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1719 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1720 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1721 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1722 | * available antenna masks, except for the "all" mask */ |
| 1723 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1724 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1725 | result = -EINVAL; |
| 1726 | goto bad_res; |
| 1727 | } |
| 1728 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1729 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1730 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1731 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1732 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1733 | if (result) |
| 1734 | goto bad_res; |
| 1735 | } |
| 1736 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1737 | changed = 0; |
| 1738 | |
| 1739 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1740 | retry_short = nla_get_u8( |
| 1741 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1742 | if (retry_short == 0) { |
| 1743 | result = -EINVAL; |
| 1744 | goto bad_res; |
| 1745 | } |
| 1746 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1747 | } |
| 1748 | |
| 1749 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1750 | retry_long = nla_get_u8( |
| 1751 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1752 | if (retry_long == 0) { |
| 1753 | result = -EINVAL; |
| 1754 | goto bad_res; |
| 1755 | } |
| 1756 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1757 | } |
| 1758 | |
| 1759 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1760 | frag_threshold = nla_get_u32( |
| 1761 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1762 | if (frag_threshold < 256) { |
| 1763 | result = -EINVAL; |
| 1764 | goto bad_res; |
| 1765 | } |
| 1766 | if (frag_threshold != (u32) -1) { |
| 1767 | /* |
| 1768 | * Fragments (apart from the last one) are required to |
| 1769 | * have even length. Make the fragmentation code |
| 1770 | * simpler by stripping LSB should someone try to use |
| 1771 | * odd threshold value. |
| 1772 | */ |
| 1773 | frag_threshold &= ~0x1; |
| 1774 | } |
| 1775 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1776 | } |
| 1777 | |
| 1778 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1779 | rts_threshold = nla_get_u32( |
| 1780 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1781 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1782 | } |
| 1783 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1784 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1785 | coverage_class = nla_get_u8( |
| 1786 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1787 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1788 | } |
| 1789 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1790 | if (changed) { |
| 1791 | u8 old_retry_short, old_retry_long; |
| 1792 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1793 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1794 | |
| 1795 | if (!rdev->ops->set_wiphy_params) { |
| 1796 | result = -EOPNOTSUPP; |
| 1797 | goto bad_res; |
| 1798 | } |
| 1799 | |
| 1800 | old_retry_short = rdev->wiphy.retry_short; |
| 1801 | old_retry_long = rdev->wiphy.retry_long; |
| 1802 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1803 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1804 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1805 | |
| 1806 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1807 | rdev->wiphy.retry_short = retry_short; |
| 1808 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1809 | rdev->wiphy.retry_long = retry_long; |
| 1810 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1811 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1812 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1813 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1814 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1815 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1816 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1817 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1818 | if (result) { |
| 1819 | rdev->wiphy.retry_short = old_retry_short; |
| 1820 | rdev->wiphy.retry_long = old_retry_long; |
| 1821 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1822 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1823 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1824 | } |
| 1825 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1826 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1827 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1828 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1829 | if (netdev) |
| 1830 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1831 | return result; |
| 1832 | } |
| 1833 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1834 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1835 | { |
| 1836 | return (u64)wdev->identifier | |
| 1837 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1838 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1839 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1840 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1841 | struct cfg80211_chan_def *chandef) |
| 1842 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1843 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1844 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1845 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1846 | chandef->chan->center_freq)) |
| 1847 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1848 | switch (chandef->width) { |
| 1849 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1850 | case NL80211_CHAN_WIDTH_20: |
| 1851 | case NL80211_CHAN_WIDTH_40: |
| 1852 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1853 | cfg80211_get_chandef_type(chandef))) |
| 1854 | return -ENOBUFS; |
| 1855 | break; |
| 1856 | default: |
| 1857 | break; |
| 1858 | } |
| 1859 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1860 | return -ENOBUFS; |
| 1861 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1862 | return -ENOBUFS; |
| 1863 | if (chandef->center_freq2 && |
| 1864 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1865 | return -ENOBUFS; |
| 1866 | return 0; |
| 1867 | } |
| 1868 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1869 | 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] | 1870 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1871 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1872 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1873 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1874 | void *hdr; |
| 1875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1876 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1877 | if (!hdr) |
| 1878 | return -1; |
| 1879 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1880 | if (dev && |
| 1881 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1882 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1883 | goto nla_put_failure; |
| 1884 | |
| 1885 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1886 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1887 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1888 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1889 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1890 | rdev->devlist_generation ^ |
| 1891 | (cfg80211_rdev_list_generation << 2))) |
| 1892 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1893 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1894 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1895 | int ret; |
| 1896 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1897 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1898 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1899 | if (ret == 0) { |
| 1900 | if (nl80211_send_chandef(msg, &chandef)) |
| 1901 | goto nla_put_failure; |
| 1902 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1903 | } |
| 1904 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1905 | if (wdev->ssid_len) { |
| 1906 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1907 | goto nla_put_failure; |
| 1908 | } |
| 1909 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1910 | return genlmsg_end(msg, hdr); |
| 1911 | |
| 1912 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1913 | genlmsg_cancel(msg, hdr); |
| 1914 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1918 | { |
| 1919 | int wp_idx = 0; |
| 1920 | int if_idx = 0; |
| 1921 | int wp_start = cb->args[0]; |
| 1922 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1923 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1924 | struct wireless_dev *wdev; |
| 1925 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1926 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1927 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1928 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1929 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1930 | if (wp_idx < wp_start) { |
| 1931 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1932 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1933 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1934 | if_idx = 0; |
| 1935 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1936 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1937 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1938 | if (if_idx < if_start) { |
| 1939 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1940 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1941 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1942 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1943 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1944 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1945 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1946 | goto out; |
| 1947 | } |
| 1948 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1949 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1950 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1951 | |
| 1952 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1953 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1954 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1955 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1956 | |
| 1957 | cb->args[0] = wp_idx; |
| 1958 | cb->args[1] = if_idx; |
| 1959 | |
| 1960 | return skb->len; |
| 1961 | } |
| 1962 | |
| 1963 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1964 | { |
| 1965 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1966 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1967 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1968 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1970 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1971 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1972 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1973 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1974 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1975 | nlmsg_free(msg); |
| 1976 | return -ENOBUFS; |
| 1977 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1978 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1979 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1980 | } |
| 1981 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1982 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1983 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1984 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1985 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1986 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1987 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1988 | }; |
| 1989 | |
| 1990 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1991 | { |
| 1992 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1993 | int flag; |
| 1994 | |
| 1995 | *mntrflags = 0; |
| 1996 | |
| 1997 | if (!nla) |
| 1998 | return -EINVAL; |
| 1999 | |
| 2000 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2001 | nla, mntr_flags_policy)) |
| 2002 | return -EINVAL; |
| 2003 | |
| 2004 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2005 | if (flags[flag]) |
| 2006 | *mntrflags |= (1<<flag); |
| 2007 | |
| 2008 | return 0; |
| 2009 | } |
| 2010 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2011 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2012 | struct net_device *netdev, u8 use_4addr, |
| 2013 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2014 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2015 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2016 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2017 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2018 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2019 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2020 | |
| 2021 | switch (iftype) { |
| 2022 | case NL80211_IFTYPE_AP_VLAN: |
| 2023 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2024 | return 0; |
| 2025 | break; |
| 2026 | case NL80211_IFTYPE_STATION: |
| 2027 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2028 | return 0; |
| 2029 | break; |
| 2030 | default: |
| 2031 | break; |
| 2032 | } |
| 2033 | |
| 2034 | return -EOPNOTSUPP; |
| 2035 | } |
| 2036 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2037 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2038 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2039 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2040 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2041 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2042 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2043 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2044 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2045 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2046 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2047 | memset(¶ms, 0, sizeof(params)); |
| 2048 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2049 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2050 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2051 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2052 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2053 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2054 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2055 | if (ntype > NL80211_IFTYPE_MAX) |
| 2056 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2057 | } |
| 2058 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2059 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2060 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2061 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2062 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2063 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2064 | if (netif_running(dev)) |
| 2065 | return -EBUSY; |
| 2066 | |
| 2067 | wdev_lock(wdev); |
| 2068 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2069 | IEEE80211_MAX_MESH_ID_LEN); |
| 2070 | wdev->mesh_id_up_len = |
| 2071 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2072 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2073 | wdev->mesh_id_up_len); |
| 2074 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2077 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2078 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2079 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2080 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2081 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2082 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2083 | } else { |
| 2084 | params.use_4addr = -1; |
| 2085 | } |
| 2086 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2087 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2088 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2089 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2090 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2091 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2092 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2093 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2094 | |
| 2095 | flags = &_flags; |
| 2096 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2097 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2098 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2099 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2100 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2101 | else |
| 2102 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2103 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2104 | if (!err && params.use_4addr != -1) |
| 2105 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2106 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2107 | return err; |
| 2108 | } |
| 2109 | |
| 2110 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2111 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2113 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2114 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2115 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2116 | int err; |
| 2117 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2118 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2119 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2120 | memset(¶ms, 0, sizeof(params)); |
| 2121 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2122 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2123 | return -EINVAL; |
| 2124 | |
| 2125 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2126 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2127 | if (type > NL80211_IFTYPE_MAX) |
| 2128 | return -EINVAL; |
| 2129 | } |
| 2130 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2131 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2132 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2133 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2134 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2135 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2136 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2137 | ETH_ALEN); |
| 2138 | if (!is_valid_ether_addr(params.macaddr)) |
| 2139 | return -EADDRNOTAVAIL; |
| 2140 | } |
| 2141 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2142 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2143 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2144 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2145 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2146 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2147 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2148 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2149 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2150 | if (!msg) |
| 2151 | return -ENOMEM; |
| 2152 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2153 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2154 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2155 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2156 | wdev = rdev_add_virtual_intf(rdev, |
| 2157 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2158 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2159 | if (IS_ERR(wdev)) { |
| 2160 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2161 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2162 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2163 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2164 | switch (type) { |
| 2165 | case NL80211_IFTYPE_MESH_POINT: |
| 2166 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2167 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2168 | wdev_lock(wdev); |
| 2169 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2170 | IEEE80211_MAX_MESH_ID_LEN); |
| 2171 | wdev->mesh_id_up_len = |
| 2172 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2173 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2174 | wdev->mesh_id_up_len); |
| 2175 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2176 | break; |
| 2177 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2178 | /* |
| 2179 | * P2P Device doesn't have a netdev, so doesn't go |
| 2180 | * through the netdev notifier and must be added here |
| 2181 | */ |
| 2182 | mutex_init(&wdev->mtx); |
| 2183 | INIT_LIST_HEAD(&wdev->event_list); |
| 2184 | spin_lock_init(&wdev->event_lock); |
| 2185 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2186 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2187 | |
| 2188 | mutex_lock(&rdev->devlist_mtx); |
| 2189 | wdev->identifier = ++rdev->wdev_id; |
| 2190 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2191 | rdev->devlist_generation++; |
| 2192 | mutex_unlock(&rdev->devlist_mtx); |
| 2193 | break; |
| 2194 | default: |
| 2195 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2196 | } |
| 2197 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2198 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2199 | rdev, wdev) < 0) { |
| 2200 | nlmsg_free(msg); |
| 2201 | return -ENOBUFS; |
| 2202 | } |
| 2203 | |
| 2204 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2208 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2209 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2210 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2211 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2212 | if (!rdev->ops->del_virtual_intf) |
| 2213 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2214 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2215 | /* |
| 2216 | * If we remove a wireless device without a netdev then clear |
| 2217 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2218 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2219 | * since the wdev has been freed, unlike with a netdev where |
| 2220 | * we need the dev_put() for the netdev to really be freed. |
| 2221 | */ |
| 2222 | if (!wdev->netdev) |
| 2223 | info->user_ptr[1] = NULL; |
| 2224 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2225 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2226 | } |
| 2227 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2228 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2229 | { |
| 2230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2231 | struct net_device *dev = info->user_ptr[1]; |
| 2232 | u16 noack_map; |
| 2233 | |
| 2234 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2235 | return -EINVAL; |
| 2236 | |
| 2237 | if (!rdev->ops->set_noack_map) |
| 2238 | return -EOPNOTSUPP; |
| 2239 | |
| 2240 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2241 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2242 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2243 | } |
| 2244 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2245 | struct get_key_cookie { |
| 2246 | struct sk_buff *msg; |
| 2247 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2248 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2249 | }; |
| 2250 | |
| 2251 | static void get_key_callback(void *c, struct key_params *params) |
| 2252 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2253 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2254 | struct get_key_cookie *cookie = c; |
| 2255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2256 | if ((params->key && |
| 2257 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2258 | params->key_len, params->key)) || |
| 2259 | (params->seq && |
| 2260 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2261 | params->seq_len, params->seq)) || |
| 2262 | (params->cipher && |
| 2263 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2264 | params->cipher))) |
| 2265 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2266 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2267 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2268 | if (!key) |
| 2269 | goto nla_put_failure; |
| 2270 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2271 | if ((params->key && |
| 2272 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2273 | params->key_len, params->key)) || |
| 2274 | (params->seq && |
| 2275 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2276 | params->seq_len, params->seq)) || |
| 2277 | (params->cipher && |
| 2278 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2279 | params->cipher))) |
| 2280 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2281 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2282 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2283 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2284 | |
| 2285 | nla_nest_end(cookie->msg, key); |
| 2286 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2287 | return; |
| 2288 | nla_put_failure: |
| 2289 | cookie->error = 1; |
| 2290 | } |
| 2291 | |
| 2292 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2293 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2295 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2296 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2297 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2298 | const u8 *mac_addr = NULL; |
| 2299 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2300 | struct get_key_cookie cookie = { |
| 2301 | .error = 0, |
| 2302 | }; |
| 2303 | void *hdr; |
| 2304 | struct sk_buff *msg; |
| 2305 | |
| 2306 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2307 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2308 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2309 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2310 | return -EINVAL; |
| 2311 | |
| 2312 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2313 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2314 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2315 | pairwise = !!mac_addr; |
| 2316 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2317 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2318 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2319 | return -EINVAL; |
| 2320 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2321 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2322 | return -EINVAL; |
| 2323 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2324 | } |
| 2325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2326 | if (!rdev->ops->get_key) |
| 2327 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2328 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2329 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2330 | if (!msg) |
| 2331 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2332 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2333 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2334 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2335 | if (IS_ERR(hdr)) |
| 2336 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2337 | |
| 2338 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2339 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2340 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2341 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2342 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2343 | goto nla_put_failure; |
| 2344 | if (mac_addr && |
| 2345 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2346 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2347 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2348 | if (pairwise && mac_addr && |
| 2349 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2350 | return -ENOENT; |
| 2351 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2352 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2353 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2354 | |
| 2355 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2356 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2357 | |
| 2358 | if (cookie.error) |
| 2359 | goto nla_put_failure; |
| 2360 | |
| 2361 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2362 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2363 | |
| 2364 | nla_put_failure: |
| 2365 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2366 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2367 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2368 | return err; |
| 2369 | } |
| 2370 | |
| 2371 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2372 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2373 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2374 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2375 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2376 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2377 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2378 | err = nl80211_parse_key(info, &key); |
| 2379 | if (err) |
| 2380 | return err; |
| 2381 | |
| 2382 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2383 | return -EINVAL; |
| 2384 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2385 | /* only support setting default key */ |
| 2386 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2387 | return -EINVAL; |
| 2388 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2389 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2390 | |
| 2391 | if (key.def) { |
| 2392 | if (!rdev->ops->set_default_key) { |
| 2393 | err = -EOPNOTSUPP; |
| 2394 | goto out; |
| 2395 | } |
| 2396 | |
| 2397 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2398 | if (err) |
| 2399 | goto out; |
| 2400 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2401 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2402 | key.def_uni, key.def_multi); |
| 2403 | |
| 2404 | if (err) |
| 2405 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2406 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2407 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2408 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2409 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2410 | } else { |
| 2411 | if (key.def_uni || !key.def_multi) { |
| 2412 | err = -EINVAL; |
| 2413 | goto out; |
| 2414 | } |
| 2415 | |
| 2416 | if (!rdev->ops->set_default_mgmt_key) { |
| 2417 | err = -EOPNOTSUPP; |
| 2418 | goto out; |
| 2419 | } |
| 2420 | |
| 2421 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2422 | if (err) |
| 2423 | goto out; |
| 2424 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2425 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2426 | if (err) |
| 2427 | goto out; |
| 2428 | |
| 2429 | #ifdef CONFIG_CFG80211_WEXT |
| 2430 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2431 | #endif |
| 2432 | } |
| 2433 | |
| 2434 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2435 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2436 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2437 | return err; |
| 2438 | } |
| 2439 | |
| 2440 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2441 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2442 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2443 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2444 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2445 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2446 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2447 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2448 | err = nl80211_parse_key(info, &key); |
| 2449 | if (err) |
| 2450 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2451 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2452 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2453 | return -EINVAL; |
| 2454 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2455 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2456 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2457 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2458 | if (key.type == -1) { |
| 2459 | if (mac_addr) |
| 2460 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2461 | else |
| 2462 | key.type = NL80211_KEYTYPE_GROUP; |
| 2463 | } |
| 2464 | |
| 2465 | /* for now */ |
| 2466 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2467 | key.type != NL80211_KEYTYPE_GROUP) |
| 2468 | return -EINVAL; |
| 2469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2470 | if (!rdev->ops->add_key) |
| 2471 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2472 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2473 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2474 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2475 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2476 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2477 | |
| 2478 | wdev_lock(dev->ieee80211_ptr); |
| 2479 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2480 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2481 | err = rdev_add_key(rdev, dev, key.idx, |
| 2482 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2483 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2484 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2485 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2486 | return err; |
| 2487 | } |
| 2488 | |
| 2489 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2490 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2492 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2493 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2494 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2495 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2496 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2497 | err = nl80211_parse_key(info, &key); |
| 2498 | if (err) |
| 2499 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2500 | |
| 2501 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2502 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2503 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2504 | if (key.type == -1) { |
| 2505 | if (mac_addr) |
| 2506 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2507 | else |
| 2508 | key.type = NL80211_KEYTYPE_GROUP; |
| 2509 | } |
| 2510 | |
| 2511 | /* for now */ |
| 2512 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2513 | key.type != NL80211_KEYTYPE_GROUP) |
| 2514 | return -EINVAL; |
| 2515 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2516 | if (!rdev->ops->del_key) |
| 2517 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2518 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2519 | wdev_lock(dev->ieee80211_ptr); |
| 2520 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2521 | |
| 2522 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2523 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2524 | err = -ENOENT; |
| 2525 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2526 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2527 | err = rdev_del_key(rdev, dev, key.idx, |
| 2528 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2529 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2530 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2531 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2532 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2533 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2534 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2535 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2536 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2537 | } |
| 2538 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2539 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2540 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2541 | return err; |
| 2542 | } |
| 2543 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2544 | /* This function returns an error or the number of nested attributes */ |
| 2545 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2546 | { |
| 2547 | struct nlattr *attr; |
| 2548 | int n_entries = 0, tmp; |
| 2549 | |
| 2550 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2551 | if (nla_len(attr) != ETH_ALEN) |
| 2552 | return -EINVAL; |
| 2553 | |
| 2554 | n_entries++; |
| 2555 | } |
| 2556 | |
| 2557 | return n_entries; |
| 2558 | } |
| 2559 | |
| 2560 | /* |
| 2561 | * This function parses ACL information and allocates memory for ACL data. |
| 2562 | * On successful return, the calling function is responsible to free the |
| 2563 | * ACL buffer returned by this function. |
| 2564 | */ |
| 2565 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2566 | struct genl_info *info) |
| 2567 | { |
| 2568 | enum nl80211_acl_policy acl_policy; |
| 2569 | struct nlattr *attr; |
| 2570 | struct cfg80211_acl_data *acl; |
| 2571 | int i = 0, n_entries, tmp; |
| 2572 | |
| 2573 | if (!wiphy->max_acl_mac_addrs) |
| 2574 | return ERR_PTR(-EOPNOTSUPP); |
| 2575 | |
| 2576 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2577 | return ERR_PTR(-EINVAL); |
| 2578 | |
| 2579 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2580 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2581 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2582 | return ERR_PTR(-EINVAL); |
| 2583 | |
| 2584 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2585 | return ERR_PTR(-EINVAL); |
| 2586 | |
| 2587 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2588 | if (n_entries < 0) |
| 2589 | return ERR_PTR(n_entries); |
| 2590 | |
| 2591 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2592 | return ERR_PTR(-ENOTSUPP); |
| 2593 | |
| 2594 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2595 | GFP_KERNEL); |
| 2596 | if (!acl) |
| 2597 | return ERR_PTR(-ENOMEM); |
| 2598 | |
| 2599 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2600 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2601 | i++; |
| 2602 | } |
| 2603 | |
| 2604 | acl->n_acl_entries = n_entries; |
| 2605 | acl->acl_policy = acl_policy; |
| 2606 | |
| 2607 | return acl; |
| 2608 | } |
| 2609 | |
| 2610 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2611 | { |
| 2612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2613 | struct net_device *dev = info->user_ptr[1]; |
| 2614 | struct cfg80211_acl_data *acl; |
| 2615 | int err; |
| 2616 | |
| 2617 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2618 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2619 | return -EOPNOTSUPP; |
| 2620 | |
| 2621 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2622 | return -EINVAL; |
| 2623 | |
| 2624 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2625 | if (IS_ERR(acl)) |
| 2626 | return PTR_ERR(acl); |
| 2627 | |
| 2628 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2629 | |
| 2630 | kfree(acl); |
| 2631 | |
| 2632 | return err; |
| 2633 | } |
| 2634 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2635 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2636 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2637 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2638 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2639 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2640 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2641 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2642 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2643 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2644 | return -EINVAL; |
| 2645 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2646 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2647 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2648 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2649 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2650 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2651 | if (!bcn->head_len) |
| 2652 | return -EINVAL; |
| 2653 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2657 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2658 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2659 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2660 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2663 | if (!haveinfo) |
| 2664 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2665 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2666 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2667 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2668 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2672 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2673 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2674 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2675 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2676 | } |
| 2677 | |
| 2678 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2679 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2680 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2681 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2682 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2683 | } |
| 2684 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2685 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2686 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2687 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2688 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2689 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2690 | } |
| 2691 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2692 | return 0; |
| 2693 | } |
| 2694 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2695 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2696 | struct cfg80211_ap_settings *params) |
| 2697 | { |
| 2698 | struct wireless_dev *wdev; |
| 2699 | bool ret = false; |
| 2700 | |
| 2701 | mutex_lock(&rdev->devlist_mtx); |
| 2702 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2703 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2704 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2705 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2706 | continue; |
| 2707 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2708 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2709 | continue; |
| 2710 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2711 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2712 | ret = true; |
| 2713 | break; |
| 2714 | } |
| 2715 | |
| 2716 | mutex_unlock(&rdev->devlist_mtx); |
| 2717 | |
| 2718 | return ret; |
| 2719 | } |
| 2720 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2721 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2722 | enum nl80211_auth_type auth_type, |
| 2723 | enum nl80211_commands cmd) |
| 2724 | { |
| 2725 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2726 | return false; |
| 2727 | |
| 2728 | switch (cmd) { |
| 2729 | case NL80211_CMD_AUTHENTICATE: |
| 2730 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2731 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2732 | return false; |
| 2733 | return true; |
| 2734 | case NL80211_CMD_CONNECT: |
| 2735 | case NL80211_CMD_START_AP: |
| 2736 | /* SAE not supported yet */ |
| 2737 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2738 | return false; |
| 2739 | return true; |
| 2740 | default: |
| 2741 | return false; |
| 2742 | } |
| 2743 | } |
| 2744 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2745 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2746 | { |
| 2747 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2748 | struct net_device *dev = info->user_ptr[1]; |
| 2749 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2750 | struct cfg80211_ap_settings params; |
| 2751 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2752 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2753 | |
| 2754 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2755 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2756 | return -EOPNOTSUPP; |
| 2757 | |
| 2758 | if (!rdev->ops->start_ap) |
| 2759 | return -EOPNOTSUPP; |
| 2760 | |
| 2761 | if (wdev->beacon_interval) |
| 2762 | return -EALREADY; |
| 2763 | |
| 2764 | memset(¶ms, 0, sizeof(params)); |
| 2765 | |
| 2766 | /* these are required for START_AP */ |
| 2767 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2768 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2769 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2770 | return -EINVAL; |
| 2771 | |
| 2772 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2773 | if (err) |
| 2774 | return err; |
| 2775 | |
| 2776 | params.beacon_interval = |
| 2777 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2778 | params.dtim_period = |
| 2779 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2780 | |
| 2781 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2782 | if (err) |
| 2783 | return err; |
| 2784 | |
| 2785 | /* |
| 2786 | * In theory, some of these attributes should be required here |
| 2787 | * but since they were not used when the command was originally |
| 2788 | * added, keep them optional for old user space programs to let |
| 2789 | * them continue to work with drivers that do not need the |
| 2790 | * additional information -- drivers must check! |
| 2791 | */ |
| 2792 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2793 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2794 | params.ssid_len = |
| 2795 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2796 | if (params.ssid_len == 0 || |
| 2797 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2798 | return -EINVAL; |
| 2799 | } |
| 2800 | |
| 2801 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2802 | params.hidden_ssid = nla_get_u32( |
| 2803 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2804 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2805 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2806 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2807 | return -EINVAL; |
| 2808 | } |
| 2809 | |
| 2810 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2811 | |
| 2812 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2813 | params.auth_type = nla_get_u32( |
| 2814 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2815 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2816 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2817 | return -EINVAL; |
| 2818 | } else |
| 2819 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2820 | |
| 2821 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2822 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2823 | if (err) |
| 2824 | return err; |
| 2825 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2826 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2827 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2828 | return -EOPNOTSUPP; |
| 2829 | params.inactivity_timeout = nla_get_u16( |
| 2830 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2831 | } |
| 2832 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2833 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2834 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2835 | return -EINVAL; |
| 2836 | params.p2p_ctwindow = |
| 2837 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2838 | if (params.p2p_ctwindow > 127) |
| 2839 | return -EINVAL; |
| 2840 | if (params.p2p_ctwindow != 0 && |
| 2841 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2842 | return -EINVAL; |
| 2843 | } |
| 2844 | |
| 2845 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2846 | u8 tmp; |
| 2847 | |
| 2848 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2849 | return -EINVAL; |
| 2850 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2851 | if (tmp > 1) |
| 2852 | return -EINVAL; |
| 2853 | params.p2p_opp_ps = tmp; |
| 2854 | if (params.p2p_opp_ps != 0 && |
| 2855 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2856 | return -EINVAL; |
| 2857 | } |
| 2858 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2859 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2860 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2861 | if (err) |
| 2862 | return err; |
| 2863 | } else if (wdev->preset_chandef.chan) { |
| 2864 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2865 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2866 | return -EINVAL; |
| 2867 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2868 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2869 | return -EINVAL; |
| 2870 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2871 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 2872 | if (err < 0) |
| 2873 | return err; |
| 2874 | if (err) { |
| 2875 | radar_detect_width = BIT(params.chandef.width); |
| 2876 | params.radar_required = true; |
| 2877 | } |
| 2878 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2879 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2880 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 2881 | params.chandef.chan, |
| 2882 | CHAN_MODE_SHARED, |
| 2883 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2884 | mutex_unlock(&rdev->devlist_mtx); |
| 2885 | |
| 2886 | if (err) |
| 2887 | return err; |
| 2888 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2889 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 2890 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 2891 | if (IS_ERR(params.acl)) |
| 2892 | return PTR_ERR(params.acl); |
| 2893 | } |
| 2894 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2895 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2896 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2897 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2898 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2899 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2900 | wdev->ssid_len = params.ssid_len; |
| 2901 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2902 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2903 | |
| 2904 | kfree(params.acl); |
| 2905 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2906 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2907 | } |
| 2908 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2909 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2910 | { |
| 2911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2912 | struct net_device *dev = info->user_ptr[1]; |
| 2913 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2914 | struct cfg80211_beacon_data params; |
| 2915 | int err; |
| 2916 | |
| 2917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2918 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2919 | return -EOPNOTSUPP; |
| 2920 | |
| 2921 | if (!rdev->ops->change_beacon) |
| 2922 | return -EOPNOTSUPP; |
| 2923 | |
| 2924 | if (!wdev->beacon_interval) |
| 2925 | return -EINVAL; |
| 2926 | |
| 2927 | err = nl80211_parse_beacon(info, ¶ms); |
| 2928 | if (err) |
| 2929 | return err; |
| 2930 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2931 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | 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] | 2935 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2937 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2938 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2939 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2942 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2943 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2944 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2945 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2946 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2947 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2948 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2949 | }; |
| 2950 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2951 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2952 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2953 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2954 | { |
| 2955 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2956 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2957 | int flag; |
| 2958 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2959 | /* |
| 2960 | * Try parsing the new attribute first so userspace |
| 2961 | * can specify both for older kernels. |
| 2962 | */ |
| 2963 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2964 | if (nla) { |
| 2965 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2966 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2967 | sta_flags = nla_data(nla); |
| 2968 | params->sta_flags_mask = sta_flags->mask; |
| 2969 | params->sta_flags_set = sta_flags->set; |
| 2970 | if ((params->sta_flags_mask | |
| 2971 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2972 | return -EINVAL; |
| 2973 | return 0; |
| 2974 | } |
| 2975 | |
| 2976 | /* if present, parse the old attribute */ |
| 2977 | |
| 2978 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2979 | if (!nla) |
| 2980 | return 0; |
| 2981 | |
| 2982 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2983 | nla, sta_flags_policy)) |
| 2984 | return -EINVAL; |
| 2985 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2986 | /* |
| 2987 | * Only allow certain flags for interface types so that |
| 2988 | * other attributes are silently ignored. Remember that |
| 2989 | * this is backward compatibility code with old userspace |
| 2990 | * and shouldn't be hit in other cases anyway. |
| 2991 | */ |
| 2992 | switch (iftype) { |
| 2993 | case NL80211_IFTYPE_AP: |
| 2994 | case NL80211_IFTYPE_AP_VLAN: |
| 2995 | case NL80211_IFTYPE_P2P_GO: |
| 2996 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2997 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2998 | BIT(NL80211_STA_FLAG_WME) | |
| 2999 | BIT(NL80211_STA_FLAG_MFP); |
| 3000 | break; |
| 3001 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3002 | case NL80211_IFTYPE_STATION: |
| 3003 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3004 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3005 | break; |
| 3006 | case NL80211_IFTYPE_MESH_POINT: |
| 3007 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3008 | BIT(NL80211_STA_FLAG_MFP) | |
| 3009 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3010 | default: |
| 3011 | return -EINVAL; |
| 3012 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3013 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3014 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3015 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3016 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3017 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3018 | /* no longer support new API additions in old API */ |
| 3019 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3020 | return -EINVAL; |
| 3021 | } |
| 3022 | } |
| 3023 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3024 | return 0; |
| 3025 | } |
| 3026 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3027 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3028 | int attr) |
| 3029 | { |
| 3030 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3031 | u32 bitrate; |
| 3032 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3033 | |
| 3034 | rate = nla_nest_start(msg, attr); |
| 3035 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3036 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3037 | |
| 3038 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3039 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3040 | /* report 16-bit bitrate only if we can */ |
| 3041 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3042 | if (bitrate > 0 && |
| 3043 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3044 | return false; |
| 3045 | if (bitrate_compat > 0 && |
| 3046 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3047 | return false; |
| 3048 | |
| 3049 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3050 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3051 | return false; |
| 3052 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3053 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3054 | return false; |
| 3055 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3056 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3057 | return false; |
| 3058 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3059 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3060 | return false; |
| 3061 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3062 | return false; |
| 3063 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3064 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3065 | return false; |
| 3066 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3067 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3068 | return false; |
| 3069 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3070 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3071 | return false; |
| 3072 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3073 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3074 | return false; |
| 3075 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3076 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3077 | return false; |
| 3078 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3079 | |
| 3080 | nla_nest_end(msg, rate); |
| 3081 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3082 | } |
| 3083 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3084 | 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] | 3085 | int flags, |
| 3086 | struct cfg80211_registered_device *rdev, |
| 3087 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3088 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3089 | { |
| 3090 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3091 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3092 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3093 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3094 | if (!hdr) |
| 3095 | return -1; |
| 3096 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3097 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3098 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3099 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3100 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3101 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3102 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3103 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3104 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3105 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3106 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3107 | sinfo->connected_time)) |
| 3108 | goto nla_put_failure; |
| 3109 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3110 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3111 | sinfo->inactive_time)) |
| 3112 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3113 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3114 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3115 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3116 | (u32)sinfo->rx_bytes)) |
| 3117 | goto nla_put_failure; |
| 3118 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3119 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3120 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3121 | (u32)sinfo->tx_bytes)) |
| 3122 | goto nla_put_failure; |
| 3123 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3124 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3125 | sinfo->rx_bytes)) |
| 3126 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3127 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3128 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3129 | sinfo->tx_bytes)) |
| 3130 | goto nla_put_failure; |
| 3131 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3132 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3133 | goto nla_put_failure; |
| 3134 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3135 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3136 | goto nla_put_failure; |
| 3137 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3138 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3139 | sinfo->plink_state)) |
| 3140 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3141 | switch (rdev->wiphy.signal_type) { |
| 3142 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3143 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3144 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3145 | sinfo->signal)) |
| 3146 | goto nla_put_failure; |
| 3147 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3148 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3149 | sinfo->signal_avg)) |
| 3150 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3151 | break; |
| 3152 | default: |
| 3153 | break; |
| 3154 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3155 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3156 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3157 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3158 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3159 | } |
| 3160 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3161 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3162 | NL80211_STA_INFO_RX_BITRATE)) |
| 3163 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3164 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3165 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3166 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3167 | sinfo->rx_packets)) |
| 3168 | goto nla_put_failure; |
| 3169 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3170 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3171 | sinfo->tx_packets)) |
| 3172 | goto nla_put_failure; |
| 3173 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3174 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3175 | sinfo->tx_retries)) |
| 3176 | goto nla_put_failure; |
| 3177 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3178 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3179 | sinfo->tx_failed)) |
| 3180 | goto nla_put_failure; |
| 3181 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3182 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3183 | sinfo->beacon_loss_count)) |
| 3184 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3185 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3186 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3187 | sinfo->local_pm)) |
| 3188 | goto nla_put_failure; |
| 3189 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3190 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3191 | sinfo->peer_pm)) |
| 3192 | goto nla_put_failure; |
| 3193 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3194 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3195 | sinfo->nonpeer_pm)) |
| 3196 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3197 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3198 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3199 | if (!bss_param) |
| 3200 | goto nla_put_failure; |
| 3201 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3202 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3203 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3204 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3205 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3206 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3207 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3208 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3209 | sinfo->bss_param.dtim_period) || |
| 3210 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3211 | sinfo->bss_param.beacon_interval)) |
| 3212 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3213 | |
| 3214 | nla_nest_end(msg, bss_param); |
| 3215 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3216 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3217 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3218 | sizeof(struct nl80211_sta_flag_update), |
| 3219 | &sinfo->sta_flags)) |
| 3220 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3221 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3222 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3223 | sinfo->t_offset)) |
| 3224 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3225 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3226 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3227 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3228 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3229 | sinfo->assoc_req_ies)) |
| 3230 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3231 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3232 | return genlmsg_end(msg, hdr); |
| 3233 | |
| 3234 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3235 | genlmsg_cancel(msg, hdr); |
| 3236 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3237 | } |
| 3238 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3239 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3240 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3241 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3242 | struct station_info sinfo; |
| 3243 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3244 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3245 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3246 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3247 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3248 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3249 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3250 | if (err) |
| 3251 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3252 | |
| 3253 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3254 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3255 | goto out_err; |
| 3256 | } |
| 3257 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3258 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3259 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3260 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3261 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3262 | if (err == -ENOENT) |
| 3263 | break; |
| 3264 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3265 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3266 | |
| 3267 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3268 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3269 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3270 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3271 | &sinfo) < 0) |
| 3272 | goto out; |
| 3273 | |
| 3274 | sta_idx++; |
| 3275 | } |
| 3276 | |
| 3277 | |
| 3278 | out: |
| 3279 | cb->args[1] = sta_idx; |
| 3280 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3281 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3282 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3283 | |
| 3284 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3285 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3286 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3287 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3288 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3290 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3291 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3292 | struct sk_buff *msg; |
| 3293 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3294 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3295 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3296 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3297 | |
| 3298 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3299 | return -EINVAL; |
| 3300 | |
| 3301 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3303 | if (!rdev->ops->get_station) |
| 3304 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3305 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3306 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3307 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3308 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3309 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3310 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3311 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3312 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3313 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3314 | 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] | 3315 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3316 | nlmsg_free(msg); |
| 3317 | return -ENOBUFS; |
| 3318 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3319 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3320 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3324 | * 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] | 3325 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3326 | static struct net_device *get_vlan(struct genl_info *info, |
| 3327 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3328 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3329 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3330 | struct net_device *v; |
| 3331 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3332 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3333 | if (!vlanattr) |
| 3334 | return NULL; |
| 3335 | |
| 3336 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3337 | if (!v) |
| 3338 | return ERR_PTR(-ENODEV); |
| 3339 | |
| 3340 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3341 | ret = -EINVAL; |
| 3342 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3343 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3344 | |
| 3345 | if (!netif_running(v)) { |
| 3346 | ret = -ENETDOWN; |
| 3347 | goto error; |
| 3348 | } |
| 3349 | |
| 3350 | return v; |
| 3351 | error: |
| 3352 | dev_put(v); |
| 3353 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3354 | } |
| 3355 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3356 | static struct nla_policy |
| 3357 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3358 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3359 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3360 | }; |
| 3361 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame^] | 3362 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3363 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3364 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3365 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3366 | struct nlattr *nla; |
| 3367 | int err; |
| 3368 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3369 | /* parse WME attributes if present */ |
| 3370 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3371 | return 0; |
| 3372 | |
| 3373 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3374 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3375 | nl80211_sta_wme_policy); |
| 3376 | if (err) |
| 3377 | return err; |
| 3378 | |
| 3379 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3380 | params->uapsd_queues = nla_get_u8( |
| 3381 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3382 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3383 | return -EINVAL; |
| 3384 | |
| 3385 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3386 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3387 | |
| 3388 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3389 | return -EINVAL; |
| 3390 | |
| 3391 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3392 | |
| 3393 | return 0; |
| 3394 | } |
| 3395 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame^] | 3396 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3397 | struct station_parameters *params) |
| 3398 | { |
| 3399 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3400 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3401 | params->ht_capa = |
| 3402 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3403 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3404 | params->vht_capa = |
| 3405 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3406 | |
| 3407 | return nl80211_parse_sta_wme(info, params); |
| 3408 | } |
| 3409 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3410 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3411 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3412 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3413 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3414 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3415 | struct station_parameters params; |
| 3416 | u8 *mac_addr = NULL; |
| 3417 | |
| 3418 | memset(¶ms, 0, sizeof(params)); |
| 3419 | |
| 3420 | params.listen_interval = -1; |
| 3421 | |
| 3422 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3423 | return -EINVAL; |
| 3424 | |
| 3425 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3426 | return -EINVAL; |
| 3427 | |
| 3428 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3429 | |
| 3430 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3431 | params.supported_rates = |
| 3432 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3433 | params.supported_rates_len = |
| 3434 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3435 | } |
| 3436 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3437 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3438 | params.capability = |
| 3439 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3440 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3441 | } |
| 3442 | |
| 3443 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3444 | params.ext_capab = |
| 3445 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3446 | params.ext_capab_len = |
| 3447 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3448 | } |
| 3449 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3450 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3451 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3452 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3453 | if (!rdev->ops->change_station) |
| 3454 | return -EOPNOTSUPP; |
| 3455 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3456 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3457 | return -EINVAL; |
| 3458 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3459 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3460 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3461 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3462 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3463 | return -EINVAL; |
| 3464 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3465 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3466 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3467 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3468 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3469 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3470 | return -EINVAL; |
| 3471 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3472 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3473 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3474 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3475 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3476 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3477 | |
| 3478 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3479 | pm > NL80211_MESH_POWER_MAX) |
| 3480 | return -EINVAL; |
| 3481 | |
| 3482 | params.local_pm = pm; |
| 3483 | } |
| 3484 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3485 | switch (dev->ieee80211_ptr->iftype) { |
| 3486 | case NL80211_IFTYPE_AP: |
| 3487 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3488 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3489 | /* disallow mesh-specific things */ |
| 3490 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3491 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3492 | if (params.local_pm) |
| 3493 | return -EINVAL; |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3494 | if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3495 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3496 | |
| 3497 | /* TDLS can't be set, ... */ |
| 3498 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3499 | return -EINVAL; |
| 3500 | /* |
| 3501 | * ... but don't bother the driver with it. This works around |
| 3502 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3503 | * TLDS_PEER flag in the mask even for AP mode. |
| 3504 | */ |
| 3505 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3506 | |
| 3507 | /* accept only the listed bits */ |
| 3508 | if (params.sta_flags_mask & |
| 3509 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3510 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3511 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3512 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3513 | BIT(NL80211_STA_FLAG_WME) | |
| 3514 | BIT(NL80211_STA_FLAG_MFP))) |
| 3515 | return -EINVAL; |
| 3516 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3517 | /* but authenticated/associated only if driver handles it */ |
| 3518 | if (!(rdev->wiphy.features & |
| 3519 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3520 | params.sta_flags_mask & |
| 3521 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3522 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3523 | return -EINVAL; |
| 3524 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3525 | /* reject other things that can't change */ |
| 3526 | if (params.supported_rates) |
| 3527 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3528 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3529 | return -EINVAL; |
| 3530 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3531 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3532 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3533 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3534 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3535 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3536 | /* must be last in here for error handling */ |
| 3537 | params.vlan = get_vlan(info, rdev); |
| 3538 | if (IS_ERR(params.vlan)) |
| 3539 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3540 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3541 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3542 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3543 | /* |
| 3544 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3545 | * but silently ignore attempts to change it since we |
| 3546 | * don't have state here to verify that it doesn't try |
| 3547 | * to change the flag. |
| 3548 | */ |
| 3549 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3550 | /* Include parameters for TDLS peer (driver will check) */ |
| 3551 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3552 | if (err) |
| 3553 | return err; |
| 3554 | /* disallow things sta doesn't support */ |
| 3555 | if (params.plink_action) |
| 3556 | return -EINVAL; |
| 3557 | if (params.local_pm) |
| 3558 | return -EINVAL; |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3559 | if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3560 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3561 | /* reject any changes other than AUTHORIZED or WME (for TDLS) */ |
| 3562 | if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3563 | BIT(NL80211_STA_FLAG_WME))) |
| 3564 | return -EINVAL; |
| 3565 | break; |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3566 | case NL80211_IFTYPE_ADHOC: |
| 3567 | /* disallow things sta doesn't support */ |
| 3568 | if (params.plink_action) |
| 3569 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3570 | if (params.local_pm) |
| 3571 | return -EINVAL; |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3572 | if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3573 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3574 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3575 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3576 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3577 | /* reject any changes other than AUTHORIZED */ |
| 3578 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3579 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3580 | break; |
| 3581 | case NL80211_IFTYPE_MESH_POINT: |
| 3582 | /* disallow things mesh doesn't support */ |
| 3583 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3584 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3585 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3586 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3587 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3588 | return -EINVAL; |
| 3589 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3590 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3591 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3592 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3593 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3594 | /* |
| 3595 | * No special handling for TDLS here -- the userspace |
| 3596 | * mesh code doesn't have this bug. |
| 3597 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3598 | if (params.sta_flags_mask & |
| 3599 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3600 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3601 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3602 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3603 | break; |
| 3604 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3605 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3606 | } |
| 3607 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3608 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3609 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3610 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3611 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3612 | if (params.vlan) |
| 3613 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3614 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3615 | return err; |
| 3616 | } |
| 3617 | |
| 3618 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3619 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3621 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3622 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3623 | struct station_parameters params; |
| 3624 | u8 *mac_addr = NULL; |
| 3625 | |
| 3626 | memset(¶ms, 0, sizeof(params)); |
| 3627 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3628 | if (!rdev->ops->add_station) |
| 3629 | return -EOPNOTSUPP; |
| 3630 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3631 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3632 | return -EINVAL; |
| 3633 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3634 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3635 | return -EINVAL; |
| 3636 | |
| 3637 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3638 | return -EINVAL; |
| 3639 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3640 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3641 | return -EINVAL; |
| 3642 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3643 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3644 | params.supported_rates = |
| 3645 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3646 | params.supported_rates_len = |
| 3647 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3648 | params.listen_interval = |
| 3649 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3650 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3651 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3652 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3653 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3654 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3655 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3656 | params.capability = |
| 3657 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3658 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3659 | } |
| 3660 | |
| 3661 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3662 | params.ext_capab = |
| 3663 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3664 | params.ext_capab_len = |
| 3665 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3666 | } |
| 3667 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3668 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3669 | params.ht_capa = |
| 3670 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3671 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3672 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3673 | params.vht_capa = |
| 3674 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3675 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3676 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3677 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3678 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3679 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3680 | return -EINVAL; |
| 3681 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3682 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame^] | 3683 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 3684 | if (err) |
| 3685 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3686 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3687 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3688 | return -EINVAL; |
| 3689 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3690 | switch (dev->ieee80211_ptr->iftype) { |
| 3691 | case NL80211_IFTYPE_AP: |
| 3692 | case NL80211_IFTYPE_AP_VLAN: |
| 3693 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3694 | /* ignore WME attributes if iface/sta is not capable */ |
| 3695 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 3696 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 3697 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3698 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3699 | /* TDLS peers cannot be added */ |
| 3700 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3701 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3702 | /* but don't bother the driver with it */ |
| 3703 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3704 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3705 | /* allow authenticated/associated only if driver handles it */ |
| 3706 | if (!(rdev->wiphy.features & |
| 3707 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3708 | params.sta_flags_mask & |
| 3709 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3710 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3711 | return -EINVAL; |
| 3712 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3713 | /* must be last in here for error handling */ |
| 3714 | params.vlan = get_vlan(info, rdev); |
| 3715 | if (IS_ERR(params.vlan)) |
| 3716 | return PTR_ERR(params.vlan); |
| 3717 | break; |
| 3718 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3719 | /* ignore uAPSD data */ |
| 3720 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 3721 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3722 | /* associated is disallowed */ |
| 3723 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3724 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3725 | /* TDLS peers cannot be added */ |
| 3726 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3727 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3728 | break; |
| 3729 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3730 | /* ignore uAPSD data */ |
| 3731 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 3732 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3733 | /* associated is disallowed */ |
| 3734 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3735 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3736 | /* Only TDLS peers can be added */ |
| 3737 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3738 | return -EINVAL; |
| 3739 | /* Can only add if TDLS ... */ |
| 3740 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3741 | return -EOPNOTSUPP; |
| 3742 | /* ... with external setup is supported */ |
| 3743 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3744 | return -EOPNOTSUPP; |
| 3745 | break; |
| 3746 | default: |
| 3747 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3748 | } |
| 3749 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3750 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3751 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3752 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3753 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3754 | if (params.vlan) |
| 3755 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3756 | return err; |
| 3757 | } |
| 3758 | |
| 3759 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3760 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3761 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3762 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3763 | u8 *mac_addr = NULL; |
| 3764 | |
| 3765 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3766 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3767 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3768 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3770 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3772 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3774 | if (!rdev->ops->del_station) |
| 3775 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3776 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3777 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3778 | } |
| 3779 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3780 | 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] | 3781 | int flags, struct net_device *dev, |
| 3782 | u8 *dst, u8 *next_hop, |
| 3783 | struct mpath_info *pinfo) |
| 3784 | { |
| 3785 | void *hdr; |
| 3786 | struct nlattr *pinfoattr; |
| 3787 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3788 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3789 | if (!hdr) |
| 3790 | return -1; |
| 3791 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3792 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3794 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3795 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3796 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3797 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3798 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3799 | if (!pinfoattr) |
| 3800 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3801 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3802 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3803 | pinfo->frame_qlen)) |
| 3804 | goto nla_put_failure; |
| 3805 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3806 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3807 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3808 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3809 | pinfo->metric)) || |
| 3810 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3811 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3812 | pinfo->exptime)) || |
| 3813 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3814 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3815 | pinfo->flags)) || |
| 3816 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3817 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3818 | pinfo->discovery_timeout)) || |
| 3819 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3820 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3821 | pinfo->discovery_retries))) |
| 3822 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3823 | |
| 3824 | nla_nest_end(msg, pinfoattr); |
| 3825 | |
| 3826 | return genlmsg_end(msg, hdr); |
| 3827 | |
| 3828 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3829 | genlmsg_cancel(msg, hdr); |
| 3830 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3834 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3835 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3836 | struct mpath_info pinfo; |
| 3837 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3838 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3839 | u8 dst[ETH_ALEN]; |
| 3840 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3841 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3842 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3843 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3844 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3845 | if (err) |
| 3846 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3847 | |
| 3848 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3849 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3850 | goto out_err; |
| 3851 | } |
| 3852 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3853 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3854 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3855 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3856 | } |
| 3857 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3858 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3859 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3860 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3861 | if (err == -ENOENT) |
| 3862 | break; |
| 3863 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3864 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3865 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3866 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3867 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3868 | netdev, dst, next_hop, |
| 3869 | &pinfo) < 0) |
| 3870 | goto out; |
| 3871 | |
| 3872 | path_idx++; |
| 3873 | } |
| 3874 | |
| 3875 | |
| 3876 | out: |
| 3877 | cb->args[1] = path_idx; |
| 3878 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3879 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3880 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3881 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3885 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3887 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3888 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3889 | struct mpath_info pinfo; |
| 3890 | struct sk_buff *msg; |
| 3891 | u8 *dst = NULL; |
| 3892 | u8 next_hop[ETH_ALEN]; |
| 3893 | |
| 3894 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3895 | |
| 3896 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3897 | return -EINVAL; |
| 3898 | |
| 3899 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3900 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3901 | if (!rdev->ops->get_mpath) |
| 3902 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3903 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3904 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3905 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3906 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3907 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3908 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3909 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3910 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3911 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3912 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3913 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3914 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3915 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3916 | dev, dst, next_hop, &pinfo) < 0) { |
| 3917 | nlmsg_free(msg); |
| 3918 | return -ENOBUFS; |
| 3919 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3921 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3925 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3926 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3927 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3928 | u8 *dst = NULL; |
| 3929 | u8 *next_hop = NULL; |
| 3930 | |
| 3931 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3932 | return -EINVAL; |
| 3933 | |
| 3934 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3935 | return -EINVAL; |
| 3936 | |
| 3937 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3938 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3939 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3940 | if (!rdev->ops->change_mpath) |
| 3941 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3942 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3943 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3944 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3945 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3946 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3947 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3948 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3949 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3950 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3952 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3953 | u8 *dst = NULL; |
| 3954 | u8 *next_hop = NULL; |
| 3955 | |
| 3956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3957 | return -EINVAL; |
| 3958 | |
| 3959 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3960 | return -EINVAL; |
| 3961 | |
| 3962 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3963 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3964 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3965 | if (!rdev->ops->add_mpath) |
| 3966 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3967 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3968 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3969 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3970 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3971 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3975 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3977 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3978 | u8 *dst = NULL; |
| 3979 | |
| 3980 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3981 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3982 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3983 | if (!rdev->ops->del_mpath) |
| 3984 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3985 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3986 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3987 | } |
| 3988 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3989 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3990 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3991 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3992 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3993 | struct bss_parameters params; |
| 3994 | |
| 3995 | memset(¶ms, 0, sizeof(params)); |
| 3996 | /* default to not changing parameters */ |
| 3997 | params.use_cts_prot = -1; |
| 3998 | params.use_short_preamble = -1; |
| 3999 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4000 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4001 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4002 | params.p2p_ctwindow = -1; |
| 4003 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4004 | |
| 4005 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4006 | params.use_cts_prot = |
| 4007 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4008 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4009 | params.use_short_preamble = |
| 4010 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4011 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4012 | params.use_short_slot_time = |
| 4013 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4014 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4015 | params.basic_rates = |
| 4016 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4017 | params.basic_rates_len = |
| 4018 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4019 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4020 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4021 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4022 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4023 | params.ht_opmode = |
| 4024 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4025 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4026 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4027 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4028 | return -EINVAL; |
| 4029 | params.p2p_ctwindow = |
| 4030 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4031 | if (params.p2p_ctwindow < 0) |
| 4032 | return -EINVAL; |
| 4033 | if (params.p2p_ctwindow != 0 && |
| 4034 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4035 | return -EINVAL; |
| 4036 | } |
| 4037 | |
| 4038 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4039 | u8 tmp; |
| 4040 | |
| 4041 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4042 | return -EINVAL; |
| 4043 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4044 | if (tmp > 1) |
| 4045 | return -EINVAL; |
| 4046 | params.p2p_opp_ps = tmp; |
| 4047 | if (params.p2p_opp_ps && |
| 4048 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4049 | return -EINVAL; |
| 4050 | } |
| 4051 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4052 | if (!rdev->ops->change_bss) |
| 4053 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4054 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4055 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4056 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4057 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4058 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4059 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4060 | } |
| 4061 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4062 | 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] | 4063 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4064 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4065 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4066 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4067 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4068 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4069 | }; |
| 4070 | |
| 4071 | static int parse_reg_rule(struct nlattr *tb[], |
| 4072 | struct ieee80211_reg_rule *reg_rule) |
| 4073 | { |
| 4074 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4075 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4076 | |
| 4077 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4078 | return -EINVAL; |
| 4079 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4080 | return -EINVAL; |
| 4081 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4082 | return -EINVAL; |
| 4083 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4084 | return -EINVAL; |
| 4085 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4086 | return -EINVAL; |
| 4087 | |
| 4088 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4089 | |
| 4090 | freq_range->start_freq_khz = |
| 4091 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4092 | freq_range->end_freq_khz = |
| 4093 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4094 | freq_range->max_bandwidth_khz = |
| 4095 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4096 | |
| 4097 | power_rule->max_eirp = |
| 4098 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4099 | |
| 4100 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4101 | power_rule->max_antenna_gain = |
| 4102 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4103 | |
| 4104 | return 0; |
| 4105 | } |
| 4106 | |
| 4107 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4108 | { |
| 4109 | int r; |
| 4110 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4111 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4112 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4113 | /* |
| 4114 | * You should only get this when cfg80211 hasn't yet initialized |
| 4115 | * completely when built-in to the kernel right between the time |
| 4116 | * window between nl80211_init() and regulatory_init(), if that is |
| 4117 | * even possible. |
| 4118 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4119 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4120 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4121 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4122 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4123 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4124 | |
| 4125 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4126 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4127 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4128 | user_reg_hint_type = |
| 4129 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4130 | else |
| 4131 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4132 | |
| 4133 | switch (user_reg_hint_type) { |
| 4134 | case NL80211_USER_REG_HINT_USER: |
| 4135 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4136 | break; |
| 4137 | default: |
| 4138 | return -EINVAL; |
| 4139 | } |
| 4140 | |
| 4141 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4142 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4143 | return r; |
| 4144 | } |
| 4145 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4146 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4147 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4150 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4151 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4152 | struct mesh_config cur_params; |
| 4153 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4154 | void *hdr; |
| 4155 | struct nlattr *pinfoattr; |
| 4156 | struct sk_buff *msg; |
| 4157 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4158 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4159 | return -EOPNOTSUPP; |
| 4160 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4161 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4162 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4163 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4164 | wdev_lock(wdev); |
| 4165 | /* If not connected, get default parameters */ |
| 4166 | if (!wdev->mesh_id_len) |
| 4167 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4168 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4169 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4170 | wdev_unlock(wdev); |
| 4171 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4172 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4173 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4174 | |
| 4175 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4176 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4177 | if (!msg) |
| 4178 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4179 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4180 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4181 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4182 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4183 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4184 | if (!pinfoattr) |
| 4185 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4186 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4187 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4188 | cur_params.dot11MeshRetryTimeout) || |
| 4189 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4190 | cur_params.dot11MeshConfirmTimeout) || |
| 4191 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4192 | cur_params.dot11MeshHoldingTimeout) || |
| 4193 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4194 | cur_params.dot11MeshMaxPeerLinks) || |
| 4195 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4196 | cur_params.dot11MeshMaxRetries) || |
| 4197 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4198 | cur_params.dot11MeshTTL) || |
| 4199 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4200 | cur_params.element_ttl) || |
| 4201 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4202 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4203 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4204 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4205 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4206 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4207 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4208 | cur_params.path_refresh_time) || |
| 4209 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4210 | cur_params.min_discovery_timeout) || |
| 4211 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4212 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4213 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4214 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4215 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4216 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4217 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4218 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4219 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4220 | cur_params.dot11MeshHWMPRootMode) || |
| 4221 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4222 | cur_params.dot11MeshHWMPRannInterval) || |
| 4223 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4224 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4225 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4226 | cur_params.dot11MeshForwarding) || |
| 4227 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4228 | cur_params.rssi_threshold) || |
| 4229 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4230 | cur_params.ht_opmode) || |
| 4231 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4232 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4233 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4234 | cur_params.dot11MeshHWMProotInterval) || |
| 4235 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4236 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4237 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4238 | cur_params.power_mode) || |
| 4239 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4240 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4241 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4242 | nla_nest_end(msg, pinfoattr); |
| 4243 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4245 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4246 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4247 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4248 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4249 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4250 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4253 | 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] | 4254 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4255 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4256 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4257 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4258 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4259 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4260 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4261 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4262 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4263 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4264 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4265 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4266 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4267 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4268 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4269 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4270 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4271 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4272 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4273 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4274 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4275 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4276 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4277 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4278 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4279 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4280 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4281 | }; |
| 4282 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4283 | static const struct nla_policy |
| 4284 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4285 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4286 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4287 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4288 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4289 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4290 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4291 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4292 | }; |
| 4293 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4294 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4295 | struct mesh_config *cfg, |
| 4296 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4297 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4298 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4299 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4300 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4301 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4302 | do { \ |
| 4303 | if (tb[attr]) { \ |
| 4304 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4305 | return -EINVAL; \ |
| 4306 | cfg->param = fn(tb[attr]); \ |
| 4307 | mask |= (1 << (attr - 1)); \ |
| 4308 | } \ |
| 4309 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4310 | |
| 4311 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4312 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4313 | return -EINVAL; |
| 4314 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4315 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4316 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4317 | return -EINVAL; |
| 4318 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4319 | /* This makes sure that there aren't more than 32 mesh config |
| 4320 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4321 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4322 | |
| 4323 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4324 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4325 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4326 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4327 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4328 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4329 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4330 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4331 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4332 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4333 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4334 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4335 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4336 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4337 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4338 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4339 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4340 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4341 | 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] | 4342 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4343 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4344 | 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] | 4345 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4346 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4348 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4349 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4350 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4351 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4352 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4353 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4354 | 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] | 4355 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4356 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4357 | 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] | 4358 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4359 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4360 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4361 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4362 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4363 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4364 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4365 | 1, 65535, mask, |
| 4366 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4367 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4368 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4369 | 1, 65535, mask, |
| 4370 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4371 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4372 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4373 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4374 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4375 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4376 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4377 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4378 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4379 | nla_get_u8); |
| 4380 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4381 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4382 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4383 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4384 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4385 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4386 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4387 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4388 | mask, NL80211_MESHCONF_FORWARDING, |
| 4389 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4390 | 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] | 4391 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4392 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4393 | 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] | 4394 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4395 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4396 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4397 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4398 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4399 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4400 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4401 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4402 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4403 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4404 | dot11MeshHWMPconfirmationInterval, |
| 4405 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4406 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4407 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4408 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4409 | NL80211_MESH_POWER_ACTIVE, |
| 4410 | NL80211_MESH_POWER_MAX, |
| 4411 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4412 | nla_get_u32); |
| 4413 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4414 | 0, 65535, mask, |
| 4415 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4416 | if (mask_out) |
| 4417 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4418 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4419 | return 0; |
| 4420 | |
| 4421 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4422 | } |
| 4423 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4424 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4425 | struct mesh_setup *setup) |
| 4426 | { |
| 4427 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4428 | |
| 4429 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4430 | return -EINVAL; |
| 4431 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4432 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4433 | nl80211_mesh_setup_params_policy)) |
| 4434 | return -EINVAL; |
| 4435 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4436 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4437 | setup->sync_method = |
| 4438 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4439 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4440 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4441 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4442 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4443 | setup->path_sel_proto = |
| 4444 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4445 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4446 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4447 | |
| 4448 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4449 | setup->path_metric = |
| 4450 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4451 | IEEE80211_PATH_METRIC_VENDOR : |
| 4452 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4453 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4454 | |
| 4455 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4456 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4457 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4458 | if (!is_valid_ie_attr(ieattr)) |
| 4459 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4460 | setup->ie = nla_data(ieattr); |
| 4461 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4462 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4463 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4464 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4465 | |
| 4466 | return 0; |
| 4467 | } |
| 4468 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4469 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4470 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4471 | { |
| 4472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4473 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4474 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4475 | struct mesh_config cfg; |
| 4476 | u32 mask; |
| 4477 | int err; |
| 4478 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4479 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4480 | return -EOPNOTSUPP; |
| 4481 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4482 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4483 | return -EOPNOTSUPP; |
| 4484 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4485 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4486 | if (err) |
| 4487 | return err; |
| 4488 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4489 | wdev_lock(wdev); |
| 4490 | if (!wdev->mesh_id_len) |
| 4491 | err = -ENOLINK; |
| 4492 | |
| 4493 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4494 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4495 | |
| 4496 | wdev_unlock(wdev); |
| 4497 | |
| 4498 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4501 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4502 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4503 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4504 | struct sk_buff *msg; |
| 4505 | void *hdr = NULL; |
| 4506 | struct nlattr *nl_reg_rules; |
| 4507 | unsigned int i; |
| 4508 | int err = -EINVAL; |
| 4509 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4510 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4511 | |
| 4512 | if (!cfg80211_regdomain) |
| 4513 | goto out; |
| 4514 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4515 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4516 | if (!msg) { |
| 4517 | err = -ENOBUFS; |
| 4518 | goto out; |
| 4519 | } |
| 4520 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4521 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4522 | NL80211_CMD_GET_REG); |
| 4523 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4524 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4525 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4526 | if (reg_last_request_cell_base() && |
| 4527 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4528 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4529 | goto nla_put_failure; |
| 4530 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4531 | rcu_read_lock(); |
| 4532 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4533 | |
| 4534 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4535 | (regdom->dfs_region && |
| 4536 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4537 | goto nla_put_failure_rcu; |
| 4538 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4539 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4540 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4541 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4542 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4543 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4544 | struct nlattr *nl_reg_rule; |
| 4545 | const struct ieee80211_reg_rule *reg_rule; |
| 4546 | const struct ieee80211_freq_range *freq_range; |
| 4547 | const struct ieee80211_power_rule *power_rule; |
| 4548 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4549 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4550 | freq_range = ®_rule->freq_range; |
| 4551 | power_rule = ®_rule->power_rule; |
| 4552 | |
| 4553 | nl_reg_rule = nla_nest_start(msg, i); |
| 4554 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4555 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4556 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4557 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4558 | reg_rule->flags) || |
| 4559 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4560 | freq_range->start_freq_khz) || |
| 4561 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4562 | freq_range->end_freq_khz) || |
| 4563 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4564 | freq_range->max_bandwidth_khz) || |
| 4565 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4566 | power_rule->max_antenna_gain) || |
| 4567 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4568 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4569 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4570 | |
| 4571 | nla_nest_end(msg, nl_reg_rule); |
| 4572 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4573 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4574 | |
| 4575 | nla_nest_end(msg, nl_reg_rules); |
| 4576 | |
| 4577 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4578 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4579 | goto out; |
| 4580 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4581 | nla_put_failure_rcu: |
| 4582 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4583 | nla_put_failure: |
| 4584 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4585 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4586 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4587 | err = -EMSGSIZE; |
| 4588 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4589 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4590 | return err; |
| 4591 | } |
| 4592 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4593 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4594 | { |
| 4595 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4596 | struct nlattr *nl_reg_rule; |
| 4597 | char *alpha2 = NULL; |
| 4598 | int rem_reg_rules = 0, r = 0; |
| 4599 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4600 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4601 | struct ieee80211_regdomain *rd = NULL; |
| 4602 | |
| 4603 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4604 | return -EINVAL; |
| 4605 | |
| 4606 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4607 | return -EINVAL; |
| 4608 | |
| 4609 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4610 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4611 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4612 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4613 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4614 | 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] | 4615 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4616 | num_rules++; |
| 4617 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4618 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4619 | } |
| 4620 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4621 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4622 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4623 | |
| 4624 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4625 | if (!rd) |
| 4626 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4627 | |
| 4628 | rd->n_reg_rules = num_rules; |
| 4629 | rd->alpha2[0] = alpha2[0]; |
| 4630 | rd->alpha2[1] = alpha2[1]; |
| 4631 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4632 | /* |
| 4633 | * Disable DFS master mode if the DFS region was |
| 4634 | * not supported or known on this kernel. |
| 4635 | */ |
| 4636 | if (reg_supported_dfs_region(dfs_region)) |
| 4637 | rd->dfs_region = dfs_region; |
| 4638 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4639 | 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] | 4640 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4641 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4642 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4643 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4644 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4645 | if (r) |
| 4646 | goto bad_reg; |
| 4647 | |
| 4648 | rule_idx++; |
| 4649 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4650 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4651 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4652 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4653 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4656 | mutex_lock(&cfg80211_mutex); |
| 4657 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4658 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4659 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4660 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4661 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4662 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4663 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4664 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4665 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4668 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4669 | { |
| 4670 | struct nlattr *attr1, *attr2; |
| 4671 | int n_channels = 0, tmp1, tmp2; |
| 4672 | |
| 4673 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4674 | n_channels++; |
| 4675 | /* |
| 4676 | * Some hardware has a limited channel list for |
| 4677 | * scanning, and it is pretty much nonsensical |
| 4678 | * to scan for a channel twice, so disallow that |
| 4679 | * and don't require drivers to check that the |
| 4680 | * channel list they get isn't longer than what |
| 4681 | * they can scan, as long as they can scan all |
| 4682 | * the channels they registered at once. |
| 4683 | */ |
| 4684 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4685 | if (attr1 != attr2 && |
| 4686 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4687 | return 0; |
| 4688 | } |
| 4689 | |
| 4690 | return n_channels; |
| 4691 | } |
| 4692 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4693 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4694 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4696 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4697 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4698 | struct nlattr *attr; |
| 4699 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4700 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4701 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4702 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4703 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4704 | return -EINVAL; |
| 4705 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4706 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4708 | if (!rdev->ops->scan) |
| 4709 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4710 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4711 | if (rdev->scan_req) |
| 4712 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4713 | |
| 4714 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4715 | n_channels = validate_scan_freqs( |
| 4716 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4717 | if (!n_channels) |
| 4718 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4719 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4720 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4721 | n_channels = 0; |
| 4722 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4723 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4724 | if (wiphy->bands[band]) |
| 4725 | n_channels += wiphy->bands[band]->n_channels; |
| 4726 | } |
| 4727 | |
| 4728 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4729 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4730 | n_ssids++; |
| 4731 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4732 | if (n_ssids > wiphy->max_scan_ssids) |
| 4733 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4734 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4735 | if (info->attrs[NL80211_ATTR_IE]) |
| 4736 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4737 | else |
| 4738 | ie_len = 0; |
| 4739 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4740 | if (ie_len > wiphy->max_scan_ie_len) |
| 4741 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4742 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4743 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4744 | + sizeof(*request->ssids) * n_ssids |
| 4745 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4746 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4747 | if (!request) |
| 4748 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4749 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4750 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4751 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4752 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4753 | if (ie_len) { |
| 4754 | if (request->ssids) |
| 4755 | request->ie = (void *)(request->ssids + n_ssids); |
| 4756 | else |
| 4757 | request->ie = (void *)(request->channels + n_channels); |
| 4758 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4759 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4760 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4761 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4762 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4763 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4764 | struct ieee80211_channel *chan; |
| 4765 | |
| 4766 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4767 | |
| 4768 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4769 | err = -EINVAL; |
| 4770 | goto out_free; |
| 4771 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4772 | |
| 4773 | /* ignore disabled channels */ |
| 4774 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4775 | continue; |
| 4776 | |
| 4777 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4778 | i++; |
| 4779 | } |
| 4780 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4781 | enum ieee80211_band band; |
| 4782 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4783 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4784 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4785 | int j; |
| 4786 | if (!wiphy->bands[band]) |
| 4787 | continue; |
| 4788 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4789 | struct ieee80211_channel *chan; |
| 4790 | |
| 4791 | chan = &wiphy->bands[band]->channels[j]; |
| 4792 | |
| 4793 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4794 | continue; |
| 4795 | |
| 4796 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4797 | i++; |
| 4798 | } |
| 4799 | } |
| 4800 | } |
| 4801 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4802 | if (!i) { |
| 4803 | err = -EINVAL; |
| 4804 | goto out_free; |
| 4805 | } |
| 4806 | |
| 4807 | request->n_channels = i; |
| 4808 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4809 | i = 0; |
| 4810 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4811 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4812 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4813 | err = -EINVAL; |
| 4814 | goto out_free; |
| 4815 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4816 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4817 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4818 | i++; |
| 4819 | } |
| 4820 | } |
| 4821 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4822 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4823 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4824 | memcpy((void *)request->ie, |
| 4825 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4826 | request->ie_len); |
| 4827 | } |
| 4828 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4829 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4830 | if (wiphy->bands[i]) |
| 4831 | request->rates[i] = |
| 4832 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4833 | |
| 4834 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4835 | nla_for_each_nested(attr, |
| 4836 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4837 | tmp) { |
| 4838 | enum ieee80211_band band = nla_type(attr); |
| 4839 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4840 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4841 | err = -EINVAL; |
| 4842 | goto out_free; |
| 4843 | } |
| 4844 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4845 | nla_data(attr), |
| 4846 | nla_len(attr), |
| 4847 | &request->rates[band]); |
| 4848 | if (err) |
| 4849 | goto out_free; |
| 4850 | } |
| 4851 | } |
| 4852 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4853 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4854 | request->flags = nla_get_u32( |
| 4855 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4856 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4857 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4858 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4859 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4860 | err = -EOPNOTSUPP; |
| 4861 | goto out_free; |
| 4862 | } |
| 4863 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4864 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4865 | request->no_cck = |
| 4866 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4867 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4868 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4869 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4870 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4871 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4872 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4873 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4874 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4875 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4876 | nl80211_send_scan_start(rdev, wdev); |
| 4877 | if (wdev->netdev) |
| 4878 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4879 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4880 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4881 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4882 | kfree(request); |
| 4883 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4884 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4885 | return err; |
| 4886 | } |
| 4887 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4888 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4889 | struct genl_info *info) |
| 4890 | { |
| 4891 | struct cfg80211_sched_scan_request *request; |
| 4892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4893 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4894 | struct nlattr *attr; |
| 4895 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4896 | 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] | 4897 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4898 | enum ieee80211_band band; |
| 4899 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4900 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4901 | |
| 4902 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4903 | !rdev->ops->sched_scan_start) |
| 4904 | return -EOPNOTSUPP; |
| 4905 | |
| 4906 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4907 | return -EINVAL; |
| 4908 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4909 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4910 | return -EINVAL; |
| 4911 | |
| 4912 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4913 | if (interval == 0) |
| 4914 | return -EINVAL; |
| 4915 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4916 | wiphy = &rdev->wiphy; |
| 4917 | |
| 4918 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4919 | n_channels = validate_scan_freqs( |
| 4920 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4921 | if (!n_channels) |
| 4922 | return -EINVAL; |
| 4923 | } else { |
| 4924 | n_channels = 0; |
| 4925 | |
| 4926 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4927 | if (wiphy->bands[band]) |
| 4928 | n_channels += wiphy->bands[band]->n_channels; |
| 4929 | } |
| 4930 | |
| 4931 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4932 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4933 | tmp) |
| 4934 | n_ssids++; |
| 4935 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4936 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4937 | return -EINVAL; |
| 4938 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4939 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4940 | nla_for_each_nested(attr, |
| 4941 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4942 | tmp) |
| 4943 | n_match_sets++; |
| 4944 | |
| 4945 | if (n_match_sets > wiphy->max_match_sets) |
| 4946 | return -EINVAL; |
| 4947 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4948 | if (info->attrs[NL80211_ATTR_IE]) |
| 4949 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4950 | else |
| 4951 | ie_len = 0; |
| 4952 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4953 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4954 | return -EINVAL; |
| 4955 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4956 | mutex_lock(&rdev->sched_scan_mtx); |
| 4957 | |
| 4958 | if (rdev->sched_scan_req) { |
| 4959 | err = -EINPROGRESS; |
| 4960 | goto out; |
| 4961 | } |
| 4962 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4963 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4964 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4965 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4966 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4967 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4968 | if (!request) { |
| 4969 | err = -ENOMEM; |
| 4970 | goto out; |
| 4971 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4972 | |
| 4973 | if (n_ssids) |
| 4974 | request->ssids = (void *)&request->channels[n_channels]; |
| 4975 | request->n_ssids = n_ssids; |
| 4976 | if (ie_len) { |
| 4977 | if (request->ssids) |
| 4978 | request->ie = (void *)(request->ssids + n_ssids); |
| 4979 | else |
| 4980 | request->ie = (void *)(request->channels + n_channels); |
| 4981 | } |
| 4982 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4983 | if (n_match_sets) { |
| 4984 | if (request->ie) |
| 4985 | request->match_sets = (void *)(request->ie + ie_len); |
| 4986 | else if (request->ssids) |
| 4987 | request->match_sets = |
| 4988 | (void *)(request->ssids + n_ssids); |
| 4989 | else |
| 4990 | request->match_sets = |
| 4991 | (void *)(request->channels + n_channels); |
| 4992 | } |
| 4993 | request->n_match_sets = n_match_sets; |
| 4994 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4995 | i = 0; |
| 4996 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4997 | /* user specified, bail out if channel not found */ |
| 4998 | nla_for_each_nested(attr, |
| 4999 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5000 | tmp) { |
| 5001 | struct ieee80211_channel *chan; |
| 5002 | |
| 5003 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5004 | |
| 5005 | if (!chan) { |
| 5006 | err = -EINVAL; |
| 5007 | goto out_free; |
| 5008 | } |
| 5009 | |
| 5010 | /* ignore disabled channels */ |
| 5011 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5012 | continue; |
| 5013 | |
| 5014 | request->channels[i] = chan; |
| 5015 | i++; |
| 5016 | } |
| 5017 | } else { |
| 5018 | /* all channels */ |
| 5019 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5020 | int j; |
| 5021 | if (!wiphy->bands[band]) |
| 5022 | continue; |
| 5023 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5024 | struct ieee80211_channel *chan; |
| 5025 | |
| 5026 | chan = &wiphy->bands[band]->channels[j]; |
| 5027 | |
| 5028 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5029 | continue; |
| 5030 | |
| 5031 | request->channels[i] = chan; |
| 5032 | i++; |
| 5033 | } |
| 5034 | } |
| 5035 | } |
| 5036 | |
| 5037 | if (!i) { |
| 5038 | err = -EINVAL; |
| 5039 | goto out_free; |
| 5040 | } |
| 5041 | |
| 5042 | request->n_channels = i; |
| 5043 | |
| 5044 | i = 0; |
| 5045 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5046 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5047 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5048 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5049 | err = -EINVAL; |
| 5050 | goto out_free; |
| 5051 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5052 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5053 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5054 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5055 | i++; |
| 5056 | } |
| 5057 | } |
| 5058 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5059 | i = 0; |
| 5060 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5061 | nla_for_each_nested(attr, |
| 5062 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5063 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5064 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5065 | |
| 5066 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5067 | nla_data(attr), nla_len(attr), |
| 5068 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5069 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5070 | if (ssid) { |
| 5071 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5072 | err = -EINVAL; |
| 5073 | goto out_free; |
| 5074 | } |
| 5075 | memcpy(request->match_sets[i].ssid.ssid, |
| 5076 | nla_data(ssid), nla_len(ssid)); |
| 5077 | request->match_sets[i].ssid.ssid_len = |
| 5078 | nla_len(ssid); |
| 5079 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5080 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5081 | if (rssi) |
| 5082 | request->rssi_thold = nla_get_u32(rssi); |
| 5083 | else |
| 5084 | request->rssi_thold = |
| 5085 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5086 | i++; |
| 5087 | } |
| 5088 | } |
| 5089 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5090 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5091 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5092 | memcpy((void *)request->ie, |
| 5093 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5094 | request->ie_len); |
| 5095 | } |
| 5096 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5097 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5098 | request->flags = nla_get_u32( |
| 5099 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5100 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5101 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5102 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5103 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5104 | err = -EOPNOTSUPP; |
| 5105 | goto out_free; |
| 5106 | } |
| 5107 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5108 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5109 | request->dev = dev; |
| 5110 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5111 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5112 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5113 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5114 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5115 | if (!err) { |
| 5116 | rdev->sched_scan_req = request; |
| 5117 | nl80211_send_sched_scan(rdev, dev, |
| 5118 | NL80211_CMD_START_SCHED_SCAN); |
| 5119 | goto out; |
| 5120 | } |
| 5121 | |
| 5122 | out_free: |
| 5123 | kfree(request); |
| 5124 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5125 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5126 | return err; |
| 5127 | } |
| 5128 | |
| 5129 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5130 | struct genl_info *info) |
| 5131 | { |
| 5132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5133 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5134 | |
| 5135 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5136 | !rdev->ops->sched_scan_stop) |
| 5137 | return -EOPNOTSUPP; |
| 5138 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5139 | mutex_lock(&rdev->sched_scan_mtx); |
| 5140 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5141 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5142 | |
| 5143 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5144 | } |
| 5145 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5146 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5147 | struct genl_info *info) |
| 5148 | { |
| 5149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5150 | struct net_device *dev = info->user_ptr[1]; |
| 5151 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5152 | struct cfg80211_chan_def chandef; |
| 5153 | int err; |
| 5154 | |
| 5155 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5156 | if (err) |
| 5157 | return err; |
| 5158 | |
| 5159 | if (wdev->cac_started) |
| 5160 | return -EBUSY; |
| 5161 | |
| 5162 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5163 | if (err < 0) |
| 5164 | return err; |
| 5165 | |
| 5166 | if (err == 0) |
| 5167 | return -EINVAL; |
| 5168 | |
| 5169 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5170 | return -EINVAL; |
| 5171 | |
| 5172 | if (!rdev->ops->start_radar_detection) |
| 5173 | return -EOPNOTSUPP; |
| 5174 | |
| 5175 | mutex_lock(&rdev->devlist_mtx); |
| 5176 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5177 | chandef.chan, CHAN_MODE_SHARED, |
| 5178 | BIT(chandef.width)); |
| 5179 | if (err) |
| 5180 | goto err_locked; |
| 5181 | |
| 5182 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5183 | if (!err) { |
| 5184 | wdev->channel = chandef.chan; |
| 5185 | wdev->cac_started = true; |
| 5186 | wdev->cac_start_time = jiffies; |
| 5187 | } |
| 5188 | err_locked: |
| 5189 | mutex_unlock(&rdev->devlist_mtx); |
| 5190 | |
| 5191 | return err; |
| 5192 | } |
| 5193 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5194 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5195 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5196 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5197 | struct wireless_dev *wdev, |
| 5198 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5199 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5200 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5201 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5202 | void *hdr; |
| 5203 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5204 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5205 | |
| 5206 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5207 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5208 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5209 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5210 | if (!hdr) |
| 5211 | return -1; |
| 5212 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5213 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5214 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5215 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5216 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5217 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5218 | |
| 5219 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5220 | if (!bss) |
| 5221 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5222 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5223 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5224 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5225 | |
| 5226 | rcu_read_lock(); |
| 5227 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5228 | if (ies) { |
| 5229 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5230 | goto fail_unlock_rcu; |
| 5231 | tsf = true; |
| 5232 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5233 | ies->len, ies->data)) |
| 5234 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5235 | } |
| 5236 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5237 | if (ies) { |
| 5238 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5239 | goto fail_unlock_rcu; |
| 5240 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5241 | ies->len, ies->data)) |
| 5242 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5243 | } |
| 5244 | rcu_read_unlock(); |
| 5245 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5246 | if (res->beacon_interval && |
| 5247 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5248 | goto nla_put_failure; |
| 5249 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5250 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5251 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5252 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5253 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5254 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5255 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5256 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5257 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5258 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5259 | break; |
| 5260 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5261 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5262 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5263 | break; |
| 5264 | default: |
| 5265 | break; |
| 5266 | } |
| 5267 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5268 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5269 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5270 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5271 | if (intbss == wdev->current_bss && |
| 5272 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5273 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5274 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5275 | break; |
| 5276 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5277 | if (intbss == wdev->current_bss && |
| 5278 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5279 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5280 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5281 | break; |
| 5282 | default: |
| 5283 | break; |
| 5284 | } |
| 5285 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5286 | nla_nest_end(msg, bss); |
| 5287 | |
| 5288 | return genlmsg_end(msg, hdr); |
| 5289 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5290 | fail_unlock_rcu: |
| 5291 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5292 | nla_put_failure: |
| 5293 | genlmsg_cancel(msg, hdr); |
| 5294 | return -EMSGSIZE; |
| 5295 | } |
| 5296 | |
| 5297 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5298 | struct netlink_callback *cb) |
| 5299 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5300 | struct cfg80211_registered_device *rdev; |
| 5301 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5302 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5303 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5304 | int start = cb->args[1], idx = 0; |
| 5305 | int err; |
| 5306 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5307 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5308 | if (err) |
| 5309 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5310 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5311 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5312 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5313 | wdev_lock(wdev); |
| 5314 | spin_lock_bh(&rdev->bss_lock); |
| 5315 | cfg80211_bss_expire(rdev); |
| 5316 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5317 | cb->seq = rdev->bss_generation; |
| 5318 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5319 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5320 | if (++idx <= start) |
| 5321 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5322 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5323 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5324 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5326 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5327 | } |
| 5328 | } |
| 5329 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5330 | spin_unlock_bh(&rdev->bss_lock); |
| 5331 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5332 | |
| 5333 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5334 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5335 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5336 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5337 | } |
| 5338 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5339 | 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] | 5340 | int flags, struct net_device *dev, |
| 5341 | struct survey_info *survey) |
| 5342 | { |
| 5343 | void *hdr; |
| 5344 | struct nlattr *infoattr; |
| 5345 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5346 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5347 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5348 | if (!hdr) |
| 5349 | return -ENOMEM; |
| 5350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5351 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5352 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5353 | |
| 5354 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5355 | if (!infoattr) |
| 5356 | goto nla_put_failure; |
| 5357 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5358 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5359 | survey->channel->center_freq)) |
| 5360 | goto nla_put_failure; |
| 5361 | |
| 5362 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5363 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5364 | goto nla_put_failure; |
| 5365 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5366 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5367 | goto nla_put_failure; |
| 5368 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5369 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5370 | survey->channel_time)) |
| 5371 | goto nla_put_failure; |
| 5372 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5373 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5374 | survey->channel_time_busy)) |
| 5375 | goto nla_put_failure; |
| 5376 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5377 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5378 | survey->channel_time_ext_busy)) |
| 5379 | goto nla_put_failure; |
| 5380 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5381 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5382 | survey->channel_time_rx)) |
| 5383 | goto nla_put_failure; |
| 5384 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5385 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5386 | survey->channel_time_tx)) |
| 5387 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5388 | |
| 5389 | nla_nest_end(msg, infoattr); |
| 5390 | |
| 5391 | return genlmsg_end(msg, hdr); |
| 5392 | |
| 5393 | nla_put_failure: |
| 5394 | genlmsg_cancel(msg, hdr); |
| 5395 | return -EMSGSIZE; |
| 5396 | } |
| 5397 | |
| 5398 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5399 | struct netlink_callback *cb) |
| 5400 | { |
| 5401 | struct survey_info survey; |
| 5402 | struct cfg80211_registered_device *dev; |
| 5403 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5404 | int survey_idx = cb->args[1]; |
| 5405 | int res; |
| 5406 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5407 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5408 | if (res) |
| 5409 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5410 | |
| 5411 | if (!dev->ops->dump_survey) { |
| 5412 | res = -EOPNOTSUPP; |
| 5413 | goto out_err; |
| 5414 | } |
| 5415 | |
| 5416 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5417 | struct ieee80211_channel *chan; |
| 5418 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5419 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5420 | if (res == -ENOENT) |
| 5421 | break; |
| 5422 | if (res) |
| 5423 | goto out_err; |
| 5424 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5425 | /* Survey without a channel doesn't make sense */ |
| 5426 | if (!survey.channel) { |
| 5427 | res = -EINVAL; |
| 5428 | goto out; |
| 5429 | } |
| 5430 | |
| 5431 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5432 | survey.channel->center_freq); |
| 5433 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5434 | survey_idx++; |
| 5435 | continue; |
| 5436 | } |
| 5437 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5438 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5439 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5440 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5441 | netdev, |
| 5442 | &survey) < 0) |
| 5443 | goto out; |
| 5444 | survey_idx++; |
| 5445 | } |
| 5446 | |
| 5447 | out: |
| 5448 | cb->args[1] = survey_idx; |
| 5449 | res = skb->len; |
| 5450 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5451 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5452 | return res; |
| 5453 | } |
| 5454 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5455 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5456 | { |
| 5457 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5458 | NL80211_WPA_VERSION_2)); |
| 5459 | } |
| 5460 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5461 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5462 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5464 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5465 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5466 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5467 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5468 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5469 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5470 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5471 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5472 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5473 | return -EINVAL; |
| 5474 | |
| 5475 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5476 | return -EINVAL; |
| 5477 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5478 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5479 | return -EINVAL; |
| 5480 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5481 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5482 | return -EINVAL; |
| 5483 | |
| 5484 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5485 | return -EINVAL; |
| 5486 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5487 | err = nl80211_parse_key(info, &key); |
| 5488 | if (err) |
| 5489 | return err; |
| 5490 | |
| 5491 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5492 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5493 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5494 | if (!key.p.key || !key.p.key_len) |
| 5495 | return -EINVAL; |
| 5496 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5497 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5498 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5499 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5500 | return -EINVAL; |
| 5501 | if (key.idx > 4) |
| 5502 | return -EINVAL; |
| 5503 | } else { |
| 5504 | key.p.key_len = 0; |
| 5505 | key.p.key = NULL; |
| 5506 | } |
| 5507 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5508 | if (key.idx >= 0) { |
| 5509 | int i; |
| 5510 | bool ok = false; |
| 5511 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5512 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5513 | ok = true; |
| 5514 | break; |
| 5515 | } |
| 5516 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5517 | if (!ok) |
| 5518 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5519 | } |
| 5520 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5521 | if (!rdev->ops->auth) |
| 5522 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5523 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5524 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5525 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5526 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5527 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5528 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5529 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5530 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5531 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5532 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5533 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5534 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5535 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5536 | |
| 5537 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5538 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5539 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5540 | } |
| 5541 | |
| 5542 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5543 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5544 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5545 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5546 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5547 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5548 | return -EINVAL; |
| 5549 | |
| 5550 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5551 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5552 | return -EINVAL; |
| 5553 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5554 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5555 | /* need to include at least Auth Transaction and Status Code */ |
| 5556 | if (sae_data_len < 4) |
| 5557 | return -EINVAL; |
| 5558 | } |
| 5559 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5560 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5561 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5562 | /* |
| 5563 | * Since we no longer track auth state, ignore |
| 5564 | * requests to only change local state. |
| 5565 | */ |
| 5566 | if (local_state_change) |
| 5567 | return 0; |
| 5568 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5569 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5570 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5571 | key.p.key, key.p.key_len, key.idx, |
| 5572 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5573 | } |
| 5574 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5575 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5576 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5577 | struct cfg80211_crypto_settings *settings, |
| 5578 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5579 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5580 | memset(settings, 0, sizeof(*settings)); |
| 5581 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5582 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5583 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5584 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5585 | u16 proto; |
| 5586 | proto = nla_get_u16( |
| 5587 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5588 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5589 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5590 | proto != ETH_P_PAE) |
| 5591 | return -EINVAL; |
| 5592 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5593 | settings->control_port_no_encrypt = true; |
| 5594 | } else |
| 5595 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5596 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5597 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5598 | void *data; |
| 5599 | int len, i; |
| 5600 | |
| 5601 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5602 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5603 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5604 | |
| 5605 | if (len % sizeof(u32)) |
| 5606 | return -EINVAL; |
| 5607 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5608 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5609 | return -EINVAL; |
| 5610 | |
| 5611 | memcpy(settings->ciphers_pairwise, data, len); |
| 5612 | |
| 5613 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5614 | if (!cfg80211_supported_cipher_suite( |
| 5615 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5616 | settings->ciphers_pairwise[i])) |
| 5617 | return -EINVAL; |
| 5618 | } |
| 5619 | |
| 5620 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5621 | settings->cipher_group = |
| 5622 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5623 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5624 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5625 | return -EINVAL; |
| 5626 | } |
| 5627 | |
| 5628 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5629 | settings->wpa_versions = |
| 5630 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5631 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5632 | return -EINVAL; |
| 5633 | } |
| 5634 | |
| 5635 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5636 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5637 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5638 | |
| 5639 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5640 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5641 | settings->n_akm_suites = len / sizeof(u32); |
| 5642 | |
| 5643 | if (len % sizeof(u32)) |
| 5644 | return -EINVAL; |
| 5645 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5646 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5647 | return -EINVAL; |
| 5648 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5649 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | return 0; |
| 5653 | } |
| 5654 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5655 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5656 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5658 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5659 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5660 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5661 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5662 | int err, ssid_len, ie_len = 0; |
| 5663 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5664 | u32 flags = 0; |
| 5665 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5666 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5667 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5668 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5669 | return -EINVAL; |
| 5670 | |
| 5671 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5672 | !info->attrs[NL80211_ATTR_SSID] || |
| 5673 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5674 | return -EINVAL; |
| 5675 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5676 | if (!rdev->ops->assoc) |
| 5677 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5678 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5679 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5681 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5682 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5683 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5684 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5685 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5686 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5687 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5688 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5689 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5690 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5691 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5692 | |
| 5693 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5694 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5695 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5696 | } |
| 5697 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5698 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5699 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5700 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5701 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5702 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5703 | else if (mfp != NL80211_MFP_NO) |
| 5704 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5705 | } |
| 5706 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5707 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5708 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5709 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5710 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5711 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5712 | |
| 5713 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5714 | ht_capa_mask = |
| 5715 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5716 | |
| 5717 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5718 | if (!ht_capa_mask) |
| 5719 | return -EINVAL; |
| 5720 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5721 | } |
| 5722 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5723 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5724 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5725 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5726 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5727 | &crypto, flags, ht_capa, |
| 5728 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5729 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5730 | return err; |
| 5731 | } |
| 5732 | |
| 5733 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5734 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5736 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5737 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5738 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5739 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5740 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5741 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5742 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5743 | return -EINVAL; |
| 5744 | |
| 5745 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5746 | return -EINVAL; |
| 5747 | |
| 5748 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5749 | return -EINVAL; |
| 5750 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5751 | if (!rdev->ops->deauth) |
| 5752 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5753 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5754 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5755 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5756 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5757 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5758 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5759 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5760 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5761 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5762 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5763 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5764 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5765 | |
| 5766 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5767 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5768 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5769 | } |
| 5770 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5771 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5773 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5774 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5778 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5780 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5781 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5782 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5783 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5784 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5785 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5786 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5787 | return -EINVAL; |
| 5788 | |
| 5789 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5790 | return -EINVAL; |
| 5791 | |
| 5792 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5793 | return -EINVAL; |
| 5794 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5795 | if (!rdev->ops->disassoc) |
| 5796 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5797 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5798 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5799 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5800 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5801 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5802 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5803 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5804 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5805 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5806 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5807 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5808 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5809 | |
| 5810 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5811 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5812 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5813 | } |
| 5814 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5815 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5816 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5817 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5818 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5819 | } |
| 5820 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5821 | static bool |
| 5822 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5823 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5824 | int rateval) |
| 5825 | { |
| 5826 | struct wiphy *wiphy = &rdev->wiphy; |
| 5827 | bool found = false; |
| 5828 | int band, i; |
| 5829 | |
| 5830 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5831 | struct ieee80211_supported_band *sband; |
| 5832 | |
| 5833 | sband = wiphy->bands[band]; |
| 5834 | if (!sband) |
| 5835 | continue; |
| 5836 | |
| 5837 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5838 | if (sband->bitrates[i].bitrate == rateval) { |
| 5839 | mcast_rate[band] = i + 1; |
| 5840 | found = true; |
| 5841 | break; |
| 5842 | } |
| 5843 | } |
| 5844 | } |
| 5845 | |
| 5846 | return found; |
| 5847 | } |
| 5848 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5849 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5850 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5851 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5852 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5853 | struct cfg80211_ibss_params ibss; |
| 5854 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5855 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5856 | int err; |
| 5857 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5858 | memset(&ibss, 0, sizeof(ibss)); |
| 5859 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5860 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5861 | return -EINVAL; |
| 5862 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5863 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5864 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5865 | return -EINVAL; |
| 5866 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5867 | ibss.beacon_interval = 100; |
| 5868 | |
| 5869 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5870 | ibss.beacon_interval = |
| 5871 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5872 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5873 | return -EINVAL; |
| 5874 | } |
| 5875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5876 | if (!rdev->ops->join_ibss) |
| 5877 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5878 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5880 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5881 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5882 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5883 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5884 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5885 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5886 | |
| 5887 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5888 | return -EINVAL; |
| 5889 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5890 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5891 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5892 | |
| 5893 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5894 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5895 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5896 | } |
| 5897 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5898 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5899 | if (err) |
| 5900 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5901 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5902 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5903 | return -EINVAL; |
| 5904 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5905 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5906 | return -EINVAL; |
| 5907 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5908 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5909 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5910 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5911 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5912 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5913 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5914 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5915 | u8 *rates = |
| 5916 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5917 | int n_rates = |
| 5918 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5919 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5920 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5921 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5922 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5923 | &ibss.basic_rates); |
| 5924 | if (err) |
| 5925 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5926 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5927 | |
| 5928 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5929 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5930 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5931 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5932 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5933 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5934 | bool no_ht = false; |
| 5935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5936 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5937 | info->attrs[NL80211_ATTR_KEYS], |
| 5938 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5939 | if (IS_ERR(connkeys)) |
| 5940 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5941 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5942 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5943 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5944 | kfree(connkeys); |
| 5945 | return -EINVAL; |
| 5946 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5947 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5948 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5949 | ibss.control_port = |
| 5950 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5951 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5952 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5953 | if (err) |
| 5954 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5955 | return err; |
| 5956 | } |
| 5957 | |
| 5958 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5961 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5963 | if (!rdev->ops->leave_ibss) |
| 5964 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5965 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5967 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5969 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5970 | } |
| 5971 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5972 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5973 | { |
| 5974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5975 | struct net_device *dev = info->user_ptr[1]; |
| 5976 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5977 | u32 nla_rate; |
| 5978 | int err; |
| 5979 | |
| 5980 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5981 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5982 | return -EOPNOTSUPP; |
| 5983 | |
| 5984 | if (!rdev->ops->set_mcast_rate) |
| 5985 | return -EOPNOTSUPP; |
| 5986 | |
| 5987 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5988 | |
| 5989 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5990 | return -EINVAL; |
| 5991 | |
| 5992 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5993 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5994 | return -EINVAL; |
| 5995 | |
| 5996 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5997 | |
| 5998 | return err; |
| 5999 | } |
| 6000 | |
| 6001 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6002 | #ifdef CONFIG_NL80211_TESTMODE |
| 6003 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6004 | .name = "testmode", |
| 6005 | }; |
| 6006 | |
| 6007 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6008 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6010 | int err; |
| 6011 | |
| 6012 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6013 | return -EINVAL; |
| 6014 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6015 | err = -EOPNOTSUPP; |
| 6016 | if (rdev->ops->testmode_cmd) { |
| 6017 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6018 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6019 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6020 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6021 | rdev->testmode_info = NULL; |
| 6022 | } |
| 6023 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6024 | return err; |
| 6025 | } |
| 6026 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6027 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6028 | struct netlink_callback *cb) |
| 6029 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6030 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6031 | int err; |
| 6032 | long phy_idx; |
| 6033 | void *data = NULL; |
| 6034 | int data_len = 0; |
| 6035 | |
| 6036 | if (cb->args[0]) { |
| 6037 | /* |
| 6038 | * 0 is a valid index, but not valid for args[0], |
| 6039 | * so we need to offset by 1. |
| 6040 | */ |
| 6041 | phy_idx = cb->args[0] - 1; |
| 6042 | } else { |
| 6043 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6044 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6045 | nl80211_policy); |
| 6046 | if (err) |
| 6047 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6048 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6049 | mutex_lock(&cfg80211_mutex); |
| 6050 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6051 | nl80211_fam.attrbuf); |
| 6052 | if (IS_ERR(rdev)) { |
| 6053 | mutex_unlock(&cfg80211_mutex); |
| 6054 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6055 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6056 | phy_idx = rdev->wiphy_idx; |
| 6057 | rdev = NULL; |
| 6058 | mutex_unlock(&cfg80211_mutex); |
| 6059 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6060 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6061 | cb->args[1] = |
| 6062 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6063 | } |
| 6064 | |
| 6065 | if (cb->args[1]) { |
| 6066 | data = nla_data((void *)cb->args[1]); |
| 6067 | data_len = nla_len((void *)cb->args[1]); |
| 6068 | } |
| 6069 | |
| 6070 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6071 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6072 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6073 | mutex_unlock(&cfg80211_mutex); |
| 6074 | return -ENOENT; |
| 6075 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6076 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6077 | mutex_unlock(&cfg80211_mutex); |
| 6078 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6079 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6080 | err = -EOPNOTSUPP; |
| 6081 | goto out_err; |
| 6082 | } |
| 6083 | |
| 6084 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6085 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6086 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6087 | NL80211_CMD_TESTMODE); |
| 6088 | struct nlattr *tmdata; |
| 6089 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6090 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6091 | genlmsg_cancel(skb, hdr); |
| 6092 | break; |
| 6093 | } |
| 6094 | |
| 6095 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6096 | if (!tmdata) { |
| 6097 | genlmsg_cancel(skb, hdr); |
| 6098 | break; |
| 6099 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6100 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6101 | nla_nest_end(skb, tmdata); |
| 6102 | |
| 6103 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6104 | genlmsg_cancel(skb, hdr); |
| 6105 | break; |
| 6106 | } else if (err) { |
| 6107 | genlmsg_cancel(skb, hdr); |
| 6108 | goto out_err; |
| 6109 | } |
| 6110 | |
| 6111 | genlmsg_end(skb, hdr); |
| 6112 | } |
| 6113 | |
| 6114 | err = skb->len; |
| 6115 | /* see above */ |
| 6116 | cb->args[0] = phy_idx + 1; |
| 6117 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6118 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6119 | return err; |
| 6120 | } |
| 6121 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6122 | static struct sk_buff * |
| 6123 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6124 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6125 | { |
| 6126 | struct sk_buff *skb; |
| 6127 | void *hdr; |
| 6128 | struct nlattr *data; |
| 6129 | |
| 6130 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6131 | if (!skb) |
| 6132 | return NULL; |
| 6133 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6134 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6135 | if (!hdr) { |
| 6136 | kfree_skb(skb); |
| 6137 | return NULL; |
| 6138 | } |
| 6139 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6140 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6141 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6142 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6143 | |
| 6144 | ((void **)skb->cb)[0] = rdev; |
| 6145 | ((void **)skb->cb)[1] = hdr; |
| 6146 | ((void **)skb->cb)[2] = data; |
| 6147 | |
| 6148 | return skb; |
| 6149 | |
| 6150 | nla_put_failure: |
| 6151 | kfree_skb(skb); |
| 6152 | return NULL; |
| 6153 | } |
| 6154 | |
| 6155 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6156 | int approxlen) |
| 6157 | { |
| 6158 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6159 | |
| 6160 | if (WARN_ON(!rdev->testmode_info)) |
| 6161 | return NULL; |
| 6162 | |
| 6163 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6164 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6165 | rdev->testmode_info->snd_seq, |
| 6166 | GFP_KERNEL); |
| 6167 | } |
| 6168 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6169 | |
| 6170 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6171 | { |
| 6172 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6173 | void *hdr = ((void **)skb->cb)[1]; |
| 6174 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6175 | |
| 6176 | if (WARN_ON(!rdev->testmode_info)) { |
| 6177 | kfree_skb(skb); |
| 6178 | return -EINVAL; |
| 6179 | } |
| 6180 | |
| 6181 | nla_nest_end(skb, data); |
| 6182 | genlmsg_end(skb, hdr); |
| 6183 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6184 | } |
| 6185 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6186 | |
| 6187 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6188 | int approxlen, gfp_t gfp) |
| 6189 | { |
| 6190 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6191 | |
| 6192 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6193 | } |
| 6194 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6195 | |
| 6196 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6197 | { |
| 6198 | void *hdr = ((void **)skb->cb)[1]; |
| 6199 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6200 | |
| 6201 | nla_nest_end(skb, data); |
| 6202 | genlmsg_end(skb, hdr); |
| 6203 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6204 | } |
| 6205 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6206 | #endif |
| 6207 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6208 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6209 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6211 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6212 | struct cfg80211_connect_params connect; |
| 6213 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6214 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6215 | int err; |
| 6216 | |
| 6217 | memset(&connect, 0, sizeof(connect)); |
| 6218 | |
| 6219 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6220 | return -EINVAL; |
| 6221 | |
| 6222 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6223 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6224 | return -EINVAL; |
| 6225 | |
| 6226 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6227 | connect.auth_type = |
| 6228 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6229 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6230 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6231 | return -EINVAL; |
| 6232 | } else |
| 6233 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6234 | |
| 6235 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6236 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6237 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6238 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6239 | if (err) |
| 6240 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6241 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6242 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6243 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6244 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6245 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6246 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6247 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6248 | connect.bg_scan_period = -1; |
| 6249 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6250 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6251 | connect.bg_scan_period = |
| 6252 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6253 | } |
| 6254 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6255 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6256 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6257 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6258 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6259 | |
| 6260 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6261 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6262 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6263 | } |
| 6264 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6265 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6266 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6267 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6268 | connect.mfp != NL80211_MFP_NO) |
| 6269 | return -EINVAL; |
| 6270 | } else { |
| 6271 | connect.mfp = NL80211_MFP_NO; |
| 6272 | } |
| 6273 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6274 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6275 | connect.channel = |
| 6276 | ieee80211_get_channel(wiphy, |
| 6277 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6278 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6279 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6280 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6281 | } |
| 6282 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6283 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6284 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6285 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6286 | if (IS_ERR(connkeys)) |
| 6287 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6288 | } |
| 6289 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6290 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6291 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6292 | |
| 6293 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6294 | memcpy(&connect.ht_capa_mask, |
| 6295 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6296 | sizeof(connect.ht_capa_mask)); |
| 6297 | |
| 6298 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6299 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6300 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6301 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6302 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6303 | memcpy(&connect.ht_capa, |
| 6304 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6305 | sizeof(connect.ht_capa)); |
| 6306 | } |
| 6307 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6308 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6309 | if (err) |
| 6310 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6311 | return err; |
| 6312 | } |
| 6313 | |
| 6314 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6315 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6317 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6318 | u16 reason; |
| 6319 | |
| 6320 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6321 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6322 | else |
| 6323 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6324 | |
| 6325 | if (reason == 0) |
| 6326 | return -EINVAL; |
| 6327 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6328 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6329 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6330 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6333 | } |
| 6334 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6335 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6336 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6338 | struct net *net; |
| 6339 | int err; |
| 6340 | u32 pid; |
| 6341 | |
| 6342 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6343 | return -EINVAL; |
| 6344 | |
| 6345 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6346 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6347 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6348 | if (IS_ERR(net)) |
| 6349 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6350 | |
| 6351 | err = 0; |
| 6352 | |
| 6353 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6355 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6356 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6357 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6358 | return err; |
| 6359 | } |
| 6360 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6361 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6362 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6364 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6365 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6366 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6367 | struct cfg80211_pmksa pmksa; |
| 6368 | |
| 6369 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6370 | |
| 6371 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6372 | return -EINVAL; |
| 6373 | |
| 6374 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6375 | return -EINVAL; |
| 6376 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6377 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6378 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6379 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6380 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6382 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6383 | |
| 6384 | switch (info->genlhdr->cmd) { |
| 6385 | case NL80211_CMD_SET_PMKSA: |
| 6386 | rdev_ops = rdev->ops->set_pmksa; |
| 6387 | break; |
| 6388 | case NL80211_CMD_DEL_PMKSA: |
| 6389 | rdev_ops = rdev->ops->del_pmksa; |
| 6390 | break; |
| 6391 | default: |
| 6392 | WARN_ON(1); |
| 6393 | break; |
| 6394 | } |
| 6395 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6396 | if (!rdev_ops) |
| 6397 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6398 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6399 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6403 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6405 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6406 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6407 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6408 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6409 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6411 | if (!rdev->ops->flush_pmksa) |
| 6412 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6413 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6414 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6415 | } |
| 6416 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6417 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6418 | { |
| 6419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6420 | struct net_device *dev = info->user_ptr[1]; |
| 6421 | u8 action_code, dialog_token; |
| 6422 | u16 status_code; |
| 6423 | u8 *peer; |
| 6424 | |
| 6425 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6426 | !rdev->ops->tdls_mgmt) |
| 6427 | return -EOPNOTSUPP; |
| 6428 | |
| 6429 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6430 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6431 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6432 | !info->attrs[NL80211_ATTR_IE] || |
| 6433 | !info->attrs[NL80211_ATTR_MAC]) |
| 6434 | return -EINVAL; |
| 6435 | |
| 6436 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6437 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6438 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6439 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6440 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6441 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6442 | dialog_token, status_code, |
| 6443 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6444 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6448 | { |
| 6449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6450 | struct net_device *dev = info->user_ptr[1]; |
| 6451 | enum nl80211_tdls_operation operation; |
| 6452 | u8 *peer; |
| 6453 | |
| 6454 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6455 | !rdev->ops->tdls_oper) |
| 6456 | return -EOPNOTSUPP; |
| 6457 | |
| 6458 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6459 | !info->attrs[NL80211_ATTR_MAC]) |
| 6460 | return -EINVAL; |
| 6461 | |
| 6462 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6463 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6464 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6465 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6466 | } |
| 6467 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6468 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6469 | struct genl_info *info) |
| 6470 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6472 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6473 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6474 | struct sk_buff *msg; |
| 6475 | void *hdr; |
| 6476 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6477 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6478 | int err; |
| 6479 | |
| 6480 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6481 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6482 | return -EINVAL; |
| 6483 | |
| 6484 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6485 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6486 | if (!rdev->ops->remain_on_channel || |
| 6487 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6488 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6489 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6490 | /* |
| 6491 | * We should be on that channel for at least a minimum amount of |
| 6492 | * time (10ms) but no longer than the driver supports. |
| 6493 | */ |
| 6494 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6495 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6496 | return -EINVAL; |
| 6497 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6498 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6499 | if (err) |
| 6500 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6501 | |
| 6502 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | if (!msg) |
| 6504 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6505 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6506 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6507 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6508 | |
| 6509 | if (IS_ERR(hdr)) { |
| 6510 | err = PTR_ERR(hdr); |
| 6511 | goto free_msg; |
| 6512 | } |
| 6513 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6514 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6515 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6516 | |
| 6517 | if (err) |
| 6518 | goto free_msg; |
| 6519 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6520 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6521 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6522 | |
| 6523 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6524 | |
| 6525 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6526 | |
| 6527 | nla_put_failure: |
| 6528 | err = -ENOBUFS; |
| 6529 | free_msg: |
| 6530 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6531 | return err; |
| 6532 | } |
| 6533 | |
| 6534 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6535 | struct genl_info *info) |
| 6536 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6538 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6539 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6540 | |
| 6541 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6542 | return -EINVAL; |
| 6543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6544 | if (!rdev->ops->cancel_remain_on_channel) |
| 6545 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6546 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6547 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6548 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6549 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6550 | } |
| 6551 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6552 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6553 | u8 *rates, u8 rates_len) |
| 6554 | { |
| 6555 | u8 i; |
| 6556 | u32 mask = 0; |
| 6557 | |
| 6558 | for (i = 0; i < rates_len; i++) { |
| 6559 | int rate = (rates[i] & 0x7f) * 5; |
| 6560 | int ridx; |
| 6561 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6562 | struct ieee80211_rate *srate = |
| 6563 | &sband->bitrates[ridx]; |
| 6564 | if (rate == srate->bitrate) { |
| 6565 | mask |= 1 << ridx; |
| 6566 | break; |
| 6567 | } |
| 6568 | } |
| 6569 | if (ridx == sband->n_bitrates) |
| 6570 | return 0; /* rate not found */ |
| 6571 | } |
| 6572 | |
| 6573 | return mask; |
| 6574 | } |
| 6575 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6576 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6577 | u8 *rates, u8 rates_len, |
| 6578 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6579 | { |
| 6580 | u8 i; |
| 6581 | |
| 6582 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6583 | |
| 6584 | for (i = 0; i < rates_len; i++) { |
| 6585 | int ridx, rbit; |
| 6586 | |
| 6587 | ridx = rates[i] / 8; |
| 6588 | rbit = BIT(rates[i] % 8); |
| 6589 | |
| 6590 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6591 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6592 | return false; |
| 6593 | |
| 6594 | /* check availability */ |
| 6595 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6596 | mcs[ridx] |= rbit; |
| 6597 | else |
| 6598 | return false; |
| 6599 | } |
| 6600 | |
| 6601 | return true; |
| 6602 | } |
| 6603 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6604 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6605 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6606 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6607 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6608 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6609 | }; |
| 6610 | |
| 6611 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6612 | struct genl_info *info) |
| 6613 | { |
| 6614 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6616 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6617 | int rem, i; |
| 6618 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6619 | struct nlattr *tx_rates; |
| 6620 | struct ieee80211_supported_band *sband; |
| 6621 | |
| 6622 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6623 | return -EINVAL; |
| 6624 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6625 | if (!rdev->ops->set_bitrate_mask) |
| 6626 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6627 | |
| 6628 | memset(&mask, 0, sizeof(mask)); |
| 6629 | /* Default to all rates enabled */ |
| 6630 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6631 | sband = rdev->wiphy.bands[i]; |
| 6632 | mask.control[i].legacy = |
| 6633 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6634 | if (sband) |
| 6635 | memcpy(mask.control[i].mcs, |
| 6636 | sband->ht_cap.mcs.rx_mask, |
| 6637 | sizeof(mask.control[i].mcs)); |
| 6638 | else |
| 6639 | memset(mask.control[i].mcs, 0, |
| 6640 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | /* |
| 6644 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6645 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6646 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6647 | 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] | 6648 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6649 | { |
| 6650 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6651 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6652 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6653 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6654 | if (sband == NULL) |
| 6655 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6656 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6657 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6658 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6659 | mask.control[band].legacy = rateset_to_mask( |
| 6660 | sband, |
| 6661 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6662 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6663 | if ((mask.control[band].legacy == 0) && |
| 6664 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6665 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6666 | } |
| 6667 | if (tb[NL80211_TXRATE_MCS]) { |
| 6668 | if (!ht_rateset_to_mask( |
| 6669 | sband, |
| 6670 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6671 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6672 | mask.control[band].mcs)) |
| 6673 | return -EINVAL; |
| 6674 | } |
| 6675 | |
| 6676 | if (mask.control[band].legacy == 0) { |
| 6677 | /* don't allow empty legacy rates if HT |
| 6678 | * is not even supported. */ |
| 6679 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6680 | return -EINVAL; |
| 6681 | |
| 6682 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6683 | if (mask.control[band].mcs[i]) |
| 6684 | break; |
| 6685 | |
| 6686 | /* legacy and mcs rates may not be both empty */ |
| 6687 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6688 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6689 | } |
| 6690 | } |
| 6691 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6692 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6693 | } |
| 6694 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6695 | 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] | 6696 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6698 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6699 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6700 | |
| 6701 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6702 | return -EINVAL; |
| 6703 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6704 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6705 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6706 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6707 | switch (wdev->iftype) { |
| 6708 | case NL80211_IFTYPE_STATION: |
| 6709 | case NL80211_IFTYPE_ADHOC: |
| 6710 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6711 | case NL80211_IFTYPE_AP: |
| 6712 | case NL80211_IFTYPE_AP_VLAN: |
| 6713 | case NL80211_IFTYPE_MESH_POINT: |
| 6714 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6715 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6716 | break; |
| 6717 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6718 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6719 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6720 | |
| 6721 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6722 | if (!rdev->ops->mgmt_tx) |
| 6723 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6724 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6725 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6726 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6727 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6728 | } |
| 6729 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6730 | 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] | 6731 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6733 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6734 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6735 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6736 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6737 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6738 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6739 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6740 | bool offchan, no_cck, dont_wait_for_ack; |
| 6741 | |
| 6742 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6743 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6744 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6745 | return -EINVAL; |
| 6746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | if (!rdev->ops->mgmt_tx) |
| 6748 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6749 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6750 | switch (wdev->iftype) { |
| 6751 | case NL80211_IFTYPE_STATION: |
| 6752 | case NL80211_IFTYPE_ADHOC: |
| 6753 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6754 | case NL80211_IFTYPE_AP: |
| 6755 | case NL80211_IFTYPE_AP_VLAN: |
| 6756 | case NL80211_IFTYPE_MESH_POINT: |
| 6757 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6758 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6759 | break; |
| 6760 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6761 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6762 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6763 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6764 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6765 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6766 | return -EINVAL; |
| 6767 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6768 | |
| 6769 | /* |
| 6770 | * We should wait on the channel for at least a minimum amount |
| 6771 | * of time (10ms) but no longer than the driver supports. |
| 6772 | */ |
| 6773 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6774 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6775 | return -EINVAL; |
| 6776 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6777 | } |
| 6778 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6779 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6780 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6781 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6782 | return -EINVAL; |
| 6783 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6784 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6785 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6786 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6787 | if (err) |
| 6788 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6789 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6790 | if (!dont_wait_for_ack) { |
| 6791 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6792 | if (!msg) |
| 6793 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6794 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6795 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6796 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6797 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6798 | if (IS_ERR(hdr)) { |
| 6799 | err = PTR_ERR(hdr); |
| 6800 | goto free_msg; |
| 6801 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6802 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6803 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6804 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6805 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6806 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6807 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6808 | if (err) |
| 6809 | goto free_msg; |
| 6810 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6811 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6812 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6813 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6814 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6815 | genlmsg_end(msg, hdr); |
| 6816 | return genlmsg_reply(msg, info); |
| 6817 | } |
| 6818 | |
| 6819 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6820 | |
| 6821 | nla_put_failure: |
| 6822 | err = -ENOBUFS; |
| 6823 | free_msg: |
| 6824 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6825 | return err; |
| 6826 | } |
| 6827 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6828 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6829 | { |
| 6830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6831 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6832 | u64 cookie; |
| 6833 | |
| 6834 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6835 | return -EINVAL; |
| 6836 | |
| 6837 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6838 | return -EOPNOTSUPP; |
| 6839 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6840 | switch (wdev->iftype) { |
| 6841 | case NL80211_IFTYPE_STATION: |
| 6842 | case NL80211_IFTYPE_ADHOC: |
| 6843 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6844 | case NL80211_IFTYPE_AP: |
| 6845 | case NL80211_IFTYPE_AP_VLAN: |
| 6846 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6847 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6848 | break; |
| 6849 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6850 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6851 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6852 | |
| 6853 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6854 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6855 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6856 | } |
| 6857 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6858 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6859 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6861 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6862 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6863 | u8 ps_state; |
| 6864 | bool state; |
| 6865 | int err; |
| 6866 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6867 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6868 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6869 | |
| 6870 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6872 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6873 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6874 | |
| 6875 | wdev = dev->ieee80211_ptr; |
| 6876 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6877 | if (!rdev->ops->set_power_mgmt) |
| 6878 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6879 | |
| 6880 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6881 | |
| 6882 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6883 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6884 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6885 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6886 | if (!err) |
| 6887 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6888 | return err; |
| 6889 | } |
| 6890 | |
| 6891 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6892 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6894 | enum nl80211_ps_state ps_state; |
| 6895 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6896 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6897 | struct sk_buff *msg; |
| 6898 | void *hdr; |
| 6899 | int err; |
| 6900 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6901 | wdev = dev->ieee80211_ptr; |
| 6902 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6903 | if (!rdev->ops->set_power_mgmt) |
| 6904 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6905 | |
| 6906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6907 | if (!msg) |
| 6908 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6909 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6910 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6911 | NL80211_CMD_GET_POWER_SAVE); |
| 6912 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6913 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6914 | goto free_msg; |
| 6915 | } |
| 6916 | |
| 6917 | if (wdev->ps) |
| 6918 | ps_state = NL80211_PS_ENABLED; |
| 6919 | else |
| 6920 | ps_state = NL80211_PS_DISABLED; |
| 6921 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6922 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6923 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6924 | |
| 6925 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6926 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6927 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6928 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6929 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6930 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6931 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6932 | return err; |
| 6933 | } |
| 6934 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6935 | static struct nla_policy |
| 6936 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6937 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6938 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6939 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6940 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6941 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6942 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6943 | }; |
| 6944 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6945 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6946 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6947 | { |
| 6948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6949 | struct wireless_dev *wdev; |
| 6950 | struct net_device *dev = info->user_ptr[1]; |
| 6951 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6952 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6953 | return -EINVAL; |
| 6954 | |
| 6955 | wdev = dev->ieee80211_ptr; |
| 6956 | |
| 6957 | if (!rdev->ops->set_cqm_txe_config) |
| 6958 | return -EOPNOTSUPP; |
| 6959 | |
| 6960 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6961 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6962 | return -EOPNOTSUPP; |
| 6963 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6964 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6967 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6968 | s32 threshold, u32 hysteresis) |
| 6969 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6971 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6972 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6973 | |
| 6974 | if (threshold > 0) |
| 6975 | return -EINVAL; |
| 6976 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6977 | wdev = dev->ieee80211_ptr; |
| 6978 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6979 | if (!rdev->ops->set_cqm_rssi_config) |
| 6980 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6981 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6982 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6983 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6984 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6985 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6986 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6990 | { |
| 6991 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6992 | struct nlattr *cqm; |
| 6993 | int err; |
| 6994 | |
| 6995 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6996 | if (!cqm) { |
| 6997 | err = -EINVAL; |
| 6998 | goto out; |
| 6999 | } |
| 7000 | |
| 7001 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7002 | nl80211_attr_cqm_policy); |
| 7003 | if (err) |
| 7004 | goto out; |
| 7005 | |
| 7006 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7007 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7008 | s32 threshold; |
| 7009 | u32 hysteresis; |
| 7010 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7011 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7012 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7013 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7014 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7015 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7016 | u32 rate, pkts, intvl; |
| 7017 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7018 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7019 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7020 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7021 | } else |
| 7022 | err = -EINVAL; |
| 7023 | |
| 7024 | out: |
| 7025 | return err; |
| 7026 | } |
| 7027 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7028 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7029 | { |
| 7030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7031 | struct net_device *dev = info->user_ptr[1]; |
| 7032 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7033 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7034 | int err; |
| 7035 | |
| 7036 | /* start with default */ |
| 7037 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7038 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7039 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7040 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7041 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7042 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7043 | if (err) |
| 7044 | return err; |
| 7045 | } |
| 7046 | |
| 7047 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7048 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7049 | return -EINVAL; |
| 7050 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7051 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7052 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7053 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7054 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7055 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7056 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7057 | return -EINVAL; |
| 7058 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7059 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7060 | setup.beacon_interval = |
| 7061 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7062 | if (setup.beacon_interval < 10 || |
| 7063 | setup.beacon_interval > 10000) |
| 7064 | return -EINVAL; |
| 7065 | } |
| 7066 | |
| 7067 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7068 | setup.dtim_period = |
| 7069 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7070 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7071 | return -EINVAL; |
| 7072 | } |
| 7073 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7074 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7075 | /* parse additional setup parameters if given */ |
| 7076 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7077 | if (err) |
| 7078 | return err; |
| 7079 | } |
| 7080 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7081 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7082 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7083 | if (err) |
| 7084 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7085 | } else { |
| 7086 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7087 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7088 | } |
| 7089 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7090 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7094 | { |
| 7095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7096 | struct net_device *dev = info->user_ptr[1]; |
| 7097 | |
| 7098 | return cfg80211_leave_mesh(rdev, dev); |
| 7099 | } |
| 7100 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7101 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7102 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7103 | struct cfg80211_registered_device *rdev) |
| 7104 | { |
| 7105 | struct nlattr *nl_pats, *nl_pat; |
| 7106 | int i, pat_len; |
| 7107 | |
| 7108 | if (!rdev->wowlan->n_patterns) |
| 7109 | return 0; |
| 7110 | |
| 7111 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7112 | if (!nl_pats) |
| 7113 | return -ENOBUFS; |
| 7114 | |
| 7115 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7116 | nl_pat = nla_nest_start(msg, i + 1); |
| 7117 | if (!nl_pat) |
| 7118 | return -ENOBUFS; |
| 7119 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7120 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7121 | DIV_ROUND_UP(pat_len, 8), |
| 7122 | rdev->wowlan->patterns[i].mask) || |
| 7123 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7124 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7125 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7126 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7127 | return -ENOBUFS; |
| 7128 | nla_nest_end(msg, nl_pat); |
| 7129 | } |
| 7130 | nla_nest_end(msg, nl_pats); |
| 7131 | |
| 7132 | return 0; |
| 7133 | } |
| 7134 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7135 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7136 | struct cfg80211_wowlan_tcp *tcp) |
| 7137 | { |
| 7138 | struct nlattr *nl_tcp; |
| 7139 | |
| 7140 | if (!tcp) |
| 7141 | return 0; |
| 7142 | |
| 7143 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7144 | if (!nl_tcp) |
| 7145 | return -ENOBUFS; |
| 7146 | |
| 7147 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7148 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7149 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7150 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7151 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7152 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7153 | tcp->payload_len, tcp->payload) || |
| 7154 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7155 | tcp->data_interval) || |
| 7156 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7157 | tcp->wake_len, tcp->wake_data) || |
| 7158 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7159 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7160 | return -ENOBUFS; |
| 7161 | |
| 7162 | if (tcp->payload_seq.len && |
| 7163 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7164 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7165 | return -ENOBUFS; |
| 7166 | |
| 7167 | if (tcp->payload_tok.len && |
| 7168 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7169 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7170 | &tcp->payload_tok)) |
| 7171 | return -ENOBUFS; |
| 7172 | |
| 7173 | return 0; |
| 7174 | } |
| 7175 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7176 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7177 | { |
| 7178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7179 | struct sk_buff *msg; |
| 7180 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7181 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7182 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7183 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7184 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7185 | return -EOPNOTSUPP; |
| 7186 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7187 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7188 | /* adjust size to have room for all the data */ |
| 7189 | size += rdev->wowlan->tcp->tokens_size + |
| 7190 | rdev->wowlan->tcp->payload_len + |
| 7191 | rdev->wowlan->tcp->wake_len + |
| 7192 | rdev->wowlan->tcp->wake_len / 8; |
| 7193 | } |
| 7194 | |
| 7195 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7196 | if (!msg) |
| 7197 | return -ENOMEM; |
| 7198 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7199 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7200 | NL80211_CMD_GET_WOWLAN); |
| 7201 | if (!hdr) |
| 7202 | goto nla_put_failure; |
| 7203 | |
| 7204 | if (rdev->wowlan) { |
| 7205 | struct nlattr *nl_wowlan; |
| 7206 | |
| 7207 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7208 | if (!nl_wowlan) |
| 7209 | goto nla_put_failure; |
| 7210 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7211 | if ((rdev->wowlan->any && |
| 7212 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7213 | (rdev->wowlan->disconnect && |
| 7214 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7215 | (rdev->wowlan->magic_pkt && |
| 7216 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7217 | (rdev->wowlan->gtk_rekey_failure && |
| 7218 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7219 | (rdev->wowlan->eap_identity_req && |
| 7220 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7221 | (rdev->wowlan->four_way_handshake && |
| 7222 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7223 | (rdev->wowlan->rfkill_release && |
| 7224 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7225 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7226 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7227 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7228 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7229 | |
| 7230 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7231 | goto nla_put_failure; |
| 7232 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7233 | nla_nest_end(msg, nl_wowlan); |
| 7234 | } |
| 7235 | |
| 7236 | genlmsg_end(msg, hdr); |
| 7237 | return genlmsg_reply(msg, info); |
| 7238 | |
| 7239 | nla_put_failure: |
| 7240 | nlmsg_free(msg); |
| 7241 | return -ENOBUFS; |
| 7242 | } |
| 7243 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7244 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7245 | struct nlattr *attr, |
| 7246 | struct cfg80211_wowlan *trig) |
| 7247 | { |
| 7248 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7249 | struct cfg80211_wowlan_tcp *cfg; |
| 7250 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7251 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7252 | u32 size; |
| 7253 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7254 | int err, port; |
| 7255 | |
| 7256 | if (!rdev->wiphy.wowlan.tcp) |
| 7257 | return -EINVAL; |
| 7258 | |
| 7259 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7260 | nla_data(attr), nla_len(attr), |
| 7261 | nl80211_wowlan_tcp_policy); |
| 7262 | if (err) |
| 7263 | return err; |
| 7264 | |
| 7265 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7266 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7267 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7268 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7269 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7270 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7271 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7272 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7273 | return -EINVAL; |
| 7274 | |
| 7275 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7276 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7277 | return -EINVAL; |
| 7278 | |
| 7279 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 7280 | rdev->wiphy.wowlan.tcp->data_interval_max) |
| 7281 | return -EINVAL; |
| 7282 | |
| 7283 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7284 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7285 | return -EINVAL; |
| 7286 | |
| 7287 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7288 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7289 | return -EINVAL; |
| 7290 | |
| 7291 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7292 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7293 | |
| 7294 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7295 | tokens_size = tokln - sizeof(*tok); |
| 7296 | |
| 7297 | if (!tok->len || tokens_size % tok->len) |
| 7298 | return -EINVAL; |
| 7299 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7300 | return -EINVAL; |
| 7301 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7302 | return -EINVAL; |
| 7303 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7304 | return -EINVAL; |
| 7305 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7306 | return -EINVAL; |
| 7307 | if (tok->offset + tok->len > data_size) |
| 7308 | return -EINVAL; |
| 7309 | } |
| 7310 | |
| 7311 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7312 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7313 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7314 | return -EINVAL; |
| 7315 | if (seq->len == 0 || seq->len > 4) |
| 7316 | return -EINVAL; |
| 7317 | if (seq->len + seq->offset > data_size) |
| 7318 | return -EINVAL; |
| 7319 | } |
| 7320 | |
| 7321 | size = sizeof(*cfg); |
| 7322 | size += data_size; |
| 7323 | size += wake_size + wake_mask_size; |
| 7324 | size += tokens_size; |
| 7325 | |
| 7326 | cfg = kzalloc(size, GFP_KERNEL); |
| 7327 | if (!cfg) |
| 7328 | return -ENOMEM; |
| 7329 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7330 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7331 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7332 | ETH_ALEN); |
| 7333 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7334 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7335 | else |
| 7336 | port = 0; |
| 7337 | #ifdef CONFIG_INET |
| 7338 | /* allocate a socket and port for it and use it */ |
| 7339 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7340 | IPPROTO_TCP, &cfg->sock, 1); |
| 7341 | if (err) { |
| 7342 | kfree(cfg); |
| 7343 | return err; |
| 7344 | } |
| 7345 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7346 | sock_release(cfg->sock); |
| 7347 | kfree(cfg); |
| 7348 | return -EADDRINUSE; |
| 7349 | } |
| 7350 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7351 | #else |
| 7352 | if (!port) { |
| 7353 | kfree(cfg); |
| 7354 | return -EINVAL; |
| 7355 | } |
| 7356 | cfg->src_port = port; |
| 7357 | #endif |
| 7358 | |
| 7359 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7360 | cfg->payload_len = data_size; |
| 7361 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7362 | memcpy((void *)cfg->payload, |
| 7363 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7364 | data_size); |
| 7365 | if (seq) |
| 7366 | cfg->payload_seq = *seq; |
| 7367 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7368 | cfg->wake_len = wake_size; |
| 7369 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7370 | memcpy((void *)cfg->wake_data, |
| 7371 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7372 | wake_size); |
| 7373 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7374 | data_size + wake_size; |
| 7375 | memcpy((void *)cfg->wake_mask, |
| 7376 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7377 | wake_mask_size); |
| 7378 | if (tok) { |
| 7379 | cfg->tokens_size = tokens_size; |
| 7380 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7381 | } |
| 7382 | |
| 7383 | trig->tcp = cfg; |
| 7384 | |
| 7385 | return 0; |
| 7386 | } |
| 7387 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7388 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7389 | { |
| 7390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7391 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7392 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7393 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7394 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7395 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7396 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7397 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7398 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7399 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7400 | return -EOPNOTSUPP; |
| 7401 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7402 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7403 | cfg80211_rdev_free_wowlan(rdev); |
| 7404 | rdev->wowlan = NULL; |
| 7405 | goto set_wakeup; |
| 7406 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7407 | |
| 7408 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7409 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7410 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7411 | nl80211_wowlan_policy); |
| 7412 | if (err) |
| 7413 | return err; |
| 7414 | |
| 7415 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7416 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7417 | return -EINVAL; |
| 7418 | new_triggers.any = true; |
| 7419 | } |
| 7420 | |
| 7421 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7422 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7423 | return -EINVAL; |
| 7424 | new_triggers.disconnect = true; |
| 7425 | } |
| 7426 | |
| 7427 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7428 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7429 | return -EINVAL; |
| 7430 | new_triggers.magic_pkt = true; |
| 7431 | } |
| 7432 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7433 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7434 | return -EINVAL; |
| 7435 | |
| 7436 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7437 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7438 | return -EINVAL; |
| 7439 | new_triggers.gtk_rekey_failure = true; |
| 7440 | } |
| 7441 | |
| 7442 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7443 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7444 | return -EINVAL; |
| 7445 | new_triggers.eap_identity_req = true; |
| 7446 | } |
| 7447 | |
| 7448 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7449 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7450 | return -EINVAL; |
| 7451 | new_triggers.four_way_handshake = true; |
| 7452 | } |
| 7453 | |
| 7454 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7455 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7456 | return -EINVAL; |
| 7457 | new_triggers.rfkill_release = true; |
| 7458 | } |
| 7459 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7460 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7461 | struct nlattr *pat; |
| 7462 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7463 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7464 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7465 | |
| 7466 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7467 | rem) |
| 7468 | n_patterns++; |
| 7469 | if (n_patterns > wowlan->n_patterns) |
| 7470 | return -EINVAL; |
| 7471 | |
| 7472 | new_triggers.patterns = kcalloc(n_patterns, |
| 7473 | sizeof(new_triggers.patterns[0]), |
| 7474 | GFP_KERNEL); |
| 7475 | if (!new_triggers.patterns) |
| 7476 | return -ENOMEM; |
| 7477 | |
| 7478 | new_triggers.n_patterns = n_patterns; |
| 7479 | i = 0; |
| 7480 | |
| 7481 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7482 | rem) { |
| 7483 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7484 | nla_data(pat), nla_len(pat), NULL); |
| 7485 | err = -EINVAL; |
| 7486 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7487 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7488 | goto error; |
| 7489 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7490 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7491 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7492 | mask_len) |
| 7493 | goto error; |
| 7494 | if (pat_len > wowlan->pattern_max_len || |
| 7495 | pat_len < wowlan->pattern_min_len) |
| 7496 | goto error; |
| 7497 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7498 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7499 | pkt_offset = 0; |
| 7500 | else |
| 7501 | pkt_offset = nla_get_u32( |
| 7502 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7503 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7504 | goto error; |
| 7505 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7506 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7507 | new_triggers.patterns[i].mask = |
| 7508 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7509 | if (!new_triggers.patterns[i].mask) { |
| 7510 | err = -ENOMEM; |
| 7511 | goto error; |
| 7512 | } |
| 7513 | new_triggers.patterns[i].pattern = |
| 7514 | new_triggers.patterns[i].mask + mask_len; |
| 7515 | memcpy(new_triggers.patterns[i].mask, |
| 7516 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7517 | mask_len); |
| 7518 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7519 | memcpy(new_triggers.patterns[i].pattern, |
| 7520 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7521 | pat_len); |
| 7522 | i++; |
| 7523 | } |
| 7524 | } |
| 7525 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7526 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7527 | err = nl80211_parse_wowlan_tcp( |
| 7528 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7529 | &new_triggers); |
| 7530 | if (err) |
| 7531 | goto error; |
| 7532 | } |
| 7533 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7534 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7535 | if (!ntrig) { |
| 7536 | err = -ENOMEM; |
| 7537 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7538 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7539 | cfg80211_rdev_free_wowlan(rdev); |
| 7540 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7541 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7542 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7543 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7544 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7545 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7546 | return 0; |
| 7547 | error: |
| 7548 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7549 | kfree(new_triggers.patterns[i].mask); |
| 7550 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7551 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7552 | sock_release(new_triggers.tcp->sock); |
| 7553 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7554 | return err; |
| 7555 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7556 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7557 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7558 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7559 | { |
| 7560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7561 | struct net_device *dev = info->user_ptr[1]; |
| 7562 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7563 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7564 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7565 | int err; |
| 7566 | |
| 7567 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7568 | return -EINVAL; |
| 7569 | |
| 7570 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7571 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7572 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7573 | nl80211_rekey_policy); |
| 7574 | if (err) |
| 7575 | return err; |
| 7576 | |
| 7577 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7578 | return -ERANGE; |
| 7579 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7580 | return -ERANGE; |
| 7581 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7582 | return -ERANGE; |
| 7583 | |
| 7584 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7585 | NL80211_KEK_LEN); |
| 7586 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7587 | NL80211_KCK_LEN); |
| 7588 | memcpy(rekey_data.replay_ctr, |
| 7589 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7590 | NL80211_REPLAY_CTR_LEN); |
| 7591 | |
| 7592 | wdev_lock(wdev); |
| 7593 | if (!wdev->current_bss) { |
| 7594 | err = -ENOTCONN; |
| 7595 | goto out; |
| 7596 | } |
| 7597 | |
| 7598 | if (!rdev->ops->set_rekey_data) { |
| 7599 | err = -EOPNOTSUPP; |
| 7600 | goto out; |
| 7601 | } |
| 7602 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7603 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7604 | out: |
| 7605 | wdev_unlock(wdev); |
| 7606 | return err; |
| 7607 | } |
| 7608 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7609 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7610 | struct genl_info *info) |
| 7611 | { |
| 7612 | struct net_device *dev = info->user_ptr[1]; |
| 7613 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7614 | |
| 7615 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7616 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7617 | return -EINVAL; |
| 7618 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7619 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7620 | return -EBUSY; |
| 7621 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7622 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7623 | return 0; |
| 7624 | } |
| 7625 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7626 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7627 | struct genl_info *info) |
| 7628 | { |
| 7629 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7630 | struct net_device *dev = info->user_ptr[1]; |
| 7631 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7632 | struct sk_buff *msg; |
| 7633 | void *hdr; |
| 7634 | const u8 *addr; |
| 7635 | u64 cookie; |
| 7636 | int err; |
| 7637 | |
| 7638 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7639 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7640 | return -EOPNOTSUPP; |
| 7641 | |
| 7642 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7643 | return -EINVAL; |
| 7644 | |
| 7645 | if (!rdev->ops->probe_client) |
| 7646 | return -EOPNOTSUPP; |
| 7647 | |
| 7648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7649 | if (!msg) |
| 7650 | return -ENOMEM; |
| 7651 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7652 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7653 | NL80211_CMD_PROBE_CLIENT); |
| 7654 | |
| 7655 | if (IS_ERR(hdr)) { |
| 7656 | err = PTR_ERR(hdr); |
| 7657 | goto free_msg; |
| 7658 | } |
| 7659 | |
| 7660 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7661 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7662 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7663 | if (err) |
| 7664 | goto free_msg; |
| 7665 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7666 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7667 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7668 | |
| 7669 | genlmsg_end(msg, hdr); |
| 7670 | |
| 7671 | return genlmsg_reply(msg, info); |
| 7672 | |
| 7673 | nla_put_failure: |
| 7674 | err = -ENOBUFS; |
| 7675 | free_msg: |
| 7676 | nlmsg_free(msg); |
| 7677 | return err; |
| 7678 | } |
| 7679 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7680 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7681 | { |
| 7682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7683 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7684 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7685 | |
| 7686 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7687 | return -EOPNOTSUPP; |
| 7688 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7689 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7690 | if (!nreg) |
| 7691 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7692 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7693 | /* First, check if already registered. */ |
| 7694 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7695 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7696 | if (reg->nlportid == info->snd_portid) { |
| 7697 | rv = -EALREADY; |
| 7698 | goto out_err; |
| 7699 | } |
| 7700 | } |
| 7701 | /* Add it to the list */ |
| 7702 | nreg->nlportid = info->snd_portid; |
| 7703 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7704 | |
| 7705 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7706 | |
| 7707 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7708 | out_err: |
| 7709 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7710 | kfree(nreg); |
| 7711 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7712 | } |
| 7713 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7714 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7715 | { |
| 7716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7717 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7718 | int err; |
| 7719 | |
| 7720 | if (!rdev->ops->start_p2p_device) |
| 7721 | return -EOPNOTSUPP; |
| 7722 | |
| 7723 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7724 | return -EOPNOTSUPP; |
| 7725 | |
| 7726 | if (wdev->p2p_started) |
| 7727 | return 0; |
| 7728 | |
| 7729 | mutex_lock(&rdev->devlist_mtx); |
| 7730 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7731 | mutex_unlock(&rdev->devlist_mtx); |
| 7732 | if (err) |
| 7733 | return err; |
| 7734 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7735 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7736 | if (err) |
| 7737 | return err; |
| 7738 | |
| 7739 | wdev->p2p_started = true; |
| 7740 | mutex_lock(&rdev->devlist_mtx); |
| 7741 | rdev->opencount++; |
| 7742 | mutex_unlock(&rdev->devlist_mtx); |
| 7743 | |
| 7744 | return 0; |
| 7745 | } |
| 7746 | |
| 7747 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7748 | { |
| 7749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7750 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7751 | |
| 7752 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7753 | return -EOPNOTSUPP; |
| 7754 | |
| 7755 | if (!rdev->ops->stop_p2p_device) |
| 7756 | return -EOPNOTSUPP; |
| 7757 | |
| 7758 | if (!wdev->p2p_started) |
| 7759 | return 0; |
| 7760 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7761 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7762 | wdev->p2p_started = false; |
| 7763 | |
| 7764 | mutex_lock(&rdev->devlist_mtx); |
| 7765 | rdev->opencount--; |
| 7766 | mutex_unlock(&rdev->devlist_mtx); |
| 7767 | |
| 7768 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7769 | rdev->scan_req->aborted = true; |
| 7770 | ___cfg80211_scan_done(rdev, true); |
| 7771 | } |
| 7772 | |
| 7773 | return 0; |
| 7774 | } |
| 7775 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7776 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7777 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7778 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7779 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7780 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7781 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7782 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7783 | /* 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] | 7784 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7785 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7786 | |
| 7787 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7788 | struct genl_info *info) |
| 7789 | { |
| 7790 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7791 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7792 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7793 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7794 | |
| 7795 | if (rtnl) |
| 7796 | rtnl_lock(); |
| 7797 | |
| 7798 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7799 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7800 | if (IS_ERR(rdev)) { |
| 7801 | if (rtnl) |
| 7802 | rtnl_unlock(); |
| 7803 | return PTR_ERR(rdev); |
| 7804 | } |
| 7805 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7806 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7807 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7808 | mutex_lock(&cfg80211_mutex); |
| 7809 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7810 | info->attrs); |
| 7811 | if (IS_ERR(wdev)) { |
| 7812 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7813 | if (rtnl) |
| 7814 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7815 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7816 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7817 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7818 | dev = wdev->netdev; |
| 7819 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7820 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7821 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7822 | if (!dev) { |
| 7823 | mutex_unlock(&cfg80211_mutex); |
| 7824 | if (rtnl) |
| 7825 | rtnl_unlock(); |
| 7826 | return -EINVAL; |
| 7827 | } |
| 7828 | |
| 7829 | info->user_ptr[1] = dev; |
| 7830 | } else { |
| 7831 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7832 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7833 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7834 | if (dev) { |
| 7835 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7836 | !netif_running(dev)) { |
| 7837 | mutex_unlock(&cfg80211_mutex); |
| 7838 | if (rtnl) |
| 7839 | rtnl_unlock(); |
| 7840 | return -ENETDOWN; |
| 7841 | } |
| 7842 | |
| 7843 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7844 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7845 | if (!wdev->p2p_started) { |
| 7846 | mutex_unlock(&cfg80211_mutex); |
| 7847 | if (rtnl) |
| 7848 | rtnl_unlock(); |
| 7849 | return -ENETDOWN; |
| 7850 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7851 | } |
| 7852 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7853 | cfg80211_lock_rdev(rdev); |
| 7854 | |
| 7855 | mutex_unlock(&cfg80211_mutex); |
| 7856 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7857 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7858 | } |
| 7859 | |
| 7860 | return 0; |
| 7861 | } |
| 7862 | |
| 7863 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7864 | struct genl_info *info) |
| 7865 | { |
| 7866 | if (info->user_ptr[0]) |
| 7867 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7868 | if (info->user_ptr[1]) { |
| 7869 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7870 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7871 | |
| 7872 | if (wdev->netdev) |
| 7873 | dev_put(wdev->netdev); |
| 7874 | } else { |
| 7875 | dev_put(info->user_ptr[1]); |
| 7876 | } |
| 7877 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7878 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7879 | rtnl_unlock(); |
| 7880 | } |
| 7881 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7882 | static struct genl_ops nl80211_ops[] = { |
| 7883 | { |
| 7884 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7885 | .doit = nl80211_get_wiphy, |
| 7886 | .dumpit = nl80211_dump_wiphy, |
| 7887 | .policy = nl80211_policy, |
| 7888 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7889 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7890 | }, |
| 7891 | { |
| 7892 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7893 | .doit = nl80211_set_wiphy, |
| 7894 | .policy = nl80211_policy, |
| 7895 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7896 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7897 | }, |
| 7898 | { |
| 7899 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7900 | .doit = nl80211_get_interface, |
| 7901 | .dumpit = nl80211_dump_interface, |
| 7902 | .policy = nl80211_policy, |
| 7903 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7904 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7905 | }, |
| 7906 | { |
| 7907 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7908 | .doit = nl80211_set_interface, |
| 7909 | .policy = nl80211_policy, |
| 7910 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7911 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7912 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7913 | }, |
| 7914 | { |
| 7915 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7916 | .doit = nl80211_new_interface, |
| 7917 | .policy = nl80211_policy, |
| 7918 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7919 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7920 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7921 | }, |
| 7922 | { |
| 7923 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7924 | .doit = nl80211_del_interface, |
| 7925 | .policy = nl80211_policy, |
| 7926 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7927 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7928 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7929 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7930 | { |
| 7931 | .cmd = NL80211_CMD_GET_KEY, |
| 7932 | .doit = nl80211_get_key, |
| 7933 | .policy = nl80211_policy, |
| 7934 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7936 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7937 | }, |
| 7938 | { |
| 7939 | .cmd = NL80211_CMD_SET_KEY, |
| 7940 | .doit = nl80211_set_key, |
| 7941 | .policy = nl80211_policy, |
| 7942 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7943 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7944 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7945 | }, |
| 7946 | { |
| 7947 | .cmd = NL80211_CMD_NEW_KEY, |
| 7948 | .doit = nl80211_new_key, |
| 7949 | .policy = nl80211_policy, |
| 7950 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7951 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7952 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7953 | }, |
| 7954 | { |
| 7955 | .cmd = NL80211_CMD_DEL_KEY, |
| 7956 | .doit = nl80211_del_key, |
| 7957 | .policy = nl80211_policy, |
| 7958 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7959 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7960 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7961 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7962 | { |
| 7963 | .cmd = NL80211_CMD_SET_BEACON, |
| 7964 | .policy = nl80211_policy, |
| 7965 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7966 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7968 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7969 | }, |
| 7970 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7971 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7972 | .policy = nl80211_policy, |
| 7973 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7974 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7976 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7977 | }, |
| 7978 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7979 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7980 | .policy = nl80211_policy, |
| 7981 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7982 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7984 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7985 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7986 | { |
| 7987 | .cmd = NL80211_CMD_GET_STATION, |
| 7988 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7989 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7990 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7991 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7992 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7993 | }, |
| 7994 | { |
| 7995 | .cmd = NL80211_CMD_SET_STATION, |
| 7996 | .doit = nl80211_set_station, |
| 7997 | .policy = nl80211_policy, |
| 7998 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7999 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8000 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8001 | }, |
| 8002 | { |
| 8003 | .cmd = NL80211_CMD_NEW_STATION, |
| 8004 | .doit = nl80211_new_station, |
| 8005 | .policy = nl80211_policy, |
| 8006 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8007 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8008 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8009 | }, |
| 8010 | { |
| 8011 | .cmd = NL80211_CMD_DEL_STATION, |
| 8012 | .doit = nl80211_del_station, |
| 8013 | .policy = nl80211_policy, |
| 8014 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8016 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8017 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8018 | { |
| 8019 | .cmd = NL80211_CMD_GET_MPATH, |
| 8020 | .doit = nl80211_get_mpath, |
| 8021 | .dumpit = nl80211_dump_mpath, |
| 8022 | .policy = nl80211_policy, |
| 8023 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8024 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8025 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8026 | }, |
| 8027 | { |
| 8028 | .cmd = NL80211_CMD_SET_MPATH, |
| 8029 | .doit = nl80211_set_mpath, |
| 8030 | .policy = nl80211_policy, |
| 8031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8032 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8033 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8034 | }, |
| 8035 | { |
| 8036 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8037 | .doit = nl80211_new_mpath, |
| 8038 | .policy = nl80211_policy, |
| 8039 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8041 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8042 | }, |
| 8043 | { |
| 8044 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8045 | .doit = nl80211_del_mpath, |
| 8046 | .policy = nl80211_policy, |
| 8047 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8048 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8049 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8050 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8051 | { |
| 8052 | .cmd = NL80211_CMD_SET_BSS, |
| 8053 | .doit = nl80211_set_bss, |
| 8054 | .policy = nl80211_policy, |
| 8055 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8056 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8057 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8058 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8059 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8060 | .cmd = NL80211_CMD_GET_REG, |
| 8061 | .doit = nl80211_get_reg, |
| 8062 | .policy = nl80211_policy, |
| 8063 | /* can be retrieved by unprivileged users */ |
| 8064 | }, |
| 8065 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8066 | .cmd = NL80211_CMD_SET_REG, |
| 8067 | .doit = nl80211_set_reg, |
| 8068 | .policy = nl80211_policy, |
| 8069 | .flags = GENL_ADMIN_PERM, |
| 8070 | }, |
| 8071 | { |
| 8072 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8073 | .doit = nl80211_req_set_reg, |
| 8074 | .policy = nl80211_policy, |
| 8075 | .flags = GENL_ADMIN_PERM, |
| 8076 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8077 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8078 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8079 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8080 | .policy = nl80211_policy, |
| 8081 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8082 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8083 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8084 | }, |
| 8085 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8086 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8087 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8088 | .policy = nl80211_policy, |
| 8089 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8090 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8091 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8092 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8093 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8094 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8095 | .doit = nl80211_trigger_scan, |
| 8096 | .policy = nl80211_policy, |
| 8097 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8098 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8099 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8100 | }, |
| 8101 | { |
| 8102 | .cmd = NL80211_CMD_GET_SCAN, |
| 8103 | .policy = nl80211_policy, |
| 8104 | .dumpit = nl80211_dump_scan, |
| 8105 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8106 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8107 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8108 | .doit = nl80211_start_sched_scan, |
| 8109 | .policy = nl80211_policy, |
| 8110 | .flags = GENL_ADMIN_PERM, |
| 8111 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8112 | NL80211_FLAG_NEED_RTNL, |
| 8113 | }, |
| 8114 | { |
| 8115 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8116 | .doit = nl80211_stop_sched_scan, |
| 8117 | .policy = nl80211_policy, |
| 8118 | .flags = GENL_ADMIN_PERM, |
| 8119 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8120 | NL80211_FLAG_NEED_RTNL, |
| 8121 | }, |
| 8122 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8123 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8124 | .doit = nl80211_authenticate, |
| 8125 | .policy = nl80211_policy, |
| 8126 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8127 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8128 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8129 | }, |
| 8130 | { |
| 8131 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8132 | .doit = nl80211_associate, |
| 8133 | .policy = nl80211_policy, |
| 8134 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8135 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8136 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8137 | }, |
| 8138 | { |
| 8139 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8140 | .doit = nl80211_deauthenticate, |
| 8141 | .policy = nl80211_policy, |
| 8142 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8143 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8144 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8145 | }, |
| 8146 | { |
| 8147 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8148 | .doit = nl80211_disassociate, |
| 8149 | .policy = nl80211_policy, |
| 8150 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8151 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8152 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8153 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8154 | { |
| 8155 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8156 | .doit = nl80211_join_ibss, |
| 8157 | .policy = nl80211_policy, |
| 8158 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8159 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8160 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8161 | }, |
| 8162 | { |
| 8163 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8164 | .doit = nl80211_leave_ibss, |
| 8165 | .policy = nl80211_policy, |
| 8166 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8167 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8168 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8169 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8170 | #ifdef CONFIG_NL80211_TESTMODE |
| 8171 | { |
| 8172 | .cmd = NL80211_CMD_TESTMODE, |
| 8173 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8174 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8175 | .policy = nl80211_policy, |
| 8176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8177 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8178 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8179 | }, |
| 8180 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8181 | { |
| 8182 | .cmd = NL80211_CMD_CONNECT, |
| 8183 | .doit = nl80211_connect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8188 | }, |
| 8189 | { |
| 8190 | .cmd = NL80211_CMD_DISCONNECT, |
| 8191 | .doit = nl80211_disconnect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8196 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8197 | { |
| 8198 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8199 | .doit = nl80211_wiphy_netns, |
| 8200 | .policy = nl80211_policy, |
| 8201 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8202 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8203 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8204 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8205 | { |
| 8206 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8207 | .policy = nl80211_policy, |
| 8208 | .dumpit = nl80211_dump_survey, |
| 8209 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8210 | { |
| 8211 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8212 | .doit = nl80211_setdel_pmksa, |
| 8213 | .policy = nl80211_policy, |
| 8214 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8215 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8216 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8217 | }, |
| 8218 | { |
| 8219 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8220 | .doit = nl80211_setdel_pmksa, |
| 8221 | .policy = nl80211_policy, |
| 8222 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8224 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8225 | }, |
| 8226 | { |
| 8227 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8228 | .doit = nl80211_flush_pmksa, |
| 8229 | .policy = nl80211_policy, |
| 8230 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8231 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8232 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8233 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8234 | { |
| 8235 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8236 | .doit = nl80211_remain_on_channel, |
| 8237 | .policy = nl80211_policy, |
| 8238 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8239 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8240 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8241 | }, |
| 8242 | { |
| 8243 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8244 | .doit = nl80211_cancel_remain_on_channel, |
| 8245 | .policy = nl80211_policy, |
| 8246 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8247 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8248 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8249 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8250 | { |
| 8251 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8252 | .doit = nl80211_set_tx_bitrate_mask, |
| 8253 | .policy = nl80211_policy, |
| 8254 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8255 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8256 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8257 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8258 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8259 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8260 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8261 | .policy = nl80211_policy, |
| 8262 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8263 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8264 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8265 | }, |
| 8266 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8267 | .cmd = NL80211_CMD_FRAME, |
| 8268 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8269 | .policy = nl80211_policy, |
| 8270 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8271 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8272 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8273 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8274 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8275 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8276 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8277 | .policy = nl80211_policy, |
| 8278 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8279 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8280 | NL80211_FLAG_NEED_RTNL, |
| 8281 | }, |
| 8282 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8283 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8284 | .doit = nl80211_set_power_save, |
| 8285 | .policy = nl80211_policy, |
| 8286 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8287 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8288 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8289 | }, |
| 8290 | { |
| 8291 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8292 | .doit = nl80211_get_power_save, |
| 8293 | .policy = nl80211_policy, |
| 8294 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8295 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8296 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8297 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8298 | { |
| 8299 | .cmd = NL80211_CMD_SET_CQM, |
| 8300 | .doit = nl80211_set_cqm, |
| 8301 | .policy = nl80211_policy, |
| 8302 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8303 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8304 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8305 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8306 | { |
| 8307 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8308 | .doit = nl80211_set_channel, |
| 8309 | .policy = nl80211_policy, |
| 8310 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8311 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8312 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8313 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8314 | { |
| 8315 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8316 | .doit = nl80211_set_wds_peer, |
| 8317 | .policy = nl80211_policy, |
| 8318 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8319 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8320 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8321 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8322 | { |
| 8323 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8324 | .doit = nl80211_join_mesh, |
| 8325 | .policy = nl80211_policy, |
| 8326 | .flags = GENL_ADMIN_PERM, |
| 8327 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8328 | NL80211_FLAG_NEED_RTNL, |
| 8329 | }, |
| 8330 | { |
| 8331 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8332 | .doit = nl80211_leave_mesh, |
| 8333 | .policy = nl80211_policy, |
| 8334 | .flags = GENL_ADMIN_PERM, |
| 8335 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8336 | NL80211_FLAG_NEED_RTNL, |
| 8337 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8338 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8339 | { |
| 8340 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8341 | .doit = nl80211_get_wowlan, |
| 8342 | .policy = nl80211_policy, |
| 8343 | /* can be retrieved by unprivileged users */ |
| 8344 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8345 | NL80211_FLAG_NEED_RTNL, |
| 8346 | }, |
| 8347 | { |
| 8348 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8349 | .doit = nl80211_set_wowlan, |
| 8350 | .policy = nl80211_policy, |
| 8351 | .flags = GENL_ADMIN_PERM, |
| 8352 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8353 | NL80211_FLAG_NEED_RTNL, |
| 8354 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8355 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8356 | { |
| 8357 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8358 | .doit = nl80211_set_rekey_data, |
| 8359 | .policy = nl80211_policy, |
| 8360 | .flags = GENL_ADMIN_PERM, |
| 8361 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8362 | NL80211_FLAG_NEED_RTNL, |
| 8363 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8364 | { |
| 8365 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8366 | .doit = nl80211_tdls_mgmt, |
| 8367 | .policy = nl80211_policy, |
| 8368 | .flags = GENL_ADMIN_PERM, |
| 8369 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8370 | NL80211_FLAG_NEED_RTNL, |
| 8371 | }, |
| 8372 | { |
| 8373 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8374 | .doit = nl80211_tdls_oper, |
| 8375 | .policy = nl80211_policy, |
| 8376 | .flags = GENL_ADMIN_PERM, |
| 8377 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8378 | NL80211_FLAG_NEED_RTNL, |
| 8379 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8380 | { |
| 8381 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8382 | .doit = nl80211_register_unexpected_frame, |
| 8383 | .policy = nl80211_policy, |
| 8384 | .flags = GENL_ADMIN_PERM, |
| 8385 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8386 | NL80211_FLAG_NEED_RTNL, |
| 8387 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8388 | { |
| 8389 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8390 | .doit = nl80211_probe_client, |
| 8391 | .policy = nl80211_policy, |
| 8392 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8393 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8394 | NL80211_FLAG_NEED_RTNL, |
| 8395 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8396 | { |
| 8397 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8398 | .doit = nl80211_register_beacons, |
| 8399 | .policy = nl80211_policy, |
| 8400 | .flags = GENL_ADMIN_PERM, |
| 8401 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8402 | NL80211_FLAG_NEED_RTNL, |
| 8403 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8404 | { |
| 8405 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8406 | .doit = nl80211_set_noack_map, |
| 8407 | .policy = nl80211_policy, |
| 8408 | .flags = GENL_ADMIN_PERM, |
| 8409 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8410 | NL80211_FLAG_NEED_RTNL, |
| 8411 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8412 | { |
| 8413 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8414 | .doit = nl80211_start_p2p_device, |
| 8415 | .policy = nl80211_policy, |
| 8416 | .flags = GENL_ADMIN_PERM, |
| 8417 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8418 | NL80211_FLAG_NEED_RTNL, |
| 8419 | }, |
| 8420 | { |
| 8421 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8422 | .doit = nl80211_stop_p2p_device, |
| 8423 | .policy = nl80211_policy, |
| 8424 | .flags = GENL_ADMIN_PERM, |
| 8425 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8426 | NL80211_FLAG_NEED_RTNL, |
| 8427 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8428 | { |
| 8429 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8430 | .doit = nl80211_set_mcast_rate, |
| 8431 | .policy = nl80211_policy, |
| 8432 | .flags = GENL_ADMIN_PERM, |
| 8433 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8434 | NL80211_FLAG_NEED_RTNL, |
| 8435 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8436 | { |
| 8437 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8438 | .doit = nl80211_set_mac_acl, |
| 8439 | .policy = nl80211_policy, |
| 8440 | .flags = GENL_ADMIN_PERM, |
| 8441 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8442 | NL80211_FLAG_NEED_RTNL, |
| 8443 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8444 | { |
| 8445 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8446 | .doit = nl80211_start_radar_detection, |
| 8447 | .policy = nl80211_policy, |
| 8448 | .flags = GENL_ADMIN_PERM, |
| 8449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8450 | NL80211_FLAG_NEED_RTNL, |
| 8451 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8452 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8453 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8454 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8455 | .name = "mlme", |
| 8456 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8457 | |
| 8458 | /* multicast groups */ |
| 8459 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8460 | .name = "config", |
| 8461 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8462 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8463 | .name = "scan", |
| 8464 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8465 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8466 | .name = "regulatory", |
| 8467 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8468 | |
| 8469 | /* notification functions */ |
| 8470 | |
| 8471 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8472 | { |
| 8473 | struct sk_buff *msg; |
| 8474 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8475 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8476 | if (!msg) |
| 8477 | return; |
| 8478 | |
| 8479 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8480 | nlmsg_free(msg); |
| 8481 | return; |
| 8482 | } |
| 8483 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8484 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8485 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8486 | } |
| 8487 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8488 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8489 | struct cfg80211_registered_device *rdev) |
| 8490 | { |
| 8491 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8492 | struct nlattr *nest; |
| 8493 | int i; |
| 8494 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8495 | ASSERT_RDEV_LOCK(rdev); |
| 8496 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8497 | if (WARN_ON(!req)) |
| 8498 | return 0; |
| 8499 | |
| 8500 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8501 | if (!nest) |
| 8502 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8503 | for (i = 0; i < req->n_ssids; i++) { |
| 8504 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8505 | goto nla_put_failure; |
| 8506 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8507 | nla_nest_end(msg, nest); |
| 8508 | |
| 8509 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8510 | if (!nest) |
| 8511 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8512 | for (i = 0; i < req->n_channels; i++) { |
| 8513 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8514 | goto nla_put_failure; |
| 8515 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8516 | nla_nest_end(msg, nest); |
| 8517 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8518 | if (req->ie && |
| 8519 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8520 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8521 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8522 | if (req->flags) |
| 8523 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8524 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8525 | return 0; |
| 8526 | nla_put_failure: |
| 8527 | return -ENOBUFS; |
| 8528 | } |
| 8529 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8530 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8531 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8532 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8533 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8534 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8535 | { |
| 8536 | void *hdr; |
| 8537 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8538 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8539 | if (!hdr) |
| 8540 | return -1; |
| 8541 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8543 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8544 | wdev->netdev->ifindex)) || |
| 8545 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8546 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8547 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8548 | /* ignore errors and send incomplete event anyway */ |
| 8549 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8550 | |
| 8551 | return genlmsg_end(msg, hdr); |
| 8552 | |
| 8553 | nla_put_failure: |
| 8554 | genlmsg_cancel(msg, hdr); |
| 8555 | return -EMSGSIZE; |
| 8556 | } |
| 8557 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8558 | static int |
| 8559 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8560 | struct cfg80211_registered_device *rdev, |
| 8561 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8562 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8563 | { |
| 8564 | void *hdr; |
| 8565 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8566 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8567 | if (!hdr) |
| 8568 | return -1; |
| 8569 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8570 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8571 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8572 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8573 | |
| 8574 | return genlmsg_end(msg, hdr); |
| 8575 | |
| 8576 | nla_put_failure: |
| 8577 | genlmsg_cancel(msg, hdr); |
| 8578 | return -EMSGSIZE; |
| 8579 | } |
| 8580 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8581 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8582 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8583 | { |
| 8584 | struct sk_buff *msg; |
| 8585 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8587 | if (!msg) |
| 8588 | return; |
| 8589 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8590 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8591 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8592 | nlmsg_free(msg); |
| 8593 | return; |
| 8594 | } |
| 8595 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8596 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8597 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8598 | } |
| 8599 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8600 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8601 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8602 | { |
| 8603 | struct sk_buff *msg; |
| 8604 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8605 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8606 | if (!msg) |
| 8607 | return; |
| 8608 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8609 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8610 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8611 | nlmsg_free(msg); |
| 8612 | return; |
| 8613 | } |
| 8614 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8615 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8616 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8617 | } |
| 8618 | |
| 8619 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8620 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8621 | { |
| 8622 | struct sk_buff *msg; |
| 8623 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8624 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8625 | if (!msg) |
| 8626 | return; |
| 8627 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8628 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8629 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8630 | nlmsg_free(msg); |
| 8631 | return; |
| 8632 | } |
| 8633 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8634 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8635 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8636 | } |
| 8637 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8638 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8639 | struct net_device *netdev) |
| 8640 | { |
| 8641 | struct sk_buff *msg; |
| 8642 | |
| 8643 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8644 | if (!msg) |
| 8645 | return; |
| 8646 | |
| 8647 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8648 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8649 | nlmsg_free(msg); |
| 8650 | return; |
| 8651 | } |
| 8652 | |
| 8653 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8654 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8655 | } |
| 8656 | |
| 8657 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8658 | struct net_device *netdev, u32 cmd) |
| 8659 | { |
| 8660 | struct sk_buff *msg; |
| 8661 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8662 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8663 | if (!msg) |
| 8664 | return; |
| 8665 | |
| 8666 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8667 | nlmsg_free(msg); |
| 8668 | return; |
| 8669 | } |
| 8670 | |
| 8671 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8672 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8673 | } |
| 8674 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8675 | /* |
| 8676 | * This can happen on global regulatory changes or device specific settings |
| 8677 | * based on custom world regulatory domains. |
| 8678 | */ |
| 8679 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8680 | { |
| 8681 | struct sk_buff *msg; |
| 8682 | void *hdr; |
| 8683 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8684 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8685 | if (!msg) |
| 8686 | return; |
| 8687 | |
| 8688 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8689 | if (!hdr) { |
| 8690 | nlmsg_free(msg); |
| 8691 | return; |
| 8692 | } |
| 8693 | |
| 8694 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8695 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8696 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8697 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8698 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8699 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8700 | NL80211_REGDOM_TYPE_WORLD)) |
| 8701 | goto nla_put_failure; |
| 8702 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8703 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8704 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8705 | goto nla_put_failure; |
| 8706 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8707 | request->intersect) { |
| 8708 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8709 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8710 | goto nla_put_failure; |
| 8711 | } else { |
| 8712 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8713 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8714 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8715 | request->alpha2)) |
| 8716 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8717 | } |
| 8718 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8719 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8720 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8721 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8722 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8723 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8724 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8725 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8726 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8727 | GFP_ATOMIC); |
| 8728 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8729 | |
| 8730 | return; |
| 8731 | |
| 8732 | nla_put_failure: |
| 8733 | genlmsg_cancel(msg, hdr); |
| 8734 | nlmsg_free(msg); |
| 8735 | } |
| 8736 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8737 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8738 | struct net_device *netdev, |
| 8739 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8740 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8741 | { |
| 8742 | struct sk_buff *msg; |
| 8743 | void *hdr; |
| 8744 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8746 | if (!msg) |
| 8747 | return; |
| 8748 | |
| 8749 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8750 | if (!hdr) { |
| 8751 | nlmsg_free(msg); |
| 8752 | return; |
| 8753 | } |
| 8754 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8755 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8756 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8757 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8758 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8759 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8760 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8761 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8762 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8763 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8764 | return; |
| 8765 | |
| 8766 | nla_put_failure: |
| 8767 | genlmsg_cancel(msg, hdr); |
| 8768 | nlmsg_free(msg); |
| 8769 | } |
| 8770 | |
| 8771 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8772 | struct net_device *netdev, const u8 *buf, |
| 8773 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8774 | { |
| 8775 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8776 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8777 | } |
| 8778 | |
| 8779 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8780 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8781 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8782 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8783 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8784 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8785 | } |
| 8786 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8787 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8788 | struct net_device *netdev, const u8 *buf, |
| 8789 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8790 | { |
| 8791 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8792 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8793 | } |
| 8794 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8795 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8796 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8797 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8798 | { |
| 8799 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8800 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8801 | } |
| 8802 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8803 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8804 | struct net_device *netdev, const u8 *buf, |
| 8805 | size_t len, gfp_t gfp) |
| 8806 | { |
| 8807 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8808 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8809 | } |
| 8810 | |
| 8811 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8812 | struct net_device *netdev, const u8 *buf, |
| 8813 | size_t len, gfp_t gfp) |
| 8814 | { |
| 8815 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8816 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8817 | } |
| 8818 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8819 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8820 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8821 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8822 | { |
| 8823 | struct sk_buff *msg; |
| 8824 | void *hdr; |
| 8825 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8826 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8827 | if (!msg) |
| 8828 | return; |
| 8829 | |
| 8830 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8831 | if (!hdr) { |
| 8832 | nlmsg_free(msg); |
| 8833 | return; |
| 8834 | } |
| 8835 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8836 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8837 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8838 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8839 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8840 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8841 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8842 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8843 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8844 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8845 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8846 | return; |
| 8847 | |
| 8848 | nla_put_failure: |
| 8849 | genlmsg_cancel(msg, hdr); |
| 8850 | nlmsg_free(msg); |
| 8851 | } |
| 8852 | |
| 8853 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8854 | struct net_device *netdev, const u8 *addr, |
| 8855 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8856 | { |
| 8857 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8858 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8859 | } |
| 8860 | |
| 8861 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8862 | struct net_device *netdev, const u8 *addr, |
| 8863 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8864 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8865 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8866 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8867 | } |
| 8868 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8869 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8870 | struct net_device *netdev, const u8 *bssid, |
| 8871 | const u8 *req_ie, size_t req_ie_len, |
| 8872 | const u8 *resp_ie, size_t resp_ie_len, |
| 8873 | u16 status, gfp_t gfp) |
| 8874 | { |
| 8875 | struct sk_buff *msg; |
| 8876 | void *hdr; |
| 8877 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8879 | if (!msg) |
| 8880 | return; |
| 8881 | |
| 8882 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8883 | if (!hdr) { |
| 8884 | nlmsg_free(msg); |
| 8885 | return; |
| 8886 | } |
| 8887 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8888 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8889 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8890 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8891 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8892 | (req_ie && |
| 8893 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8894 | (resp_ie && |
| 8895 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8896 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8897 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8898 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8899 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8900 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8901 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8902 | return; |
| 8903 | |
| 8904 | nla_put_failure: |
| 8905 | genlmsg_cancel(msg, hdr); |
| 8906 | nlmsg_free(msg); |
| 8907 | |
| 8908 | } |
| 8909 | |
| 8910 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8911 | struct net_device *netdev, const u8 *bssid, |
| 8912 | const u8 *req_ie, size_t req_ie_len, |
| 8913 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8914 | { |
| 8915 | struct sk_buff *msg; |
| 8916 | void *hdr; |
| 8917 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8918 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8919 | if (!msg) |
| 8920 | return; |
| 8921 | |
| 8922 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8923 | if (!hdr) { |
| 8924 | nlmsg_free(msg); |
| 8925 | return; |
| 8926 | } |
| 8927 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8928 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8929 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8930 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8931 | (req_ie && |
| 8932 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8933 | (resp_ie && |
| 8934 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8935 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8936 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8937 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8938 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8939 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8940 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8941 | return; |
| 8942 | |
| 8943 | nla_put_failure: |
| 8944 | genlmsg_cancel(msg, hdr); |
| 8945 | nlmsg_free(msg); |
| 8946 | |
| 8947 | } |
| 8948 | |
| 8949 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8950 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8951 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8952 | { |
| 8953 | struct sk_buff *msg; |
| 8954 | void *hdr; |
| 8955 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8956 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8957 | if (!msg) |
| 8958 | return; |
| 8959 | |
| 8960 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8961 | if (!hdr) { |
| 8962 | nlmsg_free(msg); |
| 8963 | return; |
| 8964 | } |
| 8965 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8966 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8967 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8968 | (from_ap && reason && |
| 8969 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8970 | (from_ap && |
| 8971 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8972 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8973 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8974 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8975 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8976 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8977 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8978 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8979 | return; |
| 8980 | |
| 8981 | nla_put_failure: |
| 8982 | genlmsg_cancel(msg, hdr); |
| 8983 | nlmsg_free(msg); |
| 8984 | |
| 8985 | } |
| 8986 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8987 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8988 | struct net_device *netdev, const u8 *bssid, |
| 8989 | gfp_t gfp) |
| 8990 | { |
| 8991 | struct sk_buff *msg; |
| 8992 | void *hdr; |
| 8993 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8994 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8995 | if (!msg) |
| 8996 | return; |
| 8997 | |
| 8998 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8999 | if (!hdr) { |
| 9000 | nlmsg_free(msg); |
| 9001 | return; |
| 9002 | } |
| 9003 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9004 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9005 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9006 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9007 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9008 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9009 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9010 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9011 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9012 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9013 | return; |
| 9014 | |
| 9015 | nla_put_failure: |
| 9016 | genlmsg_cancel(msg, hdr); |
| 9017 | nlmsg_free(msg); |
| 9018 | } |
| 9019 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9020 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 9021 | struct net_device *netdev, |
| 9022 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 9023 | gfp_t gfp) |
| 9024 | { |
| 9025 | struct sk_buff *msg; |
| 9026 | void *hdr; |
| 9027 | |
| 9028 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9029 | if (!msg) |
| 9030 | return; |
| 9031 | |
| 9032 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9033 | if (!hdr) { |
| 9034 | nlmsg_free(msg); |
| 9035 | return; |
| 9036 | } |
| 9037 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9039 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9040 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 9041 | (ie_len && ie && |
| 9042 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9043 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9044 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9045 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9046 | |
| 9047 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9048 | nl80211_mlme_mcgrp.id, gfp); |
| 9049 | return; |
| 9050 | |
| 9051 | nla_put_failure: |
| 9052 | genlmsg_cancel(msg, hdr); |
| 9053 | nlmsg_free(msg); |
| 9054 | } |
| 9055 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9056 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9057 | struct net_device *netdev, const u8 *addr, |
| 9058 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9059 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9060 | { |
| 9061 | struct sk_buff *msg; |
| 9062 | void *hdr; |
| 9063 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9064 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9065 | if (!msg) |
| 9066 | return; |
| 9067 | |
| 9068 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9069 | if (!hdr) { |
| 9070 | nlmsg_free(msg); |
| 9071 | return; |
| 9072 | } |
| 9073 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9074 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9075 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9076 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9077 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9078 | (key_id != -1 && |
| 9079 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9080 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9081 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9082 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9083 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9084 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9085 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9086 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9087 | return; |
| 9088 | |
| 9089 | nla_put_failure: |
| 9090 | genlmsg_cancel(msg, hdr); |
| 9091 | nlmsg_free(msg); |
| 9092 | } |
| 9093 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9094 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9095 | struct ieee80211_channel *channel_before, |
| 9096 | struct ieee80211_channel *channel_after) |
| 9097 | { |
| 9098 | struct sk_buff *msg; |
| 9099 | void *hdr; |
| 9100 | struct nlattr *nl_freq; |
| 9101 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9103 | if (!msg) |
| 9104 | return; |
| 9105 | |
| 9106 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9107 | if (!hdr) { |
| 9108 | nlmsg_free(msg); |
| 9109 | return; |
| 9110 | } |
| 9111 | |
| 9112 | /* |
| 9113 | * Since we are applying the beacon hint to a wiphy we know its |
| 9114 | * wiphy_idx is valid |
| 9115 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9116 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9117 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9118 | |
| 9119 | /* Before */ |
| 9120 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9121 | if (!nl_freq) |
| 9122 | goto nla_put_failure; |
| 9123 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 9124 | goto nla_put_failure; |
| 9125 | nla_nest_end(msg, nl_freq); |
| 9126 | |
| 9127 | /* After */ |
| 9128 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9129 | if (!nl_freq) |
| 9130 | goto nla_put_failure; |
| 9131 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 9132 | goto nla_put_failure; |
| 9133 | nla_nest_end(msg, nl_freq); |
| 9134 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9135 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9136 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9137 | rcu_read_lock(); |
| 9138 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9139 | GFP_ATOMIC); |
| 9140 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9141 | |
| 9142 | return; |
| 9143 | |
| 9144 | nla_put_failure: |
| 9145 | genlmsg_cancel(msg, hdr); |
| 9146 | nlmsg_free(msg); |
| 9147 | } |
| 9148 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9149 | static void nl80211_send_remain_on_chan_event( |
| 9150 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9151 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9152 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9153 | unsigned int duration, gfp_t gfp) |
| 9154 | { |
| 9155 | struct sk_buff *msg; |
| 9156 | void *hdr; |
| 9157 | |
| 9158 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9159 | if (!msg) |
| 9160 | return; |
| 9161 | |
| 9162 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9163 | if (!hdr) { |
| 9164 | nlmsg_free(msg); |
| 9165 | return; |
| 9166 | } |
| 9167 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9169 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9170 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9171 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9172 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9173 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9174 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9175 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9176 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9177 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9178 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9179 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9180 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9181 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9182 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9183 | |
| 9184 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9185 | nl80211_mlme_mcgrp.id, gfp); |
| 9186 | return; |
| 9187 | |
| 9188 | nla_put_failure: |
| 9189 | genlmsg_cancel(msg, hdr); |
| 9190 | nlmsg_free(msg); |
| 9191 | } |
| 9192 | |
| 9193 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9194 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9195 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9196 | unsigned int duration, gfp_t gfp) |
| 9197 | { |
| 9198 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9199 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9200 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9201 | } |
| 9202 | |
| 9203 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9204 | struct cfg80211_registered_device *rdev, |
| 9205 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9206 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9207 | { |
| 9208 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9209 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9210 | } |
| 9211 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9212 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 9213 | struct net_device *dev, const u8 *mac_addr, |
| 9214 | struct station_info *sinfo, gfp_t gfp) |
| 9215 | { |
| 9216 | struct sk_buff *msg; |
| 9217 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9218 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9219 | if (!msg) |
| 9220 | return; |
| 9221 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9222 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9223 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9224 | nlmsg_free(msg); |
| 9225 | return; |
| 9226 | } |
| 9227 | |
| 9228 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9229 | nl80211_mlme_mcgrp.id, gfp); |
| 9230 | } |
| 9231 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9232 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 9233 | struct net_device *dev, const u8 *mac_addr, |
| 9234 | gfp_t gfp) |
| 9235 | { |
| 9236 | struct sk_buff *msg; |
| 9237 | void *hdr; |
| 9238 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9239 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9240 | if (!msg) |
| 9241 | return; |
| 9242 | |
| 9243 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9244 | if (!hdr) { |
| 9245 | nlmsg_free(msg); |
| 9246 | return; |
| 9247 | } |
| 9248 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9249 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9250 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9251 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9252 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9253 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9254 | |
| 9255 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9256 | nl80211_mlme_mcgrp.id, gfp); |
| 9257 | return; |
| 9258 | |
| 9259 | nla_put_failure: |
| 9260 | genlmsg_cancel(msg, hdr); |
| 9261 | nlmsg_free(msg); |
| 9262 | } |
| 9263 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9264 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 9265 | struct net_device *dev, const u8 *mac_addr, |
| 9266 | enum nl80211_connect_failed_reason reason, |
| 9267 | gfp_t gfp) |
| 9268 | { |
| 9269 | struct sk_buff *msg; |
| 9270 | void *hdr; |
| 9271 | |
| 9272 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9273 | if (!msg) |
| 9274 | return; |
| 9275 | |
| 9276 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9277 | if (!hdr) { |
| 9278 | nlmsg_free(msg); |
| 9279 | return; |
| 9280 | } |
| 9281 | |
| 9282 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9283 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9284 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9285 | goto nla_put_failure; |
| 9286 | |
| 9287 | genlmsg_end(msg, hdr); |
| 9288 | |
| 9289 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9290 | nl80211_mlme_mcgrp.id, gfp); |
| 9291 | return; |
| 9292 | |
| 9293 | nla_put_failure: |
| 9294 | genlmsg_cancel(msg, hdr); |
| 9295 | nlmsg_free(msg); |
| 9296 | } |
| 9297 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9298 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9299 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9300 | { |
| 9301 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9302 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9303 | struct sk_buff *msg; |
| 9304 | void *hdr; |
| 9305 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9306 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9307 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9308 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9309 | return false; |
| 9310 | |
| 9311 | msg = nlmsg_new(100, gfp); |
| 9312 | if (!msg) |
| 9313 | return true; |
| 9314 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9315 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9316 | if (!hdr) { |
| 9317 | nlmsg_free(msg); |
| 9318 | return true; |
| 9319 | } |
| 9320 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9322 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9323 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9324 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9325 | |
| 9326 | err = genlmsg_end(msg, hdr); |
| 9327 | if (err < 0) { |
| 9328 | nlmsg_free(msg); |
| 9329 | return true; |
| 9330 | } |
| 9331 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9332 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9333 | return true; |
| 9334 | |
| 9335 | nla_put_failure: |
| 9336 | genlmsg_cancel(msg, hdr); |
| 9337 | nlmsg_free(msg); |
| 9338 | return true; |
| 9339 | } |
| 9340 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9341 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 9342 | { |
| 9343 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9344 | addr, gfp); |
| 9345 | } |
| 9346 | |
| 9347 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 9348 | const u8 *addr, gfp_t gfp) |
| 9349 | { |
| 9350 | return __nl80211_unexpected_frame(dev, |
| 9351 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9352 | addr, gfp); |
| 9353 | } |
| 9354 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9355 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9356 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9357 | int freq, int sig_dbm, |
| 9358 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9359 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9360 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9361 | struct sk_buff *msg; |
| 9362 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9363 | |
| 9364 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9365 | if (!msg) |
| 9366 | return -ENOMEM; |
| 9367 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9368 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9369 | if (!hdr) { |
| 9370 | nlmsg_free(msg); |
| 9371 | return -ENOMEM; |
| 9372 | } |
| 9373 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9374 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9375 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9376 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9377 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9378 | (sig_dbm && |
| 9379 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9380 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9381 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9382 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9383 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9384 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9385 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9386 | |
| 9387 | nla_put_failure: |
| 9388 | genlmsg_cancel(msg, hdr); |
| 9389 | nlmsg_free(msg); |
| 9390 | return -ENOBUFS; |
| 9391 | } |
| 9392 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9393 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9394 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9395 | const u8 *buf, size_t len, bool ack, |
| 9396 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9397 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9398 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9399 | struct sk_buff *msg; |
| 9400 | void *hdr; |
| 9401 | |
| 9402 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9403 | if (!msg) |
| 9404 | return; |
| 9405 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9406 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9407 | if (!hdr) { |
| 9408 | nlmsg_free(msg); |
| 9409 | return; |
| 9410 | } |
| 9411 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9412 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9413 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9414 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9415 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9416 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9417 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9418 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9420 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9421 | |
| 9422 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9423 | return; |
| 9424 | |
| 9425 | nla_put_failure: |
| 9426 | genlmsg_cancel(msg, hdr); |
| 9427 | nlmsg_free(msg); |
| 9428 | } |
| 9429 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9430 | void |
| 9431 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9432 | struct net_device *netdev, |
| 9433 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9434 | gfp_t gfp) |
| 9435 | { |
| 9436 | struct sk_buff *msg; |
| 9437 | struct nlattr *pinfoattr; |
| 9438 | void *hdr; |
| 9439 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9441 | if (!msg) |
| 9442 | return; |
| 9443 | |
| 9444 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9445 | if (!hdr) { |
| 9446 | nlmsg_free(msg); |
| 9447 | return; |
| 9448 | } |
| 9449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9451 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9452 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9453 | |
| 9454 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9455 | if (!pinfoattr) |
| 9456 | goto nla_put_failure; |
| 9457 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9458 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9459 | rssi_event)) |
| 9460 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9461 | |
| 9462 | nla_nest_end(msg, pinfoattr); |
| 9463 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9464 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9465 | |
| 9466 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9467 | nl80211_mlme_mcgrp.id, gfp); |
| 9468 | return; |
| 9469 | |
| 9470 | nla_put_failure: |
| 9471 | genlmsg_cancel(msg, hdr); |
| 9472 | nlmsg_free(msg); |
| 9473 | } |
| 9474 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9475 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9476 | struct net_device *netdev, const u8 *bssid, |
| 9477 | const u8 *replay_ctr, gfp_t gfp) |
| 9478 | { |
| 9479 | struct sk_buff *msg; |
| 9480 | struct nlattr *rekey_attr; |
| 9481 | void *hdr; |
| 9482 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9484 | if (!msg) |
| 9485 | return; |
| 9486 | |
| 9487 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9488 | if (!hdr) { |
| 9489 | nlmsg_free(msg); |
| 9490 | return; |
| 9491 | } |
| 9492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9493 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9494 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9495 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9496 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9497 | |
| 9498 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9499 | if (!rekey_attr) |
| 9500 | goto nla_put_failure; |
| 9501 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9502 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9503 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9504 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9505 | |
| 9506 | nla_nest_end(msg, rekey_attr); |
| 9507 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9508 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9509 | |
| 9510 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9511 | nl80211_mlme_mcgrp.id, gfp); |
| 9512 | return; |
| 9513 | |
| 9514 | nla_put_failure: |
| 9515 | genlmsg_cancel(msg, hdr); |
| 9516 | nlmsg_free(msg); |
| 9517 | } |
| 9518 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9519 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9520 | struct net_device *netdev, int index, |
| 9521 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9522 | { |
| 9523 | struct sk_buff *msg; |
| 9524 | struct nlattr *attr; |
| 9525 | void *hdr; |
| 9526 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9528 | if (!msg) |
| 9529 | return; |
| 9530 | |
| 9531 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9532 | if (!hdr) { |
| 9533 | nlmsg_free(msg); |
| 9534 | return; |
| 9535 | } |
| 9536 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9537 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9538 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9539 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9540 | |
| 9541 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9542 | if (!attr) |
| 9543 | goto nla_put_failure; |
| 9544 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9545 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9546 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9547 | (preauth && |
| 9548 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9549 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9550 | |
| 9551 | nla_nest_end(msg, attr); |
| 9552 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9553 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9554 | |
| 9555 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9556 | nl80211_mlme_mcgrp.id, gfp); |
| 9557 | return; |
| 9558 | |
| 9559 | nla_put_failure: |
| 9560 | genlmsg_cancel(msg, hdr); |
| 9561 | nlmsg_free(msg); |
| 9562 | } |
| 9563 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9564 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9565 | struct net_device *netdev, |
| 9566 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9567 | { |
| 9568 | struct sk_buff *msg; |
| 9569 | void *hdr; |
| 9570 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9572 | if (!msg) |
| 9573 | return; |
| 9574 | |
| 9575 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9576 | if (!hdr) { |
| 9577 | nlmsg_free(msg); |
| 9578 | return; |
| 9579 | } |
| 9580 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9581 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9582 | goto nla_put_failure; |
| 9583 | |
| 9584 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9585 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9586 | |
| 9587 | genlmsg_end(msg, hdr); |
| 9588 | |
| 9589 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9590 | nl80211_mlme_mcgrp.id, gfp); |
| 9591 | return; |
| 9592 | |
| 9593 | nla_put_failure: |
| 9594 | genlmsg_cancel(msg, hdr); |
| 9595 | nlmsg_free(msg); |
| 9596 | } |
| 9597 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9598 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9599 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9600 | struct net_device *netdev, const u8 *peer, |
| 9601 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9602 | { |
| 9603 | struct sk_buff *msg; |
| 9604 | struct nlattr *pinfoattr; |
| 9605 | void *hdr; |
| 9606 | |
| 9607 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9608 | if (!msg) |
| 9609 | return; |
| 9610 | |
| 9611 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9612 | if (!hdr) { |
| 9613 | nlmsg_free(msg); |
| 9614 | return; |
| 9615 | } |
| 9616 | |
| 9617 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9618 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9619 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9620 | goto nla_put_failure; |
| 9621 | |
| 9622 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9623 | if (!pinfoattr) |
| 9624 | goto nla_put_failure; |
| 9625 | |
| 9626 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9627 | goto nla_put_failure; |
| 9628 | |
| 9629 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9630 | goto nla_put_failure; |
| 9631 | |
| 9632 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9633 | goto nla_put_failure; |
| 9634 | |
| 9635 | nla_nest_end(msg, pinfoattr); |
| 9636 | |
| 9637 | genlmsg_end(msg, hdr); |
| 9638 | |
| 9639 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9640 | nl80211_mlme_mcgrp.id, gfp); |
| 9641 | return; |
| 9642 | |
| 9643 | nla_put_failure: |
| 9644 | genlmsg_cancel(msg, hdr); |
| 9645 | nlmsg_free(msg); |
| 9646 | } |
| 9647 | |
| 9648 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9649 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 9650 | struct cfg80211_chan_def *chandef, |
| 9651 | enum nl80211_radar_event event, |
| 9652 | struct net_device *netdev, gfp_t gfp) |
| 9653 | { |
| 9654 | struct sk_buff *msg; |
| 9655 | void *hdr; |
| 9656 | |
| 9657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9658 | if (!msg) |
| 9659 | return; |
| 9660 | |
| 9661 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 9662 | if (!hdr) { |
| 9663 | nlmsg_free(msg); |
| 9664 | return; |
| 9665 | } |
| 9666 | |
| 9667 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9668 | goto nla_put_failure; |
| 9669 | |
| 9670 | /* NOP and radar events don't need a netdev parameter */ |
| 9671 | if (netdev) { |
| 9672 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 9673 | |
| 9674 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9675 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9676 | goto nla_put_failure; |
| 9677 | } |
| 9678 | |
| 9679 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 9680 | goto nla_put_failure; |
| 9681 | |
| 9682 | if (nl80211_send_chandef(msg, chandef)) |
| 9683 | goto nla_put_failure; |
| 9684 | |
| 9685 | if (genlmsg_end(msg, hdr) < 0) { |
| 9686 | nlmsg_free(msg); |
| 9687 | return; |
| 9688 | } |
| 9689 | |
| 9690 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9691 | nl80211_mlme_mcgrp.id, gfp); |
| 9692 | return; |
| 9693 | |
| 9694 | nla_put_failure: |
| 9695 | genlmsg_cancel(msg, hdr); |
| 9696 | nlmsg_free(msg); |
| 9697 | } |
| 9698 | |
| 9699 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9700 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9701 | struct net_device *netdev, const u8 *peer, |
| 9702 | u32 num_packets, gfp_t gfp) |
| 9703 | { |
| 9704 | struct sk_buff *msg; |
| 9705 | struct nlattr *pinfoattr; |
| 9706 | void *hdr; |
| 9707 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9709 | if (!msg) |
| 9710 | return; |
| 9711 | |
| 9712 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9713 | if (!hdr) { |
| 9714 | nlmsg_free(msg); |
| 9715 | return; |
| 9716 | } |
| 9717 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9718 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9719 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9720 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9721 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9722 | |
| 9723 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9724 | if (!pinfoattr) |
| 9725 | goto nla_put_failure; |
| 9726 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9727 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9728 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9729 | |
| 9730 | nla_nest_end(msg, pinfoattr); |
| 9731 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9732 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9733 | |
| 9734 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9735 | nl80211_mlme_mcgrp.id, gfp); |
| 9736 | return; |
| 9737 | |
| 9738 | nla_put_failure: |
| 9739 | genlmsg_cancel(msg, hdr); |
| 9740 | nlmsg_free(msg); |
| 9741 | } |
| 9742 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9743 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9744 | u64 cookie, bool acked, gfp_t gfp) |
| 9745 | { |
| 9746 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9747 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9748 | struct sk_buff *msg; |
| 9749 | void *hdr; |
| 9750 | int err; |
| 9751 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9752 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9753 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9754 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9755 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9756 | if (!msg) |
| 9757 | return; |
| 9758 | |
| 9759 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9760 | if (!hdr) { |
| 9761 | nlmsg_free(msg); |
| 9762 | return; |
| 9763 | } |
| 9764 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9765 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9766 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9767 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9768 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9769 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9770 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9771 | |
| 9772 | err = genlmsg_end(msg, hdr); |
| 9773 | if (err < 0) { |
| 9774 | nlmsg_free(msg); |
| 9775 | return; |
| 9776 | } |
| 9777 | |
| 9778 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9779 | nl80211_mlme_mcgrp.id, gfp); |
| 9780 | return; |
| 9781 | |
| 9782 | nla_put_failure: |
| 9783 | genlmsg_cancel(msg, hdr); |
| 9784 | nlmsg_free(msg); |
| 9785 | } |
| 9786 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9787 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9788 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9789 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9790 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9791 | { |
| 9792 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9793 | struct sk_buff *msg; |
| 9794 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9795 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9796 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9797 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9798 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9799 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9800 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9801 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9802 | if (!msg) { |
| 9803 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9804 | return; |
| 9805 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9806 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9807 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9808 | if (!hdr) |
| 9809 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9810 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9812 | (freq && |
| 9813 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9814 | (sig_dbm && |
| 9815 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9816 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9817 | goto nla_put_failure; |
| 9818 | |
| 9819 | genlmsg_end(msg, hdr); |
| 9820 | |
| 9821 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9822 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9823 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9824 | return; |
| 9825 | |
| 9826 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9827 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9828 | if (hdr) |
| 9829 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9830 | nlmsg_free(msg); |
| 9831 | } |
| 9832 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9833 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9834 | #ifdef CONFIG_PM |
| 9835 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9836 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9837 | gfp_t gfp) |
| 9838 | { |
| 9839 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9840 | struct sk_buff *msg; |
| 9841 | void *hdr; |
| 9842 | int err, size = 200; |
| 9843 | |
| 9844 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9845 | |
| 9846 | if (wakeup) |
| 9847 | size += wakeup->packet_present_len; |
| 9848 | |
| 9849 | msg = nlmsg_new(size, gfp); |
| 9850 | if (!msg) |
| 9851 | return; |
| 9852 | |
| 9853 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9854 | if (!hdr) |
| 9855 | goto free_msg; |
| 9856 | |
| 9857 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9858 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9859 | goto free_msg; |
| 9860 | |
| 9861 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9862 | wdev->netdev->ifindex)) |
| 9863 | goto free_msg; |
| 9864 | |
| 9865 | if (wakeup) { |
| 9866 | struct nlattr *reasons; |
| 9867 | |
| 9868 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9869 | |
| 9870 | if (wakeup->disconnect && |
| 9871 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9872 | goto free_msg; |
| 9873 | if (wakeup->magic_pkt && |
| 9874 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9875 | goto free_msg; |
| 9876 | if (wakeup->gtk_rekey_failure && |
| 9877 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9878 | goto free_msg; |
| 9879 | if (wakeup->eap_identity_req && |
| 9880 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9881 | goto free_msg; |
| 9882 | if (wakeup->four_way_handshake && |
| 9883 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9884 | goto free_msg; |
| 9885 | if (wakeup->rfkill_release && |
| 9886 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9887 | goto free_msg; |
| 9888 | |
| 9889 | if (wakeup->pattern_idx >= 0 && |
| 9890 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9891 | wakeup->pattern_idx)) |
| 9892 | goto free_msg; |
| 9893 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9894 | if (wakeup->tcp_match) |
| 9895 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 9896 | |
| 9897 | if (wakeup->tcp_connlost) |
| 9898 | nla_put_flag(msg, |
| 9899 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 9900 | |
| 9901 | if (wakeup->tcp_nomoretokens) |
| 9902 | nla_put_flag(msg, |
| 9903 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 9904 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9905 | if (wakeup->packet) { |
| 9906 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9907 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9908 | |
| 9909 | if (!wakeup->packet_80211) { |
| 9910 | pkt_attr = |
| 9911 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9912 | len_attr = |
| 9913 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9914 | } |
| 9915 | |
| 9916 | if (wakeup->packet_len && |
| 9917 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9918 | goto free_msg; |
| 9919 | |
| 9920 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9921 | wakeup->packet)) |
| 9922 | goto free_msg; |
| 9923 | } |
| 9924 | |
| 9925 | nla_nest_end(msg, reasons); |
| 9926 | } |
| 9927 | |
| 9928 | err = genlmsg_end(msg, hdr); |
| 9929 | if (err < 0) |
| 9930 | goto free_msg; |
| 9931 | |
| 9932 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9933 | nl80211_mlme_mcgrp.id, gfp); |
| 9934 | return; |
| 9935 | |
| 9936 | free_msg: |
| 9937 | nlmsg_free(msg); |
| 9938 | } |
| 9939 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9940 | #endif |
| 9941 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9942 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9943 | enum nl80211_tdls_operation oper, |
| 9944 | u16 reason_code, gfp_t gfp) |
| 9945 | { |
| 9946 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9947 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9948 | struct sk_buff *msg; |
| 9949 | void *hdr; |
| 9950 | int err; |
| 9951 | |
| 9952 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9953 | reason_code); |
| 9954 | |
| 9955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9956 | if (!msg) |
| 9957 | return; |
| 9958 | |
| 9959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9960 | if (!hdr) { |
| 9961 | nlmsg_free(msg); |
| 9962 | return; |
| 9963 | } |
| 9964 | |
| 9965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9966 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9967 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9968 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9969 | (reason_code > 0 && |
| 9970 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9971 | goto nla_put_failure; |
| 9972 | |
| 9973 | err = genlmsg_end(msg, hdr); |
| 9974 | if (err < 0) { |
| 9975 | nlmsg_free(msg); |
| 9976 | return; |
| 9977 | } |
| 9978 | |
| 9979 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9980 | nl80211_mlme_mcgrp.id, gfp); |
| 9981 | return; |
| 9982 | |
| 9983 | nla_put_failure: |
| 9984 | genlmsg_cancel(msg, hdr); |
| 9985 | nlmsg_free(msg); |
| 9986 | } |
| 9987 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9988 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9989 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9990 | unsigned long state, |
| 9991 | void *_notify) |
| 9992 | { |
| 9993 | struct netlink_notify *notify = _notify; |
| 9994 | struct cfg80211_registered_device *rdev; |
| 9995 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9996 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9997 | |
| 9998 | if (state != NETLINK_URELEASE) |
| 9999 | return NOTIFY_DONE; |
| 10000 | |
| 10001 | rcu_read_lock(); |
| 10002 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10003 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10004 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10005 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10006 | |
| 10007 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10008 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10009 | list) { |
| 10010 | if (reg->nlportid == notify->portid) { |
| 10011 | list_del(®->list); |
| 10012 | kfree(reg); |
| 10013 | break; |
| 10014 | } |
| 10015 | } |
| 10016 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10017 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10018 | |
| 10019 | rcu_read_unlock(); |
| 10020 | |
| 10021 | return NOTIFY_DONE; |
| 10022 | } |
| 10023 | |
| 10024 | static struct notifier_block nl80211_netlink_notifier = { |
| 10025 | .notifier_call = nl80211_netlink_notify, |
| 10026 | }; |
| 10027 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10028 | /* initialisation/exit functions */ |
| 10029 | |
| 10030 | int nl80211_init(void) |
| 10031 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10032 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10033 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10034 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10035 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10036 | if (err) |
| 10037 | return err; |
| 10038 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10039 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10040 | if (err) |
| 10041 | goto err_out; |
| 10042 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10043 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10044 | if (err) |
| 10045 | goto err_out; |
| 10046 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10047 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10048 | if (err) |
| 10049 | goto err_out; |
| 10050 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10051 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10052 | if (err) |
| 10053 | goto err_out; |
| 10054 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10055 | #ifdef CONFIG_NL80211_TESTMODE |
| 10056 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10057 | if (err) |
| 10058 | goto err_out; |
| 10059 | #endif |
| 10060 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10061 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10062 | if (err) |
| 10063 | goto err_out; |
| 10064 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10065 | return 0; |
| 10066 | err_out: |
| 10067 | genl_unregister_family(&nl80211_fam); |
| 10068 | return err; |
| 10069 | } |
| 10070 | |
| 10071 | void nl80211_exit(void) |
| 10072 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10073 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10074 | genl_unregister_family(&nl80211_fam); |
| 10075 | } |