Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame^] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 373 | }; |
| 374 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 376 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 377 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 379 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 380 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 381 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 382 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 384 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 385 | }; |
| 386 | |
| 387 | /* policy for the key default flags */ |
| 388 | static const struct nla_policy |
| 389 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 390 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 391 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 392 | }; |
| 393 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 394 | /* policy for WoWLAN attributes */ |
| 395 | static const struct nla_policy |
| 396 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 397 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 398 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 399 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 400 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 401 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 402 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 403 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 404 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 405 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 406 | }; |
| 407 | |
| 408 | static const struct nla_policy |
| 409 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 410 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 411 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 412 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 413 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 414 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 415 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 416 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 417 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 418 | }, |
| 419 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 420 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 421 | }, |
| 422 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 423 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 424 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 425 | }; |
| 426 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 427 | /* policy for GTK rekey offload attributes */ |
| 428 | static const struct nla_policy |
| 429 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 430 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 431 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 432 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 433 | }; |
| 434 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 435 | static const struct nla_policy |
| 436 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 437 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 438 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 439 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 440 | }; |
| 441 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 442 | /* ifidx get helper */ |
| 443 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 444 | { |
| 445 | int res; |
| 446 | |
| 447 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 448 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 449 | nl80211_policy); |
| 450 | if (res) |
| 451 | return res; |
| 452 | |
| 453 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 454 | return -EINVAL; |
| 455 | |
| 456 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 457 | if (!res) |
| 458 | return -EINVAL; |
| 459 | return res; |
| 460 | } |
| 461 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 462 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 463 | struct netlink_callback *cb, |
| 464 | struct cfg80211_registered_device **rdev, |
| 465 | struct net_device **dev) |
| 466 | { |
| 467 | int ifidx = cb->args[0]; |
| 468 | int err; |
| 469 | |
| 470 | if (!ifidx) |
| 471 | ifidx = nl80211_get_ifidx(cb); |
| 472 | if (ifidx < 0) |
| 473 | return ifidx; |
| 474 | |
| 475 | cb->args[0] = ifidx; |
| 476 | |
| 477 | rtnl_lock(); |
| 478 | |
| 479 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 480 | if (!*dev) { |
| 481 | err = -ENODEV; |
| 482 | goto out_rtnl; |
| 483 | } |
| 484 | |
| 485 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 486 | if (IS_ERR(*rdev)) { |
| 487 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 488 | goto out_rtnl; |
| 489 | } |
| 490 | |
| 491 | return 0; |
| 492 | out_rtnl: |
| 493 | rtnl_unlock(); |
| 494 | return err; |
| 495 | } |
| 496 | |
| 497 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 498 | { |
| 499 | cfg80211_unlock_rdev(rdev); |
| 500 | rtnl_unlock(); |
| 501 | } |
| 502 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 503 | /* IE validation */ |
| 504 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 505 | { |
| 506 | const u8 *pos; |
| 507 | int len; |
| 508 | |
| 509 | if (!attr) |
| 510 | return true; |
| 511 | |
| 512 | pos = nla_data(attr); |
| 513 | len = nla_len(attr); |
| 514 | |
| 515 | while (len) { |
| 516 | u8 elemlen; |
| 517 | |
| 518 | if (len < 2) |
| 519 | return false; |
| 520 | len -= 2; |
| 521 | |
| 522 | elemlen = pos[1]; |
| 523 | if (elemlen > len) |
| 524 | return false; |
| 525 | |
| 526 | len -= elemlen; |
| 527 | pos += 2 + elemlen; |
| 528 | } |
| 529 | |
| 530 | return true; |
| 531 | } |
| 532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 533 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 534 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 535 | int flags, u8 cmd) |
| 536 | { |
| 537 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 538 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 541 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 542 | struct ieee80211_channel *chan) |
| 543 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 545 | chan->center_freq)) |
| 546 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 547 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 548 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 549 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 550 | goto nla_put_failure; |
| 551 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 552 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 553 | goto nla_put_failure; |
| 554 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 556 | goto nla_put_failure; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 557 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 558 | u32 time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 559 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 560 | goto nla_put_failure; |
| 561 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 562 | chan->dfs_state)) |
| 563 | goto nla_put_failure; |
| 564 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, time)) |
| 565 | goto nla_put_failure; |
| 566 | } |
Johannes Berg | 50640f1 | 2012-12-12 17:59:39 +0100 | [diff] [blame] | 567 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 569 | goto nla_put_failure; |
| 570 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 572 | goto nla_put_failure; |
| 573 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 574 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 575 | goto nla_put_failure; |
| 576 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 578 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 580 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 581 | DBM_TO_MBM(chan->max_power))) |
| 582 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 583 | |
| 584 | return 0; |
| 585 | |
| 586 | nla_put_failure: |
| 587 | return -ENOBUFS; |
| 588 | } |
| 589 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 590 | /* netlink command implementations */ |
| 591 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 592 | struct key_parse { |
| 593 | struct key_params p; |
| 594 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 595 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 596 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 597 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 601 | { |
| 602 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 603 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 604 | nl80211_key_policy); |
| 605 | if (err) |
| 606 | return err; |
| 607 | |
| 608 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 609 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 610 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 611 | if (k->def) { |
| 612 | k->def_uni = true; |
| 613 | k->def_multi = true; |
| 614 | } |
| 615 | if (k->defmgmt) |
| 616 | k->def_multi = true; |
| 617 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 618 | if (tb[NL80211_KEY_IDX]) |
| 619 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 620 | |
| 621 | if (tb[NL80211_KEY_DATA]) { |
| 622 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 623 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 624 | } |
| 625 | |
| 626 | if (tb[NL80211_KEY_SEQ]) { |
| 627 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 628 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 629 | } |
| 630 | |
| 631 | if (tb[NL80211_KEY_CIPHER]) |
| 632 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 633 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 634 | if (tb[NL80211_KEY_TYPE]) { |
| 635 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 636 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 637 | return -EINVAL; |
| 638 | } |
| 639 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 640 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 641 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 642 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 643 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 644 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 645 | if (err) |
| 646 | return err; |
| 647 | |
| 648 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 649 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 650 | } |
| 651 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 656 | { |
| 657 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 658 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 659 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 660 | } |
| 661 | |
| 662 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 663 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 664 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 665 | } |
| 666 | |
| 667 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 668 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 669 | |
| 670 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 671 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 672 | |
| 673 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 674 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 675 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 676 | if (k->def) { |
| 677 | k->def_uni = true; |
| 678 | k->def_multi = true; |
| 679 | } |
| 680 | if (k->defmgmt) |
| 681 | k->def_multi = true; |
| 682 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 683 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 684 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 685 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 686 | return -EINVAL; |
| 687 | } |
| 688 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 689 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 690 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 691 | int err = nla_parse_nested( |
| 692 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 693 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 694 | nl80211_key_default_policy); |
| 695 | if (err) |
| 696 | return err; |
| 697 | |
| 698 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 699 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 700 | } |
| 701 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 706 | { |
| 707 | int err; |
| 708 | |
| 709 | memset(k, 0, sizeof(*k)); |
| 710 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 711 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 712 | |
| 713 | if (info->attrs[NL80211_ATTR_KEY]) |
| 714 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 715 | else |
| 716 | err = nl80211_parse_key_old(info, k); |
| 717 | |
| 718 | if (err) |
| 719 | return err; |
| 720 | |
| 721 | if (k->def && k->defmgmt) |
| 722 | return -EINVAL; |
| 723 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 724 | if (k->defmgmt) { |
| 725 | if (k->def_uni || !k->def_multi) |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 729 | if (k->idx != -1) { |
| 730 | if (k->defmgmt) { |
| 731 | if (k->idx < 4 || k->idx > 5) |
| 732 | return -EINVAL; |
| 733 | } else if (k->def) { |
| 734 | if (k->idx < 0 || k->idx > 3) |
| 735 | return -EINVAL; |
| 736 | } else { |
| 737 | if (k->idx < 0 || k->idx > 5) |
| 738 | return -EINVAL; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 745 | static struct cfg80211_cached_keys * |
| 746 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 747 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 748 | { |
| 749 | struct key_parse parse; |
| 750 | struct nlattr *key; |
| 751 | struct cfg80211_cached_keys *result; |
| 752 | int rem, err, def = 0; |
| 753 | |
| 754 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 755 | if (!result) |
| 756 | return ERR_PTR(-ENOMEM); |
| 757 | |
| 758 | result->def = -1; |
| 759 | result->defmgmt = -1; |
| 760 | |
| 761 | nla_for_each_nested(key, keys, rem) { |
| 762 | memset(&parse, 0, sizeof(parse)); |
| 763 | parse.idx = -1; |
| 764 | |
| 765 | err = nl80211_parse_key_new(key, &parse); |
| 766 | if (err) |
| 767 | goto error; |
| 768 | err = -EINVAL; |
| 769 | if (!parse.p.key) |
| 770 | goto error; |
| 771 | if (parse.idx < 0 || parse.idx > 4) |
| 772 | goto error; |
| 773 | if (parse.def) { |
| 774 | if (def) |
| 775 | goto error; |
| 776 | def = 1; |
| 777 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 778 | if (!parse.def_uni || !parse.def_multi) |
| 779 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 780 | } else if (parse.defmgmt) |
| 781 | goto error; |
| 782 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 783 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 784 | if (err) |
| 785 | goto error; |
| 786 | result->params[parse.idx].cipher = parse.p.cipher; |
| 787 | result->params[parse.idx].key_len = parse.p.key_len; |
| 788 | result->params[parse.idx].key = result->data[parse.idx]; |
| 789 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 790 | |
| 791 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 792 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 793 | if (no_ht) |
| 794 | *no_ht = true; |
| 795 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | return result; |
| 799 | error: |
| 800 | kfree(result); |
| 801 | return ERR_PTR(err); |
| 802 | } |
| 803 | |
| 804 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 805 | { |
| 806 | ASSERT_WDEV_LOCK(wdev); |
| 807 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 808 | switch (wdev->iftype) { |
| 809 | case NL80211_IFTYPE_AP: |
| 810 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 811 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 812 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | break; |
| 814 | case NL80211_IFTYPE_ADHOC: |
| 815 | if (!wdev->current_bss) |
| 816 | return -ENOLINK; |
| 817 | break; |
| 818 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 819 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 820 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 821 | return -ENOLINK; |
| 822 | break; |
| 823 | default: |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | |
| 827 | return 0; |
| 828 | } |
| 829 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 830 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 831 | { |
| 832 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 833 | int i; |
| 834 | |
| 835 | if (!nl_modes) |
| 836 | goto nla_put_failure; |
| 837 | |
| 838 | i = 0; |
| 839 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 840 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 841 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 842 | ifmodes >>= 1; |
| 843 | i++; |
| 844 | } |
| 845 | |
| 846 | nla_nest_end(msg, nl_modes); |
| 847 | return 0; |
| 848 | |
| 849 | nla_put_failure: |
| 850 | return -ENOBUFS; |
| 851 | } |
| 852 | |
| 853 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 854 | struct sk_buff *msg) |
| 855 | { |
| 856 | struct nlattr *nl_combis; |
| 857 | int i, j; |
| 858 | |
| 859 | nl_combis = nla_nest_start(msg, |
| 860 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 861 | if (!nl_combis) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 865 | const struct ieee80211_iface_combination *c; |
| 866 | struct nlattr *nl_combi, *nl_limits; |
| 867 | |
| 868 | c = &wiphy->iface_combinations[i]; |
| 869 | |
| 870 | nl_combi = nla_nest_start(msg, i + 1); |
| 871 | if (!nl_combi) |
| 872 | goto nla_put_failure; |
| 873 | |
| 874 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 875 | if (!nl_limits) |
| 876 | goto nla_put_failure; |
| 877 | |
| 878 | for (j = 0; j < c->n_limits; j++) { |
| 879 | struct nlattr *nl_limit; |
| 880 | |
| 881 | nl_limit = nla_nest_start(msg, j + 1); |
| 882 | if (!nl_limit) |
| 883 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 884 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 885 | c->limits[j].max)) |
| 886 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 887 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 888 | c->limits[j].types)) |
| 889 | goto nla_put_failure; |
| 890 | nla_nest_end(msg, nl_limit); |
| 891 | } |
| 892 | |
| 893 | nla_nest_end(msg, nl_limits); |
| 894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 895 | if (c->beacon_int_infra_match && |
| 896 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 897 | goto nla_put_failure; |
| 898 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 899 | c->num_different_channels) || |
| 900 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 901 | c->max_interfaces)) |
| 902 | goto nla_put_failure; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 903 | if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 904 | c->radar_detect_widths)) |
| 905 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 906 | |
| 907 | nla_nest_end(msg, nl_combi); |
| 908 | } |
| 909 | |
| 910 | nla_nest_end(msg, nl_combis); |
| 911 | |
| 912 | return 0; |
| 913 | nla_put_failure: |
| 914 | return -ENOBUFS; |
| 915 | } |
| 916 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 917 | #ifdef CONFIG_PM |
| 918 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 919 | struct sk_buff *msg) |
| 920 | { |
| 921 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 922 | struct nlattr *nl_tcp; |
| 923 | |
| 924 | if (!tcp) |
| 925 | return 0; |
| 926 | |
| 927 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 928 | if (!nl_tcp) |
| 929 | return -ENOBUFS; |
| 930 | |
| 931 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 932 | tcp->data_payload_max)) |
| 933 | return -ENOBUFS; |
| 934 | |
| 935 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 936 | tcp->data_payload_max)) |
| 937 | return -ENOBUFS; |
| 938 | |
| 939 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 940 | return -ENOBUFS; |
| 941 | |
| 942 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 943 | sizeof(*tcp->tok), tcp->tok)) |
| 944 | return -ENOBUFS; |
| 945 | |
| 946 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 947 | tcp->data_interval_max)) |
| 948 | return -ENOBUFS; |
| 949 | |
| 950 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 951 | tcp->wake_payload_max)) |
| 952 | return -ENOBUFS; |
| 953 | |
| 954 | nla_nest_end(msg, nl_tcp); |
| 955 | return 0; |
| 956 | } |
| 957 | #endif |
| 958 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 959 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 960 | struct cfg80211_registered_device *dev) |
| 961 | { |
| 962 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 963 | struct nlattr *nl_bands, *nl_band; |
| 964 | struct nlattr *nl_freqs, *nl_freq; |
| 965 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 966 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 967 | enum ieee80211_band band; |
| 968 | struct ieee80211_channel *chan; |
| 969 | struct ieee80211_rate *rate; |
| 970 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 971 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 972 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 973 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 974 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 975 | if (!hdr) |
| 976 | return -1; |
| 977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 979 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 980 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 981 | cfg80211_rdev_list_generation) || |
| 982 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 983 | dev->wiphy.retry_short) || |
| 984 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 985 | dev->wiphy.retry_long) || |
| 986 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 987 | dev->wiphy.frag_threshold) || |
| 988 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 989 | dev->wiphy.rts_threshold) || |
| 990 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 991 | dev->wiphy.coverage_class) || |
| 992 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 993 | dev->wiphy.max_scan_ssids) || |
| 994 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 995 | dev->wiphy.max_sched_scan_ssids) || |
| 996 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 997 | dev->wiphy.max_scan_ie_len) || |
| 998 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 999 | dev->wiphy.max_sched_scan_ie_len) || |
| 1000 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1001 | dev->wiphy.max_match_sets)) |
| 1002 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1003 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1004 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1005 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1006 | goto nla_put_failure; |
| 1007 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1008 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1009 | goto nla_put_failure; |
| 1010 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1011 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1012 | goto nla_put_failure; |
| 1013 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1014 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1015 | goto nla_put_failure; |
| 1016 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1017 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1018 | goto nla_put_failure; |
| 1019 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1020 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 1021 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1022 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1023 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1024 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1025 | dev->wiphy.cipher_suites)) |
| 1026 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1027 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1028 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1029 | dev->wiphy.max_num_pmkids)) |
| 1030 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 1031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1032 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1033 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1034 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 1035 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1036 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1037 | dev->wiphy.available_antennas_tx) || |
| 1038 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1039 | dev->wiphy.available_antennas_rx)) |
| 1040 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1041 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1042 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1043 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1044 | dev->wiphy.probe_resp_offload)) |
| 1045 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 1046 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1047 | if ((dev->wiphy.available_antennas_tx || |
| 1048 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1049 | u32 tx_ant = 0, rx_ant = 0; |
| 1050 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1051 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1052 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1054 | tx_ant) || |
| 1055 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1056 | rx_ant)) |
| 1057 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1061 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1062 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1063 | goto nla_put_failure; |
| 1064 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1065 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1066 | if (!nl_bands) |
| 1067 | goto nla_put_failure; |
| 1068 | |
| 1069 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1070 | if (!dev->wiphy.bands[band]) |
| 1071 | continue; |
| 1072 | |
| 1073 | nl_band = nla_nest_start(msg, band); |
| 1074 | if (!nl_band) |
| 1075 | goto nla_put_failure; |
| 1076 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1077 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1078 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 1079 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1080 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 1081 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 1082 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1083 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 1084 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1085 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 1086 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1087 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 1088 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1089 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1090 | /* add VHT info */ |
| 1091 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1092 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1093 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1094 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1095 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1096 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1097 | goto nla_put_failure; |
| 1098 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1099 | /* add frequencies */ |
| 1100 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1101 | if (!nl_freqs) |
| 1102 | goto nla_put_failure; |
| 1103 | |
| 1104 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1105 | nl_freq = nla_nest_start(msg, i); |
| 1106 | if (!nl_freq) |
| 1107 | goto nla_put_failure; |
| 1108 | |
| 1109 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1110 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1111 | if (nl80211_msg_put_channel(msg, chan)) |
| 1112 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1113 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1114 | nla_nest_end(msg, nl_freq); |
| 1115 | } |
| 1116 | |
| 1117 | nla_nest_end(msg, nl_freqs); |
| 1118 | |
| 1119 | /* add bitrates */ |
| 1120 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1121 | if (!nl_rates) |
| 1122 | goto nla_put_failure; |
| 1123 | |
| 1124 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1125 | nl_rate = nla_nest_start(msg, i); |
| 1126 | if (!nl_rate) |
| 1127 | goto nla_put_failure; |
| 1128 | |
| 1129 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1130 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1131 | rate->bitrate)) |
| 1132 | goto nla_put_failure; |
| 1133 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1134 | nla_put_flag(msg, |
| 1135 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1136 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1137 | |
| 1138 | nla_nest_end(msg, nl_rate); |
| 1139 | } |
| 1140 | |
| 1141 | nla_nest_end(msg, nl_rates); |
| 1142 | |
| 1143 | nla_nest_end(msg, nl_band); |
| 1144 | } |
| 1145 | nla_nest_end(msg, nl_bands); |
| 1146 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1147 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1148 | if (!nl_cmds) |
| 1149 | goto nla_put_failure; |
| 1150 | |
| 1151 | i = 0; |
| 1152 | #define CMD(op, n) \ |
| 1153 | do { \ |
| 1154 | if (dev->ops->op) { \ |
| 1155 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1156 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1157 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1158 | } \ |
| 1159 | } while (0) |
| 1160 | |
| 1161 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1162 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1163 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1164 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1165 | CMD(add_station, NEW_STATION); |
| 1166 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1167 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1168 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1169 | CMD(auth, AUTHENTICATE); |
| 1170 | CMD(assoc, ASSOCIATE); |
| 1171 | CMD(deauth, DEAUTHENTICATE); |
| 1172 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1173 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1174 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1175 | CMD(set_pmksa, SET_PMKSA); |
| 1176 | CMD(del_pmksa, DEL_PMKSA); |
| 1177 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1178 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1179 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1180 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1181 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1182 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1183 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1184 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1185 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1186 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1187 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1188 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1189 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1190 | i++; |
| 1191 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1192 | goto nla_put_failure; |
| 1193 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1194 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1195 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1196 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1197 | CMD(tdls_oper, TDLS_OPER); |
| 1198 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1199 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1200 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1201 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1202 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1203 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1204 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1205 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1206 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1207 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1208 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1209 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1210 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1211 | #ifdef CONFIG_NL80211_TESTMODE |
| 1212 | CMD(testmode_cmd, TESTMODE); |
| 1213 | #endif |
| 1214 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1215 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1216 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1217 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1218 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1219 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1220 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1223 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1224 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1225 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1226 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1229 | nla_nest_end(msg, nl_cmds); |
| 1230 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1231 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1232 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1233 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1234 | dev->wiphy.max_remain_on_channel_duration)) |
| 1235 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1236 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1237 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1238 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1239 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1240 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1241 | if (mgmt_stypes) { |
| 1242 | u16 stypes; |
| 1243 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1244 | enum nl80211_iftype ift; |
| 1245 | |
| 1246 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1247 | if (!nl_ifs) |
| 1248 | goto nla_put_failure; |
| 1249 | |
| 1250 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1251 | nl_ftypes = nla_nest_start(msg, ift); |
| 1252 | if (!nl_ftypes) |
| 1253 | goto nla_put_failure; |
| 1254 | i = 0; |
| 1255 | stypes = mgmt_stypes[ift].tx; |
| 1256 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1257 | if ((stypes & 1) && |
| 1258 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1259 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1260 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1261 | stypes >>= 1; |
| 1262 | i++; |
| 1263 | } |
| 1264 | nla_nest_end(msg, nl_ftypes); |
| 1265 | } |
| 1266 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1267 | nla_nest_end(msg, nl_ifs); |
| 1268 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1269 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1270 | if (!nl_ifs) |
| 1271 | goto nla_put_failure; |
| 1272 | |
| 1273 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1274 | nl_ftypes = nla_nest_start(msg, ift); |
| 1275 | if (!nl_ftypes) |
| 1276 | goto nla_put_failure; |
| 1277 | i = 0; |
| 1278 | stypes = mgmt_stypes[ift].rx; |
| 1279 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1280 | if ((stypes & 1) && |
| 1281 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1282 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1283 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1284 | stypes >>= 1; |
| 1285 | i++; |
| 1286 | } |
| 1287 | nla_nest_end(msg, nl_ftypes); |
| 1288 | } |
| 1289 | nla_nest_end(msg, nl_ifs); |
| 1290 | } |
| 1291 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1292 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1293 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1294 | struct nlattr *nl_wowlan; |
| 1295 | |
| 1296 | nl_wowlan = nla_nest_start(msg, |
| 1297 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1298 | if (!nl_wowlan) |
| 1299 | goto nla_put_failure; |
| 1300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1301 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1303 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1305 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1307 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1308 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1309 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1310 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1311 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1312 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1313 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1314 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1315 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1316 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1317 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1318 | if (dev->wiphy.wowlan.n_patterns) { |
| 1319 | struct nl80211_wowlan_pattern_support pat = { |
| 1320 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1321 | .min_pattern_len = |
| 1322 | dev->wiphy.wowlan.pattern_min_len, |
| 1323 | .max_pattern_len = |
| 1324 | dev->wiphy.wowlan.pattern_max_len, |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 1325 | .max_pkt_offset = |
| 1326 | dev->wiphy.wowlan.max_pkt_offset, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1327 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1328 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1329 | sizeof(pat), &pat)) |
| 1330 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 1333 | if (nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1334 | goto nla_put_failure; |
| 1335 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1336 | nla_nest_end(msg, nl_wowlan); |
| 1337 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1338 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1339 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1340 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1341 | dev->wiphy.software_iftypes)) |
| 1342 | goto nla_put_failure; |
| 1343 | |
| 1344 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1345 | goto nla_put_failure; |
| 1346 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1347 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1348 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1349 | dev->wiphy.ap_sme_capa)) |
| 1350 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1351 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1352 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1353 | dev->wiphy.features)) |
| 1354 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1355 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1356 | if (dev->wiphy.ht_capa_mod_mask && |
| 1357 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1358 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1359 | dev->wiphy.ht_capa_mod_mask)) |
| 1360 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1361 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 1362 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1363 | dev->wiphy.max_acl_mac_addrs && |
| 1364 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1365 | dev->wiphy.max_acl_mac_addrs)) |
| 1366 | goto nla_put_failure; |
| 1367 | |
Johannes Berg | a50df0c | 2013-02-11 14:20:05 +0100 | [diff] [blame] | 1368 | if (dev->wiphy.extended_capabilities && |
| 1369 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1370 | dev->wiphy.extended_capabilities_len, |
| 1371 | dev->wiphy.extended_capabilities) || |
| 1372 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1373 | dev->wiphy.extended_capabilities_len, |
| 1374 | dev->wiphy.extended_capabilities_mask))) |
| 1375 | goto nla_put_failure; |
| 1376 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1377 | return genlmsg_end(msg, hdr); |
| 1378 | |
| 1379 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1380 | genlmsg_cancel(msg, hdr); |
| 1381 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1385 | { |
| 1386 | int idx = 0; |
| 1387 | int start = cb->args[0]; |
| 1388 | struct cfg80211_registered_device *dev; |
| 1389 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1390 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1391 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1392 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1393 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1394 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1395 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1396 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1397 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1398 | dev) < 0) { |
| 1399 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1400 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1401 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1402 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1403 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1404 | |
| 1405 | cb->args[0] = idx; |
| 1406 | |
| 1407 | return skb->len; |
| 1408 | } |
| 1409 | |
| 1410 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1411 | { |
| 1412 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1413 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1414 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1415 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1416 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1417 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1418 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1419 | if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1420 | nlmsg_free(msg); |
| 1421 | return -ENOBUFS; |
| 1422 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1423 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1424 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1425 | } |
| 1426 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1427 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1428 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1429 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1430 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1431 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1432 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1433 | }; |
| 1434 | |
| 1435 | static int parse_txq_params(struct nlattr *tb[], |
| 1436 | struct ieee80211_txq_params *txq_params) |
| 1437 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1438 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1439 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1440 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1441 | return -EINVAL; |
| 1442 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1443 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1444 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1445 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1446 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1447 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1448 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1449 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1450 | return -EINVAL; |
| 1451 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1452 | return 0; |
| 1453 | } |
| 1454 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1455 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1456 | { |
| 1457 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1458 | * You can only set the channel explicitly for WDS interfaces, |
| 1459 | * all others have their channel managed via their respective |
| 1460 | * "establish a connection" command (connect, join, ...) |
| 1461 | * |
| 1462 | * For AP/GO and mesh mode, the channel can be set with the |
| 1463 | * channel userspace API, but is only stored and passed to the |
| 1464 | * low-level driver when the AP starts or the mesh is joined. |
| 1465 | * This is for backward compatibility, userspace can also give |
| 1466 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1467 | * |
| 1468 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1469 | * whatever else is going on, so they have their own special |
| 1470 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1471 | */ |
| 1472 | return !wdev || |
| 1473 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1474 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1475 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1476 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1479 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1480 | struct genl_info *info, |
| 1481 | struct cfg80211_chan_def *chandef) |
| 1482 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1483 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1484 | |
| 1485 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1486 | return -EINVAL; |
| 1487 | |
| 1488 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1489 | |
| 1490 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1491 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1492 | chandef->center_freq1 = control_freq; |
| 1493 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1494 | |
| 1495 | /* Primary channel not allowed */ |
| 1496 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1497 | return -EINVAL; |
| 1498 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1499 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1500 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1501 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1502 | chantype = nla_get_u32( |
| 1503 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1504 | |
| 1505 | switch (chantype) { |
| 1506 | case NL80211_CHAN_NO_HT: |
| 1507 | case NL80211_CHAN_HT20: |
| 1508 | case NL80211_CHAN_HT40PLUS: |
| 1509 | case NL80211_CHAN_HT40MINUS: |
| 1510 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1511 | chantype); |
| 1512 | break; |
| 1513 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1514 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1515 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1516 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1517 | chandef->width = |
| 1518 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1519 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1520 | chandef->center_freq1 = |
| 1521 | nla_get_u32( |
| 1522 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1523 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1524 | chandef->center_freq2 = |
| 1525 | nla_get_u32( |
| 1526 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1527 | } |
| 1528 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1529 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1530 | return -EINVAL; |
| 1531 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1532 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1533 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1534 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1535 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1536 | return 0; |
| 1537 | } |
| 1538 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1539 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1540 | struct wireless_dev *wdev, |
| 1541 | struct genl_info *info) |
| 1542 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1543 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1544 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1545 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1546 | |
| 1547 | if (wdev) |
| 1548 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1549 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1550 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1551 | return -EOPNOTSUPP; |
| 1552 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1553 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1554 | if (result) |
| 1555 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1556 | |
| 1557 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1558 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1559 | case NL80211_IFTYPE_AP: |
| 1560 | case NL80211_IFTYPE_P2P_GO: |
| 1561 | if (wdev->beacon_interval) { |
| 1562 | result = -EBUSY; |
| 1563 | break; |
| 1564 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1565 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1566 | result = -EINVAL; |
| 1567 | break; |
| 1568 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1569 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1570 | result = 0; |
| 1571 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1572 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1573 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1574 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1575 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1576 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1577 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1578 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1579 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1580 | } |
| 1581 | mutex_unlock(&rdev->devlist_mtx); |
| 1582 | |
| 1583 | return result; |
| 1584 | } |
| 1585 | |
| 1586 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1587 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1589 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1590 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1591 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1592 | } |
| 1593 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1594 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1595 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1597 | struct net_device *dev = info->user_ptr[1]; |
| 1598 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1599 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1600 | |
| 1601 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1602 | return -EINVAL; |
| 1603 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1604 | if (netif_running(dev)) |
| 1605 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1606 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1607 | if (!rdev->ops->set_wds_peer) |
| 1608 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1609 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1610 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1611 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1612 | |
| 1613 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1614 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1619 | { |
| 1620 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1621 | struct net_device *netdev = NULL; |
| 1622 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1623 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1624 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1625 | u32 changed; |
| 1626 | u8 retry_short = 0, retry_long = 0; |
| 1627 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1628 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1629 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1630 | /* |
| 1631 | * Try to find the wiphy and netdev. Normally this |
| 1632 | * function shouldn't need the netdev, but this is |
| 1633 | * done for backward compatibility -- previously |
| 1634 | * setting the channel was done per wiphy, but now |
| 1635 | * it is per netdev. Previous userland like hostapd |
| 1636 | * also passed a netdev to set_wiphy, so that it is |
| 1637 | * possible to let that go to the right netdev! |
| 1638 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1639 | mutex_lock(&cfg80211_mutex); |
| 1640 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1641 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1642 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1643 | |
| 1644 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1645 | if (netdev && netdev->ieee80211_ptr) { |
| 1646 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1647 | mutex_lock(&rdev->mtx); |
| 1648 | } else |
| 1649 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1652 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1653 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1654 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1655 | if (IS_ERR(rdev)) { |
| 1656 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1657 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1658 | } |
| 1659 | wdev = NULL; |
| 1660 | netdev = NULL; |
| 1661 | result = 0; |
| 1662 | |
| 1663 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1664 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1665 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1666 | |
| 1667 | /* |
| 1668 | * end workaround code, by now the rdev is available |
| 1669 | * and locked, and wdev may or may not be NULL. |
| 1670 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1671 | |
| 1672 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1673 | result = cfg80211_dev_rename( |
| 1674 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1675 | |
| 1676 | mutex_unlock(&cfg80211_mutex); |
| 1677 | |
| 1678 | if (result) |
| 1679 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1680 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1681 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1682 | struct ieee80211_txq_params txq_params; |
| 1683 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1684 | |
| 1685 | if (!rdev->ops->set_txq_params) { |
| 1686 | result = -EOPNOTSUPP; |
| 1687 | goto bad_res; |
| 1688 | } |
| 1689 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1690 | if (!netdev) { |
| 1691 | result = -EINVAL; |
| 1692 | goto bad_res; |
| 1693 | } |
| 1694 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1695 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1696 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1697 | result = -EINVAL; |
| 1698 | goto bad_res; |
| 1699 | } |
| 1700 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1701 | if (!netif_running(netdev)) { |
| 1702 | result = -ENETDOWN; |
| 1703 | goto bad_res; |
| 1704 | } |
| 1705 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1706 | nla_for_each_nested(nl_txq_params, |
| 1707 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1708 | rem_txq_params) { |
| 1709 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1710 | nla_data(nl_txq_params), |
| 1711 | nla_len(nl_txq_params), |
| 1712 | txq_params_policy); |
| 1713 | result = parse_txq_params(tb, &txq_params); |
| 1714 | if (result) |
| 1715 | goto bad_res; |
| 1716 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1717 | result = rdev_set_txq_params(rdev, netdev, |
| 1718 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1719 | if (result) |
| 1720 | goto bad_res; |
| 1721 | } |
| 1722 | } |
| 1723 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1724 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1725 | result = __nl80211_set_channel(rdev, |
| 1726 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1727 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1728 | if (result) |
| 1729 | goto bad_res; |
| 1730 | } |
| 1731 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1732 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1733 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1734 | enum nl80211_tx_power_setting type; |
| 1735 | int idx, mbm = 0; |
| 1736 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1737 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1738 | txp_wdev = NULL; |
| 1739 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1740 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1741 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1742 | goto bad_res; |
| 1743 | } |
| 1744 | |
| 1745 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1746 | type = nla_get_u32(info->attrs[idx]); |
| 1747 | |
| 1748 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1749 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1750 | result = -EINVAL; |
| 1751 | goto bad_res; |
| 1752 | } |
| 1753 | |
| 1754 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1755 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1756 | mbm = nla_get_u32(info->attrs[idx]); |
| 1757 | } |
| 1758 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1759 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1760 | if (result) |
| 1761 | goto bad_res; |
| 1762 | } |
| 1763 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1764 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1765 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1766 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1767 | if ((!rdev->wiphy.available_antennas_tx && |
| 1768 | !rdev->wiphy.available_antennas_rx) || |
| 1769 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1770 | result = -EOPNOTSUPP; |
| 1771 | goto bad_res; |
| 1772 | } |
| 1773 | |
| 1774 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1775 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1776 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1777 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1778 | * available antenna masks, except for the "all" mask */ |
| 1779 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1780 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1781 | result = -EINVAL; |
| 1782 | goto bad_res; |
| 1783 | } |
| 1784 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1785 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1786 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1787 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1788 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1789 | if (result) |
| 1790 | goto bad_res; |
| 1791 | } |
| 1792 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1793 | changed = 0; |
| 1794 | |
| 1795 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1796 | retry_short = nla_get_u8( |
| 1797 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1798 | if (retry_short == 0) { |
| 1799 | result = -EINVAL; |
| 1800 | goto bad_res; |
| 1801 | } |
| 1802 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1803 | } |
| 1804 | |
| 1805 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1806 | retry_long = nla_get_u8( |
| 1807 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1808 | if (retry_long == 0) { |
| 1809 | result = -EINVAL; |
| 1810 | goto bad_res; |
| 1811 | } |
| 1812 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1813 | } |
| 1814 | |
| 1815 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1816 | frag_threshold = nla_get_u32( |
| 1817 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1818 | if (frag_threshold < 256) { |
| 1819 | result = -EINVAL; |
| 1820 | goto bad_res; |
| 1821 | } |
| 1822 | if (frag_threshold != (u32) -1) { |
| 1823 | /* |
| 1824 | * Fragments (apart from the last one) are required to |
| 1825 | * have even length. Make the fragmentation code |
| 1826 | * simpler by stripping LSB should someone try to use |
| 1827 | * odd threshold value. |
| 1828 | */ |
| 1829 | frag_threshold &= ~0x1; |
| 1830 | } |
| 1831 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1832 | } |
| 1833 | |
| 1834 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1835 | rts_threshold = nla_get_u32( |
| 1836 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1837 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1838 | } |
| 1839 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1840 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1841 | coverage_class = nla_get_u8( |
| 1842 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1843 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1844 | } |
| 1845 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1846 | if (changed) { |
| 1847 | u8 old_retry_short, old_retry_long; |
| 1848 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1849 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1850 | |
| 1851 | if (!rdev->ops->set_wiphy_params) { |
| 1852 | result = -EOPNOTSUPP; |
| 1853 | goto bad_res; |
| 1854 | } |
| 1855 | |
| 1856 | old_retry_short = rdev->wiphy.retry_short; |
| 1857 | old_retry_long = rdev->wiphy.retry_long; |
| 1858 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1859 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1860 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1861 | |
| 1862 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1863 | rdev->wiphy.retry_short = retry_short; |
| 1864 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1865 | rdev->wiphy.retry_long = retry_long; |
| 1866 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1867 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1868 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1869 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1870 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1871 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1872 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1873 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1874 | if (result) { |
| 1875 | rdev->wiphy.retry_short = old_retry_short; |
| 1876 | rdev->wiphy.retry_long = old_retry_long; |
| 1877 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1878 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1879 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1880 | } |
| 1881 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1882 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1883 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1884 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1885 | if (netdev) |
| 1886 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1887 | return result; |
| 1888 | } |
| 1889 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1890 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1891 | { |
| 1892 | return (u64)wdev->identifier | |
| 1893 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1894 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1895 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1896 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1897 | struct cfg80211_chan_def *chandef) |
| 1898 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1899 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1900 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1901 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1902 | chandef->chan->center_freq)) |
| 1903 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1904 | switch (chandef->width) { |
| 1905 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1906 | case NL80211_CHAN_WIDTH_20: |
| 1907 | case NL80211_CHAN_WIDTH_40: |
| 1908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1909 | cfg80211_get_chandef_type(chandef))) |
| 1910 | return -ENOBUFS; |
| 1911 | break; |
| 1912 | default: |
| 1913 | break; |
| 1914 | } |
| 1915 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1916 | return -ENOBUFS; |
| 1917 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1918 | return -ENOBUFS; |
| 1919 | if (chandef->center_freq2 && |
| 1920 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1921 | return -ENOBUFS; |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1925 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1926 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1927 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1928 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1929 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1930 | void *hdr; |
| 1931 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1932 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1933 | if (!hdr) |
| 1934 | return -1; |
| 1935 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1936 | if (dev && |
| 1937 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1938 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1939 | goto nla_put_failure; |
| 1940 | |
| 1941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1942 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1943 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1944 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1945 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1946 | rdev->devlist_generation ^ |
| 1947 | (cfg80211_rdev_list_generation << 2))) |
| 1948 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1949 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1950 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1951 | int ret; |
| 1952 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1953 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1954 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1955 | if (ret == 0) { |
| 1956 | if (nl80211_send_chandef(msg, &chandef)) |
| 1957 | goto nla_put_failure; |
| 1958 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1959 | } |
| 1960 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1961 | if (wdev->ssid_len) { |
| 1962 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1963 | goto nla_put_failure; |
| 1964 | } |
| 1965 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1966 | return genlmsg_end(msg, hdr); |
| 1967 | |
| 1968 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1969 | genlmsg_cancel(msg, hdr); |
| 1970 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1974 | { |
| 1975 | int wp_idx = 0; |
| 1976 | int if_idx = 0; |
| 1977 | int wp_start = cb->args[0]; |
| 1978 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1979 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1980 | struct wireless_dev *wdev; |
| 1981 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1982 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1983 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1984 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1985 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1986 | if (wp_idx < wp_start) { |
| 1987 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1988 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1989 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1990 | if_idx = 0; |
| 1991 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1992 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1993 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1994 | if (if_idx < if_start) { |
| 1995 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1996 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1997 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1998 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1999 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2000 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2001 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2002 | goto out; |
| 2003 | } |
| 2004 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2005 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2006 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2007 | |
| 2008 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2009 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2010 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2011 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2012 | |
| 2013 | cb->args[0] = wp_idx; |
| 2014 | cb->args[1] = if_idx; |
| 2015 | |
| 2016 | return skb->len; |
| 2017 | } |
| 2018 | |
| 2019 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2020 | { |
| 2021 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2022 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2023 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2024 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2026 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2028 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2029 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2030 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2031 | nlmsg_free(msg); |
| 2032 | return -ENOBUFS; |
| 2033 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2034 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2035 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2038 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2039 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2040 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2041 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2042 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2043 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2044 | }; |
| 2045 | |
| 2046 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2047 | { |
| 2048 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2049 | int flag; |
| 2050 | |
| 2051 | *mntrflags = 0; |
| 2052 | |
| 2053 | if (!nla) |
| 2054 | return -EINVAL; |
| 2055 | |
| 2056 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2057 | nla, mntr_flags_policy)) |
| 2058 | return -EINVAL; |
| 2059 | |
| 2060 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2061 | if (flags[flag]) |
| 2062 | *mntrflags |= (1<<flag); |
| 2063 | |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2067 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2068 | struct net_device *netdev, u8 use_4addr, |
| 2069 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2070 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2071 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2072 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2073 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2074 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2075 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2076 | |
| 2077 | switch (iftype) { |
| 2078 | case NL80211_IFTYPE_AP_VLAN: |
| 2079 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2080 | return 0; |
| 2081 | break; |
| 2082 | case NL80211_IFTYPE_STATION: |
| 2083 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2084 | return 0; |
| 2085 | break; |
| 2086 | default: |
| 2087 | break; |
| 2088 | } |
| 2089 | |
| 2090 | return -EOPNOTSUPP; |
| 2091 | } |
| 2092 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2093 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2094 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2096 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2097 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2098 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2099 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2100 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2101 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2102 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2103 | memset(¶ms, 0, sizeof(params)); |
| 2104 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2105 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2106 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2107 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2108 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2109 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2110 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2111 | if (ntype > NL80211_IFTYPE_MAX) |
| 2112 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2115 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2116 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2118 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2119 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2120 | if (netif_running(dev)) |
| 2121 | return -EBUSY; |
| 2122 | |
| 2123 | wdev_lock(wdev); |
| 2124 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2125 | IEEE80211_MAX_MESH_ID_LEN); |
| 2126 | wdev->mesh_id_up_len = |
| 2127 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2128 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2129 | wdev->mesh_id_up_len); |
| 2130 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2133 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2134 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2135 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2136 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2137 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2139 | } else { |
| 2140 | params.use_4addr = -1; |
| 2141 | } |
| 2142 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2143 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2144 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2145 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2146 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2147 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2148 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2149 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2150 | |
| 2151 | flags = &_flags; |
| 2152 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2153 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2154 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2155 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2156 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2157 | else |
| 2158 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2159 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2160 | if (!err && params.use_4addr != -1) |
| 2161 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2162 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2163 | return err; |
| 2164 | } |
| 2165 | |
| 2166 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2167 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2168 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2169 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2170 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2171 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2172 | int err; |
| 2173 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2174 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2175 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2176 | memset(¶ms, 0, sizeof(params)); |
| 2177 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2178 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2179 | return -EINVAL; |
| 2180 | |
| 2181 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2182 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2183 | if (type > NL80211_IFTYPE_MAX) |
| 2184 | return -EINVAL; |
| 2185 | } |
| 2186 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2187 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2188 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2189 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2190 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2191 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2192 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2193 | ETH_ALEN); |
| 2194 | if (!is_valid_ether_addr(params.macaddr)) |
| 2195 | return -EADDRNOTAVAIL; |
| 2196 | } |
| 2197 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2198 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2199 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2200 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2201 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2202 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2203 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2204 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2205 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2206 | if (!msg) |
| 2207 | return -ENOMEM; |
| 2208 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2209 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2210 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2211 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2212 | wdev = rdev_add_virtual_intf(rdev, |
| 2213 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2214 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2215 | if (IS_ERR(wdev)) { |
| 2216 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2217 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2218 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2219 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2220 | switch (type) { |
| 2221 | case NL80211_IFTYPE_MESH_POINT: |
| 2222 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2223 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2224 | wdev_lock(wdev); |
| 2225 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2226 | IEEE80211_MAX_MESH_ID_LEN); |
| 2227 | wdev->mesh_id_up_len = |
| 2228 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2229 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2230 | wdev->mesh_id_up_len); |
| 2231 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2232 | break; |
| 2233 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2234 | /* |
| 2235 | * P2P Device doesn't have a netdev, so doesn't go |
| 2236 | * through the netdev notifier and must be added here |
| 2237 | */ |
| 2238 | mutex_init(&wdev->mtx); |
| 2239 | INIT_LIST_HEAD(&wdev->event_list); |
| 2240 | spin_lock_init(&wdev->event_lock); |
| 2241 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2242 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2243 | |
| 2244 | mutex_lock(&rdev->devlist_mtx); |
| 2245 | wdev->identifier = ++rdev->wdev_id; |
| 2246 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2247 | rdev->devlist_generation++; |
| 2248 | mutex_unlock(&rdev->devlist_mtx); |
| 2249 | break; |
| 2250 | default: |
| 2251 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2252 | } |
| 2253 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2254 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2255 | rdev, wdev) < 0) { |
| 2256 | nlmsg_free(msg); |
| 2257 | return -ENOBUFS; |
| 2258 | } |
| 2259 | |
| 2260 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2264 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2266 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2267 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2268 | if (!rdev->ops->del_virtual_intf) |
| 2269 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2270 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2271 | /* |
| 2272 | * If we remove a wireless device without a netdev then clear |
| 2273 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2274 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2275 | * since the wdev has been freed, unlike with a netdev where |
| 2276 | * we need the dev_put() for the netdev to really be freed. |
| 2277 | */ |
| 2278 | if (!wdev->netdev) |
| 2279 | info->user_ptr[1] = NULL; |
| 2280 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2281 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2282 | } |
| 2283 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2284 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2285 | { |
| 2286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2287 | struct net_device *dev = info->user_ptr[1]; |
| 2288 | u16 noack_map; |
| 2289 | |
| 2290 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2291 | return -EINVAL; |
| 2292 | |
| 2293 | if (!rdev->ops->set_noack_map) |
| 2294 | return -EOPNOTSUPP; |
| 2295 | |
| 2296 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2297 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2298 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2301 | struct get_key_cookie { |
| 2302 | struct sk_buff *msg; |
| 2303 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2304 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2305 | }; |
| 2306 | |
| 2307 | static void get_key_callback(void *c, struct key_params *params) |
| 2308 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2309 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2310 | struct get_key_cookie *cookie = c; |
| 2311 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2312 | if ((params->key && |
| 2313 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2314 | params->key_len, params->key)) || |
| 2315 | (params->seq && |
| 2316 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2317 | params->seq_len, params->seq)) || |
| 2318 | (params->cipher && |
| 2319 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2320 | params->cipher))) |
| 2321 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2322 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2323 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2324 | if (!key) |
| 2325 | goto nla_put_failure; |
| 2326 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2327 | if ((params->key && |
| 2328 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2329 | params->key_len, params->key)) || |
| 2330 | (params->seq && |
| 2331 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2332 | params->seq_len, params->seq)) || |
| 2333 | (params->cipher && |
| 2334 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2335 | params->cipher))) |
| 2336 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2337 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2338 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2339 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2340 | |
| 2341 | nla_nest_end(cookie->msg, key); |
| 2342 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2343 | return; |
| 2344 | nla_put_failure: |
| 2345 | cookie->error = 1; |
| 2346 | } |
| 2347 | |
| 2348 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2349 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2351 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2352 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2353 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2354 | const u8 *mac_addr = NULL; |
| 2355 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2356 | struct get_key_cookie cookie = { |
| 2357 | .error = 0, |
| 2358 | }; |
| 2359 | void *hdr; |
| 2360 | struct sk_buff *msg; |
| 2361 | |
| 2362 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2363 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2364 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2365 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2366 | return -EINVAL; |
| 2367 | |
| 2368 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2369 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2370 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2371 | pairwise = !!mac_addr; |
| 2372 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2373 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2374 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2375 | return -EINVAL; |
| 2376 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2377 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2378 | return -EINVAL; |
| 2379 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2380 | } |
| 2381 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | if (!rdev->ops->get_key) |
| 2383 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2384 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2386 | if (!msg) |
| 2387 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2388 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2389 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2390 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2391 | if (IS_ERR(hdr)) |
| 2392 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2393 | |
| 2394 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2395 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2396 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2397 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2398 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2399 | goto nla_put_failure; |
| 2400 | if (mac_addr && |
| 2401 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2402 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2403 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2404 | if (pairwise && mac_addr && |
| 2405 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2406 | return -ENOENT; |
| 2407 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2408 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2409 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2410 | |
| 2411 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2412 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2413 | |
| 2414 | if (cookie.error) |
| 2415 | goto nla_put_failure; |
| 2416 | |
| 2417 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2418 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2419 | |
| 2420 | nla_put_failure: |
| 2421 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2422 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2423 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2424 | return err; |
| 2425 | } |
| 2426 | |
| 2427 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2428 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2430 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2431 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2432 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2433 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2434 | err = nl80211_parse_key(info, &key); |
| 2435 | if (err) |
| 2436 | return err; |
| 2437 | |
| 2438 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2439 | return -EINVAL; |
| 2440 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2441 | /* only support setting default key */ |
| 2442 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2443 | return -EINVAL; |
| 2444 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2445 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2446 | |
| 2447 | if (key.def) { |
| 2448 | if (!rdev->ops->set_default_key) { |
| 2449 | err = -EOPNOTSUPP; |
| 2450 | goto out; |
| 2451 | } |
| 2452 | |
| 2453 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2454 | if (err) |
| 2455 | goto out; |
| 2456 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2457 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2458 | key.def_uni, key.def_multi); |
| 2459 | |
| 2460 | if (err) |
| 2461 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2462 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2463 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2464 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2465 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2466 | } else { |
| 2467 | if (key.def_uni || !key.def_multi) { |
| 2468 | err = -EINVAL; |
| 2469 | goto out; |
| 2470 | } |
| 2471 | |
| 2472 | if (!rdev->ops->set_default_mgmt_key) { |
| 2473 | err = -EOPNOTSUPP; |
| 2474 | goto out; |
| 2475 | } |
| 2476 | |
| 2477 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2478 | if (err) |
| 2479 | goto out; |
| 2480 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2481 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2482 | if (err) |
| 2483 | goto out; |
| 2484 | |
| 2485 | #ifdef CONFIG_CFG80211_WEXT |
| 2486 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2487 | #endif |
| 2488 | } |
| 2489 | |
| 2490 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2491 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2492 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2493 | return err; |
| 2494 | } |
| 2495 | |
| 2496 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2497 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2499 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2500 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2501 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2502 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2503 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2504 | err = nl80211_parse_key(info, &key); |
| 2505 | if (err) |
| 2506 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2507 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2508 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2509 | return -EINVAL; |
| 2510 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2511 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2512 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2513 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2514 | if (key.type == -1) { |
| 2515 | if (mac_addr) |
| 2516 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2517 | else |
| 2518 | key.type = NL80211_KEYTYPE_GROUP; |
| 2519 | } |
| 2520 | |
| 2521 | /* for now */ |
| 2522 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2523 | key.type != NL80211_KEYTYPE_GROUP) |
| 2524 | return -EINVAL; |
| 2525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2526 | if (!rdev->ops->add_key) |
| 2527 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2528 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2529 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2530 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2531 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2532 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2533 | |
| 2534 | wdev_lock(dev->ieee80211_ptr); |
| 2535 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2536 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2537 | err = rdev_add_key(rdev, dev, key.idx, |
| 2538 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2539 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2540 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2541 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2542 | return err; |
| 2543 | } |
| 2544 | |
| 2545 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2546 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2548 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2549 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2550 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2551 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2552 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2553 | err = nl80211_parse_key(info, &key); |
| 2554 | if (err) |
| 2555 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2556 | |
| 2557 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2558 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2559 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2560 | if (key.type == -1) { |
| 2561 | if (mac_addr) |
| 2562 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2563 | else |
| 2564 | key.type = NL80211_KEYTYPE_GROUP; |
| 2565 | } |
| 2566 | |
| 2567 | /* for now */ |
| 2568 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2569 | key.type != NL80211_KEYTYPE_GROUP) |
| 2570 | return -EINVAL; |
| 2571 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2572 | if (!rdev->ops->del_key) |
| 2573 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2574 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2575 | wdev_lock(dev->ieee80211_ptr); |
| 2576 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2577 | |
| 2578 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2579 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2580 | err = -ENOENT; |
| 2581 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2582 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2583 | err = rdev_del_key(rdev, dev, key.idx, |
| 2584 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2585 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2586 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2587 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2588 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2589 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2590 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2591 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2592 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2593 | } |
| 2594 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2595 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2596 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2597 | return err; |
| 2598 | } |
| 2599 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2600 | /* This function returns an error or the number of nested attributes */ |
| 2601 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2602 | { |
| 2603 | struct nlattr *attr; |
| 2604 | int n_entries = 0, tmp; |
| 2605 | |
| 2606 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2607 | if (nla_len(attr) != ETH_ALEN) |
| 2608 | return -EINVAL; |
| 2609 | |
| 2610 | n_entries++; |
| 2611 | } |
| 2612 | |
| 2613 | return n_entries; |
| 2614 | } |
| 2615 | |
| 2616 | /* |
| 2617 | * This function parses ACL information and allocates memory for ACL data. |
| 2618 | * On successful return, the calling function is responsible to free the |
| 2619 | * ACL buffer returned by this function. |
| 2620 | */ |
| 2621 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2622 | struct genl_info *info) |
| 2623 | { |
| 2624 | enum nl80211_acl_policy acl_policy; |
| 2625 | struct nlattr *attr; |
| 2626 | struct cfg80211_acl_data *acl; |
| 2627 | int i = 0, n_entries, tmp; |
| 2628 | |
| 2629 | if (!wiphy->max_acl_mac_addrs) |
| 2630 | return ERR_PTR(-EOPNOTSUPP); |
| 2631 | |
| 2632 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2633 | return ERR_PTR(-EINVAL); |
| 2634 | |
| 2635 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2636 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2637 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2638 | return ERR_PTR(-EINVAL); |
| 2639 | |
| 2640 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2641 | return ERR_PTR(-EINVAL); |
| 2642 | |
| 2643 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2644 | if (n_entries < 0) |
| 2645 | return ERR_PTR(n_entries); |
| 2646 | |
| 2647 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2648 | return ERR_PTR(-ENOTSUPP); |
| 2649 | |
| 2650 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2651 | GFP_KERNEL); |
| 2652 | if (!acl) |
| 2653 | return ERR_PTR(-ENOMEM); |
| 2654 | |
| 2655 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2656 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2657 | i++; |
| 2658 | } |
| 2659 | |
| 2660 | acl->n_acl_entries = n_entries; |
| 2661 | acl->acl_policy = acl_policy; |
| 2662 | |
| 2663 | return acl; |
| 2664 | } |
| 2665 | |
| 2666 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2667 | { |
| 2668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2669 | struct net_device *dev = info->user_ptr[1]; |
| 2670 | struct cfg80211_acl_data *acl; |
| 2671 | int err; |
| 2672 | |
| 2673 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2674 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2675 | return -EOPNOTSUPP; |
| 2676 | |
| 2677 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2678 | return -EINVAL; |
| 2679 | |
| 2680 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2681 | if (IS_ERR(acl)) |
| 2682 | return PTR_ERR(acl); |
| 2683 | |
| 2684 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2685 | |
| 2686 | kfree(acl); |
| 2687 | |
| 2688 | return err; |
| 2689 | } |
| 2690 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2691 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2692 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2693 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2694 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2695 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2696 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2697 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2698 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2699 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2700 | return -EINVAL; |
| 2701 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2702 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2703 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2704 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2705 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2706 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2707 | if (!bcn->head_len) |
| 2708 | return -EINVAL; |
| 2709 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2713 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2714 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2715 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2716 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2717 | } |
| 2718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2719 | if (!haveinfo) |
| 2720 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2721 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2722 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2723 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2724 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2728 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2729 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2730 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2731 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2732 | } |
| 2733 | |
| 2734 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2735 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2736 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2737 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2738 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2739 | } |
| 2740 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2741 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2742 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2743 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2744 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2745 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2746 | } |
| 2747 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2748 | return 0; |
| 2749 | } |
| 2750 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2751 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2752 | struct cfg80211_ap_settings *params) |
| 2753 | { |
| 2754 | struct wireless_dev *wdev; |
| 2755 | bool ret = false; |
| 2756 | |
| 2757 | mutex_lock(&rdev->devlist_mtx); |
| 2758 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2759 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2760 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2761 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2762 | continue; |
| 2763 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2764 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2765 | continue; |
| 2766 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2767 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2768 | ret = true; |
| 2769 | break; |
| 2770 | } |
| 2771 | |
| 2772 | mutex_unlock(&rdev->devlist_mtx); |
| 2773 | |
| 2774 | return ret; |
| 2775 | } |
| 2776 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2777 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2778 | enum nl80211_auth_type auth_type, |
| 2779 | enum nl80211_commands cmd) |
| 2780 | { |
| 2781 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2782 | return false; |
| 2783 | |
| 2784 | switch (cmd) { |
| 2785 | case NL80211_CMD_AUTHENTICATE: |
| 2786 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2787 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2788 | return false; |
| 2789 | return true; |
| 2790 | case NL80211_CMD_CONNECT: |
| 2791 | case NL80211_CMD_START_AP: |
| 2792 | /* SAE not supported yet */ |
| 2793 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2794 | return false; |
| 2795 | return true; |
| 2796 | default: |
| 2797 | return false; |
| 2798 | } |
| 2799 | } |
| 2800 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2801 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2802 | { |
| 2803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2804 | struct net_device *dev = info->user_ptr[1]; |
| 2805 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2806 | struct cfg80211_ap_settings params; |
| 2807 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2808 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2809 | |
| 2810 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2811 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2812 | return -EOPNOTSUPP; |
| 2813 | |
| 2814 | if (!rdev->ops->start_ap) |
| 2815 | return -EOPNOTSUPP; |
| 2816 | |
| 2817 | if (wdev->beacon_interval) |
| 2818 | return -EALREADY; |
| 2819 | |
| 2820 | memset(¶ms, 0, sizeof(params)); |
| 2821 | |
| 2822 | /* these are required for START_AP */ |
| 2823 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2824 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2825 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2826 | return -EINVAL; |
| 2827 | |
| 2828 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2829 | if (err) |
| 2830 | return err; |
| 2831 | |
| 2832 | params.beacon_interval = |
| 2833 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2834 | params.dtim_period = |
| 2835 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2836 | |
| 2837 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2838 | if (err) |
| 2839 | return err; |
| 2840 | |
| 2841 | /* |
| 2842 | * In theory, some of these attributes should be required here |
| 2843 | * but since they were not used when the command was originally |
| 2844 | * added, keep them optional for old user space programs to let |
| 2845 | * them continue to work with drivers that do not need the |
| 2846 | * additional information -- drivers must check! |
| 2847 | */ |
| 2848 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2849 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2850 | params.ssid_len = |
| 2851 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2852 | if (params.ssid_len == 0 || |
| 2853 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2854 | return -EINVAL; |
| 2855 | } |
| 2856 | |
| 2857 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2858 | params.hidden_ssid = nla_get_u32( |
| 2859 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2860 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2861 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2862 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2863 | return -EINVAL; |
| 2864 | } |
| 2865 | |
| 2866 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2867 | |
| 2868 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2869 | params.auth_type = nla_get_u32( |
| 2870 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2871 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2872 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2873 | return -EINVAL; |
| 2874 | } else |
| 2875 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2876 | |
| 2877 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2878 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2879 | if (err) |
| 2880 | return err; |
| 2881 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2882 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2883 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2884 | return -EOPNOTSUPP; |
| 2885 | params.inactivity_timeout = nla_get_u16( |
| 2886 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2887 | } |
| 2888 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2889 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2890 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2891 | return -EINVAL; |
| 2892 | params.p2p_ctwindow = |
| 2893 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2894 | if (params.p2p_ctwindow > 127) |
| 2895 | return -EINVAL; |
| 2896 | if (params.p2p_ctwindow != 0 && |
| 2897 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2898 | return -EINVAL; |
| 2899 | } |
| 2900 | |
| 2901 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2902 | u8 tmp; |
| 2903 | |
| 2904 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2905 | return -EINVAL; |
| 2906 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2907 | if (tmp > 1) |
| 2908 | return -EINVAL; |
| 2909 | params.p2p_opp_ps = tmp; |
| 2910 | if (params.p2p_opp_ps != 0 && |
| 2911 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2912 | return -EINVAL; |
| 2913 | } |
| 2914 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2915 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2916 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2917 | if (err) |
| 2918 | return err; |
| 2919 | } else if (wdev->preset_chandef.chan) { |
| 2920 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2921 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2922 | return -EINVAL; |
| 2923 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2924 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2925 | return -EINVAL; |
| 2926 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2927 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 2928 | if (err < 0) |
| 2929 | return err; |
| 2930 | if (err) { |
| 2931 | radar_detect_width = BIT(params.chandef.width); |
| 2932 | params.radar_required = true; |
| 2933 | } |
| 2934 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2935 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2936 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 2937 | params.chandef.chan, |
| 2938 | CHAN_MODE_SHARED, |
| 2939 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2940 | mutex_unlock(&rdev->devlist_mtx); |
| 2941 | |
| 2942 | if (err) |
| 2943 | return err; |
| 2944 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2945 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 2946 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 2947 | if (IS_ERR(params.acl)) |
| 2948 | return PTR_ERR(params.acl); |
| 2949 | } |
| 2950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2951 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2952 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2953 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2954 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2955 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2956 | wdev->ssid_len = params.ssid_len; |
| 2957 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2958 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2959 | |
| 2960 | kfree(params.acl); |
| 2961 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2962 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2963 | } |
| 2964 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2965 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2966 | { |
| 2967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2968 | struct net_device *dev = info->user_ptr[1]; |
| 2969 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2970 | struct cfg80211_beacon_data params; |
| 2971 | int err; |
| 2972 | |
| 2973 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2974 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2975 | return -EOPNOTSUPP; |
| 2976 | |
| 2977 | if (!rdev->ops->change_beacon) |
| 2978 | return -EOPNOTSUPP; |
| 2979 | |
| 2980 | if (!wdev->beacon_interval) |
| 2981 | return -EINVAL; |
| 2982 | |
| 2983 | err = nl80211_parse_beacon(info, ¶ms); |
| 2984 | if (err) |
| 2985 | return err; |
| 2986 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2987 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2991 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2993 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2994 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2995 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2996 | } |
| 2997 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2998 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2999 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3000 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3001 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3002 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3003 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3004 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3005 | }; |
| 3006 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3007 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3008 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3009 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3010 | { |
| 3011 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3012 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3013 | int flag; |
| 3014 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3015 | /* |
| 3016 | * Try parsing the new attribute first so userspace |
| 3017 | * can specify both for older kernels. |
| 3018 | */ |
| 3019 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3020 | if (nla) { |
| 3021 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3022 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3023 | sta_flags = nla_data(nla); |
| 3024 | params->sta_flags_mask = sta_flags->mask; |
| 3025 | params->sta_flags_set = sta_flags->set; |
| 3026 | if ((params->sta_flags_mask | |
| 3027 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3028 | return -EINVAL; |
| 3029 | return 0; |
| 3030 | } |
| 3031 | |
| 3032 | /* if present, parse the old attribute */ |
| 3033 | |
| 3034 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3035 | if (!nla) |
| 3036 | return 0; |
| 3037 | |
| 3038 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3039 | nla, sta_flags_policy)) |
| 3040 | return -EINVAL; |
| 3041 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3042 | /* |
| 3043 | * Only allow certain flags for interface types so that |
| 3044 | * other attributes are silently ignored. Remember that |
| 3045 | * this is backward compatibility code with old userspace |
| 3046 | * and shouldn't be hit in other cases anyway. |
| 3047 | */ |
| 3048 | switch (iftype) { |
| 3049 | case NL80211_IFTYPE_AP: |
| 3050 | case NL80211_IFTYPE_AP_VLAN: |
| 3051 | case NL80211_IFTYPE_P2P_GO: |
| 3052 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3053 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3054 | BIT(NL80211_STA_FLAG_WME) | |
| 3055 | BIT(NL80211_STA_FLAG_MFP); |
| 3056 | break; |
| 3057 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3058 | case NL80211_IFTYPE_STATION: |
| 3059 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3060 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3061 | break; |
| 3062 | case NL80211_IFTYPE_MESH_POINT: |
| 3063 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3064 | BIT(NL80211_STA_FLAG_MFP) | |
| 3065 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3066 | default: |
| 3067 | return -EINVAL; |
| 3068 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3069 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3070 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3071 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3072 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3073 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3074 | /* no longer support new API additions in old API */ |
| 3075 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3076 | return -EINVAL; |
| 3077 | } |
| 3078 | } |
| 3079 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3080 | return 0; |
| 3081 | } |
| 3082 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3083 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3084 | int attr) |
| 3085 | { |
| 3086 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3087 | u32 bitrate; |
| 3088 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3089 | |
| 3090 | rate = nla_nest_start(msg, attr); |
| 3091 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3092 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3093 | |
| 3094 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3095 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3096 | /* report 16-bit bitrate only if we can */ |
| 3097 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3098 | if (bitrate > 0 && |
| 3099 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3100 | return false; |
| 3101 | if (bitrate_compat > 0 && |
| 3102 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3103 | return false; |
| 3104 | |
| 3105 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3106 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3107 | return false; |
| 3108 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3109 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3110 | return false; |
| 3111 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3112 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3113 | return false; |
| 3114 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3115 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3116 | return false; |
| 3117 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3118 | return false; |
| 3119 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3120 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3121 | return false; |
| 3122 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3123 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3124 | return false; |
| 3125 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3126 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3127 | return false; |
| 3128 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3129 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3130 | return false; |
| 3131 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3132 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3133 | return false; |
| 3134 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3135 | |
| 3136 | nla_nest_end(msg, rate); |
| 3137 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3138 | } |
| 3139 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3140 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3141 | int flags, |
| 3142 | struct cfg80211_registered_device *rdev, |
| 3143 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3144 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3145 | { |
| 3146 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3147 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3148 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3149 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3150 | if (!hdr) |
| 3151 | return -1; |
| 3152 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3153 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3154 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3155 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3156 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3157 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3158 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3159 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3160 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3161 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3162 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3163 | sinfo->connected_time)) |
| 3164 | goto nla_put_failure; |
| 3165 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3166 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3167 | sinfo->inactive_time)) |
| 3168 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3169 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3170 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3171 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3172 | (u32)sinfo->rx_bytes)) |
| 3173 | goto nla_put_failure; |
| 3174 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3175 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3176 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3177 | (u32)sinfo->tx_bytes)) |
| 3178 | goto nla_put_failure; |
| 3179 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3180 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3181 | sinfo->rx_bytes)) |
| 3182 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3183 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3184 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3185 | sinfo->tx_bytes)) |
| 3186 | goto nla_put_failure; |
| 3187 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3188 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3189 | goto nla_put_failure; |
| 3190 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3191 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3192 | goto nla_put_failure; |
| 3193 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3194 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3195 | sinfo->plink_state)) |
| 3196 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3197 | switch (rdev->wiphy.signal_type) { |
| 3198 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3199 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3200 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3201 | sinfo->signal)) |
| 3202 | goto nla_put_failure; |
| 3203 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3204 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3205 | sinfo->signal_avg)) |
| 3206 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3207 | break; |
| 3208 | default: |
| 3209 | break; |
| 3210 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3211 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3212 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3213 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3214 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3215 | } |
| 3216 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3217 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3218 | NL80211_STA_INFO_RX_BITRATE)) |
| 3219 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3220 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3221 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3222 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3223 | sinfo->rx_packets)) |
| 3224 | goto nla_put_failure; |
| 3225 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3226 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3227 | sinfo->tx_packets)) |
| 3228 | goto nla_put_failure; |
| 3229 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3230 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3231 | sinfo->tx_retries)) |
| 3232 | goto nla_put_failure; |
| 3233 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3234 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3235 | sinfo->tx_failed)) |
| 3236 | goto nla_put_failure; |
| 3237 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3238 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3239 | sinfo->beacon_loss_count)) |
| 3240 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3241 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3242 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3243 | sinfo->local_pm)) |
| 3244 | goto nla_put_failure; |
| 3245 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3246 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3247 | sinfo->peer_pm)) |
| 3248 | goto nla_put_failure; |
| 3249 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3250 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3251 | sinfo->nonpeer_pm)) |
| 3252 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3253 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3254 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3255 | if (!bss_param) |
| 3256 | goto nla_put_failure; |
| 3257 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3258 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3259 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3260 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3261 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3262 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3263 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3264 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3265 | sinfo->bss_param.dtim_period) || |
| 3266 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3267 | sinfo->bss_param.beacon_interval)) |
| 3268 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3269 | |
| 3270 | nla_nest_end(msg, bss_param); |
| 3271 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3272 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3273 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3274 | sizeof(struct nl80211_sta_flag_update), |
| 3275 | &sinfo->sta_flags)) |
| 3276 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3277 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3278 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3279 | sinfo->t_offset)) |
| 3280 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3281 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3282 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3283 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3284 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3285 | sinfo->assoc_req_ies)) |
| 3286 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3287 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3288 | return genlmsg_end(msg, hdr); |
| 3289 | |
| 3290 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3291 | genlmsg_cancel(msg, hdr); |
| 3292 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3293 | } |
| 3294 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3295 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3296 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3297 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3298 | struct station_info sinfo; |
| 3299 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3300 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3301 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3302 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3303 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3304 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3305 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3306 | if (err) |
| 3307 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3308 | |
| 3309 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3310 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3311 | goto out_err; |
| 3312 | } |
| 3313 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3314 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3315 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3316 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3317 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3318 | if (err == -ENOENT) |
| 3319 | break; |
| 3320 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3321 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3322 | |
| 3323 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3324 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3325 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3326 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3327 | &sinfo) < 0) |
| 3328 | goto out; |
| 3329 | |
| 3330 | sta_idx++; |
| 3331 | } |
| 3332 | |
| 3333 | |
| 3334 | out: |
| 3335 | cb->args[1] = sta_idx; |
| 3336 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3337 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3338 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3339 | |
| 3340 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3341 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3342 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3343 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3344 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3346 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3347 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3348 | struct sk_buff *msg; |
| 3349 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3350 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3351 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3352 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3353 | |
| 3354 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3355 | return -EINVAL; |
| 3356 | |
| 3357 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3358 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3359 | if (!rdev->ops->get_station) |
| 3360 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3361 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3362 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3363 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3364 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3365 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3366 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3367 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3368 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3369 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3370 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3371 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3372 | nlmsg_free(msg); |
| 3373 | return -ENOBUFS; |
| 3374 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3376 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3380 | * Get vlan interface making sure it is running and on the right wiphy. |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3381 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3382 | static struct net_device *get_vlan(struct genl_info *info, |
| 3383 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3384 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3385 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3386 | struct net_device *v; |
| 3387 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3388 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3389 | if (!vlanattr) |
| 3390 | return NULL; |
| 3391 | |
| 3392 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3393 | if (!v) |
| 3394 | return ERR_PTR(-ENODEV); |
| 3395 | |
| 3396 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3397 | ret = -EINVAL; |
| 3398 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3399 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3400 | |
| 3401 | if (!netif_running(v)) { |
| 3402 | ret = -ENETDOWN; |
| 3403 | goto error; |
| 3404 | } |
| 3405 | |
| 3406 | return v; |
| 3407 | error: |
| 3408 | dev_put(v); |
| 3409 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3413 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3415 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3416 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3417 | struct station_parameters params; |
| 3418 | u8 *mac_addr = NULL; |
| 3419 | |
| 3420 | memset(¶ms, 0, sizeof(params)); |
| 3421 | |
| 3422 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3423 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3424 | |
| 3425 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3426 | return -EINVAL; |
| 3427 | |
| 3428 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3429 | return -EINVAL; |
| 3430 | |
| 3431 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3432 | |
| 3433 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3434 | params.supported_rates = |
| 3435 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3436 | params.supported_rates_len = |
| 3437 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3438 | } |
| 3439 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame^] | 3440 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3441 | params.capability = |
| 3442 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3443 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3444 | } |
| 3445 | |
| 3446 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3447 | params.ext_capab = |
| 3448 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3449 | params.ext_capab_len = |
| 3450 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3451 | } |
| 3452 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3453 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL] || |
| 3454 | info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3455 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3456 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3457 | if (!rdev->ops->change_station) |
| 3458 | return -EOPNOTSUPP; |
| 3459 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3460 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3461 | return -EINVAL; |
| 3462 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3463 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3464 | params.plink_action = |
| 3465 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3466 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3467 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3468 | params.plink_state = |
| 3469 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3470 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3471 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3472 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3473 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3474 | |
| 3475 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3476 | pm > NL80211_MESH_POWER_MAX) |
| 3477 | return -EINVAL; |
| 3478 | |
| 3479 | params.local_pm = pm; |
| 3480 | } |
| 3481 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3482 | switch (dev->ieee80211_ptr->iftype) { |
| 3483 | case NL80211_IFTYPE_AP: |
| 3484 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3485 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3486 | /* disallow mesh-specific things */ |
| 3487 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3488 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3489 | if (params.local_pm) |
| 3490 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3491 | |
| 3492 | /* TDLS can't be set, ... */ |
| 3493 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3494 | return -EINVAL; |
| 3495 | /* |
| 3496 | * ... but don't bother the driver with it. This works around |
| 3497 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3498 | * TLDS_PEER flag in the mask even for AP mode. |
| 3499 | */ |
| 3500 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3501 | |
| 3502 | /* accept only the listed bits */ |
| 3503 | if (params.sta_flags_mask & |
| 3504 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3505 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3506 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3507 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3508 | BIT(NL80211_STA_FLAG_WME) | |
| 3509 | BIT(NL80211_STA_FLAG_MFP))) |
| 3510 | return -EINVAL; |
| 3511 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3512 | /* but authenticated/associated only if driver handles it */ |
| 3513 | if (!(rdev->wiphy.features & |
| 3514 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3515 | params.sta_flags_mask & |
| 3516 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3517 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3518 | return -EINVAL; |
| 3519 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3520 | /* reject other things that can't change */ |
| 3521 | if (params.supported_rates) |
| 3522 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame^] | 3523 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3524 | return -EINVAL; |
| 3525 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3526 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3527 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3528 | /* must be last in here for error handling */ |
| 3529 | params.vlan = get_vlan(info, rdev); |
| 3530 | if (IS_ERR(params.vlan)) |
| 3531 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3532 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3533 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3534 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3535 | /* |
| 3536 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3537 | * but silently ignore attempts to change it since we |
| 3538 | * don't have state here to verify that it doesn't try |
| 3539 | * to change the flag. |
| 3540 | */ |
| 3541 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3542 | /* fall through */ |
| 3543 | case NL80211_IFTYPE_ADHOC: |
| 3544 | /* disallow things sta doesn't support */ |
| 3545 | if (params.plink_action) |
| 3546 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3547 | if (params.local_pm) |
| 3548 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3549 | /* reject any changes other than AUTHORIZED */ |
| 3550 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3551 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3552 | break; |
| 3553 | case NL80211_IFTYPE_MESH_POINT: |
| 3554 | /* disallow things mesh doesn't support */ |
| 3555 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3556 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3557 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3558 | return -EINVAL; |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame^] | 3559 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) |
| 3560 | return -EINVAL; |
| 3561 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) |
| 3562 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3563 | /* |
| 3564 | * No special handling for TDLS here -- the userspace |
| 3565 | * mesh code doesn't have this bug. |
| 3566 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3567 | if (params.sta_flags_mask & |
| 3568 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3569 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3570 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3571 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3572 | break; |
| 3573 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3574 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3575 | } |
| 3576 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3577 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3578 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3579 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3580 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3581 | if (params.vlan) |
| 3582 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3583 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3584 | return err; |
| 3585 | } |
| 3586 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3587 | static struct nla_policy |
| 3588 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3589 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3590 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3591 | }; |
| 3592 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3593 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3596 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3597 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3598 | struct station_parameters params; |
| 3599 | u8 *mac_addr = NULL; |
| 3600 | |
| 3601 | memset(¶ms, 0, sizeof(params)); |
| 3602 | |
| 3603 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3604 | return -EINVAL; |
| 3605 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3606 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3607 | return -EINVAL; |
| 3608 | |
| 3609 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3610 | return -EINVAL; |
| 3611 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3612 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3613 | return -EINVAL; |
| 3614 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3615 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3616 | params.supported_rates = |
| 3617 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3618 | params.supported_rates_len = |
| 3619 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3620 | params.listen_interval = |
| 3621 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3622 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3623 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3624 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3625 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3626 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame^] | 3627 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3628 | params.capability = |
| 3629 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3630 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3631 | } |
| 3632 | |
| 3633 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3634 | params.ext_capab = |
| 3635 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3636 | params.ext_capab_len = |
| 3637 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3638 | } |
| 3639 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3640 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3641 | params.ht_capa = |
| 3642 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3643 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3644 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3645 | params.vht_capa = |
| 3646 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3647 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3648 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3649 | params.plink_action = |
| 3650 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3651 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3652 | if (!rdev->ops->add_station) |
| 3653 | return -EOPNOTSUPP; |
| 3654 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3655 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3656 | return -EINVAL; |
| 3657 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3658 | switch (dev->ieee80211_ptr->iftype) { |
| 3659 | case NL80211_IFTYPE_AP: |
| 3660 | case NL80211_IFTYPE_AP_VLAN: |
| 3661 | case NL80211_IFTYPE_P2P_GO: |
| 3662 | /* parse WME attributes if sta is WME capable */ |
| 3663 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3664 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3665 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3666 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3667 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3668 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3669 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3670 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3671 | nl80211_sta_wme_policy); |
| 3672 | if (err) |
| 3673 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3674 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3675 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3676 | params.uapsd_queues = |
| 3677 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3678 | if (params.uapsd_queues & |
| 3679 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3680 | return -EINVAL; |
| 3681 | |
| 3682 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3683 | params.max_sp = |
| 3684 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3685 | |
| 3686 | if (params.max_sp & |
| 3687 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3688 | return -EINVAL; |
| 3689 | |
| 3690 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3691 | } |
| 3692 | /* TDLS peers cannot be added */ |
| 3693 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3694 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3695 | /* but don't bother the driver with it */ |
| 3696 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3697 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3698 | /* allow authenticated/associated only if driver handles it */ |
| 3699 | if (!(rdev->wiphy.features & |
| 3700 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3701 | params.sta_flags_mask & |
| 3702 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3703 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3704 | return -EINVAL; |
| 3705 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3706 | /* must be last in here for error handling */ |
| 3707 | params.vlan = get_vlan(info, rdev); |
| 3708 | if (IS_ERR(params.vlan)) |
| 3709 | return PTR_ERR(params.vlan); |
| 3710 | break; |
| 3711 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3712 | /* associated is disallowed */ |
| 3713 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3714 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3715 | /* TDLS peers cannot be added */ |
| 3716 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3717 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3718 | break; |
| 3719 | case NL80211_IFTYPE_STATION: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3720 | /* associated is disallowed */ |
| 3721 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3722 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3723 | /* Only TDLS peers can be added */ |
| 3724 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3725 | return -EINVAL; |
| 3726 | /* Can only add if TDLS ... */ |
| 3727 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3728 | return -EOPNOTSUPP; |
| 3729 | /* ... with external setup is supported */ |
| 3730 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3731 | return -EOPNOTSUPP; |
| 3732 | break; |
| 3733 | default: |
| 3734 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3735 | } |
| 3736 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3737 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3738 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3739 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3740 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3741 | if (params.vlan) |
| 3742 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3743 | return err; |
| 3744 | } |
| 3745 | |
| 3746 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3747 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3749 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3750 | u8 *mac_addr = NULL; |
| 3751 | |
| 3752 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3753 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3754 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3755 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3756 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3757 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3758 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3759 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3761 | if (!rdev->ops->del_station) |
| 3762 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3763 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3764 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3765 | } |
| 3766 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3767 | 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] | 3768 | int flags, struct net_device *dev, |
| 3769 | u8 *dst, u8 *next_hop, |
| 3770 | struct mpath_info *pinfo) |
| 3771 | { |
| 3772 | void *hdr; |
| 3773 | struct nlattr *pinfoattr; |
| 3774 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3775 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3776 | if (!hdr) |
| 3777 | return -1; |
| 3778 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3779 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3780 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3781 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3782 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3783 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3784 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3785 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3786 | if (!pinfoattr) |
| 3787 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3788 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3789 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3790 | pinfo->frame_qlen)) |
| 3791 | goto nla_put_failure; |
| 3792 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3793 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3794 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3795 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3796 | pinfo->metric)) || |
| 3797 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3798 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3799 | pinfo->exptime)) || |
| 3800 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3801 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3802 | pinfo->flags)) || |
| 3803 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3804 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3805 | pinfo->discovery_timeout)) || |
| 3806 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3807 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3808 | pinfo->discovery_retries))) |
| 3809 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3810 | |
| 3811 | nla_nest_end(msg, pinfoattr); |
| 3812 | |
| 3813 | return genlmsg_end(msg, hdr); |
| 3814 | |
| 3815 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3816 | genlmsg_cancel(msg, hdr); |
| 3817 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3821 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3822 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3823 | struct mpath_info pinfo; |
| 3824 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3825 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3826 | u8 dst[ETH_ALEN]; |
| 3827 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3828 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3829 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3830 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3831 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3832 | if (err) |
| 3833 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3834 | |
| 3835 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3836 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3837 | goto out_err; |
| 3838 | } |
| 3839 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3840 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3841 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3842 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3843 | } |
| 3844 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3845 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3846 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3847 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3848 | if (err == -ENOENT) |
| 3849 | break; |
| 3850 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3851 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3852 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3853 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3854 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3855 | netdev, dst, next_hop, |
| 3856 | &pinfo) < 0) |
| 3857 | goto out; |
| 3858 | |
| 3859 | path_idx++; |
| 3860 | } |
| 3861 | |
| 3862 | |
| 3863 | out: |
| 3864 | cb->args[1] = path_idx; |
| 3865 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3866 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3867 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3868 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3872 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3874 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3875 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3876 | struct mpath_info pinfo; |
| 3877 | struct sk_buff *msg; |
| 3878 | u8 *dst = NULL; |
| 3879 | u8 next_hop[ETH_ALEN]; |
| 3880 | |
| 3881 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3882 | |
| 3883 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3884 | return -EINVAL; |
| 3885 | |
| 3886 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3887 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3888 | if (!rdev->ops->get_mpath) |
| 3889 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3890 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3891 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3892 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3893 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3894 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3895 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3896 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3897 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3898 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3899 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3900 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3901 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3902 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3903 | dev, dst, next_hop, &pinfo) < 0) { |
| 3904 | nlmsg_free(msg); |
| 3905 | return -ENOBUFS; |
| 3906 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3907 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3908 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3912 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3914 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3915 | u8 *dst = NULL; |
| 3916 | u8 *next_hop = NULL; |
| 3917 | |
| 3918 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3919 | return -EINVAL; |
| 3920 | |
| 3921 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3922 | return -EINVAL; |
| 3923 | |
| 3924 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3925 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3926 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3927 | if (!rdev->ops->change_mpath) |
| 3928 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3929 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3930 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3931 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3932 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3933 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3934 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3935 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3936 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3937 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3939 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3940 | u8 *dst = NULL; |
| 3941 | u8 *next_hop = NULL; |
| 3942 | |
| 3943 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3944 | return -EINVAL; |
| 3945 | |
| 3946 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3947 | return -EINVAL; |
| 3948 | |
| 3949 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3950 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3951 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3952 | if (!rdev->ops->add_mpath) |
| 3953 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3954 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3955 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3956 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3957 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3958 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3962 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3964 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3965 | u8 *dst = NULL; |
| 3966 | |
| 3967 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3968 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3969 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3970 | if (!rdev->ops->del_mpath) |
| 3971 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3972 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3973 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3974 | } |
| 3975 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3976 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3977 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3979 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3980 | struct bss_parameters params; |
| 3981 | |
| 3982 | memset(¶ms, 0, sizeof(params)); |
| 3983 | /* default to not changing parameters */ |
| 3984 | params.use_cts_prot = -1; |
| 3985 | params.use_short_preamble = -1; |
| 3986 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3987 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3988 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3989 | params.p2p_ctwindow = -1; |
| 3990 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3991 | |
| 3992 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3993 | params.use_cts_prot = |
| 3994 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3995 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3996 | params.use_short_preamble = |
| 3997 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3998 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3999 | params.use_short_slot_time = |
| 4000 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4001 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4002 | params.basic_rates = |
| 4003 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4004 | params.basic_rates_len = |
| 4005 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4006 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4007 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4008 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4010 | params.ht_opmode = |
| 4011 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4012 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4013 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4014 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4015 | return -EINVAL; |
| 4016 | params.p2p_ctwindow = |
| 4017 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4018 | if (params.p2p_ctwindow < 0) |
| 4019 | return -EINVAL; |
| 4020 | if (params.p2p_ctwindow != 0 && |
| 4021 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4022 | return -EINVAL; |
| 4023 | } |
| 4024 | |
| 4025 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4026 | u8 tmp; |
| 4027 | |
| 4028 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4029 | return -EINVAL; |
| 4030 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4031 | if (tmp > 1) |
| 4032 | return -EINVAL; |
| 4033 | params.p2p_opp_ps = tmp; |
| 4034 | if (params.p2p_opp_ps && |
| 4035 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4036 | return -EINVAL; |
| 4037 | } |
| 4038 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4039 | if (!rdev->ops->change_bss) |
| 4040 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4041 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4042 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4043 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4044 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4045 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4046 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4047 | } |
| 4048 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4049 | 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] | 4050 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4051 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4052 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4053 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4054 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4055 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4056 | }; |
| 4057 | |
| 4058 | static int parse_reg_rule(struct nlattr *tb[], |
| 4059 | struct ieee80211_reg_rule *reg_rule) |
| 4060 | { |
| 4061 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4062 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4063 | |
| 4064 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4065 | return -EINVAL; |
| 4066 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4067 | return -EINVAL; |
| 4068 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4069 | return -EINVAL; |
| 4070 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4071 | return -EINVAL; |
| 4072 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4073 | return -EINVAL; |
| 4074 | |
| 4075 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4076 | |
| 4077 | freq_range->start_freq_khz = |
| 4078 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4079 | freq_range->end_freq_khz = |
| 4080 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4081 | freq_range->max_bandwidth_khz = |
| 4082 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4083 | |
| 4084 | power_rule->max_eirp = |
| 4085 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4086 | |
| 4087 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4088 | power_rule->max_antenna_gain = |
| 4089 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4090 | |
| 4091 | return 0; |
| 4092 | } |
| 4093 | |
| 4094 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4095 | { |
| 4096 | int r; |
| 4097 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4098 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4099 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4100 | /* |
| 4101 | * You should only get this when cfg80211 hasn't yet initialized |
| 4102 | * completely when built-in to the kernel right between the time |
| 4103 | * window between nl80211_init() and regulatory_init(), if that is |
| 4104 | * even possible. |
| 4105 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4106 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4107 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4108 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4109 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4110 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4111 | |
| 4112 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4113 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4114 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4115 | user_reg_hint_type = |
| 4116 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4117 | else |
| 4118 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4119 | |
| 4120 | switch (user_reg_hint_type) { |
| 4121 | case NL80211_USER_REG_HINT_USER: |
| 4122 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4123 | break; |
| 4124 | default: |
| 4125 | return -EINVAL; |
| 4126 | } |
| 4127 | |
| 4128 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4129 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4130 | return r; |
| 4131 | } |
| 4132 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4133 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4134 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4135 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4136 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4137 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4138 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4139 | struct mesh_config cur_params; |
| 4140 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4141 | void *hdr; |
| 4142 | struct nlattr *pinfoattr; |
| 4143 | struct sk_buff *msg; |
| 4144 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4145 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4146 | return -EOPNOTSUPP; |
| 4147 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4148 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4149 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4150 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4151 | wdev_lock(wdev); |
| 4152 | /* If not connected, get default parameters */ |
| 4153 | if (!wdev->mesh_id_len) |
| 4154 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4155 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4156 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4157 | wdev_unlock(wdev); |
| 4158 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4159 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4160 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4161 | |
| 4162 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4163 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4164 | if (!msg) |
| 4165 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4166 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4167 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4168 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4169 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4170 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4171 | if (!pinfoattr) |
| 4172 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4173 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4174 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4175 | cur_params.dot11MeshRetryTimeout) || |
| 4176 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4177 | cur_params.dot11MeshConfirmTimeout) || |
| 4178 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4179 | cur_params.dot11MeshHoldingTimeout) || |
| 4180 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4181 | cur_params.dot11MeshMaxPeerLinks) || |
| 4182 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4183 | cur_params.dot11MeshMaxRetries) || |
| 4184 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4185 | cur_params.dot11MeshTTL) || |
| 4186 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4187 | cur_params.element_ttl) || |
| 4188 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4189 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4190 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4191 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4192 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4193 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4194 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4195 | cur_params.path_refresh_time) || |
| 4196 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4197 | cur_params.min_discovery_timeout) || |
| 4198 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4199 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4200 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4201 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4202 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4203 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4204 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4205 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4206 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4207 | cur_params.dot11MeshHWMPRootMode) || |
| 4208 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4209 | cur_params.dot11MeshHWMPRannInterval) || |
| 4210 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4211 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4212 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4213 | cur_params.dot11MeshForwarding) || |
| 4214 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4215 | cur_params.rssi_threshold) || |
| 4216 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4217 | cur_params.ht_opmode) || |
| 4218 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4219 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4220 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4221 | cur_params.dot11MeshHWMProotInterval) || |
| 4222 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4223 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4224 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4225 | cur_params.power_mode) || |
| 4226 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4227 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4228 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4229 | nla_nest_end(msg, pinfoattr); |
| 4230 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4231 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4232 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4233 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4234 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4235 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4236 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4237 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4240 | 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] | 4241 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4242 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4243 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4244 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4245 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4246 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4247 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4248 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4249 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4250 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4251 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4252 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4253 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4254 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4255 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4256 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4257 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4258 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4259 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4260 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4261 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4262 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4263 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4264 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4265 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4266 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4267 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4268 | }; |
| 4269 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4270 | static const struct nla_policy |
| 4271 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4272 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4273 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4274 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4275 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4276 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4277 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4278 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4279 | }; |
| 4280 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4281 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4282 | struct mesh_config *cfg, |
| 4283 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4284 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4285 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4286 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4287 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4288 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4289 | do { \ |
| 4290 | if (tb[attr]) { \ |
| 4291 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4292 | return -EINVAL; \ |
| 4293 | cfg->param = fn(tb[attr]); \ |
| 4294 | mask |= (1 << (attr - 1)); \ |
| 4295 | } \ |
| 4296 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4297 | |
| 4298 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4299 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4300 | return -EINVAL; |
| 4301 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4302 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4303 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4304 | return -EINVAL; |
| 4305 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4306 | /* This makes sure that there aren't more than 32 mesh config |
| 4307 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4308 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4309 | |
| 4310 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4311 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4312 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4313 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4314 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4315 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4316 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4317 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4318 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4319 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4320 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4321 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4322 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4323 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4324 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4325 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4326 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4327 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4328 | 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] | 4329 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4330 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4331 | 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] | 4332 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4333 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4334 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4335 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4336 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4337 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4338 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4339 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4340 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4341 | 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] | 4342 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4343 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4344 | 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] | 4345 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4346 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4348 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4349 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4350 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4351 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4352 | 1, 65535, mask, |
| 4353 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4354 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4355 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4356 | 1, 65535, mask, |
| 4357 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4358 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4359 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4360 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4361 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4362 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4363 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4364 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4365 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4366 | nla_get_u8); |
| 4367 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4368 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4369 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4370 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4371 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4372 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4373 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4374 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4375 | mask, NL80211_MESHCONF_FORWARDING, |
| 4376 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4377 | 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] | 4378 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4379 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4380 | 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] | 4381 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4382 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4383 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4384 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4385 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4386 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4387 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4388 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4389 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4390 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4391 | dot11MeshHWMPconfirmationInterval, |
| 4392 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4393 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4394 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4395 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4396 | NL80211_MESH_POWER_ACTIVE, |
| 4397 | NL80211_MESH_POWER_MAX, |
| 4398 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4399 | nla_get_u32); |
| 4400 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4401 | 0, 65535, mask, |
| 4402 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4403 | if (mask_out) |
| 4404 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4405 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4406 | return 0; |
| 4407 | |
| 4408 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4409 | } |
| 4410 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4411 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4412 | struct mesh_setup *setup) |
| 4413 | { |
| 4414 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4415 | |
| 4416 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4417 | return -EINVAL; |
| 4418 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4419 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4420 | nl80211_mesh_setup_params_policy)) |
| 4421 | return -EINVAL; |
| 4422 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4423 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4424 | setup->sync_method = |
| 4425 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4426 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4427 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4428 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4429 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4430 | setup->path_sel_proto = |
| 4431 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4432 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4433 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4434 | |
| 4435 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4436 | setup->path_metric = |
| 4437 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4438 | IEEE80211_PATH_METRIC_VENDOR : |
| 4439 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4440 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4441 | |
| 4442 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4443 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4444 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4445 | if (!is_valid_ie_attr(ieattr)) |
| 4446 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4447 | setup->ie = nla_data(ieattr); |
| 4448 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4449 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4450 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4451 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4452 | |
| 4453 | return 0; |
| 4454 | } |
| 4455 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4456 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4457 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4458 | { |
| 4459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4460 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4461 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4462 | struct mesh_config cfg; |
| 4463 | u32 mask; |
| 4464 | int err; |
| 4465 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4466 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4467 | return -EOPNOTSUPP; |
| 4468 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4469 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4470 | return -EOPNOTSUPP; |
| 4471 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4472 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4473 | if (err) |
| 4474 | return err; |
| 4475 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4476 | wdev_lock(wdev); |
| 4477 | if (!wdev->mesh_id_len) |
| 4478 | err = -ENOLINK; |
| 4479 | |
| 4480 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4481 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4482 | |
| 4483 | wdev_unlock(wdev); |
| 4484 | |
| 4485 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4486 | } |
| 4487 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4488 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4489 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4490 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4491 | struct sk_buff *msg; |
| 4492 | void *hdr = NULL; |
| 4493 | struct nlattr *nl_reg_rules; |
| 4494 | unsigned int i; |
| 4495 | int err = -EINVAL; |
| 4496 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4497 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4498 | |
| 4499 | if (!cfg80211_regdomain) |
| 4500 | goto out; |
| 4501 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4502 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4503 | if (!msg) { |
| 4504 | err = -ENOBUFS; |
| 4505 | goto out; |
| 4506 | } |
| 4507 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4508 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4509 | NL80211_CMD_GET_REG); |
| 4510 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4511 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4512 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4513 | if (reg_last_request_cell_base() && |
| 4514 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4515 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4516 | goto nla_put_failure; |
| 4517 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4518 | rcu_read_lock(); |
| 4519 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4520 | |
| 4521 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4522 | (regdom->dfs_region && |
| 4523 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4524 | goto nla_put_failure_rcu; |
| 4525 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4526 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4527 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4528 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4529 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4530 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4531 | struct nlattr *nl_reg_rule; |
| 4532 | const struct ieee80211_reg_rule *reg_rule; |
| 4533 | const struct ieee80211_freq_range *freq_range; |
| 4534 | const struct ieee80211_power_rule *power_rule; |
| 4535 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4536 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4537 | freq_range = ®_rule->freq_range; |
| 4538 | power_rule = ®_rule->power_rule; |
| 4539 | |
| 4540 | nl_reg_rule = nla_nest_start(msg, i); |
| 4541 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4542 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4543 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4544 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4545 | reg_rule->flags) || |
| 4546 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4547 | freq_range->start_freq_khz) || |
| 4548 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4549 | freq_range->end_freq_khz) || |
| 4550 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4551 | freq_range->max_bandwidth_khz) || |
| 4552 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4553 | power_rule->max_antenna_gain) || |
| 4554 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4555 | power_rule->max_eirp)) |
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 | |
| 4558 | nla_nest_end(msg, nl_reg_rule); |
| 4559 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4560 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4561 | |
| 4562 | nla_nest_end(msg, nl_reg_rules); |
| 4563 | |
| 4564 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4565 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4566 | goto out; |
| 4567 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4568 | nla_put_failure_rcu: |
| 4569 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4570 | nla_put_failure: |
| 4571 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4572 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4573 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4574 | err = -EMSGSIZE; |
| 4575 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4576 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4577 | return err; |
| 4578 | } |
| 4579 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4580 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4581 | { |
| 4582 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4583 | struct nlattr *nl_reg_rule; |
| 4584 | char *alpha2 = NULL; |
| 4585 | int rem_reg_rules = 0, r = 0; |
| 4586 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4587 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4588 | struct ieee80211_regdomain *rd = NULL; |
| 4589 | |
| 4590 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4591 | return -EINVAL; |
| 4592 | |
| 4593 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4594 | return -EINVAL; |
| 4595 | |
| 4596 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4597 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4598 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4599 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4600 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4601 | 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] | 4602 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4603 | num_rules++; |
| 4604 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4605 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4606 | } |
| 4607 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4608 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4609 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4610 | |
| 4611 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4612 | if (!rd) |
| 4613 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4614 | |
| 4615 | rd->n_reg_rules = num_rules; |
| 4616 | rd->alpha2[0] = alpha2[0]; |
| 4617 | rd->alpha2[1] = alpha2[1]; |
| 4618 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4619 | /* |
| 4620 | * Disable DFS master mode if the DFS region was |
| 4621 | * not supported or known on this kernel. |
| 4622 | */ |
| 4623 | if (reg_supported_dfs_region(dfs_region)) |
| 4624 | rd->dfs_region = dfs_region; |
| 4625 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4626 | 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] | 4627 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4628 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4629 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4630 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4631 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4632 | if (r) |
| 4633 | goto bad_reg; |
| 4634 | |
| 4635 | rule_idx++; |
| 4636 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4637 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4638 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4639 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4640 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4643 | mutex_lock(&cfg80211_mutex); |
| 4644 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4645 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4646 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4647 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4648 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4649 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4650 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4651 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4652 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4655 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4656 | { |
| 4657 | struct nlattr *attr1, *attr2; |
| 4658 | int n_channels = 0, tmp1, tmp2; |
| 4659 | |
| 4660 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4661 | n_channels++; |
| 4662 | /* |
| 4663 | * Some hardware has a limited channel list for |
| 4664 | * scanning, and it is pretty much nonsensical |
| 4665 | * to scan for a channel twice, so disallow that |
| 4666 | * and don't require drivers to check that the |
| 4667 | * channel list they get isn't longer than what |
| 4668 | * they can scan, as long as they can scan all |
| 4669 | * the channels they registered at once. |
| 4670 | */ |
| 4671 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4672 | if (attr1 != attr2 && |
| 4673 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4674 | return 0; |
| 4675 | } |
| 4676 | |
| 4677 | return n_channels; |
| 4678 | } |
| 4679 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4680 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4681 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4683 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4684 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4685 | struct nlattr *attr; |
| 4686 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4687 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4688 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4689 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4690 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4691 | return -EINVAL; |
| 4692 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4693 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4694 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4695 | if (!rdev->ops->scan) |
| 4696 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4698 | if (rdev->scan_req) |
| 4699 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4700 | |
| 4701 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4702 | n_channels = validate_scan_freqs( |
| 4703 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4704 | if (!n_channels) |
| 4705 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4706 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4707 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4708 | n_channels = 0; |
| 4709 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4710 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4711 | if (wiphy->bands[band]) |
| 4712 | n_channels += wiphy->bands[band]->n_channels; |
| 4713 | } |
| 4714 | |
| 4715 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4716 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4717 | n_ssids++; |
| 4718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | if (n_ssids > wiphy->max_scan_ssids) |
| 4720 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4721 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4722 | if (info->attrs[NL80211_ATTR_IE]) |
| 4723 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4724 | else |
| 4725 | ie_len = 0; |
| 4726 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4727 | if (ie_len > wiphy->max_scan_ie_len) |
| 4728 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4729 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4730 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4731 | + sizeof(*request->ssids) * n_ssids |
| 4732 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4733 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4734 | if (!request) |
| 4735 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4736 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4737 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4738 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4739 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4740 | if (ie_len) { |
| 4741 | if (request->ssids) |
| 4742 | request->ie = (void *)(request->ssids + n_ssids); |
| 4743 | else |
| 4744 | request->ie = (void *)(request->channels + n_channels); |
| 4745 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4746 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4747 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4748 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4749 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4750 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4751 | struct ieee80211_channel *chan; |
| 4752 | |
| 4753 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4754 | |
| 4755 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4756 | err = -EINVAL; |
| 4757 | goto out_free; |
| 4758 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4759 | |
| 4760 | /* ignore disabled channels */ |
| 4761 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4762 | continue; |
| 4763 | |
| 4764 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4765 | i++; |
| 4766 | } |
| 4767 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4768 | enum ieee80211_band band; |
| 4769 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4770 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4771 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4772 | int j; |
| 4773 | if (!wiphy->bands[band]) |
| 4774 | continue; |
| 4775 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4776 | struct ieee80211_channel *chan; |
| 4777 | |
| 4778 | chan = &wiphy->bands[band]->channels[j]; |
| 4779 | |
| 4780 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4781 | continue; |
| 4782 | |
| 4783 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4784 | i++; |
| 4785 | } |
| 4786 | } |
| 4787 | } |
| 4788 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4789 | if (!i) { |
| 4790 | err = -EINVAL; |
| 4791 | goto out_free; |
| 4792 | } |
| 4793 | |
| 4794 | request->n_channels = i; |
| 4795 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4796 | i = 0; |
| 4797 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4798 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4799 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4800 | err = -EINVAL; |
| 4801 | goto out_free; |
| 4802 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4803 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4804 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4805 | i++; |
| 4806 | } |
| 4807 | } |
| 4808 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4809 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4810 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4811 | memcpy((void *)request->ie, |
| 4812 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4813 | request->ie_len); |
| 4814 | } |
| 4815 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4816 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4817 | if (wiphy->bands[i]) |
| 4818 | request->rates[i] = |
| 4819 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4820 | |
| 4821 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4822 | nla_for_each_nested(attr, |
| 4823 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4824 | tmp) { |
| 4825 | enum ieee80211_band band = nla_type(attr); |
| 4826 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4827 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4828 | err = -EINVAL; |
| 4829 | goto out_free; |
| 4830 | } |
| 4831 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4832 | nla_data(attr), |
| 4833 | nla_len(attr), |
| 4834 | &request->rates[band]); |
| 4835 | if (err) |
| 4836 | goto out_free; |
| 4837 | } |
| 4838 | } |
| 4839 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4840 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4841 | request->flags = nla_get_u32( |
| 4842 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4843 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4844 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4845 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4846 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4847 | err = -EOPNOTSUPP; |
| 4848 | goto out_free; |
| 4849 | } |
| 4850 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4851 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4852 | request->no_cck = |
| 4853 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4854 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4855 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4856 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4857 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4858 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4859 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4860 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4861 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4862 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4863 | nl80211_send_scan_start(rdev, wdev); |
| 4864 | if (wdev->netdev) |
| 4865 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4866 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4867 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4868 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4869 | kfree(request); |
| 4870 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4871 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4872 | return err; |
| 4873 | } |
| 4874 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4875 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4876 | struct genl_info *info) |
| 4877 | { |
| 4878 | struct cfg80211_sched_scan_request *request; |
| 4879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4880 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4881 | struct nlattr *attr; |
| 4882 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4883 | 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] | 4884 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4885 | enum ieee80211_band band; |
| 4886 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4887 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4888 | |
| 4889 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4890 | !rdev->ops->sched_scan_start) |
| 4891 | return -EOPNOTSUPP; |
| 4892 | |
| 4893 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4894 | return -EINVAL; |
| 4895 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4896 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4897 | return -EINVAL; |
| 4898 | |
| 4899 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4900 | if (interval == 0) |
| 4901 | return -EINVAL; |
| 4902 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4903 | wiphy = &rdev->wiphy; |
| 4904 | |
| 4905 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4906 | n_channels = validate_scan_freqs( |
| 4907 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4908 | if (!n_channels) |
| 4909 | return -EINVAL; |
| 4910 | } else { |
| 4911 | n_channels = 0; |
| 4912 | |
| 4913 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4914 | if (wiphy->bands[band]) |
| 4915 | n_channels += wiphy->bands[band]->n_channels; |
| 4916 | } |
| 4917 | |
| 4918 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4919 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4920 | tmp) |
| 4921 | n_ssids++; |
| 4922 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4923 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4924 | return -EINVAL; |
| 4925 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4926 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4927 | nla_for_each_nested(attr, |
| 4928 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4929 | tmp) |
| 4930 | n_match_sets++; |
| 4931 | |
| 4932 | if (n_match_sets > wiphy->max_match_sets) |
| 4933 | return -EINVAL; |
| 4934 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4935 | if (info->attrs[NL80211_ATTR_IE]) |
| 4936 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4937 | else |
| 4938 | ie_len = 0; |
| 4939 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4940 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4941 | return -EINVAL; |
| 4942 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4943 | mutex_lock(&rdev->sched_scan_mtx); |
| 4944 | |
| 4945 | if (rdev->sched_scan_req) { |
| 4946 | err = -EINPROGRESS; |
| 4947 | goto out; |
| 4948 | } |
| 4949 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4950 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4951 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4952 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4953 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4954 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4955 | if (!request) { |
| 4956 | err = -ENOMEM; |
| 4957 | goto out; |
| 4958 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4959 | |
| 4960 | if (n_ssids) |
| 4961 | request->ssids = (void *)&request->channels[n_channels]; |
| 4962 | request->n_ssids = n_ssids; |
| 4963 | if (ie_len) { |
| 4964 | if (request->ssids) |
| 4965 | request->ie = (void *)(request->ssids + n_ssids); |
| 4966 | else |
| 4967 | request->ie = (void *)(request->channels + n_channels); |
| 4968 | } |
| 4969 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4970 | if (n_match_sets) { |
| 4971 | if (request->ie) |
| 4972 | request->match_sets = (void *)(request->ie + ie_len); |
| 4973 | else if (request->ssids) |
| 4974 | request->match_sets = |
| 4975 | (void *)(request->ssids + n_ssids); |
| 4976 | else |
| 4977 | request->match_sets = |
| 4978 | (void *)(request->channels + n_channels); |
| 4979 | } |
| 4980 | request->n_match_sets = n_match_sets; |
| 4981 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4982 | i = 0; |
| 4983 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4984 | /* user specified, bail out if channel not found */ |
| 4985 | nla_for_each_nested(attr, |
| 4986 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4987 | tmp) { |
| 4988 | struct ieee80211_channel *chan; |
| 4989 | |
| 4990 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4991 | |
| 4992 | if (!chan) { |
| 4993 | err = -EINVAL; |
| 4994 | goto out_free; |
| 4995 | } |
| 4996 | |
| 4997 | /* ignore disabled channels */ |
| 4998 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4999 | continue; |
| 5000 | |
| 5001 | request->channels[i] = chan; |
| 5002 | i++; |
| 5003 | } |
| 5004 | } else { |
| 5005 | /* all channels */ |
| 5006 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5007 | int j; |
| 5008 | if (!wiphy->bands[band]) |
| 5009 | continue; |
| 5010 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5011 | struct ieee80211_channel *chan; |
| 5012 | |
| 5013 | chan = &wiphy->bands[band]->channels[j]; |
| 5014 | |
| 5015 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5016 | continue; |
| 5017 | |
| 5018 | request->channels[i] = chan; |
| 5019 | i++; |
| 5020 | } |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | if (!i) { |
| 5025 | err = -EINVAL; |
| 5026 | goto out_free; |
| 5027 | } |
| 5028 | |
| 5029 | request->n_channels = i; |
| 5030 | |
| 5031 | i = 0; |
| 5032 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5033 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5034 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5035 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5036 | err = -EINVAL; |
| 5037 | goto out_free; |
| 5038 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5039 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5040 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5041 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5042 | i++; |
| 5043 | } |
| 5044 | } |
| 5045 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5046 | i = 0; |
| 5047 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5048 | nla_for_each_nested(attr, |
| 5049 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5050 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5051 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5052 | |
| 5053 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5054 | nla_data(attr), nla_len(attr), |
| 5055 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5056 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5057 | if (ssid) { |
| 5058 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5059 | err = -EINVAL; |
| 5060 | goto out_free; |
| 5061 | } |
| 5062 | memcpy(request->match_sets[i].ssid.ssid, |
| 5063 | nla_data(ssid), nla_len(ssid)); |
| 5064 | request->match_sets[i].ssid.ssid_len = |
| 5065 | nla_len(ssid); |
| 5066 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5067 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5068 | if (rssi) |
| 5069 | request->rssi_thold = nla_get_u32(rssi); |
| 5070 | else |
| 5071 | request->rssi_thold = |
| 5072 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5073 | i++; |
| 5074 | } |
| 5075 | } |
| 5076 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5077 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5078 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5079 | memcpy((void *)request->ie, |
| 5080 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5081 | request->ie_len); |
| 5082 | } |
| 5083 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5084 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5085 | request->flags = nla_get_u32( |
| 5086 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5087 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5088 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5089 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5090 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5091 | err = -EOPNOTSUPP; |
| 5092 | goto out_free; |
| 5093 | } |
| 5094 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5095 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5096 | request->dev = dev; |
| 5097 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5098 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5099 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5100 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5101 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5102 | if (!err) { |
| 5103 | rdev->sched_scan_req = request; |
| 5104 | nl80211_send_sched_scan(rdev, dev, |
| 5105 | NL80211_CMD_START_SCHED_SCAN); |
| 5106 | goto out; |
| 5107 | } |
| 5108 | |
| 5109 | out_free: |
| 5110 | kfree(request); |
| 5111 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5112 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5113 | return err; |
| 5114 | } |
| 5115 | |
| 5116 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5117 | struct genl_info *info) |
| 5118 | { |
| 5119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5120 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5121 | |
| 5122 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5123 | !rdev->ops->sched_scan_stop) |
| 5124 | return -EOPNOTSUPP; |
| 5125 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5126 | mutex_lock(&rdev->sched_scan_mtx); |
| 5127 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5128 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5129 | |
| 5130 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5131 | } |
| 5132 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5133 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5134 | struct genl_info *info) |
| 5135 | { |
| 5136 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5137 | struct net_device *dev = info->user_ptr[1]; |
| 5138 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5139 | struct cfg80211_chan_def chandef; |
| 5140 | int err; |
| 5141 | |
| 5142 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5143 | if (err) |
| 5144 | return err; |
| 5145 | |
| 5146 | if (wdev->cac_started) |
| 5147 | return -EBUSY; |
| 5148 | |
| 5149 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5150 | if (err < 0) |
| 5151 | return err; |
| 5152 | |
| 5153 | if (err == 0) |
| 5154 | return -EINVAL; |
| 5155 | |
| 5156 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5157 | return -EINVAL; |
| 5158 | |
| 5159 | if (!rdev->ops->start_radar_detection) |
| 5160 | return -EOPNOTSUPP; |
| 5161 | |
| 5162 | mutex_lock(&rdev->devlist_mtx); |
| 5163 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5164 | chandef.chan, CHAN_MODE_SHARED, |
| 5165 | BIT(chandef.width)); |
| 5166 | if (err) |
| 5167 | goto err_locked; |
| 5168 | |
| 5169 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5170 | if (!err) { |
| 5171 | wdev->channel = chandef.chan; |
| 5172 | wdev->cac_started = true; |
| 5173 | wdev->cac_start_time = jiffies; |
| 5174 | } |
| 5175 | err_locked: |
| 5176 | mutex_unlock(&rdev->devlist_mtx); |
| 5177 | |
| 5178 | return err; |
| 5179 | } |
| 5180 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5181 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5182 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5183 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5184 | struct wireless_dev *wdev, |
| 5185 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5186 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5187 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5188 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5189 | void *hdr; |
| 5190 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5191 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5192 | |
| 5193 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5194 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5195 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5196 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5197 | if (!hdr) |
| 5198 | return -1; |
| 5199 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5200 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5201 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5202 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5203 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5204 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | |
| 5206 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5207 | if (!bss) |
| 5208 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5209 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5210 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5211 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5212 | |
| 5213 | rcu_read_lock(); |
| 5214 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5215 | if (ies) { |
| 5216 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5217 | goto fail_unlock_rcu; |
| 5218 | tsf = true; |
| 5219 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5220 | ies->len, ies->data)) |
| 5221 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5222 | } |
| 5223 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5224 | if (ies) { |
| 5225 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5226 | goto fail_unlock_rcu; |
| 5227 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5228 | ies->len, ies->data)) |
| 5229 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5230 | } |
| 5231 | rcu_read_unlock(); |
| 5232 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5233 | if (res->beacon_interval && |
| 5234 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5235 | goto nla_put_failure; |
| 5236 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5237 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5238 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5239 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5240 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5241 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5242 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5243 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5244 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5245 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5246 | break; |
| 5247 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5248 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5249 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5250 | break; |
| 5251 | default: |
| 5252 | break; |
| 5253 | } |
| 5254 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5255 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5256 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5257 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5258 | if (intbss == wdev->current_bss && |
| 5259 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5260 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5261 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5262 | break; |
| 5263 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5264 | if (intbss == wdev->current_bss && |
| 5265 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5266 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5267 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5268 | break; |
| 5269 | default: |
| 5270 | break; |
| 5271 | } |
| 5272 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5273 | nla_nest_end(msg, bss); |
| 5274 | |
| 5275 | return genlmsg_end(msg, hdr); |
| 5276 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5277 | fail_unlock_rcu: |
| 5278 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5279 | nla_put_failure: |
| 5280 | genlmsg_cancel(msg, hdr); |
| 5281 | return -EMSGSIZE; |
| 5282 | } |
| 5283 | |
| 5284 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5285 | struct netlink_callback *cb) |
| 5286 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5287 | struct cfg80211_registered_device *rdev; |
| 5288 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5289 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5290 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5291 | int start = cb->args[1], idx = 0; |
| 5292 | int err; |
| 5293 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5294 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5295 | if (err) |
| 5296 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5297 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5298 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5299 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5300 | wdev_lock(wdev); |
| 5301 | spin_lock_bh(&rdev->bss_lock); |
| 5302 | cfg80211_bss_expire(rdev); |
| 5303 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5304 | cb->seq = rdev->bss_generation; |
| 5305 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5306 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5307 | if (++idx <= start) |
| 5308 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5309 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5310 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5311 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5312 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5313 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5314 | } |
| 5315 | } |
| 5316 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5317 | spin_unlock_bh(&rdev->bss_lock); |
| 5318 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5319 | |
| 5320 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5321 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5323 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5324 | } |
| 5325 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5326 | 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] | 5327 | int flags, struct net_device *dev, |
| 5328 | struct survey_info *survey) |
| 5329 | { |
| 5330 | void *hdr; |
| 5331 | struct nlattr *infoattr; |
| 5332 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5333 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5334 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5335 | if (!hdr) |
| 5336 | return -ENOMEM; |
| 5337 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5338 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5339 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5340 | |
| 5341 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5342 | if (!infoattr) |
| 5343 | goto nla_put_failure; |
| 5344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5345 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5346 | survey->channel->center_freq)) |
| 5347 | goto nla_put_failure; |
| 5348 | |
| 5349 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5350 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5351 | goto nla_put_failure; |
| 5352 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5353 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5354 | goto nla_put_failure; |
| 5355 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5356 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5357 | survey->channel_time)) |
| 5358 | goto nla_put_failure; |
| 5359 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5360 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5361 | survey->channel_time_busy)) |
| 5362 | goto nla_put_failure; |
| 5363 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5364 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5365 | survey->channel_time_ext_busy)) |
| 5366 | goto nla_put_failure; |
| 5367 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5368 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5369 | survey->channel_time_rx)) |
| 5370 | goto nla_put_failure; |
| 5371 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5372 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5373 | survey->channel_time_tx)) |
| 5374 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5375 | |
| 5376 | nla_nest_end(msg, infoattr); |
| 5377 | |
| 5378 | return genlmsg_end(msg, hdr); |
| 5379 | |
| 5380 | nla_put_failure: |
| 5381 | genlmsg_cancel(msg, hdr); |
| 5382 | return -EMSGSIZE; |
| 5383 | } |
| 5384 | |
| 5385 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5386 | struct netlink_callback *cb) |
| 5387 | { |
| 5388 | struct survey_info survey; |
| 5389 | struct cfg80211_registered_device *dev; |
| 5390 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5391 | int survey_idx = cb->args[1]; |
| 5392 | int res; |
| 5393 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5394 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5395 | if (res) |
| 5396 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5397 | |
| 5398 | if (!dev->ops->dump_survey) { |
| 5399 | res = -EOPNOTSUPP; |
| 5400 | goto out_err; |
| 5401 | } |
| 5402 | |
| 5403 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5404 | struct ieee80211_channel *chan; |
| 5405 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5406 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5407 | if (res == -ENOENT) |
| 5408 | break; |
| 5409 | if (res) |
| 5410 | goto out_err; |
| 5411 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5412 | /* Survey without a channel doesn't make sense */ |
| 5413 | if (!survey.channel) { |
| 5414 | res = -EINVAL; |
| 5415 | goto out; |
| 5416 | } |
| 5417 | |
| 5418 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5419 | survey.channel->center_freq); |
| 5420 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5421 | survey_idx++; |
| 5422 | continue; |
| 5423 | } |
| 5424 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5425 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5426 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5427 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5428 | netdev, |
| 5429 | &survey) < 0) |
| 5430 | goto out; |
| 5431 | survey_idx++; |
| 5432 | } |
| 5433 | |
| 5434 | out: |
| 5435 | cb->args[1] = survey_idx; |
| 5436 | res = skb->len; |
| 5437 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5438 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5439 | return res; |
| 5440 | } |
| 5441 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5442 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5443 | { |
| 5444 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5445 | NL80211_WPA_VERSION_2)); |
| 5446 | } |
| 5447 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5448 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5449 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5450 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5451 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5452 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5453 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5454 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5455 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5456 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5457 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5458 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5459 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5460 | return -EINVAL; |
| 5461 | |
| 5462 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5463 | return -EINVAL; |
| 5464 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5465 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5466 | return -EINVAL; |
| 5467 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5468 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5469 | return -EINVAL; |
| 5470 | |
| 5471 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5472 | return -EINVAL; |
| 5473 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5474 | err = nl80211_parse_key(info, &key); |
| 5475 | if (err) |
| 5476 | return err; |
| 5477 | |
| 5478 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5479 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5480 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5481 | if (!key.p.key || !key.p.key_len) |
| 5482 | return -EINVAL; |
| 5483 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5484 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5485 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5486 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5487 | return -EINVAL; |
| 5488 | if (key.idx > 4) |
| 5489 | return -EINVAL; |
| 5490 | } else { |
| 5491 | key.p.key_len = 0; |
| 5492 | key.p.key = NULL; |
| 5493 | } |
| 5494 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5495 | if (key.idx >= 0) { |
| 5496 | int i; |
| 5497 | bool ok = false; |
| 5498 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5499 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5500 | ok = true; |
| 5501 | break; |
| 5502 | } |
| 5503 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5504 | if (!ok) |
| 5505 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5506 | } |
| 5507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5508 | if (!rdev->ops->auth) |
| 5509 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5510 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5511 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5512 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5513 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5514 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5515 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5516 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5517 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5518 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5519 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5520 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5521 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5522 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5523 | |
| 5524 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5525 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5526 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5527 | } |
| 5528 | |
| 5529 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5530 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5531 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5532 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5533 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5534 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5535 | return -EINVAL; |
| 5536 | |
| 5537 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5538 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5539 | return -EINVAL; |
| 5540 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5541 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5542 | /* need to include at least Auth Transaction and Status Code */ |
| 5543 | if (sae_data_len < 4) |
| 5544 | return -EINVAL; |
| 5545 | } |
| 5546 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5547 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5548 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5549 | /* |
| 5550 | * Since we no longer track auth state, ignore |
| 5551 | * requests to only change local state. |
| 5552 | */ |
| 5553 | if (local_state_change) |
| 5554 | return 0; |
| 5555 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5556 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5557 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5558 | key.p.key, key.p.key_len, key.idx, |
| 5559 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5560 | } |
| 5561 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5562 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5563 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5564 | struct cfg80211_crypto_settings *settings, |
| 5565 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5566 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5567 | memset(settings, 0, sizeof(*settings)); |
| 5568 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5569 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5570 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5571 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5572 | u16 proto; |
| 5573 | proto = nla_get_u16( |
| 5574 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5575 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5576 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5577 | proto != ETH_P_PAE) |
| 5578 | return -EINVAL; |
| 5579 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5580 | settings->control_port_no_encrypt = true; |
| 5581 | } else |
| 5582 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5583 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5584 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5585 | void *data; |
| 5586 | int len, i; |
| 5587 | |
| 5588 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5589 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5590 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5591 | |
| 5592 | if (len % sizeof(u32)) |
| 5593 | return -EINVAL; |
| 5594 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5595 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5596 | return -EINVAL; |
| 5597 | |
| 5598 | memcpy(settings->ciphers_pairwise, data, len); |
| 5599 | |
| 5600 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5601 | if (!cfg80211_supported_cipher_suite( |
| 5602 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5603 | settings->ciphers_pairwise[i])) |
| 5604 | return -EINVAL; |
| 5605 | } |
| 5606 | |
| 5607 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5608 | settings->cipher_group = |
| 5609 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5610 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5611 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5612 | return -EINVAL; |
| 5613 | } |
| 5614 | |
| 5615 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5616 | settings->wpa_versions = |
| 5617 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5618 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5619 | return -EINVAL; |
| 5620 | } |
| 5621 | |
| 5622 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5623 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5624 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5625 | |
| 5626 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5627 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5628 | settings->n_akm_suites = len / sizeof(u32); |
| 5629 | |
| 5630 | if (len % sizeof(u32)) |
| 5631 | return -EINVAL; |
| 5632 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5633 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5634 | return -EINVAL; |
| 5635 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5636 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | return 0; |
| 5640 | } |
| 5641 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5642 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5643 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5645 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5646 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5647 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5648 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5649 | int err, ssid_len, ie_len = 0; |
| 5650 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5651 | u32 flags = 0; |
| 5652 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5653 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5654 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5655 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5656 | return -EINVAL; |
| 5657 | |
| 5658 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5659 | !info->attrs[NL80211_ATTR_SSID] || |
| 5660 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5661 | return -EINVAL; |
| 5662 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5663 | if (!rdev->ops->assoc) |
| 5664 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5665 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5666 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5667 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5668 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5669 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5670 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5671 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5672 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5673 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5674 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5675 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5676 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5677 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5678 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5679 | |
| 5680 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5681 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5682 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5683 | } |
| 5684 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5685 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5686 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5687 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5688 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5689 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5690 | else if (mfp != NL80211_MFP_NO) |
| 5691 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5692 | } |
| 5693 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5694 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5695 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5696 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5697 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5698 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5699 | |
| 5700 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5701 | ht_capa_mask = |
| 5702 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5703 | |
| 5704 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5705 | if (!ht_capa_mask) |
| 5706 | return -EINVAL; |
| 5707 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5708 | } |
| 5709 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5710 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5711 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5712 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5713 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5714 | &crypto, flags, ht_capa, |
| 5715 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5716 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5717 | return err; |
| 5718 | } |
| 5719 | |
| 5720 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5721 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5723 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5724 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5725 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5726 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5727 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5728 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5729 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5730 | return -EINVAL; |
| 5731 | |
| 5732 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5733 | return -EINVAL; |
| 5734 | |
| 5735 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5736 | return -EINVAL; |
| 5737 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5738 | if (!rdev->ops->deauth) |
| 5739 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5740 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5742 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5743 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5744 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5745 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5746 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5747 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5748 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5749 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5750 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5751 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5752 | |
| 5753 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5754 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5755 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5756 | } |
| 5757 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5758 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5760 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5761 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5765 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5767 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5768 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5769 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5770 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5771 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5772 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5773 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5774 | return -EINVAL; |
| 5775 | |
| 5776 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5777 | return -EINVAL; |
| 5778 | |
| 5779 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5780 | return -EINVAL; |
| 5781 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5782 | if (!rdev->ops->disassoc) |
| 5783 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5784 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5785 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5786 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5787 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5788 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5789 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5790 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5791 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5792 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5793 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5794 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5795 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5796 | |
| 5797 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5798 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5799 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5800 | } |
| 5801 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5802 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5804 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5805 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5806 | } |
| 5807 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5808 | static bool |
| 5809 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5810 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5811 | int rateval) |
| 5812 | { |
| 5813 | struct wiphy *wiphy = &rdev->wiphy; |
| 5814 | bool found = false; |
| 5815 | int band, i; |
| 5816 | |
| 5817 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5818 | struct ieee80211_supported_band *sband; |
| 5819 | |
| 5820 | sband = wiphy->bands[band]; |
| 5821 | if (!sband) |
| 5822 | continue; |
| 5823 | |
| 5824 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5825 | if (sband->bitrates[i].bitrate == rateval) { |
| 5826 | mcast_rate[band] = i + 1; |
| 5827 | found = true; |
| 5828 | break; |
| 5829 | } |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | return found; |
| 5834 | } |
| 5835 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5836 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5837 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5839 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5840 | struct cfg80211_ibss_params ibss; |
| 5841 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5842 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5843 | int err; |
| 5844 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5845 | memset(&ibss, 0, sizeof(ibss)); |
| 5846 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5847 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5848 | return -EINVAL; |
| 5849 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5850 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5851 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5852 | return -EINVAL; |
| 5853 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5854 | ibss.beacon_interval = 100; |
| 5855 | |
| 5856 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5857 | ibss.beacon_interval = |
| 5858 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5859 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5860 | return -EINVAL; |
| 5861 | } |
| 5862 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5863 | if (!rdev->ops->join_ibss) |
| 5864 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5865 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5866 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5867 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5868 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5869 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5870 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5871 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5872 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5873 | |
| 5874 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5875 | return -EINVAL; |
| 5876 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5877 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5878 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5879 | |
| 5880 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5881 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5882 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5883 | } |
| 5884 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5885 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5886 | if (err) |
| 5887 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5888 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5889 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5890 | return -EINVAL; |
| 5891 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5892 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5893 | return -EINVAL; |
| 5894 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5895 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5896 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5897 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5898 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5899 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5900 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5901 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5902 | u8 *rates = |
| 5903 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5904 | int n_rates = |
| 5905 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5906 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5907 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5908 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5909 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5910 | &ibss.basic_rates); |
| 5911 | if (err) |
| 5912 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5913 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5914 | |
| 5915 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5916 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5917 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5918 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5920 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5921 | bool no_ht = false; |
| 5922 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5923 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5924 | info->attrs[NL80211_ATTR_KEYS], |
| 5925 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5926 | if (IS_ERR(connkeys)) |
| 5927 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5928 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5929 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5930 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5931 | kfree(connkeys); |
| 5932 | return -EINVAL; |
| 5933 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5934 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5935 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5936 | ibss.control_port = |
| 5937 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5938 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5939 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5940 | if (err) |
| 5941 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5942 | return err; |
| 5943 | } |
| 5944 | |
| 5945 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5946 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5947 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5948 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5949 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5950 | if (!rdev->ops->leave_ibss) |
| 5951 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5953 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5954 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5955 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5956 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5957 | } |
| 5958 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5959 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5960 | { |
| 5961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5962 | struct net_device *dev = info->user_ptr[1]; |
| 5963 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5964 | u32 nla_rate; |
| 5965 | int err; |
| 5966 | |
| 5967 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5968 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5969 | return -EOPNOTSUPP; |
| 5970 | |
| 5971 | if (!rdev->ops->set_mcast_rate) |
| 5972 | return -EOPNOTSUPP; |
| 5973 | |
| 5974 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5975 | |
| 5976 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5977 | return -EINVAL; |
| 5978 | |
| 5979 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5980 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5981 | return -EINVAL; |
| 5982 | |
| 5983 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5984 | |
| 5985 | return err; |
| 5986 | } |
| 5987 | |
| 5988 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5989 | #ifdef CONFIG_NL80211_TESTMODE |
| 5990 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5991 | .name = "testmode", |
| 5992 | }; |
| 5993 | |
| 5994 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5995 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5996 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5997 | int err; |
| 5998 | |
| 5999 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6000 | return -EINVAL; |
| 6001 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6002 | err = -EOPNOTSUPP; |
| 6003 | if (rdev->ops->testmode_cmd) { |
| 6004 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6005 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6006 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6007 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6008 | rdev->testmode_info = NULL; |
| 6009 | } |
| 6010 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6011 | return err; |
| 6012 | } |
| 6013 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6014 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6015 | struct netlink_callback *cb) |
| 6016 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6017 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6018 | int err; |
| 6019 | long phy_idx; |
| 6020 | void *data = NULL; |
| 6021 | int data_len = 0; |
| 6022 | |
| 6023 | if (cb->args[0]) { |
| 6024 | /* |
| 6025 | * 0 is a valid index, but not valid for args[0], |
| 6026 | * so we need to offset by 1. |
| 6027 | */ |
| 6028 | phy_idx = cb->args[0] - 1; |
| 6029 | } else { |
| 6030 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6031 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6032 | nl80211_policy); |
| 6033 | if (err) |
| 6034 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6035 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6036 | mutex_lock(&cfg80211_mutex); |
| 6037 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6038 | nl80211_fam.attrbuf); |
| 6039 | if (IS_ERR(rdev)) { |
| 6040 | mutex_unlock(&cfg80211_mutex); |
| 6041 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6042 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6043 | phy_idx = rdev->wiphy_idx; |
| 6044 | rdev = NULL; |
| 6045 | mutex_unlock(&cfg80211_mutex); |
| 6046 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6047 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6048 | cb->args[1] = |
| 6049 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6050 | } |
| 6051 | |
| 6052 | if (cb->args[1]) { |
| 6053 | data = nla_data((void *)cb->args[1]); |
| 6054 | data_len = nla_len((void *)cb->args[1]); |
| 6055 | } |
| 6056 | |
| 6057 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6058 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6059 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6060 | mutex_unlock(&cfg80211_mutex); |
| 6061 | return -ENOENT; |
| 6062 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6063 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6064 | mutex_unlock(&cfg80211_mutex); |
| 6065 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6066 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6067 | err = -EOPNOTSUPP; |
| 6068 | goto out_err; |
| 6069 | } |
| 6070 | |
| 6071 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6072 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6073 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6074 | NL80211_CMD_TESTMODE); |
| 6075 | struct nlattr *tmdata; |
| 6076 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6077 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6078 | genlmsg_cancel(skb, hdr); |
| 6079 | break; |
| 6080 | } |
| 6081 | |
| 6082 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6083 | if (!tmdata) { |
| 6084 | genlmsg_cancel(skb, hdr); |
| 6085 | break; |
| 6086 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6087 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6088 | nla_nest_end(skb, tmdata); |
| 6089 | |
| 6090 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6091 | genlmsg_cancel(skb, hdr); |
| 6092 | break; |
| 6093 | } else if (err) { |
| 6094 | genlmsg_cancel(skb, hdr); |
| 6095 | goto out_err; |
| 6096 | } |
| 6097 | |
| 6098 | genlmsg_end(skb, hdr); |
| 6099 | } |
| 6100 | |
| 6101 | err = skb->len; |
| 6102 | /* see above */ |
| 6103 | cb->args[0] = phy_idx + 1; |
| 6104 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6105 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6106 | return err; |
| 6107 | } |
| 6108 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6109 | static struct sk_buff * |
| 6110 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6111 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6112 | { |
| 6113 | struct sk_buff *skb; |
| 6114 | void *hdr; |
| 6115 | struct nlattr *data; |
| 6116 | |
| 6117 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6118 | if (!skb) |
| 6119 | return NULL; |
| 6120 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6121 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6122 | if (!hdr) { |
| 6123 | kfree_skb(skb); |
| 6124 | return NULL; |
| 6125 | } |
| 6126 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6127 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6128 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6129 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6130 | |
| 6131 | ((void **)skb->cb)[0] = rdev; |
| 6132 | ((void **)skb->cb)[1] = hdr; |
| 6133 | ((void **)skb->cb)[2] = data; |
| 6134 | |
| 6135 | return skb; |
| 6136 | |
| 6137 | nla_put_failure: |
| 6138 | kfree_skb(skb); |
| 6139 | return NULL; |
| 6140 | } |
| 6141 | |
| 6142 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6143 | int approxlen) |
| 6144 | { |
| 6145 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6146 | |
| 6147 | if (WARN_ON(!rdev->testmode_info)) |
| 6148 | return NULL; |
| 6149 | |
| 6150 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6151 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6152 | rdev->testmode_info->snd_seq, |
| 6153 | GFP_KERNEL); |
| 6154 | } |
| 6155 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6156 | |
| 6157 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6158 | { |
| 6159 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6160 | void *hdr = ((void **)skb->cb)[1]; |
| 6161 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6162 | |
| 6163 | if (WARN_ON(!rdev->testmode_info)) { |
| 6164 | kfree_skb(skb); |
| 6165 | return -EINVAL; |
| 6166 | } |
| 6167 | |
| 6168 | nla_nest_end(skb, data); |
| 6169 | genlmsg_end(skb, hdr); |
| 6170 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6171 | } |
| 6172 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6173 | |
| 6174 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6175 | int approxlen, gfp_t gfp) |
| 6176 | { |
| 6177 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6178 | |
| 6179 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6180 | } |
| 6181 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6182 | |
| 6183 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6184 | { |
| 6185 | void *hdr = ((void **)skb->cb)[1]; |
| 6186 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6187 | |
| 6188 | nla_nest_end(skb, data); |
| 6189 | genlmsg_end(skb, hdr); |
| 6190 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6191 | } |
| 6192 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6193 | #endif |
| 6194 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6195 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6196 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6198 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6199 | struct cfg80211_connect_params connect; |
| 6200 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6201 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6202 | int err; |
| 6203 | |
| 6204 | memset(&connect, 0, sizeof(connect)); |
| 6205 | |
| 6206 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6207 | return -EINVAL; |
| 6208 | |
| 6209 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6210 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6211 | return -EINVAL; |
| 6212 | |
| 6213 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6214 | connect.auth_type = |
| 6215 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6216 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6217 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6218 | return -EINVAL; |
| 6219 | } else |
| 6220 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6221 | |
| 6222 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6223 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6224 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6225 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6226 | if (err) |
| 6227 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6228 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6229 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6230 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6231 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6232 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6233 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6234 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6235 | connect.bg_scan_period = -1; |
| 6236 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6237 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6238 | connect.bg_scan_period = |
| 6239 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6240 | } |
| 6241 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6242 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6243 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6244 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6245 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6246 | |
| 6247 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6248 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6249 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6250 | } |
| 6251 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6252 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6253 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6254 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6255 | connect.mfp != NL80211_MFP_NO) |
| 6256 | return -EINVAL; |
| 6257 | } else { |
| 6258 | connect.mfp = NL80211_MFP_NO; |
| 6259 | } |
| 6260 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6261 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6262 | connect.channel = |
| 6263 | ieee80211_get_channel(wiphy, |
| 6264 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6265 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6266 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6267 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6268 | } |
| 6269 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6270 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6271 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6272 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6273 | if (IS_ERR(connkeys)) |
| 6274 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6275 | } |
| 6276 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6277 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6278 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6279 | |
| 6280 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6281 | memcpy(&connect.ht_capa_mask, |
| 6282 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6283 | sizeof(connect.ht_capa_mask)); |
| 6284 | |
| 6285 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6286 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6287 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6288 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6289 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6290 | memcpy(&connect.ht_capa, |
| 6291 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6292 | sizeof(connect.ht_capa)); |
| 6293 | } |
| 6294 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6295 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6296 | if (err) |
| 6297 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6298 | return err; |
| 6299 | } |
| 6300 | |
| 6301 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6302 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6304 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6305 | u16 reason; |
| 6306 | |
| 6307 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6308 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6309 | else |
| 6310 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6311 | |
| 6312 | if (reason == 0) |
| 6313 | return -EINVAL; |
| 6314 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6315 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6316 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6317 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6318 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6319 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6320 | } |
| 6321 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6322 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6323 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6325 | struct net *net; |
| 6326 | int err; |
| 6327 | u32 pid; |
| 6328 | |
| 6329 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6330 | return -EINVAL; |
| 6331 | |
| 6332 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6333 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6334 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6335 | if (IS_ERR(net)) |
| 6336 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6337 | |
| 6338 | err = 0; |
| 6339 | |
| 6340 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6341 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6342 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6343 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6344 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6345 | return err; |
| 6346 | } |
| 6347 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6348 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6349 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6351 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6352 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6353 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6354 | struct cfg80211_pmksa pmksa; |
| 6355 | |
| 6356 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6357 | |
| 6358 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6359 | return -EINVAL; |
| 6360 | |
| 6361 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6362 | return -EINVAL; |
| 6363 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6364 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6365 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6366 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6367 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6368 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6369 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6370 | |
| 6371 | switch (info->genlhdr->cmd) { |
| 6372 | case NL80211_CMD_SET_PMKSA: |
| 6373 | rdev_ops = rdev->ops->set_pmksa; |
| 6374 | break; |
| 6375 | case NL80211_CMD_DEL_PMKSA: |
| 6376 | rdev_ops = rdev->ops->del_pmksa; |
| 6377 | break; |
| 6378 | default: |
| 6379 | WARN_ON(1); |
| 6380 | break; |
| 6381 | } |
| 6382 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6383 | if (!rdev_ops) |
| 6384 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6385 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6386 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6392 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6393 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6394 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6395 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6396 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6397 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6398 | if (!rdev->ops->flush_pmksa) |
| 6399 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6400 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6401 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6402 | } |
| 6403 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6404 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6405 | { |
| 6406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6407 | struct net_device *dev = info->user_ptr[1]; |
| 6408 | u8 action_code, dialog_token; |
| 6409 | u16 status_code; |
| 6410 | u8 *peer; |
| 6411 | |
| 6412 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6413 | !rdev->ops->tdls_mgmt) |
| 6414 | return -EOPNOTSUPP; |
| 6415 | |
| 6416 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6417 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6418 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6419 | !info->attrs[NL80211_ATTR_IE] || |
| 6420 | !info->attrs[NL80211_ATTR_MAC]) |
| 6421 | return -EINVAL; |
| 6422 | |
| 6423 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6424 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6425 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6426 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6427 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6428 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6429 | dialog_token, status_code, |
| 6430 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6431 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6432 | } |
| 6433 | |
| 6434 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6435 | { |
| 6436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6437 | struct net_device *dev = info->user_ptr[1]; |
| 6438 | enum nl80211_tdls_operation operation; |
| 6439 | u8 *peer; |
| 6440 | |
| 6441 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6442 | !rdev->ops->tdls_oper) |
| 6443 | return -EOPNOTSUPP; |
| 6444 | |
| 6445 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6446 | !info->attrs[NL80211_ATTR_MAC]) |
| 6447 | return -EINVAL; |
| 6448 | |
| 6449 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6450 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6451 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6452 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6453 | } |
| 6454 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6455 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6456 | struct genl_info *info) |
| 6457 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6459 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6460 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6461 | struct sk_buff *msg; |
| 6462 | void *hdr; |
| 6463 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6464 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6465 | int err; |
| 6466 | |
| 6467 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6468 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6469 | return -EINVAL; |
| 6470 | |
| 6471 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6472 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6473 | if (!rdev->ops->remain_on_channel || |
| 6474 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6475 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6476 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6477 | /* |
| 6478 | * We should be on that channel for at least a minimum amount of |
| 6479 | * time (10ms) but no longer than the driver supports. |
| 6480 | */ |
| 6481 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6482 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6483 | return -EINVAL; |
| 6484 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6485 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6486 | if (err) |
| 6487 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6488 | |
| 6489 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6490 | if (!msg) |
| 6491 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6492 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6493 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6494 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6495 | |
| 6496 | if (IS_ERR(hdr)) { |
| 6497 | err = PTR_ERR(hdr); |
| 6498 | goto free_msg; |
| 6499 | } |
| 6500 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6501 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6502 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6503 | |
| 6504 | if (err) |
| 6505 | goto free_msg; |
| 6506 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6507 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6508 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6509 | |
| 6510 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6511 | |
| 6512 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6513 | |
| 6514 | nla_put_failure: |
| 6515 | err = -ENOBUFS; |
| 6516 | free_msg: |
| 6517 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6518 | return err; |
| 6519 | } |
| 6520 | |
| 6521 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6522 | struct genl_info *info) |
| 6523 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6525 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6526 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6527 | |
| 6528 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6529 | return -EINVAL; |
| 6530 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6531 | if (!rdev->ops->cancel_remain_on_channel) |
| 6532 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6533 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6534 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6535 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6536 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6537 | } |
| 6538 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6539 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6540 | u8 *rates, u8 rates_len) |
| 6541 | { |
| 6542 | u8 i; |
| 6543 | u32 mask = 0; |
| 6544 | |
| 6545 | for (i = 0; i < rates_len; i++) { |
| 6546 | int rate = (rates[i] & 0x7f) * 5; |
| 6547 | int ridx; |
| 6548 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6549 | struct ieee80211_rate *srate = |
| 6550 | &sband->bitrates[ridx]; |
| 6551 | if (rate == srate->bitrate) { |
| 6552 | mask |= 1 << ridx; |
| 6553 | break; |
| 6554 | } |
| 6555 | } |
| 6556 | if (ridx == sband->n_bitrates) |
| 6557 | return 0; /* rate not found */ |
| 6558 | } |
| 6559 | |
| 6560 | return mask; |
| 6561 | } |
| 6562 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6563 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6564 | u8 *rates, u8 rates_len, |
| 6565 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6566 | { |
| 6567 | u8 i; |
| 6568 | |
| 6569 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6570 | |
| 6571 | for (i = 0; i < rates_len; i++) { |
| 6572 | int ridx, rbit; |
| 6573 | |
| 6574 | ridx = rates[i] / 8; |
| 6575 | rbit = BIT(rates[i] % 8); |
| 6576 | |
| 6577 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6578 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6579 | return false; |
| 6580 | |
| 6581 | /* check availability */ |
| 6582 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6583 | mcs[ridx] |= rbit; |
| 6584 | else |
| 6585 | return false; |
| 6586 | } |
| 6587 | |
| 6588 | return true; |
| 6589 | } |
| 6590 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6591 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6592 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6593 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6594 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6595 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6596 | }; |
| 6597 | |
| 6598 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6599 | struct genl_info *info) |
| 6600 | { |
| 6601 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6603 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6604 | int rem, i; |
| 6605 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6606 | struct nlattr *tx_rates; |
| 6607 | struct ieee80211_supported_band *sband; |
| 6608 | |
| 6609 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6610 | return -EINVAL; |
| 6611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6612 | if (!rdev->ops->set_bitrate_mask) |
| 6613 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6614 | |
| 6615 | memset(&mask, 0, sizeof(mask)); |
| 6616 | /* Default to all rates enabled */ |
| 6617 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6618 | sband = rdev->wiphy.bands[i]; |
| 6619 | mask.control[i].legacy = |
| 6620 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6621 | if (sband) |
| 6622 | memcpy(mask.control[i].mcs, |
| 6623 | sband->ht_cap.mcs.rx_mask, |
| 6624 | sizeof(mask.control[i].mcs)); |
| 6625 | else |
| 6626 | memset(mask.control[i].mcs, 0, |
| 6627 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | /* |
| 6631 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6632 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6633 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6634 | 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] | 6635 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6636 | { |
| 6637 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6638 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6639 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6640 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6641 | if (sband == NULL) |
| 6642 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6643 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6644 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6645 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6646 | mask.control[band].legacy = rateset_to_mask( |
| 6647 | sband, |
| 6648 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6649 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6650 | if ((mask.control[band].legacy == 0) && |
| 6651 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6652 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6653 | } |
| 6654 | if (tb[NL80211_TXRATE_MCS]) { |
| 6655 | if (!ht_rateset_to_mask( |
| 6656 | sband, |
| 6657 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6658 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6659 | mask.control[band].mcs)) |
| 6660 | return -EINVAL; |
| 6661 | } |
| 6662 | |
| 6663 | if (mask.control[band].legacy == 0) { |
| 6664 | /* don't allow empty legacy rates if HT |
| 6665 | * is not even supported. */ |
| 6666 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6667 | return -EINVAL; |
| 6668 | |
| 6669 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6670 | if (mask.control[band].mcs[i]) |
| 6671 | break; |
| 6672 | |
| 6673 | /* legacy and mcs rates may not be both empty */ |
| 6674 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6675 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6676 | } |
| 6677 | } |
| 6678 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6679 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6680 | } |
| 6681 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6682 | 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] | 6683 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6685 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6686 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6687 | |
| 6688 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6689 | return -EINVAL; |
| 6690 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6691 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6692 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6693 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6694 | switch (wdev->iftype) { |
| 6695 | case NL80211_IFTYPE_STATION: |
| 6696 | case NL80211_IFTYPE_ADHOC: |
| 6697 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6698 | case NL80211_IFTYPE_AP: |
| 6699 | case NL80211_IFTYPE_AP_VLAN: |
| 6700 | case NL80211_IFTYPE_MESH_POINT: |
| 6701 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6702 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6703 | break; |
| 6704 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6705 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6706 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6707 | |
| 6708 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6709 | if (!rdev->ops->mgmt_tx) |
| 6710 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6711 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6712 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6713 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6714 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6715 | } |
| 6716 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6717 | 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] | 6718 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6720 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6721 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6722 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6723 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6724 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6725 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6726 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6727 | bool offchan, no_cck, dont_wait_for_ack; |
| 6728 | |
| 6729 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6730 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6731 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6732 | return -EINVAL; |
| 6733 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6734 | if (!rdev->ops->mgmt_tx) |
| 6735 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6736 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6737 | switch (wdev->iftype) { |
| 6738 | case NL80211_IFTYPE_STATION: |
| 6739 | case NL80211_IFTYPE_ADHOC: |
| 6740 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6741 | case NL80211_IFTYPE_AP: |
| 6742 | case NL80211_IFTYPE_AP_VLAN: |
| 6743 | case NL80211_IFTYPE_MESH_POINT: |
| 6744 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6745 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6746 | break; |
| 6747 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6748 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6749 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6750 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6751 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6752 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6753 | return -EINVAL; |
| 6754 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6755 | |
| 6756 | /* |
| 6757 | * We should wait on the channel for at least a minimum amount |
| 6758 | * of time (10ms) but no longer than the driver supports. |
| 6759 | */ |
| 6760 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6761 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6762 | return -EINVAL; |
| 6763 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6764 | } |
| 6765 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6766 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6767 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6768 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6769 | return -EINVAL; |
| 6770 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6771 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6772 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6773 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6774 | if (err) |
| 6775 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6776 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6777 | if (!dont_wait_for_ack) { |
| 6778 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6779 | if (!msg) |
| 6780 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6781 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6782 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6783 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6784 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6785 | if (IS_ERR(hdr)) { |
| 6786 | err = PTR_ERR(hdr); |
| 6787 | goto free_msg; |
| 6788 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6789 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6790 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6791 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6792 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6793 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6794 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6795 | if (err) |
| 6796 | goto free_msg; |
| 6797 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6798 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6799 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6800 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6801 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6802 | genlmsg_end(msg, hdr); |
| 6803 | return genlmsg_reply(msg, info); |
| 6804 | } |
| 6805 | |
| 6806 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6807 | |
| 6808 | nla_put_failure: |
| 6809 | err = -ENOBUFS; |
| 6810 | free_msg: |
| 6811 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6812 | return err; |
| 6813 | } |
| 6814 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6815 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6816 | { |
| 6817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6818 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6819 | u64 cookie; |
| 6820 | |
| 6821 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6822 | return -EINVAL; |
| 6823 | |
| 6824 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6825 | return -EOPNOTSUPP; |
| 6826 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6827 | switch (wdev->iftype) { |
| 6828 | case NL80211_IFTYPE_STATION: |
| 6829 | case NL80211_IFTYPE_ADHOC: |
| 6830 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6831 | case NL80211_IFTYPE_AP: |
| 6832 | case NL80211_IFTYPE_AP_VLAN: |
| 6833 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6834 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6835 | break; |
| 6836 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6837 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6838 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6839 | |
| 6840 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6841 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6842 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6843 | } |
| 6844 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6845 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6846 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6848 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6849 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6850 | u8 ps_state; |
| 6851 | bool state; |
| 6852 | int err; |
| 6853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6854 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6855 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6856 | |
| 6857 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6859 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6860 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6861 | |
| 6862 | wdev = dev->ieee80211_ptr; |
| 6863 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6864 | if (!rdev->ops->set_power_mgmt) |
| 6865 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6866 | |
| 6867 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6868 | |
| 6869 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6870 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6871 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6872 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6873 | if (!err) |
| 6874 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6875 | return err; |
| 6876 | } |
| 6877 | |
| 6878 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6879 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6880 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6881 | enum nl80211_ps_state ps_state; |
| 6882 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6883 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6884 | struct sk_buff *msg; |
| 6885 | void *hdr; |
| 6886 | int err; |
| 6887 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6888 | wdev = dev->ieee80211_ptr; |
| 6889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6890 | if (!rdev->ops->set_power_mgmt) |
| 6891 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6892 | |
| 6893 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6894 | if (!msg) |
| 6895 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6896 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6897 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6898 | NL80211_CMD_GET_POWER_SAVE); |
| 6899 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6900 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6901 | goto free_msg; |
| 6902 | } |
| 6903 | |
| 6904 | if (wdev->ps) |
| 6905 | ps_state = NL80211_PS_ENABLED; |
| 6906 | else |
| 6907 | ps_state = NL80211_PS_DISABLED; |
| 6908 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6909 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6910 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6911 | |
| 6912 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6913 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6914 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6915 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6916 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6917 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6918 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6919 | return err; |
| 6920 | } |
| 6921 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6922 | static struct nla_policy |
| 6923 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6924 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6925 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6926 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6927 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6928 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6929 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6930 | }; |
| 6931 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6932 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6933 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6934 | { |
| 6935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6936 | struct wireless_dev *wdev; |
| 6937 | struct net_device *dev = info->user_ptr[1]; |
| 6938 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6939 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6940 | return -EINVAL; |
| 6941 | |
| 6942 | wdev = dev->ieee80211_ptr; |
| 6943 | |
| 6944 | if (!rdev->ops->set_cqm_txe_config) |
| 6945 | return -EOPNOTSUPP; |
| 6946 | |
| 6947 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6948 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6949 | return -EOPNOTSUPP; |
| 6950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6951 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6954 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6955 | s32 threshold, u32 hysteresis) |
| 6956 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6958 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6959 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6960 | |
| 6961 | if (threshold > 0) |
| 6962 | return -EINVAL; |
| 6963 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6964 | wdev = dev->ieee80211_ptr; |
| 6965 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6966 | if (!rdev->ops->set_cqm_rssi_config) |
| 6967 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6968 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6969 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6970 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6971 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6972 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6973 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6974 | } |
| 6975 | |
| 6976 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6977 | { |
| 6978 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6979 | struct nlattr *cqm; |
| 6980 | int err; |
| 6981 | |
| 6982 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6983 | if (!cqm) { |
| 6984 | err = -EINVAL; |
| 6985 | goto out; |
| 6986 | } |
| 6987 | |
| 6988 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6989 | nl80211_attr_cqm_policy); |
| 6990 | if (err) |
| 6991 | goto out; |
| 6992 | |
| 6993 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6994 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6995 | s32 threshold; |
| 6996 | u32 hysteresis; |
| 6997 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6998 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6999 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7000 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7001 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7002 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7003 | u32 rate, pkts, intvl; |
| 7004 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7005 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7006 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7007 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7008 | } else |
| 7009 | err = -EINVAL; |
| 7010 | |
| 7011 | out: |
| 7012 | return err; |
| 7013 | } |
| 7014 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7015 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7016 | { |
| 7017 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7018 | struct net_device *dev = info->user_ptr[1]; |
| 7019 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7020 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7021 | int err; |
| 7022 | |
| 7023 | /* start with default */ |
| 7024 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7025 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7026 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7027 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7028 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7029 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7030 | if (err) |
| 7031 | return err; |
| 7032 | } |
| 7033 | |
| 7034 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7035 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7036 | return -EINVAL; |
| 7037 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7038 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7039 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7040 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7041 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7042 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7043 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7044 | return -EINVAL; |
| 7045 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7046 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7047 | setup.beacon_interval = |
| 7048 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7049 | if (setup.beacon_interval < 10 || |
| 7050 | setup.beacon_interval > 10000) |
| 7051 | return -EINVAL; |
| 7052 | } |
| 7053 | |
| 7054 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7055 | setup.dtim_period = |
| 7056 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7057 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7058 | return -EINVAL; |
| 7059 | } |
| 7060 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7061 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7062 | /* parse additional setup parameters if given */ |
| 7063 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7064 | if (err) |
| 7065 | return err; |
| 7066 | } |
| 7067 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7068 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7069 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7070 | if (err) |
| 7071 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7072 | } else { |
| 7073 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7074 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7075 | } |
| 7076 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7077 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7081 | { |
| 7082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7083 | struct net_device *dev = info->user_ptr[1]; |
| 7084 | |
| 7085 | return cfg80211_leave_mesh(rdev, dev); |
| 7086 | } |
| 7087 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7088 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7089 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7090 | struct cfg80211_registered_device *rdev) |
| 7091 | { |
| 7092 | struct nlattr *nl_pats, *nl_pat; |
| 7093 | int i, pat_len; |
| 7094 | |
| 7095 | if (!rdev->wowlan->n_patterns) |
| 7096 | return 0; |
| 7097 | |
| 7098 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7099 | if (!nl_pats) |
| 7100 | return -ENOBUFS; |
| 7101 | |
| 7102 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7103 | nl_pat = nla_nest_start(msg, i + 1); |
| 7104 | if (!nl_pat) |
| 7105 | return -ENOBUFS; |
| 7106 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7107 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7108 | DIV_ROUND_UP(pat_len, 8), |
| 7109 | rdev->wowlan->patterns[i].mask) || |
| 7110 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7111 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7112 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7113 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7114 | return -ENOBUFS; |
| 7115 | nla_nest_end(msg, nl_pat); |
| 7116 | } |
| 7117 | nla_nest_end(msg, nl_pats); |
| 7118 | |
| 7119 | return 0; |
| 7120 | } |
| 7121 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7122 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7123 | struct cfg80211_wowlan_tcp *tcp) |
| 7124 | { |
| 7125 | struct nlattr *nl_tcp; |
| 7126 | |
| 7127 | if (!tcp) |
| 7128 | return 0; |
| 7129 | |
| 7130 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7131 | if (!nl_tcp) |
| 7132 | return -ENOBUFS; |
| 7133 | |
| 7134 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7135 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7136 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7137 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7138 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7139 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7140 | tcp->payload_len, tcp->payload) || |
| 7141 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7142 | tcp->data_interval) || |
| 7143 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7144 | tcp->wake_len, tcp->wake_data) || |
| 7145 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7146 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7147 | return -ENOBUFS; |
| 7148 | |
| 7149 | if (tcp->payload_seq.len && |
| 7150 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7151 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7152 | return -ENOBUFS; |
| 7153 | |
| 7154 | if (tcp->payload_tok.len && |
| 7155 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7156 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7157 | &tcp->payload_tok)) |
| 7158 | return -ENOBUFS; |
| 7159 | |
| 7160 | return 0; |
| 7161 | } |
| 7162 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7163 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7164 | { |
| 7165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7166 | struct sk_buff *msg; |
| 7167 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7168 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7169 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7170 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7171 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7172 | return -EOPNOTSUPP; |
| 7173 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7174 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7175 | /* adjust size to have room for all the data */ |
| 7176 | size += rdev->wowlan->tcp->tokens_size + |
| 7177 | rdev->wowlan->tcp->payload_len + |
| 7178 | rdev->wowlan->tcp->wake_len + |
| 7179 | rdev->wowlan->tcp->wake_len / 8; |
| 7180 | } |
| 7181 | |
| 7182 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7183 | if (!msg) |
| 7184 | return -ENOMEM; |
| 7185 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7186 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7187 | NL80211_CMD_GET_WOWLAN); |
| 7188 | if (!hdr) |
| 7189 | goto nla_put_failure; |
| 7190 | |
| 7191 | if (rdev->wowlan) { |
| 7192 | struct nlattr *nl_wowlan; |
| 7193 | |
| 7194 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7195 | if (!nl_wowlan) |
| 7196 | goto nla_put_failure; |
| 7197 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7198 | if ((rdev->wowlan->any && |
| 7199 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7200 | (rdev->wowlan->disconnect && |
| 7201 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7202 | (rdev->wowlan->magic_pkt && |
| 7203 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7204 | (rdev->wowlan->gtk_rekey_failure && |
| 7205 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7206 | (rdev->wowlan->eap_identity_req && |
| 7207 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7208 | (rdev->wowlan->four_way_handshake && |
| 7209 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7210 | (rdev->wowlan->rfkill_release && |
| 7211 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7212 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7213 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7214 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7215 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7216 | |
| 7217 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7218 | goto nla_put_failure; |
| 7219 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7220 | nla_nest_end(msg, nl_wowlan); |
| 7221 | } |
| 7222 | |
| 7223 | genlmsg_end(msg, hdr); |
| 7224 | return genlmsg_reply(msg, info); |
| 7225 | |
| 7226 | nla_put_failure: |
| 7227 | nlmsg_free(msg); |
| 7228 | return -ENOBUFS; |
| 7229 | } |
| 7230 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7231 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7232 | struct nlattr *attr, |
| 7233 | struct cfg80211_wowlan *trig) |
| 7234 | { |
| 7235 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7236 | struct cfg80211_wowlan_tcp *cfg; |
| 7237 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7238 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7239 | u32 size; |
| 7240 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7241 | int err, port; |
| 7242 | |
| 7243 | if (!rdev->wiphy.wowlan.tcp) |
| 7244 | return -EINVAL; |
| 7245 | |
| 7246 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7247 | nla_data(attr), nla_len(attr), |
| 7248 | nl80211_wowlan_tcp_policy); |
| 7249 | if (err) |
| 7250 | return err; |
| 7251 | |
| 7252 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7253 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7254 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7255 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7256 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7257 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7258 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7259 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7260 | return -EINVAL; |
| 7261 | |
| 7262 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7263 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7264 | return -EINVAL; |
| 7265 | |
| 7266 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 7267 | rdev->wiphy.wowlan.tcp->data_interval_max) |
| 7268 | return -EINVAL; |
| 7269 | |
| 7270 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7271 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7272 | return -EINVAL; |
| 7273 | |
| 7274 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7275 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7276 | return -EINVAL; |
| 7277 | |
| 7278 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7279 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7280 | |
| 7281 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7282 | tokens_size = tokln - sizeof(*tok); |
| 7283 | |
| 7284 | if (!tok->len || tokens_size % tok->len) |
| 7285 | return -EINVAL; |
| 7286 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7287 | return -EINVAL; |
| 7288 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7289 | return -EINVAL; |
| 7290 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7291 | return -EINVAL; |
| 7292 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7293 | return -EINVAL; |
| 7294 | if (tok->offset + tok->len > data_size) |
| 7295 | return -EINVAL; |
| 7296 | } |
| 7297 | |
| 7298 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7299 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7300 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7301 | return -EINVAL; |
| 7302 | if (seq->len == 0 || seq->len > 4) |
| 7303 | return -EINVAL; |
| 7304 | if (seq->len + seq->offset > data_size) |
| 7305 | return -EINVAL; |
| 7306 | } |
| 7307 | |
| 7308 | size = sizeof(*cfg); |
| 7309 | size += data_size; |
| 7310 | size += wake_size + wake_mask_size; |
| 7311 | size += tokens_size; |
| 7312 | |
| 7313 | cfg = kzalloc(size, GFP_KERNEL); |
| 7314 | if (!cfg) |
| 7315 | return -ENOMEM; |
| 7316 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7317 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7318 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7319 | ETH_ALEN); |
| 7320 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7321 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7322 | else |
| 7323 | port = 0; |
| 7324 | #ifdef CONFIG_INET |
| 7325 | /* allocate a socket and port for it and use it */ |
| 7326 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7327 | IPPROTO_TCP, &cfg->sock, 1); |
| 7328 | if (err) { |
| 7329 | kfree(cfg); |
| 7330 | return err; |
| 7331 | } |
| 7332 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7333 | sock_release(cfg->sock); |
| 7334 | kfree(cfg); |
| 7335 | return -EADDRINUSE; |
| 7336 | } |
| 7337 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7338 | #else |
| 7339 | if (!port) { |
| 7340 | kfree(cfg); |
| 7341 | return -EINVAL; |
| 7342 | } |
| 7343 | cfg->src_port = port; |
| 7344 | #endif |
| 7345 | |
| 7346 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7347 | cfg->payload_len = data_size; |
| 7348 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7349 | memcpy((void *)cfg->payload, |
| 7350 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7351 | data_size); |
| 7352 | if (seq) |
| 7353 | cfg->payload_seq = *seq; |
| 7354 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7355 | cfg->wake_len = wake_size; |
| 7356 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7357 | memcpy((void *)cfg->wake_data, |
| 7358 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7359 | wake_size); |
| 7360 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7361 | data_size + wake_size; |
| 7362 | memcpy((void *)cfg->wake_mask, |
| 7363 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7364 | wake_mask_size); |
| 7365 | if (tok) { |
| 7366 | cfg->tokens_size = tokens_size; |
| 7367 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7368 | } |
| 7369 | |
| 7370 | trig->tcp = cfg; |
| 7371 | |
| 7372 | return 0; |
| 7373 | } |
| 7374 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7375 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7376 | { |
| 7377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7378 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7379 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7380 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7381 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7382 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7383 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7384 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7385 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7386 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7387 | return -EOPNOTSUPP; |
| 7388 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7389 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7390 | cfg80211_rdev_free_wowlan(rdev); |
| 7391 | rdev->wowlan = NULL; |
| 7392 | goto set_wakeup; |
| 7393 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7394 | |
| 7395 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7396 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7397 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7398 | nl80211_wowlan_policy); |
| 7399 | if (err) |
| 7400 | return err; |
| 7401 | |
| 7402 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7403 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7404 | return -EINVAL; |
| 7405 | new_triggers.any = true; |
| 7406 | } |
| 7407 | |
| 7408 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7409 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7410 | return -EINVAL; |
| 7411 | new_triggers.disconnect = true; |
| 7412 | } |
| 7413 | |
| 7414 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7415 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7416 | return -EINVAL; |
| 7417 | new_triggers.magic_pkt = true; |
| 7418 | } |
| 7419 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7420 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7421 | return -EINVAL; |
| 7422 | |
| 7423 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7424 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7425 | return -EINVAL; |
| 7426 | new_triggers.gtk_rekey_failure = true; |
| 7427 | } |
| 7428 | |
| 7429 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7430 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7431 | return -EINVAL; |
| 7432 | new_triggers.eap_identity_req = true; |
| 7433 | } |
| 7434 | |
| 7435 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7436 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7437 | return -EINVAL; |
| 7438 | new_triggers.four_way_handshake = true; |
| 7439 | } |
| 7440 | |
| 7441 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7442 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7443 | return -EINVAL; |
| 7444 | new_triggers.rfkill_release = true; |
| 7445 | } |
| 7446 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7447 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7448 | struct nlattr *pat; |
| 7449 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7450 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7451 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7452 | |
| 7453 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7454 | rem) |
| 7455 | n_patterns++; |
| 7456 | if (n_patterns > wowlan->n_patterns) |
| 7457 | return -EINVAL; |
| 7458 | |
| 7459 | new_triggers.patterns = kcalloc(n_patterns, |
| 7460 | sizeof(new_triggers.patterns[0]), |
| 7461 | GFP_KERNEL); |
| 7462 | if (!new_triggers.patterns) |
| 7463 | return -ENOMEM; |
| 7464 | |
| 7465 | new_triggers.n_patterns = n_patterns; |
| 7466 | i = 0; |
| 7467 | |
| 7468 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7469 | rem) { |
| 7470 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7471 | nla_data(pat), nla_len(pat), NULL); |
| 7472 | err = -EINVAL; |
| 7473 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7474 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7475 | goto error; |
| 7476 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7477 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7478 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7479 | mask_len) |
| 7480 | goto error; |
| 7481 | if (pat_len > wowlan->pattern_max_len || |
| 7482 | pat_len < wowlan->pattern_min_len) |
| 7483 | goto error; |
| 7484 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7485 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7486 | pkt_offset = 0; |
| 7487 | else |
| 7488 | pkt_offset = nla_get_u32( |
| 7489 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7490 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7491 | goto error; |
| 7492 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7493 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7494 | new_triggers.patterns[i].mask = |
| 7495 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7496 | if (!new_triggers.patterns[i].mask) { |
| 7497 | err = -ENOMEM; |
| 7498 | goto error; |
| 7499 | } |
| 7500 | new_triggers.patterns[i].pattern = |
| 7501 | new_triggers.patterns[i].mask + mask_len; |
| 7502 | memcpy(new_triggers.patterns[i].mask, |
| 7503 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7504 | mask_len); |
| 7505 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7506 | memcpy(new_triggers.patterns[i].pattern, |
| 7507 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7508 | pat_len); |
| 7509 | i++; |
| 7510 | } |
| 7511 | } |
| 7512 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7513 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7514 | err = nl80211_parse_wowlan_tcp( |
| 7515 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7516 | &new_triggers); |
| 7517 | if (err) |
| 7518 | goto error; |
| 7519 | } |
| 7520 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7521 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7522 | if (!ntrig) { |
| 7523 | err = -ENOMEM; |
| 7524 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7525 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7526 | cfg80211_rdev_free_wowlan(rdev); |
| 7527 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7528 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7529 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7530 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7531 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7532 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7533 | return 0; |
| 7534 | error: |
| 7535 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7536 | kfree(new_triggers.patterns[i].mask); |
| 7537 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7538 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7539 | sock_release(new_triggers.tcp->sock); |
| 7540 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7541 | return err; |
| 7542 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7543 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7544 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7545 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7546 | { |
| 7547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7548 | struct net_device *dev = info->user_ptr[1]; |
| 7549 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7550 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7551 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7552 | int err; |
| 7553 | |
| 7554 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7555 | return -EINVAL; |
| 7556 | |
| 7557 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7558 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7559 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7560 | nl80211_rekey_policy); |
| 7561 | if (err) |
| 7562 | return err; |
| 7563 | |
| 7564 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7565 | return -ERANGE; |
| 7566 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7567 | return -ERANGE; |
| 7568 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7569 | return -ERANGE; |
| 7570 | |
| 7571 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7572 | NL80211_KEK_LEN); |
| 7573 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7574 | NL80211_KCK_LEN); |
| 7575 | memcpy(rekey_data.replay_ctr, |
| 7576 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7577 | NL80211_REPLAY_CTR_LEN); |
| 7578 | |
| 7579 | wdev_lock(wdev); |
| 7580 | if (!wdev->current_bss) { |
| 7581 | err = -ENOTCONN; |
| 7582 | goto out; |
| 7583 | } |
| 7584 | |
| 7585 | if (!rdev->ops->set_rekey_data) { |
| 7586 | err = -EOPNOTSUPP; |
| 7587 | goto out; |
| 7588 | } |
| 7589 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7590 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7591 | out: |
| 7592 | wdev_unlock(wdev); |
| 7593 | return err; |
| 7594 | } |
| 7595 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7596 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7597 | struct genl_info *info) |
| 7598 | { |
| 7599 | struct net_device *dev = info->user_ptr[1]; |
| 7600 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7601 | |
| 7602 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7603 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7604 | return -EINVAL; |
| 7605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7606 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7607 | return -EBUSY; |
| 7608 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7609 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7610 | return 0; |
| 7611 | } |
| 7612 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7613 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7614 | struct genl_info *info) |
| 7615 | { |
| 7616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7617 | struct net_device *dev = info->user_ptr[1]; |
| 7618 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7619 | struct sk_buff *msg; |
| 7620 | void *hdr; |
| 7621 | const u8 *addr; |
| 7622 | u64 cookie; |
| 7623 | int err; |
| 7624 | |
| 7625 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7626 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7627 | return -EOPNOTSUPP; |
| 7628 | |
| 7629 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7630 | return -EINVAL; |
| 7631 | |
| 7632 | if (!rdev->ops->probe_client) |
| 7633 | return -EOPNOTSUPP; |
| 7634 | |
| 7635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7636 | if (!msg) |
| 7637 | return -ENOMEM; |
| 7638 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7639 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7640 | NL80211_CMD_PROBE_CLIENT); |
| 7641 | |
| 7642 | if (IS_ERR(hdr)) { |
| 7643 | err = PTR_ERR(hdr); |
| 7644 | goto free_msg; |
| 7645 | } |
| 7646 | |
| 7647 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7648 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7649 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7650 | if (err) |
| 7651 | goto free_msg; |
| 7652 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7653 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7654 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7655 | |
| 7656 | genlmsg_end(msg, hdr); |
| 7657 | |
| 7658 | return genlmsg_reply(msg, info); |
| 7659 | |
| 7660 | nla_put_failure: |
| 7661 | err = -ENOBUFS; |
| 7662 | free_msg: |
| 7663 | nlmsg_free(msg); |
| 7664 | return err; |
| 7665 | } |
| 7666 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7667 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7668 | { |
| 7669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7670 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7671 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7672 | |
| 7673 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7674 | return -EOPNOTSUPP; |
| 7675 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7676 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7677 | if (!nreg) |
| 7678 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7679 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7680 | /* First, check if already registered. */ |
| 7681 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7682 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7683 | if (reg->nlportid == info->snd_portid) { |
| 7684 | rv = -EALREADY; |
| 7685 | goto out_err; |
| 7686 | } |
| 7687 | } |
| 7688 | /* Add it to the list */ |
| 7689 | nreg->nlportid = info->snd_portid; |
| 7690 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7691 | |
| 7692 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7693 | |
| 7694 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7695 | out_err: |
| 7696 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7697 | kfree(nreg); |
| 7698 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7699 | } |
| 7700 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7701 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7702 | { |
| 7703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7704 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7705 | int err; |
| 7706 | |
| 7707 | if (!rdev->ops->start_p2p_device) |
| 7708 | return -EOPNOTSUPP; |
| 7709 | |
| 7710 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7711 | return -EOPNOTSUPP; |
| 7712 | |
| 7713 | if (wdev->p2p_started) |
| 7714 | return 0; |
| 7715 | |
| 7716 | mutex_lock(&rdev->devlist_mtx); |
| 7717 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7718 | mutex_unlock(&rdev->devlist_mtx); |
| 7719 | if (err) |
| 7720 | return err; |
| 7721 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7722 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7723 | if (err) |
| 7724 | return err; |
| 7725 | |
| 7726 | wdev->p2p_started = true; |
| 7727 | mutex_lock(&rdev->devlist_mtx); |
| 7728 | rdev->opencount++; |
| 7729 | mutex_unlock(&rdev->devlist_mtx); |
| 7730 | |
| 7731 | return 0; |
| 7732 | } |
| 7733 | |
| 7734 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7735 | { |
| 7736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7737 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7738 | |
| 7739 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7740 | return -EOPNOTSUPP; |
| 7741 | |
| 7742 | if (!rdev->ops->stop_p2p_device) |
| 7743 | return -EOPNOTSUPP; |
| 7744 | |
| 7745 | if (!wdev->p2p_started) |
| 7746 | return 0; |
| 7747 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7748 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7749 | wdev->p2p_started = false; |
| 7750 | |
| 7751 | mutex_lock(&rdev->devlist_mtx); |
| 7752 | rdev->opencount--; |
| 7753 | mutex_unlock(&rdev->devlist_mtx); |
| 7754 | |
| 7755 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7756 | rdev->scan_req->aborted = true; |
| 7757 | ___cfg80211_scan_done(rdev, true); |
| 7758 | } |
| 7759 | |
| 7760 | return 0; |
| 7761 | } |
| 7762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7763 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7764 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7765 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7766 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7767 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7768 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7769 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7770 | /* 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] | 7771 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7772 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7773 | |
| 7774 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7775 | struct genl_info *info) |
| 7776 | { |
| 7777 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7778 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7779 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7780 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7781 | |
| 7782 | if (rtnl) |
| 7783 | rtnl_lock(); |
| 7784 | |
| 7785 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7786 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7787 | if (IS_ERR(rdev)) { |
| 7788 | if (rtnl) |
| 7789 | rtnl_unlock(); |
| 7790 | return PTR_ERR(rdev); |
| 7791 | } |
| 7792 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7793 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7794 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7795 | mutex_lock(&cfg80211_mutex); |
| 7796 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7797 | info->attrs); |
| 7798 | if (IS_ERR(wdev)) { |
| 7799 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7800 | if (rtnl) |
| 7801 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7802 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7803 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7804 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7805 | dev = wdev->netdev; |
| 7806 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7807 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7808 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7809 | if (!dev) { |
| 7810 | mutex_unlock(&cfg80211_mutex); |
| 7811 | if (rtnl) |
| 7812 | rtnl_unlock(); |
| 7813 | return -EINVAL; |
| 7814 | } |
| 7815 | |
| 7816 | info->user_ptr[1] = dev; |
| 7817 | } else { |
| 7818 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7819 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7820 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7821 | if (dev) { |
| 7822 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7823 | !netif_running(dev)) { |
| 7824 | mutex_unlock(&cfg80211_mutex); |
| 7825 | if (rtnl) |
| 7826 | rtnl_unlock(); |
| 7827 | return -ENETDOWN; |
| 7828 | } |
| 7829 | |
| 7830 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7831 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7832 | if (!wdev->p2p_started) { |
| 7833 | mutex_unlock(&cfg80211_mutex); |
| 7834 | if (rtnl) |
| 7835 | rtnl_unlock(); |
| 7836 | return -ENETDOWN; |
| 7837 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7838 | } |
| 7839 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7840 | cfg80211_lock_rdev(rdev); |
| 7841 | |
| 7842 | mutex_unlock(&cfg80211_mutex); |
| 7843 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7844 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7845 | } |
| 7846 | |
| 7847 | return 0; |
| 7848 | } |
| 7849 | |
| 7850 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7851 | struct genl_info *info) |
| 7852 | { |
| 7853 | if (info->user_ptr[0]) |
| 7854 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7855 | if (info->user_ptr[1]) { |
| 7856 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7857 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7858 | |
| 7859 | if (wdev->netdev) |
| 7860 | dev_put(wdev->netdev); |
| 7861 | } else { |
| 7862 | dev_put(info->user_ptr[1]); |
| 7863 | } |
| 7864 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7865 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7866 | rtnl_unlock(); |
| 7867 | } |
| 7868 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7869 | static struct genl_ops nl80211_ops[] = { |
| 7870 | { |
| 7871 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7872 | .doit = nl80211_get_wiphy, |
| 7873 | .dumpit = nl80211_dump_wiphy, |
| 7874 | .policy = nl80211_policy, |
| 7875 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7876 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7877 | }, |
| 7878 | { |
| 7879 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7880 | .doit = nl80211_set_wiphy, |
| 7881 | .policy = nl80211_policy, |
| 7882 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7883 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7884 | }, |
| 7885 | { |
| 7886 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7887 | .doit = nl80211_get_interface, |
| 7888 | .dumpit = nl80211_dump_interface, |
| 7889 | .policy = nl80211_policy, |
| 7890 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7891 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7892 | }, |
| 7893 | { |
| 7894 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7895 | .doit = nl80211_set_interface, |
| 7896 | .policy = nl80211_policy, |
| 7897 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7898 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7899 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7900 | }, |
| 7901 | { |
| 7902 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7903 | .doit = nl80211_new_interface, |
| 7904 | .policy = nl80211_policy, |
| 7905 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7906 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7907 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7908 | }, |
| 7909 | { |
| 7910 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7911 | .doit = nl80211_del_interface, |
| 7912 | .policy = nl80211_policy, |
| 7913 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7914 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7915 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7916 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7917 | { |
| 7918 | .cmd = NL80211_CMD_GET_KEY, |
| 7919 | .doit = nl80211_get_key, |
| 7920 | .policy = nl80211_policy, |
| 7921 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7922 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7923 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7924 | }, |
| 7925 | { |
| 7926 | .cmd = NL80211_CMD_SET_KEY, |
| 7927 | .doit = nl80211_set_key, |
| 7928 | .policy = nl80211_policy, |
| 7929 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7930 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7931 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7932 | }, |
| 7933 | { |
| 7934 | .cmd = NL80211_CMD_NEW_KEY, |
| 7935 | .doit = nl80211_new_key, |
| 7936 | .policy = nl80211_policy, |
| 7937 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7938 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7939 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7940 | }, |
| 7941 | { |
| 7942 | .cmd = NL80211_CMD_DEL_KEY, |
| 7943 | .doit = nl80211_del_key, |
| 7944 | .policy = nl80211_policy, |
| 7945 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7947 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7948 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7949 | { |
| 7950 | .cmd = NL80211_CMD_SET_BEACON, |
| 7951 | .policy = nl80211_policy, |
| 7952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7953 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7955 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7956 | }, |
| 7957 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7958 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7959 | .policy = nl80211_policy, |
| 7960 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7961 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7962 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7963 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7964 | }, |
| 7965 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7966 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7967 | .policy = nl80211_policy, |
| 7968 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7969 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7970 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7971 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7972 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7973 | { |
| 7974 | .cmd = NL80211_CMD_GET_STATION, |
| 7975 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7976 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7977 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7978 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7979 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7980 | }, |
| 7981 | { |
| 7982 | .cmd = NL80211_CMD_SET_STATION, |
| 7983 | .doit = nl80211_set_station, |
| 7984 | .policy = nl80211_policy, |
| 7985 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7986 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7987 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7988 | }, |
| 7989 | { |
| 7990 | .cmd = NL80211_CMD_NEW_STATION, |
| 7991 | .doit = nl80211_new_station, |
| 7992 | .policy = nl80211_policy, |
| 7993 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7995 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7996 | }, |
| 7997 | { |
| 7998 | .cmd = NL80211_CMD_DEL_STATION, |
| 7999 | .doit = nl80211_del_station, |
| 8000 | .policy = nl80211_policy, |
| 8001 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8003 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8004 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8005 | { |
| 8006 | .cmd = NL80211_CMD_GET_MPATH, |
| 8007 | .doit = nl80211_get_mpath, |
| 8008 | .dumpit = nl80211_dump_mpath, |
| 8009 | .policy = nl80211_policy, |
| 8010 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8012 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8013 | }, |
| 8014 | { |
| 8015 | .cmd = NL80211_CMD_SET_MPATH, |
| 8016 | .doit = nl80211_set_mpath, |
| 8017 | .policy = nl80211_policy, |
| 8018 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8020 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8021 | }, |
| 8022 | { |
| 8023 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8024 | .doit = nl80211_new_mpath, |
| 8025 | .policy = nl80211_policy, |
| 8026 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8028 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8029 | }, |
| 8030 | { |
| 8031 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8032 | .doit = nl80211_del_mpath, |
| 8033 | .policy = nl80211_policy, |
| 8034 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8036 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8037 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8038 | { |
| 8039 | .cmd = NL80211_CMD_SET_BSS, |
| 8040 | .doit = nl80211_set_bss, |
| 8041 | .policy = nl80211_policy, |
| 8042 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8043 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8044 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8045 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8046 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8047 | .cmd = NL80211_CMD_GET_REG, |
| 8048 | .doit = nl80211_get_reg, |
| 8049 | .policy = nl80211_policy, |
| 8050 | /* can be retrieved by unprivileged users */ |
| 8051 | }, |
| 8052 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8053 | .cmd = NL80211_CMD_SET_REG, |
| 8054 | .doit = nl80211_set_reg, |
| 8055 | .policy = nl80211_policy, |
| 8056 | .flags = GENL_ADMIN_PERM, |
| 8057 | }, |
| 8058 | { |
| 8059 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8060 | .doit = nl80211_req_set_reg, |
| 8061 | .policy = nl80211_policy, |
| 8062 | .flags = GENL_ADMIN_PERM, |
| 8063 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8064 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8065 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8066 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8067 | .policy = nl80211_policy, |
| 8068 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8069 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8070 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8071 | }, |
| 8072 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8073 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8074 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8075 | .policy = nl80211_policy, |
| 8076 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8077 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8078 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8079 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8080 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8081 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8082 | .doit = nl80211_trigger_scan, |
| 8083 | .policy = nl80211_policy, |
| 8084 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8085 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8086 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8087 | }, |
| 8088 | { |
| 8089 | .cmd = NL80211_CMD_GET_SCAN, |
| 8090 | .policy = nl80211_policy, |
| 8091 | .dumpit = nl80211_dump_scan, |
| 8092 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8093 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8094 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8095 | .doit = nl80211_start_sched_scan, |
| 8096 | .policy = nl80211_policy, |
| 8097 | .flags = GENL_ADMIN_PERM, |
| 8098 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8099 | NL80211_FLAG_NEED_RTNL, |
| 8100 | }, |
| 8101 | { |
| 8102 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8103 | .doit = nl80211_stop_sched_scan, |
| 8104 | .policy = nl80211_policy, |
| 8105 | .flags = GENL_ADMIN_PERM, |
| 8106 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8107 | NL80211_FLAG_NEED_RTNL, |
| 8108 | }, |
| 8109 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8110 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8111 | .doit = nl80211_authenticate, |
| 8112 | .policy = nl80211_policy, |
| 8113 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8114 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8115 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8116 | }, |
| 8117 | { |
| 8118 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8119 | .doit = nl80211_associate, |
| 8120 | .policy = nl80211_policy, |
| 8121 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8122 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8123 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8124 | }, |
| 8125 | { |
| 8126 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8127 | .doit = nl80211_deauthenticate, |
| 8128 | .policy = nl80211_policy, |
| 8129 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8130 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8131 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8132 | }, |
| 8133 | { |
| 8134 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8135 | .doit = nl80211_disassociate, |
| 8136 | .policy = nl80211_policy, |
| 8137 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8138 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8139 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8140 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8141 | { |
| 8142 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8143 | .doit = nl80211_join_ibss, |
| 8144 | .policy = nl80211_policy, |
| 8145 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8146 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8147 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8148 | }, |
| 8149 | { |
| 8150 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8151 | .doit = nl80211_leave_ibss, |
| 8152 | .policy = nl80211_policy, |
| 8153 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8154 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8155 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8156 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8157 | #ifdef CONFIG_NL80211_TESTMODE |
| 8158 | { |
| 8159 | .cmd = NL80211_CMD_TESTMODE, |
| 8160 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8161 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8162 | .policy = nl80211_policy, |
| 8163 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8164 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8165 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8166 | }, |
| 8167 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8168 | { |
| 8169 | .cmd = NL80211_CMD_CONNECT, |
| 8170 | .doit = nl80211_connect, |
| 8171 | .policy = nl80211_policy, |
| 8172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8173 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8174 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8175 | }, |
| 8176 | { |
| 8177 | .cmd = NL80211_CMD_DISCONNECT, |
| 8178 | .doit = nl80211_disconnect, |
| 8179 | .policy = nl80211_policy, |
| 8180 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8181 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8182 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8183 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8184 | { |
| 8185 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8186 | .doit = nl80211_wiphy_netns, |
| 8187 | .policy = nl80211_policy, |
| 8188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8189 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8190 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8191 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8192 | { |
| 8193 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8194 | .policy = nl80211_policy, |
| 8195 | .dumpit = nl80211_dump_survey, |
| 8196 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8197 | { |
| 8198 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8199 | .doit = nl80211_setdel_pmksa, |
| 8200 | .policy = nl80211_policy, |
| 8201 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8203 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8204 | }, |
| 8205 | { |
| 8206 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8207 | .doit = nl80211_setdel_pmksa, |
| 8208 | .policy = nl80211_policy, |
| 8209 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8211 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8212 | }, |
| 8213 | { |
| 8214 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8215 | .doit = nl80211_flush_pmksa, |
| 8216 | .policy = nl80211_policy, |
| 8217 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8219 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8220 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8221 | { |
| 8222 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8223 | .doit = nl80211_remain_on_channel, |
| 8224 | .policy = nl80211_policy, |
| 8225 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8226 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8227 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8228 | }, |
| 8229 | { |
| 8230 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8231 | .doit = nl80211_cancel_remain_on_channel, |
| 8232 | .policy = nl80211_policy, |
| 8233 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8234 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8235 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8236 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8237 | { |
| 8238 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8239 | .doit = nl80211_set_tx_bitrate_mask, |
| 8240 | .policy = nl80211_policy, |
| 8241 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8242 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8243 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8244 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8245 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8246 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8247 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8248 | .policy = nl80211_policy, |
| 8249 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8250 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8251 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8252 | }, |
| 8253 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8254 | .cmd = NL80211_CMD_FRAME, |
| 8255 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8256 | .policy = nl80211_policy, |
| 8257 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8258 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8259 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8260 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8261 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8262 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8263 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8264 | .policy = nl80211_policy, |
| 8265 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8266 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8267 | NL80211_FLAG_NEED_RTNL, |
| 8268 | }, |
| 8269 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8270 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8271 | .doit = nl80211_set_power_save, |
| 8272 | .policy = nl80211_policy, |
| 8273 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8274 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8275 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8276 | }, |
| 8277 | { |
| 8278 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8279 | .doit = nl80211_get_power_save, |
| 8280 | .policy = nl80211_policy, |
| 8281 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8282 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8283 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8284 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8285 | { |
| 8286 | .cmd = NL80211_CMD_SET_CQM, |
| 8287 | .doit = nl80211_set_cqm, |
| 8288 | .policy = nl80211_policy, |
| 8289 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8290 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8291 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8292 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8293 | { |
| 8294 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8295 | .doit = nl80211_set_channel, |
| 8296 | .policy = nl80211_policy, |
| 8297 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8298 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8299 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8300 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8301 | { |
| 8302 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8303 | .doit = nl80211_set_wds_peer, |
| 8304 | .policy = nl80211_policy, |
| 8305 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8306 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8307 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8308 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8309 | { |
| 8310 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8311 | .doit = nl80211_join_mesh, |
| 8312 | .policy = nl80211_policy, |
| 8313 | .flags = GENL_ADMIN_PERM, |
| 8314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8315 | NL80211_FLAG_NEED_RTNL, |
| 8316 | }, |
| 8317 | { |
| 8318 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8319 | .doit = nl80211_leave_mesh, |
| 8320 | .policy = nl80211_policy, |
| 8321 | .flags = GENL_ADMIN_PERM, |
| 8322 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8323 | NL80211_FLAG_NEED_RTNL, |
| 8324 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8325 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8326 | { |
| 8327 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8328 | .doit = nl80211_get_wowlan, |
| 8329 | .policy = nl80211_policy, |
| 8330 | /* can be retrieved by unprivileged users */ |
| 8331 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8332 | NL80211_FLAG_NEED_RTNL, |
| 8333 | }, |
| 8334 | { |
| 8335 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8336 | .doit = nl80211_set_wowlan, |
| 8337 | .policy = nl80211_policy, |
| 8338 | .flags = GENL_ADMIN_PERM, |
| 8339 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8340 | NL80211_FLAG_NEED_RTNL, |
| 8341 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8342 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8343 | { |
| 8344 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8345 | .doit = nl80211_set_rekey_data, |
| 8346 | .policy = nl80211_policy, |
| 8347 | .flags = GENL_ADMIN_PERM, |
| 8348 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8349 | NL80211_FLAG_NEED_RTNL, |
| 8350 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8351 | { |
| 8352 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8353 | .doit = nl80211_tdls_mgmt, |
| 8354 | .policy = nl80211_policy, |
| 8355 | .flags = GENL_ADMIN_PERM, |
| 8356 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8357 | NL80211_FLAG_NEED_RTNL, |
| 8358 | }, |
| 8359 | { |
| 8360 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8361 | .doit = nl80211_tdls_oper, |
| 8362 | .policy = nl80211_policy, |
| 8363 | .flags = GENL_ADMIN_PERM, |
| 8364 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8365 | NL80211_FLAG_NEED_RTNL, |
| 8366 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8367 | { |
| 8368 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8369 | .doit = nl80211_register_unexpected_frame, |
| 8370 | .policy = nl80211_policy, |
| 8371 | .flags = GENL_ADMIN_PERM, |
| 8372 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8373 | NL80211_FLAG_NEED_RTNL, |
| 8374 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8375 | { |
| 8376 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8377 | .doit = nl80211_probe_client, |
| 8378 | .policy = nl80211_policy, |
| 8379 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8380 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8381 | NL80211_FLAG_NEED_RTNL, |
| 8382 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8383 | { |
| 8384 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8385 | .doit = nl80211_register_beacons, |
| 8386 | .policy = nl80211_policy, |
| 8387 | .flags = GENL_ADMIN_PERM, |
| 8388 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8389 | NL80211_FLAG_NEED_RTNL, |
| 8390 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8391 | { |
| 8392 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8393 | .doit = nl80211_set_noack_map, |
| 8394 | .policy = nl80211_policy, |
| 8395 | .flags = GENL_ADMIN_PERM, |
| 8396 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8397 | NL80211_FLAG_NEED_RTNL, |
| 8398 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8399 | { |
| 8400 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8401 | .doit = nl80211_start_p2p_device, |
| 8402 | .policy = nl80211_policy, |
| 8403 | .flags = GENL_ADMIN_PERM, |
| 8404 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8405 | NL80211_FLAG_NEED_RTNL, |
| 8406 | }, |
| 8407 | { |
| 8408 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8409 | .doit = nl80211_stop_p2p_device, |
| 8410 | .policy = nl80211_policy, |
| 8411 | .flags = GENL_ADMIN_PERM, |
| 8412 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8413 | NL80211_FLAG_NEED_RTNL, |
| 8414 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8415 | { |
| 8416 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8417 | .doit = nl80211_set_mcast_rate, |
| 8418 | .policy = nl80211_policy, |
| 8419 | .flags = GENL_ADMIN_PERM, |
| 8420 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8421 | NL80211_FLAG_NEED_RTNL, |
| 8422 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8423 | { |
| 8424 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8425 | .doit = nl80211_set_mac_acl, |
| 8426 | .policy = nl80211_policy, |
| 8427 | .flags = GENL_ADMIN_PERM, |
| 8428 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8429 | NL80211_FLAG_NEED_RTNL, |
| 8430 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8431 | { |
| 8432 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8433 | .doit = nl80211_start_radar_detection, |
| 8434 | .policy = nl80211_policy, |
| 8435 | .flags = GENL_ADMIN_PERM, |
| 8436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8437 | NL80211_FLAG_NEED_RTNL, |
| 8438 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8439 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8440 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8441 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8442 | .name = "mlme", |
| 8443 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8444 | |
| 8445 | /* multicast groups */ |
| 8446 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8447 | .name = "config", |
| 8448 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8449 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8450 | .name = "scan", |
| 8451 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8452 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8453 | .name = "regulatory", |
| 8454 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8455 | |
| 8456 | /* notification functions */ |
| 8457 | |
| 8458 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8459 | { |
| 8460 | struct sk_buff *msg; |
| 8461 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8462 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8463 | if (!msg) |
| 8464 | return; |
| 8465 | |
| 8466 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8467 | nlmsg_free(msg); |
| 8468 | return; |
| 8469 | } |
| 8470 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8471 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8472 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8473 | } |
| 8474 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8475 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8476 | struct cfg80211_registered_device *rdev) |
| 8477 | { |
| 8478 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8479 | struct nlattr *nest; |
| 8480 | int i; |
| 8481 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8482 | ASSERT_RDEV_LOCK(rdev); |
| 8483 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8484 | if (WARN_ON(!req)) |
| 8485 | return 0; |
| 8486 | |
| 8487 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8488 | if (!nest) |
| 8489 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8490 | for (i = 0; i < req->n_ssids; i++) { |
| 8491 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8492 | goto nla_put_failure; |
| 8493 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8494 | nla_nest_end(msg, nest); |
| 8495 | |
| 8496 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8497 | if (!nest) |
| 8498 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8499 | for (i = 0; i < req->n_channels; i++) { |
| 8500 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8501 | goto nla_put_failure; |
| 8502 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8503 | nla_nest_end(msg, nest); |
| 8504 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8505 | if (req->ie && |
| 8506 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8507 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8508 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8509 | if (req->flags) |
| 8510 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8511 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8512 | return 0; |
| 8513 | nla_put_failure: |
| 8514 | return -ENOBUFS; |
| 8515 | } |
| 8516 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8517 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8518 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8519 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8520 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8521 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8522 | { |
| 8523 | void *hdr; |
| 8524 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8525 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8526 | if (!hdr) |
| 8527 | return -1; |
| 8528 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8529 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8530 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8531 | wdev->netdev->ifindex)) || |
| 8532 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8533 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8534 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8535 | /* ignore errors and send incomplete event anyway */ |
| 8536 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8537 | |
| 8538 | return genlmsg_end(msg, hdr); |
| 8539 | |
| 8540 | nla_put_failure: |
| 8541 | genlmsg_cancel(msg, hdr); |
| 8542 | return -EMSGSIZE; |
| 8543 | } |
| 8544 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8545 | static int |
| 8546 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8547 | struct cfg80211_registered_device *rdev, |
| 8548 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8549 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [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); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [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) || |
| 8558 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8559 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8560 | |
| 8561 | return genlmsg_end(msg, hdr); |
| 8562 | |
| 8563 | nla_put_failure: |
| 8564 | genlmsg_cancel(msg, hdr); |
| 8565 | return -EMSGSIZE; |
| 8566 | } |
| 8567 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8568 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8569 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8570 | { |
| 8571 | struct sk_buff *msg; |
| 8572 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8573 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8574 | if (!msg) |
| 8575 | return; |
| 8576 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8577 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8578 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8579 | nlmsg_free(msg); |
| 8580 | return; |
| 8581 | } |
| 8582 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8583 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8584 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8585 | } |
| 8586 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8587 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8588 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8589 | { |
| 8590 | struct sk_buff *msg; |
| 8591 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8593 | if (!msg) |
| 8594 | return; |
| 8595 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8596 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8597 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8598 | nlmsg_free(msg); |
| 8599 | return; |
| 8600 | } |
| 8601 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8602 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8603 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8604 | } |
| 8605 | |
| 8606 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8607 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8608 | { |
| 8609 | struct sk_buff *msg; |
| 8610 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8611 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8612 | if (!msg) |
| 8613 | return; |
| 8614 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8615 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8616 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8617 | nlmsg_free(msg); |
| 8618 | return; |
| 8619 | } |
| 8620 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8621 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8622 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8623 | } |
| 8624 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8625 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8626 | struct net_device *netdev) |
| 8627 | { |
| 8628 | struct sk_buff *msg; |
| 8629 | |
| 8630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8631 | if (!msg) |
| 8632 | return; |
| 8633 | |
| 8634 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8635 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8636 | nlmsg_free(msg); |
| 8637 | return; |
| 8638 | } |
| 8639 | |
| 8640 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8641 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8642 | } |
| 8643 | |
| 8644 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8645 | struct net_device *netdev, u32 cmd) |
| 8646 | { |
| 8647 | struct sk_buff *msg; |
| 8648 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8649 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8650 | if (!msg) |
| 8651 | return; |
| 8652 | |
| 8653 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8654 | nlmsg_free(msg); |
| 8655 | return; |
| 8656 | } |
| 8657 | |
| 8658 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8659 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8660 | } |
| 8661 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8662 | /* |
| 8663 | * This can happen on global regulatory changes or device specific settings |
| 8664 | * based on custom world regulatory domains. |
| 8665 | */ |
| 8666 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8667 | { |
| 8668 | struct sk_buff *msg; |
| 8669 | void *hdr; |
| 8670 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8672 | if (!msg) |
| 8673 | return; |
| 8674 | |
| 8675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8676 | if (!hdr) { |
| 8677 | nlmsg_free(msg); |
| 8678 | return; |
| 8679 | } |
| 8680 | |
| 8681 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8682 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8683 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8684 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8685 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8686 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8687 | NL80211_REGDOM_TYPE_WORLD)) |
| 8688 | goto nla_put_failure; |
| 8689 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8690 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8691 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8692 | goto nla_put_failure; |
| 8693 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8694 | request->intersect) { |
| 8695 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8696 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8697 | goto nla_put_failure; |
| 8698 | } else { |
| 8699 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8700 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8701 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8702 | request->alpha2)) |
| 8703 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8704 | } |
| 8705 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8706 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8707 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8708 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8709 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8710 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8711 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8712 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8713 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8714 | GFP_ATOMIC); |
| 8715 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8716 | |
| 8717 | return; |
| 8718 | |
| 8719 | nla_put_failure: |
| 8720 | genlmsg_cancel(msg, hdr); |
| 8721 | nlmsg_free(msg); |
| 8722 | } |
| 8723 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8724 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8725 | struct net_device *netdev, |
| 8726 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8727 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8728 | { |
| 8729 | struct sk_buff *msg; |
| 8730 | void *hdr; |
| 8731 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8732 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8733 | if (!msg) |
| 8734 | return; |
| 8735 | |
| 8736 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8737 | if (!hdr) { |
| 8738 | nlmsg_free(msg); |
| 8739 | return; |
| 8740 | } |
| 8741 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8742 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8743 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8744 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8745 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8746 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8747 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8748 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8749 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8750 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8751 | return; |
| 8752 | |
| 8753 | nla_put_failure: |
| 8754 | genlmsg_cancel(msg, hdr); |
| 8755 | nlmsg_free(msg); |
| 8756 | } |
| 8757 | |
| 8758 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8759 | struct net_device *netdev, const u8 *buf, |
| 8760 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8761 | { |
| 8762 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8763 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8764 | } |
| 8765 | |
| 8766 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8767 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8768 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8769 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8770 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8771 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8772 | } |
| 8773 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8774 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8775 | struct net_device *netdev, const u8 *buf, |
| 8776 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8777 | { |
| 8778 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8779 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8780 | } |
| 8781 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8782 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8783 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8784 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8785 | { |
| 8786 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8787 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8788 | } |
| 8789 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8790 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8791 | struct net_device *netdev, const u8 *buf, |
| 8792 | size_t len, gfp_t gfp) |
| 8793 | { |
| 8794 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8795 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8796 | } |
| 8797 | |
| 8798 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8799 | struct net_device *netdev, const u8 *buf, |
| 8800 | size_t len, gfp_t gfp) |
| 8801 | { |
| 8802 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8803 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8804 | } |
| 8805 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8806 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8807 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8808 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8809 | { |
| 8810 | struct sk_buff *msg; |
| 8811 | void *hdr; |
| 8812 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8813 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8814 | if (!msg) |
| 8815 | return; |
| 8816 | |
| 8817 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8818 | if (!hdr) { |
| 8819 | nlmsg_free(msg); |
| 8820 | return; |
| 8821 | } |
| 8822 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8823 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8824 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8825 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8826 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8827 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8828 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8829 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8830 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8831 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8832 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8833 | return; |
| 8834 | |
| 8835 | nla_put_failure: |
| 8836 | genlmsg_cancel(msg, hdr); |
| 8837 | nlmsg_free(msg); |
| 8838 | } |
| 8839 | |
| 8840 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8841 | struct net_device *netdev, const u8 *addr, |
| 8842 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8843 | { |
| 8844 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8845 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8846 | } |
| 8847 | |
| 8848 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8849 | struct net_device *netdev, const u8 *addr, |
| 8850 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8851 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8852 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8853 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8854 | } |
| 8855 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8856 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8857 | struct net_device *netdev, const u8 *bssid, |
| 8858 | const u8 *req_ie, size_t req_ie_len, |
| 8859 | const u8 *resp_ie, size_t resp_ie_len, |
| 8860 | u16 status, gfp_t gfp) |
| 8861 | { |
| 8862 | struct sk_buff *msg; |
| 8863 | void *hdr; |
| 8864 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8865 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8866 | if (!msg) |
| 8867 | return; |
| 8868 | |
| 8869 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8870 | if (!hdr) { |
| 8871 | nlmsg_free(msg); |
| 8872 | return; |
| 8873 | } |
| 8874 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8875 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8876 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8877 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8878 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8879 | (req_ie && |
| 8880 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8881 | (resp_ie && |
| 8882 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8883 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8884 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8885 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8886 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8887 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8888 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8889 | return; |
| 8890 | |
| 8891 | nla_put_failure: |
| 8892 | genlmsg_cancel(msg, hdr); |
| 8893 | nlmsg_free(msg); |
| 8894 | |
| 8895 | } |
| 8896 | |
| 8897 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8898 | struct net_device *netdev, const u8 *bssid, |
| 8899 | const u8 *req_ie, size_t req_ie_len, |
| 8900 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8901 | { |
| 8902 | struct sk_buff *msg; |
| 8903 | void *hdr; |
| 8904 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8905 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8906 | if (!msg) |
| 8907 | return; |
| 8908 | |
| 8909 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8910 | if (!hdr) { |
| 8911 | nlmsg_free(msg); |
| 8912 | return; |
| 8913 | } |
| 8914 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8915 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8916 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8917 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8918 | (req_ie && |
| 8919 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8920 | (resp_ie && |
| 8921 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8922 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8923 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8924 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8925 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8926 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8927 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8928 | return; |
| 8929 | |
| 8930 | nla_put_failure: |
| 8931 | genlmsg_cancel(msg, hdr); |
| 8932 | nlmsg_free(msg); |
| 8933 | |
| 8934 | } |
| 8935 | |
| 8936 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8937 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8938 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8939 | { |
| 8940 | struct sk_buff *msg; |
| 8941 | void *hdr; |
| 8942 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8943 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8944 | if (!msg) |
| 8945 | return; |
| 8946 | |
| 8947 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8948 | if (!hdr) { |
| 8949 | nlmsg_free(msg); |
| 8950 | return; |
| 8951 | } |
| 8952 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8953 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8954 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8955 | (from_ap && reason && |
| 8956 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8957 | (from_ap && |
| 8958 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8959 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8960 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8961 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8962 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8963 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8964 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8965 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8966 | return; |
| 8967 | |
| 8968 | nla_put_failure: |
| 8969 | genlmsg_cancel(msg, hdr); |
| 8970 | nlmsg_free(msg); |
| 8971 | |
| 8972 | } |
| 8973 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8974 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8975 | struct net_device *netdev, const u8 *bssid, |
| 8976 | gfp_t gfp) |
| 8977 | { |
| 8978 | struct sk_buff *msg; |
| 8979 | void *hdr; |
| 8980 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8981 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8982 | if (!msg) |
| 8983 | return; |
| 8984 | |
| 8985 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8986 | if (!hdr) { |
| 8987 | nlmsg_free(msg); |
| 8988 | return; |
| 8989 | } |
| 8990 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8991 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8992 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8993 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8994 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8995 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8996 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8997 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8998 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8999 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9000 | return; |
| 9001 | |
| 9002 | nla_put_failure: |
| 9003 | genlmsg_cancel(msg, hdr); |
| 9004 | nlmsg_free(msg); |
| 9005 | } |
| 9006 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9007 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 9008 | struct net_device *netdev, |
| 9009 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 9010 | gfp_t gfp) |
| 9011 | { |
| 9012 | struct sk_buff *msg; |
| 9013 | void *hdr; |
| 9014 | |
| 9015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9016 | if (!msg) |
| 9017 | return; |
| 9018 | |
| 9019 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9020 | if (!hdr) { |
| 9021 | nlmsg_free(msg); |
| 9022 | return; |
| 9023 | } |
| 9024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9025 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9026 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9027 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 9028 | (ie_len && ie && |
| 9029 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9030 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9031 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9032 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9033 | |
| 9034 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9035 | nl80211_mlme_mcgrp.id, gfp); |
| 9036 | return; |
| 9037 | |
| 9038 | nla_put_failure: |
| 9039 | genlmsg_cancel(msg, hdr); |
| 9040 | nlmsg_free(msg); |
| 9041 | } |
| 9042 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9043 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9044 | struct net_device *netdev, const u8 *addr, |
| 9045 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9046 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9047 | { |
| 9048 | struct sk_buff *msg; |
| 9049 | void *hdr; |
| 9050 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9052 | if (!msg) |
| 9053 | return; |
| 9054 | |
| 9055 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9056 | if (!hdr) { |
| 9057 | nlmsg_free(msg); |
| 9058 | return; |
| 9059 | } |
| 9060 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9061 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9062 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9063 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9064 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9065 | (key_id != -1 && |
| 9066 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9067 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9068 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9069 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9070 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9071 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9072 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9073 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9074 | return; |
| 9075 | |
| 9076 | nla_put_failure: |
| 9077 | genlmsg_cancel(msg, hdr); |
| 9078 | nlmsg_free(msg); |
| 9079 | } |
| 9080 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9081 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9082 | struct ieee80211_channel *channel_before, |
| 9083 | struct ieee80211_channel *channel_after) |
| 9084 | { |
| 9085 | struct sk_buff *msg; |
| 9086 | void *hdr; |
| 9087 | struct nlattr *nl_freq; |
| 9088 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9089 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9090 | if (!msg) |
| 9091 | return; |
| 9092 | |
| 9093 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9094 | if (!hdr) { |
| 9095 | nlmsg_free(msg); |
| 9096 | return; |
| 9097 | } |
| 9098 | |
| 9099 | /* |
| 9100 | * Since we are applying the beacon hint to a wiphy we know its |
| 9101 | * wiphy_idx is valid |
| 9102 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9103 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9104 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9105 | |
| 9106 | /* Before */ |
| 9107 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9108 | if (!nl_freq) |
| 9109 | goto nla_put_failure; |
| 9110 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 9111 | goto nla_put_failure; |
| 9112 | nla_nest_end(msg, nl_freq); |
| 9113 | |
| 9114 | /* After */ |
| 9115 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9116 | if (!nl_freq) |
| 9117 | goto nla_put_failure; |
| 9118 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 9119 | goto nla_put_failure; |
| 9120 | nla_nest_end(msg, nl_freq); |
| 9121 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9122 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9123 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9124 | rcu_read_lock(); |
| 9125 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9126 | GFP_ATOMIC); |
| 9127 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9128 | |
| 9129 | return; |
| 9130 | |
| 9131 | nla_put_failure: |
| 9132 | genlmsg_cancel(msg, hdr); |
| 9133 | nlmsg_free(msg); |
| 9134 | } |
| 9135 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9136 | static void nl80211_send_remain_on_chan_event( |
| 9137 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9138 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9139 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9140 | unsigned int duration, gfp_t gfp) |
| 9141 | { |
| 9142 | struct sk_buff *msg; |
| 9143 | void *hdr; |
| 9144 | |
| 9145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9146 | if (!msg) |
| 9147 | return; |
| 9148 | |
| 9149 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9150 | if (!hdr) { |
| 9151 | nlmsg_free(msg); |
| 9152 | return; |
| 9153 | } |
| 9154 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9155 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9156 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9157 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9158 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9159 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9160 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9161 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9162 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9163 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9164 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9165 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9166 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9167 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9168 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9169 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9170 | |
| 9171 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9172 | nl80211_mlme_mcgrp.id, gfp); |
| 9173 | return; |
| 9174 | |
| 9175 | nla_put_failure: |
| 9176 | genlmsg_cancel(msg, hdr); |
| 9177 | nlmsg_free(msg); |
| 9178 | } |
| 9179 | |
| 9180 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9181 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9182 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9183 | unsigned int duration, gfp_t gfp) |
| 9184 | { |
| 9185 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9186 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9187 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9188 | } |
| 9189 | |
| 9190 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9191 | struct cfg80211_registered_device *rdev, |
| 9192 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9193 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9194 | { |
| 9195 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9196 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9197 | } |
| 9198 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9199 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 9200 | struct net_device *dev, const u8 *mac_addr, |
| 9201 | struct station_info *sinfo, gfp_t gfp) |
| 9202 | { |
| 9203 | struct sk_buff *msg; |
| 9204 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9205 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9206 | if (!msg) |
| 9207 | return; |
| 9208 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9209 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9210 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9211 | nlmsg_free(msg); |
| 9212 | return; |
| 9213 | } |
| 9214 | |
| 9215 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9216 | nl80211_mlme_mcgrp.id, gfp); |
| 9217 | } |
| 9218 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9219 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 9220 | struct net_device *dev, const u8 *mac_addr, |
| 9221 | gfp_t gfp) |
| 9222 | { |
| 9223 | struct sk_buff *msg; |
| 9224 | void *hdr; |
| 9225 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9226 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9227 | if (!msg) |
| 9228 | return; |
| 9229 | |
| 9230 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9231 | if (!hdr) { |
| 9232 | nlmsg_free(msg); |
| 9233 | return; |
| 9234 | } |
| 9235 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9236 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9237 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9238 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9239 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9240 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9241 | |
| 9242 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9243 | nl80211_mlme_mcgrp.id, gfp); |
| 9244 | return; |
| 9245 | |
| 9246 | nla_put_failure: |
| 9247 | genlmsg_cancel(msg, hdr); |
| 9248 | nlmsg_free(msg); |
| 9249 | } |
| 9250 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9251 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 9252 | struct net_device *dev, const u8 *mac_addr, |
| 9253 | enum nl80211_connect_failed_reason reason, |
| 9254 | gfp_t gfp) |
| 9255 | { |
| 9256 | struct sk_buff *msg; |
| 9257 | void *hdr; |
| 9258 | |
| 9259 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9260 | if (!msg) |
| 9261 | return; |
| 9262 | |
| 9263 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9264 | if (!hdr) { |
| 9265 | nlmsg_free(msg); |
| 9266 | return; |
| 9267 | } |
| 9268 | |
| 9269 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9270 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9271 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9272 | goto nla_put_failure; |
| 9273 | |
| 9274 | genlmsg_end(msg, hdr); |
| 9275 | |
| 9276 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9277 | nl80211_mlme_mcgrp.id, gfp); |
| 9278 | return; |
| 9279 | |
| 9280 | nla_put_failure: |
| 9281 | genlmsg_cancel(msg, hdr); |
| 9282 | nlmsg_free(msg); |
| 9283 | } |
| 9284 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9285 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9286 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9287 | { |
| 9288 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9289 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9290 | struct sk_buff *msg; |
| 9291 | void *hdr; |
| 9292 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9293 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9294 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9295 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9296 | return false; |
| 9297 | |
| 9298 | msg = nlmsg_new(100, gfp); |
| 9299 | if (!msg) |
| 9300 | return true; |
| 9301 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9302 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9303 | if (!hdr) { |
| 9304 | nlmsg_free(msg); |
| 9305 | return true; |
| 9306 | } |
| 9307 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9308 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9309 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9310 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9311 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9312 | |
| 9313 | err = genlmsg_end(msg, hdr); |
| 9314 | if (err < 0) { |
| 9315 | nlmsg_free(msg); |
| 9316 | return true; |
| 9317 | } |
| 9318 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9319 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9320 | return true; |
| 9321 | |
| 9322 | nla_put_failure: |
| 9323 | genlmsg_cancel(msg, hdr); |
| 9324 | nlmsg_free(msg); |
| 9325 | return true; |
| 9326 | } |
| 9327 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9328 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 9329 | { |
| 9330 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9331 | addr, gfp); |
| 9332 | } |
| 9333 | |
| 9334 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 9335 | const u8 *addr, gfp_t gfp) |
| 9336 | { |
| 9337 | return __nl80211_unexpected_frame(dev, |
| 9338 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9339 | addr, gfp); |
| 9340 | } |
| 9341 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9342 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9343 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9344 | int freq, int sig_dbm, |
| 9345 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9346 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9347 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9348 | struct sk_buff *msg; |
| 9349 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9350 | |
| 9351 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9352 | if (!msg) |
| 9353 | return -ENOMEM; |
| 9354 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9355 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9356 | if (!hdr) { |
| 9357 | nlmsg_free(msg); |
| 9358 | return -ENOMEM; |
| 9359 | } |
| 9360 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9361 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9362 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9363 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9364 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9365 | (sig_dbm && |
| 9366 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9367 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9368 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9369 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9370 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9371 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9372 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9373 | |
| 9374 | nla_put_failure: |
| 9375 | genlmsg_cancel(msg, hdr); |
| 9376 | nlmsg_free(msg); |
| 9377 | return -ENOBUFS; |
| 9378 | } |
| 9379 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9380 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9381 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9382 | const u8 *buf, size_t len, bool ack, |
| 9383 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9384 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9385 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9386 | struct sk_buff *msg; |
| 9387 | void *hdr; |
| 9388 | |
| 9389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9390 | if (!msg) |
| 9391 | return; |
| 9392 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9393 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9394 | if (!hdr) { |
| 9395 | nlmsg_free(msg); |
| 9396 | return; |
| 9397 | } |
| 9398 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9399 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9400 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9401 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9402 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9403 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9404 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9405 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9406 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9407 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9408 | |
| 9409 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9410 | return; |
| 9411 | |
| 9412 | nla_put_failure: |
| 9413 | genlmsg_cancel(msg, hdr); |
| 9414 | nlmsg_free(msg); |
| 9415 | } |
| 9416 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9417 | void |
| 9418 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9419 | struct net_device *netdev, |
| 9420 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9421 | gfp_t gfp) |
| 9422 | { |
| 9423 | struct sk_buff *msg; |
| 9424 | struct nlattr *pinfoattr; |
| 9425 | void *hdr; |
| 9426 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9427 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9428 | if (!msg) |
| 9429 | return; |
| 9430 | |
| 9431 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9432 | if (!hdr) { |
| 9433 | nlmsg_free(msg); |
| 9434 | return; |
| 9435 | } |
| 9436 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9437 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9438 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9439 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9440 | |
| 9441 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9442 | if (!pinfoattr) |
| 9443 | goto nla_put_failure; |
| 9444 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9445 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9446 | rssi_event)) |
| 9447 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9448 | |
| 9449 | nla_nest_end(msg, pinfoattr); |
| 9450 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9451 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9452 | |
| 9453 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9454 | nl80211_mlme_mcgrp.id, gfp); |
| 9455 | return; |
| 9456 | |
| 9457 | nla_put_failure: |
| 9458 | genlmsg_cancel(msg, hdr); |
| 9459 | nlmsg_free(msg); |
| 9460 | } |
| 9461 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9462 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9463 | struct net_device *netdev, const u8 *bssid, |
| 9464 | const u8 *replay_ctr, gfp_t gfp) |
| 9465 | { |
| 9466 | struct sk_buff *msg; |
| 9467 | struct nlattr *rekey_attr; |
| 9468 | void *hdr; |
| 9469 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9471 | if (!msg) |
| 9472 | return; |
| 9473 | |
| 9474 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9475 | if (!hdr) { |
| 9476 | nlmsg_free(msg); |
| 9477 | return; |
| 9478 | } |
| 9479 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9480 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9481 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9482 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9483 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9484 | |
| 9485 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9486 | if (!rekey_attr) |
| 9487 | goto nla_put_failure; |
| 9488 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9489 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9490 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9491 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9492 | |
| 9493 | nla_nest_end(msg, rekey_attr); |
| 9494 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9495 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9496 | |
| 9497 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9498 | nl80211_mlme_mcgrp.id, gfp); |
| 9499 | return; |
| 9500 | |
| 9501 | nla_put_failure: |
| 9502 | genlmsg_cancel(msg, hdr); |
| 9503 | nlmsg_free(msg); |
| 9504 | } |
| 9505 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9506 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9507 | struct net_device *netdev, int index, |
| 9508 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9509 | { |
| 9510 | struct sk_buff *msg; |
| 9511 | struct nlattr *attr; |
| 9512 | void *hdr; |
| 9513 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9514 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9515 | if (!msg) |
| 9516 | return; |
| 9517 | |
| 9518 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9519 | if (!hdr) { |
| 9520 | nlmsg_free(msg); |
| 9521 | return; |
| 9522 | } |
| 9523 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9524 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9525 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9526 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9527 | |
| 9528 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9529 | if (!attr) |
| 9530 | goto nla_put_failure; |
| 9531 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9532 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9533 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9534 | (preauth && |
| 9535 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9536 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9537 | |
| 9538 | nla_nest_end(msg, attr); |
| 9539 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9540 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9541 | |
| 9542 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9543 | nl80211_mlme_mcgrp.id, gfp); |
| 9544 | return; |
| 9545 | |
| 9546 | nla_put_failure: |
| 9547 | genlmsg_cancel(msg, hdr); |
| 9548 | nlmsg_free(msg); |
| 9549 | } |
| 9550 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9551 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9552 | struct net_device *netdev, |
| 9553 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9554 | { |
| 9555 | struct sk_buff *msg; |
| 9556 | void *hdr; |
| 9557 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9558 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9559 | if (!msg) |
| 9560 | return; |
| 9561 | |
| 9562 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9563 | if (!hdr) { |
| 9564 | nlmsg_free(msg); |
| 9565 | return; |
| 9566 | } |
| 9567 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9568 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9569 | goto nla_put_failure; |
| 9570 | |
| 9571 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9572 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9573 | |
| 9574 | genlmsg_end(msg, hdr); |
| 9575 | |
| 9576 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9577 | nl80211_mlme_mcgrp.id, gfp); |
| 9578 | return; |
| 9579 | |
| 9580 | nla_put_failure: |
| 9581 | genlmsg_cancel(msg, hdr); |
| 9582 | nlmsg_free(msg); |
| 9583 | } |
| 9584 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9585 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9586 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9587 | struct net_device *netdev, const u8 *peer, |
| 9588 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9589 | { |
| 9590 | struct sk_buff *msg; |
| 9591 | struct nlattr *pinfoattr; |
| 9592 | void *hdr; |
| 9593 | |
| 9594 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9595 | if (!msg) |
| 9596 | return; |
| 9597 | |
| 9598 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9599 | if (!hdr) { |
| 9600 | nlmsg_free(msg); |
| 9601 | return; |
| 9602 | } |
| 9603 | |
| 9604 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9605 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9606 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9607 | goto nla_put_failure; |
| 9608 | |
| 9609 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9610 | if (!pinfoattr) |
| 9611 | goto nla_put_failure; |
| 9612 | |
| 9613 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9614 | goto nla_put_failure; |
| 9615 | |
| 9616 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9617 | goto nla_put_failure; |
| 9618 | |
| 9619 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9620 | goto nla_put_failure; |
| 9621 | |
| 9622 | nla_nest_end(msg, pinfoattr); |
| 9623 | |
| 9624 | genlmsg_end(msg, hdr); |
| 9625 | |
| 9626 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9627 | nl80211_mlme_mcgrp.id, gfp); |
| 9628 | return; |
| 9629 | |
| 9630 | nla_put_failure: |
| 9631 | genlmsg_cancel(msg, hdr); |
| 9632 | nlmsg_free(msg); |
| 9633 | } |
| 9634 | |
| 9635 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9636 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 9637 | struct cfg80211_chan_def *chandef, |
| 9638 | enum nl80211_radar_event event, |
| 9639 | struct net_device *netdev, gfp_t gfp) |
| 9640 | { |
| 9641 | struct sk_buff *msg; |
| 9642 | void *hdr; |
| 9643 | |
| 9644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9645 | if (!msg) |
| 9646 | return; |
| 9647 | |
| 9648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 9649 | if (!hdr) { |
| 9650 | nlmsg_free(msg); |
| 9651 | return; |
| 9652 | } |
| 9653 | |
| 9654 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9655 | goto nla_put_failure; |
| 9656 | |
| 9657 | /* NOP and radar events don't need a netdev parameter */ |
| 9658 | if (netdev) { |
| 9659 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 9660 | |
| 9661 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9662 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9663 | goto nla_put_failure; |
| 9664 | } |
| 9665 | |
| 9666 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 9667 | goto nla_put_failure; |
| 9668 | |
| 9669 | if (nl80211_send_chandef(msg, chandef)) |
| 9670 | goto nla_put_failure; |
| 9671 | |
| 9672 | if (genlmsg_end(msg, hdr) < 0) { |
| 9673 | nlmsg_free(msg); |
| 9674 | return; |
| 9675 | } |
| 9676 | |
| 9677 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9678 | nl80211_mlme_mcgrp.id, gfp); |
| 9679 | return; |
| 9680 | |
| 9681 | nla_put_failure: |
| 9682 | genlmsg_cancel(msg, hdr); |
| 9683 | nlmsg_free(msg); |
| 9684 | } |
| 9685 | |
| 9686 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9687 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9688 | struct net_device *netdev, const u8 *peer, |
| 9689 | u32 num_packets, gfp_t gfp) |
| 9690 | { |
| 9691 | struct sk_buff *msg; |
| 9692 | struct nlattr *pinfoattr; |
| 9693 | void *hdr; |
| 9694 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9695 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9696 | if (!msg) |
| 9697 | return; |
| 9698 | |
| 9699 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9700 | if (!hdr) { |
| 9701 | nlmsg_free(msg); |
| 9702 | return; |
| 9703 | } |
| 9704 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9707 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9708 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9709 | |
| 9710 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9711 | if (!pinfoattr) |
| 9712 | goto nla_put_failure; |
| 9713 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9714 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9715 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9716 | |
| 9717 | nla_nest_end(msg, pinfoattr); |
| 9718 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9719 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9720 | |
| 9721 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9722 | nl80211_mlme_mcgrp.id, gfp); |
| 9723 | return; |
| 9724 | |
| 9725 | nla_put_failure: |
| 9726 | genlmsg_cancel(msg, hdr); |
| 9727 | nlmsg_free(msg); |
| 9728 | } |
| 9729 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9730 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9731 | u64 cookie, bool acked, gfp_t gfp) |
| 9732 | { |
| 9733 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9734 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9735 | struct sk_buff *msg; |
| 9736 | void *hdr; |
| 9737 | int err; |
| 9738 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9739 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9740 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9741 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9742 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9743 | if (!msg) |
| 9744 | return; |
| 9745 | |
| 9746 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9747 | if (!hdr) { |
| 9748 | nlmsg_free(msg); |
| 9749 | return; |
| 9750 | } |
| 9751 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9753 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9754 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9755 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9756 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9757 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9758 | |
| 9759 | err = genlmsg_end(msg, hdr); |
| 9760 | if (err < 0) { |
| 9761 | nlmsg_free(msg); |
| 9762 | return; |
| 9763 | } |
| 9764 | |
| 9765 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9766 | nl80211_mlme_mcgrp.id, gfp); |
| 9767 | return; |
| 9768 | |
| 9769 | nla_put_failure: |
| 9770 | genlmsg_cancel(msg, hdr); |
| 9771 | nlmsg_free(msg); |
| 9772 | } |
| 9773 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9774 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9775 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9776 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9777 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9778 | { |
| 9779 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9780 | struct sk_buff *msg; |
| 9781 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9782 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9783 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9784 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9785 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9786 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9787 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9788 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9789 | if (!msg) { |
| 9790 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9791 | return; |
| 9792 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9793 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9794 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9795 | if (!hdr) |
| 9796 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9797 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9798 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9799 | (freq && |
| 9800 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9801 | (sig_dbm && |
| 9802 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9803 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9804 | goto nla_put_failure; |
| 9805 | |
| 9806 | genlmsg_end(msg, hdr); |
| 9807 | |
| 9808 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9809 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9810 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9811 | return; |
| 9812 | |
| 9813 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9814 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9815 | if (hdr) |
| 9816 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9817 | nlmsg_free(msg); |
| 9818 | } |
| 9819 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9820 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9821 | #ifdef CONFIG_PM |
| 9822 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9823 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9824 | gfp_t gfp) |
| 9825 | { |
| 9826 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9827 | struct sk_buff *msg; |
| 9828 | void *hdr; |
| 9829 | int err, size = 200; |
| 9830 | |
| 9831 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9832 | |
| 9833 | if (wakeup) |
| 9834 | size += wakeup->packet_present_len; |
| 9835 | |
| 9836 | msg = nlmsg_new(size, gfp); |
| 9837 | if (!msg) |
| 9838 | return; |
| 9839 | |
| 9840 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9841 | if (!hdr) |
| 9842 | goto free_msg; |
| 9843 | |
| 9844 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9845 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9846 | goto free_msg; |
| 9847 | |
| 9848 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9849 | wdev->netdev->ifindex)) |
| 9850 | goto free_msg; |
| 9851 | |
| 9852 | if (wakeup) { |
| 9853 | struct nlattr *reasons; |
| 9854 | |
| 9855 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9856 | |
| 9857 | if (wakeup->disconnect && |
| 9858 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9859 | goto free_msg; |
| 9860 | if (wakeup->magic_pkt && |
| 9861 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9862 | goto free_msg; |
| 9863 | if (wakeup->gtk_rekey_failure && |
| 9864 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9865 | goto free_msg; |
| 9866 | if (wakeup->eap_identity_req && |
| 9867 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9868 | goto free_msg; |
| 9869 | if (wakeup->four_way_handshake && |
| 9870 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9871 | goto free_msg; |
| 9872 | if (wakeup->rfkill_release && |
| 9873 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9874 | goto free_msg; |
| 9875 | |
| 9876 | if (wakeup->pattern_idx >= 0 && |
| 9877 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9878 | wakeup->pattern_idx)) |
| 9879 | goto free_msg; |
| 9880 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9881 | if (wakeup->tcp_match) |
| 9882 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 9883 | |
| 9884 | if (wakeup->tcp_connlost) |
| 9885 | nla_put_flag(msg, |
| 9886 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 9887 | |
| 9888 | if (wakeup->tcp_nomoretokens) |
| 9889 | nla_put_flag(msg, |
| 9890 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 9891 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9892 | if (wakeup->packet) { |
| 9893 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9894 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9895 | |
| 9896 | if (!wakeup->packet_80211) { |
| 9897 | pkt_attr = |
| 9898 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9899 | len_attr = |
| 9900 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9901 | } |
| 9902 | |
| 9903 | if (wakeup->packet_len && |
| 9904 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9905 | goto free_msg; |
| 9906 | |
| 9907 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9908 | wakeup->packet)) |
| 9909 | goto free_msg; |
| 9910 | } |
| 9911 | |
| 9912 | nla_nest_end(msg, reasons); |
| 9913 | } |
| 9914 | |
| 9915 | err = genlmsg_end(msg, hdr); |
| 9916 | if (err < 0) |
| 9917 | goto free_msg; |
| 9918 | |
| 9919 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9920 | nl80211_mlme_mcgrp.id, gfp); |
| 9921 | return; |
| 9922 | |
| 9923 | free_msg: |
| 9924 | nlmsg_free(msg); |
| 9925 | } |
| 9926 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9927 | #endif |
| 9928 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9929 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9930 | enum nl80211_tdls_operation oper, |
| 9931 | u16 reason_code, gfp_t gfp) |
| 9932 | { |
| 9933 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9934 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9935 | struct sk_buff *msg; |
| 9936 | void *hdr; |
| 9937 | int err; |
| 9938 | |
| 9939 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9940 | reason_code); |
| 9941 | |
| 9942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9943 | if (!msg) |
| 9944 | return; |
| 9945 | |
| 9946 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9947 | if (!hdr) { |
| 9948 | nlmsg_free(msg); |
| 9949 | return; |
| 9950 | } |
| 9951 | |
| 9952 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9953 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9954 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9955 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9956 | (reason_code > 0 && |
| 9957 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9958 | goto nla_put_failure; |
| 9959 | |
| 9960 | err = genlmsg_end(msg, hdr); |
| 9961 | if (err < 0) { |
| 9962 | nlmsg_free(msg); |
| 9963 | return; |
| 9964 | } |
| 9965 | |
| 9966 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9967 | nl80211_mlme_mcgrp.id, gfp); |
| 9968 | return; |
| 9969 | |
| 9970 | nla_put_failure: |
| 9971 | genlmsg_cancel(msg, hdr); |
| 9972 | nlmsg_free(msg); |
| 9973 | } |
| 9974 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9975 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9976 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9977 | unsigned long state, |
| 9978 | void *_notify) |
| 9979 | { |
| 9980 | struct netlink_notify *notify = _notify; |
| 9981 | struct cfg80211_registered_device *rdev; |
| 9982 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9983 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9984 | |
| 9985 | if (state != NETLINK_URELEASE) |
| 9986 | return NOTIFY_DONE; |
| 9987 | |
| 9988 | rcu_read_lock(); |
| 9989 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9990 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9991 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9992 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9993 | |
| 9994 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9995 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9996 | list) { |
| 9997 | if (reg->nlportid == notify->portid) { |
| 9998 | list_del(®->list); |
| 9999 | kfree(reg); |
| 10000 | break; |
| 10001 | } |
| 10002 | } |
| 10003 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10004 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10005 | |
| 10006 | rcu_read_unlock(); |
| 10007 | |
| 10008 | return NOTIFY_DONE; |
| 10009 | } |
| 10010 | |
| 10011 | static struct notifier_block nl80211_netlink_notifier = { |
| 10012 | .notifier_call = nl80211_netlink_notify, |
| 10013 | }; |
| 10014 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10015 | /* initialisation/exit functions */ |
| 10016 | |
| 10017 | int nl80211_init(void) |
| 10018 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10019 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10020 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10021 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10022 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10023 | if (err) |
| 10024 | return err; |
| 10025 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10026 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10027 | if (err) |
| 10028 | goto err_out; |
| 10029 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10030 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10031 | if (err) |
| 10032 | goto err_out; |
| 10033 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10034 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10035 | if (err) |
| 10036 | goto err_out; |
| 10037 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10038 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10039 | if (err) |
| 10040 | goto err_out; |
| 10041 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10042 | #ifdef CONFIG_NL80211_TESTMODE |
| 10043 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10044 | if (err) |
| 10045 | goto err_out; |
| 10046 | #endif |
| 10047 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10048 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10049 | if (err) |
| 10050 | goto err_out; |
| 10051 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10052 | return 0; |
| 10053 | err_out: |
| 10054 | genl_unregister_family(&nl80211_fam); |
| 10055 | return err; |
| 10056 | } |
| 10057 | |
| 10058 | void nl80211_exit(void) |
| 10059 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10060 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10061 | genl_unregister_family(&nl80211_fam); |
| 10062 | } |