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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 25 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 26 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 49 | /* returns ERR_PTR values */ |
| 50 | static struct wireless_dev * |
| 51 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 53 | struct cfg80211_registered_device *rdev; |
| 54 | struct wireless_dev *result = NULL; |
| 55 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 56 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 57 | u64 wdev_id; |
| 58 | int wiphy_idx = -1; |
| 59 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 63 | if (!have_ifidx && !have_wdev_id) |
| 64 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 65 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 66 | if (have_ifidx) |
| 67 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 68 | if (have_wdev_id) { |
| 69 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 70 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 74 | struct wireless_dev *wdev; |
| 75 | |
| 76 | if (wiphy_net(&rdev->wiphy) != netns) |
| 77 | continue; |
| 78 | |
| 79 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 80 | continue; |
| 81 | |
| 82 | mutex_lock(&rdev->devlist_mtx); |
| 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | mutex_unlock(&rdev->devlist_mtx); |
| 95 | |
| 96 | if (result) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | if (result) |
| 101 | return result; |
| 102 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 105 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 106 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 107 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 108 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 109 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 110 | |
| 111 | assert_cfg80211_lock(); |
| 112 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 113 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 114 | !attrs[NL80211_ATTR_IFINDEX] && |
| 115 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 116 | return ERR_PTR(-EINVAL); |
| 117 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 118 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 119 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 122 | if (attrs[NL80211_ATTR_WDEV]) { |
| 123 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 124 | struct wireless_dev *wdev; |
| 125 | bool found = false; |
| 126 | |
| 127 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 128 | if (tmp) { |
| 129 | /* make sure wdev exists */ |
| 130 | mutex_lock(&tmp->devlist_mtx); |
| 131 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 132 | if (wdev->identifier != (u32)wdev_id) |
| 133 | continue; |
| 134 | found = true; |
| 135 | break; |
| 136 | } |
| 137 | mutex_unlock(&tmp->devlist_mtx); |
| 138 | |
| 139 | if (!found) |
| 140 | tmp = NULL; |
| 141 | |
| 142 | if (rdev && tmp != rdev) |
| 143 | return ERR_PTR(-EINVAL); |
| 144 | rdev = tmp; |
| 145 | } |
| 146 | } |
| 147 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 148 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 149 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 150 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 151 | if (netdev) { |
| 152 | if (netdev->ieee80211_ptr) |
| 153 | tmp = wiphy_to_dev( |
| 154 | netdev->ieee80211_ptr->wiphy); |
| 155 | else |
| 156 | tmp = NULL; |
| 157 | |
| 158 | dev_put(netdev); |
| 159 | |
| 160 | /* not wireless device -- return error */ |
| 161 | if (!tmp) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | |
| 164 | /* mismatch -- return error */ |
| 165 | if (rdev && tmp != rdev) |
| 166 | return ERR_PTR(-EINVAL); |
| 167 | |
| 168 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 169 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (!rdev) |
| 173 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 174 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 175 | if (netns != wiphy_net(&rdev->wiphy)) |
| 176 | return ERR_PTR(-ENODEV); |
| 177 | |
| 178 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This function returns a pointer to the driver |
| 183 | * that the genl_info item that is passed refers to. |
| 184 | * If successful, it returns non-NULL and also locks |
| 185 | * the driver's mutex! |
| 186 | * |
| 187 | * This means that you need to call cfg80211_unlock_rdev() |
| 188 | * before being allowed to acquire &cfg80211_mutex! |
| 189 | * |
| 190 | * This is necessary because we need to lock the global |
| 191 | * mutex to get an item off the list safely, and then |
| 192 | * we lock the rdev mutex so it doesn't go away under us. |
| 193 | * |
| 194 | * We don't want to keep cfg80211_mutex locked |
| 195 | * for all the time in order to allow requests on |
| 196 | * other interfaces to go through at the same time. |
| 197 | * |
| 198 | * The result of this can be a PTR_ERR and hence must |
| 199 | * be checked with IS_ERR() for errors. |
| 200 | */ |
| 201 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 202 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | { |
| 204 | struct cfg80211_registered_device *rdev; |
| 205 | |
| 206 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 207 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | |
| 209 | /* if it is not an error we grab the lock on |
| 210 | * it to assure it won't be going away while |
| 211 | * we operate on it */ |
| 212 | if (!IS_ERR(rdev)) |
| 213 | mutex_lock(&rdev->mtx); |
| 214 | |
| 215 | mutex_unlock(&cfg80211_mutex); |
| 216 | |
| 217 | return rdev; |
| 218 | } |
| 219 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 221 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 222 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 224 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 226 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 232 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 234 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 238 | |
| 239 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 240 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 244 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 245 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 248 | .len = WLAN_MAX_KEY_LEN }, |
| 249 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 250 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 252 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 254 | |
| 255 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 256 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 258 | .len = IEEE80211_MAX_DATA_LEN }, |
| 259 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 260 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 262 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 264 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 265 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 268 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 269 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 270 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 272 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 273 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 274 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 275 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 277 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 279 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 280 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 282 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 283 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 284 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 285 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 289 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 291 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 292 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 293 | |
| 294 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 295 | .len = IEEE80211_MAX_SSID_LEN }, |
| 296 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 297 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_STA_FLAGS2] = { |
| 302 | .len = sizeof(struct nl80211_sta_flag_update), |
| 303 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 304 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 306 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 308 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 311 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 313 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 314 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 318 | .len = IEEE80211_MAX_DATA_LEN }, |
| 319 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 322 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 323 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 325 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 327 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 328 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 335 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 339 | .len = IEEE80211_MAX_DATA_LEN }, |
| 340 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 341 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 342 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 343 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 344 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 345 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 346 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 349 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 350 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 352 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 353 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 354 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 355 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 356 | .len = NL80211_HT_CAPABILITY_LEN |
| 357 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 358 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 359 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 361 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 362 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 363 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 364 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 365 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 367 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 368 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 369 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 370 | }; |
| 371 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 372 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 373 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 374 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 375 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 376 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 377 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 379 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 380 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 381 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 382 | }; |
| 383 | |
| 384 | /* policy for the key default flags */ |
| 385 | static const struct nla_policy |
| 386 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 387 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 388 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 389 | }; |
| 390 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 391 | /* policy for WoWLAN attributes */ |
| 392 | static const struct nla_policy |
| 393 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 394 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 395 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 396 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 397 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 398 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 399 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 400 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 401 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 402 | }; |
| 403 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 404 | /* policy for GTK rekey offload attributes */ |
| 405 | static const struct nla_policy |
| 406 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 407 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 408 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 409 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 410 | }; |
| 411 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 412 | static const struct nla_policy |
| 413 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 414 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 415 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 416 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 417 | }; |
| 418 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 419 | /* ifidx get helper */ |
| 420 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 421 | { |
| 422 | int res; |
| 423 | |
| 424 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 425 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 426 | nl80211_policy); |
| 427 | if (res) |
| 428 | return res; |
| 429 | |
| 430 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 431 | return -EINVAL; |
| 432 | |
| 433 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 434 | if (!res) |
| 435 | return -EINVAL; |
| 436 | return res; |
| 437 | } |
| 438 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 439 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 440 | struct netlink_callback *cb, |
| 441 | struct cfg80211_registered_device **rdev, |
| 442 | struct net_device **dev) |
| 443 | { |
| 444 | int ifidx = cb->args[0]; |
| 445 | int err; |
| 446 | |
| 447 | if (!ifidx) |
| 448 | ifidx = nl80211_get_ifidx(cb); |
| 449 | if (ifidx < 0) |
| 450 | return ifidx; |
| 451 | |
| 452 | cb->args[0] = ifidx; |
| 453 | |
| 454 | rtnl_lock(); |
| 455 | |
| 456 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 457 | if (!*dev) { |
| 458 | err = -ENODEV; |
| 459 | goto out_rtnl; |
| 460 | } |
| 461 | |
| 462 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 463 | if (IS_ERR(*rdev)) { |
| 464 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 465 | goto out_rtnl; |
| 466 | } |
| 467 | |
| 468 | return 0; |
| 469 | out_rtnl: |
| 470 | rtnl_unlock(); |
| 471 | return err; |
| 472 | } |
| 473 | |
| 474 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 475 | { |
| 476 | cfg80211_unlock_rdev(rdev); |
| 477 | rtnl_unlock(); |
| 478 | } |
| 479 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 480 | /* IE validation */ |
| 481 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 482 | { |
| 483 | const u8 *pos; |
| 484 | int len; |
| 485 | |
| 486 | if (!attr) |
| 487 | return true; |
| 488 | |
| 489 | pos = nla_data(attr); |
| 490 | len = nla_len(attr); |
| 491 | |
| 492 | while (len) { |
| 493 | u8 elemlen; |
| 494 | |
| 495 | if (len < 2) |
| 496 | return false; |
| 497 | len -= 2; |
| 498 | |
| 499 | elemlen = pos[1]; |
| 500 | if (elemlen > len) |
| 501 | return false; |
| 502 | |
| 503 | len -= elemlen; |
| 504 | pos += 2 + elemlen; |
| 505 | } |
| 506 | |
| 507 | return true; |
| 508 | } |
| 509 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 510 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 511 | 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] | 512 | int flags, u8 cmd) |
| 513 | { |
| 514 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 515 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 518 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 519 | struct ieee80211_channel *chan) |
| 520 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 521 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 522 | chan->center_freq)) |
| 523 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 524 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 525 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 526 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 527 | goto nla_put_failure; |
| 528 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 529 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 530 | goto nla_put_failure; |
| 531 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 532 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 533 | goto nla_put_failure; |
| 534 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 535 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 536 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 537 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 538 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 539 | DBM_TO_MBM(chan->max_power))) |
| 540 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 541 | |
| 542 | return 0; |
| 543 | |
| 544 | nla_put_failure: |
| 545 | return -ENOBUFS; |
| 546 | } |
| 547 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 548 | /* netlink command implementations */ |
| 549 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 550 | struct key_parse { |
| 551 | struct key_params p; |
| 552 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 553 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 554 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 555 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 556 | }; |
| 557 | |
| 558 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 559 | { |
| 560 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 561 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 562 | nl80211_key_policy); |
| 563 | if (err) |
| 564 | return err; |
| 565 | |
| 566 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 567 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 568 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 569 | if (k->def) { |
| 570 | k->def_uni = true; |
| 571 | k->def_multi = true; |
| 572 | } |
| 573 | if (k->defmgmt) |
| 574 | k->def_multi = true; |
| 575 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 576 | if (tb[NL80211_KEY_IDX]) |
| 577 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 578 | |
| 579 | if (tb[NL80211_KEY_DATA]) { |
| 580 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 581 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 582 | } |
| 583 | |
| 584 | if (tb[NL80211_KEY_SEQ]) { |
| 585 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 586 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 587 | } |
| 588 | |
| 589 | if (tb[NL80211_KEY_CIPHER]) |
| 590 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 591 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 592 | if (tb[NL80211_KEY_TYPE]) { |
| 593 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 594 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 595 | return -EINVAL; |
| 596 | } |
| 597 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 598 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 599 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 600 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 601 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 602 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 603 | if (err) |
| 604 | return err; |
| 605 | |
| 606 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 607 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 608 | } |
| 609 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 614 | { |
| 615 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 616 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 617 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 618 | } |
| 619 | |
| 620 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 621 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 622 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 623 | } |
| 624 | |
| 625 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 626 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 627 | |
| 628 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 629 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 630 | |
| 631 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 632 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 633 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 634 | if (k->def) { |
| 635 | k->def_uni = true; |
| 636 | k->def_multi = true; |
| 637 | } |
| 638 | if (k->defmgmt) |
| 639 | k->def_multi = true; |
| 640 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 641 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 642 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 643 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 644 | return -EINVAL; |
| 645 | } |
| 646 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 647 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 648 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 649 | int err = nla_parse_nested( |
| 650 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 651 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 652 | nl80211_key_default_policy); |
| 653 | if (err) |
| 654 | return err; |
| 655 | |
| 656 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 657 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 658 | } |
| 659 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 664 | { |
| 665 | int err; |
| 666 | |
| 667 | memset(k, 0, sizeof(*k)); |
| 668 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 669 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 670 | |
| 671 | if (info->attrs[NL80211_ATTR_KEY]) |
| 672 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 673 | else |
| 674 | err = nl80211_parse_key_old(info, k); |
| 675 | |
| 676 | if (err) |
| 677 | return err; |
| 678 | |
| 679 | if (k->def && k->defmgmt) |
| 680 | return -EINVAL; |
| 681 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 682 | if (k->defmgmt) { |
| 683 | if (k->def_uni || !k->def_multi) |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 687 | if (k->idx != -1) { |
| 688 | if (k->defmgmt) { |
| 689 | if (k->idx < 4 || k->idx > 5) |
| 690 | return -EINVAL; |
| 691 | } else if (k->def) { |
| 692 | if (k->idx < 0 || k->idx > 3) |
| 693 | return -EINVAL; |
| 694 | } else { |
| 695 | if (k->idx < 0 || k->idx > 5) |
| 696 | return -EINVAL; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 703 | static struct cfg80211_cached_keys * |
| 704 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 705 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 706 | { |
| 707 | struct key_parse parse; |
| 708 | struct nlattr *key; |
| 709 | struct cfg80211_cached_keys *result; |
| 710 | int rem, err, def = 0; |
| 711 | |
| 712 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 713 | if (!result) |
| 714 | return ERR_PTR(-ENOMEM); |
| 715 | |
| 716 | result->def = -1; |
| 717 | result->defmgmt = -1; |
| 718 | |
| 719 | nla_for_each_nested(key, keys, rem) { |
| 720 | memset(&parse, 0, sizeof(parse)); |
| 721 | parse.idx = -1; |
| 722 | |
| 723 | err = nl80211_parse_key_new(key, &parse); |
| 724 | if (err) |
| 725 | goto error; |
| 726 | err = -EINVAL; |
| 727 | if (!parse.p.key) |
| 728 | goto error; |
| 729 | if (parse.idx < 0 || parse.idx > 4) |
| 730 | goto error; |
| 731 | if (parse.def) { |
| 732 | if (def) |
| 733 | goto error; |
| 734 | def = 1; |
| 735 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 736 | if (!parse.def_uni || !parse.def_multi) |
| 737 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 738 | } else if (parse.defmgmt) |
| 739 | goto error; |
| 740 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 741 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 742 | if (err) |
| 743 | goto error; |
| 744 | result->params[parse.idx].cipher = parse.p.cipher; |
| 745 | result->params[parse.idx].key_len = parse.p.key_len; |
| 746 | result->params[parse.idx].key = result->data[parse.idx]; |
| 747 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 748 | |
| 749 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 750 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 751 | if (no_ht) |
| 752 | *no_ht = true; |
| 753 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | return result; |
| 757 | error: |
| 758 | kfree(result); |
| 759 | return ERR_PTR(err); |
| 760 | } |
| 761 | |
| 762 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 763 | { |
| 764 | ASSERT_WDEV_LOCK(wdev); |
| 765 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 766 | switch (wdev->iftype) { |
| 767 | case NL80211_IFTYPE_AP: |
| 768 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 769 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 770 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 771 | break; |
| 772 | case NL80211_IFTYPE_ADHOC: |
| 773 | if (!wdev->current_bss) |
| 774 | return -ENOLINK; |
| 775 | break; |
| 776 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 777 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 778 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 779 | return -ENOLINK; |
| 780 | break; |
| 781 | default: |
| 782 | return -EINVAL; |
| 783 | } |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 788 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 789 | { |
| 790 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 791 | int i; |
| 792 | |
| 793 | if (!nl_modes) |
| 794 | goto nla_put_failure; |
| 795 | |
| 796 | i = 0; |
| 797 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 798 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 799 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 800 | ifmodes >>= 1; |
| 801 | i++; |
| 802 | } |
| 803 | |
| 804 | nla_nest_end(msg, nl_modes); |
| 805 | return 0; |
| 806 | |
| 807 | nla_put_failure: |
| 808 | return -ENOBUFS; |
| 809 | } |
| 810 | |
| 811 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 812 | struct sk_buff *msg) |
| 813 | { |
| 814 | struct nlattr *nl_combis; |
| 815 | int i, j; |
| 816 | |
| 817 | nl_combis = nla_nest_start(msg, |
| 818 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 819 | if (!nl_combis) |
| 820 | goto nla_put_failure; |
| 821 | |
| 822 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 823 | const struct ieee80211_iface_combination *c; |
| 824 | struct nlattr *nl_combi, *nl_limits; |
| 825 | |
| 826 | c = &wiphy->iface_combinations[i]; |
| 827 | |
| 828 | nl_combi = nla_nest_start(msg, i + 1); |
| 829 | if (!nl_combi) |
| 830 | goto nla_put_failure; |
| 831 | |
| 832 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 833 | if (!nl_limits) |
| 834 | goto nla_put_failure; |
| 835 | |
| 836 | for (j = 0; j < c->n_limits; j++) { |
| 837 | struct nlattr *nl_limit; |
| 838 | |
| 839 | nl_limit = nla_nest_start(msg, j + 1); |
| 840 | if (!nl_limit) |
| 841 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 842 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 843 | c->limits[j].max)) |
| 844 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 845 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 846 | c->limits[j].types)) |
| 847 | goto nla_put_failure; |
| 848 | nla_nest_end(msg, nl_limit); |
| 849 | } |
| 850 | |
| 851 | nla_nest_end(msg, nl_limits); |
| 852 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 853 | if (c->beacon_int_infra_match && |
| 854 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 855 | goto nla_put_failure; |
| 856 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 857 | c->num_different_channels) || |
| 858 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 859 | c->max_interfaces)) |
| 860 | goto nla_put_failure; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 861 | if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 862 | c->radar_detect_widths)) |
| 863 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 864 | |
| 865 | nla_nest_end(msg, nl_combi); |
| 866 | } |
| 867 | |
| 868 | nla_nest_end(msg, nl_combis); |
| 869 | |
| 870 | return 0; |
| 871 | nla_put_failure: |
| 872 | return -ENOBUFS; |
| 873 | } |
| 874 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 875 | 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] | 876 | struct cfg80211_registered_device *dev) |
| 877 | { |
| 878 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 879 | struct nlattr *nl_bands, *nl_band; |
| 880 | struct nlattr *nl_freqs, *nl_freq; |
| 881 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 882 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 883 | enum ieee80211_band band; |
| 884 | struct ieee80211_channel *chan; |
| 885 | struct ieee80211_rate *rate; |
| 886 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 887 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 888 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 889 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 890 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 891 | if (!hdr) |
| 892 | return -1; |
| 893 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 894 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 895 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 896 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 897 | cfg80211_rdev_list_generation) || |
| 898 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 899 | dev->wiphy.retry_short) || |
| 900 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 901 | dev->wiphy.retry_long) || |
| 902 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 903 | dev->wiphy.frag_threshold) || |
| 904 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 905 | dev->wiphy.rts_threshold) || |
| 906 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 907 | dev->wiphy.coverage_class) || |
| 908 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 909 | dev->wiphy.max_scan_ssids) || |
| 910 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 911 | dev->wiphy.max_sched_scan_ssids) || |
| 912 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 913 | dev->wiphy.max_scan_ie_len) || |
| 914 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 915 | dev->wiphy.max_sched_scan_ie_len) || |
| 916 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 917 | dev->wiphy.max_match_sets)) |
| 918 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 920 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 921 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 922 | goto nla_put_failure; |
| 923 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 924 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 925 | goto nla_put_failure; |
| 926 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 927 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 928 | goto nla_put_failure; |
| 929 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 930 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 931 | goto nla_put_failure; |
| 932 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 933 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 934 | goto nla_put_failure; |
| 935 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 936 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 937 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 938 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 939 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 940 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 941 | dev->wiphy.cipher_suites)) |
| 942 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 943 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 944 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 945 | dev->wiphy.max_num_pmkids)) |
| 946 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 947 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 948 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 949 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 950 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 951 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 952 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 953 | dev->wiphy.available_antennas_tx) || |
| 954 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 955 | dev->wiphy.available_antennas_rx)) |
| 956 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 957 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 958 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 959 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 960 | dev->wiphy.probe_resp_offload)) |
| 961 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 962 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 963 | if ((dev->wiphy.available_antennas_tx || |
| 964 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 965 | u32 tx_ant = 0, rx_ant = 0; |
| 966 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 967 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 968 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 969 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 970 | tx_ant) || |
| 971 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 972 | rx_ant)) |
| 973 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 977 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 978 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 979 | goto nla_put_failure; |
| 980 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 981 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 982 | if (!nl_bands) |
| 983 | goto nla_put_failure; |
| 984 | |
| 985 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 986 | if (!dev->wiphy.bands[band]) |
| 987 | continue; |
| 988 | |
| 989 | nl_band = nla_nest_start(msg, band); |
| 990 | if (!nl_band) |
| 991 | goto nla_put_failure; |
| 992 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 993 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 994 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 995 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 996 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 997 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 998 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 999 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 1000 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1001 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 1002 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1003 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 1004 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1005 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1006 | /* add VHT info */ |
| 1007 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1008 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1009 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1010 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1011 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1012 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1013 | goto nla_put_failure; |
| 1014 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1015 | /* add frequencies */ |
| 1016 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1017 | if (!nl_freqs) |
| 1018 | goto nla_put_failure; |
| 1019 | |
| 1020 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1021 | nl_freq = nla_nest_start(msg, i); |
| 1022 | if (!nl_freq) |
| 1023 | goto nla_put_failure; |
| 1024 | |
| 1025 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1026 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1027 | if (nl80211_msg_put_channel(msg, chan)) |
| 1028 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1029 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1030 | nla_nest_end(msg, nl_freq); |
| 1031 | } |
| 1032 | |
| 1033 | nla_nest_end(msg, nl_freqs); |
| 1034 | |
| 1035 | /* add bitrates */ |
| 1036 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1037 | if (!nl_rates) |
| 1038 | goto nla_put_failure; |
| 1039 | |
| 1040 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1041 | nl_rate = nla_nest_start(msg, i); |
| 1042 | if (!nl_rate) |
| 1043 | goto nla_put_failure; |
| 1044 | |
| 1045 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1046 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1047 | rate->bitrate)) |
| 1048 | goto nla_put_failure; |
| 1049 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1050 | nla_put_flag(msg, |
| 1051 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1052 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1053 | |
| 1054 | nla_nest_end(msg, nl_rate); |
| 1055 | } |
| 1056 | |
| 1057 | nla_nest_end(msg, nl_rates); |
| 1058 | |
| 1059 | nla_nest_end(msg, nl_band); |
| 1060 | } |
| 1061 | nla_nest_end(msg, nl_bands); |
| 1062 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1063 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1064 | if (!nl_cmds) |
| 1065 | goto nla_put_failure; |
| 1066 | |
| 1067 | i = 0; |
| 1068 | #define CMD(op, n) \ |
| 1069 | do { \ |
| 1070 | if (dev->ops->op) { \ |
| 1071 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1072 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1073 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1074 | } \ |
| 1075 | } while (0) |
| 1076 | |
| 1077 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1078 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1079 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1080 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1081 | CMD(add_station, NEW_STATION); |
| 1082 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1083 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1084 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1085 | CMD(auth, AUTHENTICATE); |
| 1086 | CMD(assoc, ASSOCIATE); |
| 1087 | CMD(deauth, DEAUTHENTICATE); |
| 1088 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1089 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1090 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1091 | CMD(set_pmksa, SET_PMKSA); |
| 1092 | CMD(del_pmksa, DEL_PMKSA); |
| 1093 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1094 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1095 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1096 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1097 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1098 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1099 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1100 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1101 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1102 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1103 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1104 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1105 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1106 | i++; |
| 1107 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1108 | goto nla_put_failure; |
| 1109 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1110 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1111 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1112 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1113 | CMD(tdls_oper, TDLS_OPER); |
| 1114 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1115 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1116 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1117 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1118 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1119 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1120 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1121 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1122 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1123 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1124 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1125 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1126 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1127 | #ifdef CONFIG_NL80211_TESTMODE |
| 1128 | CMD(testmode_cmd, TESTMODE); |
| 1129 | #endif |
| 1130 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1131 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1132 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1133 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1134 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1135 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1136 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1139 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1140 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1141 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1142 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1145 | nla_nest_end(msg, nl_cmds); |
| 1146 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1147 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1148 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1149 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1150 | dev->wiphy.max_remain_on_channel_duration)) |
| 1151 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1152 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1153 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1154 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1155 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1156 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1157 | if (mgmt_stypes) { |
| 1158 | u16 stypes; |
| 1159 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1160 | enum nl80211_iftype ift; |
| 1161 | |
| 1162 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1163 | if (!nl_ifs) |
| 1164 | goto nla_put_failure; |
| 1165 | |
| 1166 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1167 | nl_ftypes = nla_nest_start(msg, ift); |
| 1168 | if (!nl_ftypes) |
| 1169 | goto nla_put_failure; |
| 1170 | i = 0; |
| 1171 | stypes = mgmt_stypes[ift].tx; |
| 1172 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1173 | if ((stypes & 1) && |
| 1174 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1175 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1176 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1177 | stypes >>= 1; |
| 1178 | i++; |
| 1179 | } |
| 1180 | nla_nest_end(msg, nl_ftypes); |
| 1181 | } |
| 1182 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1183 | nla_nest_end(msg, nl_ifs); |
| 1184 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1185 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1186 | if (!nl_ifs) |
| 1187 | goto nla_put_failure; |
| 1188 | |
| 1189 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1190 | nl_ftypes = nla_nest_start(msg, ift); |
| 1191 | if (!nl_ftypes) |
| 1192 | goto nla_put_failure; |
| 1193 | i = 0; |
| 1194 | stypes = mgmt_stypes[ift].rx; |
| 1195 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1196 | if ((stypes & 1) && |
| 1197 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1198 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1199 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1200 | stypes >>= 1; |
| 1201 | i++; |
| 1202 | } |
| 1203 | nla_nest_end(msg, nl_ftypes); |
| 1204 | } |
| 1205 | nla_nest_end(msg, nl_ifs); |
| 1206 | } |
| 1207 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1208 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1209 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1210 | struct nlattr *nl_wowlan; |
| 1211 | |
| 1212 | nl_wowlan = nla_nest_start(msg, |
| 1213 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1214 | if (!nl_wowlan) |
| 1215 | goto nla_put_failure; |
| 1216 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1217 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1218 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1219 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1220 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1221 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1222 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1223 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1224 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1225 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1226 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1227 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1228 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1229 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1230 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1231 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1232 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1233 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1234 | if (dev->wiphy.wowlan.n_patterns) { |
| 1235 | struct nl80211_wowlan_pattern_support pat = { |
| 1236 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1237 | .min_pattern_len = |
| 1238 | dev->wiphy.wowlan.pattern_min_len, |
| 1239 | .max_pattern_len = |
| 1240 | dev->wiphy.wowlan.pattern_max_len, |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame^] | 1241 | .max_pkt_offset = |
| 1242 | dev->wiphy.wowlan.max_pkt_offset, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1243 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1244 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1245 | sizeof(pat), &pat)) |
| 1246 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | nla_nest_end(msg, nl_wowlan); |
| 1250 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1251 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1252 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1253 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1254 | dev->wiphy.software_iftypes)) |
| 1255 | goto nla_put_failure; |
| 1256 | |
| 1257 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1258 | goto nla_put_failure; |
| 1259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1260 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1261 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1262 | dev->wiphy.ap_sme_capa)) |
| 1263 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1264 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1265 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1266 | dev->wiphy.features)) |
| 1267 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1268 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1269 | if (dev->wiphy.ht_capa_mod_mask && |
| 1270 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1271 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1272 | dev->wiphy.ht_capa_mod_mask)) |
| 1273 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1274 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 1275 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1276 | dev->wiphy.max_acl_mac_addrs && |
| 1277 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1278 | dev->wiphy.max_acl_mac_addrs)) |
| 1279 | goto nla_put_failure; |
| 1280 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1281 | return genlmsg_end(msg, hdr); |
| 1282 | |
| 1283 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1284 | genlmsg_cancel(msg, hdr); |
| 1285 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1289 | { |
| 1290 | int idx = 0; |
| 1291 | int start = cb->args[0]; |
| 1292 | struct cfg80211_registered_device *dev; |
| 1293 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1294 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1295 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1296 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1297 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1298 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1299 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1300 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1301 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1302 | dev) < 0) { |
| 1303 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1304 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1305 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1306 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1307 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1308 | |
| 1309 | cb->args[0] = idx; |
| 1310 | |
| 1311 | return skb->len; |
| 1312 | } |
| 1313 | |
| 1314 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1315 | { |
| 1316 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1317 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1318 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1319 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1320 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1321 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1322 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1323 | 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] | 1324 | nlmsg_free(msg); |
| 1325 | return -ENOBUFS; |
| 1326 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1327 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1328 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1331 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1332 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1333 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1334 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1335 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1336 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1337 | }; |
| 1338 | |
| 1339 | static int parse_txq_params(struct nlattr *tb[], |
| 1340 | struct ieee80211_txq_params *txq_params) |
| 1341 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1342 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1343 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1344 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1345 | return -EINVAL; |
| 1346 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1347 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1348 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1349 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1350 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1351 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1352 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1353 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1354 | return -EINVAL; |
| 1355 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1356 | return 0; |
| 1357 | } |
| 1358 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1359 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1360 | { |
| 1361 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1362 | * You can only set the channel explicitly for WDS interfaces, |
| 1363 | * all others have their channel managed via their respective |
| 1364 | * "establish a connection" command (connect, join, ...) |
| 1365 | * |
| 1366 | * For AP/GO and mesh mode, the channel can be set with the |
| 1367 | * channel userspace API, but is only stored and passed to the |
| 1368 | * low-level driver when the AP starts or the mesh is joined. |
| 1369 | * This is for backward compatibility, userspace can also give |
| 1370 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1371 | * |
| 1372 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1373 | * whatever else is going on, so they have their own special |
| 1374 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1375 | */ |
| 1376 | return !wdev || |
| 1377 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1378 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1379 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1380 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1381 | } |
| 1382 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1383 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1384 | struct genl_info *info, |
| 1385 | struct cfg80211_chan_def *chandef) |
| 1386 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1387 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1388 | |
| 1389 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1390 | return -EINVAL; |
| 1391 | |
| 1392 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1393 | |
| 1394 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1395 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1396 | chandef->center_freq1 = control_freq; |
| 1397 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1398 | |
| 1399 | /* Primary channel not allowed */ |
| 1400 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1401 | return -EINVAL; |
| 1402 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1403 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1404 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1405 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1406 | chantype = nla_get_u32( |
| 1407 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1408 | |
| 1409 | switch (chantype) { |
| 1410 | case NL80211_CHAN_NO_HT: |
| 1411 | case NL80211_CHAN_HT20: |
| 1412 | case NL80211_CHAN_HT40PLUS: |
| 1413 | case NL80211_CHAN_HT40MINUS: |
| 1414 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1415 | chantype); |
| 1416 | break; |
| 1417 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1418 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1419 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1420 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1421 | chandef->width = |
| 1422 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1423 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1424 | chandef->center_freq1 = |
| 1425 | nla_get_u32( |
| 1426 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1427 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1428 | chandef->center_freq2 = |
| 1429 | nla_get_u32( |
| 1430 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1431 | } |
| 1432 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1433 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1434 | return -EINVAL; |
| 1435 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1436 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1437 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1438 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1439 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1443 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1444 | struct wireless_dev *wdev, |
| 1445 | struct genl_info *info) |
| 1446 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1447 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1448 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1449 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1450 | |
| 1451 | if (wdev) |
| 1452 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1453 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1454 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1455 | return -EOPNOTSUPP; |
| 1456 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1457 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1458 | if (result) |
| 1459 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1460 | |
| 1461 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1462 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1463 | case NL80211_IFTYPE_AP: |
| 1464 | case NL80211_IFTYPE_P2P_GO: |
| 1465 | if (wdev->beacon_interval) { |
| 1466 | result = -EBUSY; |
| 1467 | break; |
| 1468 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1469 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1470 | result = -EINVAL; |
| 1471 | break; |
| 1472 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1473 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1474 | result = 0; |
| 1475 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1476 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1477 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1478 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1479 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1480 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1481 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1482 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1483 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1484 | } |
| 1485 | mutex_unlock(&rdev->devlist_mtx); |
| 1486 | |
| 1487 | return result; |
| 1488 | } |
| 1489 | |
| 1490 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1491 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1493 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1494 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1495 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1496 | } |
| 1497 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1498 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1499 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1500 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1501 | struct net_device *dev = info->user_ptr[1]; |
| 1502 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1503 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1504 | |
| 1505 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1506 | return -EINVAL; |
| 1507 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1508 | if (netif_running(dev)) |
| 1509 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1510 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1511 | if (!rdev->ops->set_wds_peer) |
| 1512 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1513 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1514 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1515 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1516 | |
| 1517 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1518 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1522 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1523 | { |
| 1524 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1525 | struct net_device *netdev = NULL; |
| 1526 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1527 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1528 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1529 | u32 changed; |
| 1530 | u8 retry_short = 0, retry_long = 0; |
| 1531 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1532 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1533 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1534 | /* |
| 1535 | * Try to find the wiphy and netdev. Normally this |
| 1536 | * function shouldn't need the netdev, but this is |
| 1537 | * done for backward compatibility -- previously |
| 1538 | * setting the channel was done per wiphy, but now |
| 1539 | * it is per netdev. Previous userland like hostapd |
| 1540 | * also passed a netdev to set_wiphy, so that it is |
| 1541 | * possible to let that go to the right netdev! |
| 1542 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1543 | mutex_lock(&cfg80211_mutex); |
| 1544 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1545 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1546 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1547 | |
| 1548 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1549 | if (netdev && netdev->ieee80211_ptr) { |
| 1550 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1551 | mutex_lock(&rdev->mtx); |
| 1552 | } else |
| 1553 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1556 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1557 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1558 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1559 | if (IS_ERR(rdev)) { |
| 1560 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1561 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1562 | } |
| 1563 | wdev = NULL; |
| 1564 | netdev = NULL; |
| 1565 | result = 0; |
| 1566 | |
| 1567 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1568 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1569 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1570 | |
| 1571 | /* |
| 1572 | * end workaround code, by now the rdev is available |
| 1573 | * and locked, and wdev may or may not be NULL. |
| 1574 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1575 | |
| 1576 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1577 | result = cfg80211_dev_rename( |
| 1578 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1579 | |
| 1580 | mutex_unlock(&cfg80211_mutex); |
| 1581 | |
| 1582 | if (result) |
| 1583 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1584 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1585 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1586 | struct ieee80211_txq_params txq_params; |
| 1587 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1588 | |
| 1589 | if (!rdev->ops->set_txq_params) { |
| 1590 | result = -EOPNOTSUPP; |
| 1591 | goto bad_res; |
| 1592 | } |
| 1593 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1594 | if (!netdev) { |
| 1595 | result = -EINVAL; |
| 1596 | goto bad_res; |
| 1597 | } |
| 1598 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1599 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1600 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1601 | result = -EINVAL; |
| 1602 | goto bad_res; |
| 1603 | } |
| 1604 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1605 | if (!netif_running(netdev)) { |
| 1606 | result = -ENETDOWN; |
| 1607 | goto bad_res; |
| 1608 | } |
| 1609 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1610 | nla_for_each_nested(nl_txq_params, |
| 1611 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1612 | rem_txq_params) { |
| 1613 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1614 | nla_data(nl_txq_params), |
| 1615 | nla_len(nl_txq_params), |
| 1616 | txq_params_policy); |
| 1617 | result = parse_txq_params(tb, &txq_params); |
| 1618 | if (result) |
| 1619 | goto bad_res; |
| 1620 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1621 | result = rdev_set_txq_params(rdev, netdev, |
| 1622 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1623 | if (result) |
| 1624 | goto bad_res; |
| 1625 | } |
| 1626 | } |
| 1627 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1628 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1629 | result = __nl80211_set_channel(rdev, |
| 1630 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1631 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1632 | if (result) |
| 1633 | goto bad_res; |
| 1634 | } |
| 1635 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1636 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1637 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1638 | enum nl80211_tx_power_setting type; |
| 1639 | int idx, mbm = 0; |
| 1640 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1641 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1642 | txp_wdev = NULL; |
| 1643 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1644 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1645 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1646 | goto bad_res; |
| 1647 | } |
| 1648 | |
| 1649 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1650 | type = nla_get_u32(info->attrs[idx]); |
| 1651 | |
| 1652 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1653 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1654 | result = -EINVAL; |
| 1655 | goto bad_res; |
| 1656 | } |
| 1657 | |
| 1658 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1659 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1660 | mbm = nla_get_u32(info->attrs[idx]); |
| 1661 | } |
| 1662 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1663 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1664 | if (result) |
| 1665 | goto bad_res; |
| 1666 | } |
| 1667 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1668 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1669 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1670 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1671 | if ((!rdev->wiphy.available_antennas_tx && |
| 1672 | !rdev->wiphy.available_antennas_rx) || |
| 1673 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1674 | result = -EOPNOTSUPP; |
| 1675 | goto bad_res; |
| 1676 | } |
| 1677 | |
| 1678 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1679 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1680 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1681 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1682 | * available antenna masks, except for the "all" mask */ |
| 1683 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1684 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1685 | result = -EINVAL; |
| 1686 | goto bad_res; |
| 1687 | } |
| 1688 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1689 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1690 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1691 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1692 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1693 | if (result) |
| 1694 | goto bad_res; |
| 1695 | } |
| 1696 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1697 | changed = 0; |
| 1698 | |
| 1699 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1700 | retry_short = nla_get_u8( |
| 1701 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1702 | if (retry_short == 0) { |
| 1703 | result = -EINVAL; |
| 1704 | goto bad_res; |
| 1705 | } |
| 1706 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1707 | } |
| 1708 | |
| 1709 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1710 | retry_long = nla_get_u8( |
| 1711 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1712 | if (retry_long == 0) { |
| 1713 | result = -EINVAL; |
| 1714 | goto bad_res; |
| 1715 | } |
| 1716 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1717 | } |
| 1718 | |
| 1719 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1720 | frag_threshold = nla_get_u32( |
| 1721 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1722 | if (frag_threshold < 256) { |
| 1723 | result = -EINVAL; |
| 1724 | goto bad_res; |
| 1725 | } |
| 1726 | if (frag_threshold != (u32) -1) { |
| 1727 | /* |
| 1728 | * Fragments (apart from the last one) are required to |
| 1729 | * have even length. Make the fragmentation code |
| 1730 | * simpler by stripping LSB should someone try to use |
| 1731 | * odd threshold value. |
| 1732 | */ |
| 1733 | frag_threshold &= ~0x1; |
| 1734 | } |
| 1735 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1736 | } |
| 1737 | |
| 1738 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1739 | rts_threshold = nla_get_u32( |
| 1740 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1741 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1742 | } |
| 1743 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1744 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1745 | coverage_class = nla_get_u8( |
| 1746 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1747 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1748 | } |
| 1749 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1750 | if (changed) { |
| 1751 | u8 old_retry_short, old_retry_long; |
| 1752 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1753 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1754 | |
| 1755 | if (!rdev->ops->set_wiphy_params) { |
| 1756 | result = -EOPNOTSUPP; |
| 1757 | goto bad_res; |
| 1758 | } |
| 1759 | |
| 1760 | old_retry_short = rdev->wiphy.retry_short; |
| 1761 | old_retry_long = rdev->wiphy.retry_long; |
| 1762 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1763 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1764 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1765 | |
| 1766 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1767 | rdev->wiphy.retry_short = retry_short; |
| 1768 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1769 | rdev->wiphy.retry_long = retry_long; |
| 1770 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1771 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1772 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1773 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1774 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1775 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1776 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1777 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1778 | if (result) { |
| 1779 | rdev->wiphy.retry_short = old_retry_short; |
| 1780 | rdev->wiphy.retry_long = old_retry_long; |
| 1781 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1782 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1783 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1784 | } |
| 1785 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1786 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1787 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1788 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1789 | if (netdev) |
| 1790 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1791 | return result; |
| 1792 | } |
| 1793 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1794 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1795 | { |
| 1796 | return (u64)wdev->identifier | |
| 1797 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1798 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1799 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1800 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1801 | struct cfg80211_chan_def *chandef) |
| 1802 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1803 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1804 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1805 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1806 | chandef->chan->center_freq)) |
| 1807 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1808 | switch (chandef->width) { |
| 1809 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1810 | case NL80211_CHAN_WIDTH_20: |
| 1811 | case NL80211_CHAN_WIDTH_40: |
| 1812 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1813 | cfg80211_get_chandef_type(chandef))) |
| 1814 | return -ENOBUFS; |
| 1815 | break; |
| 1816 | default: |
| 1817 | break; |
| 1818 | } |
| 1819 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1820 | return -ENOBUFS; |
| 1821 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1822 | return -ENOBUFS; |
| 1823 | if (chandef->center_freq2 && |
| 1824 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1825 | return -ENOBUFS; |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1829 | 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] | 1830 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1831 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1832 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1833 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | void *hdr; |
| 1835 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1836 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1837 | if (!hdr) |
| 1838 | return -1; |
| 1839 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1840 | if (dev && |
| 1841 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1842 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1843 | goto nla_put_failure; |
| 1844 | |
| 1845 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1846 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1847 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1848 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1849 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1850 | rdev->devlist_generation ^ |
| 1851 | (cfg80211_rdev_list_generation << 2))) |
| 1852 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1853 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1854 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1855 | int ret; |
| 1856 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1857 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1858 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1859 | if (ret == 0) { |
| 1860 | if (nl80211_send_chandef(msg, &chandef)) |
| 1861 | goto nla_put_failure; |
| 1862 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1863 | } |
| 1864 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1865 | if (wdev->ssid_len) { |
| 1866 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1867 | goto nla_put_failure; |
| 1868 | } |
| 1869 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1870 | return genlmsg_end(msg, hdr); |
| 1871 | |
| 1872 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1873 | genlmsg_cancel(msg, hdr); |
| 1874 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1878 | { |
| 1879 | int wp_idx = 0; |
| 1880 | int if_idx = 0; |
| 1881 | int wp_start = cb->args[0]; |
| 1882 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1883 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1884 | struct wireless_dev *wdev; |
| 1885 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1886 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1887 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1888 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1889 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1890 | if (wp_idx < wp_start) { |
| 1891 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1892 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1893 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1894 | if_idx = 0; |
| 1895 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1896 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1897 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1898 | if (if_idx < if_start) { |
| 1899 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1900 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1901 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1902 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1903 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1904 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1905 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1906 | goto out; |
| 1907 | } |
| 1908 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1909 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1910 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1911 | |
| 1912 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1913 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1914 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1915 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | |
| 1917 | cb->args[0] = wp_idx; |
| 1918 | cb->args[1] = if_idx; |
| 1919 | |
| 1920 | return skb->len; |
| 1921 | } |
| 1922 | |
| 1923 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1924 | { |
| 1925 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1926 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1927 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1928 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1930 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1931 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1932 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1933 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1934 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1935 | nlmsg_free(msg); |
| 1936 | return -ENOBUFS; |
| 1937 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1938 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1939 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1940 | } |
| 1941 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1942 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1943 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1944 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1945 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1946 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1947 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1948 | }; |
| 1949 | |
| 1950 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1951 | { |
| 1952 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1953 | int flag; |
| 1954 | |
| 1955 | *mntrflags = 0; |
| 1956 | |
| 1957 | if (!nla) |
| 1958 | return -EINVAL; |
| 1959 | |
| 1960 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1961 | nla, mntr_flags_policy)) |
| 1962 | return -EINVAL; |
| 1963 | |
| 1964 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1965 | if (flags[flag]) |
| 1966 | *mntrflags |= (1<<flag); |
| 1967 | |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1971 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1972 | struct net_device *netdev, u8 use_4addr, |
| 1973 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1974 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1975 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1976 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1977 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1978 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1979 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1980 | |
| 1981 | switch (iftype) { |
| 1982 | case NL80211_IFTYPE_AP_VLAN: |
| 1983 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1984 | return 0; |
| 1985 | break; |
| 1986 | case NL80211_IFTYPE_STATION: |
| 1987 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1988 | return 0; |
| 1989 | break; |
| 1990 | default: |
| 1991 | break; |
| 1992 | } |
| 1993 | |
| 1994 | return -EOPNOTSUPP; |
| 1995 | } |
| 1996 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1997 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1998 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2000 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2001 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2002 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2003 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2004 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2005 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2006 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2007 | memset(¶ms, 0, sizeof(params)); |
| 2008 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2009 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2010 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2011 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2012 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2013 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2014 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2015 | if (ntype > NL80211_IFTYPE_MAX) |
| 2016 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2019 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2022 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2023 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2024 | if (netif_running(dev)) |
| 2025 | return -EBUSY; |
| 2026 | |
| 2027 | wdev_lock(wdev); |
| 2028 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2029 | IEEE80211_MAX_MESH_ID_LEN); |
| 2030 | wdev->mesh_id_up_len = |
| 2031 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2032 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2033 | wdev->mesh_id_up_len); |
| 2034 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2035 | } |
| 2036 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2037 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2038 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2039 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2040 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2041 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2042 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2043 | } else { |
| 2044 | params.use_4addr = -1; |
| 2045 | } |
| 2046 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2047 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2048 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2049 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2050 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2051 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2052 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2053 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2054 | |
| 2055 | flags = &_flags; |
| 2056 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2057 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2058 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2059 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2060 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2061 | else |
| 2062 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2063 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2064 | if (!err && params.use_4addr != -1) |
| 2065 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2066 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2067 | return err; |
| 2068 | } |
| 2069 | |
| 2070 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2071 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2073 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2074 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2075 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2076 | int err; |
| 2077 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2078 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2079 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2080 | memset(¶ms, 0, sizeof(params)); |
| 2081 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2082 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2083 | return -EINVAL; |
| 2084 | |
| 2085 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2086 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2087 | if (type > NL80211_IFTYPE_MAX) |
| 2088 | return -EINVAL; |
| 2089 | } |
| 2090 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2091 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2092 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2093 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2094 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2095 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2096 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2097 | ETH_ALEN); |
| 2098 | if (!is_valid_ether_addr(params.macaddr)) |
| 2099 | return -EADDRNOTAVAIL; |
| 2100 | } |
| 2101 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2102 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2103 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2104 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2105 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2106 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2107 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2108 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2109 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2110 | if (!msg) |
| 2111 | return -ENOMEM; |
| 2112 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2113 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2114 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2115 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2116 | wdev = rdev_add_virtual_intf(rdev, |
| 2117 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2118 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2119 | if (IS_ERR(wdev)) { |
| 2120 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2121 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2122 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2123 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2124 | switch (type) { |
| 2125 | case NL80211_IFTYPE_MESH_POINT: |
| 2126 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2127 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2128 | wdev_lock(wdev); |
| 2129 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2130 | IEEE80211_MAX_MESH_ID_LEN); |
| 2131 | wdev->mesh_id_up_len = |
| 2132 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2133 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2134 | wdev->mesh_id_up_len); |
| 2135 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2136 | break; |
| 2137 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2138 | /* |
| 2139 | * P2P Device doesn't have a netdev, so doesn't go |
| 2140 | * through the netdev notifier and must be added here |
| 2141 | */ |
| 2142 | mutex_init(&wdev->mtx); |
| 2143 | INIT_LIST_HEAD(&wdev->event_list); |
| 2144 | spin_lock_init(&wdev->event_lock); |
| 2145 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2146 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2147 | |
| 2148 | mutex_lock(&rdev->devlist_mtx); |
| 2149 | wdev->identifier = ++rdev->wdev_id; |
| 2150 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2151 | rdev->devlist_generation++; |
| 2152 | mutex_unlock(&rdev->devlist_mtx); |
| 2153 | break; |
| 2154 | default: |
| 2155 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2158 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2159 | rdev, wdev) < 0) { |
| 2160 | nlmsg_free(msg); |
| 2161 | return -ENOBUFS; |
| 2162 | } |
| 2163 | |
| 2164 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2168 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2170 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2171 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2172 | if (!rdev->ops->del_virtual_intf) |
| 2173 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2174 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2175 | /* |
| 2176 | * If we remove a wireless device without a netdev then clear |
| 2177 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2178 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2179 | * since the wdev has been freed, unlike with a netdev where |
| 2180 | * we need the dev_put() for the netdev to really be freed. |
| 2181 | */ |
| 2182 | if (!wdev->netdev) |
| 2183 | info->user_ptr[1] = NULL; |
| 2184 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2185 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2186 | } |
| 2187 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2188 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2189 | { |
| 2190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2191 | struct net_device *dev = info->user_ptr[1]; |
| 2192 | u16 noack_map; |
| 2193 | |
| 2194 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2195 | return -EINVAL; |
| 2196 | |
| 2197 | if (!rdev->ops->set_noack_map) |
| 2198 | return -EOPNOTSUPP; |
| 2199 | |
| 2200 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2201 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2202 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2203 | } |
| 2204 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2205 | struct get_key_cookie { |
| 2206 | struct sk_buff *msg; |
| 2207 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2208 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2209 | }; |
| 2210 | |
| 2211 | static void get_key_callback(void *c, struct key_params *params) |
| 2212 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2213 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2214 | struct get_key_cookie *cookie = c; |
| 2215 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2216 | if ((params->key && |
| 2217 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2218 | params->key_len, params->key)) || |
| 2219 | (params->seq && |
| 2220 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2221 | params->seq_len, params->seq)) || |
| 2222 | (params->cipher && |
| 2223 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2224 | params->cipher))) |
| 2225 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2226 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2227 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2228 | if (!key) |
| 2229 | goto nla_put_failure; |
| 2230 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2231 | if ((params->key && |
| 2232 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2233 | params->key_len, params->key)) || |
| 2234 | (params->seq && |
| 2235 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2236 | params->seq_len, params->seq)) || |
| 2237 | (params->cipher && |
| 2238 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2239 | params->cipher))) |
| 2240 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2241 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2242 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2243 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2244 | |
| 2245 | nla_nest_end(cookie->msg, key); |
| 2246 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2247 | return; |
| 2248 | nla_put_failure: |
| 2249 | cookie->error = 1; |
| 2250 | } |
| 2251 | |
| 2252 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2253 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2255 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2256 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2257 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2258 | const u8 *mac_addr = NULL; |
| 2259 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2260 | struct get_key_cookie cookie = { |
| 2261 | .error = 0, |
| 2262 | }; |
| 2263 | void *hdr; |
| 2264 | struct sk_buff *msg; |
| 2265 | |
| 2266 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2267 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2268 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2269 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2270 | return -EINVAL; |
| 2271 | |
| 2272 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2273 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2274 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2275 | pairwise = !!mac_addr; |
| 2276 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2277 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2278 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2279 | return -EINVAL; |
| 2280 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2281 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2282 | return -EINVAL; |
| 2283 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2284 | } |
| 2285 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2286 | if (!rdev->ops->get_key) |
| 2287 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2288 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2289 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2290 | if (!msg) |
| 2291 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2292 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2293 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2294 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | if (IS_ERR(hdr)) |
| 2296 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2297 | |
| 2298 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2299 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2301 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2302 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2303 | goto nla_put_failure; |
| 2304 | if (mac_addr && |
| 2305 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2306 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2307 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2308 | if (pairwise && mac_addr && |
| 2309 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2310 | return -ENOENT; |
| 2311 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2312 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2313 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2314 | |
| 2315 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2316 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2317 | |
| 2318 | if (cookie.error) |
| 2319 | goto nla_put_failure; |
| 2320 | |
| 2321 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2322 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2323 | |
| 2324 | nla_put_failure: |
| 2325 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2326 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2327 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2328 | return err; |
| 2329 | } |
| 2330 | |
| 2331 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2332 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2334 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2335 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2336 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2337 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2338 | err = nl80211_parse_key(info, &key); |
| 2339 | if (err) |
| 2340 | return err; |
| 2341 | |
| 2342 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2343 | return -EINVAL; |
| 2344 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2345 | /* only support setting default key */ |
| 2346 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2347 | return -EINVAL; |
| 2348 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2349 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2350 | |
| 2351 | if (key.def) { |
| 2352 | if (!rdev->ops->set_default_key) { |
| 2353 | err = -EOPNOTSUPP; |
| 2354 | goto out; |
| 2355 | } |
| 2356 | |
| 2357 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2358 | if (err) |
| 2359 | goto out; |
| 2360 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2361 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2362 | key.def_uni, key.def_multi); |
| 2363 | |
| 2364 | if (err) |
| 2365 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2366 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2367 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2368 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2369 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2370 | } else { |
| 2371 | if (key.def_uni || !key.def_multi) { |
| 2372 | err = -EINVAL; |
| 2373 | goto out; |
| 2374 | } |
| 2375 | |
| 2376 | if (!rdev->ops->set_default_mgmt_key) { |
| 2377 | err = -EOPNOTSUPP; |
| 2378 | goto out; |
| 2379 | } |
| 2380 | |
| 2381 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2382 | if (err) |
| 2383 | goto out; |
| 2384 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2385 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2386 | if (err) |
| 2387 | goto out; |
| 2388 | |
| 2389 | #ifdef CONFIG_CFG80211_WEXT |
| 2390 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2391 | #endif |
| 2392 | } |
| 2393 | |
| 2394 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2395 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2396 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2397 | return err; |
| 2398 | } |
| 2399 | |
| 2400 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2401 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2403 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2404 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2405 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2406 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2407 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2408 | err = nl80211_parse_key(info, &key); |
| 2409 | if (err) |
| 2410 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2411 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2412 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2413 | return -EINVAL; |
| 2414 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2415 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2416 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2417 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2418 | if (key.type == -1) { |
| 2419 | if (mac_addr) |
| 2420 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2421 | else |
| 2422 | key.type = NL80211_KEYTYPE_GROUP; |
| 2423 | } |
| 2424 | |
| 2425 | /* for now */ |
| 2426 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2427 | key.type != NL80211_KEYTYPE_GROUP) |
| 2428 | return -EINVAL; |
| 2429 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2430 | if (!rdev->ops->add_key) |
| 2431 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2432 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2433 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2434 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2435 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2437 | |
| 2438 | wdev_lock(dev->ieee80211_ptr); |
| 2439 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2440 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2441 | err = rdev_add_key(rdev, dev, key.idx, |
| 2442 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2443 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2444 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2445 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2446 | return err; |
| 2447 | } |
| 2448 | |
| 2449 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2452 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2453 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2454 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2455 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2456 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2457 | err = nl80211_parse_key(info, &key); |
| 2458 | if (err) |
| 2459 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2460 | |
| 2461 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2462 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2463 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2464 | if (key.type == -1) { |
| 2465 | if (mac_addr) |
| 2466 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2467 | else |
| 2468 | key.type = NL80211_KEYTYPE_GROUP; |
| 2469 | } |
| 2470 | |
| 2471 | /* for now */ |
| 2472 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2473 | key.type != NL80211_KEYTYPE_GROUP) |
| 2474 | return -EINVAL; |
| 2475 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2476 | if (!rdev->ops->del_key) |
| 2477 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2478 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2479 | wdev_lock(dev->ieee80211_ptr); |
| 2480 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2481 | |
| 2482 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2483 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2484 | err = -ENOENT; |
| 2485 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2486 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2487 | err = rdev_del_key(rdev, dev, key.idx, |
| 2488 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2489 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2490 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2491 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2492 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2493 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2494 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2495 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2496 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2497 | } |
| 2498 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2499 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2500 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2501 | return err; |
| 2502 | } |
| 2503 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2504 | /* This function returns an error or the number of nested attributes */ |
| 2505 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2506 | { |
| 2507 | struct nlattr *attr; |
| 2508 | int n_entries = 0, tmp; |
| 2509 | |
| 2510 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2511 | if (nla_len(attr) != ETH_ALEN) |
| 2512 | return -EINVAL; |
| 2513 | |
| 2514 | n_entries++; |
| 2515 | } |
| 2516 | |
| 2517 | return n_entries; |
| 2518 | } |
| 2519 | |
| 2520 | /* |
| 2521 | * This function parses ACL information and allocates memory for ACL data. |
| 2522 | * On successful return, the calling function is responsible to free the |
| 2523 | * ACL buffer returned by this function. |
| 2524 | */ |
| 2525 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2526 | struct genl_info *info) |
| 2527 | { |
| 2528 | enum nl80211_acl_policy acl_policy; |
| 2529 | struct nlattr *attr; |
| 2530 | struct cfg80211_acl_data *acl; |
| 2531 | int i = 0, n_entries, tmp; |
| 2532 | |
| 2533 | if (!wiphy->max_acl_mac_addrs) |
| 2534 | return ERR_PTR(-EOPNOTSUPP); |
| 2535 | |
| 2536 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2537 | return ERR_PTR(-EINVAL); |
| 2538 | |
| 2539 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2540 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2541 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2542 | return ERR_PTR(-EINVAL); |
| 2543 | |
| 2544 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2545 | return ERR_PTR(-EINVAL); |
| 2546 | |
| 2547 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2548 | if (n_entries < 0) |
| 2549 | return ERR_PTR(n_entries); |
| 2550 | |
| 2551 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2552 | return ERR_PTR(-ENOTSUPP); |
| 2553 | |
| 2554 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2555 | GFP_KERNEL); |
| 2556 | if (!acl) |
| 2557 | return ERR_PTR(-ENOMEM); |
| 2558 | |
| 2559 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2560 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2561 | i++; |
| 2562 | } |
| 2563 | |
| 2564 | acl->n_acl_entries = n_entries; |
| 2565 | acl->acl_policy = acl_policy; |
| 2566 | |
| 2567 | return acl; |
| 2568 | } |
| 2569 | |
| 2570 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2571 | { |
| 2572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2573 | struct net_device *dev = info->user_ptr[1]; |
| 2574 | struct cfg80211_acl_data *acl; |
| 2575 | int err; |
| 2576 | |
| 2577 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2578 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2579 | return -EOPNOTSUPP; |
| 2580 | |
| 2581 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2582 | return -EINVAL; |
| 2583 | |
| 2584 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2585 | if (IS_ERR(acl)) |
| 2586 | return PTR_ERR(acl); |
| 2587 | |
| 2588 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2589 | |
| 2590 | kfree(acl); |
| 2591 | |
| 2592 | return err; |
| 2593 | } |
| 2594 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2595 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2596 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2597 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2598 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2599 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2600 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2601 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2602 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2603 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2604 | return -EINVAL; |
| 2605 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2606 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2607 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2608 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2609 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2610 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2611 | if (!bcn->head_len) |
| 2612 | return -EINVAL; |
| 2613 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2617 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2618 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2619 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2620 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2621 | } |
| 2622 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2623 | if (!haveinfo) |
| 2624 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2625 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2626 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2627 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2628 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2632 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2633 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2634 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2635 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2636 | } |
| 2637 | |
| 2638 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2639 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2640 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2641 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2642 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2643 | } |
| 2644 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2645 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2646 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2647 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2648 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2649 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2650 | } |
| 2651 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2652 | return 0; |
| 2653 | } |
| 2654 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2655 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2656 | struct cfg80211_ap_settings *params) |
| 2657 | { |
| 2658 | struct wireless_dev *wdev; |
| 2659 | bool ret = false; |
| 2660 | |
| 2661 | mutex_lock(&rdev->devlist_mtx); |
| 2662 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2663 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2664 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2665 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2666 | continue; |
| 2667 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2668 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2669 | continue; |
| 2670 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2671 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2672 | ret = true; |
| 2673 | break; |
| 2674 | } |
| 2675 | |
| 2676 | mutex_unlock(&rdev->devlist_mtx); |
| 2677 | |
| 2678 | return ret; |
| 2679 | } |
| 2680 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2681 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2682 | enum nl80211_auth_type auth_type, |
| 2683 | enum nl80211_commands cmd) |
| 2684 | { |
| 2685 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2686 | return false; |
| 2687 | |
| 2688 | switch (cmd) { |
| 2689 | case NL80211_CMD_AUTHENTICATE: |
| 2690 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2691 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2692 | return false; |
| 2693 | return true; |
| 2694 | case NL80211_CMD_CONNECT: |
| 2695 | case NL80211_CMD_START_AP: |
| 2696 | /* SAE not supported yet */ |
| 2697 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2698 | return false; |
| 2699 | return true; |
| 2700 | default: |
| 2701 | return false; |
| 2702 | } |
| 2703 | } |
| 2704 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2705 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2706 | { |
| 2707 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2708 | struct net_device *dev = info->user_ptr[1]; |
| 2709 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2710 | struct cfg80211_ap_settings params; |
| 2711 | int err; |
| 2712 | |
| 2713 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2714 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2715 | return -EOPNOTSUPP; |
| 2716 | |
| 2717 | if (!rdev->ops->start_ap) |
| 2718 | return -EOPNOTSUPP; |
| 2719 | |
| 2720 | if (wdev->beacon_interval) |
| 2721 | return -EALREADY; |
| 2722 | |
| 2723 | memset(¶ms, 0, sizeof(params)); |
| 2724 | |
| 2725 | /* these are required for START_AP */ |
| 2726 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2727 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2728 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2729 | return -EINVAL; |
| 2730 | |
| 2731 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2732 | if (err) |
| 2733 | return err; |
| 2734 | |
| 2735 | params.beacon_interval = |
| 2736 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2737 | params.dtim_period = |
| 2738 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2739 | |
| 2740 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2741 | if (err) |
| 2742 | return err; |
| 2743 | |
| 2744 | /* |
| 2745 | * In theory, some of these attributes should be required here |
| 2746 | * but since they were not used when the command was originally |
| 2747 | * added, keep them optional for old user space programs to let |
| 2748 | * them continue to work with drivers that do not need the |
| 2749 | * additional information -- drivers must check! |
| 2750 | */ |
| 2751 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2752 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2753 | params.ssid_len = |
| 2754 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2755 | if (params.ssid_len == 0 || |
| 2756 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2757 | return -EINVAL; |
| 2758 | } |
| 2759 | |
| 2760 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2761 | params.hidden_ssid = nla_get_u32( |
| 2762 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2763 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2764 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2765 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2766 | return -EINVAL; |
| 2767 | } |
| 2768 | |
| 2769 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2770 | |
| 2771 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2772 | params.auth_type = nla_get_u32( |
| 2773 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2774 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2775 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2776 | return -EINVAL; |
| 2777 | } else |
| 2778 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2779 | |
| 2780 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2781 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2782 | if (err) |
| 2783 | return err; |
| 2784 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2785 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2786 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2787 | return -EOPNOTSUPP; |
| 2788 | params.inactivity_timeout = nla_get_u16( |
| 2789 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2790 | } |
| 2791 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2792 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2793 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2794 | return -EINVAL; |
| 2795 | params.p2p_ctwindow = |
| 2796 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2797 | if (params.p2p_ctwindow > 127) |
| 2798 | return -EINVAL; |
| 2799 | if (params.p2p_ctwindow != 0 && |
| 2800 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2801 | return -EINVAL; |
| 2802 | } |
| 2803 | |
| 2804 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2805 | u8 tmp; |
| 2806 | |
| 2807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2808 | return -EINVAL; |
| 2809 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2810 | if (tmp > 1) |
| 2811 | return -EINVAL; |
| 2812 | params.p2p_opp_ps = tmp; |
| 2813 | if (params.p2p_opp_ps != 0 && |
| 2814 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2815 | return -EINVAL; |
| 2816 | } |
| 2817 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2818 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2819 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2820 | if (err) |
| 2821 | return err; |
| 2822 | } else if (wdev->preset_chandef.chan) { |
| 2823 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2824 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2825 | return -EINVAL; |
| 2826 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2827 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2828 | return -EINVAL; |
| 2829 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2830 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2831 | err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan, |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2832 | CHAN_MODE_SHARED); |
| 2833 | mutex_unlock(&rdev->devlist_mtx); |
| 2834 | |
| 2835 | if (err) |
| 2836 | return err; |
| 2837 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2838 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 2839 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 2840 | if (IS_ERR(params.acl)) |
| 2841 | return PTR_ERR(params.acl); |
| 2842 | } |
| 2843 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2844 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2845 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2846 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2847 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2848 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2849 | wdev->ssid_len = params.ssid_len; |
| 2850 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2851 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2852 | |
| 2853 | kfree(params.acl); |
| 2854 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2855 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2856 | } |
| 2857 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2858 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2859 | { |
| 2860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2861 | struct net_device *dev = info->user_ptr[1]; |
| 2862 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2863 | struct cfg80211_beacon_data params; |
| 2864 | int err; |
| 2865 | |
| 2866 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2867 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2868 | return -EOPNOTSUPP; |
| 2869 | |
| 2870 | if (!rdev->ops->change_beacon) |
| 2871 | return -EOPNOTSUPP; |
| 2872 | |
| 2873 | if (!wdev->beacon_interval) |
| 2874 | return -EINVAL; |
| 2875 | |
| 2876 | err = nl80211_parse_beacon(info, ¶ms); |
| 2877 | if (err) |
| 2878 | return err; |
| 2879 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2880 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | 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] | 2884 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2886 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2887 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2888 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2891 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2892 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2893 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2894 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2895 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2896 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2897 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2898 | }; |
| 2899 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2900 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2901 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2902 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2903 | { |
| 2904 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2905 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2906 | int flag; |
| 2907 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2908 | /* |
| 2909 | * Try parsing the new attribute first so userspace |
| 2910 | * can specify both for older kernels. |
| 2911 | */ |
| 2912 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2913 | if (nla) { |
| 2914 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2915 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2916 | sta_flags = nla_data(nla); |
| 2917 | params->sta_flags_mask = sta_flags->mask; |
| 2918 | params->sta_flags_set = sta_flags->set; |
| 2919 | if ((params->sta_flags_mask | |
| 2920 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2921 | return -EINVAL; |
| 2922 | return 0; |
| 2923 | } |
| 2924 | |
| 2925 | /* if present, parse the old attribute */ |
| 2926 | |
| 2927 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2928 | if (!nla) |
| 2929 | return 0; |
| 2930 | |
| 2931 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2932 | nla, sta_flags_policy)) |
| 2933 | return -EINVAL; |
| 2934 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2935 | /* |
| 2936 | * Only allow certain flags for interface types so that |
| 2937 | * other attributes are silently ignored. Remember that |
| 2938 | * this is backward compatibility code with old userspace |
| 2939 | * and shouldn't be hit in other cases anyway. |
| 2940 | */ |
| 2941 | switch (iftype) { |
| 2942 | case NL80211_IFTYPE_AP: |
| 2943 | case NL80211_IFTYPE_AP_VLAN: |
| 2944 | case NL80211_IFTYPE_P2P_GO: |
| 2945 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2946 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2947 | BIT(NL80211_STA_FLAG_WME) | |
| 2948 | BIT(NL80211_STA_FLAG_MFP); |
| 2949 | break; |
| 2950 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2951 | case NL80211_IFTYPE_STATION: |
| 2952 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2953 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2954 | break; |
| 2955 | case NL80211_IFTYPE_MESH_POINT: |
| 2956 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2957 | BIT(NL80211_STA_FLAG_MFP) | |
| 2958 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2959 | default: |
| 2960 | return -EINVAL; |
| 2961 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2962 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2963 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2964 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2965 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2966 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2967 | /* no longer support new API additions in old API */ |
| 2968 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2969 | return -EINVAL; |
| 2970 | } |
| 2971 | } |
| 2972 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2973 | return 0; |
| 2974 | } |
| 2975 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2976 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2977 | int attr) |
| 2978 | { |
| 2979 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2980 | u32 bitrate; |
| 2981 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2982 | |
| 2983 | rate = nla_nest_start(msg, attr); |
| 2984 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2985 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2986 | |
| 2987 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2988 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2989 | /* report 16-bit bitrate only if we can */ |
| 2990 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2991 | if (bitrate > 0 && |
| 2992 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 2993 | return false; |
| 2994 | if (bitrate_compat > 0 && |
| 2995 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 2996 | return false; |
| 2997 | |
| 2998 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 2999 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3000 | return false; |
| 3001 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3002 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3003 | return false; |
| 3004 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3005 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3006 | return false; |
| 3007 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3008 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3009 | return false; |
| 3010 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3011 | return false; |
| 3012 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3013 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3014 | return false; |
| 3015 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3016 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3017 | return false; |
| 3018 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3019 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3020 | return false; |
| 3021 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3022 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3023 | return false; |
| 3024 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3025 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3026 | return false; |
| 3027 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3028 | |
| 3029 | nla_nest_end(msg, rate); |
| 3030 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3031 | } |
| 3032 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3033 | 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] | 3034 | int flags, |
| 3035 | struct cfg80211_registered_device *rdev, |
| 3036 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3037 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3038 | { |
| 3039 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3040 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3041 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3042 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3043 | if (!hdr) |
| 3044 | return -1; |
| 3045 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3046 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3047 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3048 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3049 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3050 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3051 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3052 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3053 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3054 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3055 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3056 | sinfo->connected_time)) |
| 3057 | goto nla_put_failure; |
| 3058 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3059 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3060 | sinfo->inactive_time)) |
| 3061 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3062 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3063 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3064 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3065 | (u32)sinfo->rx_bytes)) |
| 3066 | goto nla_put_failure; |
| 3067 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3068 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3069 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3070 | (u32)sinfo->tx_bytes)) |
| 3071 | goto nla_put_failure; |
| 3072 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3073 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3074 | sinfo->rx_bytes)) |
| 3075 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3076 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3077 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3078 | sinfo->tx_bytes)) |
| 3079 | goto nla_put_failure; |
| 3080 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3081 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3082 | goto nla_put_failure; |
| 3083 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3084 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3085 | goto nla_put_failure; |
| 3086 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3087 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3088 | sinfo->plink_state)) |
| 3089 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3090 | switch (rdev->wiphy.signal_type) { |
| 3091 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3092 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3093 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3094 | sinfo->signal)) |
| 3095 | goto nla_put_failure; |
| 3096 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3097 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3098 | sinfo->signal_avg)) |
| 3099 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3100 | break; |
| 3101 | default: |
| 3102 | break; |
| 3103 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3104 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3105 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3106 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3107 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3108 | } |
| 3109 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3110 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3111 | NL80211_STA_INFO_RX_BITRATE)) |
| 3112 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3113 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3114 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3115 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3116 | sinfo->rx_packets)) |
| 3117 | goto nla_put_failure; |
| 3118 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3119 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3120 | sinfo->tx_packets)) |
| 3121 | goto nla_put_failure; |
| 3122 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3123 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3124 | sinfo->tx_retries)) |
| 3125 | goto nla_put_failure; |
| 3126 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3127 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3128 | sinfo->tx_failed)) |
| 3129 | goto nla_put_failure; |
| 3130 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3131 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3132 | sinfo->beacon_loss_count)) |
| 3133 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3134 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3135 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3136 | sinfo->local_pm)) |
| 3137 | goto nla_put_failure; |
| 3138 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3139 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3140 | sinfo->peer_pm)) |
| 3141 | goto nla_put_failure; |
| 3142 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3143 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3144 | sinfo->nonpeer_pm)) |
| 3145 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3146 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3147 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3148 | if (!bss_param) |
| 3149 | goto nla_put_failure; |
| 3150 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3151 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3152 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3153 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3154 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3155 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3156 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3157 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3158 | sinfo->bss_param.dtim_period) || |
| 3159 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3160 | sinfo->bss_param.beacon_interval)) |
| 3161 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3162 | |
| 3163 | nla_nest_end(msg, bss_param); |
| 3164 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3165 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3166 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3167 | sizeof(struct nl80211_sta_flag_update), |
| 3168 | &sinfo->sta_flags)) |
| 3169 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3170 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3171 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3172 | sinfo->t_offset)) |
| 3173 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3174 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3175 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3176 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3177 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3178 | sinfo->assoc_req_ies)) |
| 3179 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3180 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3181 | return genlmsg_end(msg, hdr); |
| 3182 | |
| 3183 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3184 | genlmsg_cancel(msg, hdr); |
| 3185 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3186 | } |
| 3187 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3188 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3189 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3190 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3191 | struct station_info sinfo; |
| 3192 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3193 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3194 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3195 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3196 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3197 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3198 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3199 | if (err) |
| 3200 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3201 | |
| 3202 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3203 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3204 | goto out_err; |
| 3205 | } |
| 3206 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3207 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3208 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3209 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3210 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3211 | if (err == -ENOENT) |
| 3212 | break; |
| 3213 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3214 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3215 | |
| 3216 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3217 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3218 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3219 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3220 | &sinfo) < 0) |
| 3221 | goto out; |
| 3222 | |
| 3223 | sta_idx++; |
| 3224 | } |
| 3225 | |
| 3226 | |
| 3227 | out: |
| 3228 | cb->args[1] = sta_idx; |
| 3229 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3230 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3231 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3232 | |
| 3233 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3234 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3235 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3236 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3237 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3239 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3240 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3241 | struct sk_buff *msg; |
| 3242 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3243 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3244 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3245 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3246 | |
| 3247 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3248 | return -EINVAL; |
| 3249 | |
| 3250 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3252 | if (!rdev->ops->get_station) |
| 3253 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3254 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3255 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3256 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3257 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3258 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3260 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3261 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3263 | 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] | 3264 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3265 | nlmsg_free(msg); |
| 3266 | return -ENOBUFS; |
| 3267 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3269 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3273 | * 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] | 3274 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3275 | static struct net_device *get_vlan(struct genl_info *info, |
| 3276 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3277 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3278 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3279 | struct net_device *v; |
| 3280 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3281 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3282 | if (!vlanattr) |
| 3283 | return NULL; |
| 3284 | |
| 3285 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3286 | if (!v) |
| 3287 | return ERR_PTR(-ENODEV); |
| 3288 | |
| 3289 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3290 | ret = -EINVAL; |
| 3291 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3292 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3293 | |
| 3294 | if (!netif_running(v)) { |
| 3295 | ret = -ENETDOWN; |
| 3296 | goto error; |
| 3297 | } |
| 3298 | |
| 3299 | return v; |
| 3300 | error: |
| 3301 | dev_put(v); |
| 3302 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3306 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3308 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3309 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3310 | struct station_parameters params; |
| 3311 | u8 *mac_addr = NULL; |
| 3312 | |
| 3313 | memset(¶ms, 0, sizeof(params)); |
| 3314 | |
| 3315 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3316 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3317 | |
| 3318 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3319 | return -EINVAL; |
| 3320 | |
| 3321 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3322 | return -EINVAL; |
| 3323 | |
| 3324 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3325 | |
| 3326 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3327 | params.supported_rates = |
| 3328 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3329 | params.supported_rates_len = |
| 3330 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3331 | } |
| 3332 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3333 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL] || |
| 3334 | info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3335 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3336 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3337 | if (!rdev->ops->change_station) |
| 3338 | return -EOPNOTSUPP; |
| 3339 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3340 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3341 | return -EINVAL; |
| 3342 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3343 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3344 | params.plink_action = |
| 3345 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3346 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3347 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3348 | params.plink_state = |
| 3349 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3350 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3351 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3352 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3353 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3354 | |
| 3355 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3356 | pm > NL80211_MESH_POWER_MAX) |
| 3357 | return -EINVAL; |
| 3358 | |
| 3359 | params.local_pm = pm; |
| 3360 | } |
| 3361 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3362 | switch (dev->ieee80211_ptr->iftype) { |
| 3363 | case NL80211_IFTYPE_AP: |
| 3364 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3365 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3366 | /* disallow mesh-specific things */ |
| 3367 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3368 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3369 | if (params.local_pm) |
| 3370 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3371 | |
| 3372 | /* TDLS can't be set, ... */ |
| 3373 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3374 | return -EINVAL; |
| 3375 | /* |
| 3376 | * ... but don't bother the driver with it. This works around |
| 3377 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3378 | * TLDS_PEER flag in the mask even for AP mode. |
| 3379 | */ |
| 3380 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3381 | |
| 3382 | /* accept only the listed bits */ |
| 3383 | if (params.sta_flags_mask & |
| 3384 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3385 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3386 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3387 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3388 | BIT(NL80211_STA_FLAG_WME) | |
| 3389 | BIT(NL80211_STA_FLAG_MFP))) |
| 3390 | return -EINVAL; |
| 3391 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3392 | /* but authenticated/associated only if driver handles it */ |
| 3393 | if (!(rdev->wiphy.features & |
| 3394 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3395 | params.sta_flags_mask & |
| 3396 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3397 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3398 | return -EINVAL; |
| 3399 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3400 | /* reject other things that can't change */ |
| 3401 | if (params.supported_rates) |
| 3402 | return -EINVAL; |
| 3403 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3404 | /* must be last in here for error handling */ |
| 3405 | params.vlan = get_vlan(info, rdev); |
| 3406 | if (IS_ERR(params.vlan)) |
| 3407 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3408 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3409 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3410 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3411 | /* |
| 3412 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3413 | * but silently ignore attempts to change it since we |
| 3414 | * don't have state here to verify that it doesn't try |
| 3415 | * to change the flag. |
| 3416 | */ |
| 3417 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3418 | /* fall through */ |
| 3419 | case NL80211_IFTYPE_ADHOC: |
| 3420 | /* disallow things sta doesn't support */ |
| 3421 | if (params.plink_action) |
| 3422 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3423 | if (params.local_pm) |
| 3424 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3425 | /* reject any changes other than AUTHORIZED */ |
| 3426 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3427 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3428 | break; |
| 3429 | case NL80211_IFTYPE_MESH_POINT: |
| 3430 | /* disallow things mesh doesn't support */ |
| 3431 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3432 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3433 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3434 | return -EINVAL; |
| 3435 | /* |
| 3436 | * No special handling for TDLS here -- the userspace |
| 3437 | * mesh code doesn't have this bug. |
| 3438 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3439 | if (params.sta_flags_mask & |
| 3440 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3441 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3442 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3443 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3444 | break; |
| 3445 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3446 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3447 | } |
| 3448 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3449 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3450 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3451 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3452 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3453 | if (params.vlan) |
| 3454 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3455 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3456 | return err; |
| 3457 | } |
| 3458 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3459 | static struct nla_policy |
| 3460 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3461 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3462 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3463 | }; |
| 3464 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3465 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3466 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3468 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3469 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3470 | struct station_parameters params; |
| 3471 | u8 *mac_addr = NULL; |
| 3472 | |
| 3473 | memset(¶ms, 0, sizeof(params)); |
| 3474 | |
| 3475 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3476 | return -EINVAL; |
| 3477 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3478 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3479 | return -EINVAL; |
| 3480 | |
| 3481 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3482 | return -EINVAL; |
| 3483 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3484 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3485 | return -EINVAL; |
| 3486 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3487 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3488 | params.supported_rates = |
| 3489 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3490 | params.supported_rates_len = |
| 3491 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3492 | params.listen_interval = |
| 3493 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3494 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3495 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3496 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3497 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3498 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3499 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3500 | params.ht_capa = |
| 3501 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3502 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3503 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3504 | params.vht_capa = |
| 3505 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3506 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3507 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3508 | params.plink_action = |
| 3509 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3510 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3511 | if (!rdev->ops->add_station) |
| 3512 | return -EOPNOTSUPP; |
| 3513 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3514 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3515 | return -EINVAL; |
| 3516 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3517 | switch (dev->ieee80211_ptr->iftype) { |
| 3518 | case NL80211_IFTYPE_AP: |
| 3519 | case NL80211_IFTYPE_AP_VLAN: |
| 3520 | case NL80211_IFTYPE_P2P_GO: |
| 3521 | /* parse WME attributes if sta is WME capable */ |
| 3522 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3523 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3524 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3525 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3526 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3527 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3528 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3529 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3530 | nl80211_sta_wme_policy); |
| 3531 | if (err) |
| 3532 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3533 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3534 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3535 | params.uapsd_queues = |
| 3536 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3537 | if (params.uapsd_queues & |
| 3538 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3539 | return -EINVAL; |
| 3540 | |
| 3541 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3542 | params.max_sp = |
| 3543 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3544 | |
| 3545 | if (params.max_sp & |
| 3546 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3547 | return -EINVAL; |
| 3548 | |
| 3549 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3550 | } |
| 3551 | /* TDLS peers cannot be added */ |
| 3552 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3553 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3554 | /* but don't bother the driver with it */ |
| 3555 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3556 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3557 | /* allow authenticated/associated only if driver handles it */ |
| 3558 | if (!(rdev->wiphy.features & |
| 3559 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3560 | params.sta_flags_mask & |
| 3561 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3562 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3563 | return -EINVAL; |
| 3564 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3565 | /* must be last in here for error handling */ |
| 3566 | params.vlan = get_vlan(info, rdev); |
| 3567 | if (IS_ERR(params.vlan)) |
| 3568 | return PTR_ERR(params.vlan); |
| 3569 | break; |
| 3570 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3571 | /* associated is disallowed */ |
| 3572 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3573 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3574 | /* TDLS peers cannot be added */ |
| 3575 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3576 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3577 | break; |
| 3578 | case NL80211_IFTYPE_STATION: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3579 | /* associated is disallowed */ |
| 3580 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3581 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3582 | /* Only TDLS peers can be added */ |
| 3583 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3584 | return -EINVAL; |
| 3585 | /* Can only add if TDLS ... */ |
| 3586 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3587 | return -EOPNOTSUPP; |
| 3588 | /* ... with external setup is supported */ |
| 3589 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3590 | return -EOPNOTSUPP; |
| 3591 | break; |
| 3592 | default: |
| 3593 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3594 | } |
| 3595 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3596 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3597 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3598 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3599 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3600 | if (params.vlan) |
| 3601 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3602 | return err; |
| 3603 | } |
| 3604 | |
| 3605 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3606 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3607 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3608 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3609 | u8 *mac_addr = NULL; |
| 3610 | |
| 3611 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3612 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3613 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3614 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3615 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3616 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3618 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3619 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3620 | if (!rdev->ops->del_station) |
| 3621 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3622 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3623 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3624 | } |
| 3625 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3626 | 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] | 3627 | int flags, struct net_device *dev, |
| 3628 | u8 *dst, u8 *next_hop, |
| 3629 | struct mpath_info *pinfo) |
| 3630 | { |
| 3631 | void *hdr; |
| 3632 | struct nlattr *pinfoattr; |
| 3633 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3634 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3635 | if (!hdr) |
| 3636 | return -1; |
| 3637 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3638 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3639 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3640 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3641 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3642 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3643 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3644 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3645 | if (!pinfoattr) |
| 3646 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3647 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3648 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3649 | pinfo->frame_qlen)) |
| 3650 | goto nla_put_failure; |
| 3651 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3652 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3653 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3654 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3655 | pinfo->metric)) || |
| 3656 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3657 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3658 | pinfo->exptime)) || |
| 3659 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3660 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3661 | pinfo->flags)) || |
| 3662 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3663 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3664 | pinfo->discovery_timeout)) || |
| 3665 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3666 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3667 | pinfo->discovery_retries))) |
| 3668 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3669 | |
| 3670 | nla_nest_end(msg, pinfoattr); |
| 3671 | |
| 3672 | return genlmsg_end(msg, hdr); |
| 3673 | |
| 3674 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3675 | genlmsg_cancel(msg, hdr); |
| 3676 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3680 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3681 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3682 | struct mpath_info pinfo; |
| 3683 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3684 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3685 | u8 dst[ETH_ALEN]; |
| 3686 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3687 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3688 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3689 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3690 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3691 | if (err) |
| 3692 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3693 | |
| 3694 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3695 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3696 | goto out_err; |
| 3697 | } |
| 3698 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3699 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3700 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3701 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3702 | } |
| 3703 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3704 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3705 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3706 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3707 | if (err == -ENOENT) |
| 3708 | break; |
| 3709 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3710 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3711 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3712 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3713 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3714 | netdev, dst, next_hop, |
| 3715 | &pinfo) < 0) |
| 3716 | goto out; |
| 3717 | |
| 3718 | path_idx++; |
| 3719 | } |
| 3720 | |
| 3721 | |
| 3722 | out: |
| 3723 | cb->args[1] = path_idx; |
| 3724 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3725 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3726 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3727 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3731 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3733 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3734 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3735 | struct mpath_info pinfo; |
| 3736 | struct sk_buff *msg; |
| 3737 | u8 *dst = NULL; |
| 3738 | u8 next_hop[ETH_ALEN]; |
| 3739 | |
| 3740 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3741 | |
| 3742 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3743 | return -EINVAL; |
| 3744 | |
| 3745 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3747 | if (!rdev->ops->get_mpath) |
| 3748 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3749 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3750 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3751 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3752 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3753 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3754 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3755 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3756 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3758 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3759 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3760 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3761 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3762 | dev, dst, next_hop, &pinfo) < 0) { |
| 3763 | nlmsg_free(msg); |
| 3764 | return -ENOBUFS; |
| 3765 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3766 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3767 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3773 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3774 | u8 *dst = NULL; |
| 3775 | u8 *next_hop = NULL; |
| 3776 | |
| 3777 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3778 | return -EINVAL; |
| 3779 | |
| 3780 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3781 | return -EINVAL; |
| 3782 | |
| 3783 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3784 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3786 | if (!rdev->ops->change_mpath) |
| 3787 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3788 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3789 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3790 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3791 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3792 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3793 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3794 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3795 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3796 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3798 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3799 | u8 *dst = NULL; |
| 3800 | u8 *next_hop = NULL; |
| 3801 | |
| 3802 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3803 | return -EINVAL; |
| 3804 | |
| 3805 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3806 | return -EINVAL; |
| 3807 | |
| 3808 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3809 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3810 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3811 | if (!rdev->ops->add_mpath) |
| 3812 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3813 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3814 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3815 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3816 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3817 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3823 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3824 | u8 *dst = NULL; |
| 3825 | |
| 3826 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3827 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3828 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3829 | if (!rdev->ops->del_mpath) |
| 3830 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3831 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3832 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3833 | } |
| 3834 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3835 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3836 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3838 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3839 | struct bss_parameters params; |
| 3840 | |
| 3841 | memset(¶ms, 0, sizeof(params)); |
| 3842 | /* default to not changing parameters */ |
| 3843 | params.use_cts_prot = -1; |
| 3844 | params.use_short_preamble = -1; |
| 3845 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3846 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3847 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3848 | params.p2p_ctwindow = -1; |
| 3849 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3850 | |
| 3851 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3852 | params.use_cts_prot = |
| 3853 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3854 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3855 | params.use_short_preamble = |
| 3856 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3857 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3858 | params.use_short_slot_time = |
| 3859 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3860 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3861 | params.basic_rates = |
| 3862 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3863 | params.basic_rates_len = |
| 3864 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3865 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3866 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3867 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3868 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3869 | params.ht_opmode = |
| 3870 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3871 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3872 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3873 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3874 | return -EINVAL; |
| 3875 | params.p2p_ctwindow = |
| 3876 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3877 | if (params.p2p_ctwindow < 0) |
| 3878 | return -EINVAL; |
| 3879 | if (params.p2p_ctwindow != 0 && |
| 3880 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3881 | return -EINVAL; |
| 3882 | } |
| 3883 | |
| 3884 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3885 | u8 tmp; |
| 3886 | |
| 3887 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3888 | return -EINVAL; |
| 3889 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3890 | if (tmp > 1) |
| 3891 | return -EINVAL; |
| 3892 | params.p2p_opp_ps = tmp; |
| 3893 | if (params.p2p_opp_ps && |
| 3894 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3895 | return -EINVAL; |
| 3896 | } |
| 3897 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3898 | if (!rdev->ops->change_bss) |
| 3899 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3900 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3901 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3902 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3903 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3904 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3905 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3906 | } |
| 3907 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3908 | 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] | 3909 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3910 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3911 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3912 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3913 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3914 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3915 | }; |
| 3916 | |
| 3917 | static int parse_reg_rule(struct nlattr *tb[], |
| 3918 | struct ieee80211_reg_rule *reg_rule) |
| 3919 | { |
| 3920 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3921 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3922 | |
| 3923 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3924 | return -EINVAL; |
| 3925 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3926 | return -EINVAL; |
| 3927 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3928 | return -EINVAL; |
| 3929 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3930 | return -EINVAL; |
| 3931 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3932 | return -EINVAL; |
| 3933 | |
| 3934 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3935 | |
| 3936 | freq_range->start_freq_khz = |
| 3937 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3938 | freq_range->end_freq_khz = |
| 3939 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3940 | freq_range->max_bandwidth_khz = |
| 3941 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3942 | |
| 3943 | power_rule->max_eirp = |
| 3944 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3945 | |
| 3946 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3947 | power_rule->max_antenna_gain = |
| 3948 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3949 | |
| 3950 | return 0; |
| 3951 | } |
| 3952 | |
| 3953 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3954 | { |
| 3955 | int r; |
| 3956 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3957 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3958 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3959 | /* |
| 3960 | * You should only get this when cfg80211 hasn't yet initialized |
| 3961 | * completely when built-in to the kernel right between the time |
| 3962 | * window between nl80211_init() and regulatory_init(), if that is |
| 3963 | * even possible. |
| 3964 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 3965 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3966 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3967 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3968 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3969 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3970 | |
| 3971 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3972 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3973 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3974 | user_reg_hint_type = |
| 3975 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3976 | else |
| 3977 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3978 | |
| 3979 | switch (user_reg_hint_type) { |
| 3980 | case NL80211_USER_REG_HINT_USER: |
| 3981 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3982 | break; |
| 3983 | default: |
| 3984 | return -EINVAL; |
| 3985 | } |
| 3986 | |
| 3987 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3988 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3989 | return r; |
| 3990 | } |
| 3991 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3992 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3993 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3994 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3996 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3997 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3998 | struct mesh_config cur_params; |
| 3999 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4000 | void *hdr; |
| 4001 | struct nlattr *pinfoattr; |
| 4002 | struct sk_buff *msg; |
| 4003 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4004 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4005 | return -EOPNOTSUPP; |
| 4006 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4007 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4008 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4009 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4010 | wdev_lock(wdev); |
| 4011 | /* If not connected, get default parameters */ |
| 4012 | if (!wdev->mesh_id_len) |
| 4013 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4014 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4015 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4016 | wdev_unlock(wdev); |
| 4017 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4018 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4019 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4020 | |
| 4021 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4022 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4023 | if (!msg) |
| 4024 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4025 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4026 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4027 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4028 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4029 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4030 | if (!pinfoattr) |
| 4031 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4032 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4033 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4034 | cur_params.dot11MeshRetryTimeout) || |
| 4035 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4036 | cur_params.dot11MeshConfirmTimeout) || |
| 4037 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4038 | cur_params.dot11MeshHoldingTimeout) || |
| 4039 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4040 | cur_params.dot11MeshMaxPeerLinks) || |
| 4041 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4042 | cur_params.dot11MeshMaxRetries) || |
| 4043 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4044 | cur_params.dot11MeshTTL) || |
| 4045 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4046 | cur_params.element_ttl) || |
| 4047 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4048 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4049 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4050 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4051 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4052 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4053 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4054 | cur_params.path_refresh_time) || |
| 4055 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4056 | cur_params.min_discovery_timeout) || |
| 4057 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4058 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4059 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4060 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4061 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4062 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4063 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4064 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4065 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4066 | cur_params.dot11MeshHWMPRootMode) || |
| 4067 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4068 | cur_params.dot11MeshHWMPRannInterval) || |
| 4069 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4070 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4071 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4072 | cur_params.dot11MeshForwarding) || |
| 4073 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4074 | cur_params.rssi_threshold) || |
| 4075 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4076 | cur_params.ht_opmode) || |
| 4077 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4078 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4079 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4080 | cur_params.dot11MeshHWMProotInterval) || |
| 4081 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4082 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4083 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4084 | cur_params.power_mode) || |
| 4085 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4086 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4087 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4088 | nla_nest_end(msg, pinfoattr); |
| 4089 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4090 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4091 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4092 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4093 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4094 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4095 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4096 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4099 | 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] | 4100 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4101 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4102 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4103 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4104 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4105 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4106 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4107 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4108 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4109 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4110 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4111 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4112 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4113 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4114 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4115 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4116 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4117 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4118 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4119 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4120 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4121 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4122 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4123 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4124 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4125 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4126 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4127 | }; |
| 4128 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4129 | static const struct nla_policy |
| 4130 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4131 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4132 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4133 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4134 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4135 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4136 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4137 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4138 | }; |
| 4139 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4140 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4141 | struct mesh_config *cfg, |
| 4142 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4143 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4144 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4145 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4146 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4147 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4148 | do { \ |
| 4149 | if (tb[attr]) { \ |
| 4150 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4151 | return -EINVAL; \ |
| 4152 | cfg->param = fn(tb[attr]); \ |
| 4153 | mask |= (1 << (attr - 1)); \ |
| 4154 | } \ |
| 4155 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4156 | |
| 4157 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4158 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4159 | return -EINVAL; |
| 4160 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4161 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4162 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4163 | return -EINVAL; |
| 4164 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4165 | /* This makes sure that there aren't more than 32 mesh config |
| 4166 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4167 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4168 | |
| 4169 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4170 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4171 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4172 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4174 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4175 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4177 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4178 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4179 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4180 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4181 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4182 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4183 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4184 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4186 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4187 | 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] | 4188 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4189 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4190 | 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] | 4191 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4192 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4193 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4194 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4195 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4196 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4197 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4198 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4199 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4200 | 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] | 4201 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4202 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4203 | 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] | 4204 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4205 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4207 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4208 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4209 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4210 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4211 | 1, 65535, mask, |
| 4212 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4213 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4214 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4215 | 1, 65535, mask, |
| 4216 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4217 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4219 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4220 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4221 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4222 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4223 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4224 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4225 | nla_get_u8); |
| 4226 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4227 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4228 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4230 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4231 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4232 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4233 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4234 | mask, NL80211_MESHCONF_FORWARDING, |
| 4235 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4236 | 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] | 4237 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4238 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4239 | 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] | 4240 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4241 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4243 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4244 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4245 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4246 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4247 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4248 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4249 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4250 | dot11MeshHWMPconfirmationInterval, |
| 4251 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4252 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4253 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4255 | NL80211_MESH_POWER_ACTIVE, |
| 4256 | NL80211_MESH_POWER_MAX, |
| 4257 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4258 | nla_get_u32); |
| 4259 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4260 | 0, 65535, mask, |
| 4261 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4262 | if (mask_out) |
| 4263 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4264 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4265 | return 0; |
| 4266 | |
| 4267 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4268 | } |
| 4269 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4270 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4271 | struct mesh_setup *setup) |
| 4272 | { |
| 4273 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4274 | |
| 4275 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4276 | return -EINVAL; |
| 4277 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4278 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4279 | nl80211_mesh_setup_params_policy)) |
| 4280 | return -EINVAL; |
| 4281 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4282 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4283 | setup->sync_method = |
| 4284 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4285 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4286 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4287 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4288 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4289 | setup->path_sel_proto = |
| 4290 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4291 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4292 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4293 | |
| 4294 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4295 | setup->path_metric = |
| 4296 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4297 | IEEE80211_PATH_METRIC_VENDOR : |
| 4298 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4299 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4300 | |
| 4301 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4302 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4303 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4304 | if (!is_valid_ie_attr(ieattr)) |
| 4305 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4306 | setup->ie = nla_data(ieattr); |
| 4307 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4308 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4309 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4310 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4311 | |
| 4312 | return 0; |
| 4313 | } |
| 4314 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4315 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4316 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4317 | { |
| 4318 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4319 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4320 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4321 | struct mesh_config cfg; |
| 4322 | u32 mask; |
| 4323 | int err; |
| 4324 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4325 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4326 | return -EOPNOTSUPP; |
| 4327 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4328 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4329 | return -EOPNOTSUPP; |
| 4330 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4331 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4332 | if (err) |
| 4333 | return err; |
| 4334 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4335 | wdev_lock(wdev); |
| 4336 | if (!wdev->mesh_id_len) |
| 4337 | err = -ENOLINK; |
| 4338 | |
| 4339 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4340 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4341 | |
| 4342 | wdev_unlock(wdev); |
| 4343 | |
| 4344 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4345 | } |
| 4346 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4347 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4348 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4349 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4350 | struct sk_buff *msg; |
| 4351 | void *hdr = NULL; |
| 4352 | struct nlattr *nl_reg_rules; |
| 4353 | unsigned int i; |
| 4354 | int err = -EINVAL; |
| 4355 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4356 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4357 | |
| 4358 | if (!cfg80211_regdomain) |
| 4359 | goto out; |
| 4360 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4361 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4362 | if (!msg) { |
| 4363 | err = -ENOBUFS; |
| 4364 | goto out; |
| 4365 | } |
| 4366 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4367 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4368 | NL80211_CMD_GET_REG); |
| 4369 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4370 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4371 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4372 | if (reg_last_request_cell_base() && |
| 4373 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4374 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4375 | goto nla_put_failure; |
| 4376 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4377 | rcu_read_lock(); |
| 4378 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4379 | |
| 4380 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4381 | (regdom->dfs_region && |
| 4382 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4383 | goto nla_put_failure_rcu; |
| 4384 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4385 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4386 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4387 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4388 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4389 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4390 | struct nlattr *nl_reg_rule; |
| 4391 | const struct ieee80211_reg_rule *reg_rule; |
| 4392 | const struct ieee80211_freq_range *freq_range; |
| 4393 | const struct ieee80211_power_rule *power_rule; |
| 4394 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4395 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4396 | freq_range = ®_rule->freq_range; |
| 4397 | power_rule = ®_rule->power_rule; |
| 4398 | |
| 4399 | nl_reg_rule = nla_nest_start(msg, i); |
| 4400 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4401 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4402 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4403 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4404 | reg_rule->flags) || |
| 4405 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4406 | freq_range->start_freq_khz) || |
| 4407 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4408 | freq_range->end_freq_khz) || |
| 4409 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4410 | freq_range->max_bandwidth_khz) || |
| 4411 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4412 | power_rule->max_antenna_gain) || |
| 4413 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4414 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4415 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4416 | |
| 4417 | nla_nest_end(msg, nl_reg_rule); |
| 4418 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4419 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4420 | |
| 4421 | nla_nest_end(msg, nl_reg_rules); |
| 4422 | |
| 4423 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4424 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4425 | goto out; |
| 4426 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4427 | nla_put_failure_rcu: |
| 4428 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4429 | nla_put_failure: |
| 4430 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4431 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4432 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4433 | err = -EMSGSIZE; |
| 4434 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4435 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4436 | return err; |
| 4437 | } |
| 4438 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4439 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4440 | { |
| 4441 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4442 | struct nlattr *nl_reg_rule; |
| 4443 | char *alpha2 = NULL; |
| 4444 | int rem_reg_rules = 0, r = 0; |
| 4445 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4446 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4447 | struct ieee80211_regdomain *rd = NULL; |
| 4448 | |
| 4449 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4450 | return -EINVAL; |
| 4451 | |
| 4452 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4453 | return -EINVAL; |
| 4454 | |
| 4455 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4456 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4457 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4458 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4459 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4460 | 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] | 4461 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4462 | num_rules++; |
| 4463 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4464 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4467 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4468 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4469 | |
| 4470 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4471 | if (!rd) |
| 4472 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4473 | |
| 4474 | rd->n_reg_rules = num_rules; |
| 4475 | rd->alpha2[0] = alpha2[0]; |
| 4476 | rd->alpha2[1] = alpha2[1]; |
| 4477 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4478 | /* |
| 4479 | * Disable DFS master mode if the DFS region was |
| 4480 | * not supported or known on this kernel. |
| 4481 | */ |
| 4482 | if (reg_supported_dfs_region(dfs_region)) |
| 4483 | rd->dfs_region = dfs_region; |
| 4484 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4485 | 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] | 4486 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4487 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4488 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4489 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4490 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4491 | if (r) |
| 4492 | goto bad_reg; |
| 4493 | |
| 4494 | rule_idx++; |
| 4495 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4496 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4497 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4498 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4499 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4502 | mutex_lock(&cfg80211_mutex); |
| 4503 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4504 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4505 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4506 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4507 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4508 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4509 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4510 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4511 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4512 | } |
| 4513 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4514 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4515 | { |
| 4516 | struct nlattr *attr1, *attr2; |
| 4517 | int n_channels = 0, tmp1, tmp2; |
| 4518 | |
| 4519 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4520 | n_channels++; |
| 4521 | /* |
| 4522 | * Some hardware has a limited channel list for |
| 4523 | * scanning, and it is pretty much nonsensical |
| 4524 | * to scan for a channel twice, so disallow that |
| 4525 | * and don't require drivers to check that the |
| 4526 | * channel list they get isn't longer than what |
| 4527 | * they can scan, as long as they can scan all |
| 4528 | * the channels they registered at once. |
| 4529 | */ |
| 4530 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4531 | if (attr1 != attr2 && |
| 4532 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4533 | return 0; |
| 4534 | } |
| 4535 | |
| 4536 | return n_channels; |
| 4537 | } |
| 4538 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4539 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4542 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4543 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4544 | struct nlattr *attr; |
| 4545 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4546 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4547 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4548 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4549 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4550 | return -EINVAL; |
| 4551 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4552 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4554 | if (!rdev->ops->scan) |
| 4555 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4557 | if (rdev->scan_req) |
| 4558 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4559 | |
| 4560 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4561 | n_channels = validate_scan_freqs( |
| 4562 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4563 | if (!n_channels) |
| 4564 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4565 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4566 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4567 | n_channels = 0; |
| 4568 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4569 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4570 | if (wiphy->bands[band]) |
| 4571 | n_channels += wiphy->bands[band]->n_channels; |
| 4572 | } |
| 4573 | |
| 4574 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4575 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4576 | n_ssids++; |
| 4577 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4578 | if (n_ssids > wiphy->max_scan_ssids) |
| 4579 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4580 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4581 | if (info->attrs[NL80211_ATTR_IE]) |
| 4582 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4583 | else |
| 4584 | ie_len = 0; |
| 4585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4586 | if (ie_len > wiphy->max_scan_ie_len) |
| 4587 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4588 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4589 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4590 | + sizeof(*request->ssids) * n_ssids |
| 4591 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4592 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4593 | if (!request) |
| 4594 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4595 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4596 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4597 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4598 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4599 | if (ie_len) { |
| 4600 | if (request->ssids) |
| 4601 | request->ie = (void *)(request->ssids + n_ssids); |
| 4602 | else |
| 4603 | request->ie = (void *)(request->channels + n_channels); |
| 4604 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4605 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4606 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4607 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4608 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4609 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4610 | struct ieee80211_channel *chan; |
| 4611 | |
| 4612 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4613 | |
| 4614 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4615 | err = -EINVAL; |
| 4616 | goto out_free; |
| 4617 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4618 | |
| 4619 | /* ignore disabled channels */ |
| 4620 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4621 | continue; |
| 4622 | |
| 4623 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4624 | i++; |
| 4625 | } |
| 4626 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4627 | enum ieee80211_band band; |
| 4628 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4629 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4630 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4631 | int j; |
| 4632 | if (!wiphy->bands[band]) |
| 4633 | continue; |
| 4634 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4635 | struct ieee80211_channel *chan; |
| 4636 | |
| 4637 | chan = &wiphy->bands[band]->channels[j]; |
| 4638 | |
| 4639 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4640 | continue; |
| 4641 | |
| 4642 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4643 | i++; |
| 4644 | } |
| 4645 | } |
| 4646 | } |
| 4647 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4648 | if (!i) { |
| 4649 | err = -EINVAL; |
| 4650 | goto out_free; |
| 4651 | } |
| 4652 | |
| 4653 | request->n_channels = i; |
| 4654 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4655 | i = 0; |
| 4656 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4657 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4658 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4659 | err = -EINVAL; |
| 4660 | goto out_free; |
| 4661 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4662 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4663 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4664 | i++; |
| 4665 | } |
| 4666 | } |
| 4667 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4668 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4669 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4670 | memcpy((void *)request->ie, |
| 4671 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4672 | request->ie_len); |
| 4673 | } |
| 4674 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4675 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4676 | if (wiphy->bands[i]) |
| 4677 | request->rates[i] = |
| 4678 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4679 | |
| 4680 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4681 | nla_for_each_nested(attr, |
| 4682 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4683 | tmp) { |
| 4684 | enum ieee80211_band band = nla_type(attr); |
| 4685 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4686 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4687 | err = -EINVAL; |
| 4688 | goto out_free; |
| 4689 | } |
| 4690 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4691 | nla_data(attr), |
| 4692 | nla_len(attr), |
| 4693 | &request->rates[band]); |
| 4694 | if (err) |
| 4695 | goto out_free; |
| 4696 | } |
| 4697 | } |
| 4698 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4699 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4700 | request->flags = nla_get_u32( |
| 4701 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4702 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4703 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4704 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4705 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4706 | err = -EOPNOTSUPP; |
| 4707 | goto out_free; |
| 4708 | } |
| 4709 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4710 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4711 | request->no_cck = |
| 4712 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4713 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4714 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4715 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4716 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4717 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4718 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4719 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4720 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4721 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4722 | nl80211_send_scan_start(rdev, wdev); |
| 4723 | if (wdev->netdev) |
| 4724 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4725 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4726 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4727 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4728 | kfree(request); |
| 4729 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4730 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4731 | return err; |
| 4732 | } |
| 4733 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4734 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4735 | struct genl_info *info) |
| 4736 | { |
| 4737 | struct cfg80211_sched_scan_request *request; |
| 4738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4739 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4740 | struct nlattr *attr; |
| 4741 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4742 | 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] | 4743 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4744 | enum ieee80211_band band; |
| 4745 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4746 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4747 | |
| 4748 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4749 | !rdev->ops->sched_scan_start) |
| 4750 | return -EOPNOTSUPP; |
| 4751 | |
| 4752 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4753 | return -EINVAL; |
| 4754 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4755 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4756 | return -EINVAL; |
| 4757 | |
| 4758 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4759 | if (interval == 0) |
| 4760 | return -EINVAL; |
| 4761 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4762 | wiphy = &rdev->wiphy; |
| 4763 | |
| 4764 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4765 | n_channels = validate_scan_freqs( |
| 4766 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4767 | if (!n_channels) |
| 4768 | return -EINVAL; |
| 4769 | } else { |
| 4770 | n_channels = 0; |
| 4771 | |
| 4772 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4773 | if (wiphy->bands[band]) |
| 4774 | n_channels += wiphy->bands[band]->n_channels; |
| 4775 | } |
| 4776 | |
| 4777 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4778 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4779 | tmp) |
| 4780 | n_ssids++; |
| 4781 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4782 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4783 | return -EINVAL; |
| 4784 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4785 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4786 | nla_for_each_nested(attr, |
| 4787 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4788 | tmp) |
| 4789 | n_match_sets++; |
| 4790 | |
| 4791 | if (n_match_sets > wiphy->max_match_sets) |
| 4792 | return -EINVAL; |
| 4793 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4794 | if (info->attrs[NL80211_ATTR_IE]) |
| 4795 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4796 | else |
| 4797 | ie_len = 0; |
| 4798 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4799 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4800 | return -EINVAL; |
| 4801 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4802 | mutex_lock(&rdev->sched_scan_mtx); |
| 4803 | |
| 4804 | if (rdev->sched_scan_req) { |
| 4805 | err = -EINPROGRESS; |
| 4806 | goto out; |
| 4807 | } |
| 4808 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4809 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4810 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4811 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4812 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4813 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4814 | if (!request) { |
| 4815 | err = -ENOMEM; |
| 4816 | goto out; |
| 4817 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4818 | |
| 4819 | if (n_ssids) |
| 4820 | request->ssids = (void *)&request->channels[n_channels]; |
| 4821 | request->n_ssids = n_ssids; |
| 4822 | if (ie_len) { |
| 4823 | if (request->ssids) |
| 4824 | request->ie = (void *)(request->ssids + n_ssids); |
| 4825 | else |
| 4826 | request->ie = (void *)(request->channels + n_channels); |
| 4827 | } |
| 4828 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4829 | if (n_match_sets) { |
| 4830 | if (request->ie) |
| 4831 | request->match_sets = (void *)(request->ie + ie_len); |
| 4832 | else if (request->ssids) |
| 4833 | request->match_sets = |
| 4834 | (void *)(request->ssids + n_ssids); |
| 4835 | else |
| 4836 | request->match_sets = |
| 4837 | (void *)(request->channels + n_channels); |
| 4838 | } |
| 4839 | request->n_match_sets = n_match_sets; |
| 4840 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4841 | i = 0; |
| 4842 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4843 | /* user specified, bail out if channel not found */ |
| 4844 | nla_for_each_nested(attr, |
| 4845 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4846 | tmp) { |
| 4847 | struct ieee80211_channel *chan; |
| 4848 | |
| 4849 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4850 | |
| 4851 | if (!chan) { |
| 4852 | err = -EINVAL; |
| 4853 | goto out_free; |
| 4854 | } |
| 4855 | |
| 4856 | /* ignore disabled channels */ |
| 4857 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4858 | continue; |
| 4859 | |
| 4860 | request->channels[i] = chan; |
| 4861 | i++; |
| 4862 | } |
| 4863 | } else { |
| 4864 | /* all channels */ |
| 4865 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4866 | int j; |
| 4867 | if (!wiphy->bands[band]) |
| 4868 | continue; |
| 4869 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4870 | struct ieee80211_channel *chan; |
| 4871 | |
| 4872 | chan = &wiphy->bands[band]->channels[j]; |
| 4873 | |
| 4874 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4875 | continue; |
| 4876 | |
| 4877 | request->channels[i] = chan; |
| 4878 | i++; |
| 4879 | } |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | if (!i) { |
| 4884 | err = -EINVAL; |
| 4885 | goto out_free; |
| 4886 | } |
| 4887 | |
| 4888 | request->n_channels = i; |
| 4889 | |
| 4890 | i = 0; |
| 4891 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4892 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4893 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4894 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4895 | err = -EINVAL; |
| 4896 | goto out_free; |
| 4897 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4898 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4899 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4900 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4901 | i++; |
| 4902 | } |
| 4903 | } |
| 4904 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4905 | i = 0; |
| 4906 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4907 | nla_for_each_nested(attr, |
| 4908 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4909 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4910 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4911 | |
| 4912 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4913 | nla_data(attr), nla_len(attr), |
| 4914 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4915 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4916 | if (ssid) { |
| 4917 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4918 | err = -EINVAL; |
| 4919 | goto out_free; |
| 4920 | } |
| 4921 | memcpy(request->match_sets[i].ssid.ssid, |
| 4922 | nla_data(ssid), nla_len(ssid)); |
| 4923 | request->match_sets[i].ssid.ssid_len = |
| 4924 | nla_len(ssid); |
| 4925 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4926 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4927 | if (rssi) |
| 4928 | request->rssi_thold = nla_get_u32(rssi); |
| 4929 | else |
| 4930 | request->rssi_thold = |
| 4931 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4932 | i++; |
| 4933 | } |
| 4934 | } |
| 4935 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4936 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4937 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4938 | memcpy((void *)request->ie, |
| 4939 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4940 | request->ie_len); |
| 4941 | } |
| 4942 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4944 | request->flags = nla_get_u32( |
| 4945 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4946 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4947 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4948 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4949 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4950 | err = -EOPNOTSUPP; |
| 4951 | goto out_free; |
| 4952 | } |
| 4953 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4954 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4955 | request->dev = dev; |
| 4956 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4957 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4958 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4959 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4960 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4961 | if (!err) { |
| 4962 | rdev->sched_scan_req = request; |
| 4963 | nl80211_send_sched_scan(rdev, dev, |
| 4964 | NL80211_CMD_START_SCHED_SCAN); |
| 4965 | goto out; |
| 4966 | } |
| 4967 | |
| 4968 | out_free: |
| 4969 | kfree(request); |
| 4970 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4971 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4972 | return err; |
| 4973 | } |
| 4974 | |
| 4975 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4976 | struct genl_info *info) |
| 4977 | { |
| 4978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4979 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4980 | |
| 4981 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4982 | !rdev->ops->sched_scan_stop) |
| 4983 | return -EOPNOTSUPP; |
| 4984 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4985 | mutex_lock(&rdev->sched_scan_mtx); |
| 4986 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4987 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4988 | |
| 4989 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4990 | } |
| 4991 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4992 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4993 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4994 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4995 | struct wireless_dev *wdev, |
| 4996 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4997 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4998 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4999 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5000 | void *hdr; |
| 5001 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5002 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5003 | |
| 5004 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5005 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5006 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5007 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5008 | if (!hdr) |
| 5009 | return -1; |
| 5010 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5011 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5012 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5013 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5014 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5015 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5016 | |
| 5017 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5018 | if (!bss) |
| 5019 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5020 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5021 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5022 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5023 | |
| 5024 | rcu_read_lock(); |
| 5025 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5026 | if (ies) { |
| 5027 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5028 | goto fail_unlock_rcu; |
| 5029 | tsf = true; |
| 5030 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5031 | ies->len, ies->data)) |
| 5032 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5033 | } |
| 5034 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5035 | if (ies) { |
| 5036 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5037 | goto fail_unlock_rcu; |
| 5038 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5039 | ies->len, ies->data)) |
| 5040 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5041 | } |
| 5042 | rcu_read_unlock(); |
| 5043 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5044 | if (res->beacon_interval && |
| 5045 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5046 | goto nla_put_failure; |
| 5047 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5048 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5049 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5050 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5051 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5052 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5053 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5054 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5055 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5056 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5057 | break; |
| 5058 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5059 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5060 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5061 | break; |
| 5062 | default: |
| 5063 | break; |
| 5064 | } |
| 5065 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5066 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5067 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5068 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5069 | if (intbss == wdev->current_bss && |
| 5070 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5071 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5072 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5073 | break; |
| 5074 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5075 | if (intbss == wdev->current_bss && |
| 5076 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5077 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5078 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5079 | break; |
| 5080 | default: |
| 5081 | break; |
| 5082 | } |
| 5083 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5084 | nla_nest_end(msg, bss); |
| 5085 | |
| 5086 | return genlmsg_end(msg, hdr); |
| 5087 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5088 | fail_unlock_rcu: |
| 5089 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5090 | nla_put_failure: |
| 5091 | genlmsg_cancel(msg, hdr); |
| 5092 | return -EMSGSIZE; |
| 5093 | } |
| 5094 | |
| 5095 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5096 | struct netlink_callback *cb) |
| 5097 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5098 | struct cfg80211_registered_device *rdev; |
| 5099 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5100 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5101 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5102 | int start = cb->args[1], idx = 0; |
| 5103 | int err; |
| 5104 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5105 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5106 | if (err) |
| 5107 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5108 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5109 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5110 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5111 | wdev_lock(wdev); |
| 5112 | spin_lock_bh(&rdev->bss_lock); |
| 5113 | cfg80211_bss_expire(rdev); |
| 5114 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5115 | cb->seq = rdev->bss_generation; |
| 5116 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5117 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5118 | if (++idx <= start) |
| 5119 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5120 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5121 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5122 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5123 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5124 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5125 | } |
| 5126 | } |
| 5127 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5128 | spin_unlock_bh(&rdev->bss_lock); |
| 5129 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5130 | |
| 5131 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5132 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5133 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5134 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5135 | } |
| 5136 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5137 | 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] | 5138 | int flags, struct net_device *dev, |
| 5139 | struct survey_info *survey) |
| 5140 | { |
| 5141 | void *hdr; |
| 5142 | struct nlattr *infoattr; |
| 5143 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5144 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5145 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5146 | if (!hdr) |
| 5147 | return -ENOMEM; |
| 5148 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5149 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5150 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5151 | |
| 5152 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5153 | if (!infoattr) |
| 5154 | goto nla_put_failure; |
| 5155 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5156 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5157 | survey->channel->center_freq)) |
| 5158 | goto nla_put_failure; |
| 5159 | |
| 5160 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5161 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5162 | goto nla_put_failure; |
| 5163 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5164 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5165 | goto nla_put_failure; |
| 5166 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5167 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5168 | survey->channel_time)) |
| 5169 | goto nla_put_failure; |
| 5170 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5171 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5172 | survey->channel_time_busy)) |
| 5173 | goto nla_put_failure; |
| 5174 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5175 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5176 | survey->channel_time_ext_busy)) |
| 5177 | goto nla_put_failure; |
| 5178 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5179 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5180 | survey->channel_time_rx)) |
| 5181 | goto nla_put_failure; |
| 5182 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5183 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5184 | survey->channel_time_tx)) |
| 5185 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5186 | |
| 5187 | nla_nest_end(msg, infoattr); |
| 5188 | |
| 5189 | return genlmsg_end(msg, hdr); |
| 5190 | |
| 5191 | nla_put_failure: |
| 5192 | genlmsg_cancel(msg, hdr); |
| 5193 | return -EMSGSIZE; |
| 5194 | } |
| 5195 | |
| 5196 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5197 | struct netlink_callback *cb) |
| 5198 | { |
| 5199 | struct survey_info survey; |
| 5200 | struct cfg80211_registered_device *dev; |
| 5201 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5202 | int survey_idx = cb->args[1]; |
| 5203 | int res; |
| 5204 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5205 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5206 | if (res) |
| 5207 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5208 | |
| 5209 | if (!dev->ops->dump_survey) { |
| 5210 | res = -EOPNOTSUPP; |
| 5211 | goto out_err; |
| 5212 | } |
| 5213 | |
| 5214 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5215 | struct ieee80211_channel *chan; |
| 5216 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5217 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5218 | if (res == -ENOENT) |
| 5219 | break; |
| 5220 | if (res) |
| 5221 | goto out_err; |
| 5222 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5223 | /* Survey without a channel doesn't make sense */ |
| 5224 | if (!survey.channel) { |
| 5225 | res = -EINVAL; |
| 5226 | goto out; |
| 5227 | } |
| 5228 | |
| 5229 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5230 | survey.channel->center_freq); |
| 5231 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5232 | survey_idx++; |
| 5233 | continue; |
| 5234 | } |
| 5235 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5236 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5237 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5238 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5239 | netdev, |
| 5240 | &survey) < 0) |
| 5241 | goto out; |
| 5242 | survey_idx++; |
| 5243 | } |
| 5244 | |
| 5245 | out: |
| 5246 | cb->args[1] = survey_idx; |
| 5247 | res = skb->len; |
| 5248 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5249 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5250 | return res; |
| 5251 | } |
| 5252 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5253 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5254 | { |
| 5255 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5256 | NL80211_WPA_VERSION_2)); |
| 5257 | } |
| 5258 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5259 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5260 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5262 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5263 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5264 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5265 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5266 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5267 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5268 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5269 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5270 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5271 | return -EINVAL; |
| 5272 | |
| 5273 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5274 | return -EINVAL; |
| 5275 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5276 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5277 | return -EINVAL; |
| 5278 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5279 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5280 | return -EINVAL; |
| 5281 | |
| 5282 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5283 | return -EINVAL; |
| 5284 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5285 | err = nl80211_parse_key(info, &key); |
| 5286 | if (err) |
| 5287 | return err; |
| 5288 | |
| 5289 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5290 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5291 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5292 | if (!key.p.key || !key.p.key_len) |
| 5293 | return -EINVAL; |
| 5294 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5295 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5296 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5297 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5298 | return -EINVAL; |
| 5299 | if (key.idx > 4) |
| 5300 | return -EINVAL; |
| 5301 | } else { |
| 5302 | key.p.key_len = 0; |
| 5303 | key.p.key = NULL; |
| 5304 | } |
| 5305 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5306 | if (key.idx >= 0) { |
| 5307 | int i; |
| 5308 | bool ok = false; |
| 5309 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5310 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5311 | ok = true; |
| 5312 | break; |
| 5313 | } |
| 5314 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5315 | if (!ok) |
| 5316 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5317 | } |
| 5318 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5319 | if (!rdev->ops->auth) |
| 5320 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5321 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5322 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5323 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5324 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5325 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5326 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5327 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5328 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5329 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5330 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5331 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5332 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5333 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5334 | |
| 5335 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5336 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5337 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5338 | } |
| 5339 | |
| 5340 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5341 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5342 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5343 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5344 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5345 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5346 | return -EINVAL; |
| 5347 | |
| 5348 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5349 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5350 | return -EINVAL; |
| 5351 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5352 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5353 | /* need to include at least Auth Transaction and Status Code */ |
| 5354 | if (sae_data_len < 4) |
| 5355 | return -EINVAL; |
| 5356 | } |
| 5357 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5358 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5359 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5360 | /* |
| 5361 | * Since we no longer track auth state, ignore |
| 5362 | * requests to only change local state. |
| 5363 | */ |
| 5364 | if (local_state_change) |
| 5365 | return 0; |
| 5366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5367 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5368 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5369 | key.p.key, key.p.key_len, key.idx, |
| 5370 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5371 | } |
| 5372 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5373 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5374 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5375 | struct cfg80211_crypto_settings *settings, |
| 5376 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5377 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5378 | memset(settings, 0, sizeof(*settings)); |
| 5379 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5380 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5381 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5382 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5383 | u16 proto; |
| 5384 | proto = nla_get_u16( |
| 5385 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5386 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5387 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5388 | proto != ETH_P_PAE) |
| 5389 | return -EINVAL; |
| 5390 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5391 | settings->control_port_no_encrypt = true; |
| 5392 | } else |
| 5393 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5394 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5395 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5396 | void *data; |
| 5397 | int len, i; |
| 5398 | |
| 5399 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5400 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5401 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5402 | |
| 5403 | if (len % sizeof(u32)) |
| 5404 | return -EINVAL; |
| 5405 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5406 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5407 | return -EINVAL; |
| 5408 | |
| 5409 | memcpy(settings->ciphers_pairwise, data, len); |
| 5410 | |
| 5411 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5412 | if (!cfg80211_supported_cipher_suite( |
| 5413 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5414 | settings->ciphers_pairwise[i])) |
| 5415 | return -EINVAL; |
| 5416 | } |
| 5417 | |
| 5418 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5419 | settings->cipher_group = |
| 5420 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5421 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5422 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5423 | return -EINVAL; |
| 5424 | } |
| 5425 | |
| 5426 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5427 | settings->wpa_versions = |
| 5428 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5429 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5430 | return -EINVAL; |
| 5431 | } |
| 5432 | |
| 5433 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5434 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5435 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5436 | |
| 5437 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5438 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5439 | settings->n_akm_suites = len / sizeof(u32); |
| 5440 | |
| 5441 | if (len % sizeof(u32)) |
| 5442 | return -EINVAL; |
| 5443 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5444 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5445 | return -EINVAL; |
| 5446 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5447 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5448 | } |
| 5449 | |
| 5450 | return 0; |
| 5451 | } |
| 5452 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5453 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5454 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5456 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5457 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5458 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5459 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5460 | int err, ssid_len, ie_len = 0; |
| 5461 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5462 | u32 flags = 0; |
| 5463 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5464 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5465 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5466 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5467 | return -EINVAL; |
| 5468 | |
| 5469 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5470 | !info->attrs[NL80211_ATTR_SSID] || |
| 5471 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5472 | return -EINVAL; |
| 5473 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5474 | if (!rdev->ops->assoc) |
| 5475 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5476 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5478 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5479 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5480 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5481 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5482 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5483 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5484 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5485 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5486 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5487 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5488 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5489 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5490 | |
| 5491 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5492 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5493 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5494 | } |
| 5495 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5496 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5497 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5498 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5499 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5500 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5501 | else if (mfp != NL80211_MFP_NO) |
| 5502 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5503 | } |
| 5504 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5505 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5506 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5507 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5508 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5509 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5510 | |
| 5511 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5512 | ht_capa_mask = |
| 5513 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5514 | |
| 5515 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5516 | if (!ht_capa_mask) |
| 5517 | return -EINVAL; |
| 5518 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5519 | } |
| 5520 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5521 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5522 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5523 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5524 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5525 | &crypto, flags, ht_capa, |
| 5526 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5527 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5528 | return err; |
| 5529 | } |
| 5530 | |
| 5531 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5534 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5535 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5536 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5537 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5538 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5539 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5540 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5541 | return -EINVAL; |
| 5542 | |
| 5543 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5544 | return -EINVAL; |
| 5545 | |
| 5546 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5547 | return -EINVAL; |
| 5548 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5549 | if (!rdev->ops->deauth) |
| 5550 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5551 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5552 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5553 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5554 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5555 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5556 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5557 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5558 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5559 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5560 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5561 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5562 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5563 | |
| 5564 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5565 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5566 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5567 | } |
| 5568 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5569 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5570 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5571 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5572 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5576 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5578 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5579 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5580 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5581 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5582 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5583 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5584 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5585 | return -EINVAL; |
| 5586 | |
| 5587 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5588 | return -EINVAL; |
| 5589 | |
| 5590 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5591 | return -EINVAL; |
| 5592 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5593 | if (!rdev->ops->disassoc) |
| 5594 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5595 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5596 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5597 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5598 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5599 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5600 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5601 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5602 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5603 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5604 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5605 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5606 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5607 | |
| 5608 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5609 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5610 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5611 | } |
| 5612 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5613 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5614 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5615 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5616 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5617 | } |
| 5618 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5619 | static bool |
| 5620 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5621 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5622 | int rateval) |
| 5623 | { |
| 5624 | struct wiphy *wiphy = &rdev->wiphy; |
| 5625 | bool found = false; |
| 5626 | int band, i; |
| 5627 | |
| 5628 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5629 | struct ieee80211_supported_band *sband; |
| 5630 | |
| 5631 | sband = wiphy->bands[band]; |
| 5632 | if (!sband) |
| 5633 | continue; |
| 5634 | |
| 5635 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5636 | if (sband->bitrates[i].bitrate == rateval) { |
| 5637 | mcast_rate[band] = i + 1; |
| 5638 | found = true; |
| 5639 | break; |
| 5640 | } |
| 5641 | } |
| 5642 | } |
| 5643 | |
| 5644 | return found; |
| 5645 | } |
| 5646 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5647 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5648 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5650 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5651 | struct cfg80211_ibss_params ibss; |
| 5652 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5653 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5654 | int err; |
| 5655 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5656 | memset(&ibss, 0, sizeof(ibss)); |
| 5657 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5658 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5659 | return -EINVAL; |
| 5660 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5661 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5662 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5663 | return -EINVAL; |
| 5664 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5665 | ibss.beacon_interval = 100; |
| 5666 | |
| 5667 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5668 | ibss.beacon_interval = |
| 5669 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5670 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5671 | return -EINVAL; |
| 5672 | } |
| 5673 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5674 | if (!rdev->ops->join_ibss) |
| 5675 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5676 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5678 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5679 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5680 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5681 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5682 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5683 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5684 | |
| 5685 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5686 | return -EINVAL; |
| 5687 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5688 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5689 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5690 | |
| 5691 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5692 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5693 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5694 | } |
| 5695 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5696 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5697 | if (err) |
| 5698 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5699 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5700 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5701 | return -EINVAL; |
| 5702 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5703 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5704 | return -EINVAL; |
| 5705 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5706 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5707 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5708 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5709 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5710 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5711 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5712 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5713 | u8 *rates = |
| 5714 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5715 | int n_rates = |
| 5716 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5717 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5718 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5719 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5720 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5721 | &ibss.basic_rates); |
| 5722 | if (err) |
| 5723 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5724 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5725 | |
| 5726 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5727 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5728 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5729 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5730 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5731 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5732 | bool no_ht = false; |
| 5733 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5734 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5735 | info->attrs[NL80211_ATTR_KEYS], |
| 5736 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5737 | if (IS_ERR(connkeys)) |
| 5738 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5739 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5740 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5741 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5742 | kfree(connkeys); |
| 5743 | return -EINVAL; |
| 5744 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5745 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5746 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5747 | ibss.control_port = |
| 5748 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5749 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5750 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5751 | if (err) |
| 5752 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5753 | return err; |
| 5754 | } |
| 5755 | |
| 5756 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5757 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5759 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5761 | if (!rdev->ops->leave_ibss) |
| 5762 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5764 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5765 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5766 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5767 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5768 | } |
| 5769 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5770 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5771 | { |
| 5772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5773 | struct net_device *dev = info->user_ptr[1]; |
| 5774 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5775 | u32 nla_rate; |
| 5776 | int err; |
| 5777 | |
| 5778 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5779 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5780 | return -EOPNOTSUPP; |
| 5781 | |
| 5782 | if (!rdev->ops->set_mcast_rate) |
| 5783 | return -EOPNOTSUPP; |
| 5784 | |
| 5785 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5786 | |
| 5787 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5788 | return -EINVAL; |
| 5789 | |
| 5790 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5791 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5792 | return -EINVAL; |
| 5793 | |
| 5794 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5795 | |
| 5796 | return err; |
| 5797 | } |
| 5798 | |
| 5799 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5800 | #ifdef CONFIG_NL80211_TESTMODE |
| 5801 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5802 | .name = "testmode", |
| 5803 | }; |
| 5804 | |
| 5805 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5806 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5808 | int err; |
| 5809 | |
| 5810 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5811 | return -EINVAL; |
| 5812 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5813 | err = -EOPNOTSUPP; |
| 5814 | if (rdev->ops->testmode_cmd) { |
| 5815 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5816 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5817 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5818 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5819 | rdev->testmode_info = NULL; |
| 5820 | } |
| 5821 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5822 | return err; |
| 5823 | } |
| 5824 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5825 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5826 | struct netlink_callback *cb) |
| 5827 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5828 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5829 | int err; |
| 5830 | long phy_idx; |
| 5831 | void *data = NULL; |
| 5832 | int data_len = 0; |
| 5833 | |
| 5834 | if (cb->args[0]) { |
| 5835 | /* |
| 5836 | * 0 is a valid index, but not valid for args[0], |
| 5837 | * so we need to offset by 1. |
| 5838 | */ |
| 5839 | phy_idx = cb->args[0] - 1; |
| 5840 | } else { |
| 5841 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5842 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5843 | nl80211_policy); |
| 5844 | if (err) |
| 5845 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5846 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5847 | mutex_lock(&cfg80211_mutex); |
| 5848 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5849 | nl80211_fam.attrbuf); |
| 5850 | if (IS_ERR(rdev)) { |
| 5851 | mutex_unlock(&cfg80211_mutex); |
| 5852 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5853 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5854 | phy_idx = rdev->wiphy_idx; |
| 5855 | rdev = NULL; |
| 5856 | mutex_unlock(&cfg80211_mutex); |
| 5857 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5858 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5859 | cb->args[1] = |
| 5860 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5861 | } |
| 5862 | |
| 5863 | if (cb->args[1]) { |
| 5864 | data = nla_data((void *)cb->args[1]); |
| 5865 | data_len = nla_len((void *)cb->args[1]); |
| 5866 | } |
| 5867 | |
| 5868 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5869 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5870 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5871 | mutex_unlock(&cfg80211_mutex); |
| 5872 | return -ENOENT; |
| 5873 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5874 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5875 | mutex_unlock(&cfg80211_mutex); |
| 5876 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5877 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5878 | err = -EOPNOTSUPP; |
| 5879 | goto out_err; |
| 5880 | } |
| 5881 | |
| 5882 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5883 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5884 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5885 | NL80211_CMD_TESTMODE); |
| 5886 | struct nlattr *tmdata; |
| 5887 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5888 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5889 | genlmsg_cancel(skb, hdr); |
| 5890 | break; |
| 5891 | } |
| 5892 | |
| 5893 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5894 | if (!tmdata) { |
| 5895 | genlmsg_cancel(skb, hdr); |
| 5896 | break; |
| 5897 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5898 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5899 | nla_nest_end(skb, tmdata); |
| 5900 | |
| 5901 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5902 | genlmsg_cancel(skb, hdr); |
| 5903 | break; |
| 5904 | } else if (err) { |
| 5905 | genlmsg_cancel(skb, hdr); |
| 5906 | goto out_err; |
| 5907 | } |
| 5908 | |
| 5909 | genlmsg_end(skb, hdr); |
| 5910 | } |
| 5911 | |
| 5912 | err = skb->len; |
| 5913 | /* see above */ |
| 5914 | cb->args[0] = phy_idx + 1; |
| 5915 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5916 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5917 | return err; |
| 5918 | } |
| 5919 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5920 | static struct sk_buff * |
| 5921 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5922 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5923 | { |
| 5924 | struct sk_buff *skb; |
| 5925 | void *hdr; |
| 5926 | struct nlattr *data; |
| 5927 | |
| 5928 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5929 | if (!skb) |
| 5930 | return NULL; |
| 5931 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5932 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5933 | if (!hdr) { |
| 5934 | kfree_skb(skb); |
| 5935 | return NULL; |
| 5936 | } |
| 5937 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5938 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5939 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5940 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5941 | |
| 5942 | ((void **)skb->cb)[0] = rdev; |
| 5943 | ((void **)skb->cb)[1] = hdr; |
| 5944 | ((void **)skb->cb)[2] = data; |
| 5945 | |
| 5946 | return skb; |
| 5947 | |
| 5948 | nla_put_failure: |
| 5949 | kfree_skb(skb); |
| 5950 | return NULL; |
| 5951 | } |
| 5952 | |
| 5953 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5954 | int approxlen) |
| 5955 | { |
| 5956 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5957 | |
| 5958 | if (WARN_ON(!rdev->testmode_info)) |
| 5959 | return NULL; |
| 5960 | |
| 5961 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5962 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5963 | rdev->testmode_info->snd_seq, |
| 5964 | GFP_KERNEL); |
| 5965 | } |
| 5966 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5967 | |
| 5968 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5969 | { |
| 5970 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5971 | void *hdr = ((void **)skb->cb)[1]; |
| 5972 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5973 | |
| 5974 | if (WARN_ON(!rdev->testmode_info)) { |
| 5975 | kfree_skb(skb); |
| 5976 | return -EINVAL; |
| 5977 | } |
| 5978 | |
| 5979 | nla_nest_end(skb, data); |
| 5980 | genlmsg_end(skb, hdr); |
| 5981 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5982 | } |
| 5983 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5984 | |
| 5985 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5986 | int approxlen, gfp_t gfp) |
| 5987 | { |
| 5988 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5989 | |
| 5990 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5991 | } |
| 5992 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5993 | |
| 5994 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5995 | { |
| 5996 | void *hdr = ((void **)skb->cb)[1]; |
| 5997 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5998 | |
| 5999 | nla_nest_end(skb, data); |
| 6000 | genlmsg_end(skb, hdr); |
| 6001 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6002 | } |
| 6003 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6004 | #endif |
| 6005 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6006 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6007 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6009 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6010 | struct cfg80211_connect_params connect; |
| 6011 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6012 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6013 | int err; |
| 6014 | |
| 6015 | memset(&connect, 0, sizeof(connect)); |
| 6016 | |
| 6017 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6018 | return -EINVAL; |
| 6019 | |
| 6020 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6021 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6022 | return -EINVAL; |
| 6023 | |
| 6024 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6025 | connect.auth_type = |
| 6026 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6027 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6028 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6029 | return -EINVAL; |
| 6030 | } else |
| 6031 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6032 | |
| 6033 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6034 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6035 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6036 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6037 | if (err) |
| 6038 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6039 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6040 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6041 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6042 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6043 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6044 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6045 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6046 | connect.bg_scan_period = -1; |
| 6047 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6048 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6049 | connect.bg_scan_period = |
| 6050 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6051 | } |
| 6052 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6053 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6054 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6055 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6056 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6057 | |
| 6058 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6059 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6060 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6061 | } |
| 6062 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6063 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6064 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6065 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6066 | connect.mfp != NL80211_MFP_NO) |
| 6067 | return -EINVAL; |
| 6068 | } else { |
| 6069 | connect.mfp = NL80211_MFP_NO; |
| 6070 | } |
| 6071 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6072 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6073 | connect.channel = |
| 6074 | ieee80211_get_channel(wiphy, |
| 6075 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6076 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6077 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6078 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6079 | } |
| 6080 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6081 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6082 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6083 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6084 | if (IS_ERR(connkeys)) |
| 6085 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6086 | } |
| 6087 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6088 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6089 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6090 | |
| 6091 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6092 | memcpy(&connect.ht_capa_mask, |
| 6093 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6094 | sizeof(connect.ht_capa_mask)); |
| 6095 | |
| 6096 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6097 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6098 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6099 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6100 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6101 | memcpy(&connect.ht_capa, |
| 6102 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6103 | sizeof(connect.ht_capa)); |
| 6104 | } |
| 6105 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6106 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6107 | if (err) |
| 6108 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6109 | return err; |
| 6110 | } |
| 6111 | |
| 6112 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6113 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6115 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6116 | u16 reason; |
| 6117 | |
| 6118 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6119 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6120 | else |
| 6121 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6122 | |
| 6123 | if (reason == 0) |
| 6124 | return -EINVAL; |
| 6125 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6126 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6127 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6128 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6129 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6130 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6131 | } |
| 6132 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6133 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6134 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6136 | struct net *net; |
| 6137 | int err; |
| 6138 | u32 pid; |
| 6139 | |
| 6140 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6141 | return -EINVAL; |
| 6142 | |
| 6143 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6144 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6145 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6146 | if (IS_ERR(net)) |
| 6147 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6148 | |
| 6149 | err = 0; |
| 6150 | |
| 6151 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6153 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6154 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6155 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6156 | return err; |
| 6157 | } |
| 6158 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6159 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6160 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6162 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6163 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6164 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6165 | struct cfg80211_pmksa pmksa; |
| 6166 | |
| 6167 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6168 | |
| 6169 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6170 | return -EINVAL; |
| 6171 | |
| 6172 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6173 | return -EINVAL; |
| 6174 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6175 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6176 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6177 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6178 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6179 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6180 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6181 | |
| 6182 | switch (info->genlhdr->cmd) { |
| 6183 | case NL80211_CMD_SET_PMKSA: |
| 6184 | rdev_ops = rdev->ops->set_pmksa; |
| 6185 | break; |
| 6186 | case NL80211_CMD_DEL_PMKSA: |
| 6187 | rdev_ops = rdev->ops->del_pmksa; |
| 6188 | break; |
| 6189 | default: |
| 6190 | WARN_ON(1); |
| 6191 | break; |
| 6192 | } |
| 6193 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6194 | if (!rdev_ops) |
| 6195 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6201 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6202 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6203 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6204 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6205 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6206 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6207 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6208 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6209 | if (!rdev->ops->flush_pmksa) |
| 6210 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6211 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6212 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6213 | } |
| 6214 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6215 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6216 | { |
| 6217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6218 | struct net_device *dev = info->user_ptr[1]; |
| 6219 | u8 action_code, dialog_token; |
| 6220 | u16 status_code; |
| 6221 | u8 *peer; |
| 6222 | |
| 6223 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6224 | !rdev->ops->tdls_mgmt) |
| 6225 | return -EOPNOTSUPP; |
| 6226 | |
| 6227 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6228 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6229 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6230 | !info->attrs[NL80211_ATTR_IE] || |
| 6231 | !info->attrs[NL80211_ATTR_MAC]) |
| 6232 | return -EINVAL; |
| 6233 | |
| 6234 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6235 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6236 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6237 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6238 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6239 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6240 | dialog_token, status_code, |
| 6241 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6242 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6246 | { |
| 6247 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6248 | struct net_device *dev = info->user_ptr[1]; |
| 6249 | enum nl80211_tdls_operation operation; |
| 6250 | u8 *peer; |
| 6251 | |
| 6252 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6253 | !rdev->ops->tdls_oper) |
| 6254 | return -EOPNOTSUPP; |
| 6255 | |
| 6256 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6257 | !info->attrs[NL80211_ATTR_MAC]) |
| 6258 | return -EINVAL; |
| 6259 | |
| 6260 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6261 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6262 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6263 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6264 | } |
| 6265 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6266 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6267 | struct genl_info *info) |
| 6268 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6270 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6271 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6272 | struct sk_buff *msg; |
| 6273 | void *hdr; |
| 6274 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6275 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6276 | int err; |
| 6277 | |
| 6278 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6279 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6280 | return -EINVAL; |
| 6281 | |
| 6282 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6283 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6284 | if (!rdev->ops->remain_on_channel || |
| 6285 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6286 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6287 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6288 | /* |
| 6289 | * We should be on that channel for at least a minimum amount of |
| 6290 | * time (10ms) but no longer than the driver supports. |
| 6291 | */ |
| 6292 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6293 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6294 | return -EINVAL; |
| 6295 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6296 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6297 | if (err) |
| 6298 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6299 | |
| 6300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6301 | if (!msg) |
| 6302 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6303 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6304 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6305 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6306 | |
| 6307 | if (IS_ERR(hdr)) { |
| 6308 | err = PTR_ERR(hdr); |
| 6309 | goto free_msg; |
| 6310 | } |
| 6311 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6312 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6313 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6314 | |
| 6315 | if (err) |
| 6316 | goto free_msg; |
| 6317 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6318 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6319 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6320 | |
| 6321 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6322 | |
| 6323 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6324 | |
| 6325 | nla_put_failure: |
| 6326 | err = -ENOBUFS; |
| 6327 | free_msg: |
| 6328 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6329 | return err; |
| 6330 | } |
| 6331 | |
| 6332 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6333 | struct genl_info *info) |
| 6334 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6336 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6337 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6338 | |
| 6339 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6340 | return -EINVAL; |
| 6341 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6342 | if (!rdev->ops->cancel_remain_on_channel) |
| 6343 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6344 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6345 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6346 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6347 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6348 | } |
| 6349 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6350 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6351 | u8 *rates, u8 rates_len) |
| 6352 | { |
| 6353 | u8 i; |
| 6354 | u32 mask = 0; |
| 6355 | |
| 6356 | for (i = 0; i < rates_len; i++) { |
| 6357 | int rate = (rates[i] & 0x7f) * 5; |
| 6358 | int ridx; |
| 6359 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6360 | struct ieee80211_rate *srate = |
| 6361 | &sband->bitrates[ridx]; |
| 6362 | if (rate == srate->bitrate) { |
| 6363 | mask |= 1 << ridx; |
| 6364 | break; |
| 6365 | } |
| 6366 | } |
| 6367 | if (ridx == sband->n_bitrates) |
| 6368 | return 0; /* rate not found */ |
| 6369 | } |
| 6370 | |
| 6371 | return mask; |
| 6372 | } |
| 6373 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6374 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6375 | u8 *rates, u8 rates_len, |
| 6376 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6377 | { |
| 6378 | u8 i; |
| 6379 | |
| 6380 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6381 | |
| 6382 | for (i = 0; i < rates_len; i++) { |
| 6383 | int ridx, rbit; |
| 6384 | |
| 6385 | ridx = rates[i] / 8; |
| 6386 | rbit = BIT(rates[i] % 8); |
| 6387 | |
| 6388 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6389 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6390 | return false; |
| 6391 | |
| 6392 | /* check availability */ |
| 6393 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6394 | mcs[ridx] |= rbit; |
| 6395 | else |
| 6396 | return false; |
| 6397 | } |
| 6398 | |
| 6399 | return true; |
| 6400 | } |
| 6401 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6402 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6403 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6404 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6405 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6406 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6407 | }; |
| 6408 | |
| 6409 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6410 | struct genl_info *info) |
| 6411 | { |
| 6412 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6413 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6414 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6415 | int rem, i; |
| 6416 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6417 | struct nlattr *tx_rates; |
| 6418 | struct ieee80211_supported_band *sband; |
| 6419 | |
| 6420 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6421 | return -EINVAL; |
| 6422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6423 | if (!rdev->ops->set_bitrate_mask) |
| 6424 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6425 | |
| 6426 | memset(&mask, 0, sizeof(mask)); |
| 6427 | /* Default to all rates enabled */ |
| 6428 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6429 | sband = rdev->wiphy.bands[i]; |
| 6430 | mask.control[i].legacy = |
| 6431 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6432 | if (sband) |
| 6433 | memcpy(mask.control[i].mcs, |
| 6434 | sband->ht_cap.mcs.rx_mask, |
| 6435 | sizeof(mask.control[i].mcs)); |
| 6436 | else |
| 6437 | memset(mask.control[i].mcs, 0, |
| 6438 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | /* |
| 6442 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6443 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6444 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6445 | 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] | 6446 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6447 | { |
| 6448 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6449 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6450 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6451 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6452 | if (sband == NULL) |
| 6453 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6454 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6455 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6456 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6457 | mask.control[band].legacy = rateset_to_mask( |
| 6458 | sband, |
| 6459 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6460 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6461 | if ((mask.control[band].legacy == 0) && |
| 6462 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6463 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6464 | } |
| 6465 | if (tb[NL80211_TXRATE_MCS]) { |
| 6466 | if (!ht_rateset_to_mask( |
| 6467 | sband, |
| 6468 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6469 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6470 | mask.control[band].mcs)) |
| 6471 | return -EINVAL; |
| 6472 | } |
| 6473 | |
| 6474 | if (mask.control[band].legacy == 0) { |
| 6475 | /* don't allow empty legacy rates if HT |
| 6476 | * is not even supported. */ |
| 6477 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6478 | return -EINVAL; |
| 6479 | |
| 6480 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6481 | if (mask.control[band].mcs[i]) |
| 6482 | break; |
| 6483 | |
| 6484 | /* legacy and mcs rates may not be both empty */ |
| 6485 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6487 | } |
| 6488 | } |
| 6489 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6490 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6491 | } |
| 6492 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6493 | 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] | 6494 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6495 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6496 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6497 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6498 | |
| 6499 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6500 | return -EINVAL; |
| 6501 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6502 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6503 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6504 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6505 | switch (wdev->iftype) { |
| 6506 | case NL80211_IFTYPE_STATION: |
| 6507 | case NL80211_IFTYPE_ADHOC: |
| 6508 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6509 | case NL80211_IFTYPE_AP: |
| 6510 | case NL80211_IFTYPE_AP_VLAN: |
| 6511 | case NL80211_IFTYPE_MESH_POINT: |
| 6512 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6513 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6514 | break; |
| 6515 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6516 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6517 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6518 | |
| 6519 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6520 | if (!rdev->ops->mgmt_tx) |
| 6521 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6522 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6523 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6524 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6525 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6526 | } |
| 6527 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6528 | 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] | 6529 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6530 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6531 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6532 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6533 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6534 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6535 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6536 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6537 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6538 | bool offchan, no_cck, dont_wait_for_ack; |
| 6539 | |
| 6540 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6541 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6542 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6543 | return -EINVAL; |
| 6544 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6545 | if (!rdev->ops->mgmt_tx) |
| 6546 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6547 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6548 | switch (wdev->iftype) { |
| 6549 | case NL80211_IFTYPE_STATION: |
| 6550 | case NL80211_IFTYPE_ADHOC: |
| 6551 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6552 | case NL80211_IFTYPE_AP: |
| 6553 | case NL80211_IFTYPE_AP_VLAN: |
| 6554 | case NL80211_IFTYPE_MESH_POINT: |
| 6555 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6556 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6557 | break; |
| 6558 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6559 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6560 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6561 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6562 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6563 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6564 | return -EINVAL; |
| 6565 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6566 | |
| 6567 | /* |
| 6568 | * We should wait on the channel for at least a minimum amount |
| 6569 | * of time (10ms) but no longer than the driver supports. |
| 6570 | */ |
| 6571 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6572 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6573 | return -EINVAL; |
| 6574 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6575 | } |
| 6576 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6577 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6578 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6579 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6580 | return -EINVAL; |
| 6581 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6582 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6583 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6584 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6585 | if (err) |
| 6586 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6587 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6588 | if (!dont_wait_for_ack) { |
| 6589 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6590 | if (!msg) |
| 6591 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6592 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6593 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6594 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6595 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6596 | if (IS_ERR(hdr)) { |
| 6597 | err = PTR_ERR(hdr); |
| 6598 | goto free_msg; |
| 6599 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6600 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6601 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6602 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6603 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6604 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6605 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6606 | if (err) |
| 6607 | goto free_msg; |
| 6608 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6609 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6610 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6611 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6612 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6613 | genlmsg_end(msg, hdr); |
| 6614 | return genlmsg_reply(msg, info); |
| 6615 | } |
| 6616 | |
| 6617 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6618 | |
| 6619 | nla_put_failure: |
| 6620 | err = -ENOBUFS; |
| 6621 | free_msg: |
| 6622 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6623 | return err; |
| 6624 | } |
| 6625 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6626 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6627 | { |
| 6628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6629 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6630 | u64 cookie; |
| 6631 | |
| 6632 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6633 | return -EINVAL; |
| 6634 | |
| 6635 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6636 | return -EOPNOTSUPP; |
| 6637 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6638 | switch (wdev->iftype) { |
| 6639 | case NL80211_IFTYPE_STATION: |
| 6640 | case NL80211_IFTYPE_ADHOC: |
| 6641 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6642 | case NL80211_IFTYPE_AP: |
| 6643 | case NL80211_IFTYPE_AP_VLAN: |
| 6644 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6645 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6646 | break; |
| 6647 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6648 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6649 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6650 | |
| 6651 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6652 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6653 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6654 | } |
| 6655 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6656 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6657 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6659 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6660 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6661 | u8 ps_state; |
| 6662 | bool state; |
| 6663 | int err; |
| 6664 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6665 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6666 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6667 | |
| 6668 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6669 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6670 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6671 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6672 | |
| 6673 | wdev = dev->ieee80211_ptr; |
| 6674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6675 | if (!rdev->ops->set_power_mgmt) |
| 6676 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6677 | |
| 6678 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6679 | |
| 6680 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6681 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6682 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6683 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6684 | if (!err) |
| 6685 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6686 | return err; |
| 6687 | } |
| 6688 | |
| 6689 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6690 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6692 | enum nl80211_ps_state ps_state; |
| 6693 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6694 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6695 | struct sk_buff *msg; |
| 6696 | void *hdr; |
| 6697 | int err; |
| 6698 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6699 | wdev = dev->ieee80211_ptr; |
| 6700 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6701 | if (!rdev->ops->set_power_mgmt) |
| 6702 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6703 | |
| 6704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6705 | if (!msg) |
| 6706 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6707 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6708 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6709 | NL80211_CMD_GET_POWER_SAVE); |
| 6710 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6711 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6712 | goto free_msg; |
| 6713 | } |
| 6714 | |
| 6715 | if (wdev->ps) |
| 6716 | ps_state = NL80211_PS_ENABLED; |
| 6717 | else |
| 6718 | ps_state = NL80211_PS_DISABLED; |
| 6719 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6720 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6721 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6722 | |
| 6723 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6724 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6725 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6726 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6727 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6728 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6729 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6730 | return err; |
| 6731 | } |
| 6732 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6733 | static struct nla_policy |
| 6734 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6735 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6736 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6737 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6738 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6739 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6740 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6741 | }; |
| 6742 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6743 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6744 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6745 | { |
| 6746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6747 | struct wireless_dev *wdev; |
| 6748 | struct net_device *dev = info->user_ptr[1]; |
| 6749 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6750 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6751 | return -EINVAL; |
| 6752 | |
| 6753 | wdev = dev->ieee80211_ptr; |
| 6754 | |
| 6755 | if (!rdev->ops->set_cqm_txe_config) |
| 6756 | return -EOPNOTSUPP; |
| 6757 | |
| 6758 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6759 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6760 | return -EOPNOTSUPP; |
| 6761 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6762 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6763 | } |
| 6764 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6765 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6766 | s32 threshold, u32 hysteresis) |
| 6767 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6769 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6770 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6771 | |
| 6772 | if (threshold > 0) |
| 6773 | return -EINVAL; |
| 6774 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6775 | wdev = dev->ieee80211_ptr; |
| 6776 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6777 | if (!rdev->ops->set_cqm_rssi_config) |
| 6778 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6779 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6780 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6781 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6782 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6783 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6784 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6788 | { |
| 6789 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6790 | struct nlattr *cqm; |
| 6791 | int err; |
| 6792 | |
| 6793 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6794 | if (!cqm) { |
| 6795 | err = -EINVAL; |
| 6796 | goto out; |
| 6797 | } |
| 6798 | |
| 6799 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6800 | nl80211_attr_cqm_policy); |
| 6801 | if (err) |
| 6802 | goto out; |
| 6803 | |
| 6804 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6805 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6806 | s32 threshold; |
| 6807 | u32 hysteresis; |
| 6808 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6809 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6810 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6811 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6812 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6813 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6814 | u32 rate, pkts, intvl; |
| 6815 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6816 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6817 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6818 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6819 | } else |
| 6820 | err = -EINVAL; |
| 6821 | |
| 6822 | out: |
| 6823 | return err; |
| 6824 | } |
| 6825 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6826 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6827 | { |
| 6828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6829 | struct net_device *dev = info->user_ptr[1]; |
| 6830 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6831 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6832 | int err; |
| 6833 | |
| 6834 | /* start with default */ |
| 6835 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6836 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6837 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6838 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6839 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6840 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6841 | if (err) |
| 6842 | return err; |
| 6843 | } |
| 6844 | |
| 6845 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6846 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6847 | return -EINVAL; |
| 6848 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6849 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6850 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6851 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6852 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6853 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6854 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6855 | return -EINVAL; |
| 6856 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 6857 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6858 | setup.beacon_interval = |
| 6859 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6860 | if (setup.beacon_interval < 10 || |
| 6861 | setup.beacon_interval > 10000) |
| 6862 | return -EINVAL; |
| 6863 | } |
| 6864 | |
| 6865 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 6866 | setup.dtim_period = |
| 6867 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 6868 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 6869 | return -EINVAL; |
| 6870 | } |
| 6871 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6872 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6873 | /* parse additional setup parameters if given */ |
| 6874 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6875 | if (err) |
| 6876 | return err; |
| 6877 | } |
| 6878 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6879 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6880 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 6881 | if (err) |
| 6882 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6883 | } else { |
| 6884 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6885 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6886 | } |
| 6887 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6888 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6892 | { |
| 6893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6894 | struct net_device *dev = info->user_ptr[1]; |
| 6895 | |
| 6896 | return cfg80211_leave_mesh(rdev, dev); |
| 6897 | } |
| 6898 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6899 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame^] | 6900 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 6901 | struct cfg80211_registered_device *rdev) |
| 6902 | { |
| 6903 | struct nlattr *nl_pats, *nl_pat; |
| 6904 | int i, pat_len; |
| 6905 | |
| 6906 | if (!rdev->wowlan->n_patterns) |
| 6907 | return 0; |
| 6908 | |
| 6909 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6910 | if (!nl_pats) |
| 6911 | return -ENOBUFS; |
| 6912 | |
| 6913 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6914 | nl_pat = nla_nest_start(msg, i + 1); |
| 6915 | if (!nl_pat) |
| 6916 | return -ENOBUFS; |
| 6917 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 6918 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6919 | DIV_ROUND_UP(pat_len, 8), |
| 6920 | rdev->wowlan->patterns[i].mask) || |
| 6921 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6922 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 6923 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 6924 | rdev->wowlan->patterns[i].pkt_offset)) |
| 6925 | return -ENOBUFS; |
| 6926 | nla_nest_end(msg, nl_pat); |
| 6927 | } |
| 6928 | nla_nest_end(msg, nl_pats); |
| 6929 | |
| 6930 | return 0; |
| 6931 | } |
| 6932 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6933 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6934 | { |
| 6935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6936 | struct sk_buff *msg; |
| 6937 | void *hdr; |
| 6938 | |
| 6939 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6940 | return -EOPNOTSUPP; |
| 6941 | |
| 6942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6943 | if (!msg) |
| 6944 | return -ENOMEM; |
| 6945 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6946 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6947 | NL80211_CMD_GET_WOWLAN); |
| 6948 | if (!hdr) |
| 6949 | goto nla_put_failure; |
| 6950 | |
| 6951 | if (rdev->wowlan) { |
| 6952 | struct nlattr *nl_wowlan; |
| 6953 | |
| 6954 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6955 | if (!nl_wowlan) |
| 6956 | goto nla_put_failure; |
| 6957 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6958 | if ((rdev->wowlan->any && |
| 6959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6960 | (rdev->wowlan->disconnect && |
| 6961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6962 | (rdev->wowlan->magic_pkt && |
| 6963 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6964 | (rdev->wowlan->gtk_rekey_failure && |
| 6965 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6966 | (rdev->wowlan->eap_identity_req && |
| 6967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6968 | (rdev->wowlan->four_way_handshake && |
| 6969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6970 | (rdev->wowlan->rfkill_release && |
| 6971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6972 | goto nla_put_failure; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame^] | 6973 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 6974 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6975 | nla_nest_end(msg, nl_wowlan); |
| 6976 | } |
| 6977 | |
| 6978 | genlmsg_end(msg, hdr); |
| 6979 | return genlmsg_reply(msg, info); |
| 6980 | |
| 6981 | nla_put_failure: |
| 6982 | nlmsg_free(msg); |
| 6983 | return -ENOBUFS; |
| 6984 | } |
| 6985 | |
| 6986 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6987 | { |
| 6988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6989 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6990 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6991 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6992 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6993 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6994 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6995 | |
| 6996 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6997 | return -EOPNOTSUPP; |
| 6998 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6999 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7000 | cfg80211_rdev_free_wowlan(rdev); |
| 7001 | rdev->wowlan = NULL; |
| 7002 | goto set_wakeup; |
| 7003 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7004 | |
| 7005 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7006 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7007 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7008 | nl80211_wowlan_policy); |
| 7009 | if (err) |
| 7010 | return err; |
| 7011 | |
| 7012 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7013 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7014 | return -EINVAL; |
| 7015 | new_triggers.any = true; |
| 7016 | } |
| 7017 | |
| 7018 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7019 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7020 | return -EINVAL; |
| 7021 | new_triggers.disconnect = true; |
| 7022 | } |
| 7023 | |
| 7024 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7025 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7026 | return -EINVAL; |
| 7027 | new_triggers.magic_pkt = true; |
| 7028 | } |
| 7029 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7030 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7031 | return -EINVAL; |
| 7032 | |
| 7033 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7034 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7035 | return -EINVAL; |
| 7036 | new_triggers.gtk_rekey_failure = true; |
| 7037 | } |
| 7038 | |
| 7039 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7040 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7041 | return -EINVAL; |
| 7042 | new_triggers.eap_identity_req = true; |
| 7043 | } |
| 7044 | |
| 7045 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7046 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7047 | return -EINVAL; |
| 7048 | new_triggers.four_way_handshake = true; |
| 7049 | } |
| 7050 | |
| 7051 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7052 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7053 | return -EINVAL; |
| 7054 | new_triggers.rfkill_release = true; |
| 7055 | } |
| 7056 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7057 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7058 | struct nlattr *pat; |
| 7059 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame^] | 7060 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7061 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7062 | |
| 7063 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7064 | rem) |
| 7065 | n_patterns++; |
| 7066 | if (n_patterns > wowlan->n_patterns) |
| 7067 | return -EINVAL; |
| 7068 | |
| 7069 | new_triggers.patterns = kcalloc(n_patterns, |
| 7070 | sizeof(new_triggers.patterns[0]), |
| 7071 | GFP_KERNEL); |
| 7072 | if (!new_triggers.patterns) |
| 7073 | return -ENOMEM; |
| 7074 | |
| 7075 | new_triggers.n_patterns = n_patterns; |
| 7076 | i = 0; |
| 7077 | |
| 7078 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7079 | rem) { |
| 7080 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7081 | nla_data(pat), nla_len(pat), NULL); |
| 7082 | err = -EINVAL; |
| 7083 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7084 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7085 | goto error; |
| 7086 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7087 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7088 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7089 | mask_len) |
| 7090 | goto error; |
| 7091 | if (pat_len > wowlan->pattern_max_len || |
| 7092 | pat_len < wowlan->pattern_min_len) |
| 7093 | goto error; |
| 7094 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame^] | 7095 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7096 | pkt_offset = 0; |
| 7097 | else |
| 7098 | pkt_offset = nla_get_u32( |
| 7099 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7100 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7101 | goto error; |
| 7102 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7103 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7104 | new_triggers.patterns[i].mask = |
| 7105 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7106 | if (!new_triggers.patterns[i].mask) { |
| 7107 | err = -ENOMEM; |
| 7108 | goto error; |
| 7109 | } |
| 7110 | new_triggers.patterns[i].pattern = |
| 7111 | new_triggers.patterns[i].mask + mask_len; |
| 7112 | memcpy(new_triggers.patterns[i].mask, |
| 7113 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7114 | mask_len); |
| 7115 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7116 | memcpy(new_triggers.patterns[i].pattern, |
| 7117 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7118 | pat_len); |
| 7119 | i++; |
| 7120 | } |
| 7121 | } |
| 7122 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7123 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7124 | if (!ntrig) { |
| 7125 | err = -ENOMEM; |
| 7126 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7127 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7128 | cfg80211_rdev_free_wowlan(rdev); |
| 7129 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7130 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7131 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7132 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7133 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7134 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7135 | return 0; |
| 7136 | error: |
| 7137 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7138 | kfree(new_triggers.patterns[i].mask); |
| 7139 | kfree(new_triggers.patterns); |
| 7140 | return err; |
| 7141 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7142 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7143 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7144 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7145 | { |
| 7146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7147 | struct net_device *dev = info->user_ptr[1]; |
| 7148 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7149 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7150 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7151 | int err; |
| 7152 | |
| 7153 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7154 | return -EINVAL; |
| 7155 | |
| 7156 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7157 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7158 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7159 | nl80211_rekey_policy); |
| 7160 | if (err) |
| 7161 | return err; |
| 7162 | |
| 7163 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7164 | return -ERANGE; |
| 7165 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7166 | return -ERANGE; |
| 7167 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7168 | return -ERANGE; |
| 7169 | |
| 7170 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7171 | NL80211_KEK_LEN); |
| 7172 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7173 | NL80211_KCK_LEN); |
| 7174 | memcpy(rekey_data.replay_ctr, |
| 7175 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7176 | NL80211_REPLAY_CTR_LEN); |
| 7177 | |
| 7178 | wdev_lock(wdev); |
| 7179 | if (!wdev->current_bss) { |
| 7180 | err = -ENOTCONN; |
| 7181 | goto out; |
| 7182 | } |
| 7183 | |
| 7184 | if (!rdev->ops->set_rekey_data) { |
| 7185 | err = -EOPNOTSUPP; |
| 7186 | goto out; |
| 7187 | } |
| 7188 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7189 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7190 | out: |
| 7191 | wdev_unlock(wdev); |
| 7192 | return err; |
| 7193 | } |
| 7194 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7195 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7196 | struct genl_info *info) |
| 7197 | { |
| 7198 | struct net_device *dev = info->user_ptr[1]; |
| 7199 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7200 | |
| 7201 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7202 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7203 | return -EINVAL; |
| 7204 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7205 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7206 | return -EBUSY; |
| 7207 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7208 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7209 | return 0; |
| 7210 | } |
| 7211 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7212 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7213 | struct genl_info *info) |
| 7214 | { |
| 7215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7216 | struct net_device *dev = info->user_ptr[1]; |
| 7217 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7218 | struct sk_buff *msg; |
| 7219 | void *hdr; |
| 7220 | const u8 *addr; |
| 7221 | u64 cookie; |
| 7222 | int err; |
| 7223 | |
| 7224 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7225 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7226 | return -EOPNOTSUPP; |
| 7227 | |
| 7228 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7229 | return -EINVAL; |
| 7230 | |
| 7231 | if (!rdev->ops->probe_client) |
| 7232 | return -EOPNOTSUPP; |
| 7233 | |
| 7234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7235 | if (!msg) |
| 7236 | return -ENOMEM; |
| 7237 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7238 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7239 | NL80211_CMD_PROBE_CLIENT); |
| 7240 | |
| 7241 | if (IS_ERR(hdr)) { |
| 7242 | err = PTR_ERR(hdr); |
| 7243 | goto free_msg; |
| 7244 | } |
| 7245 | |
| 7246 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7247 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7248 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7249 | if (err) |
| 7250 | goto free_msg; |
| 7251 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7252 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7253 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7254 | |
| 7255 | genlmsg_end(msg, hdr); |
| 7256 | |
| 7257 | return genlmsg_reply(msg, info); |
| 7258 | |
| 7259 | nla_put_failure: |
| 7260 | err = -ENOBUFS; |
| 7261 | free_msg: |
| 7262 | nlmsg_free(msg); |
| 7263 | return err; |
| 7264 | } |
| 7265 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7266 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7267 | { |
| 7268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7269 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7270 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7271 | |
| 7272 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7273 | return -EOPNOTSUPP; |
| 7274 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7275 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7276 | if (!nreg) |
| 7277 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7278 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7279 | /* First, check if already registered. */ |
| 7280 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7281 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7282 | if (reg->nlportid == info->snd_portid) { |
| 7283 | rv = -EALREADY; |
| 7284 | goto out_err; |
| 7285 | } |
| 7286 | } |
| 7287 | /* Add it to the list */ |
| 7288 | nreg->nlportid = info->snd_portid; |
| 7289 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7290 | |
| 7291 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7292 | |
| 7293 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7294 | out_err: |
| 7295 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7296 | kfree(nreg); |
| 7297 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7298 | } |
| 7299 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7300 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7301 | { |
| 7302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7303 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7304 | int err; |
| 7305 | |
| 7306 | if (!rdev->ops->start_p2p_device) |
| 7307 | return -EOPNOTSUPP; |
| 7308 | |
| 7309 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7310 | return -EOPNOTSUPP; |
| 7311 | |
| 7312 | if (wdev->p2p_started) |
| 7313 | return 0; |
| 7314 | |
| 7315 | mutex_lock(&rdev->devlist_mtx); |
| 7316 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7317 | mutex_unlock(&rdev->devlist_mtx); |
| 7318 | if (err) |
| 7319 | return err; |
| 7320 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7321 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7322 | if (err) |
| 7323 | return err; |
| 7324 | |
| 7325 | wdev->p2p_started = true; |
| 7326 | mutex_lock(&rdev->devlist_mtx); |
| 7327 | rdev->opencount++; |
| 7328 | mutex_unlock(&rdev->devlist_mtx); |
| 7329 | |
| 7330 | return 0; |
| 7331 | } |
| 7332 | |
| 7333 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7334 | { |
| 7335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7336 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7337 | |
| 7338 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7339 | return -EOPNOTSUPP; |
| 7340 | |
| 7341 | if (!rdev->ops->stop_p2p_device) |
| 7342 | return -EOPNOTSUPP; |
| 7343 | |
| 7344 | if (!wdev->p2p_started) |
| 7345 | return 0; |
| 7346 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7347 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7348 | wdev->p2p_started = false; |
| 7349 | |
| 7350 | mutex_lock(&rdev->devlist_mtx); |
| 7351 | rdev->opencount--; |
| 7352 | mutex_unlock(&rdev->devlist_mtx); |
| 7353 | |
| 7354 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7355 | rdev->scan_req->aborted = true; |
| 7356 | ___cfg80211_scan_done(rdev, true); |
| 7357 | } |
| 7358 | |
| 7359 | return 0; |
| 7360 | } |
| 7361 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7362 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7363 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7364 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7365 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7366 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7367 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7368 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7369 | /* 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] | 7370 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7371 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7372 | |
| 7373 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7374 | struct genl_info *info) |
| 7375 | { |
| 7376 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7377 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7378 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7379 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7380 | |
| 7381 | if (rtnl) |
| 7382 | rtnl_lock(); |
| 7383 | |
| 7384 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7385 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7386 | if (IS_ERR(rdev)) { |
| 7387 | if (rtnl) |
| 7388 | rtnl_unlock(); |
| 7389 | return PTR_ERR(rdev); |
| 7390 | } |
| 7391 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7392 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7393 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7394 | mutex_lock(&cfg80211_mutex); |
| 7395 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7396 | info->attrs); |
| 7397 | if (IS_ERR(wdev)) { |
| 7398 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7399 | if (rtnl) |
| 7400 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7401 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7402 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7403 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7404 | dev = wdev->netdev; |
| 7405 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7406 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7407 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7408 | if (!dev) { |
| 7409 | mutex_unlock(&cfg80211_mutex); |
| 7410 | if (rtnl) |
| 7411 | rtnl_unlock(); |
| 7412 | return -EINVAL; |
| 7413 | } |
| 7414 | |
| 7415 | info->user_ptr[1] = dev; |
| 7416 | } else { |
| 7417 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7418 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7419 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7420 | if (dev) { |
| 7421 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7422 | !netif_running(dev)) { |
| 7423 | mutex_unlock(&cfg80211_mutex); |
| 7424 | if (rtnl) |
| 7425 | rtnl_unlock(); |
| 7426 | return -ENETDOWN; |
| 7427 | } |
| 7428 | |
| 7429 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7430 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7431 | if (!wdev->p2p_started) { |
| 7432 | mutex_unlock(&cfg80211_mutex); |
| 7433 | if (rtnl) |
| 7434 | rtnl_unlock(); |
| 7435 | return -ENETDOWN; |
| 7436 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7437 | } |
| 7438 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7439 | cfg80211_lock_rdev(rdev); |
| 7440 | |
| 7441 | mutex_unlock(&cfg80211_mutex); |
| 7442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7443 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7444 | } |
| 7445 | |
| 7446 | return 0; |
| 7447 | } |
| 7448 | |
| 7449 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7450 | struct genl_info *info) |
| 7451 | { |
| 7452 | if (info->user_ptr[0]) |
| 7453 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7454 | if (info->user_ptr[1]) { |
| 7455 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7456 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7457 | |
| 7458 | if (wdev->netdev) |
| 7459 | dev_put(wdev->netdev); |
| 7460 | } else { |
| 7461 | dev_put(info->user_ptr[1]); |
| 7462 | } |
| 7463 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7464 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7465 | rtnl_unlock(); |
| 7466 | } |
| 7467 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7468 | static struct genl_ops nl80211_ops[] = { |
| 7469 | { |
| 7470 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7471 | .doit = nl80211_get_wiphy, |
| 7472 | .dumpit = nl80211_dump_wiphy, |
| 7473 | .policy = nl80211_policy, |
| 7474 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7475 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7476 | }, |
| 7477 | { |
| 7478 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7479 | .doit = nl80211_set_wiphy, |
| 7480 | .policy = nl80211_policy, |
| 7481 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7482 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7483 | }, |
| 7484 | { |
| 7485 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7486 | .doit = nl80211_get_interface, |
| 7487 | .dumpit = nl80211_dump_interface, |
| 7488 | .policy = nl80211_policy, |
| 7489 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7490 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7491 | }, |
| 7492 | { |
| 7493 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7494 | .doit = nl80211_set_interface, |
| 7495 | .policy = nl80211_policy, |
| 7496 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7497 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7498 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7499 | }, |
| 7500 | { |
| 7501 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7502 | .doit = nl80211_new_interface, |
| 7503 | .policy = nl80211_policy, |
| 7504 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7505 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7506 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7507 | }, |
| 7508 | { |
| 7509 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7510 | .doit = nl80211_del_interface, |
| 7511 | .policy = nl80211_policy, |
| 7512 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7513 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7514 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7515 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7516 | { |
| 7517 | .cmd = NL80211_CMD_GET_KEY, |
| 7518 | .doit = nl80211_get_key, |
| 7519 | .policy = nl80211_policy, |
| 7520 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7522 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7523 | }, |
| 7524 | { |
| 7525 | .cmd = NL80211_CMD_SET_KEY, |
| 7526 | .doit = nl80211_set_key, |
| 7527 | .policy = nl80211_policy, |
| 7528 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7530 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7531 | }, |
| 7532 | { |
| 7533 | .cmd = NL80211_CMD_NEW_KEY, |
| 7534 | .doit = nl80211_new_key, |
| 7535 | .policy = nl80211_policy, |
| 7536 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7537 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7538 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7539 | }, |
| 7540 | { |
| 7541 | .cmd = NL80211_CMD_DEL_KEY, |
| 7542 | .doit = nl80211_del_key, |
| 7543 | .policy = nl80211_policy, |
| 7544 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7545 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7546 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7547 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7548 | { |
| 7549 | .cmd = NL80211_CMD_SET_BEACON, |
| 7550 | .policy = nl80211_policy, |
| 7551 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7552 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7554 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7555 | }, |
| 7556 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7557 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7558 | .policy = nl80211_policy, |
| 7559 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7560 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7562 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7563 | }, |
| 7564 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7565 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7566 | .policy = nl80211_policy, |
| 7567 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7568 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7569 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7570 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7571 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7572 | { |
| 7573 | .cmd = NL80211_CMD_GET_STATION, |
| 7574 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7575 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7576 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7577 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7578 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7579 | }, |
| 7580 | { |
| 7581 | .cmd = NL80211_CMD_SET_STATION, |
| 7582 | .doit = nl80211_set_station, |
| 7583 | .policy = nl80211_policy, |
| 7584 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7586 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7587 | }, |
| 7588 | { |
| 7589 | .cmd = NL80211_CMD_NEW_STATION, |
| 7590 | .doit = nl80211_new_station, |
| 7591 | .policy = nl80211_policy, |
| 7592 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7593 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7594 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7595 | }, |
| 7596 | { |
| 7597 | .cmd = NL80211_CMD_DEL_STATION, |
| 7598 | .doit = nl80211_del_station, |
| 7599 | .policy = nl80211_policy, |
| 7600 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7601 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7602 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7603 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7604 | { |
| 7605 | .cmd = NL80211_CMD_GET_MPATH, |
| 7606 | .doit = nl80211_get_mpath, |
| 7607 | .dumpit = nl80211_dump_mpath, |
| 7608 | .policy = nl80211_policy, |
| 7609 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7611 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7612 | }, |
| 7613 | { |
| 7614 | .cmd = NL80211_CMD_SET_MPATH, |
| 7615 | .doit = nl80211_set_mpath, |
| 7616 | .policy = nl80211_policy, |
| 7617 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7619 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7620 | }, |
| 7621 | { |
| 7622 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7623 | .doit = nl80211_new_mpath, |
| 7624 | .policy = nl80211_policy, |
| 7625 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7627 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7628 | }, |
| 7629 | { |
| 7630 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7631 | .doit = nl80211_del_mpath, |
| 7632 | .policy = nl80211_policy, |
| 7633 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7635 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7636 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7637 | { |
| 7638 | .cmd = NL80211_CMD_SET_BSS, |
| 7639 | .doit = nl80211_set_bss, |
| 7640 | .policy = nl80211_policy, |
| 7641 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7643 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7644 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7645 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7646 | .cmd = NL80211_CMD_GET_REG, |
| 7647 | .doit = nl80211_get_reg, |
| 7648 | .policy = nl80211_policy, |
| 7649 | /* can be retrieved by unprivileged users */ |
| 7650 | }, |
| 7651 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7652 | .cmd = NL80211_CMD_SET_REG, |
| 7653 | .doit = nl80211_set_reg, |
| 7654 | .policy = nl80211_policy, |
| 7655 | .flags = GENL_ADMIN_PERM, |
| 7656 | }, |
| 7657 | { |
| 7658 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7659 | .doit = nl80211_req_set_reg, |
| 7660 | .policy = nl80211_policy, |
| 7661 | .flags = GENL_ADMIN_PERM, |
| 7662 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7663 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7664 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7665 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7666 | .policy = nl80211_policy, |
| 7667 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7668 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7669 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7670 | }, |
| 7671 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7672 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7673 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7674 | .policy = nl80211_policy, |
| 7675 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7676 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7677 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7678 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7679 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7680 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7681 | .doit = nl80211_trigger_scan, |
| 7682 | .policy = nl80211_policy, |
| 7683 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7684 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7685 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7686 | }, |
| 7687 | { |
| 7688 | .cmd = NL80211_CMD_GET_SCAN, |
| 7689 | .policy = nl80211_policy, |
| 7690 | .dumpit = nl80211_dump_scan, |
| 7691 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7692 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7693 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7694 | .doit = nl80211_start_sched_scan, |
| 7695 | .policy = nl80211_policy, |
| 7696 | .flags = GENL_ADMIN_PERM, |
| 7697 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7698 | NL80211_FLAG_NEED_RTNL, |
| 7699 | }, |
| 7700 | { |
| 7701 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7702 | .doit = nl80211_stop_sched_scan, |
| 7703 | .policy = nl80211_policy, |
| 7704 | .flags = GENL_ADMIN_PERM, |
| 7705 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7706 | NL80211_FLAG_NEED_RTNL, |
| 7707 | }, |
| 7708 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7709 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7710 | .doit = nl80211_authenticate, |
| 7711 | .policy = nl80211_policy, |
| 7712 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7713 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7714 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7715 | }, |
| 7716 | { |
| 7717 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7718 | .doit = nl80211_associate, |
| 7719 | .policy = nl80211_policy, |
| 7720 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7721 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7722 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7723 | }, |
| 7724 | { |
| 7725 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7726 | .doit = nl80211_deauthenticate, |
| 7727 | .policy = nl80211_policy, |
| 7728 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7729 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7730 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7731 | }, |
| 7732 | { |
| 7733 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7734 | .doit = nl80211_disassociate, |
| 7735 | .policy = nl80211_policy, |
| 7736 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7737 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7738 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7739 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7740 | { |
| 7741 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7742 | .doit = nl80211_join_ibss, |
| 7743 | .policy = nl80211_policy, |
| 7744 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7745 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7746 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7747 | }, |
| 7748 | { |
| 7749 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7750 | .doit = nl80211_leave_ibss, |
| 7751 | .policy = nl80211_policy, |
| 7752 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7754 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7755 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7756 | #ifdef CONFIG_NL80211_TESTMODE |
| 7757 | { |
| 7758 | .cmd = NL80211_CMD_TESTMODE, |
| 7759 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7760 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7761 | .policy = nl80211_policy, |
| 7762 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7763 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7764 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7765 | }, |
| 7766 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7767 | { |
| 7768 | .cmd = NL80211_CMD_CONNECT, |
| 7769 | .doit = nl80211_connect, |
| 7770 | .policy = nl80211_policy, |
| 7771 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7772 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7773 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7774 | }, |
| 7775 | { |
| 7776 | .cmd = NL80211_CMD_DISCONNECT, |
| 7777 | .doit = nl80211_disconnect, |
| 7778 | .policy = nl80211_policy, |
| 7779 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7780 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7781 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7782 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7783 | { |
| 7784 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7785 | .doit = nl80211_wiphy_netns, |
| 7786 | .policy = nl80211_policy, |
| 7787 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7788 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7789 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7790 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7791 | { |
| 7792 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7793 | .policy = nl80211_policy, |
| 7794 | .dumpit = nl80211_dump_survey, |
| 7795 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7796 | { |
| 7797 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7798 | .doit = nl80211_setdel_pmksa, |
| 7799 | .policy = nl80211_policy, |
| 7800 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7801 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7802 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7803 | }, |
| 7804 | { |
| 7805 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7806 | .doit = nl80211_setdel_pmksa, |
| 7807 | .policy = nl80211_policy, |
| 7808 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7809 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7810 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7811 | }, |
| 7812 | { |
| 7813 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7814 | .doit = nl80211_flush_pmksa, |
| 7815 | .policy = nl80211_policy, |
| 7816 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7817 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7818 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7819 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7820 | { |
| 7821 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7822 | .doit = nl80211_remain_on_channel, |
| 7823 | .policy = nl80211_policy, |
| 7824 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7825 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7826 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7827 | }, |
| 7828 | { |
| 7829 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7830 | .doit = nl80211_cancel_remain_on_channel, |
| 7831 | .policy = nl80211_policy, |
| 7832 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7833 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7834 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7835 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7836 | { |
| 7837 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7838 | .doit = nl80211_set_tx_bitrate_mask, |
| 7839 | .policy = nl80211_policy, |
| 7840 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7841 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7842 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7843 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7844 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7845 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7846 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7847 | .policy = nl80211_policy, |
| 7848 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7849 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7850 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7851 | }, |
| 7852 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7853 | .cmd = NL80211_CMD_FRAME, |
| 7854 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7855 | .policy = nl80211_policy, |
| 7856 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7857 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7858 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7859 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7860 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7861 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7862 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7863 | .policy = nl80211_policy, |
| 7864 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7865 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7866 | NL80211_FLAG_NEED_RTNL, |
| 7867 | }, |
| 7868 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7869 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7870 | .doit = nl80211_set_power_save, |
| 7871 | .policy = nl80211_policy, |
| 7872 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7873 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7874 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7875 | }, |
| 7876 | { |
| 7877 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7878 | .doit = nl80211_get_power_save, |
| 7879 | .policy = nl80211_policy, |
| 7880 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7881 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7882 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7883 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7884 | { |
| 7885 | .cmd = NL80211_CMD_SET_CQM, |
| 7886 | .doit = nl80211_set_cqm, |
| 7887 | .policy = nl80211_policy, |
| 7888 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7889 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7890 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7891 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7892 | { |
| 7893 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7894 | .doit = nl80211_set_channel, |
| 7895 | .policy = nl80211_policy, |
| 7896 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7897 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7898 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7899 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7900 | { |
| 7901 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7902 | .doit = nl80211_set_wds_peer, |
| 7903 | .policy = nl80211_policy, |
| 7904 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7905 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7906 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7907 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7908 | { |
| 7909 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7910 | .doit = nl80211_join_mesh, |
| 7911 | .policy = nl80211_policy, |
| 7912 | .flags = GENL_ADMIN_PERM, |
| 7913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7914 | NL80211_FLAG_NEED_RTNL, |
| 7915 | }, |
| 7916 | { |
| 7917 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7918 | .doit = nl80211_leave_mesh, |
| 7919 | .policy = nl80211_policy, |
| 7920 | .flags = GENL_ADMIN_PERM, |
| 7921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7922 | NL80211_FLAG_NEED_RTNL, |
| 7923 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7924 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7925 | { |
| 7926 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7927 | .doit = nl80211_get_wowlan, |
| 7928 | .policy = nl80211_policy, |
| 7929 | /* can be retrieved by unprivileged users */ |
| 7930 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7931 | NL80211_FLAG_NEED_RTNL, |
| 7932 | }, |
| 7933 | { |
| 7934 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7935 | .doit = nl80211_set_wowlan, |
| 7936 | .policy = nl80211_policy, |
| 7937 | .flags = GENL_ADMIN_PERM, |
| 7938 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7939 | NL80211_FLAG_NEED_RTNL, |
| 7940 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7941 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7942 | { |
| 7943 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7944 | .doit = nl80211_set_rekey_data, |
| 7945 | .policy = nl80211_policy, |
| 7946 | .flags = GENL_ADMIN_PERM, |
| 7947 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7948 | NL80211_FLAG_NEED_RTNL, |
| 7949 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7950 | { |
| 7951 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7952 | .doit = nl80211_tdls_mgmt, |
| 7953 | .policy = nl80211_policy, |
| 7954 | .flags = GENL_ADMIN_PERM, |
| 7955 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7956 | NL80211_FLAG_NEED_RTNL, |
| 7957 | }, |
| 7958 | { |
| 7959 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7960 | .doit = nl80211_tdls_oper, |
| 7961 | .policy = nl80211_policy, |
| 7962 | .flags = GENL_ADMIN_PERM, |
| 7963 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7964 | NL80211_FLAG_NEED_RTNL, |
| 7965 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7966 | { |
| 7967 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7968 | .doit = nl80211_register_unexpected_frame, |
| 7969 | .policy = nl80211_policy, |
| 7970 | .flags = GENL_ADMIN_PERM, |
| 7971 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7972 | NL80211_FLAG_NEED_RTNL, |
| 7973 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7974 | { |
| 7975 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7976 | .doit = nl80211_probe_client, |
| 7977 | .policy = nl80211_policy, |
| 7978 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7979 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7980 | NL80211_FLAG_NEED_RTNL, |
| 7981 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7982 | { |
| 7983 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7984 | .doit = nl80211_register_beacons, |
| 7985 | .policy = nl80211_policy, |
| 7986 | .flags = GENL_ADMIN_PERM, |
| 7987 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7988 | NL80211_FLAG_NEED_RTNL, |
| 7989 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7990 | { |
| 7991 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7992 | .doit = nl80211_set_noack_map, |
| 7993 | .policy = nl80211_policy, |
| 7994 | .flags = GENL_ADMIN_PERM, |
| 7995 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7996 | NL80211_FLAG_NEED_RTNL, |
| 7997 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7998 | { |
| 7999 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8000 | .doit = nl80211_start_p2p_device, |
| 8001 | .policy = nl80211_policy, |
| 8002 | .flags = GENL_ADMIN_PERM, |
| 8003 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8004 | NL80211_FLAG_NEED_RTNL, |
| 8005 | }, |
| 8006 | { |
| 8007 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8008 | .doit = nl80211_stop_p2p_device, |
| 8009 | .policy = nl80211_policy, |
| 8010 | .flags = GENL_ADMIN_PERM, |
| 8011 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8012 | NL80211_FLAG_NEED_RTNL, |
| 8013 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8014 | { |
| 8015 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8016 | .doit = nl80211_set_mcast_rate, |
| 8017 | .policy = nl80211_policy, |
| 8018 | .flags = GENL_ADMIN_PERM, |
| 8019 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8020 | NL80211_FLAG_NEED_RTNL, |
| 8021 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8022 | { |
| 8023 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8024 | .doit = nl80211_set_mac_acl, |
| 8025 | .policy = nl80211_policy, |
| 8026 | .flags = GENL_ADMIN_PERM, |
| 8027 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8028 | NL80211_FLAG_NEED_RTNL, |
| 8029 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8030 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8031 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8032 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8033 | .name = "mlme", |
| 8034 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8035 | |
| 8036 | /* multicast groups */ |
| 8037 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8038 | .name = "config", |
| 8039 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8040 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8041 | .name = "scan", |
| 8042 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8043 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8044 | .name = "regulatory", |
| 8045 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8046 | |
| 8047 | /* notification functions */ |
| 8048 | |
| 8049 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8050 | { |
| 8051 | struct sk_buff *msg; |
| 8052 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8053 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8054 | if (!msg) |
| 8055 | return; |
| 8056 | |
| 8057 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8058 | nlmsg_free(msg); |
| 8059 | return; |
| 8060 | } |
| 8061 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8062 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8063 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8064 | } |
| 8065 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8066 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8067 | struct cfg80211_registered_device *rdev) |
| 8068 | { |
| 8069 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8070 | struct nlattr *nest; |
| 8071 | int i; |
| 8072 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8073 | ASSERT_RDEV_LOCK(rdev); |
| 8074 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8075 | if (WARN_ON(!req)) |
| 8076 | return 0; |
| 8077 | |
| 8078 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8079 | if (!nest) |
| 8080 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8081 | for (i = 0; i < req->n_ssids; i++) { |
| 8082 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8083 | goto nla_put_failure; |
| 8084 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8085 | nla_nest_end(msg, nest); |
| 8086 | |
| 8087 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8088 | if (!nest) |
| 8089 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8090 | for (i = 0; i < req->n_channels; i++) { |
| 8091 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8092 | goto nla_put_failure; |
| 8093 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8094 | nla_nest_end(msg, nest); |
| 8095 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8096 | if (req->ie && |
| 8097 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8098 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8099 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8100 | if (req->flags) |
| 8101 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8102 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8103 | return 0; |
| 8104 | nla_put_failure: |
| 8105 | return -ENOBUFS; |
| 8106 | } |
| 8107 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8108 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8109 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8110 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8111 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8112 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8113 | { |
| 8114 | void *hdr; |
| 8115 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8116 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8117 | if (!hdr) |
| 8118 | return -1; |
| 8119 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8120 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8121 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8122 | wdev->netdev->ifindex)) || |
| 8123 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8124 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8125 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8126 | /* ignore errors and send incomplete event anyway */ |
| 8127 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8128 | |
| 8129 | return genlmsg_end(msg, hdr); |
| 8130 | |
| 8131 | nla_put_failure: |
| 8132 | genlmsg_cancel(msg, hdr); |
| 8133 | return -EMSGSIZE; |
| 8134 | } |
| 8135 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8136 | static int |
| 8137 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8138 | struct cfg80211_registered_device *rdev, |
| 8139 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8140 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8141 | { |
| 8142 | void *hdr; |
| 8143 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8144 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8145 | if (!hdr) |
| 8146 | return -1; |
| 8147 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8148 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8149 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8150 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8151 | |
| 8152 | return genlmsg_end(msg, hdr); |
| 8153 | |
| 8154 | nla_put_failure: |
| 8155 | genlmsg_cancel(msg, hdr); |
| 8156 | return -EMSGSIZE; |
| 8157 | } |
| 8158 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8159 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8160 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8161 | { |
| 8162 | struct sk_buff *msg; |
| 8163 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8164 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8165 | if (!msg) |
| 8166 | return; |
| 8167 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8168 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8169 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8170 | nlmsg_free(msg); |
| 8171 | return; |
| 8172 | } |
| 8173 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8174 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8175 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8176 | } |
| 8177 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8178 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8179 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8180 | { |
| 8181 | struct sk_buff *msg; |
| 8182 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8184 | if (!msg) |
| 8185 | return; |
| 8186 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8187 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8188 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8189 | nlmsg_free(msg); |
| 8190 | return; |
| 8191 | } |
| 8192 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8193 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8194 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8195 | } |
| 8196 | |
| 8197 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8198 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8199 | { |
| 8200 | struct sk_buff *msg; |
| 8201 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8203 | if (!msg) |
| 8204 | return; |
| 8205 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8206 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8207 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8208 | nlmsg_free(msg); |
| 8209 | return; |
| 8210 | } |
| 8211 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8212 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8213 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8214 | } |
| 8215 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8216 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8217 | struct net_device *netdev) |
| 8218 | { |
| 8219 | struct sk_buff *msg; |
| 8220 | |
| 8221 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8222 | if (!msg) |
| 8223 | return; |
| 8224 | |
| 8225 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8226 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8227 | nlmsg_free(msg); |
| 8228 | return; |
| 8229 | } |
| 8230 | |
| 8231 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8232 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8233 | } |
| 8234 | |
| 8235 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8236 | struct net_device *netdev, u32 cmd) |
| 8237 | { |
| 8238 | struct sk_buff *msg; |
| 8239 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8241 | if (!msg) |
| 8242 | return; |
| 8243 | |
| 8244 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8245 | nlmsg_free(msg); |
| 8246 | return; |
| 8247 | } |
| 8248 | |
| 8249 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8250 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8251 | } |
| 8252 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8253 | /* |
| 8254 | * This can happen on global regulatory changes or device specific settings |
| 8255 | * based on custom world regulatory domains. |
| 8256 | */ |
| 8257 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8258 | { |
| 8259 | struct sk_buff *msg; |
| 8260 | void *hdr; |
| 8261 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8263 | if (!msg) |
| 8264 | return; |
| 8265 | |
| 8266 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8267 | if (!hdr) { |
| 8268 | nlmsg_free(msg); |
| 8269 | return; |
| 8270 | } |
| 8271 | |
| 8272 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8273 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8274 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8275 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8276 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8277 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8278 | NL80211_REGDOM_TYPE_WORLD)) |
| 8279 | goto nla_put_failure; |
| 8280 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8281 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8282 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8283 | goto nla_put_failure; |
| 8284 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8285 | request->intersect) { |
| 8286 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8287 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8288 | goto nla_put_failure; |
| 8289 | } else { |
| 8290 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8291 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8292 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8293 | request->alpha2)) |
| 8294 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8295 | } |
| 8296 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8297 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8298 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8299 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8300 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8301 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8302 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8303 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8304 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8305 | GFP_ATOMIC); |
| 8306 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8307 | |
| 8308 | return; |
| 8309 | |
| 8310 | nla_put_failure: |
| 8311 | genlmsg_cancel(msg, hdr); |
| 8312 | nlmsg_free(msg); |
| 8313 | } |
| 8314 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8315 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8316 | struct net_device *netdev, |
| 8317 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8318 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8319 | { |
| 8320 | struct sk_buff *msg; |
| 8321 | void *hdr; |
| 8322 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8323 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8324 | if (!msg) |
| 8325 | return; |
| 8326 | |
| 8327 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8328 | if (!hdr) { |
| 8329 | nlmsg_free(msg); |
| 8330 | return; |
| 8331 | } |
| 8332 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8334 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8335 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8336 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8337 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8338 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8339 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8340 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8341 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8342 | return; |
| 8343 | |
| 8344 | nla_put_failure: |
| 8345 | genlmsg_cancel(msg, hdr); |
| 8346 | nlmsg_free(msg); |
| 8347 | } |
| 8348 | |
| 8349 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8350 | struct net_device *netdev, const u8 *buf, |
| 8351 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8352 | { |
| 8353 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8354 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8355 | } |
| 8356 | |
| 8357 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8358 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8359 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8360 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8361 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8362 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8363 | } |
| 8364 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8365 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8366 | struct net_device *netdev, const u8 *buf, |
| 8367 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8368 | { |
| 8369 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8370 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8371 | } |
| 8372 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8373 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8374 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8375 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8376 | { |
| 8377 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8378 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8379 | } |
| 8380 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8381 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8382 | struct net_device *netdev, const u8 *buf, |
| 8383 | size_t len, gfp_t gfp) |
| 8384 | { |
| 8385 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8386 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8387 | } |
| 8388 | |
| 8389 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8390 | struct net_device *netdev, const u8 *buf, |
| 8391 | size_t len, gfp_t gfp) |
| 8392 | { |
| 8393 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8394 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8395 | } |
| 8396 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8397 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8398 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8399 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8400 | { |
| 8401 | struct sk_buff *msg; |
| 8402 | void *hdr; |
| 8403 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8405 | if (!msg) |
| 8406 | return; |
| 8407 | |
| 8408 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8409 | if (!hdr) { |
| 8410 | nlmsg_free(msg); |
| 8411 | return; |
| 8412 | } |
| 8413 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8415 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8416 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8417 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8418 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8420 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8421 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8422 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8423 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8424 | return; |
| 8425 | |
| 8426 | nla_put_failure: |
| 8427 | genlmsg_cancel(msg, hdr); |
| 8428 | nlmsg_free(msg); |
| 8429 | } |
| 8430 | |
| 8431 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8432 | struct net_device *netdev, const u8 *addr, |
| 8433 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8434 | { |
| 8435 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8436 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8437 | } |
| 8438 | |
| 8439 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8440 | struct net_device *netdev, const u8 *addr, |
| 8441 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8442 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8443 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8444 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8445 | } |
| 8446 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8447 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8448 | struct net_device *netdev, const u8 *bssid, |
| 8449 | const u8 *req_ie, size_t req_ie_len, |
| 8450 | const u8 *resp_ie, size_t resp_ie_len, |
| 8451 | u16 status, gfp_t gfp) |
| 8452 | { |
| 8453 | struct sk_buff *msg; |
| 8454 | void *hdr; |
| 8455 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8457 | if (!msg) |
| 8458 | return; |
| 8459 | |
| 8460 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8461 | if (!hdr) { |
| 8462 | nlmsg_free(msg); |
| 8463 | return; |
| 8464 | } |
| 8465 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8466 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8467 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8468 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8469 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8470 | (req_ie && |
| 8471 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8472 | (resp_ie && |
| 8473 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8474 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8475 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8476 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8477 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8478 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8479 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8480 | return; |
| 8481 | |
| 8482 | nla_put_failure: |
| 8483 | genlmsg_cancel(msg, hdr); |
| 8484 | nlmsg_free(msg); |
| 8485 | |
| 8486 | } |
| 8487 | |
| 8488 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8489 | struct net_device *netdev, const u8 *bssid, |
| 8490 | const u8 *req_ie, size_t req_ie_len, |
| 8491 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8492 | { |
| 8493 | struct sk_buff *msg; |
| 8494 | void *hdr; |
| 8495 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8496 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8497 | if (!msg) |
| 8498 | return; |
| 8499 | |
| 8500 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8501 | if (!hdr) { |
| 8502 | nlmsg_free(msg); |
| 8503 | return; |
| 8504 | } |
| 8505 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8506 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8507 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8508 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8509 | (req_ie && |
| 8510 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8511 | (resp_ie && |
| 8512 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8513 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8514 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8515 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8516 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8517 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8518 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8519 | return; |
| 8520 | |
| 8521 | nla_put_failure: |
| 8522 | genlmsg_cancel(msg, hdr); |
| 8523 | nlmsg_free(msg); |
| 8524 | |
| 8525 | } |
| 8526 | |
| 8527 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8528 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8529 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8530 | { |
| 8531 | struct sk_buff *msg; |
| 8532 | void *hdr; |
| 8533 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8534 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8535 | if (!msg) |
| 8536 | return; |
| 8537 | |
| 8538 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8539 | if (!hdr) { |
| 8540 | nlmsg_free(msg); |
| 8541 | return; |
| 8542 | } |
| 8543 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8544 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8545 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8546 | (from_ap && reason && |
| 8547 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8548 | (from_ap && |
| 8549 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8550 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8551 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8552 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8553 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8554 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8555 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8556 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8557 | return; |
| 8558 | |
| 8559 | nla_put_failure: |
| 8560 | genlmsg_cancel(msg, hdr); |
| 8561 | nlmsg_free(msg); |
| 8562 | |
| 8563 | } |
| 8564 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8565 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8566 | struct net_device *netdev, const u8 *bssid, |
| 8567 | gfp_t gfp) |
| 8568 | { |
| 8569 | struct sk_buff *msg; |
| 8570 | void *hdr; |
| 8571 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8573 | if (!msg) |
| 8574 | return; |
| 8575 | |
| 8576 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8577 | if (!hdr) { |
| 8578 | nlmsg_free(msg); |
| 8579 | return; |
| 8580 | } |
| 8581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8582 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8583 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8584 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8585 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8586 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8587 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8588 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8589 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8590 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8591 | return; |
| 8592 | |
| 8593 | nla_put_failure: |
| 8594 | genlmsg_cancel(msg, hdr); |
| 8595 | nlmsg_free(msg); |
| 8596 | } |
| 8597 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8598 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8599 | struct net_device *netdev, |
| 8600 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8601 | gfp_t gfp) |
| 8602 | { |
| 8603 | struct sk_buff *msg; |
| 8604 | void *hdr; |
| 8605 | |
| 8606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8607 | if (!msg) |
| 8608 | return; |
| 8609 | |
| 8610 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8611 | if (!hdr) { |
| 8612 | nlmsg_free(msg); |
| 8613 | return; |
| 8614 | } |
| 8615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8616 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8617 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8618 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8619 | (ie_len && ie && |
| 8620 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8621 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8622 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8623 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8624 | |
| 8625 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8626 | nl80211_mlme_mcgrp.id, gfp); |
| 8627 | return; |
| 8628 | |
| 8629 | nla_put_failure: |
| 8630 | genlmsg_cancel(msg, hdr); |
| 8631 | nlmsg_free(msg); |
| 8632 | } |
| 8633 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8634 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8635 | struct net_device *netdev, const u8 *addr, |
| 8636 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8637 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8638 | { |
| 8639 | struct sk_buff *msg; |
| 8640 | void *hdr; |
| 8641 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8643 | if (!msg) |
| 8644 | return; |
| 8645 | |
| 8646 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8647 | if (!hdr) { |
| 8648 | nlmsg_free(msg); |
| 8649 | return; |
| 8650 | } |
| 8651 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8652 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8653 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8654 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8655 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8656 | (key_id != -1 && |
| 8657 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8658 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8659 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8660 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8661 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8662 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8663 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8664 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8665 | return; |
| 8666 | |
| 8667 | nla_put_failure: |
| 8668 | genlmsg_cancel(msg, hdr); |
| 8669 | nlmsg_free(msg); |
| 8670 | } |
| 8671 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8672 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8673 | struct ieee80211_channel *channel_before, |
| 8674 | struct ieee80211_channel *channel_after) |
| 8675 | { |
| 8676 | struct sk_buff *msg; |
| 8677 | void *hdr; |
| 8678 | struct nlattr *nl_freq; |
| 8679 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8681 | if (!msg) |
| 8682 | return; |
| 8683 | |
| 8684 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8685 | if (!hdr) { |
| 8686 | nlmsg_free(msg); |
| 8687 | return; |
| 8688 | } |
| 8689 | |
| 8690 | /* |
| 8691 | * Since we are applying the beacon hint to a wiphy we know its |
| 8692 | * wiphy_idx is valid |
| 8693 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8694 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8695 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8696 | |
| 8697 | /* Before */ |
| 8698 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8699 | if (!nl_freq) |
| 8700 | goto nla_put_failure; |
| 8701 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8702 | goto nla_put_failure; |
| 8703 | nla_nest_end(msg, nl_freq); |
| 8704 | |
| 8705 | /* After */ |
| 8706 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8707 | if (!nl_freq) |
| 8708 | goto nla_put_failure; |
| 8709 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8710 | goto nla_put_failure; |
| 8711 | nla_nest_end(msg, nl_freq); |
| 8712 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8713 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8714 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8715 | rcu_read_lock(); |
| 8716 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8717 | GFP_ATOMIC); |
| 8718 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8719 | |
| 8720 | return; |
| 8721 | |
| 8722 | nla_put_failure: |
| 8723 | genlmsg_cancel(msg, hdr); |
| 8724 | nlmsg_free(msg); |
| 8725 | } |
| 8726 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8727 | static void nl80211_send_remain_on_chan_event( |
| 8728 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8729 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8730 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8731 | unsigned int duration, gfp_t gfp) |
| 8732 | { |
| 8733 | struct sk_buff *msg; |
| 8734 | void *hdr; |
| 8735 | |
| 8736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8737 | if (!msg) |
| 8738 | return; |
| 8739 | |
| 8740 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8741 | if (!hdr) { |
| 8742 | nlmsg_free(msg); |
| 8743 | return; |
| 8744 | } |
| 8745 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8746 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8747 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8748 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8749 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8750 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8751 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8752 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8753 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8754 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8755 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8756 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8757 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8758 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8759 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8760 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8761 | |
| 8762 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8763 | nl80211_mlme_mcgrp.id, gfp); |
| 8764 | return; |
| 8765 | |
| 8766 | nla_put_failure: |
| 8767 | genlmsg_cancel(msg, hdr); |
| 8768 | nlmsg_free(msg); |
| 8769 | } |
| 8770 | |
| 8771 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8772 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8773 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8774 | unsigned int duration, gfp_t gfp) |
| 8775 | { |
| 8776 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8777 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8778 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8779 | } |
| 8780 | |
| 8781 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8782 | struct cfg80211_registered_device *rdev, |
| 8783 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8784 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8785 | { |
| 8786 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8787 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8788 | } |
| 8789 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8790 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8791 | struct net_device *dev, const u8 *mac_addr, |
| 8792 | struct station_info *sinfo, gfp_t gfp) |
| 8793 | { |
| 8794 | struct sk_buff *msg; |
| 8795 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8797 | if (!msg) |
| 8798 | return; |
| 8799 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8800 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8801 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8802 | nlmsg_free(msg); |
| 8803 | return; |
| 8804 | } |
| 8805 | |
| 8806 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8807 | nl80211_mlme_mcgrp.id, gfp); |
| 8808 | } |
| 8809 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8810 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8811 | struct net_device *dev, const u8 *mac_addr, |
| 8812 | gfp_t gfp) |
| 8813 | { |
| 8814 | struct sk_buff *msg; |
| 8815 | void *hdr; |
| 8816 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8817 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8818 | if (!msg) |
| 8819 | return; |
| 8820 | |
| 8821 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8822 | if (!hdr) { |
| 8823 | nlmsg_free(msg); |
| 8824 | return; |
| 8825 | } |
| 8826 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8827 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8828 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8829 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8830 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8831 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8832 | |
| 8833 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8834 | nl80211_mlme_mcgrp.id, gfp); |
| 8835 | return; |
| 8836 | |
| 8837 | nla_put_failure: |
| 8838 | genlmsg_cancel(msg, hdr); |
| 8839 | nlmsg_free(msg); |
| 8840 | } |
| 8841 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8842 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8843 | struct net_device *dev, const u8 *mac_addr, |
| 8844 | enum nl80211_connect_failed_reason reason, |
| 8845 | gfp_t gfp) |
| 8846 | { |
| 8847 | struct sk_buff *msg; |
| 8848 | void *hdr; |
| 8849 | |
| 8850 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8851 | if (!msg) |
| 8852 | return; |
| 8853 | |
| 8854 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8855 | if (!hdr) { |
| 8856 | nlmsg_free(msg); |
| 8857 | return; |
| 8858 | } |
| 8859 | |
| 8860 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8862 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8863 | goto nla_put_failure; |
| 8864 | |
| 8865 | genlmsg_end(msg, hdr); |
| 8866 | |
| 8867 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8868 | nl80211_mlme_mcgrp.id, gfp); |
| 8869 | return; |
| 8870 | |
| 8871 | nla_put_failure: |
| 8872 | genlmsg_cancel(msg, hdr); |
| 8873 | nlmsg_free(msg); |
| 8874 | } |
| 8875 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8876 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8877 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8878 | { |
| 8879 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8880 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8881 | struct sk_buff *msg; |
| 8882 | void *hdr; |
| 8883 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8884 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8885 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8886 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8887 | return false; |
| 8888 | |
| 8889 | msg = nlmsg_new(100, gfp); |
| 8890 | if (!msg) |
| 8891 | return true; |
| 8892 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8893 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8894 | if (!hdr) { |
| 8895 | nlmsg_free(msg); |
| 8896 | return true; |
| 8897 | } |
| 8898 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8899 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8900 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8901 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8902 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8903 | |
| 8904 | err = genlmsg_end(msg, hdr); |
| 8905 | if (err < 0) { |
| 8906 | nlmsg_free(msg); |
| 8907 | return true; |
| 8908 | } |
| 8909 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8910 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8911 | return true; |
| 8912 | |
| 8913 | nla_put_failure: |
| 8914 | genlmsg_cancel(msg, hdr); |
| 8915 | nlmsg_free(msg); |
| 8916 | return true; |
| 8917 | } |
| 8918 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8919 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8920 | { |
| 8921 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8922 | addr, gfp); |
| 8923 | } |
| 8924 | |
| 8925 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8926 | const u8 *addr, gfp_t gfp) |
| 8927 | { |
| 8928 | return __nl80211_unexpected_frame(dev, |
| 8929 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8930 | addr, gfp); |
| 8931 | } |
| 8932 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8933 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8934 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8935 | int freq, int sig_dbm, |
| 8936 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8937 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8938 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8939 | struct sk_buff *msg; |
| 8940 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8941 | |
| 8942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8943 | if (!msg) |
| 8944 | return -ENOMEM; |
| 8945 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8946 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8947 | if (!hdr) { |
| 8948 | nlmsg_free(msg); |
| 8949 | return -ENOMEM; |
| 8950 | } |
| 8951 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8952 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8953 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8954 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8955 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8956 | (sig_dbm && |
| 8957 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8958 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8959 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8960 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8961 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8962 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8963 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8964 | |
| 8965 | nla_put_failure: |
| 8966 | genlmsg_cancel(msg, hdr); |
| 8967 | nlmsg_free(msg); |
| 8968 | return -ENOBUFS; |
| 8969 | } |
| 8970 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8971 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8972 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8973 | const u8 *buf, size_t len, bool ack, |
| 8974 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8975 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8976 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8977 | struct sk_buff *msg; |
| 8978 | void *hdr; |
| 8979 | |
| 8980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8981 | if (!msg) |
| 8982 | return; |
| 8983 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8984 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8985 | if (!hdr) { |
| 8986 | nlmsg_free(msg); |
| 8987 | return; |
| 8988 | } |
| 8989 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8990 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8991 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8992 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8993 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8994 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8995 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8996 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8997 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8998 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8999 | |
| 9000 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9001 | return; |
| 9002 | |
| 9003 | nla_put_failure: |
| 9004 | genlmsg_cancel(msg, hdr); |
| 9005 | nlmsg_free(msg); |
| 9006 | } |
| 9007 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9008 | void |
| 9009 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9010 | struct net_device *netdev, |
| 9011 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9012 | gfp_t gfp) |
| 9013 | { |
| 9014 | struct sk_buff *msg; |
| 9015 | struct nlattr *pinfoattr; |
| 9016 | void *hdr; |
| 9017 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9018 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9019 | if (!msg) |
| 9020 | return; |
| 9021 | |
| 9022 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9023 | if (!hdr) { |
| 9024 | nlmsg_free(msg); |
| 9025 | return; |
| 9026 | } |
| 9027 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9028 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9029 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9030 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9031 | |
| 9032 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9033 | if (!pinfoattr) |
| 9034 | goto nla_put_failure; |
| 9035 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9036 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9037 | rssi_event)) |
| 9038 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9039 | |
| 9040 | nla_nest_end(msg, pinfoattr); |
| 9041 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9042 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9043 | |
| 9044 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9045 | nl80211_mlme_mcgrp.id, gfp); |
| 9046 | return; |
| 9047 | |
| 9048 | nla_put_failure: |
| 9049 | genlmsg_cancel(msg, hdr); |
| 9050 | nlmsg_free(msg); |
| 9051 | } |
| 9052 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9053 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9054 | struct net_device *netdev, const u8 *bssid, |
| 9055 | const u8 *replay_ctr, gfp_t gfp) |
| 9056 | { |
| 9057 | struct sk_buff *msg; |
| 9058 | struct nlattr *rekey_attr; |
| 9059 | void *hdr; |
| 9060 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9061 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9062 | if (!msg) |
| 9063 | return; |
| 9064 | |
| 9065 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9066 | if (!hdr) { |
| 9067 | nlmsg_free(msg); |
| 9068 | return; |
| 9069 | } |
| 9070 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9071 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9072 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9073 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9074 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9075 | |
| 9076 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9077 | if (!rekey_attr) |
| 9078 | goto nla_put_failure; |
| 9079 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9080 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9081 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9082 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9083 | |
| 9084 | nla_nest_end(msg, rekey_attr); |
| 9085 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9086 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9087 | |
| 9088 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9089 | nl80211_mlme_mcgrp.id, gfp); |
| 9090 | return; |
| 9091 | |
| 9092 | nla_put_failure: |
| 9093 | genlmsg_cancel(msg, hdr); |
| 9094 | nlmsg_free(msg); |
| 9095 | } |
| 9096 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9097 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9098 | struct net_device *netdev, int index, |
| 9099 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9100 | { |
| 9101 | struct sk_buff *msg; |
| 9102 | struct nlattr *attr; |
| 9103 | void *hdr; |
| 9104 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9105 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9106 | if (!msg) |
| 9107 | return; |
| 9108 | |
| 9109 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9110 | if (!hdr) { |
| 9111 | nlmsg_free(msg); |
| 9112 | return; |
| 9113 | } |
| 9114 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9115 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9116 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9117 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9118 | |
| 9119 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9120 | if (!attr) |
| 9121 | goto nla_put_failure; |
| 9122 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9123 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9124 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9125 | (preauth && |
| 9126 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9127 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9128 | |
| 9129 | nla_nest_end(msg, attr); |
| 9130 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9131 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9132 | |
| 9133 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9134 | nl80211_mlme_mcgrp.id, gfp); |
| 9135 | return; |
| 9136 | |
| 9137 | nla_put_failure: |
| 9138 | genlmsg_cancel(msg, hdr); |
| 9139 | nlmsg_free(msg); |
| 9140 | } |
| 9141 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9142 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9143 | struct net_device *netdev, |
| 9144 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9145 | { |
| 9146 | struct sk_buff *msg; |
| 9147 | void *hdr; |
| 9148 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9149 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9150 | if (!msg) |
| 9151 | return; |
| 9152 | |
| 9153 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9154 | if (!hdr) { |
| 9155 | nlmsg_free(msg); |
| 9156 | return; |
| 9157 | } |
| 9158 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9159 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9160 | goto nla_put_failure; |
| 9161 | |
| 9162 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9163 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9164 | |
| 9165 | genlmsg_end(msg, hdr); |
| 9166 | |
| 9167 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9168 | nl80211_mlme_mcgrp.id, gfp); |
| 9169 | return; |
| 9170 | |
| 9171 | nla_put_failure: |
| 9172 | genlmsg_cancel(msg, hdr); |
| 9173 | nlmsg_free(msg); |
| 9174 | } |
| 9175 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9176 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9177 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9178 | struct net_device *netdev, const u8 *peer, |
| 9179 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9180 | { |
| 9181 | struct sk_buff *msg; |
| 9182 | struct nlattr *pinfoattr; |
| 9183 | void *hdr; |
| 9184 | |
| 9185 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9186 | if (!msg) |
| 9187 | return; |
| 9188 | |
| 9189 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9190 | if (!hdr) { |
| 9191 | nlmsg_free(msg); |
| 9192 | return; |
| 9193 | } |
| 9194 | |
| 9195 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9196 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9197 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9198 | goto nla_put_failure; |
| 9199 | |
| 9200 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9201 | if (!pinfoattr) |
| 9202 | goto nla_put_failure; |
| 9203 | |
| 9204 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9205 | goto nla_put_failure; |
| 9206 | |
| 9207 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9208 | goto nla_put_failure; |
| 9209 | |
| 9210 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9211 | goto nla_put_failure; |
| 9212 | |
| 9213 | nla_nest_end(msg, pinfoattr); |
| 9214 | |
| 9215 | genlmsg_end(msg, hdr); |
| 9216 | |
| 9217 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9218 | nl80211_mlme_mcgrp.id, gfp); |
| 9219 | return; |
| 9220 | |
| 9221 | nla_put_failure: |
| 9222 | genlmsg_cancel(msg, hdr); |
| 9223 | nlmsg_free(msg); |
| 9224 | } |
| 9225 | |
| 9226 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9227 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9228 | struct net_device *netdev, const u8 *peer, |
| 9229 | u32 num_packets, gfp_t gfp) |
| 9230 | { |
| 9231 | struct sk_buff *msg; |
| 9232 | struct nlattr *pinfoattr; |
| 9233 | void *hdr; |
| 9234 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9236 | if (!msg) |
| 9237 | return; |
| 9238 | |
| 9239 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9240 | if (!hdr) { |
| 9241 | nlmsg_free(msg); |
| 9242 | return; |
| 9243 | } |
| 9244 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9245 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9246 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9247 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9248 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9249 | |
| 9250 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9251 | if (!pinfoattr) |
| 9252 | goto nla_put_failure; |
| 9253 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9254 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9255 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9256 | |
| 9257 | nla_nest_end(msg, pinfoattr); |
| 9258 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9259 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9260 | |
| 9261 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9262 | nl80211_mlme_mcgrp.id, gfp); |
| 9263 | return; |
| 9264 | |
| 9265 | nla_put_failure: |
| 9266 | genlmsg_cancel(msg, hdr); |
| 9267 | nlmsg_free(msg); |
| 9268 | } |
| 9269 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9270 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9271 | u64 cookie, bool acked, gfp_t gfp) |
| 9272 | { |
| 9273 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9274 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9275 | struct sk_buff *msg; |
| 9276 | void *hdr; |
| 9277 | int err; |
| 9278 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9279 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9280 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9282 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9283 | if (!msg) |
| 9284 | return; |
| 9285 | |
| 9286 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9287 | if (!hdr) { |
| 9288 | nlmsg_free(msg); |
| 9289 | return; |
| 9290 | } |
| 9291 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9292 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9293 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9294 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9295 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9296 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9297 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9298 | |
| 9299 | err = genlmsg_end(msg, hdr); |
| 9300 | if (err < 0) { |
| 9301 | nlmsg_free(msg); |
| 9302 | return; |
| 9303 | } |
| 9304 | |
| 9305 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9306 | nl80211_mlme_mcgrp.id, gfp); |
| 9307 | return; |
| 9308 | |
| 9309 | nla_put_failure: |
| 9310 | genlmsg_cancel(msg, hdr); |
| 9311 | nlmsg_free(msg); |
| 9312 | } |
| 9313 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9314 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9315 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9316 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9317 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9318 | { |
| 9319 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9320 | struct sk_buff *msg; |
| 9321 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9322 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9323 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9324 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9325 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9326 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9327 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9328 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9329 | if (!msg) { |
| 9330 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9331 | return; |
| 9332 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9333 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9334 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9335 | if (!hdr) |
| 9336 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9337 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9339 | (freq && |
| 9340 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9341 | (sig_dbm && |
| 9342 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9343 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9344 | goto nla_put_failure; |
| 9345 | |
| 9346 | genlmsg_end(msg, hdr); |
| 9347 | |
| 9348 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9349 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9350 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9351 | return; |
| 9352 | |
| 9353 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9354 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9355 | if (hdr) |
| 9356 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9357 | nlmsg_free(msg); |
| 9358 | } |
| 9359 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9360 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9361 | #ifdef CONFIG_PM |
| 9362 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9363 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9364 | gfp_t gfp) |
| 9365 | { |
| 9366 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9367 | struct sk_buff *msg; |
| 9368 | void *hdr; |
| 9369 | int err, size = 200; |
| 9370 | |
| 9371 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9372 | |
| 9373 | if (wakeup) |
| 9374 | size += wakeup->packet_present_len; |
| 9375 | |
| 9376 | msg = nlmsg_new(size, gfp); |
| 9377 | if (!msg) |
| 9378 | return; |
| 9379 | |
| 9380 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9381 | if (!hdr) |
| 9382 | goto free_msg; |
| 9383 | |
| 9384 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9385 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9386 | goto free_msg; |
| 9387 | |
| 9388 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9389 | wdev->netdev->ifindex)) |
| 9390 | goto free_msg; |
| 9391 | |
| 9392 | if (wakeup) { |
| 9393 | struct nlattr *reasons; |
| 9394 | |
| 9395 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9396 | |
| 9397 | if (wakeup->disconnect && |
| 9398 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9399 | goto free_msg; |
| 9400 | if (wakeup->magic_pkt && |
| 9401 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9402 | goto free_msg; |
| 9403 | if (wakeup->gtk_rekey_failure && |
| 9404 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9405 | goto free_msg; |
| 9406 | if (wakeup->eap_identity_req && |
| 9407 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9408 | goto free_msg; |
| 9409 | if (wakeup->four_way_handshake && |
| 9410 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9411 | goto free_msg; |
| 9412 | if (wakeup->rfkill_release && |
| 9413 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9414 | goto free_msg; |
| 9415 | |
| 9416 | if (wakeup->pattern_idx >= 0 && |
| 9417 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9418 | wakeup->pattern_idx)) |
| 9419 | goto free_msg; |
| 9420 | |
| 9421 | if (wakeup->packet) { |
| 9422 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9423 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9424 | |
| 9425 | if (!wakeup->packet_80211) { |
| 9426 | pkt_attr = |
| 9427 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9428 | len_attr = |
| 9429 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9430 | } |
| 9431 | |
| 9432 | if (wakeup->packet_len && |
| 9433 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9434 | goto free_msg; |
| 9435 | |
| 9436 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9437 | wakeup->packet)) |
| 9438 | goto free_msg; |
| 9439 | } |
| 9440 | |
| 9441 | nla_nest_end(msg, reasons); |
| 9442 | } |
| 9443 | |
| 9444 | err = genlmsg_end(msg, hdr); |
| 9445 | if (err < 0) |
| 9446 | goto free_msg; |
| 9447 | |
| 9448 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9449 | nl80211_mlme_mcgrp.id, gfp); |
| 9450 | return; |
| 9451 | |
| 9452 | free_msg: |
| 9453 | nlmsg_free(msg); |
| 9454 | } |
| 9455 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9456 | #endif |
| 9457 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9458 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9459 | enum nl80211_tdls_operation oper, |
| 9460 | u16 reason_code, gfp_t gfp) |
| 9461 | { |
| 9462 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9463 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9464 | struct sk_buff *msg; |
| 9465 | void *hdr; |
| 9466 | int err; |
| 9467 | |
| 9468 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9469 | reason_code); |
| 9470 | |
| 9471 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9472 | if (!msg) |
| 9473 | return; |
| 9474 | |
| 9475 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9476 | if (!hdr) { |
| 9477 | nlmsg_free(msg); |
| 9478 | return; |
| 9479 | } |
| 9480 | |
| 9481 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9482 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9483 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9484 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9485 | (reason_code > 0 && |
| 9486 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9487 | goto nla_put_failure; |
| 9488 | |
| 9489 | err = genlmsg_end(msg, hdr); |
| 9490 | if (err < 0) { |
| 9491 | nlmsg_free(msg); |
| 9492 | return; |
| 9493 | } |
| 9494 | |
| 9495 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9496 | nl80211_mlme_mcgrp.id, gfp); |
| 9497 | return; |
| 9498 | |
| 9499 | nla_put_failure: |
| 9500 | genlmsg_cancel(msg, hdr); |
| 9501 | nlmsg_free(msg); |
| 9502 | } |
| 9503 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9504 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9505 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9506 | unsigned long state, |
| 9507 | void *_notify) |
| 9508 | { |
| 9509 | struct netlink_notify *notify = _notify; |
| 9510 | struct cfg80211_registered_device *rdev; |
| 9511 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9512 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9513 | |
| 9514 | if (state != NETLINK_URELEASE) |
| 9515 | return NOTIFY_DONE; |
| 9516 | |
| 9517 | rcu_read_lock(); |
| 9518 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9519 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9520 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9521 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9522 | |
| 9523 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9524 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9525 | list) { |
| 9526 | if (reg->nlportid == notify->portid) { |
| 9527 | list_del(®->list); |
| 9528 | kfree(reg); |
| 9529 | break; |
| 9530 | } |
| 9531 | } |
| 9532 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9533 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9534 | |
| 9535 | rcu_read_unlock(); |
| 9536 | |
| 9537 | return NOTIFY_DONE; |
| 9538 | } |
| 9539 | |
| 9540 | static struct notifier_block nl80211_netlink_notifier = { |
| 9541 | .notifier_call = nl80211_netlink_notify, |
| 9542 | }; |
| 9543 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9544 | /* initialisation/exit functions */ |
| 9545 | |
| 9546 | int nl80211_init(void) |
| 9547 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9548 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9549 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9550 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9551 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9552 | if (err) |
| 9553 | return err; |
| 9554 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9555 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9556 | if (err) |
| 9557 | goto err_out; |
| 9558 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9559 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9560 | if (err) |
| 9561 | goto err_out; |
| 9562 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9563 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9564 | if (err) |
| 9565 | goto err_out; |
| 9566 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9567 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9568 | if (err) |
| 9569 | goto err_out; |
| 9570 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9571 | #ifdef CONFIG_NL80211_TESTMODE |
| 9572 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9573 | if (err) |
| 9574 | goto err_out; |
| 9575 | #endif |
| 9576 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9577 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9578 | if (err) |
| 9579 | goto err_out; |
| 9580 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9581 | return 0; |
| 9582 | err_out: |
| 9583 | genl_unregister_family(&nl80211_fam); |
| 9584 | return err; |
| 9585 | } |
| 9586 | |
| 9587 | void nl80211_exit(void) |
| 9588 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9589 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9590 | genl_unregister_family(&nl80211_fam); |
| 9591 | } |