Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 373 | }; |
| 374 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 376 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 377 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 379 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 380 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 381 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 382 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 384 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 385 | }; |
| 386 | |
| 387 | /* policy for the key default flags */ |
| 388 | static const struct nla_policy |
| 389 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 390 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 391 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 392 | }; |
| 393 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 394 | /* policy for WoWLAN attributes */ |
| 395 | static const struct nla_policy |
| 396 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 397 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 398 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 399 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 400 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 401 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 402 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 403 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 404 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 405 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 406 | }; |
| 407 | |
| 408 | static const struct nla_policy |
| 409 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 410 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 411 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 412 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 413 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 414 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 415 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 416 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 417 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 418 | }, |
| 419 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 420 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 421 | }, |
| 422 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 423 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 424 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 425 | }; |
| 426 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 427 | /* policy for GTK rekey offload attributes */ |
| 428 | static const struct nla_policy |
| 429 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 430 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 431 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 432 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 433 | }; |
| 434 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 435 | static const struct nla_policy |
| 436 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 437 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 438 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 439 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 440 | }; |
| 441 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 442 | /* ifidx get helper */ |
| 443 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 444 | { |
| 445 | int res; |
| 446 | |
| 447 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 448 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 449 | nl80211_policy); |
| 450 | if (res) |
| 451 | return res; |
| 452 | |
| 453 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 454 | return -EINVAL; |
| 455 | |
| 456 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 457 | if (!res) |
| 458 | return -EINVAL; |
| 459 | return res; |
| 460 | } |
| 461 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 462 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 463 | struct netlink_callback *cb, |
| 464 | struct cfg80211_registered_device **rdev, |
| 465 | struct net_device **dev) |
| 466 | { |
| 467 | int ifidx = cb->args[0]; |
| 468 | int err; |
| 469 | |
| 470 | if (!ifidx) |
| 471 | ifidx = nl80211_get_ifidx(cb); |
| 472 | if (ifidx < 0) |
| 473 | return ifidx; |
| 474 | |
| 475 | cb->args[0] = ifidx; |
| 476 | |
| 477 | rtnl_lock(); |
| 478 | |
| 479 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 480 | if (!*dev) { |
| 481 | err = -ENODEV; |
| 482 | goto out_rtnl; |
| 483 | } |
| 484 | |
| 485 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 486 | if (IS_ERR(*rdev)) { |
| 487 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 488 | goto out_rtnl; |
| 489 | } |
| 490 | |
| 491 | return 0; |
| 492 | out_rtnl: |
| 493 | rtnl_unlock(); |
| 494 | return err; |
| 495 | } |
| 496 | |
| 497 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 498 | { |
| 499 | cfg80211_unlock_rdev(rdev); |
| 500 | rtnl_unlock(); |
| 501 | } |
| 502 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 503 | /* IE validation */ |
| 504 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 505 | { |
| 506 | const u8 *pos; |
| 507 | int len; |
| 508 | |
| 509 | if (!attr) |
| 510 | return true; |
| 511 | |
| 512 | pos = nla_data(attr); |
| 513 | len = nla_len(attr); |
| 514 | |
| 515 | while (len) { |
| 516 | u8 elemlen; |
| 517 | |
| 518 | if (len < 2) |
| 519 | return false; |
| 520 | len -= 2; |
| 521 | |
| 522 | elemlen = pos[1]; |
| 523 | if (elemlen > len) |
| 524 | return false; |
| 525 | |
| 526 | len -= elemlen; |
| 527 | pos += 2 + elemlen; |
| 528 | } |
| 529 | |
| 530 | return true; |
| 531 | } |
| 532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 533 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 534 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 535 | int flags, u8 cmd) |
| 536 | { |
| 537 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 538 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 541 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 542 | struct ieee80211_channel *chan) |
| 543 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 545 | chan->center_freq)) |
| 546 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 547 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 548 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 549 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 550 | goto nla_put_failure; |
| 551 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 552 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 553 | goto nla_put_failure; |
| 554 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 556 | goto nla_put_failure; |
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 | 25e47c1 | 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 | 5e760230 | 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 | 5e760230 | 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 | 6829c87 | 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 | 6829c87 | 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 | |
| 3362 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3363 | struct station_parameters *params) |
| 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 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3370 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3371 | params->ht_capa = |
| 3372 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3373 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3374 | params->vht_capa = |
| 3375 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3376 | |
| 3377 | /* parse WME attributes if present */ |
| 3378 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3379 | return 0; |
| 3380 | |
| 3381 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3382 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3383 | nl80211_sta_wme_policy); |
| 3384 | if (err) |
| 3385 | return err; |
| 3386 | |
| 3387 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3388 | params->uapsd_queues = nla_get_u8( |
| 3389 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3390 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3391 | return -EINVAL; |
| 3392 | |
| 3393 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3394 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3395 | |
| 3396 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3397 | return -EINVAL; |
| 3398 | |
| 3399 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3400 | |
| 3401 | return 0; |
| 3402 | } |
| 3403 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3404 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3405 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3407 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3408 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3409 | struct station_parameters params; |
| 3410 | u8 *mac_addr = NULL; |
| 3411 | |
| 3412 | memset(¶ms, 0, sizeof(params)); |
| 3413 | |
| 3414 | params.listen_interval = -1; |
| 3415 | |
| 3416 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3417 | return -EINVAL; |
| 3418 | |
| 3419 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3420 | return -EINVAL; |
| 3421 | |
| 3422 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3423 | |
| 3424 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3425 | params.supported_rates = |
| 3426 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3427 | params.supported_rates_len = |
| 3428 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3429 | } |
| 3430 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3431 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3432 | params.capability = |
| 3433 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3434 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3435 | } |
| 3436 | |
| 3437 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3438 | params.ext_capab = |
| 3439 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3440 | params.ext_capab_len = |
| 3441 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3442 | } |
| 3443 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3444 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3445 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3446 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3447 | if (!rdev->ops->change_station) |
| 3448 | return -EOPNOTSUPP; |
| 3449 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3450 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3451 | return -EINVAL; |
| 3452 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3453 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3454 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3455 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3456 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3457 | return -EINVAL; |
| 3458 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3459 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3460 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3461 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3462 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3463 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3464 | return -EINVAL; |
| 3465 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3466 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3467 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3468 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3469 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3470 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3471 | |
| 3472 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3473 | pm > NL80211_MESH_POWER_MAX) |
| 3474 | return -EINVAL; |
| 3475 | |
| 3476 | params.local_pm = pm; |
| 3477 | } |
| 3478 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3479 | switch (dev->ieee80211_ptr->iftype) { |
| 3480 | case NL80211_IFTYPE_AP: |
| 3481 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3482 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3483 | /* disallow mesh-specific things */ |
| 3484 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3485 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3486 | if (params.local_pm) |
| 3487 | return -EINVAL; |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3488 | if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3489 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3490 | |
| 3491 | /* TDLS can't be set, ... */ |
| 3492 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3493 | return -EINVAL; |
| 3494 | /* |
| 3495 | * ... but don't bother the driver with it. This works around |
| 3496 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3497 | * TLDS_PEER flag in the mask even for AP mode. |
| 3498 | */ |
| 3499 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3500 | |
| 3501 | /* accept only the listed bits */ |
| 3502 | if (params.sta_flags_mask & |
| 3503 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3504 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3505 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3506 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3507 | BIT(NL80211_STA_FLAG_WME) | |
| 3508 | BIT(NL80211_STA_FLAG_MFP))) |
| 3509 | return -EINVAL; |
| 3510 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3511 | /* but authenticated/associated only if driver handles it */ |
| 3512 | if (!(rdev->wiphy.features & |
| 3513 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3514 | params.sta_flags_mask & |
| 3515 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3516 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3517 | return -EINVAL; |
| 3518 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3519 | /* reject other things that can't change */ |
| 3520 | if (params.supported_rates) |
| 3521 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3522 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3523 | return -EINVAL; |
| 3524 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3525 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3526 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3527 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3528 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3529 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3530 | /* must be last in here for error handling */ |
| 3531 | params.vlan = get_vlan(info, rdev); |
| 3532 | if (IS_ERR(params.vlan)) |
| 3533 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3534 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3535 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3536 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3537 | /* |
| 3538 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3539 | * but silently ignore attempts to change it since we |
| 3540 | * don't have state here to verify that it doesn't try |
| 3541 | * to change the flag. |
| 3542 | */ |
| 3543 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3544 | /* Include parameters for TDLS peer (driver will check) */ |
| 3545 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3546 | if (err) |
| 3547 | return err; |
| 3548 | /* disallow things sta doesn't support */ |
| 3549 | if (params.plink_action) |
| 3550 | return -EINVAL; |
| 3551 | if (params.local_pm) |
| 3552 | return -EINVAL; |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3553 | if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3554 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3555 | /* reject any changes other than AUTHORIZED or WME (for TDLS) */ |
| 3556 | if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3557 | BIT(NL80211_STA_FLAG_WME))) |
| 3558 | return -EINVAL; |
| 3559 | break; |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3560 | case NL80211_IFTYPE_ADHOC: |
| 3561 | /* disallow things sta doesn't support */ |
| 3562 | if (params.plink_action) |
| 3563 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3564 | if (params.local_pm) |
| 3565 | return -EINVAL; |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3566 | if (params.sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3567 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3568 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3569 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3570 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3571 | /* reject any changes other than AUTHORIZED */ |
| 3572 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3573 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3574 | break; |
| 3575 | case NL80211_IFTYPE_MESH_POINT: |
| 3576 | /* disallow things mesh doesn't support */ |
| 3577 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3578 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3579 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3580 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3581 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3582 | return -EINVAL; |
| 3583 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3584 | return -EINVAL; |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3585 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY] || |
| 3586 | info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3587 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3588 | /* |
| 3589 | * No special handling for TDLS here -- the userspace |
| 3590 | * mesh code doesn't have this bug. |
| 3591 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3592 | if (params.sta_flags_mask & |
| 3593 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3594 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3595 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3596 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3597 | break; |
| 3598 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3599 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3600 | } |
| 3601 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3602 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3603 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3604 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3605 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3606 | if (params.vlan) |
| 3607 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3608 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3609 | return err; |
| 3610 | } |
| 3611 | |
| 3612 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3613 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3615 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3616 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3617 | struct station_parameters params; |
| 3618 | u8 *mac_addr = NULL; |
| 3619 | |
| 3620 | memset(¶ms, 0, sizeof(params)); |
| 3621 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame^] | 3622 | if (!rdev->ops->add_station) |
| 3623 | return -EOPNOTSUPP; |
| 3624 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3625 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3626 | return -EINVAL; |
| 3627 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3628 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3629 | return -EINVAL; |
| 3630 | |
| 3631 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3632 | return -EINVAL; |
| 3633 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3634 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3635 | return -EINVAL; |
| 3636 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3637 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3638 | params.supported_rates = |
| 3639 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3640 | params.supported_rates_len = |
| 3641 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3642 | params.listen_interval = |
| 3643 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3644 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3645 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3646 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3647 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3648 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3649 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3650 | params.capability = |
| 3651 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3652 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3653 | } |
| 3654 | |
| 3655 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3656 | params.ext_capab = |
| 3657 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3658 | params.ext_capab_len = |
| 3659 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3660 | } |
| 3661 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3662 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3663 | params.ht_capa = |
| 3664 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3665 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3666 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3667 | params.vht_capa = |
| 3668 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3669 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3670 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3671 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3672 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3673 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3674 | return -EINVAL; |
| 3675 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3676 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame^] | 3677 | if (info->attrs[NL80211_ATTR_STA_WME]) { |
| 3678 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3679 | struct nlattr *nla; |
| 3680 | |
| 3681 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3682 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3683 | nl80211_sta_wme_policy); |
| 3684 | if (err) |
| 3685 | return err; |
| 3686 | |
| 3687 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3688 | params.uapsd_queues = |
| 3689 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3690 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3691 | return -EINVAL; |
| 3692 | |
| 3693 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3694 | params.max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3695 | |
| 3696 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3697 | return -EINVAL; |
| 3698 | |
| 3699 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3700 | } |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3701 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3702 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3703 | return -EINVAL; |
| 3704 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3705 | switch (dev->ieee80211_ptr->iftype) { |
| 3706 | case NL80211_IFTYPE_AP: |
| 3707 | case NL80211_IFTYPE_AP_VLAN: |
| 3708 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame^] | 3709 | /* ignore WME attributes if iface/sta is not capable */ |
| 3710 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 3711 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 3712 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3713 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3714 | /* TDLS peers cannot be added */ |
| 3715 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3716 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3717 | /* but don't bother the driver with it */ |
| 3718 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3719 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3720 | /* allow authenticated/associated only if driver handles it */ |
| 3721 | if (!(rdev->wiphy.features & |
| 3722 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3723 | params.sta_flags_mask & |
| 3724 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3725 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3726 | return -EINVAL; |
| 3727 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3728 | /* must be last in here for error handling */ |
| 3729 | params.vlan = get_vlan(info, rdev); |
| 3730 | if (IS_ERR(params.vlan)) |
| 3731 | return PTR_ERR(params.vlan); |
| 3732 | break; |
| 3733 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame^] | 3734 | /* ignore uAPSD data */ |
| 3735 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 3736 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3737 | /* associated is disallowed */ |
| 3738 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3739 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3740 | /* TDLS peers cannot be added */ |
| 3741 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3742 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3743 | break; |
| 3744 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame^] | 3745 | /* ignore uAPSD data */ |
| 3746 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 3747 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3748 | /* associated is disallowed */ |
| 3749 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3750 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3751 | /* Only TDLS peers can be added */ |
| 3752 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3753 | return -EINVAL; |
| 3754 | /* Can only add if TDLS ... */ |
| 3755 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3756 | return -EOPNOTSUPP; |
| 3757 | /* ... with external setup is supported */ |
| 3758 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3759 | return -EOPNOTSUPP; |
| 3760 | break; |
| 3761 | default: |
| 3762 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3763 | } |
| 3764 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3765 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3766 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3767 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3768 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3769 | if (params.vlan) |
| 3770 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3771 | return err; |
| 3772 | } |
| 3773 | |
| 3774 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3775 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3776 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3777 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3778 | u8 *mac_addr = NULL; |
| 3779 | |
| 3780 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3781 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3782 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3783 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3784 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3785 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3786 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3787 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3788 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3789 | if (!rdev->ops->del_station) |
| 3790 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3791 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3792 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3793 | } |
| 3794 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3795 | 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] | 3796 | int flags, struct net_device *dev, |
| 3797 | u8 *dst, u8 *next_hop, |
| 3798 | struct mpath_info *pinfo) |
| 3799 | { |
| 3800 | void *hdr; |
| 3801 | struct nlattr *pinfoattr; |
| 3802 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3803 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3804 | if (!hdr) |
| 3805 | return -1; |
| 3806 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3807 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3808 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3809 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3810 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3811 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3812 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3813 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3814 | if (!pinfoattr) |
| 3815 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3816 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3817 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3818 | pinfo->frame_qlen)) |
| 3819 | goto nla_put_failure; |
| 3820 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3821 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3822 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3823 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3824 | pinfo->metric)) || |
| 3825 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3826 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3827 | pinfo->exptime)) || |
| 3828 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3829 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3830 | pinfo->flags)) || |
| 3831 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3832 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3833 | pinfo->discovery_timeout)) || |
| 3834 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3835 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3836 | pinfo->discovery_retries))) |
| 3837 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3838 | |
| 3839 | nla_nest_end(msg, pinfoattr); |
| 3840 | |
| 3841 | return genlmsg_end(msg, hdr); |
| 3842 | |
| 3843 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3844 | genlmsg_cancel(msg, hdr); |
| 3845 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3849 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3850 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3851 | struct mpath_info pinfo; |
| 3852 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3853 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3854 | u8 dst[ETH_ALEN]; |
| 3855 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3856 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3857 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3858 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3859 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3860 | if (err) |
| 3861 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3862 | |
| 3863 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3864 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3865 | goto out_err; |
| 3866 | } |
| 3867 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3868 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3869 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3870 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3871 | } |
| 3872 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3873 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3874 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3875 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3876 | if (err == -ENOENT) |
| 3877 | break; |
| 3878 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3879 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3880 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3881 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3882 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3883 | netdev, dst, next_hop, |
| 3884 | &pinfo) < 0) |
| 3885 | goto out; |
| 3886 | |
| 3887 | path_idx++; |
| 3888 | } |
| 3889 | |
| 3890 | |
| 3891 | out: |
| 3892 | cb->args[1] = path_idx; |
| 3893 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3894 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3895 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3896 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3900 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3902 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3903 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3904 | struct mpath_info pinfo; |
| 3905 | struct sk_buff *msg; |
| 3906 | u8 *dst = NULL; |
| 3907 | u8 next_hop[ETH_ALEN]; |
| 3908 | |
| 3909 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3910 | |
| 3911 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3912 | return -EINVAL; |
| 3913 | |
| 3914 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3916 | if (!rdev->ops->get_mpath) |
| 3917 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3918 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3919 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3920 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3921 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3922 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3923 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3924 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3925 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3926 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3927 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3928 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3929 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3930 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3931 | dev, dst, next_hop, &pinfo) < 0) { |
| 3932 | nlmsg_free(msg); |
| 3933 | return -ENOBUFS; |
| 3934 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3936 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3940 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3942 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3943 | u8 *dst = NULL; |
| 3944 | u8 *next_hop = NULL; |
| 3945 | |
| 3946 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3947 | return -EINVAL; |
| 3948 | |
| 3949 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3950 | return -EINVAL; |
| 3951 | |
| 3952 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3953 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3954 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3955 | if (!rdev->ops->change_mpath) |
| 3956 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3957 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3958 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3959 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3960 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3961 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3962 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3963 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3964 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3965 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3967 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3968 | u8 *dst = NULL; |
| 3969 | u8 *next_hop = NULL; |
| 3970 | |
| 3971 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3972 | return -EINVAL; |
| 3973 | |
| 3974 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3975 | return -EINVAL; |
| 3976 | |
| 3977 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3978 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3980 | if (!rdev->ops->add_mpath) |
| 3981 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3982 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3983 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3984 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3985 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3986 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | static int nl80211_del_mpath(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]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3993 | u8 *dst = NULL; |
| 3994 | |
| 3995 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3996 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3997 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3998 | if (!rdev->ops->del_mpath) |
| 3999 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4000 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4001 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4002 | } |
| 4003 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4004 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4005 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4007 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4008 | struct bss_parameters params; |
| 4009 | |
| 4010 | memset(¶ms, 0, sizeof(params)); |
| 4011 | /* default to not changing parameters */ |
| 4012 | params.use_cts_prot = -1; |
| 4013 | params.use_short_preamble = -1; |
| 4014 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4015 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4016 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4017 | params.p2p_ctwindow = -1; |
| 4018 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4019 | |
| 4020 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4021 | params.use_cts_prot = |
| 4022 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4023 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4024 | params.use_short_preamble = |
| 4025 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4026 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4027 | params.use_short_slot_time = |
| 4028 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4029 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4030 | params.basic_rates = |
| 4031 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4032 | params.basic_rates_len = |
| 4033 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4034 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4035 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4036 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4037 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4038 | params.ht_opmode = |
| 4039 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4040 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4041 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4042 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4043 | return -EINVAL; |
| 4044 | params.p2p_ctwindow = |
| 4045 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4046 | if (params.p2p_ctwindow < 0) |
| 4047 | return -EINVAL; |
| 4048 | if (params.p2p_ctwindow != 0 && |
| 4049 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4050 | return -EINVAL; |
| 4051 | } |
| 4052 | |
| 4053 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4054 | u8 tmp; |
| 4055 | |
| 4056 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4057 | return -EINVAL; |
| 4058 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4059 | if (tmp > 1) |
| 4060 | return -EINVAL; |
| 4061 | params.p2p_opp_ps = tmp; |
| 4062 | if (params.p2p_opp_ps && |
| 4063 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4064 | return -EINVAL; |
| 4065 | } |
| 4066 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4067 | if (!rdev->ops->change_bss) |
| 4068 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4069 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4070 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4071 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4072 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4073 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4074 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4075 | } |
| 4076 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4077 | 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] | 4078 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4079 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4080 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4081 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4082 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4083 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4084 | }; |
| 4085 | |
| 4086 | static int parse_reg_rule(struct nlattr *tb[], |
| 4087 | struct ieee80211_reg_rule *reg_rule) |
| 4088 | { |
| 4089 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4090 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4091 | |
| 4092 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4093 | return -EINVAL; |
| 4094 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4095 | return -EINVAL; |
| 4096 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4097 | return -EINVAL; |
| 4098 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4099 | return -EINVAL; |
| 4100 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4101 | return -EINVAL; |
| 4102 | |
| 4103 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4104 | |
| 4105 | freq_range->start_freq_khz = |
| 4106 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4107 | freq_range->end_freq_khz = |
| 4108 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4109 | freq_range->max_bandwidth_khz = |
| 4110 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4111 | |
| 4112 | power_rule->max_eirp = |
| 4113 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4114 | |
| 4115 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4116 | power_rule->max_antenna_gain = |
| 4117 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4118 | |
| 4119 | return 0; |
| 4120 | } |
| 4121 | |
| 4122 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4123 | { |
| 4124 | int r; |
| 4125 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4126 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4127 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4128 | /* |
| 4129 | * You should only get this when cfg80211 hasn't yet initialized |
| 4130 | * completely when built-in to the kernel right between the time |
| 4131 | * window between nl80211_init() and regulatory_init(), if that is |
| 4132 | * even possible. |
| 4133 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4134 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4135 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4136 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4137 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4138 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4139 | |
| 4140 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4141 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4142 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4143 | user_reg_hint_type = |
| 4144 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4145 | else |
| 4146 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4147 | |
| 4148 | switch (user_reg_hint_type) { |
| 4149 | case NL80211_USER_REG_HINT_USER: |
| 4150 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4151 | break; |
| 4152 | default: |
| 4153 | return -EINVAL; |
| 4154 | } |
| 4155 | |
| 4156 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4157 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4158 | return r; |
| 4159 | } |
| 4160 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4161 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4162 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4163 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4165 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4166 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4167 | struct mesh_config cur_params; |
| 4168 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4169 | void *hdr; |
| 4170 | struct nlattr *pinfoattr; |
| 4171 | struct sk_buff *msg; |
| 4172 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4173 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4174 | return -EOPNOTSUPP; |
| 4175 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4176 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4177 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4178 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4179 | wdev_lock(wdev); |
| 4180 | /* If not connected, get default parameters */ |
| 4181 | if (!wdev->mesh_id_len) |
| 4182 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4183 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4184 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4185 | wdev_unlock(wdev); |
| 4186 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4187 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4188 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4189 | |
| 4190 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4191 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4192 | if (!msg) |
| 4193 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4194 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4195 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4196 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4197 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4198 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4199 | if (!pinfoattr) |
| 4200 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4201 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4202 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4203 | cur_params.dot11MeshRetryTimeout) || |
| 4204 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4205 | cur_params.dot11MeshConfirmTimeout) || |
| 4206 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4207 | cur_params.dot11MeshHoldingTimeout) || |
| 4208 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4209 | cur_params.dot11MeshMaxPeerLinks) || |
| 4210 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4211 | cur_params.dot11MeshMaxRetries) || |
| 4212 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4213 | cur_params.dot11MeshTTL) || |
| 4214 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4215 | cur_params.element_ttl) || |
| 4216 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4217 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4218 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4219 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4220 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4221 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4222 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4223 | cur_params.path_refresh_time) || |
| 4224 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4225 | cur_params.min_discovery_timeout) || |
| 4226 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4227 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4228 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4229 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4230 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4231 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4232 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4233 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4234 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4235 | cur_params.dot11MeshHWMPRootMode) || |
| 4236 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4237 | cur_params.dot11MeshHWMPRannInterval) || |
| 4238 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4239 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4240 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4241 | cur_params.dot11MeshForwarding) || |
| 4242 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4243 | cur_params.rssi_threshold) || |
| 4244 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4245 | cur_params.ht_opmode) || |
| 4246 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4247 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4248 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4249 | cur_params.dot11MeshHWMProotInterval) || |
| 4250 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4251 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4252 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4253 | cur_params.power_mode) || |
| 4254 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4255 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4256 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4257 | nla_nest_end(msg, pinfoattr); |
| 4258 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4259 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4260 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4261 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4262 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4263 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4264 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4265 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4268 | 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] | 4269 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4270 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4271 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4272 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4273 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4274 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4275 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4276 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4277 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4278 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4279 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4280 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4281 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4282 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4283 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4284 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4285 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4286 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4287 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4288 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4289 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4290 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4291 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4292 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4293 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4294 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4295 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4296 | }; |
| 4297 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4298 | static const struct nla_policy |
| 4299 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4300 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4301 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4302 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4303 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4304 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4305 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4306 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4307 | }; |
| 4308 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4309 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4310 | struct mesh_config *cfg, |
| 4311 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4312 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4313 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4314 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4315 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4316 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4317 | do { \ |
| 4318 | if (tb[attr]) { \ |
| 4319 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4320 | return -EINVAL; \ |
| 4321 | cfg->param = fn(tb[attr]); \ |
| 4322 | mask |= (1 << (attr - 1)); \ |
| 4323 | } \ |
| 4324 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4325 | |
| 4326 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4327 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4328 | return -EINVAL; |
| 4329 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4330 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4331 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4332 | return -EINVAL; |
| 4333 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4334 | /* This makes sure that there aren't more than 32 mesh config |
| 4335 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4336 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4337 | |
| 4338 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4339 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4340 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4341 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4342 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4343 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4344 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4345 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4346 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4347 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4348 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4349 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4350 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4351 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4352 | mask, NL80211_MESHCONF_MAX_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, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4355 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4356 | 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] | 4357 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4358 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4359 | 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] | 4360 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4361 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4362 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4363 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4364 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4365 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4366 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4367 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4368 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4369 | 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] | 4370 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4371 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4372 | 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] | 4373 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4374 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4375 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4376 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4377 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4378 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4379 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4380 | 1, 65535, mask, |
| 4381 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4382 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4383 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4384 | 1, 65535, mask, |
| 4385 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4386 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4387 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4388 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4389 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4390 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4391 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4392 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4393 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4394 | nla_get_u8); |
| 4395 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4396 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4397 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4398 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4399 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4400 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4401 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4402 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4403 | mask, NL80211_MESHCONF_FORWARDING, |
| 4404 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4405 | 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] | 4406 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4407 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4408 | 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] | 4409 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4410 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4411 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4412 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4413 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4414 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4415 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4416 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4417 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4418 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4419 | dot11MeshHWMPconfirmationInterval, |
| 4420 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4421 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4422 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4423 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4424 | NL80211_MESH_POWER_ACTIVE, |
| 4425 | NL80211_MESH_POWER_MAX, |
| 4426 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4427 | nla_get_u32); |
| 4428 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4429 | 0, 65535, mask, |
| 4430 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4431 | if (mask_out) |
| 4432 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4433 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4434 | return 0; |
| 4435 | |
| 4436 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4437 | } |
| 4438 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4439 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4440 | struct mesh_setup *setup) |
| 4441 | { |
| 4442 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4443 | |
| 4444 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4445 | return -EINVAL; |
| 4446 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4447 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4448 | nl80211_mesh_setup_params_policy)) |
| 4449 | return -EINVAL; |
| 4450 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4451 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4452 | setup->sync_method = |
| 4453 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4454 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4455 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4456 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4457 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4458 | setup->path_sel_proto = |
| 4459 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4460 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4461 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4462 | |
| 4463 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4464 | setup->path_metric = |
| 4465 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4466 | IEEE80211_PATH_METRIC_VENDOR : |
| 4467 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4468 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4469 | |
| 4470 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4471 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4472 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4473 | if (!is_valid_ie_attr(ieattr)) |
| 4474 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4475 | setup->ie = nla_data(ieattr); |
| 4476 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4477 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4478 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4479 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4480 | |
| 4481 | return 0; |
| 4482 | } |
| 4483 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4484 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4485 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4486 | { |
| 4487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4488 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4490 | struct mesh_config cfg; |
| 4491 | u32 mask; |
| 4492 | int err; |
| 4493 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4494 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4495 | return -EOPNOTSUPP; |
| 4496 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4497 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4498 | return -EOPNOTSUPP; |
| 4499 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4500 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4501 | if (err) |
| 4502 | return err; |
| 4503 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4504 | wdev_lock(wdev); |
| 4505 | if (!wdev->mesh_id_len) |
| 4506 | err = -ENOLINK; |
| 4507 | |
| 4508 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4509 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4510 | |
| 4511 | wdev_unlock(wdev); |
| 4512 | |
| 4513 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4516 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4517 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4518 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4519 | struct sk_buff *msg; |
| 4520 | void *hdr = NULL; |
| 4521 | struct nlattr *nl_reg_rules; |
| 4522 | unsigned int i; |
| 4523 | int err = -EINVAL; |
| 4524 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4525 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4526 | |
| 4527 | if (!cfg80211_regdomain) |
| 4528 | goto out; |
| 4529 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4530 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4531 | if (!msg) { |
| 4532 | err = -ENOBUFS; |
| 4533 | goto out; |
| 4534 | } |
| 4535 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4536 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4537 | NL80211_CMD_GET_REG); |
| 4538 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4539 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4540 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4541 | if (reg_last_request_cell_base() && |
| 4542 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4543 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4544 | goto nla_put_failure; |
| 4545 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4546 | rcu_read_lock(); |
| 4547 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4548 | |
| 4549 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4550 | (regdom->dfs_region && |
| 4551 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4552 | goto nla_put_failure_rcu; |
| 4553 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4554 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4555 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4556 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4557 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4558 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4559 | struct nlattr *nl_reg_rule; |
| 4560 | const struct ieee80211_reg_rule *reg_rule; |
| 4561 | const struct ieee80211_freq_range *freq_range; |
| 4562 | const struct ieee80211_power_rule *power_rule; |
| 4563 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4564 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4565 | freq_range = ®_rule->freq_range; |
| 4566 | power_rule = ®_rule->power_rule; |
| 4567 | |
| 4568 | nl_reg_rule = nla_nest_start(msg, i); |
| 4569 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4570 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4571 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4572 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4573 | reg_rule->flags) || |
| 4574 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4575 | freq_range->start_freq_khz) || |
| 4576 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4577 | freq_range->end_freq_khz) || |
| 4578 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4579 | freq_range->max_bandwidth_khz) || |
| 4580 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4581 | power_rule->max_antenna_gain) || |
| 4582 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4583 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4584 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4585 | |
| 4586 | nla_nest_end(msg, nl_reg_rule); |
| 4587 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4588 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4589 | |
| 4590 | nla_nest_end(msg, nl_reg_rules); |
| 4591 | |
| 4592 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4593 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4594 | goto out; |
| 4595 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4596 | nla_put_failure_rcu: |
| 4597 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4598 | nla_put_failure: |
| 4599 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4600 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4601 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4602 | err = -EMSGSIZE; |
| 4603 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4604 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4605 | return err; |
| 4606 | } |
| 4607 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4608 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4609 | { |
| 4610 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4611 | struct nlattr *nl_reg_rule; |
| 4612 | char *alpha2 = NULL; |
| 4613 | int rem_reg_rules = 0, r = 0; |
| 4614 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4615 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4616 | struct ieee80211_regdomain *rd = NULL; |
| 4617 | |
| 4618 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4619 | return -EINVAL; |
| 4620 | |
| 4621 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4622 | return -EINVAL; |
| 4623 | |
| 4624 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4625 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4626 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4627 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4628 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4629 | 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] | 4630 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4631 | num_rules++; |
| 4632 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4633 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4636 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4637 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4638 | |
| 4639 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4640 | if (!rd) |
| 4641 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4642 | |
| 4643 | rd->n_reg_rules = num_rules; |
| 4644 | rd->alpha2[0] = alpha2[0]; |
| 4645 | rd->alpha2[1] = alpha2[1]; |
| 4646 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4647 | /* |
| 4648 | * Disable DFS master mode if the DFS region was |
| 4649 | * not supported or known on this kernel. |
| 4650 | */ |
| 4651 | if (reg_supported_dfs_region(dfs_region)) |
| 4652 | rd->dfs_region = dfs_region; |
| 4653 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4654 | 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] | 4655 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4656 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4657 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4658 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4659 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4660 | if (r) |
| 4661 | goto bad_reg; |
| 4662 | |
| 4663 | rule_idx++; |
| 4664 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4665 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4666 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4667 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4668 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4671 | mutex_lock(&cfg80211_mutex); |
| 4672 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4673 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4674 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4675 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4676 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4677 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4678 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4679 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4680 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4681 | } |
| 4682 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4683 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4684 | { |
| 4685 | struct nlattr *attr1, *attr2; |
| 4686 | int n_channels = 0, tmp1, tmp2; |
| 4687 | |
| 4688 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4689 | n_channels++; |
| 4690 | /* |
| 4691 | * Some hardware has a limited channel list for |
| 4692 | * scanning, and it is pretty much nonsensical |
| 4693 | * to scan for a channel twice, so disallow that |
| 4694 | * and don't require drivers to check that the |
| 4695 | * channel list they get isn't longer than what |
| 4696 | * they can scan, as long as they can scan all |
| 4697 | * the channels they registered at once. |
| 4698 | */ |
| 4699 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4700 | if (attr1 != attr2 && |
| 4701 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4702 | return 0; |
| 4703 | } |
| 4704 | |
| 4705 | return n_channels; |
| 4706 | } |
| 4707 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4708 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4709 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4710 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4711 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4712 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4713 | struct nlattr *attr; |
| 4714 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4715 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4716 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4717 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4718 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4719 | return -EINVAL; |
| 4720 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4721 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4722 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4723 | if (!rdev->ops->scan) |
| 4724 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4725 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | if (rdev->scan_req) |
| 4727 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4728 | |
| 4729 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4730 | n_channels = validate_scan_freqs( |
| 4731 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4732 | if (!n_channels) |
| 4733 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4734 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4735 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4736 | n_channels = 0; |
| 4737 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4738 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4739 | if (wiphy->bands[band]) |
| 4740 | n_channels += wiphy->bands[band]->n_channels; |
| 4741 | } |
| 4742 | |
| 4743 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4744 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4745 | n_ssids++; |
| 4746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4747 | if (n_ssids > wiphy->max_scan_ssids) |
| 4748 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4749 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4750 | if (info->attrs[NL80211_ATTR_IE]) |
| 4751 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4752 | else |
| 4753 | ie_len = 0; |
| 4754 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4755 | if (ie_len > wiphy->max_scan_ie_len) |
| 4756 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4757 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4758 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4759 | + sizeof(*request->ssids) * n_ssids |
| 4760 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4761 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4762 | if (!request) |
| 4763 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4764 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4765 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4766 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4767 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4768 | if (ie_len) { |
| 4769 | if (request->ssids) |
| 4770 | request->ie = (void *)(request->ssids + n_ssids); |
| 4771 | else |
| 4772 | request->ie = (void *)(request->channels + n_channels); |
| 4773 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4774 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4775 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4776 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4777 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4778 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4779 | struct ieee80211_channel *chan; |
| 4780 | |
| 4781 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4782 | |
| 4783 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4784 | err = -EINVAL; |
| 4785 | goto out_free; |
| 4786 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4787 | |
| 4788 | /* ignore disabled channels */ |
| 4789 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4790 | continue; |
| 4791 | |
| 4792 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4793 | i++; |
| 4794 | } |
| 4795 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4796 | enum ieee80211_band band; |
| 4797 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4798 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4799 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4800 | int j; |
| 4801 | if (!wiphy->bands[band]) |
| 4802 | continue; |
| 4803 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4804 | struct ieee80211_channel *chan; |
| 4805 | |
| 4806 | chan = &wiphy->bands[band]->channels[j]; |
| 4807 | |
| 4808 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4809 | continue; |
| 4810 | |
| 4811 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4812 | i++; |
| 4813 | } |
| 4814 | } |
| 4815 | } |
| 4816 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4817 | if (!i) { |
| 4818 | err = -EINVAL; |
| 4819 | goto out_free; |
| 4820 | } |
| 4821 | |
| 4822 | request->n_channels = i; |
| 4823 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4824 | i = 0; |
| 4825 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4826 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4827 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4828 | err = -EINVAL; |
| 4829 | goto out_free; |
| 4830 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4831 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4832 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4833 | i++; |
| 4834 | } |
| 4835 | } |
| 4836 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4837 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4838 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4839 | memcpy((void *)request->ie, |
| 4840 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4841 | request->ie_len); |
| 4842 | } |
| 4843 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4844 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4845 | if (wiphy->bands[i]) |
| 4846 | request->rates[i] = |
| 4847 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4848 | |
| 4849 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4850 | nla_for_each_nested(attr, |
| 4851 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4852 | tmp) { |
| 4853 | enum ieee80211_band band = nla_type(attr); |
| 4854 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4855 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4856 | err = -EINVAL; |
| 4857 | goto out_free; |
| 4858 | } |
| 4859 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4860 | nla_data(attr), |
| 4861 | nla_len(attr), |
| 4862 | &request->rates[band]); |
| 4863 | if (err) |
| 4864 | goto out_free; |
| 4865 | } |
| 4866 | } |
| 4867 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4868 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4869 | request->flags = nla_get_u32( |
| 4870 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4871 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4872 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4873 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4874 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4875 | err = -EOPNOTSUPP; |
| 4876 | goto out_free; |
| 4877 | } |
| 4878 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4879 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4880 | request->no_cck = |
| 4881 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4882 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4883 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4884 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4885 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4886 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4887 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4888 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4889 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4890 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4891 | nl80211_send_scan_start(rdev, wdev); |
| 4892 | if (wdev->netdev) |
| 4893 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4894 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4895 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4896 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4897 | kfree(request); |
| 4898 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4899 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4900 | return err; |
| 4901 | } |
| 4902 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4903 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4904 | struct genl_info *info) |
| 4905 | { |
| 4906 | struct cfg80211_sched_scan_request *request; |
| 4907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4908 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4909 | struct nlattr *attr; |
| 4910 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4911 | 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] | 4912 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4913 | enum ieee80211_band band; |
| 4914 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4915 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4916 | |
| 4917 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4918 | !rdev->ops->sched_scan_start) |
| 4919 | return -EOPNOTSUPP; |
| 4920 | |
| 4921 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4922 | return -EINVAL; |
| 4923 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4924 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4925 | return -EINVAL; |
| 4926 | |
| 4927 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4928 | if (interval == 0) |
| 4929 | return -EINVAL; |
| 4930 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4931 | wiphy = &rdev->wiphy; |
| 4932 | |
| 4933 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4934 | n_channels = validate_scan_freqs( |
| 4935 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4936 | if (!n_channels) |
| 4937 | return -EINVAL; |
| 4938 | } else { |
| 4939 | n_channels = 0; |
| 4940 | |
| 4941 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4942 | if (wiphy->bands[band]) |
| 4943 | n_channels += wiphy->bands[band]->n_channels; |
| 4944 | } |
| 4945 | |
| 4946 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4947 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4948 | tmp) |
| 4949 | n_ssids++; |
| 4950 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4951 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4952 | return -EINVAL; |
| 4953 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4954 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4955 | nla_for_each_nested(attr, |
| 4956 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4957 | tmp) |
| 4958 | n_match_sets++; |
| 4959 | |
| 4960 | if (n_match_sets > wiphy->max_match_sets) |
| 4961 | return -EINVAL; |
| 4962 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4963 | if (info->attrs[NL80211_ATTR_IE]) |
| 4964 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4965 | else |
| 4966 | ie_len = 0; |
| 4967 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4968 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4969 | return -EINVAL; |
| 4970 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4971 | mutex_lock(&rdev->sched_scan_mtx); |
| 4972 | |
| 4973 | if (rdev->sched_scan_req) { |
| 4974 | err = -EINPROGRESS; |
| 4975 | goto out; |
| 4976 | } |
| 4977 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4978 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4979 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4980 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4981 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4982 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4983 | if (!request) { |
| 4984 | err = -ENOMEM; |
| 4985 | goto out; |
| 4986 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4987 | |
| 4988 | if (n_ssids) |
| 4989 | request->ssids = (void *)&request->channels[n_channels]; |
| 4990 | request->n_ssids = n_ssids; |
| 4991 | if (ie_len) { |
| 4992 | if (request->ssids) |
| 4993 | request->ie = (void *)(request->ssids + n_ssids); |
| 4994 | else |
| 4995 | request->ie = (void *)(request->channels + n_channels); |
| 4996 | } |
| 4997 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4998 | if (n_match_sets) { |
| 4999 | if (request->ie) |
| 5000 | request->match_sets = (void *)(request->ie + ie_len); |
| 5001 | else if (request->ssids) |
| 5002 | request->match_sets = |
| 5003 | (void *)(request->ssids + n_ssids); |
| 5004 | else |
| 5005 | request->match_sets = |
| 5006 | (void *)(request->channels + n_channels); |
| 5007 | } |
| 5008 | request->n_match_sets = n_match_sets; |
| 5009 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5010 | i = 0; |
| 5011 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5012 | /* user specified, bail out if channel not found */ |
| 5013 | nla_for_each_nested(attr, |
| 5014 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5015 | tmp) { |
| 5016 | struct ieee80211_channel *chan; |
| 5017 | |
| 5018 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5019 | |
| 5020 | if (!chan) { |
| 5021 | err = -EINVAL; |
| 5022 | goto out_free; |
| 5023 | } |
| 5024 | |
| 5025 | /* ignore disabled channels */ |
| 5026 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5027 | continue; |
| 5028 | |
| 5029 | request->channels[i] = chan; |
| 5030 | i++; |
| 5031 | } |
| 5032 | } else { |
| 5033 | /* all channels */ |
| 5034 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5035 | int j; |
| 5036 | if (!wiphy->bands[band]) |
| 5037 | continue; |
| 5038 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5039 | struct ieee80211_channel *chan; |
| 5040 | |
| 5041 | chan = &wiphy->bands[band]->channels[j]; |
| 5042 | |
| 5043 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5044 | continue; |
| 5045 | |
| 5046 | request->channels[i] = chan; |
| 5047 | i++; |
| 5048 | } |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | if (!i) { |
| 5053 | err = -EINVAL; |
| 5054 | goto out_free; |
| 5055 | } |
| 5056 | |
| 5057 | request->n_channels = i; |
| 5058 | |
| 5059 | i = 0; |
| 5060 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5061 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5062 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5063 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5064 | err = -EINVAL; |
| 5065 | goto out_free; |
| 5066 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5067 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5068 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5069 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5070 | i++; |
| 5071 | } |
| 5072 | } |
| 5073 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5074 | i = 0; |
| 5075 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5076 | nla_for_each_nested(attr, |
| 5077 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5078 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5079 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5080 | |
| 5081 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5082 | nla_data(attr), nla_len(attr), |
| 5083 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5084 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5085 | if (ssid) { |
| 5086 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5087 | err = -EINVAL; |
| 5088 | goto out_free; |
| 5089 | } |
| 5090 | memcpy(request->match_sets[i].ssid.ssid, |
| 5091 | nla_data(ssid), nla_len(ssid)); |
| 5092 | request->match_sets[i].ssid.ssid_len = |
| 5093 | nla_len(ssid); |
| 5094 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5095 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5096 | if (rssi) |
| 5097 | request->rssi_thold = nla_get_u32(rssi); |
| 5098 | else |
| 5099 | request->rssi_thold = |
| 5100 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5101 | i++; |
| 5102 | } |
| 5103 | } |
| 5104 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5105 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5106 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5107 | memcpy((void *)request->ie, |
| 5108 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5109 | request->ie_len); |
| 5110 | } |
| 5111 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5112 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5113 | request->flags = nla_get_u32( |
| 5114 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5115 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5116 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5117 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5118 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5119 | err = -EOPNOTSUPP; |
| 5120 | goto out_free; |
| 5121 | } |
| 5122 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5123 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5124 | request->dev = dev; |
| 5125 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5126 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5127 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5128 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5129 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5130 | if (!err) { |
| 5131 | rdev->sched_scan_req = request; |
| 5132 | nl80211_send_sched_scan(rdev, dev, |
| 5133 | NL80211_CMD_START_SCHED_SCAN); |
| 5134 | goto out; |
| 5135 | } |
| 5136 | |
| 5137 | out_free: |
| 5138 | kfree(request); |
| 5139 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5140 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5141 | return err; |
| 5142 | } |
| 5143 | |
| 5144 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5145 | struct genl_info *info) |
| 5146 | { |
| 5147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5148 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5149 | |
| 5150 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5151 | !rdev->ops->sched_scan_stop) |
| 5152 | return -EOPNOTSUPP; |
| 5153 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5154 | mutex_lock(&rdev->sched_scan_mtx); |
| 5155 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5156 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5157 | |
| 5158 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5159 | } |
| 5160 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5161 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5162 | struct genl_info *info) |
| 5163 | { |
| 5164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5165 | struct net_device *dev = info->user_ptr[1]; |
| 5166 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5167 | struct cfg80211_chan_def chandef; |
| 5168 | int err; |
| 5169 | |
| 5170 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5171 | if (err) |
| 5172 | return err; |
| 5173 | |
| 5174 | if (wdev->cac_started) |
| 5175 | return -EBUSY; |
| 5176 | |
| 5177 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5178 | if (err < 0) |
| 5179 | return err; |
| 5180 | |
| 5181 | if (err == 0) |
| 5182 | return -EINVAL; |
| 5183 | |
| 5184 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5185 | return -EINVAL; |
| 5186 | |
| 5187 | if (!rdev->ops->start_radar_detection) |
| 5188 | return -EOPNOTSUPP; |
| 5189 | |
| 5190 | mutex_lock(&rdev->devlist_mtx); |
| 5191 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5192 | chandef.chan, CHAN_MODE_SHARED, |
| 5193 | BIT(chandef.width)); |
| 5194 | if (err) |
| 5195 | goto err_locked; |
| 5196 | |
| 5197 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5198 | if (!err) { |
| 5199 | wdev->channel = chandef.chan; |
| 5200 | wdev->cac_started = true; |
| 5201 | wdev->cac_start_time = jiffies; |
| 5202 | } |
| 5203 | err_locked: |
| 5204 | mutex_unlock(&rdev->devlist_mtx); |
| 5205 | |
| 5206 | return err; |
| 5207 | } |
| 5208 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5209 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5210 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5211 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5212 | struct wireless_dev *wdev, |
| 5213 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5214 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5215 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5216 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5217 | void *hdr; |
| 5218 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5219 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5220 | |
| 5221 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5222 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5223 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5224 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5225 | if (!hdr) |
| 5226 | return -1; |
| 5227 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5228 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5229 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5230 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5231 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5232 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5233 | |
| 5234 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5235 | if (!bss) |
| 5236 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5237 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5238 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5239 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5240 | |
| 5241 | rcu_read_lock(); |
| 5242 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5243 | if (ies) { |
| 5244 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5245 | goto fail_unlock_rcu; |
| 5246 | tsf = true; |
| 5247 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5248 | ies->len, ies->data)) |
| 5249 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5250 | } |
| 5251 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5252 | if (ies) { |
| 5253 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5254 | goto fail_unlock_rcu; |
| 5255 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5256 | ies->len, ies->data)) |
| 5257 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5258 | } |
| 5259 | rcu_read_unlock(); |
| 5260 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5261 | if (res->beacon_interval && |
| 5262 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5263 | goto nla_put_failure; |
| 5264 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5265 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5266 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5267 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5268 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5269 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5270 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5272 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5273 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5274 | break; |
| 5275 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5276 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5277 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5278 | break; |
| 5279 | default: |
| 5280 | break; |
| 5281 | } |
| 5282 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5283 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5284 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5285 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5286 | if (intbss == wdev->current_bss && |
| 5287 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5288 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5289 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5290 | break; |
| 5291 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5292 | if (intbss == wdev->current_bss && |
| 5293 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5294 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5295 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5296 | break; |
| 5297 | default: |
| 5298 | break; |
| 5299 | } |
| 5300 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5301 | nla_nest_end(msg, bss); |
| 5302 | |
| 5303 | return genlmsg_end(msg, hdr); |
| 5304 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5305 | fail_unlock_rcu: |
| 5306 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5307 | nla_put_failure: |
| 5308 | genlmsg_cancel(msg, hdr); |
| 5309 | return -EMSGSIZE; |
| 5310 | } |
| 5311 | |
| 5312 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5313 | struct netlink_callback *cb) |
| 5314 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5315 | struct cfg80211_registered_device *rdev; |
| 5316 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5317 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5318 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5319 | int start = cb->args[1], idx = 0; |
| 5320 | int err; |
| 5321 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5322 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5323 | if (err) |
| 5324 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5326 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5327 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5328 | wdev_lock(wdev); |
| 5329 | spin_lock_bh(&rdev->bss_lock); |
| 5330 | cfg80211_bss_expire(rdev); |
| 5331 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5332 | cb->seq = rdev->bss_generation; |
| 5333 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5334 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5335 | if (++idx <= start) |
| 5336 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5337 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5338 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5339 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5340 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5341 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5342 | } |
| 5343 | } |
| 5344 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5345 | spin_unlock_bh(&rdev->bss_lock); |
| 5346 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5347 | |
| 5348 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5349 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5350 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5351 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5352 | } |
| 5353 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5354 | 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] | 5355 | int flags, struct net_device *dev, |
| 5356 | struct survey_info *survey) |
| 5357 | { |
| 5358 | void *hdr; |
| 5359 | struct nlattr *infoattr; |
| 5360 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5361 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5362 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5363 | if (!hdr) |
| 5364 | return -ENOMEM; |
| 5365 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5366 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5367 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5368 | |
| 5369 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5370 | if (!infoattr) |
| 5371 | goto nla_put_failure; |
| 5372 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5373 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5374 | survey->channel->center_freq)) |
| 5375 | goto nla_put_failure; |
| 5376 | |
| 5377 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5378 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5379 | goto nla_put_failure; |
| 5380 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5381 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5382 | goto nla_put_failure; |
| 5383 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5384 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5385 | survey->channel_time)) |
| 5386 | goto nla_put_failure; |
| 5387 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5388 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5389 | survey->channel_time_busy)) |
| 5390 | goto nla_put_failure; |
| 5391 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5392 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5393 | survey->channel_time_ext_busy)) |
| 5394 | goto nla_put_failure; |
| 5395 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5396 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5397 | survey->channel_time_rx)) |
| 5398 | goto nla_put_failure; |
| 5399 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5400 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5401 | survey->channel_time_tx)) |
| 5402 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5403 | |
| 5404 | nla_nest_end(msg, infoattr); |
| 5405 | |
| 5406 | return genlmsg_end(msg, hdr); |
| 5407 | |
| 5408 | nla_put_failure: |
| 5409 | genlmsg_cancel(msg, hdr); |
| 5410 | return -EMSGSIZE; |
| 5411 | } |
| 5412 | |
| 5413 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5414 | struct netlink_callback *cb) |
| 5415 | { |
| 5416 | struct survey_info survey; |
| 5417 | struct cfg80211_registered_device *dev; |
| 5418 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5419 | int survey_idx = cb->args[1]; |
| 5420 | int res; |
| 5421 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5422 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5423 | if (res) |
| 5424 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5425 | |
| 5426 | if (!dev->ops->dump_survey) { |
| 5427 | res = -EOPNOTSUPP; |
| 5428 | goto out_err; |
| 5429 | } |
| 5430 | |
| 5431 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5432 | struct ieee80211_channel *chan; |
| 5433 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5434 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5435 | if (res == -ENOENT) |
| 5436 | break; |
| 5437 | if (res) |
| 5438 | goto out_err; |
| 5439 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5440 | /* Survey without a channel doesn't make sense */ |
| 5441 | if (!survey.channel) { |
| 5442 | res = -EINVAL; |
| 5443 | goto out; |
| 5444 | } |
| 5445 | |
| 5446 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5447 | survey.channel->center_freq); |
| 5448 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5449 | survey_idx++; |
| 5450 | continue; |
| 5451 | } |
| 5452 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5453 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5454 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5455 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5456 | netdev, |
| 5457 | &survey) < 0) |
| 5458 | goto out; |
| 5459 | survey_idx++; |
| 5460 | } |
| 5461 | |
| 5462 | out: |
| 5463 | cb->args[1] = survey_idx; |
| 5464 | res = skb->len; |
| 5465 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5466 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5467 | return res; |
| 5468 | } |
| 5469 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5470 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5471 | { |
| 5472 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5473 | NL80211_WPA_VERSION_2)); |
| 5474 | } |
| 5475 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5476 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5477 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5479 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5480 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5481 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5482 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5483 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5484 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5485 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5486 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5487 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5488 | return -EINVAL; |
| 5489 | |
| 5490 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5491 | return -EINVAL; |
| 5492 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5493 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5494 | return -EINVAL; |
| 5495 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5496 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5497 | return -EINVAL; |
| 5498 | |
| 5499 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5500 | return -EINVAL; |
| 5501 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5502 | err = nl80211_parse_key(info, &key); |
| 5503 | if (err) |
| 5504 | return err; |
| 5505 | |
| 5506 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5507 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5508 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5509 | if (!key.p.key || !key.p.key_len) |
| 5510 | return -EINVAL; |
| 5511 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5512 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5513 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5514 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5515 | return -EINVAL; |
| 5516 | if (key.idx > 4) |
| 5517 | return -EINVAL; |
| 5518 | } else { |
| 5519 | key.p.key_len = 0; |
| 5520 | key.p.key = NULL; |
| 5521 | } |
| 5522 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5523 | if (key.idx >= 0) { |
| 5524 | int i; |
| 5525 | bool ok = false; |
| 5526 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5527 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5528 | ok = true; |
| 5529 | break; |
| 5530 | } |
| 5531 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5532 | if (!ok) |
| 5533 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5534 | } |
| 5535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5536 | if (!rdev->ops->auth) |
| 5537 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5538 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5539 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5540 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5541 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5542 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5543 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5544 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5545 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5546 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5547 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5548 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5549 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5550 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5551 | |
| 5552 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5553 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5554 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5555 | } |
| 5556 | |
| 5557 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5558 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5559 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5560 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5561 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5562 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5563 | return -EINVAL; |
| 5564 | |
| 5565 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5566 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5567 | return -EINVAL; |
| 5568 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5569 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5570 | /* need to include at least Auth Transaction and Status Code */ |
| 5571 | if (sae_data_len < 4) |
| 5572 | return -EINVAL; |
| 5573 | } |
| 5574 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5575 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5576 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5577 | /* |
| 5578 | * Since we no longer track auth state, ignore |
| 5579 | * requests to only change local state. |
| 5580 | */ |
| 5581 | if (local_state_change) |
| 5582 | return 0; |
| 5583 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5584 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5585 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5586 | key.p.key, key.p.key_len, key.idx, |
| 5587 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5588 | } |
| 5589 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5590 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5591 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5592 | struct cfg80211_crypto_settings *settings, |
| 5593 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5594 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5595 | memset(settings, 0, sizeof(*settings)); |
| 5596 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5597 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5598 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5599 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5600 | u16 proto; |
| 5601 | proto = nla_get_u16( |
| 5602 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5603 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5604 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5605 | proto != ETH_P_PAE) |
| 5606 | return -EINVAL; |
| 5607 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5608 | settings->control_port_no_encrypt = true; |
| 5609 | } else |
| 5610 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5611 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5612 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5613 | void *data; |
| 5614 | int len, i; |
| 5615 | |
| 5616 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5617 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5618 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5619 | |
| 5620 | if (len % sizeof(u32)) |
| 5621 | return -EINVAL; |
| 5622 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5623 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5624 | return -EINVAL; |
| 5625 | |
| 5626 | memcpy(settings->ciphers_pairwise, data, len); |
| 5627 | |
| 5628 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5629 | if (!cfg80211_supported_cipher_suite( |
| 5630 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5631 | settings->ciphers_pairwise[i])) |
| 5632 | return -EINVAL; |
| 5633 | } |
| 5634 | |
| 5635 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5636 | settings->cipher_group = |
| 5637 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5638 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5639 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5640 | return -EINVAL; |
| 5641 | } |
| 5642 | |
| 5643 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5644 | settings->wpa_versions = |
| 5645 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5646 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5647 | return -EINVAL; |
| 5648 | } |
| 5649 | |
| 5650 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5651 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5652 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5653 | |
| 5654 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5655 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5656 | settings->n_akm_suites = len / sizeof(u32); |
| 5657 | |
| 5658 | if (len % sizeof(u32)) |
| 5659 | return -EINVAL; |
| 5660 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5661 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5662 | return -EINVAL; |
| 5663 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5664 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | return 0; |
| 5668 | } |
| 5669 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5670 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5671 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5673 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5674 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5675 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5676 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5677 | int err, ssid_len, ie_len = 0; |
| 5678 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5679 | u32 flags = 0; |
| 5680 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5681 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5682 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5683 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5684 | return -EINVAL; |
| 5685 | |
| 5686 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5687 | !info->attrs[NL80211_ATTR_SSID] || |
| 5688 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5689 | return -EINVAL; |
| 5690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5691 | if (!rdev->ops->assoc) |
| 5692 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5693 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5696 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5697 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5698 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5699 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5700 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5701 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5702 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5703 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5704 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5705 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5706 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5707 | |
| 5708 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5709 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5710 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5711 | } |
| 5712 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5713 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5714 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5715 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5716 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5717 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5718 | else if (mfp != NL80211_MFP_NO) |
| 5719 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5720 | } |
| 5721 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5722 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5723 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5724 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5725 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5726 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5727 | |
| 5728 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5729 | ht_capa_mask = |
| 5730 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5731 | |
| 5732 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5733 | if (!ht_capa_mask) |
| 5734 | return -EINVAL; |
| 5735 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5736 | } |
| 5737 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5738 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5739 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5740 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5741 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5742 | &crypto, flags, ht_capa, |
| 5743 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5744 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5745 | return err; |
| 5746 | } |
| 5747 | |
| 5748 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5749 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5751 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5752 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5753 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5754 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5755 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5756 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5757 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5758 | return -EINVAL; |
| 5759 | |
| 5760 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5761 | return -EINVAL; |
| 5762 | |
| 5763 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5764 | return -EINVAL; |
| 5765 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5766 | if (!rdev->ops->deauth) |
| 5767 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5768 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5769 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5770 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5771 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5772 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5773 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5774 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5775 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5776 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5777 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5778 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5779 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5780 | |
| 5781 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5782 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5783 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5784 | } |
| 5785 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5786 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5787 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5788 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5789 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5795 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5796 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5797 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5798 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5799 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5800 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5801 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5802 | return -EINVAL; |
| 5803 | |
| 5804 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5805 | return -EINVAL; |
| 5806 | |
| 5807 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5808 | return -EINVAL; |
| 5809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5810 | if (!rdev->ops->disassoc) |
| 5811 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5812 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5813 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5814 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5815 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5816 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5817 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5818 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5819 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5820 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5821 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5822 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5823 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5824 | |
| 5825 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5826 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5827 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5828 | } |
| 5829 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5830 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5831 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5832 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5833 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5834 | } |
| 5835 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5836 | static bool |
| 5837 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5838 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5839 | int rateval) |
| 5840 | { |
| 5841 | struct wiphy *wiphy = &rdev->wiphy; |
| 5842 | bool found = false; |
| 5843 | int band, i; |
| 5844 | |
| 5845 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5846 | struct ieee80211_supported_band *sband; |
| 5847 | |
| 5848 | sband = wiphy->bands[band]; |
| 5849 | if (!sband) |
| 5850 | continue; |
| 5851 | |
| 5852 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5853 | if (sband->bitrates[i].bitrate == rateval) { |
| 5854 | mcast_rate[band] = i + 1; |
| 5855 | found = true; |
| 5856 | break; |
| 5857 | } |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | return found; |
| 5862 | } |
| 5863 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5864 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5865 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5867 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5868 | struct cfg80211_ibss_params ibss; |
| 5869 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5870 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5871 | int err; |
| 5872 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5873 | memset(&ibss, 0, sizeof(ibss)); |
| 5874 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5875 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5876 | return -EINVAL; |
| 5877 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5878 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5879 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5880 | return -EINVAL; |
| 5881 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5882 | ibss.beacon_interval = 100; |
| 5883 | |
| 5884 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5885 | ibss.beacon_interval = |
| 5886 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5887 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5888 | return -EINVAL; |
| 5889 | } |
| 5890 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5891 | if (!rdev->ops->join_ibss) |
| 5892 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5893 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5894 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5895 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5896 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5897 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5898 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5899 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5900 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5901 | |
| 5902 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5903 | return -EINVAL; |
| 5904 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5905 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5906 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5907 | |
| 5908 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5909 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5910 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5911 | } |
| 5912 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5913 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5914 | if (err) |
| 5915 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5916 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5917 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5918 | return -EINVAL; |
| 5919 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5920 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5921 | return -EINVAL; |
| 5922 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5923 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5924 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5925 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5926 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5927 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5928 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5929 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5930 | u8 *rates = |
| 5931 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5932 | int n_rates = |
| 5933 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5934 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5935 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5936 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5937 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5938 | &ibss.basic_rates); |
| 5939 | if (err) |
| 5940 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5941 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5942 | |
| 5943 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5944 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5945 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5946 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5947 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5948 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5949 | bool no_ht = false; |
| 5950 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5951 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5952 | info->attrs[NL80211_ATTR_KEYS], |
| 5953 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5954 | if (IS_ERR(connkeys)) |
| 5955 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5956 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5957 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5958 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5959 | kfree(connkeys); |
| 5960 | return -EINVAL; |
| 5961 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5962 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5963 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5964 | ibss.control_port = |
| 5965 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5966 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5967 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5968 | if (err) |
| 5969 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5970 | return err; |
| 5971 | } |
| 5972 | |
| 5973 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5974 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5976 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5977 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5978 | if (!rdev->ops->leave_ibss) |
| 5979 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5980 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5981 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5982 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5983 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5984 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5985 | } |
| 5986 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5987 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5988 | { |
| 5989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5990 | struct net_device *dev = info->user_ptr[1]; |
| 5991 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5992 | u32 nla_rate; |
| 5993 | int err; |
| 5994 | |
| 5995 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5996 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5997 | return -EOPNOTSUPP; |
| 5998 | |
| 5999 | if (!rdev->ops->set_mcast_rate) |
| 6000 | return -EOPNOTSUPP; |
| 6001 | |
| 6002 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6003 | |
| 6004 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6005 | return -EINVAL; |
| 6006 | |
| 6007 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6008 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6009 | return -EINVAL; |
| 6010 | |
| 6011 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6012 | |
| 6013 | return err; |
| 6014 | } |
| 6015 | |
| 6016 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6017 | #ifdef CONFIG_NL80211_TESTMODE |
| 6018 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6019 | .name = "testmode", |
| 6020 | }; |
| 6021 | |
| 6022 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6023 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6025 | int err; |
| 6026 | |
| 6027 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6028 | return -EINVAL; |
| 6029 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6030 | err = -EOPNOTSUPP; |
| 6031 | if (rdev->ops->testmode_cmd) { |
| 6032 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6033 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6034 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6035 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6036 | rdev->testmode_info = NULL; |
| 6037 | } |
| 6038 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6039 | return err; |
| 6040 | } |
| 6041 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6042 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6043 | struct netlink_callback *cb) |
| 6044 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6045 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6046 | int err; |
| 6047 | long phy_idx; |
| 6048 | void *data = NULL; |
| 6049 | int data_len = 0; |
| 6050 | |
| 6051 | if (cb->args[0]) { |
| 6052 | /* |
| 6053 | * 0 is a valid index, but not valid for args[0], |
| 6054 | * so we need to offset by 1. |
| 6055 | */ |
| 6056 | phy_idx = cb->args[0] - 1; |
| 6057 | } else { |
| 6058 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6059 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6060 | nl80211_policy); |
| 6061 | if (err) |
| 6062 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6063 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6064 | mutex_lock(&cfg80211_mutex); |
| 6065 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6066 | nl80211_fam.attrbuf); |
| 6067 | if (IS_ERR(rdev)) { |
| 6068 | mutex_unlock(&cfg80211_mutex); |
| 6069 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6070 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6071 | phy_idx = rdev->wiphy_idx; |
| 6072 | rdev = NULL; |
| 6073 | mutex_unlock(&cfg80211_mutex); |
| 6074 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6075 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6076 | cb->args[1] = |
| 6077 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6078 | } |
| 6079 | |
| 6080 | if (cb->args[1]) { |
| 6081 | data = nla_data((void *)cb->args[1]); |
| 6082 | data_len = nla_len((void *)cb->args[1]); |
| 6083 | } |
| 6084 | |
| 6085 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6086 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6087 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6088 | mutex_unlock(&cfg80211_mutex); |
| 6089 | return -ENOENT; |
| 6090 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6091 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6092 | mutex_unlock(&cfg80211_mutex); |
| 6093 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6094 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6095 | err = -EOPNOTSUPP; |
| 6096 | goto out_err; |
| 6097 | } |
| 6098 | |
| 6099 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6100 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6101 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6102 | NL80211_CMD_TESTMODE); |
| 6103 | struct nlattr *tmdata; |
| 6104 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6105 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6106 | genlmsg_cancel(skb, hdr); |
| 6107 | break; |
| 6108 | } |
| 6109 | |
| 6110 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6111 | if (!tmdata) { |
| 6112 | genlmsg_cancel(skb, hdr); |
| 6113 | break; |
| 6114 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6115 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6116 | nla_nest_end(skb, tmdata); |
| 6117 | |
| 6118 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6119 | genlmsg_cancel(skb, hdr); |
| 6120 | break; |
| 6121 | } else if (err) { |
| 6122 | genlmsg_cancel(skb, hdr); |
| 6123 | goto out_err; |
| 6124 | } |
| 6125 | |
| 6126 | genlmsg_end(skb, hdr); |
| 6127 | } |
| 6128 | |
| 6129 | err = skb->len; |
| 6130 | /* see above */ |
| 6131 | cb->args[0] = phy_idx + 1; |
| 6132 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6133 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6134 | return err; |
| 6135 | } |
| 6136 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6137 | static struct sk_buff * |
| 6138 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6139 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6140 | { |
| 6141 | struct sk_buff *skb; |
| 6142 | void *hdr; |
| 6143 | struct nlattr *data; |
| 6144 | |
| 6145 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6146 | if (!skb) |
| 6147 | return NULL; |
| 6148 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6149 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6150 | if (!hdr) { |
| 6151 | kfree_skb(skb); |
| 6152 | return NULL; |
| 6153 | } |
| 6154 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6155 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6156 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6157 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6158 | |
| 6159 | ((void **)skb->cb)[0] = rdev; |
| 6160 | ((void **)skb->cb)[1] = hdr; |
| 6161 | ((void **)skb->cb)[2] = data; |
| 6162 | |
| 6163 | return skb; |
| 6164 | |
| 6165 | nla_put_failure: |
| 6166 | kfree_skb(skb); |
| 6167 | return NULL; |
| 6168 | } |
| 6169 | |
| 6170 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6171 | int approxlen) |
| 6172 | { |
| 6173 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6174 | |
| 6175 | if (WARN_ON(!rdev->testmode_info)) |
| 6176 | return NULL; |
| 6177 | |
| 6178 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6179 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6180 | rdev->testmode_info->snd_seq, |
| 6181 | GFP_KERNEL); |
| 6182 | } |
| 6183 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6184 | |
| 6185 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6186 | { |
| 6187 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6188 | void *hdr = ((void **)skb->cb)[1]; |
| 6189 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6190 | |
| 6191 | if (WARN_ON(!rdev->testmode_info)) { |
| 6192 | kfree_skb(skb); |
| 6193 | return -EINVAL; |
| 6194 | } |
| 6195 | |
| 6196 | nla_nest_end(skb, data); |
| 6197 | genlmsg_end(skb, hdr); |
| 6198 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6199 | } |
| 6200 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6201 | |
| 6202 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6203 | int approxlen, gfp_t gfp) |
| 6204 | { |
| 6205 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6206 | |
| 6207 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6208 | } |
| 6209 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6210 | |
| 6211 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6212 | { |
| 6213 | void *hdr = ((void **)skb->cb)[1]; |
| 6214 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6215 | |
| 6216 | nla_nest_end(skb, data); |
| 6217 | genlmsg_end(skb, hdr); |
| 6218 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6219 | } |
| 6220 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6221 | #endif |
| 6222 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6223 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6224 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6226 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6227 | struct cfg80211_connect_params connect; |
| 6228 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6229 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6230 | int err; |
| 6231 | |
| 6232 | memset(&connect, 0, sizeof(connect)); |
| 6233 | |
| 6234 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6235 | return -EINVAL; |
| 6236 | |
| 6237 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6238 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6239 | return -EINVAL; |
| 6240 | |
| 6241 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6242 | connect.auth_type = |
| 6243 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6244 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6245 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6246 | return -EINVAL; |
| 6247 | } else |
| 6248 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6249 | |
| 6250 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6251 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6252 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6253 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6254 | if (err) |
| 6255 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6256 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6257 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6258 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6259 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6260 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6261 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6262 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6263 | connect.bg_scan_period = -1; |
| 6264 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6265 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6266 | connect.bg_scan_period = |
| 6267 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6268 | } |
| 6269 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6270 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6271 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6272 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6273 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6274 | |
| 6275 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6276 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6277 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6278 | } |
| 6279 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6280 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6281 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6282 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6283 | connect.mfp != NL80211_MFP_NO) |
| 6284 | return -EINVAL; |
| 6285 | } else { |
| 6286 | connect.mfp = NL80211_MFP_NO; |
| 6287 | } |
| 6288 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6289 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6290 | connect.channel = |
| 6291 | ieee80211_get_channel(wiphy, |
| 6292 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6293 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6294 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6295 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6296 | } |
| 6297 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6298 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6299 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6300 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6301 | if (IS_ERR(connkeys)) |
| 6302 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6303 | } |
| 6304 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6305 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6306 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6307 | |
| 6308 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6309 | memcpy(&connect.ht_capa_mask, |
| 6310 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6311 | sizeof(connect.ht_capa_mask)); |
| 6312 | |
| 6313 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6314 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6315 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6316 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6317 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6318 | memcpy(&connect.ht_capa, |
| 6319 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6320 | sizeof(connect.ht_capa)); |
| 6321 | } |
| 6322 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6323 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6324 | if (err) |
| 6325 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6326 | return err; |
| 6327 | } |
| 6328 | |
| 6329 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6330 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6332 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6333 | u16 reason; |
| 6334 | |
| 6335 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6336 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6337 | else |
| 6338 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6339 | |
| 6340 | if (reason == 0) |
| 6341 | return -EINVAL; |
| 6342 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6343 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6344 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6345 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6347 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6348 | } |
| 6349 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6350 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6351 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6353 | struct net *net; |
| 6354 | int err; |
| 6355 | u32 pid; |
| 6356 | |
| 6357 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6358 | return -EINVAL; |
| 6359 | |
| 6360 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6361 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6362 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6363 | if (IS_ERR(net)) |
| 6364 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6365 | |
| 6366 | err = 0; |
| 6367 | |
| 6368 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6369 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6370 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6371 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6372 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6373 | return err; |
| 6374 | } |
| 6375 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6376 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6377 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6379 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6380 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6382 | struct cfg80211_pmksa pmksa; |
| 6383 | |
| 6384 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6385 | |
| 6386 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6387 | return -EINVAL; |
| 6388 | |
| 6389 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6390 | return -EINVAL; |
| 6391 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6392 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6393 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6394 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6395 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6396 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6397 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6398 | |
| 6399 | switch (info->genlhdr->cmd) { |
| 6400 | case NL80211_CMD_SET_PMKSA: |
| 6401 | rdev_ops = rdev->ops->set_pmksa; |
| 6402 | break; |
| 6403 | case NL80211_CMD_DEL_PMKSA: |
| 6404 | rdev_ops = rdev->ops->del_pmksa; |
| 6405 | break; |
| 6406 | default: |
| 6407 | WARN_ON(1); |
| 6408 | break; |
| 6409 | } |
| 6410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6411 | if (!rdev_ops) |
| 6412 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6414 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6420 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6421 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6422 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6423 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6424 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6426 | if (!rdev->ops->flush_pmksa) |
| 6427 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6428 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6429 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6430 | } |
| 6431 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6432 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6433 | { |
| 6434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6435 | struct net_device *dev = info->user_ptr[1]; |
| 6436 | u8 action_code, dialog_token; |
| 6437 | u16 status_code; |
| 6438 | u8 *peer; |
| 6439 | |
| 6440 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6441 | !rdev->ops->tdls_mgmt) |
| 6442 | return -EOPNOTSUPP; |
| 6443 | |
| 6444 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6445 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6446 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6447 | !info->attrs[NL80211_ATTR_IE] || |
| 6448 | !info->attrs[NL80211_ATTR_MAC]) |
| 6449 | return -EINVAL; |
| 6450 | |
| 6451 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6452 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6453 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6454 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6455 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6456 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6457 | dialog_token, status_code, |
| 6458 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6459 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6460 | } |
| 6461 | |
| 6462 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6463 | { |
| 6464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6465 | struct net_device *dev = info->user_ptr[1]; |
| 6466 | enum nl80211_tdls_operation operation; |
| 6467 | u8 *peer; |
| 6468 | |
| 6469 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6470 | !rdev->ops->tdls_oper) |
| 6471 | return -EOPNOTSUPP; |
| 6472 | |
| 6473 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6474 | !info->attrs[NL80211_ATTR_MAC]) |
| 6475 | return -EINVAL; |
| 6476 | |
| 6477 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6478 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6479 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6480 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6481 | } |
| 6482 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6483 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6484 | struct genl_info *info) |
| 6485 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6487 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6488 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6489 | struct sk_buff *msg; |
| 6490 | void *hdr; |
| 6491 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6492 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6493 | int err; |
| 6494 | |
| 6495 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6496 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6497 | return -EINVAL; |
| 6498 | |
| 6499 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6500 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6501 | if (!rdev->ops->remain_on_channel || |
| 6502 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6504 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6505 | /* |
| 6506 | * We should be on that channel for at least a minimum amount of |
| 6507 | * time (10ms) but no longer than the driver supports. |
| 6508 | */ |
| 6509 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6510 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6511 | return -EINVAL; |
| 6512 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6513 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6514 | if (err) |
| 6515 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6516 | |
| 6517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6518 | if (!msg) |
| 6519 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6520 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6521 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6522 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6523 | |
| 6524 | if (IS_ERR(hdr)) { |
| 6525 | err = PTR_ERR(hdr); |
| 6526 | goto free_msg; |
| 6527 | } |
| 6528 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6529 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6530 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6531 | |
| 6532 | if (err) |
| 6533 | goto free_msg; |
| 6534 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6535 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6536 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6537 | |
| 6538 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6539 | |
| 6540 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6541 | |
| 6542 | nla_put_failure: |
| 6543 | err = -ENOBUFS; |
| 6544 | free_msg: |
| 6545 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6546 | return err; |
| 6547 | } |
| 6548 | |
| 6549 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6550 | struct genl_info *info) |
| 6551 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6553 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6554 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6555 | |
| 6556 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6557 | return -EINVAL; |
| 6558 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6559 | if (!rdev->ops->cancel_remain_on_channel) |
| 6560 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6561 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6562 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6563 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6564 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6565 | } |
| 6566 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6567 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6568 | u8 *rates, u8 rates_len) |
| 6569 | { |
| 6570 | u8 i; |
| 6571 | u32 mask = 0; |
| 6572 | |
| 6573 | for (i = 0; i < rates_len; i++) { |
| 6574 | int rate = (rates[i] & 0x7f) * 5; |
| 6575 | int ridx; |
| 6576 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6577 | struct ieee80211_rate *srate = |
| 6578 | &sband->bitrates[ridx]; |
| 6579 | if (rate == srate->bitrate) { |
| 6580 | mask |= 1 << ridx; |
| 6581 | break; |
| 6582 | } |
| 6583 | } |
| 6584 | if (ridx == sband->n_bitrates) |
| 6585 | return 0; /* rate not found */ |
| 6586 | } |
| 6587 | |
| 6588 | return mask; |
| 6589 | } |
| 6590 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6591 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6592 | u8 *rates, u8 rates_len, |
| 6593 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6594 | { |
| 6595 | u8 i; |
| 6596 | |
| 6597 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6598 | |
| 6599 | for (i = 0; i < rates_len; i++) { |
| 6600 | int ridx, rbit; |
| 6601 | |
| 6602 | ridx = rates[i] / 8; |
| 6603 | rbit = BIT(rates[i] % 8); |
| 6604 | |
| 6605 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6606 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6607 | return false; |
| 6608 | |
| 6609 | /* check availability */ |
| 6610 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6611 | mcs[ridx] |= rbit; |
| 6612 | else |
| 6613 | return false; |
| 6614 | } |
| 6615 | |
| 6616 | return true; |
| 6617 | } |
| 6618 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6619 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6620 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6621 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6622 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6623 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6624 | }; |
| 6625 | |
| 6626 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6627 | struct genl_info *info) |
| 6628 | { |
| 6629 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6631 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6632 | int rem, i; |
| 6633 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6634 | struct nlattr *tx_rates; |
| 6635 | struct ieee80211_supported_band *sband; |
| 6636 | |
| 6637 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6638 | return -EINVAL; |
| 6639 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6640 | if (!rdev->ops->set_bitrate_mask) |
| 6641 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6642 | |
| 6643 | memset(&mask, 0, sizeof(mask)); |
| 6644 | /* Default to all rates enabled */ |
| 6645 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6646 | sband = rdev->wiphy.bands[i]; |
| 6647 | mask.control[i].legacy = |
| 6648 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6649 | if (sband) |
| 6650 | memcpy(mask.control[i].mcs, |
| 6651 | sband->ht_cap.mcs.rx_mask, |
| 6652 | sizeof(mask.control[i].mcs)); |
| 6653 | else |
| 6654 | memset(mask.control[i].mcs, 0, |
| 6655 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | /* |
| 6659 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6660 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6661 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6662 | 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] | 6663 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6664 | { |
| 6665 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6666 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6667 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6668 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6669 | if (sband == NULL) |
| 6670 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6671 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6672 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6673 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6674 | mask.control[band].legacy = rateset_to_mask( |
| 6675 | sband, |
| 6676 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6677 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6678 | if ((mask.control[band].legacy == 0) && |
| 6679 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6680 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6681 | } |
| 6682 | if (tb[NL80211_TXRATE_MCS]) { |
| 6683 | if (!ht_rateset_to_mask( |
| 6684 | sband, |
| 6685 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6686 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6687 | mask.control[band].mcs)) |
| 6688 | return -EINVAL; |
| 6689 | } |
| 6690 | |
| 6691 | if (mask.control[band].legacy == 0) { |
| 6692 | /* don't allow empty legacy rates if HT |
| 6693 | * is not even supported. */ |
| 6694 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6695 | return -EINVAL; |
| 6696 | |
| 6697 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6698 | if (mask.control[band].mcs[i]) |
| 6699 | break; |
| 6700 | |
| 6701 | /* legacy and mcs rates may not be both empty */ |
| 6702 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6703 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6704 | } |
| 6705 | } |
| 6706 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6707 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6708 | } |
| 6709 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6710 | 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] | 6711 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6713 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6714 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6715 | |
| 6716 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6717 | return -EINVAL; |
| 6718 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6719 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6720 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6721 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6722 | switch (wdev->iftype) { |
| 6723 | case NL80211_IFTYPE_STATION: |
| 6724 | case NL80211_IFTYPE_ADHOC: |
| 6725 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6726 | case NL80211_IFTYPE_AP: |
| 6727 | case NL80211_IFTYPE_AP_VLAN: |
| 6728 | case NL80211_IFTYPE_MESH_POINT: |
| 6729 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6730 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6731 | break; |
| 6732 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6733 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6734 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6735 | |
| 6736 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6737 | if (!rdev->ops->mgmt_tx) |
| 6738 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6739 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6740 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6741 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6742 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6743 | } |
| 6744 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6745 | 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] | 6746 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6748 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6749 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6750 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6751 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6752 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6753 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6754 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6755 | bool offchan, no_cck, dont_wait_for_ack; |
| 6756 | |
| 6757 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6758 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6759 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6760 | return -EINVAL; |
| 6761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6762 | if (!rdev->ops->mgmt_tx) |
| 6763 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6764 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6765 | switch (wdev->iftype) { |
| 6766 | case NL80211_IFTYPE_STATION: |
| 6767 | case NL80211_IFTYPE_ADHOC: |
| 6768 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6769 | case NL80211_IFTYPE_AP: |
| 6770 | case NL80211_IFTYPE_AP_VLAN: |
| 6771 | case NL80211_IFTYPE_MESH_POINT: |
| 6772 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6773 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6774 | break; |
| 6775 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6776 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6777 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6778 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6779 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6780 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6781 | return -EINVAL; |
| 6782 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6783 | |
| 6784 | /* |
| 6785 | * We should wait on the channel for at least a minimum amount |
| 6786 | * of time (10ms) but no longer than the driver supports. |
| 6787 | */ |
| 6788 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6789 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6790 | return -EINVAL; |
| 6791 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6792 | } |
| 6793 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6794 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6795 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6796 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6797 | return -EINVAL; |
| 6798 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6799 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6800 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6801 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6802 | if (err) |
| 6803 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6804 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6805 | if (!dont_wait_for_ack) { |
| 6806 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6807 | if (!msg) |
| 6808 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6809 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6810 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6811 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6812 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6813 | if (IS_ERR(hdr)) { |
| 6814 | err = PTR_ERR(hdr); |
| 6815 | goto free_msg; |
| 6816 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6817 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6818 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6819 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6820 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6821 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6822 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6823 | if (err) |
| 6824 | goto free_msg; |
| 6825 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6826 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6827 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6828 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6829 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6830 | genlmsg_end(msg, hdr); |
| 6831 | return genlmsg_reply(msg, info); |
| 6832 | } |
| 6833 | |
| 6834 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6835 | |
| 6836 | nla_put_failure: |
| 6837 | err = -ENOBUFS; |
| 6838 | free_msg: |
| 6839 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6840 | return err; |
| 6841 | } |
| 6842 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6843 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6844 | { |
| 6845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6846 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6847 | u64 cookie; |
| 6848 | |
| 6849 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6850 | return -EINVAL; |
| 6851 | |
| 6852 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6853 | return -EOPNOTSUPP; |
| 6854 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6855 | switch (wdev->iftype) { |
| 6856 | case NL80211_IFTYPE_STATION: |
| 6857 | case NL80211_IFTYPE_ADHOC: |
| 6858 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6859 | case NL80211_IFTYPE_AP: |
| 6860 | case NL80211_IFTYPE_AP_VLAN: |
| 6861 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6862 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6863 | break; |
| 6864 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6865 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6866 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6867 | |
| 6868 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6869 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6870 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6871 | } |
| 6872 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6873 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6874 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6876 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6877 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6878 | u8 ps_state; |
| 6879 | bool state; |
| 6880 | int err; |
| 6881 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6882 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6883 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6884 | |
| 6885 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6887 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6888 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6889 | |
| 6890 | wdev = dev->ieee80211_ptr; |
| 6891 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6892 | if (!rdev->ops->set_power_mgmt) |
| 6893 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6894 | |
| 6895 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6896 | |
| 6897 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6898 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6899 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6900 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6901 | if (!err) |
| 6902 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6903 | return err; |
| 6904 | } |
| 6905 | |
| 6906 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6907 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6909 | enum nl80211_ps_state ps_state; |
| 6910 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6911 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6912 | struct sk_buff *msg; |
| 6913 | void *hdr; |
| 6914 | int err; |
| 6915 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6916 | wdev = dev->ieee80211_ptr; |
| 6917 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6918 | if (!rdev->ops->set_power_mgmt) |
| 6919 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6920 | |
| 6921 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6922 | if (!msg) |
| 6923 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6924 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6925 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6926 | NL80211_CMD_GET_POWER_SAVE); |
| 6927 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6928 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6929 | goto free_msg; |
| 6930 | } |
| 6931 | |
| 6932 | if (wdev->ps) |
| 6933 | ps_state = NL80211_PS_ENABLED; |
| 6934 | else |
| 6935 | ps_state = NL80211_PS_DISABLED; |
| 6936 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6937 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6938 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6939 | |
| 6940 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6941 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6942 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6943 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6944 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6945 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6946 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6947 | return err; |
| 6948 | } |
| 6949 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6950 | static struct nla_policy |
| 6951 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6952 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6953 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6954 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6955 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6956 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6957 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6958 | }; |
| 6959 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6960 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6961 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6962 | { |
| 6963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6964 | struct wireless_dev *wdev; |
| 6965 | struct net_device *dev = info->user_ptr[1]; |
| 6966 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6967 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6968 | return -EINVAL; |
| 6969 | |
| 6970 | wdev = dev->ieee80211_ptr; |
| 6971 | |
| 6972 | if (!rdev->ops->set_cqm_txe_config) |
| 6973 | return -EOPNOTSUPP; |
| 6974 | |
| 6975 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6976 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6977 | return -EOPNOTSUPP; |
| 6978 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6979 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6982 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6983 | s32 threshold, u32 hysteresis) |
| 6984 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6986 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6987 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6988 | |
| 6989 | if (threshold > 0) |
| 6990 | return -EINVAL; |
| 6991 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6992 | wdev = dev->ieee80211_ptr; |
| 6993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6994 | if (!rdev->ops->set_cqm_rssi_config) |
| 6995 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6996 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6997 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6998 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6999 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7000 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7001 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7005 | { |
| 7006 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7007 | struct nlattr *cqm; |
| 7008 | int err; |
| 7009 | |
| 7010 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7011 | if (!cqm) { |
| 7012 | err = -EINVAL; |
| 7013 | goto out; |
| 7014 | } |
| 7015 | |
| 7016 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7017 | nl80211_attr_cqm_policy); |
| 7018 | if (err) |
| 7019 | goto out; |
| 7020 | |
| 7021 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7022 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7023 | s32 threshold; |
| 7024 | u32 hysteresis; |
| 7025 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7026 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7027 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7028 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7029 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7030 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7031 | u32 rate, pkts, intvl; |
| 7032 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7033 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7034 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7035 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7036 | } else |
| 7037 | err = -EINVAL; |
| 7038 | |
| 7039 | out: |
| 7040 | return err; |
| 7041 | } |
| 7042 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7043 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7044 | { |
| 7045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7046 | struct net_device *dev = info->user_ptr[1]; |
| 7047 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7048 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7049 | int err; |
| 7050 | |
| 7051 | /* start with default */ |
| 7052 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7053 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7054 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7055 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7056 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7057 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7058 | if (err) |
| 7059 | return err; |
| 7060 | } |
| 7061 | |
| 7062 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7063 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7064 | return -EINVAL; |
| 7065 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7066 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7067 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7068 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7069 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7070 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7071 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7072 | return -EINVAL; |
| 7073 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7074 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7075 | setup.beacon_interval = |
| 7076 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7077 | if (setup.beacon_interval < 10 || |
| 7078 | setup.beacon_interval > 10000) |
| 7079 | return -EINVAL; |
| 7080 | } |
| 7081 | |
| 7082 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7083 | setup.dtim_period = |
| 7084 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7085 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7086 | return -EINVAL; |
| 7087 | } |
| 7088 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7089 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7090 | /* parse additional setup parameters if given */ |
| 7091 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7092 | if (err) |
| 7093 | return err; |
| 7094 | } |
| 7095 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7096 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7097 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7098 | if (err) |
| 7099 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7100 | } else { |
| 7101 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7102 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7103 | } |
| 7104 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7105 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7109 | { |
| 7110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7111 | struct net_device *dev = info->user_ptr[1]; |
| 7112 | |
| 7113 | return cfg80211_leave_mesh(rdev, dev); |
| 7114 | } |
| 7115 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7116 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7117 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7118 | struct cfg80211_registered_device *rdev) |
| 7119 | { |
| 7120 | struct nlattr *nl_pats, *nl_pat; |
| 7121 | int i, pat_len; |
| 7122 | |
| 7123 | if (!rdev->wowlan->n_patterns) |
| 7124 | return 0; |
| 7125 | |
| 7126 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7127 | if (!nl_pats) |
| 7128 | return -ENOBUFS; |
| 7129 | |
| 7130 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7131 | nl_pat = nla_nest_start(msg, i + 1); |
| 7132 | if (!nl_pat) |
| 7133 | return -ENOBUFS; |
| 7134 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7135 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7136 | DIV_ROUND_UP(pat_len, 8), |
| 7137 | rdev->wowlan->patterns[i].mask) || |
| 7138 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7139 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7140 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7141 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7142 | return -ENOBUFS; |
| 7143 | nla_nest_end(msg, nl_pat); |
| 7144 | } |
| 7145 | nla_nest_end(msg, nl_pats); |
| 7146 | |
| 7147 | return 0; |
| 7148 | } |
| 7149 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7150 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7151 | struct cfg80211_wowlan_tcp *tcp) |
| 7152 | { |
| 7153 | struct nlattr *nl_tcp; |
| 7154 | |
| 7155 | if (!tcp) |
| 7156 | return 0; |
| 7157 | |
| 7158 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7159 | if (!nl_tcp) |
| 7160 | return -ENOBUFS; |
| 7161 | |
| 7162 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7163 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7164 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7165 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7166 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7167 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7168 | tcp->payload_len, tcp->payload) || |
| 7169 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7170 | tcp->data_interval) || |
| 7171 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7172 | tcp->wake_len, tcp->wake_data) || |
| 7173 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7174 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7175 | return -ENOBUFS; |
| 7176 | |
| 7177 | if (tcp->payload_seq.len && |
| 7178 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7179 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7180 | return -ENOBUFS; |
| 7181 | |
| 7182 | if (tcp->payload_tok.len && |
| 7183 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7184 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7185 | &tcp->payload_tok)) |
| 7186 | return -ENOBUFS; |
| 7187 | |
| 7188 | return 0; |
| 7189 | } |
| 7190 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7191 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7192 | { |
| 7193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7194 | struct sk_buff *msg; |
| 7195 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7196 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7197 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7198 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7199 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7200 | return -EOPNOTSUPP; |
| 7201 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7202 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7203 | /* adjust size to have room for all the data */ |
| 7204 | size += rdev->wowlan->tcp->tokens_size + |
| 7205 | rdev->wowlan->tcp->payload_len + |
| 7206 | rdev->wowlan->tcp->wake_len + |
| 7207 | rdev->wowlan->tcp->wake_len / 8; |
| 7208 | } |
| 7209 | |
| 7210 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7211 | if (!msg) |
| 7212 | return -ENOMEM; |
| 7213 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7214 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7215 | NL80211_CMD_GET_WOWLAN); |
| 7216 | if (!hdr) |
| 7217 | goto nla_put_failure; |
| 7218 | |
| 7219 | if (rdev->wowlan) { |
| 7220 | struct nlattr *nl_wowlan; |
| 7221 | |
| 7222 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7223 | if (!nl_wowlan) |
| 7224 | goto nla_put_failure; |
| 7225 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7226 | if ((rdev->wowlan->any && |
| 7227 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7228 | (rdev->wowlan->disconnect && |
| 7229 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7230 | (rdev->wowlan->magic_pkt && |
| 7231 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7232 | (rdev->wowlan->gtk_rekey_failure && |
| 7233 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7234 | (rdev->wowlan->eap_identity_req && |
| 7235 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7236 | (rdev->wowlan->four_way_handshake && |
| 7237 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7238 | (rdev->wowlan->rfkill_release && |
| 7239 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7240 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7241 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7242 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7243 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7244 | |
| 7245 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7246 | goto nla_put_failure; |
| 7247 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7248 | nla_nest_end(msg, nl_wowlan); |
| 7249 | } |
| 7250 | |
| 7251 | genlmsg_end(msg, hdr); |
| 7252 | return genlmsg_reply(msg, info); |
| 7253 | |
| 7254 | nla_put_failure: |
| 7255 | nlmsg_free(msg); |
| 7256 | return -ENOBUFS; |
| 7257 | } |
| 7258 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7259 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7260 | struct nlattr *attr, |
| 7261 | struct cfg80211_wowlan *trig) |
| 7262 | { |
| 7263 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7264 | struct cfg80211_wowlan_tcp *cfg; |
| 7265 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7266 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7267 | u32 size; |
| 7268 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7269 | int err, port; |
| 7270 | |
| 7271 | if (!rdev->wiphy.wowlan.tcp) |
| 7272 | return -EINVAL; |
| 7273 | |
| 7274 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7275 | nla_data(attr), nla_len(attr), |
| 7276 | nl80211_wowlan_tcp_policy); |
| 7277 | if (err) |
| 7278 | return err; |
| 7279 | |
| 7280 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7281 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7282 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7283 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7284 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7285 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7286 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7287 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7288 | return -EINVAL; |
| 7289 | |
| 7290 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7291 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7292 | return -EINVAL; |
| 7293 | |
| 7294 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 7295 | rdev->wiphy.wowlan.tcp->data_interval_max) |
| 7296 | return -EINVAL; |
| 7297 | |
| 7298 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7299 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7300 | return -EINVAL; |
| 7301 | |
| 7302 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7303 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7304 | return -EINVAL; |
| 7305 | |
| 7306 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7307 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7308 | |
| 7309 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7310 | tokens_size = tokln - sizeof(*tok); |
| 7311 | |
| 7312 | if (!tok->len || tokens_size % tok->len) |
| 7313 | return -EINVAL; |
| 7314 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7315 | return -EINVAL; |
| 7316 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7317 | return -EINVAL; |
| 7318 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7319 | return -EINVAL; |
| 7320 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7321 | return -EINVAL; |
| 7322 | if (tok->offset + tok->len > data_size) |
| 7323 | return -EINVAL; |
| 7324 | } |
| 7325 | |
| 7326 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7327 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7328 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7329 | return -EINVAL; |
| 7330 | if (seq->len == 0 || seq->len > 4) |
| 7331 | return -EINVAL; |
| 7332 | if (seq->len + seq->offset > data_size) |
| 7333 | return -EINVAL; |
| 7334 | } |
| 7335 | |
| 7336 | size = sizeof(*cfg); |
| 7337 | size += data_size; |
| 7338 | size += wake_size + wake_mask_size; |
| 7339 | size += tokens_size; |
| 7340 | |
| 7341 | cfg = kzalloc(size, GFP_KERNEL); |
| 7342 | if (!cfg) |
| 7343 | return -ENOMEM; |
| 7344 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7345 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7346 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7347 | ETH_ALEN); |
| 7348 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7349 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7350 | else |
| 7351 | port = 0; |
| 7352 | #ifdef CONFIG_INET |
| 7353 | /* allocate a socket and port for it and use it */ |
| 7354 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7355 | IPPROTO_TCP, &cfg->sock, 1); |
| 7356 | if (err) { |
| 7357 | kfree(cfg); |
| 7358 | return err; |
| 7359 | } |
| 7360 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7361 | sock_release(cfg->sock); |
| 7362 | kfree(cfg); |
| 7363 | return -EADDRINUSE; |
| 7364 | } |
| 7365 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7366 | #else |
| 7367 | if (!port) { |
| 7368 | kfree(cfg); |
| 7369 | return -EINVAL; |
| 7370 | } |
| 7371 | cfg->src_port = port; |
| 7372 | #endif |
| 7373 | |
| 7374 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7375 | cfg->payload_len = data_size; |
| 7376 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7377 | memcpy((void *)cfg->payload, |
| 7378 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7379 | data_size); |
| 7380 | if (seq) |
| 7381 | cfg->payload_seq = *seq; |
| 7382 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7383 | cfg->wake_len = wake_size; |
| 7384 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7385 | memcpy((void *)cfg->wake_data, |
| 7386 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7387 | wake_size); |
| 7388 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7389 | data_size + wake_size; |
| 7390 | memcpy((void *)cfg->wake_mask, |
| 7391 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7392 | wake_mask_size); |
| 7393 | if (tok) { |
| 7394 | cfg->tokens_size = tokens_size; |
| 7395 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7396 | } |
| 7397 | |
| 7398 | trig->tcp = cfg; |
| 7399 | |
| 7400 | return 0; |
| 7401 | } |
| 7402 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7403 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7404 | { |
| 7405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7406 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7407 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7408 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7409 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7410 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7411 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7412 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7413 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7414 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7415 | return -EOPNOTSUPP; |
| 7416 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7417 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7418 | cfg80211_rdev_free_wowlan(rdev); |
| 7419 | rdev->wowlan = NULL; |
| 7420 | goto set_wakeup; |
| 7421 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7422 | |
| 7423 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7424 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7425 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7426 | nl80211_wowlan_policy); |
| 7427 | if (err) |
| 7428 | return err; |
| 7429 | |
| 7430 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7431 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7432 | return -EINVAL; |
| 7433 | new_triggers.any = true; |
| 7434 | } |
| 7435 | |
| 7436 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7437 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7438 | return -EINVAL; |
| 7439 | new_triggers.disconnect = true; |
| 7440 | } |
| 7441 | |
| 7442 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7443 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7444 | return -EINVAL; |
| 7445 | new_triggers.magic_pkt = true; |
| 7446 | } |
| 7447 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7448 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7449 | return -EINVAL; |
| 7450 | |
| 7451 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7452 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7453 | return -EINVAL; |
| 7454 | new_triggers.gtk_rekey_failure = true; |
| 7455 | } |
| 7456 | |
| 7457 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7458 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7459 | return -EINVAL; |
| 7460 | new_triggers.eap_identity_req = true; |
| 7461 | } |
| 7462 | |
| 7463 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7464 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7465 | return -EINVAL; |
| 7466 | new_triggers.four_way_handshake = true; |
| 7467 | } |
| 7468 | |
| 7469 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7470 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7471 | return -EINVAL; |
| 7472 | new_triggers.rfkill_release = true; |
| 7473 | } |
| 7474 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7475 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7476 | struct nlattr *pat; |
| 7477 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7478 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7479 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7480 | |
| 7481 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7482 | rem) |
| 7483 | n_patterns++; |
| 7484 | if (n_patterns > wowlan->n_patterns) |
| 7485 | return -EINVAL; |
| 7486 | |
| 7487 | new_triggers.patterns = kcalloc(n_patterns, |
| 7488 | sizeof(new_triggers.patterns[0]), |
| 7489 | GFP_KERNEL); |
| 7490 | if (!new_triggers.patterns) |
| 7491 | return -ENOMEM; |
| 7492 | |
| 7493 | new_triggers.n_patterns = n_patterns; |
| 7494 | i = 0; |
| 7495 | |
| 7496 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7497 | rem) { |
| 7498 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7499 | nla_data(pat), nla_len(pat), NULL); |
| 7500 | err = -EINVAL; |
| 7501 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7502 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7503 | goto error; |
| 7504 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7505 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7506 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7507 | mask_len) |
| 7508 | goto error; |
| 7509 | if (pat_len > wowlan->pattern_max_len || |
| 7510 | pat_len < wowlan->pattern_min_len) |
| 7511 | goto error; |
| 7512 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7513 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7514 | pkt_offset = 0; |
| 7515 | else |
| 7516 | pkt_offset = nla_get_u32( |
| 7517 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7518 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7519 | goto error; |
| 7520 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7521 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7522 | new_triggers.patterns[i].mask = |
| 7523 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7524 | if (!new_triggers.patterns[i].mask) { |
| 7525 | err = -ENOMEM; |
| 7526 | goto error; |
| 7527 | } |
| 7528 | new_triggers.patterns[i].pattern = |
| 7529 | new_triggers.patterns[i].mask + mask_len; |
| 7530 | memcpy(new_triggers.patterns[i].mask, |
| 7531 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7532 | mask_len); |
| 7533 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7534 | memcpy(new_triggers.patterns[i].pattern, |
| 7535 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7536 | pat_len); |
| 7537 | i++; |
| 7538 | } |
| 7539 | } |
| 7540 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7541 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7542 | err = nl80211_parse_wowlan_tcp( |
| 7543 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7544 | &new_triggers); |
| 7545 | if (err) |
| 7546 | goto error; |
| 7547 | } |
| 7548 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7549 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7550 | if (!ntrig) { |
| 7551 | err = -ENOMEM; |
| 7552 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7553 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7554 | cfg80211_rdev_free_wowlan(rdev); |
| 7555 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7556 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7557 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7558 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7559 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7560 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7561 | return 0; |
| 7562 | error: |
| 7563 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7564 | kfree(new_triggers.patterns[i].mask); |
| 7565 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7566 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7567 | sock_release(new_triggers.tcp->sock); |
| 7568 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7569 | return err; |
| 7570 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7571 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7572 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7573 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7574 | { |
| 7575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7576 | struct net_device *dev = info->user_ptr[1]; |
| 7577 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7578 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7579 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7580 | int err; |
| 7581 | |
| 7582 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7583 | return -EINVAL; |
| 7584 | |
| 7585 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7586 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7587 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7588 | nl80211_rekey_policy); |
| 7589 | if (err) |
| 7590 | return err; |
| 7591 | |
| 7592 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7593 | return -ERANGE; |
| 7594 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7595 | return -ERANGE; |
| 7596 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7597 | return -ERANGE; |
| 7598 | |
| 7599 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7600 | NL80211_KEK_LEN); |
| 7601 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7602 | NL80211_KCK_LEN); |
| 7603 | memcpy(rekey_data.replay_ctr, |
| 7604 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7605 | NL80211_REPLAY_CTR_LEN); |
| 7606 | |
| 7607 | wdev_lock(wdev); |
| 7608 | if (!wdev->current_bss) { |
| 7609 | err = -ENOTCONN; |
| 7610 | goto out; |
| 7611 | } |
| 7612 | |
| 7613 | if (!rdev->ops->set_rekey_data) { |
| 7614 | err = -EOPNOTSUPP; |
| 7615 | goto out; |
| 7616 | } |
| 7617 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7618 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7619 | out: |
| 7620 | wdev_unlock(wdev); |
| 7621 | return err; |
| 7622 | } |
| 7623 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7624 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7625 | struct genl_info *info) |
| 7626 | { |
| 7627 | struct net_device *dev = info->user_ptr[1]; |
| 7628 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7629 | |
| 7630 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7631 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7632 | return -EINVAL; |
| 7633 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7634 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7635 | return -EBUSY; |
| 7636 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7637 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7638 | return 0; |
| 7639 | } |
| 7640 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7641 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7642 | struct genl_info *info) |
| 7643 | { |
| 7644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7645 | struct net_device *dev = info->user_ptr[1]; |
| 7646 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7647 | struct sk_buff *msg; |
| 7648 | void *hdr; |
| 7649 | const u8 *addr; |
| 7650 | u64 cookie; |
| 7651 | int err; |
| 7652 | |
| 7653 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7654 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7655 | return -EOPNOTSUPP; |
| 7656 | |
| 7657 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7658 | return -EINVAL; |
| 7659 | |
| 7660 | if (!rdev->ops->probe_client) |
| 7661 | return -EOPNOTSUPP; |
| 7662 | |
| 7663 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7664 | if (!msg) |
| 7665 | return -ENOMEM; |
| 7666 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7667 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7668 | NL80211_CMD_PROBE_CLIENT); |
| 7669 | |
| 7670 | if (IS_ERR(hdr)) { |
| 7671 | err = PTR_ERR(hdr); |
| 7672 | goto free_msg; |
| 7673 | } |
| 7674 | |
| 7675 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7676 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7677 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7678 | if (err) |
| 7679 | goto free_msg; |
| 7680 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7681 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7682 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7683 | |
| 7684 | genlmsg_end(msg, hdr); |
| 7685 | |
| 7686 | return genlmsg_reply(msg, info); |
| 7687 | |
| 7688 | nla_put_failure: |
| 7689 | err = -ENOBUFS; |
| 7690 | free_msg: |
| 7691 | nlmsg_free(msg); |
| 7692 | return err; |
| 7693 | } |
| 7694 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7695 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7696 | { |
| 7697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7698 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7699 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7700 | |
| 7701 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7702 | return -EOPNOTSUPP; |
| 7703 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7704 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7705 | if (!nreg) |
| 7706 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7707 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7708 | /* First, check if already registered. */ |
| 7709 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7710 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7711 | if (reg->nlportid == info->snd_portid) { |
| 7712 | rv = -EALREADY; |
| 7713 | goto out_err; |
| 7714 | } |
| 7715 | } |
| 7716 | /* Add it to the list */ |
| 7717 | nreg->nlportid = info->snd_portid; |
| 7718 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7719 | |
| 7720 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7721 | |
| 7722 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7723 | out_err: |
| 7724 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7725 | kfree(nreg); |
| 7726 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7727 | } |
| 7728 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7729 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7730 | { |
| 7731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7732 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7733 | int err; |
| 7734 | |
| 7735 | if (!rdev->ops->start_p2p_device) |
| 7736 | return -EOPNOTSUPP; |
| 7737 | |
| 7738 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7739 | return -EOPNOTSUPP; |
| 7740 | |
| 7741 | if (wdev->p2p_started) |
| 7742 | return 0; |
| 7743 | |
| 7744 | mutex_lock(&rdev->devlist_mtx); |
| 7745 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7746 | mutex_unlock(&rdev->devlist_mtx); |
| 7747 | if (err) |
| 7748 | return err; |
| 7749 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7750 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7751 | if (err) |
| 7752 | return err; |
| 7753 | |
| 7754 | wdev->p2p_started = true; |
| 7755 | mutex_lock(&rdev->devlist_mtx); |
| 7756 | rdev->opencount++; |
| 7757 | mutex_unlock(&rdev->devlist_mtx); |
| 7758 | |
| 7759 | return 0; |
| 7760 | } |
| 7761 | |
| 7762 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7763 | { |
| 7764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7765 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7766 | |
| 7767 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7768 | return -EOPNOTSUPP; |
| 7769 | |
| 7770 | if (!rdev->ops->stop_p2p_device) |
| 7771 | return -EOPNOTSUPP; |
| 7772 | |
| 7773 | if (!wdev->p2p_started) |
| 7774 | return 0; |
| 7775 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7776 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7777 | wdev->p2p_started = false; |
| 7778 | |
| 7779 | mutex_lock(&rdev->devlist_mtx); |
| 7780 | rdev->opencount--; |
| 7781 | mutex_unlock(&rdev->devlist_mtx); |
| 7782 | |
| 7783 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7784 | rdev->scan_req->aborted = true; |
| 7785 | ___cfg80211_scan_done(rdev, true); |
| 7786 | } |
| 7787 | |
| 7788 | return 0; |
| 7789 | } |
| 7790 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7791 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7792 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7793 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7794 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7795 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7796 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7797 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7798 | /* 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] | 7799 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7800 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7801 | |
| 7802 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7803 | struct genl_info *info) |
| 7804 | { |
| 7805 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7806 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7807 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7808 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7809 | |
| 7810 | if (rtnl) |
| 7811 | rtnl_lock(); |
| 7812 | |
| 7813 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7814 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7815 | if (IS_ERR(rdev)) { |
| 7816 | if (rtnl) |
| 7817 | rtnl_unlock(); |
| 7818 | return PTR_ERR(rdev); |
| 7819 | } |
| 7820 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7821 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7822 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7823 | mutex_lock(&cfg80211_mutex); |
| 7824 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7825 | info->attrs); |
| 7826 | if (IS_ERR(wdev)) { |
| 7827 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7828 | if (rtnl) |
| 7829 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7830 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7831 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7832 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7833 | dev = wdev->netdev; |
| 7834 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7835 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7836 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7837 | if (!dev) { |
| 7838 | mutex_unlock(&cfg80211_mutex); |
| 7839 | if (rtnl) |
| 7840 | rtnl_unlock(); |
| 7841 | return -EINVAL; |
| 7842 | } |
| 7843 | |
| 7844 | info->user_ptr[1] = dev; |
| 7845 | } else { |
| 7846 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7847 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7848 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7849 | if (dev) { |
| 7850 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7851 | !netif_running(dev)) { |
| 7852 | mutex_unlock(&cfg80211_mutex); |
| 7853 | if (rtnl) |
| 7854 | rtnl_unlock(); |
| 7855 | return -ENETDOWN; |
| 7856 | } |
| 7857 | |
| 7858 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7859 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7860 | if (!wdev->p2p_started) { |
| 7861 | mutex_unlock(&cfg80211_mutex); |
| 7862 | if (rtnl) |
| 7863 | rtnl_unlock(); |
| 7864 | return -ENETDOWN; |
| 7865 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7866 | } |
| 7867 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7868 | cfg80211_lock_rdev(rdev); |
| 7869 | |
| 7870 | mutex_unlock(&cfg80211_mutex); |
| 7871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7872 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | return 0; |
| 7876 | } |
| 7877 | |
| 7878 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7879 | struct genl_info *info) |
| 7880 | { |
| 7881 | if (info->user_ptr[0]) |
| 7882 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7883 | if (info->user_ptr[1]) { |
| 7884 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7885 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7886 | |
| 7887 | if (wdev->netdev) |
| 7888 | dev_put(wdev->netdev); |
| 7889 | } else { |
| 7890 | dev_put(info->user_ptr[1]); |
| 7891 | } |
| 7892 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7893 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7894 | rtnl_unlock(); |
| 7895 | } |
| 7896 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7897 | static struct genl_ops nl80211_ops[] = { |
| 7898 | { |
| 7899 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7900 | .doit = nl80211_get_wiphy, |
| 7901 | .dumpit = nl80211_dump_wiphy, |
| 7902 | .policy = nl80211_policy, |
| 7903 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7904 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7905 | }, |
| 7906 | { |
| 7907 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7908 | .doit = nl80211_set_wiphy, |
| 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_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7912 | }, |
| 7913 | { |
| 7914 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7915 | .doit = nl80211_get_interface, |
| 7916 | .dumpit = nl80211_dump_interface, |
| 7917 | .policy = nl80211_policy, |
| 7918 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7919 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7920 | }, |
| 7921 | { |
| 7922 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7923 | .doit = nl80211_set_interface, |
| 7924 | .policy = nl80211_policy, |
| 7925 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7926 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7927 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7928 | }, |
| 7929 | { |
| 7930 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7931 | .doit = nl80211_new_interface, |
| 7932 | .policy = nl80211_policy, |
| 7933 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7934 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7935 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7936 | }, |
| 7937 | { |
| 7938 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7939 | .doit = nl80211_del_interface, |
| 7940 | .policy = nl80211_policy, |
| 7941 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7942 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7943 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7944 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7945 | { |
| 7946 | .cmd = NL80211_CMD_GET_KEY, |
| 7947 | .doit = nl80211_get_key, |
| 7948 | .policy = nl80211_policy, |
| 7949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7951 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7952 | }, |
| 7953 | { |
| 7954 | .cmd = NL80211_CMD_SET_KEY, |
| 7955 | .doit = nl80211_set_key, |
| 7956 | .policy = nl80211_policy, |
| 7957 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7959 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7960 | }, |
| 7961 | { |
| 7962 | .cmd = NL80211_CMD_NEW_KEY, |
| 7963 | .doit = nl80211_new_key, |
| 7964 | .policy = nl80211_policy, |
| 7965 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7967 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7968 | }, |
| 7969 | { |
| 7970 | .cmd = NL80211_CMD_DEL_KEY, |
| 7971 | .doit = nl80211_del_key, |
| 7972 | .policy = nl80211_policy, |
| 7973 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7975 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7976 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7977 | { |
| 7978 | .cmd = NL80211_CMD_SET_BEACON, |
| 7979 | .policy = nl80211_policy, |
| 7980 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7981 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7982 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7983 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7984 | }, |
| 7985 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7986 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7987 | .policy = nl80211_policy, |
| 7988 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7989 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7990 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7991 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7992 | }, |
| 7993 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7994 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7995 | .policy = nl80211_policy, |
| 7996 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7997 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7999 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8000 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8001 | { |
| 8002 | .cmd = NL80211_CMD_GET_STATION, |
| 8003 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8004 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8005 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8006 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8007 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8008 | }, |
| 8009 | { |
| 8010 | .cmd = NL80211_CMD_SET_STATION, |
| 8011 | .doit = nl80211_set_station, |
| 8012 | .policy = nl80211_policy, |
| 8013 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8014 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8015 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8016 | }, |
| 8017 | { |
| 8018 | .cmd = NL80211_CMD_NEW_STATION, |
| 8019 | .doit = nl80211_new_station, |
| 8020 | .policy = nl80211_policy, |
| 8021 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8023 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8024 | }, |
| 8025 | { |
| 8026 | .cmd = NL80211_CMD_DEL_STATION, |
| 8027 | .doit = nl80211_del_station, |
| 8028 | .policy = nl80211_policy, |
| 8029 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8031 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8032 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8033 | { |
| 8034 | .cmd = NL80211_CMD_GET_MPATH, |
| 8035 | .doit = nl80211_get_mpath, |
| 8036 | .dumpit = nl80211_dump_mpath, |
| 8037 | .policy = nl80211_policy, |
| 8038 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8040 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8041 | }, |
| 8042 | { |
| 8043 | .cmd = NL80211_CMD_SET_MPATH, |
| 8044 | .doit = nl80211_set_mpath, |
| 8045 | .policy = nl80211_policy, |
| 8046 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8047 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8048 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8049 | }, |
| 8050 | { |
| 8051 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8052 | .doit = nl80211_new_mpath, |
| 8053 | .policy = nl80211_policy, |
| 8054 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8055 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8056 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8057 | }, |
| 8058 | { |
| 8059 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8060 | .doit = nl80211_del_mpath, |
| 8061 | .policy = nl80211_policy, |
| 8062 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8063 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8064 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8065 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8066 | { |
| 8067 | .cmd = NL80211_CMD_SET_BSS, |
| 8068 | .doit = nl80211_set_bss, |
| 8069 | .policy = nl80211_policy, |
| 8070 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8071 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8072 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8073 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8074 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8075 | .cmd = NL80211_CMD_GET_REG, |
| 8076 | .doit = nl80211_get_reg, |
| 8077 | .policy = nl80211_policy, |
| 8078 | /* can be retrieved by unprivileged users */ |
| 8079 | }, |
| 8080 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8081 | .cmd = NL80211_CMD_SET_REG, |
| 8082 | .doit = nl80211_set_reg, |
| 8083 | .policy = nl80211_policy, |
| 8084 | .flags = GENL_ADMIN_PERM, |
| 8085 | }, |
| 8086 | { |
| 8087 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8088 | .doit = nl80211_req_set_reg, |
| 8089 | .policy = nl80211_policy, |
| 8090 | .flags = GENL_ADMIN_PERM, |
| 8091 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8092 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8093 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8094 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8095 | .policy = nl80211_policy, |
| 8096 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8097 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8098 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8099 | }, |
| 8100 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8101 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8102 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8103 | .policy = nl80211_policy, |
| 8104 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8105 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8106 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8107 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8108 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8109 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8110 | .doit = nl80211_trigger_scan, |
| 8111 | .policy = nl80211_policy, |
| 8112 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8113 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8114 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8115 | }, |
| 8116 | { |
| 8117 | .cmd = NL80211_CMD_GET_SCAN, |
| 8118 | .policy = nl80211_policy, |
| 8119 | .dumpit = nl80211_dump_scan, |
| 8120 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8121 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8122 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8123 | .doit = nl80211_start_sched_scan, |
| 8124 | .policy = nl80211_policy, |
| 8125 | .flags = GENL_ADMIN_PERM, |
| 8126 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8127 | NL80211_FLAG_NEED_RTNL, |
| 8128 | }, |
| 8129 | { |
| 8130 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8131 | .doit = nl80211_stop_sched_scan, |
| 8132 | .policy = nl80211_policy, |
| 8133 | .flags = GENL_ADMIN_PERM, |
| 8134 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8135 | NL80211_FLAG_NEED_RTNL, |
| 8136 | }, |
| 8137 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8138 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8139 | .doit = nl80211_authenticate, |
| 8140 | .policy = nl80211_policy, |
| 8141 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8142 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8143 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8144 | }, |
| 8145 | { |
| 8146 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8147 | .doit = nl80211_associate, |
| 8148 | .policy = nl80211_policy, |
| 8149 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8150 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8151 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8152 | }, |
| 8153 | { |
| 8154 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8155 | .doit = nl80211_deauthenticate, |
| 8156 | .policy = nl80211_policy, |
| 8157 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8158 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8159 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8160 | }, |
| 8161 | { |
| 8162 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8163 | .doit = nl80211_disassociate, |
| 8164 | .policy = nl80211_policy, |
| 8165 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8167 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8168 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8169 | { |
| 8170 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8171 | .doit = nl80211_join_ibss, |
| 8172 | .policy = nl80211_policy, |
| 8173 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8174 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8175 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8176 | }, |
| 8177 | { |
| 8178 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8179 | .doit = nl80211_leave_ibss, |
| 8180 | .policy = nl80211_policy, |
| 8181 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8183 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8184 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8185 | #ifdef CONFIG_NL80211_TESTMODE |
| 8186 | { |
| 8187 | .cmd = NL80211_CMD_TESTMODE, |
| 8188 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8189 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8190 | .policy = nl80211_policy, |
| 8191 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8192 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8193 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8194 | }, |
| 8195 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8196 | { |
| 8197 | .cmd = NL80211_CMD_CONNECT, |
| 8198 | .doit = nl80211_connect, |
| 8199 | .policy = nl80211_policy, |
| 8200 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8201 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8202 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8203 | }, |
| 8204 | { |
| 8205 | .cmd = NL80211_CMD_DISCONNECT, |
| 8206 | .doit = nl80211_disconnect, |
| 8207 | .policy = nl80211_policy, |
| 8208 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8209 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8210 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8211 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8212 | { |
| 8213 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8214 | .doit = nl80211_wiphy_netns, |
| 8215 | .policy = nl80211_policy, |
| 8216 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8217 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8218 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8219 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8220 | { |
| 8221 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8222 | .policy = nl80211_policy, |
| 8223 | .dumpit = nl80211_dump_survey, |
| 8224 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8225 | { |
| 8226 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8227 | .doit = nl80211_setdel_pmksa, |
| 8228 | .policy = nl80211_policy, |
| 8229 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8230 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8231 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8232 | }, |
| 8233 | { |
| 8234 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8235 | .doit = nl80211_setdel_pmksa, |
| 8236 | .policy = nl80211_policy, |
| 8237 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8238 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8239 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8240 | }, |
| 8241 | { |
| 8242 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8243 | .doit = nl80211_flush_pmksa, |
| 8244 | .policy = nl80211_policy, |
| 8245 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8246 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8247 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8248 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8249 | { |
| 8250 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8251 | .doit = nl80211_remain_on_channel, |
| 8252 | .policy = nl80211_policy, |
| 8253 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8254 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8255 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8256 | }, |
| 8257 | { |
| 8258 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8259 | .doit = nl80211_cancel_remain_on_channel, |
| 8260 | .policy = nl80211_policy, |
| 8261 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8262 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8263 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8264 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8265 | { |
| 8266 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8267 | .doit = nl80211_set_tx_bitrate_mask, |
| 8268 | .policy = nl80211_policy, |
| 8269 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8270 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8271 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8272 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8273 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8274 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8275 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8276 | .policy = nl80211_policy, |
| 8277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8278 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8279 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8280 | }, |
| 8281 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8282 | .cmd = NL80211_CMD_FRAME, |
| 8283 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8284 | .policy = nl80211_policy, |
| 8285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8286 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8287 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8288 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8289 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8290 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8291 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8292 | .policy = nl80211_policy, |
| 8293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8294 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8295 | NL80211_FLAG_NEED_RTNL, |
| 8296 | }, |
| 8297 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8298 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8299 | .doit = nl80211_set_power_save, |
| 8300 | .policy = nl80211_policy, |
| 8301 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8302 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8303 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8304 | }, |
| 8305 | { |
| 8306 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8307 | .doit = nl80211_get_power_save, |
| 8308 | .policy = nl80211_policy, |
| 8309 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8310 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8311 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8312 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8313 | { |
| 8314 | .cmd = NL80211_CMD_SET_CQM, |
| 8315 | .doit = nl80211_set_cqm, |
| 8316 | .policy = nl80211_policy, |
| 8317 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8318 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8319 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8320 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8321 | { |
| 8322 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8323 | .doit = nl80211_set_channel, |
| 8324 | .policy = nl80211_policy, |
| 8325 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8326 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8327 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8328 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8329 | { |
| 8330 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8331 | .doit = nl80211_set_wds_peer, |
| 8332 | .policy = nl80211_policy, |
| 8333 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8334 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8335 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8336 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8337 | { |
| 8338 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8339 | .doit = nl80211_join_mesh, |
| 8340 | .policy = nl80211_policy, |
| 8341 | .flags = GENL_ADMIN_PERM, |
| 8342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8343 | NL80211_FLAG_NEED_RTNL, |
| 8344 | }, |
| 8345 | { |
| 8346 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8347 | .doit = nl80211_leave_mesh, |
| 8348 | .policy = nl80211_policy, |
| 8349 | .flags = GENL_ADMIN_PERM, |
| 8350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8351 | NL80211_FLAG_NEED_RTNL, |
| 8352 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8353 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8354 | { |
| 8355 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8356 | .doit = nl80211_get_wowlan, |
| 8357 | .policy = nl80211_policy, |
| 8358 | /* can be retrieved by unprivileged users */ |
| 8359 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8360 | NL80211_FLAG_NEED_RTNL, |
| 8361 | }, |
| 8362 | { |
| 8363 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8364 | .doit = nl80211_set_wowlan, |
| 8365 | .policy = nl80211_policy, |
| 8366 | .flags = GENL_ADMIN_PERM, |
| 8367 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8368 | NL80211_FLAG_NEED_RTNL, |
| 8369 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8370 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8371 | { |
| 8372 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8373 | .doit = nl80211_set_rekey_data, |
| 8374 | .policy = nl80211_policy, |
| 8375 | .flags = GENL_ADMIN_PERM, |
| 8376 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8377 | NL80211_FLAG_NEED_RTNL, |
| 8378 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8379 | { |
| 8380 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8381 | .doit = nl80211_tdls_mgmt, |
| 8382 | .policy = nl80211_policy, |
| 8383 | .flags = GENL_ADMIN_PERM, |
| 8384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8385 | NL80211_FLAG_NEED_RTNL, |
| 8386 | }, |
| 8387 | { |
| 8388 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8389 | .doit = nl80211_tdls_oper, |
| 8390 | .policy = nl80211_policy, |
| 8391 | .flags = GENL_ADMIN_PERM, |
| 8392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8393 | NL80211_FLAG_NEED_RTNL, |
| 8394 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8395 | { |
| 8396 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8397 | .doit = nl80211_register_unexpected_frame, |
| 8398 | .policy = nl80211_policy, |
| 8399 | .flags = GENL_ADMIN_PERM, |
| 8400 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8401 | NL80211_FLAG_NEED_RTNL, |
| 8402 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8403 | { |
| 8404 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8405 | .doit = nl80211_probe_client, |
| 8406 | .policy = nl80211_policy, |
| 8407 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8409 | NL80211_FLAG_NEED_RTNL, |
| 8410 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8411 | { |
| 8412 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8413 | .doit = nl80211_register_beacons, |
| 8414 | .policy = nl80211_policy, |
| 8415 | .flags = GENL_ADMIN_PERM, |
| 8416 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8417 | NL80211_FLAG_NEED_RTNL, |
| 8418 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8419 | { |
| 8420 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8421 | .doit = nl80211_set_noack_map, |
| 8422 | .policy = nl80211_policy, |
| 8423 | .flags = GENL_ADMIN_PERM, |
| 8424 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8425 | NL80211_FLAG_NEED_RTNL, |
| 8426 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8427 | { |
| 8428 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8429 | .doit = nl80211_start_p2p_device, |
| 8430 | .policy = nl80211_policy, |
| 8431 | .flags = GENL_ADMIN_PERM, |
| 8432 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8433 | NL80211_FLAG_NEED_RTNL, |
| 8434 | }, |
| 8435 | { |
| 8436 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8437 | .doit = nl80211_stop_p2p_device, |
| 8438 | .policy = nl80211_policy, |
| 8439 | .flags = GENL_ADMIN_PERM, |
| 8440 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8441 | NL80211_FLAG_NEED_RTNL, |
| 8442 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8443 | { |
| 8444 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8445 | .doit = nl80211_set_mcast_rate, |
| 8446 | .policy = nl80211_policy, |
| 8447 | .flags = GENL_ADMIN_PERM, |
| 8448 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8449 | NL80211_FLAG_NEED_RTNL, |
| 8450 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8451 | { |
| 8452 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8453 | .doit = nl80211_set_mac_acl, |
| 8454 | .policy = nl80211_policy, |
| 8455 | .flags = GENL_ADMIN_PERM, |
| 8456 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8457 | NL80211_FLAG_NEED_RTNL, |
| 8458 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8459 | { |
| 8460 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8461 | .doit = nl80211_start_radar_detection, |
| 8462 | .policy = nl80211_policy, |
| 8463 | .flags = GENL_ADMIN_PERM, |
| 8464 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8465 | NL80211_FLAG_NEED_RTNL, |
| 8466 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8467 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8468 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8469 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8470 | .name = "mlme", |
| 8471 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8472 | |
| 8473 | /* multicast groups */ |
| 8474 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8475 | .name = "config", |
| 8476 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8477 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8478 | .name = "scan", |
| 8479 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8480 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8481 | .name = "regulatory", |
| 8482 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8483 | |
| 8484 | /* notification functions */ |
| 8485 | |
| 8486 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8487 | { |
| 8488 | struct sk_buff *msg; |
| 8489 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8491 | if (!msg) |
| 8492 | return; |
| 8493 | |
| 8494 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8495 | nlmsg_free(msg); |
| 8496 | return; |
| 8497 | } |
| 8498 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8499 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8500 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8501 | } |
| 8502 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8503 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8504 | struct cfg80211_registered_device *rdev) |
| 8505 | { |
| 8506 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8507 | struct nlattr *nest; |
| 8508 | int i; |
| 8509 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8510 | ASSERT_RDEV_LOCK(rdev); |
| 8511 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8512 | if (WARN_ON(!req)) |
| 8513 | return 0; |
| 8514 | |
| 8515 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8516 | if (!nest) |
| 8517 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8518 | for (i = 0; i < req->n_ssids; i++) { |
| 8519 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8520 | goto nla_put_failure; |
| 8521 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8522 | nla_nest_end(msg, nest); |
| 8523 | |
| 8524 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8525 | if (!nest) |
| 8526 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8527 | for (i = 0; i < req->n_channels; i++) { |
| 8528 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8529 | goto nla_put_failure; |
| 8530 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8531 | nla_nest_end(msg, nest); |
| 8532 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8533 | if (req->ie && |
| 8534 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8535 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8536 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8537 | if (req->flags) |
| 8538 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8539 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8540 | return 0; |
| 8541 | nla_put_failure: |
| 8542 | return -ENOBUFS; |
| 8543 | } |
| 8544 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8545 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8546 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8547 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8548 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8549 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8550 | { |
| 8551 | void *hdr; |
| 8552 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8553 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8554 | if (!hdr) |
| 8555 | return -1; |
| 8556 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8557 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8558 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8559 | wdev->netdev->ifindex)) || |
| 8560 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8561 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8562 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8563 | /* ignore errors and send incomplete event anyway */ |
| 8564 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8565 | |
| 8566 | return genlmsg_end(msg, hdr); |
| 8567 | |
| 8568 | nla_put_failure: |
| 8569 | genlmsg_cancel(msg, hdr); |
| 8570 | return -EMSGSIZE; |
| 8571 | } |
| 8572 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8573 | static int |
| 8574 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8575 | struct cfg80211_registered_device *rdev, |
| 8576 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8577 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8578 | { |
| 8579 | void *hdr; |
| 8580 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8581 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8582 | if (!hdr) |
| 8583 | return -1; |
| 8584 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8585 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8586 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8587 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8588 | |
| 8589 | return genlmsg_end(msg, hdr); |
| 8590 | |
| 8591 | nla_put_failure: |
| 8592 | genlmsg_cancel(msg, hdr); |
| 8593 | return -EMSGSIZE; |
| 8594 | } |
| 8595 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8596 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8597 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8598 | { |
| 8599 | struct sk_buff *msg; |
| 8600 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8601 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8602 | if (!msg) |
| 8603 | return; |
| 8604 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8605 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8606 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8607 | nlmsg_free(msg); |
| 8608 | return; |
| 8609 | } |
| 8610 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8611 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8612 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8613 | } |
| 8614 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8615 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8616 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8617 | { |
| 8618 | struct sk_buff *msg; |
| 8619 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8620 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8621 | if (!msg) |
| 8622 | return; |
| 8623 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8624 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8625 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8626 | nlmsg_free(msg); |
| 8627 | return; |
| 8628 | } |
| 8629 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8630 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8631 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8632 | } |
| 8633 | |
| 8634 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8635 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8636 | { |
| 8637 | struct sk_buff *msg; |
| 8638 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8639 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8640 | if (!msg) |
| 8641 | return; |
| 8642 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8643 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8644 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8645 | nlmsg_free(msg); |
| 8646 | return; |
| 8647 | } |
| 8648 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8649 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8650 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8651 | } |
| 8652 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8653 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8654 | struct net_device *netdev) |
| 8655 | { |
| 8656 | struct sk_buff *msg; |
| 8657 | |
| 8658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8659 | if (!msg) |
| 8660 | return; |
| 8661 | |
| 8662 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8663 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8664 | nlmsg_free(msg); |
| 8665 | return; |
| 8666 | } |
| 8667 | |
| 8668 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8669 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8670 | } |
| 8671 | |
| 8672 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8673 | struct net_device *netdev, u32 cmd) |
| 8674 | { |
| 8675 | struct sk_buff *msg; |
| 8676 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8677 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8678 | if (!msg) |
| 8679 | return; |
| 8680 | |
| 8681 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8682 | nlmsg_free(msg); |
| 8683 | return; |
| 8684 | } |
| 8685 | |
| 8686 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8687 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8688 | } |
| 8689 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8690 | /* |
| 8691 | * This can happen on global regulatory changes or device specific settings |
| 8692 | * based on custom world regulatory domains. |
| 8693 | */ |
| 8694 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8695 | { |
| 8696 | struct sk_buff *msg; |
| 8697 | void *hdr; |
| 8698 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8699 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8700 | if (!msg) |
| 8701 | return; |
| 8702 | |
| 8703 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8704 | if (!hdr) { |
| 8705 | nlmsg_free(msg); |
| 8706 | return; |
| 8707 | } |
| 8708 | |
| 8709 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8710 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8711 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8712 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8713 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8714 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8715 | NL80211_REGDOM_TYPE_WORLD)) |
| 8716 | goto nla_put_failure; |
| 8717 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8718 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8719 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8720 | goto nla_put_failure; |
| 8721 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8722 | request->intersect) { |
| 8723 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8724 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8725 | goto nla_put_failure; |
| 8726 | } else { |
| 8727 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8728 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8729 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8730 | request->alpha2)) |
| 8731 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8732 | } |
| 8733 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8734 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8735 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8736 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8737 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8738 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8739 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8740 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8741 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8742 | GFP_ATOMIC); |
| 8743 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8744 | |
| 8745 | return; |
| 8746 | |
| 8747 | nla_put_failure: |
| 8748 | genlmsg_cancel(msg, hdr); |
| 8749 | nlmsg_free(msg); |
| 8750 | } |
| 8751 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8752 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8753 | struct net_device *netdev, |
| 8754 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8755 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8756 | { |
| 8757 | struct sk_buff *msg; |
| 8758 | void *hdr; |
| 8759 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8760 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8761 | if (!msg) |
| 8762 | return; |
| 8763 | |
| 8764 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8765 | if (!hdr) { |
| 8766 | nlmsg_free(msg); |
| 8767 | return; |
| 8768 | } |
| 8769 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8770 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8771 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8772 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8773 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8774 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8775 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8776 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8777 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8778 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8779 | return; |
| 8780 | |
| 8781 | nla_put_failure: |
| 8782 | genlmsg_cancel(msg, hdr); |
| 8783 | nlmsg_free(msg); |
| 8784 | } |
| 8785 | |
| 8786 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8787 | struct net_device *netdev, const u8 *buf, |
| 8788 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8789 | { |
| 8790 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8791 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8792 | } |
| 8793 | |
| 8794 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8795 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8796 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8797 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8798 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8799 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8800 | } |
| 8801 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8802 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8803 | struct net_device *netdev, const u8 *buf, |
| 8804 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8805 | { |
| 8806 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8807 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8808 | } |
| 8809 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8810 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8811 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8812 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8813 | { |
| 8814 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8815 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8816 | } |
| 8817 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8818 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8819 | struct net_device *netdev, const u8 *buf, |
| 8820 | size_t len, gfp_t gfp) |
| 8821 | { |
| 8822 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8823 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8824 | } |
| 8825 | |
| 8826 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8827 | struct net_device *netdev, const u8 *buf, |
| 8828 | size_t len, gfp_t gfp) |
| 8829 | { |
| 8830 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8831 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8832 | } |
| 8833 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8834 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8835 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8836 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8837 | { |
| 8838 | struct sk_buff *msg; |
| 8839 | void *hdr; |
| 8840 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8841 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8842 | if (!msg) |
| 8843 | return; |
| 8844 | |
| 8845 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8846 | if (!hdr) { |
| 8847 | nlmsg_free(msg); |
| 8848 | return; |
| 8849 | } |
| 8850 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8851 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8852 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8853 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8854 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8855 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8856 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8857 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8858 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8859 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8860 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8861 | return; |
| 8862 | |
| 8863 | nla_put_failure: |
| 8864 | genlmsg_cancel(msg, hdr); |
| 8865 | nlmsg_free(msg); |
| 8866 | } |
| 8867 | |
| 8868 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8869 | struct net_device *netdev, const u8 *addr, |
| 8870 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8871 | { |
| 8872 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8873 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8874 | } |
| 8875 | |
| 8876 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8877 | struct net_device *netdev, const u8 *addr, |
| 8878 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8879 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8880 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8881 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8882 | } |
| 8883 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8884 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8885 | struct net_device *netdev, const u8 *bssid, |
| 8886 | const u8 *req_ie, size_t req_ie_len, |
| 8887 | const u8 *resp_ie, size_t resp_ie_len, |
| 8888 | u16 status, gfp_t gfp) |
| 8889 | { |
| 8890 | struct sk_buff *msg; |
| 8891 | void *hdr; |
| 8892 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8893 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8894 | if (!msg) |
| 8895 | return; |
| 8896 | |
| 8897 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8898 | if (!hdr) { |
| 8899 | nlmsg_free(msg); |
| 8900 | return; |
| 8901 | } |
| 8902 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8903 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8904 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8905 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8906 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8907 | (req_ie && |
| 8908 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8909 | (resp_ie && |
| 8910 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8911 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8912 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8913 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8914 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8915 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8916 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8917 | return; |
| 8918 | |
| 8919 | nla_put_failure: |
| 8920 | genlmsg_cancel(msg, hdr); |
| 8921 | nlmsg_free(msg); |
| 8922 | |
| 8923 | } |
| 8924 | |
| 8925 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8926 | struct net_device *netdev, const u8 *bssid, |
| 8927 | const u8 *req_ie, size_t req_ie_len, |
| 8928 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8929 | { |
| 8930 | struct sk_buff *msg; |
| 8931 | void *hdr; |
| 8932 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8933 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8934 | if (!msg) |
| 8935 | return; |
| 8936 | |
| 8937 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8938 | if (!hdr) { |
| 8939 | nlmsg_free(msg); |
| 8940 | return; |
| 8941 | } |
| 8942 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8943 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8944 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8945 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8946 | (req_ie && |
| 8947 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8948 | (resp_ie && |
| 8949 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8950 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8951 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8952 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8953 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8954 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8955 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8956 | return; |
| 8957 | |
| 8958 | nla_put_failure: |
| 8959 | genlmsg_cancel(msg, hdr); |
| 8960 | nlmsg_free(msg); |
| 8961 | |
| 8962 | } |
| 8963 | |
| 8964 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8965 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8966 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8967 | { |
| 8968 | struct sk_buff *msg; |
| 8969 | void *hdr; |
| 8970 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8972 | if (!msg) |
| 8973 | return; |
| 8974 | |
| 8975 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8976 | if (!hdr) { |
| 8977 | nlmsg_free(msg); |
| 8978 | return; |
| 8979 | } |
| 8980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8981 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8982 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8983 | (from_ap && reason && |
| 8984 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8985 | (from_ap && |
| 8986 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8987 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8988 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8989 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8990 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8991 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8992 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8993 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8994 | return; |
| 8995 | |
| 8996 | nla_put_failure: |
| 8997 | genlmsg_cancel(msg, hdr); |
| 8998 | nlmsg_free(msg); |
| 8999 | |
| 9000 | } |
| 9001 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9002 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9003 | struct net_device *netdev, const u8 *bssid, |
| 9004 | gfp_t gfp) |
| 9005 | { |
| 9006 | struct sk_buff *msg; |
| 9007 | void *hdr; |
| 9008 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9010 | if (!msg) |
| 9011 | return; |
| 9012 | |
| 9013 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9014 | if (!hdr) { |
| 9015 | nlmsg_free(msg); |
| 9016 | return; |
| 9017 | } |
| 9018 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9019 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9020 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9021 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9022 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9023 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9024 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9025 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9026 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9027 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9028 | return; |
| 9029 | |
| 9030 | nla_put_failure: |
| 9031 | genlmsg_cancel(msg, hdr); |
| 9032 | nlmsg_free(msg); |
| 9033 | } |
| 9034 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9035 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 9036 | struct net_device *netdev, |
| 9037 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 9038 | gfp_t gfp) |
| 9039 | { |
| 9040 | struct sk_buff *msg; |
| 9041 | void *hdr; |
| 9042 | |
| 9043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9044 | if (!msg) |
| 9045 | return; |
| 9046 | |
| 9047 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9048 | if (!hdr) { |
| 9049 | nlmsg_free(msg); |
| 9050 | return; |
| 9051 | } |
| 9052 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9054 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9055 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 9056 | (ie_len && ie && |
| 9057 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9058 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9059 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9060 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9061 | |
| 9062 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9063 | nl80211_mlme_mcgrp.id, gfp); |
| 9064 | return; |
| 9065 | |
| 9066 | nla_put_failure: |
| 9067 | genlmsg_cancel(msg, hdr); |
| 9068 | nlmsg_free(msg); |
| 9069 | } |
| 9070 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9071 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9072 | struct net_device *netdev, const u8 *addr, |
| 9073 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9074 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9075 | { |
| 9076 | struct sk_buff *msg; |
| 9077 | void *hdr; |
| 9078 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9079 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9080 | if (!msg) |
| 9081 | return; |
| 9082 | |
| 9083 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9084 | if (!hdr) { |
| 9085 | nlmsg_free(msg); |
| 9086 | return; |
| 9087 | } |
| 9088 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9089 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9090 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9091 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9092 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9093 | (key_id != -1 && |
| 9094 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9095 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9096 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9097 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9098 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9099 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9100 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9101 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9102 | return; |
| 9103 | |
| 9104 | nla_put_failure: |
| 9105 | genlmsg_cancel(msg, hdr); |
| 9106 | nlmsg_free(msg); |
| 9107 | } |
| 9108 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9109 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9110 | struct ieee80211_channel *channel_before, |
| 9111 | struct ieee80211_channel *channel_after) |
| 9112 | { |
| 9113 | struct sk_buff *msg; |
| 9114 | void *hdr; |
| 9115 | struct nlattr *nl_freq; |
| 9116 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9118 | if (!msg) |
| 9119 | return; |
| 9120 | |
| 9121 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9122 | if (!hdr) { |
| 9123 | nlmsg_free(msg); |
| 9124 | return; |
| 9125 | } |
| 9126 | |
| 9127 | /* |
| 9128 | * Since we are applying the beacon hint to a wiphy we know its |
| 9129 | * wiphy_idx is valid |
| 9130 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9131 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9132 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9133 | |
| 9134 | /* Before */ |
| 9135 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9136 | if (!nl_freq) |
| 9137 | goto nla_put_failure; |
| 9138 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 9139 | goto nla_put_failure; |
| 9140 | nla_nest_end(msg, nl_freq); |
| 9141 | |
| 9142 | /* After */ |
| 9143 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9144 | if (!nl_freq) |
| 9145 | goto nla_put_failure; |
| 9146 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 9147 | goto nla_put_failure; |
| 9148 | nla_nest_end(msg, nl_freq); |
| 9149 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9150 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9151 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9152 | rcu_read_lock(); |
| 9153 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9154 | GFP_ATOMIC); |
| 9155 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9156 | |
| 9157 | return; |
| 9158 | |
| 9159 | nla_put_failure: |
| 9160 | genlmsg_cancel(msg, hdr); |
| 9161 | nlmsg_free(msg); |
| 9162 | } |
| 9163 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9164 | static void nl80211_send_remain_on_chan_event( |
| 9165 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9166 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9167 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9168 | unsigned int duration, gfp_t gfp) |
| 9169 | { |
| 9170 | struct sk_buff *msg; |
| 9171 | void *hdr; |
| 9172 | |
| 9173 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9174 | if (!msg) |
| 9175 | return; |
| 9176 | |
| 9177 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9178 | if (!hdr) { |
| 9179 | nlmsg_free(msg); |
| 9180 | return; |
| 9181 | } |
| 9182 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9183 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9184 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9185 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9186 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9187 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9188 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9189 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9190 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9191 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9192 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9193 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9194 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9195 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9196 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9197 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9198 | |
| 9199 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9200 | nl80211_mlme_mcgrp.id, gfp); |
| 9201 | return; |
| 9202 | |
| 9203 | nla_put_failure: |
| 9204 | genlmsg_cancel(msg, hdr); |
| 9205 | nlmsg_free(msg); |
| 9206 | } |
| 9207 | |
| 9208 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9209 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9210 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9211 | unsigned int duration, gfp_t gfp) |
| 9212 | { |
| 9213 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9214 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9215 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9216 | } |
| 9217 | |
| 9218 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9219 | struct cfg80211_registered_device *rdev, |
| 9220 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9221 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9222 | { |
| 9223 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9224 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9225 | } |
| 9226 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9227 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 9228 | struct net_device *dev, const u8 *mac_addr, |
| 9229 | struct station_info *sinfo, gfp_t gfp) |
| 9230 | { |
| 9231 | struct sk_buff *msg; |
| 9232 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9234 | if (!msg) |
| 9235 | return; |
| 9236 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9237 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9238 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9239 | nlmsg_free(msg); |
| 9240 | return; |
| 9241 | } |
| 9242 | |
| 9243 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9244 | nl80211_mlme_mcgrp.id, gfp); |
| 9245 | } |
| 9246 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9247 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 9248 | struct net_device *dev, const u8 *mac_addr, |
| 9249 | gfp_t gfp) |
| 9250 | { |
| 9251 | struct sk_buff *msg; |
| 9252 | void *hdr; |
| 9253 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9255 | if (!msg) |
| 9256 | return; |
| 9257 | |
| 9258 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9259 | if (!hdr) { |
| 9260 | nlmsg_free(msg); |
| 9261 | return; |
| 9262 | } |
| 9263 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9264 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9265 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9266 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9267 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9268 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9269 | |
| 9270 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9271 | nl80211_mlme_mcgrp.id, gfp); |
| 9272 | return; |
| 9273 | |
| 9274 | nla_put_failure: |
| 9275 | genlmsg_cancel(msg, hdr); |
| 9276 | nlmsg_free(msg); |
| 9277 | } |
| 9278 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9279 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 9280 | struct net_device *dev, const u8 *mac_addr, |
| 9281 | enum nl80211_connect_failed_reason reason, |
| 9282 | gfp_t gfp) |
| 9283 | { |
| 9284 | struct sk_buff *msg; |
| 9285 | void *hdr; |
| 9286 | |
| 9287 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9288 | if (!msg) |
| 9289 | return; |
| 9290 | |
| 9291 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9292 | if (!hdr) { |
| 9293 | nlmsg_free(msg); |
| 9294 | return; |
| 9295 | } |
| 9296 | |
| 9297 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9298 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9299 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9300 | goto nla_put_failure; |
| 9301 | |
| 9302 | genlmsg_end(msg, hdr); |
| 9303 | |
| 9304 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9305 | nl80211_mlme_mcgrp.id, gfp); |
| 9306 | return; |
| 9307 | |
| 9308 | nla_put_failure: |
| 9309 | genlmsg_cancel(msg, hdr); |
| 9310 | nlmsg_free(msg); |
| 9311 | } |
| 9312 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9313 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9314 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9315 | { |
| 9316 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9317 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9318 | struct sk_buff *msg; |
| 9319 | void *hdr; |
| 9320 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9321 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9322 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9323 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9324 | return false; |
| 9325 | |
| 9326 | msg = nlmsg_new(100, gfp); |
| 9327 | if (!msg) |
| 9328 | return true; |
| 9329 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9330 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9331 | if (!hdr) { |
| 9332 | nlmsg_free(msg); |
| 9333 | return true; |
| 9334 | } |
| 9335 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9337 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9338 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9339 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9340 | |
| 9341 | err = genlmsg_end(msg, hdr); |
| 9342 | if (err < 0) { |
| 9343 | nlmsg_free(msg); |
| 9344 | return true; |
| 9345 | } |
| 9346 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9347 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9348 | return true; |
| 9349 | |
| 9350 | nla_put_failure: |
| 9351 | genlmsg_cancel(msg, hdr); |
| 9352 | nlmsg_free(msg); |
| 9353 | return true; |
| 9354 | } |
| 9355 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9356 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 9357 | { |
| 9358 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9359 | addr, gfp); |
| 9360 | } |
| 9361 | |
| 9362 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 9363 | const u8 *addr, gfp_t gfp) |
| 9364 | { |
| 9365 | return __nl80211_unexpected_frame(dev, |
| 9366 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9367 | addr, gfp); |
| 9368 | } |
| 9369 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9370 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9371 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9372 | int freq, int sig_dbm, |
| 9373 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9374 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9375 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9376 | struct sk_buff *msg; |
| 9377 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9378 | |
| 9379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9380 | if (!msg) |
| 9381 | return -ENOMEM; |
| 9382 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9384 | if (!hdr) { |
| 9385 | nlmsg_free(msg); |
| 9386 | return -ENOMEM; |
| 9387 | } |
| 9388 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9389 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9390 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9391 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9392 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9393 | (sig_dbm && |
| 9394 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9395 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9396 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9397 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9398 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9399 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9400 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9401 | |
| 9402 | nla_put_failure: |
| 9403 | genlmsg_cancel(msg, hdr); |
| 9404 | nlmsg_free(msg); |
| 9405 | return -ENOBUFS; |
| 9406 | } |
| 9407 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9408 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9409 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9410 | const u8 *buf, size_t len, bool ack, |
| 9411 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9412 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9413 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9414 | struct sk_buff *msg; |
| 9415 | void *hdr; |
| 9416 | |
| 9417 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9418 | if (!msg) |
| 9419 | return; |
| 9420 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9421 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9422 | if (!hdr) { |
| 9423 | nlmsg_free(msg); |
| 9424 | return; |
| 9425 | } |
| 9426 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9427 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9428 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9429 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9430 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9431 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9432 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9433 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9434 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9435 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9436 | |
| 9437 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9438 | return; |
| 9439 | |
| 9440 | nla_put_failure: |
| 9441 | genlmsg_cancel(msg, hdr); |
| 9442 | nlmsg_free(msg); |
| 9443 | } |
| 9444 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9445 | void |
| 9446 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9447 | struct net_device *netdev, |
| 9448 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9449 | gfp_t gfp) |
| 9450 | { |
| 9451 | struct sk_buff *msg; |
| 9452 | struct nlattr *pinfoattr; |
| 9453 | void *hdr; |
| 9454 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9455 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9456 | if (!msg) |
| 9457 | return; |
| 9458 | |
| 9459 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9460 | if (!hdr) { |
| 9461 | nlmsg_free(msg); |
| 9462 | return; |
| 9463 | } |
| 9464 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9465 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9466 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9467 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9468 | |
| 9469 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9470 | if (!pinfoattr) |
| 9471 | goto nla_put_failure; |
| 9472 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9473 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9474 | rssi_event)) |
| 9475 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9476 | |
| 9477 | nla_nest_end(msg, pinfoattr); |
| 9478 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9479 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9480 | |
| 9481 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9482 | nl80211_mlme_mcgrp.id, gfp); |
| 9483 | return; |
| 9484 | |
| 9485 | nla_put_failure: |
| 9486 | genlmsg_cancel(msg, hdr); |
| 9487 | nlmsg_free(msg); |
| 9488 | } |
| 9489 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9490 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9491 | struct net_device *netdev, const u8 *bssid, |
| 9492 | const u8 *replay_ctr, gfp_t gfp) |
| 9493 | { |
| 9494 | struct sk_buff *msg; |
| 9495 | struct nlattr *rekey_attr; |
| 9496 | void *hdr; |
| 9497 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9498 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9499 | if (!msg) |
| 9500 | return; |
| 9501 | |
| 9502 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9503 | if (!hdr) { |
| 9504 | nlmsg_free(msg); |
| 9505 | return; |
| 9506 | } |
| 9507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9508 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9509 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9510 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9511 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9512 | |
| 9513 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9514 | if (!rekey_attr) |
| 9515 | goto nla_put_failure; |
| 9516 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9517 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9518 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9519 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9520 | |
| 9521 | nla_nest_end(msg, rekey_attr); |
| 9522 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9523 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9524 | |
| 9525 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9526 | nl80211_mlme_mcgrp.id, gfp); |
| 9527 | return; |
| 9528 | |
| 9529 | nla_put_failure: |
| 9530 | genlmsg_cancel(msg, hdr); |
| 9531 | nlmsg_free(msg); |
| 9532 | } |
| 9533 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9534 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9535 | struct net_device *netdev, int index, |
| 9536 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9537 | { |
| 9538 | struct sk_buff *msg; |
| 9539 | struct nlattr *attr; |
| 9540 | void *hdr; |
| 9541 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9542 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9543 | if (!msg) |
| 9544 | return; |
| 9545 | |
| 9546 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9547 | if (!hdr) { |
| 9548 | nlmsg_free(msg); |
| 9549 | return; |
| 9550 | } |
| 9551 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9552 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9553 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9554 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9555 | |
| 9556 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9557 | if (!attr) |
| 9558 | goto nla_put_failure; |
| 9559 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9560 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9561 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9562 | (preauth && |
| 9563 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9564 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9565 | |
| 9566 | nla_nest_end(msg, attr); |
| 9567 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9568 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9569 | |
| 9570 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9571 | nl80211_mlme_mcgrp.id, gfp); |
| 9572 | return; |
| 9573 | |
| 9574 | nla_put_failure: |
| 9575 | genlmsg_cancel(msg, hdr); |
| 9576 | nlmsg_free(msg); |
| 9577 | } |
| 9578 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9579 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9580 | struct net_device *netdev, |
| 9581 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9582 | { |
| 9583 | struct sk_buff *msg; |
| 9584 | void *hdr; |
| 9585 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9587 | if (!msg) |
| 9588 | return; |
| 9589 | |
| 9590 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9591 | if (!hdr) { |
| 9592 | nlmsg_free(msg); |
| 9593 | return; |
| 9594 | } |
| 9595 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9596 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9597 | goto nla_put_failure; |
| 9598 | |
| 9599 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9600 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9601 | |
| 9602 | genlmsg_end(msg, hdr); |
| 9603 | |
| 9604 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9605 | nl80211_mlme_mcgrp.id, gfp); |
| 9606 | return; |
| 9607 | |
| 9608 | nla_put_failure: |
| 9609 | genlmsg_cancel(msg, hdr); |
| 9610 | nlmsg_free(msg); |
| 9611 | } |
| 9612 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9613 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9614 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9615 | struct net_device *netdev, const u8 *peer, |
| 9616 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9617 | { |
| 9618 | struct sk_buff *msg; |
| 9619 | struct nlattr *pinfoattr; |
| 9620 | void *hdr; |
| 9621 | |
| 9622 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9623 | if (!msg) |
| 9624 | return; |
| 9625 | |
| 9626 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9627 | if (!hdr) { |
| 9628 | nlmsg_free(msg); |
| 9629 | return; |
| 9630 | } |
| 9631 | |
| 9632 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9633 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9634 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9635 | goto nla_put_failure; |
| 9636 | |
| 9637 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9638 | if (!pinfoattr) |
| 9639 | goto nla_put_failure; |
| 9640 | |
| 9641 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9642 | goto nla_put_failure; |
| 9643 | |
| 9644 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9645 | goto nla_put_failure; |
| 9646 | |
| 9647 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9648 | goto nla_put_failure; |
| 9649 | |
| 9650 | nla_nest_end(msg, pinfoattr); |
| 9651 | |
| 9652 | genlmsg_end(msg, hdr); |
| 9653 | |
| 9654 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9655 | nl80211_mlme_mcgrp.id, gfp); |
| 9656 | return; |
| 9657 | |
| 9658 | nla_put_failure: |
| 9659 | genlmsg_cancel(msg, hdr); |
| 9660 | nlmsg_free(msg); |
| 9661 | } |
| 9662 | |
| 9663 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9664 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 9665 | struct cfg80211_chan_def *chandef, |
| 9666 | enum nl80211_radar_event event, |
| 9667 | struct net_device *netdev, gfp_t gfp) |
| 9668 | { |
| 9669 | struct sk_buff *msg; |
| 9670 | void *hdr; |
| 9671 | |
| 9672 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9673 | if (!msg) |
| 9674 | return; |
| 9675 | |
| 9676 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 9677 | if (!hdr) { |
| 9678 | nlmsg_free(msg); |
| 9679 | return; |
| 9680 | } |
| 9681 | |
| 9682 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9683 | goto nla_put_failure; |
| 9684 | |
| 9685 | /* NOP and radar events don't need a netdev parameter */ |
| 9686 | if (netdev) { |
| 9687 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 9688 | |
| 9689 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9690 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9691 | goto nla_put_failure; |
| 9692 | } |
| 9693 | |
| 9694 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 9695 | goto nla_put_failure; |
| 9696 | |
| 9697 | if (nl80211_send_chandef(msg, chandef)) |
| 9698 | goto nla_put_failure; |
| 9699 | |
| 9700 | if (genlmsg_end(msg, hdr) < 0) { |
| 9701 | nlmsg_free(msg); |
| 9702 | return; |
| 9703 | } |
| 9704 | |
| 9705 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9706 | nl80211_mlme_mcgrp.id, gfp); |
| 9707 | return; |
| 9708 | |
| 9709 | nla_put_failure: |
| 9710 | genlmsg_cancel(msg, hdr); |
| 9711 | nlmsg_free(msg); |
| 9712 | } |
| 9713 | |
| 9714 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9715 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9716 | struct net_device *netdev, const u8 *peer, |
| 9717 | u32 num_packets, gfp_t gfp) |
| 9718 | { |
| 9719 | struct sk_buff *msg; |
| 9720 | struct nlattr *pinfoattr; |
| 9721 | void *hdr; |
| 9722 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9724 | if (!msg) |
| 9725 | return; |
| 9726 | |
| 9727 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9728 | if (!hdr) { |
| 9729 | nlmsg_free(msg); |
| 9730 | return; |
| 9731 | } |
| 9732 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9733 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9734 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9735 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9736 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9737 | |
| 9738 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9739 | if (!pinfoattr) |
| 9740 | goto nla_put_failure; |
| 9741 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9742 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9743 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9744 | |
| 9745 | nla_nest_end(msg, pinfoattr); |
| 9746 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9747 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9748 | |
| 9749 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9750 | nl80211_mlme_mcgrp.id, gfp); |
| 9751 | return; |
| 9752 | |
| 9753 | nla_put_failure: |
| 9754 | genlmsg_cancel(msg, hdr); |
| 9755 | nlmsg_free(msg); |
| 9756 | } |
| 9757 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9758 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9759 | u64 cookie, bool acked, gfp_t gfp) |
| 9760 | { |
| 9761 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9762 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9763 | struct sk_buff *msg; |
| 9764 | void *hdr; |
| 9765 | int err; |
| 9766 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9767 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9768 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9770 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9771 | if (!msg) |
| 9772 | return; |
| 9773 | |
| 9774 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9775 | if (!hdr) { |
| 9776 | nlmsg_free(msg); |
| 9777 | return; |
| 9778 | } |
| 9779 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9780 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9781 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9782 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9783 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9784 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9785 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9786 | |
| 9787 | err = genlmsg_end(msg, hdr); |
| 9788 | if (err < 0) { |
| 9789 | nlmsg_free(msg); |
| 9790 | return; |
| 9791 | } |
| 9792 | |
| 9793 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9794 | nl80211_mlme_mcgrp.id, gfp); |
| 9795 | return; |
| 9796 | |
| 9797 | nla_put_failure: |
| 9798 | genlmsg_cancel(msg, hdr); |
| 9799 | nlmsg_free(msg); |
| 9800 | } |
| 9801 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9802 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9803 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9804 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9805 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9806 | { |
| 9807 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9808 | struct sk_buff *msg; |
| 9809 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9810 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9811 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9812 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9813 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9814 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9815 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9816 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9817 | if (!msg) { |
| 9818 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9819 | return; |
| 9820 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9821 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9822 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9823 | if (!hdr) |
| 9824 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9825 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9826 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9827 | (freq && |
| 9828 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9829 | (sig_dbm && |
| 9830 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9831 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9832 | goto nla_put_failure; |
| 9833 | |
| 9834 | genlmsg_end(msg, hdr); |
| 9835 | |
| 9836 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9837 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9838 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9839 | return; |
| 9840 | |
| 9841 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9842 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9843 | if (hdr) |
| 9844 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9845 | nlmsg_free(msg); |
| 9846 | } |
| 9847 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9848 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9849 | #ifdef CONFIG_PM |
| 9850 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9851 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9852 | gfp_t gfp) |
| 9853 | { |
| 9854 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9855 | struct sk_buff *msg; |
| 9856 | void *hdr; |
| 9857 | int err, size = 200; |
| 9858 | |
| 9859 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9860 | |
| 9861 | if (wakeup) |
| 9862 | size += wakeup->packet_present_len; |
| 9863 | |
| 9864 | msg = nlmsg_new(size, gfp); |
| 9865 | if (!msg) |
| 9866 | return; |
| 9867 | |
| 9868 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9869 | if (!hdr) |
| 9870 | goto free_msg; |
| 9871 | |
| 9872 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9873 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9874 | goto free_msg; |
| 9875 | |
| 9876 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9877 | wdev->netdev->ifindex)) |
| 9878 | goto free_msg; |
| 9879 | |
| 9880 | if (wakeup) { |
| 9881 | struct nlattr *reasons; |
| 9882 | |
| 9883 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9884 | |
| 9885 | if (wakeup->disconnect && |
| 9886 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9887 | goto free_msg; |
| 9888 | if (wakeup->magic_pkt && |
| 9889 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9890 | goto free_msg; |
| 9891 | if (wakeup->gtk_rekey_failure && |
| 9892 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9893 | goto free_msg; |
| 9894 | if (wakeup->eap_identity_req && |
| 9895 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9896 | goto free_msg; |
| 9897 | if (wakeup->four_way_handshake && |
| 9898 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9899 | goto free_msg; |
| 9900 | if (wakeup->rfkill_release && |
| 9901 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9902 | goto free_msg; |
| 9903 | |
| 9904 | if (wakeup->pattern_idx >= 0 && |
| 9905 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9906 | wakeup->pattern_idx)) |
| 9907 | goto free_msg; |
| 9908 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9909 | if (wakeup->tcp_match) |
| 9910 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 9911 | |
| 9912 | if (wakeup->tcp_connlost) |
| 9913 | nla_put_flag(msg, |
| 9914 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 9915 | |
| 9916 | if (wakeup->tcp_nomoretokens) |
| 9917 | nla_put_flag(msg, |
| 9918 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 9919 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9920 | if (wakeup->packet) { |
| 9921 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9922 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9923 | |
| 9924 | if (!wakeup->packet_80211) { |
| 9925 | pkt_attr = |
| 9926 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9927 | len_attr = |
| 9928 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9929 | } |
| 9930 | |
| 9931 | if (wakeup->packet_len && |
| 9932 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9933 | goto free_msg; |
| 9934 | |
| 9935 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9936 | wakeup->packet)) |
| 9937 | goto free_msg; |
| 9938 | } |
| 9939 | |
| 9940 | nla_nest_end(msg, reasons); |
| 9941 | } |
| 9942 | |
| 9943 | err = genlmsg_end(msg, hdr); |
| 9944 | if (err < 0) |
| 9945 | goto free_msg; |
| 9946 | |
| 9947 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9948 | nl80211_mlme_mcgrp.id, gfp); |
| 9949 | return; |
| 9950 | |
| 9951 | free_msg: |
| 9952 | nlmsg_free(msg); |
| 9953 | } |
| 9954 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9955 | #endif |
| 9956 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9957 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9958 | enum nl80211_tdls_operation oper, |
| 9959 | u16 reason_code, gfp_t gfp) |
| 9960 | { |
| 9961 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9962 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9963 | struct sk_buff *msg; |
| 9964 | void *hdr; |
| 9965 | int err; |
| 9966 | |
| 9967 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9968 | reason_code); |
| 9969 | |
| 9970 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9971 | if (!msg) |
| 9972 | return; |
| 9973 | |
| 9974 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9975 | if (!hdr) { |
| 9976 | nlmsg_free(msg); |
| 9977 | return; |
| 9978 | } |
| 9979 | |
| 9980 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9981 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9982 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9983 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9984 | (reason_code > 0 && |
| 9985 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9986 | goto nla_put_failure; |
| 9987 | |
| 9988 | err = genlmsg_end(msg, hdr); |
| 9989 | if (err < 0) { |
| 9990 | nlmsg_free(msg); |
| 9991 | return; |
| 9992 | } |
| 9993 | |
| 9994 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9995 | nl80211_mlme_mcgrp.id, gfp); |
| 9996 | return; |
| 9997 | |
| 9998 | nla_put_failure: |
| 9999 | genlmsg_cancel(msg, hdr); |
| 10000 | nlmsg_free(msg); |
| 10001 | } |
| 10002 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10003 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10004 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10005 | unsigned long state, |
| 10006 | void *_notify) |
| 10007 | { |
| 10008 | struct netlink_notify *notify = _notify; |
| 10009 | struct cfg80211_registered_device *rdev; |
| 10010 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10011 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10012 | |
| 10013 | if (state != NETLINK_URELEASE) |
| 10014 | return NOTIFY_DONE; |
| 10015 | |
| 10016 | rcu_read_lock(); |
| 10017 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10018 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10019 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10020 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10021 | |
| 10022 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10023 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10024 | list) { |
| 10025 | if (reg->nlportid == notify->portid) { |
| 10026 | list_del(®->list); |
| 10027 | kfree(reg); |
| 10028 | break; |
| 10029 | } |
| 10030 | } |
| 10031 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10032 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10033 | |
| 10034 | rcu_read_unlock(); |
| 10035 | |
| 10036 | return NOTIFY_DONE; |
| 10037 | } |
| 10038 | |
| 10039 | static struct notifier_block nl80211_netlink_notifier = { |
| 10040 | .notifier_call = nl80211_netlink_notify, |
| 10041 | }; |
| 10042 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10043 | /* initialisation/exit functions */ |
| 10044 | |
| 10045 | int nl80211_init(void) |
| 10046 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10047 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10048 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10049 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10050 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10051 | if (err) |
| 10052 | return err; |
| 10053 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10054 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10055 | if (err) |
| 10056 | goto err_out; |
| 10057 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10058 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10059 | if (err) |
| 10060 | goto err_out; |
| 10061 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10062 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10063 | if (err) |
| 10064 | goto err_out; |
| 10065 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10066 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10067 | if (err) |
| 10068 | goto err_out; |
| 10069 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10070 | #ifdef CONFIG_NL80211_TESTMODE |
| 10071 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10072 | if (err) |
| 10073 | goto err_out; |
| 10074 | #endif |
| 10075 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10076 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10077 | if (err) |
| 10078 | goto err_out; |
| 10079 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10080 | return 0; |
| 10081 | err_out: |
| 10082 | genl_unregister_family(&nl80211_fam); |
| 10083 | return err; |
| 10084 | } |
| 10085 | |
| 10086 | void nl80211_exit(void) |
| 10087 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10088 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10089 | genl_unregister_family(&nl80211_fam); |
| 10090 | } |